From 44444207f79e1f98142ea85e3e7655f5755b2202 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 22 Aug 2020 20:23:42 +0200 Subject: [PATCH] save/restore hidden columns when switching which column is visible in FriendList --- retroshare-gui/src/gui/common/FriendListModel.cpp | 8 ++++---- retroshare-gui/src/gui/common/NewFriendList.cpp | 12 +++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index abd1c7450..39d4bbded 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -158,7 +158,7 @@ void RsFriendListModel::postMods() { endResetModel(); - emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-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 @@ -1236,7 +1236,7 @@ void RsFriendListModel::collapseItem(const QModelIndex& index) mExpandedProfiles.erase(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)); } void RsFriendListModel::expandItem(const QModelIndex& index) @@ -1258,10 +1258,10 @@ void RsFriendListModel::expandItem(const QModelIndex& index) if(hp) s += hp->profile_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 a388c9dea..501be9a3c 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -1096,7 +1096,13 @@ void NewFriendList::applyWhileKeepingTree(std::function predicate) saveExpandedPathsAndSelection(expanded_indexes, selected_indexes); // 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 soves them for good. + // due to a Qt bug, or a misuse of the proxy model on my side. Anyway, this solves them for good. + + // save hidden columns + std::list hidden_columns; + for(int i=0;ipeerTreeWidget->isColumnHidden(i)) + hidden_columns.push_back(i); mProxyModel->setSourceModel(nullptr); @@ -1104,6 +1110,10 @@ void NewFriendList::applyWhileKeepingTree(std::function predicate) mProxyModel->setSourceModel(mModel); restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes); + + // restore hidden columns + for(auto c: hidden_columns) + ui->peerTreeWidget->setColumnHidden(c,true); } void NewFriendList::checkInternalData(bool force)