mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 09:11:28 -05:00
added display of 10-posts chunks
This commit is contained in:
parent
1fced473d8
commit
6e07ead572
@ -38,6 +38,8 @@
|
|||||||
Q_DECLARE_METATYPE(RsMsgMetaData)
|
Q_DECLARE_METATYPE(RsMsgMetaData)
|
||||||
Q_DECLARE_METATYPE(RsPostedPost)
|
Q_DECLARE_METATYPE(RsPostedPost)
|
||||||
|
|
||||||
|
const uint32_t RsPostedPostsModel::DEFAULT_DISPLAYED_NB_POSTS = 10;
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere
|
std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere
|
||||||
|
|
||||||
RsPostedPostsModel::RsPostedPostsModel(QObject *parent)
|
RsPostedPostsModel::RsPostedPostsModel(QObject *parent)
|
||||||
@ -121,6 +123,8 @@ void RsPostedPostsModel::initEmptyHierarchy()
|
|||||||
|
|
||||||
mPosts.clear();
|
mPosts.clear();
|
||||||
mFilteredPosts.clear();
|
mFilteredPosts.clear();
|
||||||
|
mDisplayedNbPosts = DEFAULT_DISPLAYED_NB_POSTS;
|
||||||
|
mDisplayedStartIndex = 0;
|
||||||
|
|
||||||
postMods();
|
postMods();
|
||||||
}
|
}
|
||||||
@ -167,6 +171,9 @@ void RsPostedPostsModel::setFilter(const QStringList& strings, uint32_t& count)
|
|||||||
}
|
}
|
||||||
count = mFilteredPosts.size();
|
count = mFilteredPosts.size();
|
||||||
|
|
||||||
|
if(mDisplayedNbPosts > count)
|
||||||
|
mDisplayedNbPosts = count;
|
||||||
|
|
||||||
std::cerr << "After filtering: " << count << " posts remain." << std::endl;
|
std::cerr << "After filtering: " << count << " posts remain." << std::endl;
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(),0,rowCount()-1);
|
beginInsertRows(QModelIndex(),0,rowCount()-1);
|
||||||
@ -184,7 +191,7 @@ int RsPostedPostsModel::rowCount(const QModelIndex& parent) const
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(!parent.isValid())
|
if(!parent.isValid())
|
||||||
return mFilteredPosts.size() ;
|
return mDisplayedNbPosts;
|
||||||
|
|
||||||
RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl;
|
RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
@ -413,7 +420,6 @@ void RsPostedPostsModel::clear()
|
|||||||
{
|
{
|
||||||
preMods();
|
preMods();
|
||||||
|
|
||||||
mPosts.clear();
|
|
||||||
initEmptyHierarchy();
|
initEmptyHierarchy();
|
||||||
|
|
||||||
postMods();
|
postMods();
|
||||||
@ -458,6 +464,27 @@ void RsPostedPostsModel::setSortingStrategy(RsPostedPostsModel::SortingStrategy
|
|||||||
postMods();
|
postMods();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsPostedPostsModel::setPostsInterval(int start,int nb_posts)
|
||||||
|
{
|
||||||
|
if(start >= mFilteredPosts.size())
|
||||||
|
return;
|
||||||
|
|
||||||
|
preMods();
|
||||||
|
|
||||||
|
uint32_t old_nb_rows = rowCount() ;
|
||||||
|
|
||||||
|
mDisplayedNbPosts = (uint32_t)std::min(nb_posts,(int)mFilteredPosts.size() - (start+1));
|
||||||
|
mDisplayedStartIndex = start;
|
||||||
|
|
||||||
|
beginRemoveRows(QModelIndex(),mDisplayedNbPosts,old_nb_rows);
|
||||||
|
endRemoveRows();
|
||||||
|
|
||||||
|
beginInsertRows(QModelIndex(),old_nb_rows,mDisplayedNbPosts);
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
postMods();
|
||||||
|
}
|
||||||
|
|
||||||
void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPostedPost>& posts)
|
void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPostedPost>& posts)
|
||||||
{
|
{
|
||||||
preMods();
|
preMods();
|
||||||
@ -470,11 +497,13 @@ void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPost
|
|||||||
|
|
||||||
createPostsArray(posts);
|
createPostsArray(posts);
|
||||||
|
|
||||||
std::sort(mPosts.begin(),mPosts.end(), PostSorter(RsPostedPostsModel::SORT_NEW_SCORE));
|
std::sort(mPosts.begin(),mPosts.end(), PostSorter(SORT_NEW_SCORE));
|
||||||
|
|
||||||
mFilteredPosts.clear();
|
uint32_t tmpval;
|
||||||
for(int i=0;i<mPosts.size();++i)
|
setFilter(QStringList(),tmpval);
|
||||||
mFilteredPosts.push_back(i);
|
|
||||||
|
mDisplayedNbPosts = std::min((uint32_t)mFilteredPosts.size(),DEFAULT_DISPLAYED_NB_POSTS);
|
||||||
|
mDisplayedStartIndex = 0;
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(),0,rowCount()-1);
|
beginInsertRows(QModelIndex(),0,rowCount()-1);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
@ -31,6 +31,33 @@
|
|||||||
|
|
||||||
// The model contains a post in place 0 that is the parent of all posts.
|
// The model contains a post in place 0 that is the parent of all posts.
|
||||||
|
|
||||||
|
// The model contains 3 layers:
|
||||||
|
//
|
||||||
|
// Layer 1: list of all posts
|
||||||
|
//
|
||||||
|
// * this list is sorted according to the current sorting strategy
|
||||||
|
// * Variables: mPosts
|
||||||
|
//
|
||||||
|
// Layer 2: list of post filtered by search
|
||||||
|
//
|
||||||
|
// * depending on which chunk of posts are actually displayed, this list contains
|
||||||
|
// the subset of the general list of posts
|
||||||
|
// * Variables: mFilteredPosts
|
||||||
|
//
|
||||||
|
// Layer 3: start and end of posts actually displayed in the previous list
|
||||||
|
//
|
||||||
|
// * Variables: mDisplayedStartIndex, mDisplayedNbPosts
|
||||||
|
//
|
||||||
|
// The array below indicates which variables are updated depending on the type of data/view change:
|
||||||
|
//
|
||||||
|
// | Global list (mPosts) | Filtered List | Displayed list (mDisplayedStartIndex, mDisplayedNbPosts)
|
||||||
|
// -----------+-----------------------+------------------+----------------------------------------------------------
|
||||||
|
// New group | X | X | X (updated because FilteredList may change)
|
||||||
|
// Sort order | X | |
|
||||||
|
// Filter Str | | X | X (updated because FilteredList may change)
|
||||||
|
// Chunk chng | | X | X
|
||||||
|
//
|
||||||
|
|
||||||
typedef uint32_t PostedPostsModelIndex;
|
typedef uint32_t PostedPostsModelIndex;
|
||||||
|
|
||||||
// struct ChannelPostsModelPostEntry
|
// struct ChannelPostsModelPostEntry
|
||||||
@ -66,7 +93,8 @@ public:
|
|||||||
explicit RsPostedPostsModel(QObject *parent = NULL);
|
explicit RsPostedPostsModel(QObject *parent = NULL);
|
||||||
virtual ~RsPostedPostsModel() override;
|
virtual ~RsPostedPostsModel() override;
|
||||||
|
|
||||||
static const int COLUMN_THREAD_NB_COLUMNS = 0x01;
|
static const uint32_t COLUMN_THREAD_NB_COLUMNS = 0x01;
|
||||||
|
static const uint32_t DEFAULT_DISPLAYED_NB_POSTS ;
|
||||||
|
|
||||||
enum SortingStrategy {
|
enum SortingStrategy {
|
||||||
SORT_UNKNOWN = 0x00,
|
SORT_UNKNOWN = 0x00,
|
||||||
@ -118,6 +146,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);
|
void setSortingStrategy(SortingStrategy s);
|
||||||
|
void setPostsInterval(int start,int nb_posts);
|
||||||
|
|
||||||
#ifdef TODO
|
#ifdef TODO
|
||||||
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
||||||
@ -198,8 +227,11 @@ private:
|
|||||||
void initEmptyHierarchy();
|
void initEmptyHierarchy();
|
||||||
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
|
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
|
||||||
|
|
||||||
std::vector<int> mFilteredPosts; // stores the list of displayes indices due to filtering.
|
std::vector<RsPostedPost> mPosts ;
|
||||||
std::vector<RsPostedPost> mPosts ; // store the list of posts updated from rsForums.
|
std::vector<int> mFilteredPosts;
|
||||||
|
uint32_t mDisplayedStartIndex;
|
||||||
|
uint32_t mDisplayedNbPosts;
|
||||||
|
|
||||||
|
|
||||||
RsEventsHandlerId_t mEventHandlerId ;
|
RsEventsHandlerId_t mEventHandlerId ;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user