mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 07:59:29 -05:00
fixed sorting
This commit is contained in:
parent
6e3405d981
commit
1fced473d8
@ -116,6 +116,7 @@ protected:
|
||||
virtual void setAllMessagesReadDo(bool read, uint32_t &token) override;
|
||||
|
||||
private slots:
|
||||
void updateSorting(int);
|
||||
void updateGroupData();
|
||||
void createMsg();
|
||||
void subscribeGroup(bool subscribe);
|
||||
|
@ -343,7 +343,7 @@ p, li { white-space: pre-wrap; }
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<widget class="QComboBox" name="sortStrategy_CB">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p><span style=" 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;">Select sorting</span></p></body></html></string>
|
||||
</property>
|
||||
|
@ -420,10 +420,26 @@ void RsPostedPostsModel::clear()
|
||||
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
|
||||
{
|
||||
@ -433,6 +449,15 @@ Qt::ItemFlags RsPostedPostsModel::flags(const QModelIndex& index) const
|
||||
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)
|
||||
{
|
||||
preMods();
|
||||
@ -445,7 +470,7 @@ void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPost
|
||||
|
||||
createPostsArray(posts);
|
||||
|
||||
std::sort(mPosts.begin(),mPosts.end());
|
||||
std::sort(mPosts.begin(),mPosts.end(), PostSorter(RsPostedPostsModel::SORT_NEW_SCORE));
|
||||
|
||||
mFilteredPosts.clear();
|
||||
for(int i=0;i<mPosts.size();++i)
|
||||
|
@ -68,6 +68,13 @@ public:
|
||||
|
||||
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 {
|
||||
COLUMN_POSTS =0x00,
|
||||
COLUMN_THREAD_MSGID =0x01,
|
||||
@ -110,6 +117,7 @@ public:
|
||||
|
||||
void setMsgReadStatus(const QModelIndex &i, bool read_status, bool with_children);
|
||||
void setFilter(const QStringList &strings, uint32_t &count) ;
|
||||
void setSortingStrategy(SortingStrategy s);
|
||||
|
||||
#ifdef TODO
|
||||
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
||||
|
Loading…
Reference in New Issue
Block a user