From 756ded0b5d0086f362ea3e435a2e0d8b52a97364 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Feb 2025 20:39:13 +0100 Subject: [PATCH] fixed sorting --- retroshare-gui/src/gui/Identity/IdDialog.cpp | 32 ++++++++++++++--- retroshare-gui/src/gui/Identity/IdDialog.h | 6 +++- .../src/gui/Identity/IdentityListModel.cpp | 36 +++++-------------- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 687f11f3d..f35f3fb65 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -302,7 +302,8 @@ IdDialog::IdDialog(QWidget *parent) connect(ui->inviteButton, SIGNAL(clicked()), this, SLOT(sendInvite())); connect(ui->editButton, SIGNAL(clicked()), this, SLOT(editIdentity())); - connect( ui->idTreeWidget, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(chatIdentityItem(QModelIndex&)) ); + connect(ui->idTreeWidget, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(chatIdentityItem(QModelIndex&)) ); + connect(ui->idTreeWidget->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder))); ui->editButton->hide(); @@ -2627,21 +2628,20 @@ void IdDialog::applyWhileKeepingTree(std::function predicate) ui->idTreeWidget->setColumnWidth(i,col_sizes[i]); } + mProxyModel->setSortingEnabled(true); + mProxyModel->sort(mLastSortColumn,mLastSortOrder); + mProxyModel->setSortingEnabled(false); #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->sort(mLastSortColumn,mLastSortOrder); -// 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) { @@ -2720,3 +2720,25 @@ void IdDialog::recursRestoreExpandedItems_idTreeView(const QModelIndex& index,co ui->idTreeWidget->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); } } +void IdDialog::sortColumn(int col,Qt::SortOrder so) +{ +#ifdef DEBUG_NEW_FRIEND_LIST + std::cerr << "Sorting with column=" << col << " and order=" << so << std::endl; +#endif + std::set expanded_indexes,selected_indexes; + + saveExpandedPathsAndSelection_idTreeView(expanded_indexes, selected_indexes); + whileBlocking(ui->idTreeWidget)->clearSelection(); + + mProxyModel->setSortingEnabled(true); + mProxyModel->sort(col,so); + mProxyModel->setSortingEnabled(false); + + restoreExpandedPathsAndSelection_idTreeView(expanded_indexes,selected_indexes); + + //if(selected_index.isValid()) + // ui->peerTreeWidget->scrollTo(selected_index); + + mLastSortColumn = col; + mLastSortOrder = so; +} diff --git a/retroshare-gui/src/gui/Identity/IdDialog.h b/retroshare-gui/src/gui/Identity/IdDialog.h index dcf9b14f9..811e4424f 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.h +++ b/retroshare-gui/src/gui/Identity/IdDialog.h @@ -75,6 +75,7 @@ private slots: void showEditExistingCircle(); void updateCirclesDisplay(); void toggleAutoBanIdentities(bool b); + void sortColumn(int col,Qt::SortOrder so); void acceptCircleSubscription() ; void cancelCircleSubscription() ; @@ -149,7 +150,10 @@ private: QTreeWidgetItem *mMyCircleItem; RsGxsUpdateBroadcastBase *mCirclesBroadcastBase ; - void saveExpandedCircleItems(std::vector &expanded_root_items, std::set& expanded_circle_items) const; + int mLastSortColumn; + Qt::SortOrder mLastSortOrder; + + void saveExpandedCircleItems(std::vector &expanded_root_items, std::set& expanded_circle_items) const; void restoreExpandedCircleItems(const std::vector& expanded_root_items,const std::set& expanded_circle_items); void applyWhileKeepingTree(std::function predicate); diff --git a/retroshare-gui/src/gui/Identity/IdentityListModel.cpp b/retroshare-gui/src/gui/Identity/IdentityListModel.cpp index ebf4fdd86..2a1cd193f 100644 --- a/retroshare-gui/src/gui/Identity/IdentityListModel.cpp +++ b/retroshare-gui/src/gui/Identity/IdentityListModel.cpp @@ -495,34 +495,13 @@ QVariant RsIdentityListModel::sortRole(const EntryIndex& entry,int column) const { switch(column) { -#warning TODO -// case COLUMN_THREAD_LAST_CONTACT: -// { -// switch(entry.type) -// { -// case ENTRY_TYPE_PROFILE: -// { -// const HierarchicalProfileInformation *prof = getProfileInfo(entry); -// -// if(!prof) -// return QVariant(); -// -// uint32_t last_contact = 0; -// -// for(uint32_t i=0;ichild_node_indices.size();++i) -// last_contact = std::max(last_contact, mLocations[prof->child_node_indices[i]].node_info.lastConnect); -// -// return QVariant(last_contact); -// } -// break; -// default: -// return QVariant(); -// } -// } -// break; + case COLUMN_THREAD_REPUTATION: return decorationRole(entry,column); + case COLUMN_THREAD_ID: + case COLUMN_THREAD_OWNER: + case COLUMN_THREAD_NAME: [[__fallthrough__]]; default: - return displayRole(entry,column); + return displayRole(entry,column); } } @@ -653,7 +632,10 @@ QVariant RsIdentityListModel::displayRole(const EntryIndex& e, int col) const { case COLUMN_THREAD_NAME: return QVariant(QString::fromUtf8(det.mNickname.c_str())); case COLUMN_THREAD_ID: return QVariant(QString::fromStdString(det.mId.toStdString()) ); - case COLUMN_THREAD_OWNER: return QVariant(QString::fromStdString(det.mPgpId.toStdString()) ); + case COLUMN_THREAD_OWNER: if(det.mPgpId.isNull()) + return QVariant(); + else + return QVariant(QString::fromStdString(det.mPgpId.toStdString()) ); default: return QVariant(); }