fixed sorting

This commit is contained in:
csoler 2020-07-12 15:22:31 +02:00
parent 6e3405d981
commit 1fced473d8
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 39 additions and 5 deletions

View File

@ -116,6 +116,7 @@ protected:
virtual void setAllMessagesReadDo(bool read, uint32_t &token) override; virtual void setAllMessagesReadDo(bool read, uint32_t &token) override;
private slots: private slots:
void updateSorting(int);
void updateGroupData(); void updateGroupData();
void createMsg(); void createMsg();
void subscribeGroup(bool subscribe); void subscribeGroup(bool subscribe);

View File

@ -343,7 +343,7 @@ p, li { white-space: pre-wrap; }
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox"> <widget class="QComboBox" name="sortStrategy_CB">
<property name="toolTip"> <property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-family:'-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:14px; color:#24292e; background-color:#ffffff;&quot;&gt;Select sorting&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-family:'-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:14px; color:#24292e; background-color:#ffffff;&quot;&gt;Select sorting&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>

View File

@ -420,10 +420,26 @@ void RsPostedPostsModel::clear()
emit boardPostsLoaded(); emit boardPostsLoaded();
} }
bool operator<(const RsPostedPost& p1,const RsPostedPost& p2) class PostSorter
{ {
return p1.mMeta.mPublishTs > p2.mMeta.mPublishTs; public:
}
PostSorter(RsPostedPostsModel::SortingStrategy s) : mSortingStrategy(s) {}
bool operator()(const RsPostedPost& p1,const RsPostedPost& p2) const
{
switch(mSortingStrategy)
{
default:
case RsPostedPostsModel::SORT_NEW_SCORE : return p1.mNewScore > p2.mNewScore;
case RsPostedPostsModel::SORT_TOP_SCORE : return p1.mTopScore > p2.mTopScore;
case RsPostedPostsModel::SORT_HOT_SCORE : return p1.mHotScore > p2.mHotScore;
}
}
private:
RsPostedPostsModel::SortingStrategy mSortingStrategy;
};
Qt::ItemFlags RsPostedPostsModel::flags(const QModelIndex& index) const Qt::ItemFlags RsPostedPostsModel::flags(const QModelIndex& index) const
{ {
@ -433,6 +449,15 @@ Qt::ItemFlags RsPostedPostsModel::flags(const QModelIndex& index) const
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
} }
void RsPostedPostsModel::setSortingStrategy(RsPostedPostsModel::SortingStrategy s)
{
preMods();
std::sort(mPosts.begin(),mPosts.end(), PostSorter(s));
postMods();
}
void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPostedPost>& posts) void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPostedPost>& posts)
{ {
preMods(); preMods();
@ -445,7 +470,7 @@ void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPost
createPostsArray(posts); createPostsArray(posts);
std::sort(mPosts.begin(),mPosts.end()); std::sort(mPosts.begin(),mPosts.end(), PostSorter(RsPostedPostsModel::SORT_NEW_SCORE));
mFilteredPosts.clear(); mFilteredPosts.clear();
for(int i=0;i<mPosts.size();++i) for(int i=0;i<mPosts.size();++i)

View File

@ -68,6 +68,13 @@ public:
static const int COLUMN_THREAD_NB_COLUMNS = 0x01; static const int COLUMN_THREAD_NB_COLUMNS = 0x01;
enum SortingStrategy {
SORT_UNKNOWN = 0x00,
SORT_NEW_SCORE = 0x01,
SORT_TOP_SCORE = 0x02,
SORT_HOT_SCORE = 0x03
};
enum Columns { enum Columns {
COLUMN_POSTS =0x00, COLUMN_POSTS =0x00,
COLUMN_THREAD_MSGID =0x01, COLUMN_THREAD_MSGID =0x01,
@ -110,6 +117,7 @@ public:
void setMsgReadStatus(const QModelIndex &i, bool read_status, bool with_children); void setMsgReadStatus(const QModelIndex &i, bool read_status, bool with_children);
void setFilter(const QStringList &strings, uint32_t &count) ; void setFilter(const QStringList &strings, uint32_t &count) ;
void setSortingStrategy(SortingStrategy s);
#ifdef TODO #ifdef TODO
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op); void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);