preserve sorting strategy when updating posts

This commit is contained in:
csoler 2020-09-18 21:59:57 +02:00
parent 0e4d438066
commit a142694896
4 changed files with 19 additions and 15 deletions

View file

@ -260,6 +260,7 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI
mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW); mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW);
switchDisplayMode(); // makes everything consistent and chooses classic view as default switchDisplayMode(); // makes everything consistent and chooses classic view as default
updateSorting(ui->sortStrategy_CB->currentIndex());
mEventHandlerId = 0; mEventHandlerId = 0;
// Needs to be asynced because this function is called by another thread! // Needs to be asynced because this function is called by another thread!
@ -293,9 +294,9 @@ void PostedListWidgetWithModel::updateSorting(int s)
switch(s) switch(s)
{ {
default: default:
case 0: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_HOT_SCORE); break; case 0: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_NEW_SCORE); break;
case 1: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_NEW_SCORE); break; case 1: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_TOP_SCORE); break;
case 2: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_TOP_SCORE); break; case 2: mPostedPostsModel->setSortingStrategy(RsPostedPostsModel::SORT_HOT_SCORE); break;
} }
} }

View file

@ -351,7 +351,7 @@ p, li { white-space: pre-wrap; }
<string notr="true"/> <string notr="true"/>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -359,15 +359,6 @@ p, li { white-space: pre-wrap; }
<height>24</height> <height>24</height>
</size> </size>
</property> </property>
<item>
<property name="text">
<string>Hot</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/flame.png</normaloff>:/icons/png/flame.png</iconset>
</property>
</item>
<item> <item>
<property name="text"> <property name="text">
<string>New</string> <string>New</string>
@ -386,6 +377,15 @@ p, li { white-space: pre-wrap; }
<normaloff>:/icons/png/top.png</normaloff>:/icons/png/top.png</iconset> <normaloff>:/icons/png/top.png</normaloff>:/icons/png/top.png</iconset>
</property> </property>
</item> </item>
<item>
<property name="text">
<string>Hot</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/flame.png</normaloff>:/icons/png/flame.png</iconset>
</property>
</item>
</widget> </widget>
</item> </item>
<item> <item>

View file

@ -48,6 +48,8 @@ RsPostedPostsModel::RsPostedPostsModel(QObject *parent)
initEmptyHierarchy(); initEmptyHierarchy();
mEventHandlerId = 0; mEventHandlerId = 0;
mSortingStrategy = SORT_NEW_SCORE;
// Needs to be asynced because this function is called by another thread! // Needs to be asynced because this function is called by another thread!
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
@ -473,6 +475,7 @@ void RsPostedPostsModel::setSortingStrategy(RsPostedPostsModel::SortingStrategy
{ {
preMods(); preMods();
mSortingStrategy = s;
std::sort(mPosts.begin(),mPosts.end(), PostSorter(s)); std::sort(mPosts.begin(),mPosts.end(), PostSorter(s));
postMods(); postMods();
@ -517,7 +520,7 @@ void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPost
createPostsArray(posts); createPostsArray(posts);
std::sort(mPosts.begin(),mPosts.end(), PostSorter(SORT_NEW_SCORE)); std::sort(mPosts.begin(),mPosts.end(), PostSorter(mSortingStrategy));
uint32_t tmpval; uint32_t tmpval;
setFilter(QStringList(),tmpval); setFilter(QStringList(),tmpval);

View file

@ -245,7 +245,7 @@ private:
std::vector<int> mFilteredPosts; std::vector<int> mFilteredPosts;
uint32_t mDisplayedStartIndex; uint32_t mDisplayedStartIndex;
uint32_t mDisplayedNbPosts; uint32_t mDisplayedNbPosts;
SortingStrategy mSortingStrategy;
RsEventsHandlerId_t mEventHandlerId ; RsEventsHandlerId_t mEventHandlerId ;
}; };