diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index f10f0d55e..ed61cf4f5 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -1104,15 +1104,9 @@ Qt::ItemFlags RetroshareDirModel::flags( const QModelIndex & index ) const /* Callback from Core*/ void RetroshareDirModel::preMods() { - emit layoutAboutToBeChanged(); mUpdating = true ; -#if QT_VERSION < 0x050000 - reset(); -#else - beginResetModel(); - endResetModel(); -#endif + beginResetModel(); #ifdef RDM_DEBUG std::cerr << "RetroshareDirModel::preMods()" << std::endl; #endif @@ -1121,20 +1115,14 @@ void RetroshareDirModel::preMods() /* Callback from Core*/ void RetroshareDirModel::postMods() { -// emit layoutAboutToBeChanged(); mUpdating = false ; -#if QT_VERSION >= 0x040600 - beginResetModel(); -#endif - #ifdef RDM_DEBUG std::cerr << "RetroshareDirModel::postMods()" << std::endl; #endif -#if QT_VERSION >= 0x040600 endResetModel(); -#endif - emit layoutChanged(); + + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,COLUMN_COUNT-1,(void*)NULL)); } void FlatStyle_RDM::postMods() diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index 74d5d8746..39d4bbded 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -152,15 +152,13 @@ void RsFriendListModel::setDisplayGroups(bool b) } void RsFriendListModel::preMods() { - emit layoutAboutToBeChanged(); - beginResetModel(); } void RsFriendListModel::postMods() { endResetModel(); - emit layoutChanged(); - emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); + + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,columnCount()-1,(void*)NULL)); } int RsFriendListModel::rowCount(const QModelIndex& parent) const @@ -1060,14 +1058,16 @@ void RsFriendListModel::updateInternalData() preMods(); beginRemoveRows(QModelIndex(),0,mTopLevel.size()-1); - endRemoveRows(); mGroups.clear(); mProfiles.clear(); mLocations.clear(); - mTopLevel.clear(); + endRemoveRows(); + + auto TL = mTopLevel ; // This allows to fill TL without touching mTopLevel outside of [begin/end]InsertRows(). + // create a map of profiles and groups std::map pgp_indices; @@ -1155,7 +1155,6 @@ void RsFriendListModel::updateInternalData() RsDbg() << "Creating top level list" << std::endl; #endif - mTopLevel.clear(); std::set already_in_a_group; if(mDisplayGroups) // in this case, we list all groups at the top level followed by the profiles without parent group @@ -1170,7 +1169,7 @@ void RsFriendListModel::updateInternalData() e.type = ENTRY_TYPE_GROUP; e.group_index = i; - mTopLevel.push_back(e); + TL.push_back(e); for(uint32_t j=0;jprofile_info.gpg_id.toStdString(); if(!s.empty()) - mExpandedProfiles.insert(s); + mExpandedProfiles.insert(s); // apparently we cannot be subtle here. - emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,columnCount()-1,(void*)NULL)); } bool RsFriendListModel::isProfileExpanded(const EntryIndex& e) const diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 2dd216383..8b6f982bb 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -454,6 +454,7 @@ void NewFriendList::processSettings(bool load) if (load) // load settings { + std::cerr <<"Re-loading settings..." << std::endl; // states setShowUnconnected(!Settings->value("hideUnconnected", !mProxyModel->showOfflineNodes()).toBool()); setShowState(Settings->value("showState", mModel->getDisplayStatusString()).toBool()); @@ -1088,16 +1089,46 @@ void NewFriendList::removeGroup() checkInternalData(true); } -void NewFriendList::checkInternalData(bool force) +void NewFriendList::applyWhileKeepingTree(std::function predicate) { std::set expanded_indexes; - std::set selected_indexes; + std::set selected_indexes; - saveExpandedPathsAndSelection(expanded_indexes, selected_indexes); + saveExpandedPathsAndSelection(expanded_indexes, selected_indexes); - mModel->checkInternalData(force); + // This is a hack to avoid crashes on windows while calling endInsertRows(). I'm not sure wether these crashes are + // due to a Qt bug, or a misuse of the proxy model on my side. Anyway, this solves them for good. + // As a side effect we need to save/restore hidden columns because setSourceModel() resets this setting. - restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes); + // save hidden columns and sizes + std::vector col_visible(RsFriendListModel::COLUMN_THREAD_NB_COLUMNS); + std::vector col_sizes(RsFriendListModel::COLUMN_THREAD_NB_COLUMNS); + + for(int i=0;ipeerTreeWidget->isColumnHidden(i); + col_sizes[i] = ui->peerTreeWidget->columnWidth(i); + } + + + mProxyModel->setSourceModel(nullptr); + + predicate(); + + mProxyModel->setSourceModel(mModel); + restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes); + + // restore hidden columns + for(uint32_t i=0;ipeerTreeWidget->setColumnHidden(i,!col_visible[i]); + ui->peerTreeWidget->setColumnWidth(i,col_sizes[i]); + } +} + +void NewFriendList::checkInternalData(bool force) +{ + applyWhileKeepingTree([force,this]() { mModel->checkInternalData(force) ; }); } void NewFriendList::exportFriendlistClicked() @@ -1485,6 +1516,7 @@ bool NewFriendList::isColumnVisible(int col) const } void NewFriendList::setColumnVisible(int col,bool visible) { + std::cerr << "Setting column " << col << " to be visible: " << visible << std::endl; ui->peerTreeWidget->setColumnHidden(col, !visible); } void NewFriendList::toggleColumnVisible() @@ -1502,12 +1534,12 @@ void NewFriendList::toggleColumnVisible() void NewFriendList::setShowState(bool show) { - mModel->setDisplayStatusString(show); + applyWhileKeepingTree([show,this]() { mModel->setDisplayStatusString(show) ; }); } void NewFriendList::setShowGroups(bool show) { - mModel->setDisplayGroups(show); + applyWhileKeepingTree([show,this]() { mModel->setDisplayGroups(show) ; }); } /** diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index 4bdeddd4b..7387a477e 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -103,7 +103,9 @@ private: RsFriendListModel *mModel; QAction *mActionSortByState; - void expandGroup(const RsNodeGroupId& gid); + void applyWhileKeepingTree(std::function predicate); + + void expandGroup(const RsNodeGroupId& gid); void recursRestoreExpandedItems(const QModelIndex& index, const QString& parent_path, const std::set& exp, const std::set &sel); void recursSaveExpandedItems(const QModelIndex& index,const QString& parent_path,std::set& exp, std::set& sel); void saveExpandedPathsAndSelection(std::set& expanded_indexes, std::set& selected_indexes);