diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index 0ce266135..a2ae9052d 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -663,7 +663,8 @@ QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const else return QVariant(QString::fromUtf8(group->group_info.name.c_str())); - //case COLUMN_THREAD_ID: return QVariant(QString::fromStdString(group->group_info.id.toStdString())); + case COLUMN_THREAD_ID: return QVariant(QString::fromStdString(group->group_info.id.toStdString())); + default: return QVariant(); } diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 297217ac9..2ed099511 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -101,6 +101,7 @@ * #define FRIENDS_DEBUG 1 * #define DEBUG_NEW_FRIEND_LIST 1 *****/ +#define DEBUG_NEW_FRIEND_LIST 1 Q_DECLARE_METATYPE(ElidedLabel*) @@ -377,7 +378,7 @@ void NewFriendList::saveExpandedPathsAndSelection(std::set& expanded_in #endif for(int row = 0; row < mProxyModel->rowCount(); ++row) - recursSaveExpandedItems(mProxyModel->index(row,0),current_index,QString(),expanded_indexes,sel); + recursSaveExpandedItems(mProxyModel->index(row,0),current_index,QString(),expanded_indexes,sel,0); #ifdef DEBUG_NEW_FRIEND_LIST std::cerr << " selected index: \"" << sel.toStdString() << "\"" << std::endl; @@ -394,54 +395,51 @@ void NewFriendList::restoreExpandedPathsAndSelection(const std::set& ex ui->peerTreeWidget->blockSignals(true) ; for(int row = 0; row < mProxyModel->rowCount(); ++row) - recursRestoreExpandedItems(mProxyModel->index(row,0),QString(),expanded_indexes,index_to_select,selected_index); + recursRestoreExpandedItems(mProxyModel->index(row,0),QString(),expanded_indexes,index_to_select,selected_index,0); ui->peerTreeWidget->blockSignals(false) ; } -void NewFriendList::recursSaveExpandedItems(const QModelIndex& index,const QModelIndex& current_index,const QString& parent_path,std::set& exp, QString& sel) +void NewFriendList::recursSaveExpandedItems(const QModelIndex& index,const QModelIndex& current_index,const QString& parent_path,std::set& exp, QString& sel,int indx) { - QString local_path = parent_path + index.sibling(index.row(),RsFriendListModel::COLUMN_THREAD_ID).data(Qt::DisplayRole).toString() + " "; + QString local_path = parent_path + (parent_path.isNull()?"":"/") + index.sibling(index.row(),RsFriendListModel::COLUMN_THREAD_ID).data(Qt::DisplayRole).toString() ; #ifdef DEBUG_NEW_FRIEND_LIST - std::cerr << " At index " << index.row() << ". data[1]=" << local_path.toStdString() ; + for(int i=0;ipeerTreeWidget->isExpanded(index)) { #ifdef DEBUG_NEW_FRIEND_LIST - std::cerr << " Index is expanded." ; + std::cerr << " expanded." << std::endl; #endif if(index.isValid()) exp.insert(local_path) ; for(int row=0;rowrowCount(index);++row) - recursSaveExpandedItems(index.child(row,0),current_index,local_path,exp,sel) ; + recursSaveExpandedItems(index.child(row,0),current_index,local_path,exp,sel,indx+1) ; } #ifdef DEBUG_NEW_FRIEND_LIST else - std::cerr << " not expanded." ; + std::cerr << " not expanded." << std::endl; #endif if(index == current_index) - { -#ifdef DEBUG_NEW_FRIEND_LIST - std::cerr << " adding to selection!" << std::endl; -#endif sel = local_path ; - } -#ifdef DEBUG_NEW_FRIEND_LIST - else - std::cerr << std::endl; -#endif - - } -void NewFriendList::recursRestoreExpandedItems(const QModelIndex& index, const QString& parent_path, const std::set& exp, const QString& sel,QModelIndex& selected_index) +void NewFriendList::recursRestoreExpandedItems(const QModelIndex& index, const QString& parent_path, const std::set& exp, const QString& sel,QModelIndex& selected_index,int indx) { - QString local_path = parent_path + index.sibling(index.row(),RsFriendListModel::COLUMN_THREAD_ID).data(Qt::DisplayRole).toString() + " "; + QString local_path = parent_path + (parent_path.isNull()?"":"/") + index.sibling(index.row(),RsFriendListModel::COLUMN_THREAD_ID).data(Qt::DisplayRole).toString() ; #ifdef DEBUG_NEW_FRIEND_LIST - std::cerr << " At index " << index.row() << ". data[1]=" << local_path.toStdString() ; + for(int i=0;ipeerTreeWidget->setExpanded(index,true) ; for(int row=0;rowrowCount(index);++row) - recursRestoreExpandedItems(index.child(row,0),local_path,exp,sel,selected_index) ; - } - - if(sel == local_path) - { -#ifdef DEBUG_NEW_FRIEND_LIST - std::cerr << " selecting index \"" << local_path.toStdString() << "\"" << std::endl; -#endif - ui->peerTreeWidget->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); - selected_index = index; + recursRestoreExpandedItems(index.child(row,0),local_path,exp,sel,selected_index,indx+1) ; } #ifdef DEBUG_NEW_FRIEND_LIST else std::cerr << std::endl; #endif - + if(sel == local_path) + { + ui->peerTreeWidget->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); + selected_index = index; + } } @@ -1126,7 +1119,10 @@ void NewFriendList::applyWhileKeepingTree(std::function predicate) saveExpandedPathsAndSelection(expanded_indexes, selected); #ifdef DEBUG_NEW_FRIEND_LIST - std::cerr << "After collecting selection, selected paths is: \"" << selected.toStdString() << "\"" << std::endl; + std::cerr << "After collecting selection, selected paths is: \"" << selected.toStdString() << "\", " ; + std::cerr << "expanded paths are: " << std::endl; + for(auto path:expanded_indexes) + std::cerr << " \"" << path.toStdString() << "\"" << std::endl; #endif whileBlocking(ui->peerTreeWidget)->clearSelection(); diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index 67ae9e651..cf2e892b3 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -106,8 +106,8 @@ private: void applyWhileKeepingTree(std::function predicate); void expandGroup(const RsNodeGroupId& gid); - void recursRestoreExpandedItems(const QModelIndex& index, const QString& parent_path, const std::set& exp, const QString &sel, QModelIndex &selected_index); - void recursSaveExpandedItems(const QModelIndex& index, const QModelIndex& current_index, const QString& parent_path, std::set& exp, QString &sel); + void recursRestoreExpandedItems(const QModelIndex& index, const QString& parent_path, const std::set& exp, const QString &sel, QModelIndex &selected_index,int indx); + void recursSaveExpandedItems(const QModelIndex& index, const QModelIndex& current_index, const QString& parent_path, std::set& exp, QString &sel,int indx); void saveExpandedPathsAndSelection(std::set& expanded_indexes, QString& sel); void restoreExpandedPathsAndSelection(const std::set& expanded_indexes, const QString &index_to_select, QModelIndex &selected_index);