From c9d5a9ba30b2ef68815f8931c22f8cf33eaf2c39 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 31 Mar 2025 22:09:55 +0200 Subject: [PATCH] fixed preserving of selection and expanded items --- retroshare-gui/src/gui/Identity/IdDialog.cpp | 39 ++++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 56958e932..d0c81c211 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -1359,16 +1359,20 @@ void IdDialog::filterToggled(const bool &value) } } -void IdDialog::updateSelection(const QItemSelection& new_sel,const QItemSelection& old_sel) +void IdDialog::updateSelection(const QItemSelection& /* new_sel */,const QItemSelection& /* old_sel */) { +#ifdef DEBUG_ID_DIALOG std::cerr << "Got selectionChanged signal. Old selection is: " << std::endl; for(auto i:old_sel.indexes()) std::cerr << " " << i << std::endl; std::cerr << "Got selectionChanged signal. New selection is: " << std::endl; for(auto i:new_sel.indexes()) std::cerr << " " << i << std::endl; +#endif auto id = RsGxsGroupId(getSelectedIdentity()); +#ifdef DEBUG_ID_DIALOG std::cerr << "updating selection to id " << id << std::endl; +#endif if(id != mId) { mId = id; @@ -1393,7 +1397,6 @@ void IdDialog::updateIdListRequest() void IdDialog::updateIdList() { - std::cerr << "Updating identity list in widget." << std::endl; //print_stacktrace(); RsThread::async([this]() @@ -1409,8 +1412,10 @@ void IdDialog::updateIdList() RsQThreadUtils::postToObject( [ids,this]() { + std::cerr << "Updating identity list in widget." << std::endl; applyWhileKeepingTree( [ids,this]() { + std::cerr << "setting new identity in model." << std::endl; mIdListModel->setIdentities(*ids) ; delete ids; @@ -1595,9 +1600,6 @@ void IdDialog::updateIdentity() * thread, for example to update the data model with new information * after a blocking call to RetroShare API complete */ - std::set expanded_indexes; - std::set > selected_indices; - loadIdentity(group); }, this ); @@ -2039,7 +2041,9 @@ std::list IdDialog::getSelectedIdentities() const QModelIndexList selectedIndexes_proxy = ui->idTreeWidget->selectionModel()->selectedIndexes(); std::list res; +#ifdef DEBUG_ID_DIALOG std::cerr << "Parsing selected index list: " << std::endl; +#endif for(auto indx_proxy:selectedIndexes_proxy) { RsGxsId id; @@ -2049,7 +2053,9 @@ std::list IdDialog::getSelectedIdentities() const auto indx = mProxyModel->mapToSource(indx_proxy); auto id = mIdListModel->getIdentity(indx); +#ifdef DEBUG_ID_DIALOG std::cerr << " indx: " << indx_proxy << " original indx: " << indx << " identity: " << id << std::endl; +#endif if( !id.isNull() ) res.push_back(id); @@ -2063,7 +2069,9 @@ RsGxsId IdDialog::getSelectedIdentity() const { auto lst = getSelectedIdentities(); +#ifdef DEBUG_ID_DIALOG std::cerr << "Selected identities has size " << lst.size() << std::endl; +#endif if(lst.size() != 1) return RsGxsId(); @@ -2584,7 +2592,7 @@ void IdDialog::applyWhileKeepingTree(std::function predicate) #ifdef DEBUG_NEW_FRIEND_LIST std::cerr << "After collecting selection, selected paths is: \"" << selected.toStdString() << "\", " ; std::cerr << "expanded paths are: " << std::endl; - for(auto path:expanded_indexes) + for(auto path:expanded) std::cerr << " \"" << path.toStdString() << "\"" << std::endl; std::cerr << "Current sort column is: " << mLastSortColumn << " and order is " << mLastSortOrder << std::endl; #endif @@ -2609,12 +2617,10 @@ void IdDialog::applyWhileKeepingTree(std::function predicate) #endif #endif mProxyModel->setSourceModel(nullptr); - predicate(); + mProxyModel->setSourceModel(mIdListModel); restoreExpandedPathsAndSelection_idTreeView(expanded,selected); - - mProxyModel->setSourceModel(mIdListModel); // restore hidden columns for(uint32_t i=0;i& e void IdDialog::restoreExpandedPathsAndSelection_idTreeView(const std::set& expanded, const std::set& selected) { +#ifdef DEBUG_ID_DIALOG + std::cerr << "Restoring expanded paths and selection..." << std::endl; + std::cerr << " expanded: " << expanded.size() << " items" << std::endl; + std::cerr << " selected: " << selected.size() << " items" << std::endl; +#endif ui->idTreeWidget->blockSignals(true) ; ui->idTreeWidget->selectionModel()->blockSignals(true) ; @@ -2682,7 +2693,7 @@ void IdDialog::recursSaveExpandedItems_idTreeView(const QModelIndex& proxy_index if(ui->idTreeWidget->selectionModel()->isSelected(proxy_index)) { -#ifndef DEBUG_ID_DIALOG +#ifdef DEBUG_ID_DIALOG std::cerr << "Adding selected path "; for(auto L:local_path) std::cerr << "\"" << L.toStdString() << "\" " ; std::cerr << std::endl; #endif @@ -2695,6 +2706,10 @@ void IdDialog::recursRestoreExpandedItems_idTreeView(const QModelIndex& proxy_in QStringList local_path = parent_path; local_path.push_back(mIdListModel->indexIdentifier(mProxyModel->mapToSource(proxy_index))); +#ifdef DEBUG_ID_DIALOG + std::cerr << "Local path = " ; for(auto L:local_path) std::cerr << "\"" << L.toStdString() << "\" " ; std::cerr << std::endl; +#endif + if(expanded.find(local_path) != expanded.end()) { #ifdef DEBUG_ID_DIALOG @@ -2710,11 +2725,11 @@ void IdDialog::recursRestoreExpandedItems_idTreeView(const QModelIndex& proxy_in if(selected.find(local_path) != selected.end()) { -#ifndef DEBUG_ID_DIALOG +#ifdef DEBUG_ID_DIALOG std::cerr << "Restoring selected path "; for(auto L:local_path) std::cerr << "\"" << L.toStdString() << "\" " ; std::cerr << std::endl; #endif - ui->idTreeWidget->selectionModel()->select(proxy_index, QItemSelectionModel::Select | QItemSelectionModel::Rows); + ui->idTreeWidget->selectionModel()->select(proxy_index, QItemSelectionModel::Current|QItemSelectionModel::Select | QItemSelectionModel::Rows); } }