From 91321725e666d2bb4cbb4fc6e631713cda6b0550 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 2 Dec 2018 16:34:43 +0100 Subject: [PATCH] added sorting based on most recent TS from children --- .../src/gui/gxsforums/GxsForumModel.cpp | 31 ++++++++++++++++--- .../src/gui/gxsforums/GxsForumModel.h | 13 ++++++-- .../gui/gxsforums/GxsForumThreadWidget.cpp | 17 +++++----- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp index abf2a15f2..adadbf5bf 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp @@ -42,6 +42,16 @@ void RsGxsForumModel::setTreeMode(TreeMode mode) emit layoutChanged(); } +void RsGxsForumModel::setSortMode(SortMode mode) +{ + emit layoutAboutToBeChanged(); + + mSortMode = mode; + + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); + emit layoutChanged(); +} + void RsGxsForumModel::initEmptyHierarchy(std::vector& posts) { emit layoutAboutToBeChanged(); @@ -552,7 +562,11 @@ QVariant RsGxsForumModel::sortRole(const ForumModelPostEntry& fmpe,int column) c { switch(column) { - case COLUMN_THREAD_DATE: return QVariant(QString::number(fmpe.mPublishTs)); // we should probably have leading zeroes here + case COLUMN_THREAD_DATE: if(mSortMode == SORT_MODE_PUBLISH_TS) + return QVariant(QString::number(fmpe.mPublishTs)); // we should probably have leading zeroes here + else + return QVariant(QString::number(fmpe.mMostRecentTsInThread)); // 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: @@ -657,8 +671,10 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector& messages); - void recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below); - void recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children); + void recursUpdateReadStatusAndTimes(ForumModelIndex i,bool& has_unread_below,bool& has_read_below); uint32_t recursUpdateFilterStatus(ForumModelIndex i,int column,const QStringList& strings); + void recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children); static void generateMissingItem(const RsGxsMessageId &msgId,ForumModelPostEntry& entry); static ForumModelIndex addEntry(std::vector& posts,const ForumModelPostEntry& entry,ForumModelIndex parent); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 817dccdf7..dae56098f 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -2655,16 +2655,15 @@ void GxsForumThreadWidget::changedViewBox() // save index Settings->setValueToGroup("ForumThreadWidget", "viewBox", ui->viewBox->currentIndex()); - switch(ui->viewBox->currentIndex()) - { - default: - case VIEW_THREADED: - case VIEW_LAST_POST: mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_TREE); - break; + if(ui->viewBox->currentIndex() == VIEW_FLAT) + mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_FLAT); + else + mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_TREE); - case VIEW_FLAT: mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_FLAT); - break; - } + if(ui->viewBox->currentIndex() == VIEW_LAST_POST) + mThreadModel->setSortMode(RsGxsForumModel::SORT_MODE_CHILDREN_PUBLISH_TS); + else + mThreadModel->setSortMode(RsGxsForumModel::SORT_MODE_PUBLISH_TS); } void GxsForumThreadWidget::filterColumnChanged(int column)