From 0bda8eeb8d2e2cf0832b7a3ebd58b9081c9c6a22 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 23 Feb 2025 18:43:48 +0100 Subject: [PATCH] fixed save/restore of expanded items --- retroshare-gui/src/gui/Identity/IdDialog.cpp | 154 ++---------------- retroshare-gui/src/gui/Identity/IdDialog.h | 7 +- .../src/gui/Identity/IdentityListModel.cpp | 38 +---- 3 files changed, 28 insertions(+), 171 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 405ab9479..687f11f3d 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -440,7 +440,7 @@ IdDialog::IdDialog(QWidget *parent) connect(ui->treeWidget_membership, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CircleListCustomPopupMenu(QPoint))); connect(ui->autoBanIdentities_CB, SIGNAL(toggled(bool)), this, SLOT(toggleAutoBanIdentities(bool))); - updateIdTimer.setSingleShot(true); + updateIdTimer.setSingleShot(true); connect(&updateIdTimer, SIGNAL(timeout()), this, SLOT(updateIdList())); } @@ -1274,14 +1274,7 @@ IdDialog::~IdDialog() delete mProxyModel; delete(ui); } -void IdDialog::idListItemExpanded(const QModelIndex& index) -{ - mIdListModel->expandItem(mProxyModel->mapToSource(index)); -} -void IdDialog::idListItemCollapsed(const QModelIndex& index) -{ - mIdListModel->collapseItem(mProxyModel->mapToSource(index)); -} + static QString getHumanReadableDuration(uint32_t seconds) { if(seconds < 60) @@ -1372,7 +1365,13 @@ void IdDialog::updateIdList() std::cerr << "Updating identity list in widget: stack is:" << std::endl; //print_stacktrace(); - applyWhileKeepingTree( [this]() { mIdListModel->updateIdentityList(); }); + applyWhileKeepingTree( [this]() { + + mIdListModel->updateIdentityList(); + + } + + ); } #ifdef TO_REMOVE bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, const RsPgpId &ownPgpId, int accept) @@ -1506,114 +1505,6 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, return true; } -void IdDialog::loadIdentities(const std::map& ids_set_const) -{ - auto ids_set(ids_set_const); - - std::cerr << "Loading ID list" << std::endl; - - //First: Get current item to restore after - RsGxsGroupId oldCurrentId = mIdToNavigate; - { - QTreeWidgetItem *oldCurrent = ui->idTreeWidget->currentItem(); - if (oldCurrent) { - oldCurrentId = RsGxsGroupId(oldCurrent->text(RSID_COL_KEYID).toStdString()); - } - } - - //Save expanding - Settings->beginGroup("IdDialog"); - Settings->setValue("ExpandAll", allItem->isExpanded()); - Settings->setValue("ExpandContacts", contactsItem->isExpanded()); - Settings->setValue("ExpandOwn", ownItem->isExpanded()); - Settings->endGroup(); - - - int accept = filter; - - mStateHelper->setActive(IDDIALOG_IDLIST, true); - - RsPgpId ownPgpId = rsPeers->getGPGOwnId(); - - // Update existing and remove not existing items - // Also remove items that do not have the correct parent - - QTreeWidgetItemIterator itemIterator(ui->idTreeWidget); - QTreeWidgetItem *item = NULL; - - while ((item = *itemIterator) != NULL) - { - ++itemIterator; - auto it = ids_set.find(RsGxsGroupId(item->text(RSID_COL_KEYID).toStdString())) ; - - if(it == ids_set.end()) - { - if(item != allItem && item != contactsItem && item != ownItem) - delete(item); - - continue ; - } - - QTreeWidgetItem *parent_item = item->parent() ; - -// if(it->second.mMeta.mPublishTs > time(NULL) - 20 || it->second.mMeta.mGroupId == RsGxsGroupId("3de2172503675206b3a23c997e5ee688")) -// std::cerr << "Captured ID " <second.mMeta.mGroupId << std::endl; - - if( (parent_item == allItem && it->second.mIsAContact) || (parent_item == contactsItem && !it->second.mIsAContact)) - { - delete item ; // do not remove from the list, so that it is added again in the correct place. - continue ; - } - - if (!fillIdListItem(it->second, item, ownPgpId, accept)) - delete(item); - - ids_set.erase(it); // erase, so it is not considered to be a new item - } - - /* Insert new items */ - for (std::map::const_iterator vit = ids_set.begin(); vit != ids_set.end(); ++vit) - { - RsGxsIdGroup data = vit->second ; - - item = NULL; - - if (fillIdListItem(data, item, ownPgpId, accept)) - { - if(data.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) - ownItem->addChild(item); - else if(data.mIsAContact) - contactsItem->addChild(item); - else - allItem->addChild(item); - - } - } - - /* count items */ - int itemCount = contactsItem->childCount() + allItem->childCount() + ownItem->childCount(); - ui->label_count->setText( "(" + QString::number( itemCount ) + ")" ); - - int contactsCount = contactsItem->childCount() ; - int allCount = allItem->childCount() ; - int ownCount = ownItem->childCount(); - - contactsItem->setText(0, tr("My contacts") + ((contactsCount>0)?" (" + QString::number( contactsCount ) + ")":"") ); - allItem->setText(0, tr("All") + ((allCount>0)?" (" + QString::number( allCount ) + ")":"") ); - ownItem->setText(0, tr("My own identities") + ((ownCount>0)?" (" + QString::number( ownCount ) + ")":"") ); - - - //Restore expanding - Settings->beginGroup("IdDialog"); - allItem->setExpanded(Settings->value("ExpandAll", QVariant(true)).toBool()); - ownItem->setExpanded(Settings->value("ExpandOwn", QVariant(true)).toBool()); - contactsItem->setExpanded(Settings->value("ExpandContacts", QVariant(true)).toBool()); - Settings->endGroup(); - - navigate(RsGxsId(oldCurrentId)); - filterIds(); - updateSelection(); -} #endif void IdDialog::updateIdentity() @@ -2696,7 +2587,6 @@ void IdDialog::applyWhileKeepingTree(std::function predicate) std::set expanded,selected; saveExpandedPathsAndSelection_idTreeView(expanded, selected); - #ifdef DEBUG_NEW_FRIEND_LIST std::cerr << "After collecting selection, selected paths is: \"" << selected.toStdString() << "\", " ; std::cerr << "expanded paths are: " << std::endl; @@ -2704,7 +2594,6 @@ void IdDialog::applyWhileKeepingTree(std::function predicate) std::cerr << " \"" << path.toStdString() << "\"" << std::endl; std::cerr << "Current sort column is: " << mLastSortColumn << " and order is " << mLastSortOrder << std::endl; #endif - whileBlocking(ui->idTreeWidget)->clearSelection(); // 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. @@ -2720,16 +2609,17 @@ void IdDialog::applyWhileKeepingTree(std::function predicate) col_sizes[i] = ui->idTreeWidget->columnWidth(i); } +#ifdef SUSPENDED #ifdef DEBUG_NEW_FRIEND_LIST std::cerr << "Applying predicate..." << std::endl; #endif mProxyModel->setSourceModel(nullptr); - +#endif predicate(); - mProxyModel->setSourceModel(mIdListModel); restoreExpandedPathsAndSelection_idTreeView(expanded,selected); +// mProxyModel->setSourceModel(mIdListModel); // restore hidden columns for(uint32_t i=0;i predicate) ui->idTreeWidget->setColumnWidth(i,col_sizes[i]); } +#ifdef SUSPENDED // restore sorting // sortColumn(mLastSortColumn,mLastSortOrder); #ifdef DEBUG_NEW_FRIEND_LIST std::cerr << "Sorting again with sort column: " << mLastSortColumn << " and order " << mLastSortOrder << std::endl; #endif - mProxyModel->setSortingEnabled(true); +// mProxyModel->setSortingEnabled(true); // mProxyModel->sort(mLastSortColumn,mLastSortOrder); - mProxyModel->setSortingEnabled(false); +// mProxyModel->setSortingEnabled(false); // if(selected_index.isValid()) // ui->idTreeWidget->scrollTo(selected_index); +#endif } #define DEBUG_ID_DIALOG void IdDialog::saveExpandedPathsAndSelection_idTreeView(std::set& expanded, std::set& selected) { -// QModelIndexList selectedIndexes = ui->idTreeWidget->selectionModel()->selectedIndexes(); -// QModelIndex current_index = selectedIndexes.empty()?QModelIndex():(*selectedIndexes.begin()); - #ifdef DEBUG_ID_DIALOG std::cerr << "Saving expended paths and selection..." << std::endl; #endif @@ -2766,6 +2655,8 @@ void IdDialog::saveExpandedPathsAndSelection_idTreeView(std::set& e void IdDialog::restoreExpandedPathsAndSelection_idTreeView(const std::set& expanded, const std::set& selected) { + whileBlocking(ui->idTreeWidget)->clearSelection(); + ui->idTreeWidget->blockSignals(true) ; for(int row = 0; row < mProxyModel->rowCount(); ++row) @@ -2829,12 +2720,3 @@ void IdDialog::recursRestoreExpandedItems_idTreeView(const QModelIndex& index,co ui->idTreeWidget->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); } } -void IdDialog::trace_collapsed(const QModelIndex& i) -{ -std::cerr << "Collapsed " << i << std::endl; -} - -void IdDialog::trace_expanded(const QModelIndex& i) -{ -std::cerr << "Expanded " << i << std::endl; -} diff --git a/retroshare-gui/src/gui/Identity/IdDialog.h b/retroshare-gui/src/gui/Identity/IdDialog.h index dfb85a0bb..dcf9b14f9 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.h +++ b/retroshare-gui/src/gui/Identity/IdDialog.h @@ -69,10 +69,8 @@ protected: private slots: - void updateIdList(); + void updateIdList(); void updateCircles(); -void trace_expanded(const QModelIndex&); -void trace_collapsed(const QModelIndex& i); void createExternalCircle(); void showEditExistingCircle(); void updateCirclesDisplay(); @@ -159,9 +157,6 @@ private: RsGxsId getSelectedIdentity() const; std::list getSelectedIdentities() const; - void idListItemExpanded(const QModelIndex& index); - void idListItemCollapsed(const QModelIndex& index); - RsGxsGroupId mId; RsGxsGroupId mIdToNavigate; int filter; diff --git a/retroshare-gui/src/gui/Identity/IdentityListModel.cpp b/retroshare-gui/src/gui/Identity/IdentityListModel.cpp index 829dd7d73..ebf4fdd86 100644 --- a/retroshare-gui/src/gui/Identity/IdentityListModel.cpp +++ b/retroshare-gui/src/gui/Identity/IdentityListModel.cpp @@ -863,39 +863,19 @@ void RsIdentityListModel::updateIdentityList() { std::cerr << "Updating identity list" << std::endl; - RsThread::async([this]() + std::list ids ; + + if(!rsIdentity->getIdentitiesSummaries(ids)) { - // 1 - get message data from p3GxsForums - - std::list *ids = new std::list(); - - if(!rsIdentity->getIdentitiesSummaries(*ids)) - { - std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve identity metadata." << std::endl; - return; - } - - // 3 - update the model in the UI thread. - - RsQThreadUtils::postToObject( [ids,this]() - { - /* Here it goes any code you want to be executed on the Qt Gui - * thread, for example to update the data model with new information - * after a blocking call to RetroShare API complete, note that - * Qt::QueuedConnection is important! - */ - - setIdentities(*ids) ; - delete ids; - - //debug_dump(); - - }, this ); - - }); + std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve identity metadata." << std::endl; + return; + } + setIdentities(ids) ; } + + void RsIdentityListModel::collapseItem(const QModelIndex& index) { if(getType(index) != ENTRY_TYPE_CATEGORY)