From a14269489649c9d62f60a574305d63bcc06d6222 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 18 Sep 2020 21:59:57 +0200 Subject: [PATCH] preserve sorting strategy when updating posts --- .../gui/Posted/PostedListWidgetWithModel.cpp | 7 ++++--- .../gui/Posted/PostedListWidgetWithModel.ui | 20 +++++++++---------- .../src/gui/Posted/PostedPostsModel.cpp | 5 ++++- .../src/gui/Posted/PostedPostsModel.h | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index 1e2c648b6..08295926d 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -260,6 +260,7 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW); switchDisplayMode(); // makes everything consistent and chooses classic view as default + updateSorting(ui->sortStrategy_CB->currentIndex()); mEventHandlerId = 0; // Needs to be asynced because this function is called by another thread! @@ -293,9 +294,9 @@ void PostedListWidgetWithModel::updateSorting(int s) switch(s) { default: - case 0: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_HOT_SCORE); break; - case 1: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_NEW_SCORE); break; - case 2: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_TOP_SCORE); break; + case 0: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_NEW_SCORE); break; + case 1: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_TOP_SCORE); break; + case 2: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_HOT_SCORE); break; } } diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui index 12601ee74..2c866ac4b 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui @@ -351,7 +351,7 @@ p, li { white-space: pre-wrap; } - 1 + 0 @@ -359,15 +359,6 @@ p, li { white-space: pre-wrap; } 24 - - - Hot - - - - :/icons/png/flame.png:/icons/png/flame.png - - New @@ -386,6 +377,15 @@ p, li { white-space: pre-wrap; } :/icons/png/top.png:/icons/png/top.png + + + Hot + + + + :/icons/png/flame.png:/icons/png/flame.png + + diff --git a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp index 94eea0ae1..43f87e6ab 100644 --- a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp @@ -48,6 +48,8 @@ RsPostedPostsModel::RsPostedPostsModel(QObject *parent) initEmptyHierarchy(); mEventHandlerId = 0; + mSortingStrategy = SORT_NEW_SCORE; + // Needs to be asynced because this function is called by another thread! rsEvents->registerEventsHandler( [this](std::shared_ptr event) @@ -473,6 +475,7 @@ void RsPostedPostsModel::setSortingStrategy(RsPostedPostsModel::SortingStrategy { preMods(); + mSortingStrategy = s; std::sort(mPosts.begin(),mPosts.end(), PostSorter(s)); postMods(); @@ -517,7 +520,7 @@ void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector mFilteredPosts; uint32_t mDisplayedStartIndex; uint32_t mDisplayedNbPosts; - + SortingStrategy mSortingStrategy; RsEventsHandlerId_t mEventHandlerId ; };