From f56e932fb7fac7d33a5b5a9a62c7d372c0298989 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 30 Nov 2018 17:24:43 +0100 Subject: [PATCH] fixed sorting problem in new model due to missing call to sortRole() --- retroshare-gui/src/gui/gxs/GxsIdDetails.h | 1 + .../src/gui/gxsforums/GxsForumModel.cpp | 19 ++++++++++++++++--- .../gui/gxsforums/GxsForumThreadWidget.cpp | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.h b/retroshare-gui/src/gui/gxs/GxsIdDetails.h index 30edffd7e..8c6c8edac 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.h +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.h @@ -63,6 +63,7 @@ class GxsIdDetails : public QObject Q_OBJECT public: + static const int ICON_TYPE_NONE = 0x0000 ; static const int ICON_TYPE_AVATAR = 0x0001 ; static const int ICON_TYPE_PGP = 0x0002 ; static const int ICON_TYPE_RECOGN = 0x0004 ; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp index 6f9b0fa75..825cc02d4 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp @@ -310,6 +310,7 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const case ThreadPinnedRole: return pinnedRole (fmpe,index.column()) ; case MissingRole: return missingRole (fmpe,index.column()) ; case StatusRole: return statusRole (fmpe,index.column()) ; + case SortRole: return sortRole (fmpe,index.column()) ; default: return QVariant(); } @@ -424,10 +425,22 @@ QVariant RsGxsForumModel::authorRole(const ForumModelPostEntry& fmpe,int column) QVariant RsGxsForumModel::sortRole(const ForumModelPostEntry& fmpe,int column) const { - if(column == COLUMN_THREAD_DATA) - return QVariant(QString::number(fmpe.mPublishTs)); // we should probably have leading zeroes here + switch(column) + { + case COLUMN_THREAD_DATE: return QVariant(QString::number(fmpe.mPublishTs)); // we should probably have leading zeroes here + case COLUMN_THREAD_READ: return QVariant((bool)IS_MSG_UNREAD(fmpe.mMsgStatus)); + case COLUMN_THREAD_DISTRIBUTION: return decorationRole(fmpe,column); + case COLUMN_THREAD_AUTHOR: + { + QString str,comment ; + QList icons; + GxsIdDetails::MakeIdDesc(fmpe.mAuthorId, false, str, icons, comment,GxsIdDetails::ICON_TYPE_NONE); - return QVariant(); + return QVariant(str); + } + default: + return displayRole(fmpe,column); + } } QVariant RsGxsForumModel::displayRole(const ForumModelPostEntry& fmpe,int col) const diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 0f53abf47..a5a16caed 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -372,6 +372,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget mThreadModel = new RsGxsForumModel(this); mThreadProxyModel = new ForumPostSortFilterProxyModel(ui->threadTreeWidget->header(),this); mThreadProxyModel->setSourceModel(mThreadModel); + mThreadProxyModel->setSortRole(RsGxsForumModel::SortRole); ui->threadTreeWidget->setModel(mThreadProxyModel); ui->threadTreeWidget->setSortingEnabled(true); @@ -381,6 +382,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget ui->threadTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_AUTHOR,new AuthorItemDelegate()) ; ui->threadTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_READ,new ReadStatusItemDelegate()) ; + ui->threadTreeWidget->header()->setSortIndicatorShown(true); connect(ui->threadTreeWidget->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),this,SLOT(sortColumn(int,Qt::SortOrder))); connect(ui->versions_CB, SIGNAL(currentIndexChanged(int)), this, SLOT(changedVersion()));