fixed compilation in new ForumModel

This commit is contained in:
csoler 2018-11-22 09:28:07 +01:00
parent d3565c2ee4
commit e01de33e1a
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 43 additions and 19 deletions

View File

@ -3,6 +3,7 @@
#include <QModelIndex>
#include "util/qtthreadsutils.h"
#include "util/DateTime.h"
#include "GxsForumModel.h"
#include "retroshare/rsgxsforums.h"
@ -30,6 +31,10 @@ RsGxsForumModel::RsGxsForumModel(QObject *parent)
{
mPosts.resize(1); // adds a sentinel item
mFilterColumn=0;
mUseChildTS=false;
mFlatView=false;
// // adds some fake posts to debug
//
// int N=5 ;
@ -303,7 +308,6 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const
{
case Qt::DisplayRole: return displayRole (fmpe,index.column()) ;
case Qt::DecorationRole: return decorationRole(fmpe,index.column()) ;
case Qt::UserRole: return userRole (fmpe,index.column()) ;
case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ;
case ThreadPinnedRole: return pinnedRole (fmpe,index.column()) ;
@ -377,7 +381,7 @@ QVariant RsGxsForumModel::sizeHintRole(int col) const
QVariant RsGxsForumModel::authorRole(const ForumModelPostEntry& fmpe,int column) const
{
if(column == COLUMN_THREAD_DATA)
return QVariant(QString::fromStdString(msg.mMeta.mAuthorId.toStdString()));
return QVariant(QString::fromStdString(fmpe.mAuthorId.toStdString()));
return QVariant();
}
@ -387,6 +391,7 @@ QVariant RsGxsForumModel::sortRole(const ForumModelPostEntry& fmpe,int column) c
if(column == COLUMN_THREAD_DATA)
return QVariant(QString::number(fmpe.mPublishTs)); // we should probably have leading zeroes here
return QVariant();
}
QVariant RsGxsForumModel::displayRole(const ForumModelPostEntry& fmpe,int col) const
@ -405,7 +410,7 @@ QVariant RsGxsForumModel::displayRole(const ForumModelPostEntry& fmpe,int col) c
QDateTime qtime;
qtime.setTime_t(fmpe.mPublishTs);
return QVariant(QDateTime::formatDateTime(qtime));
return QVariant(DateTime::formatDateTime(qtime));
}
case COLUMN_THREAD_AUTHOR: return QVariant(QString::fromStdString(fmpe.mAuthorId.toStdString()));
@ -434,15 +439,22 @@ QVariant RsGxsForumModel::decorationRole(const ForumModelPostEntry& fmpe,int col
return QVariant();
}
void RsGxsForumModel::setForum(const RsGxsGroupId& forumGroup)
void RsGxsForumModel::setForum(const RsGxsGroupId& forum_group_id)
{
if(mForumGroupId == forumGroup)
if(mForumGroup.mMeta.mGroupId == forum_group_id)
return ;
mPosts.clear();
mForumGroupId = forumGroup;
// we do not set mForumGroupId yet. We'll do it when the forum data is updated.
update_posts();
update_posts(forum_group_id);
}
void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<ForumModelPostEntry>& posts)
{
mForumGroup = group;
mPosts = posts;
emit layoutChanged();
}
void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id)
@ -472,12 +484,13 @@ void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id)
// 2 - sort the messages into a proper hierarchy
std::vector<ForumModelPostEntry> *vect = new std::vector<ForumModelPostEntry>();
RsGxsForumGroup group = groups[0];
computeMessagesHierarchy(groups[0],messages,*vect);
computeMessagesHierarchy(group,messages,*vect);
// 3 - update the model in the UI thread.
RsQThreadUtils::postToObject( [vect,this]()
RsQThreadUtils::postToObject( [group,vect,this]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information
@ -485,7 +498,7 @@ void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id)
* Qt::QueuedConnection is important!
*/
setPosts(*vect) ;
setPosts(group,*vect) ;
delete vect;
@ -577,7 +590,9 @@ void RsGxsForumModel::convertMsgToPostEntry(const RsGxsForumGroup& mForumGroup,c
static bool decreasing_time_comp(const QPair<time_t,RsGxsMessageId>& e1,const QPair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_group,const std::vector<RsGxsForumMsg>& msgs_array,std::vector<ForumModelPostEntry>& posts)
void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_group,
const std::vector<RsGxsForumMsg>& msgs_array,
std::vector<ForumModelPostEntry>& posts)
{
std::cerr << "updating messages data with " << msgs_array.size() << " messages" << std::endl;
@ -757,7 +772,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou
#endif
ForumModelPostEntry entry;
convertMsgToThreadWidget(msg, mUseChildTS, mFilterColumn,NULL,entry);
convertMsgToPostEntry(forum_group,msg, mUseChildTS, mFilterColumn,entry);
ForumModelIndex entry_index = addEntry(posts,entry,0);
@ -803,7 +818,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou
{
// add dummy parent item
ForumModelPostEntry e ;
generateMissingItem(RsGxsMessageId,e);
generateMissingItem(*it,e);
ForumModelIndex e_index = addEntry(posts,e,0); // no parent -> parent is level 0
//mItems.append( e_index );

View File

@ -27,7 +27,7 @@ typedef uint32_t ForumModelIndex;
struct ForumModelPostEntry
{
typedef enum { // flags for display of posts
enum { // flags for display of posts
FLAG_POST_IS_PINNED = 0x0001,
FLAG_POST_IS_MISSING = 0x0002,
FLAG_POST_IS_REDACTED = 0x0004,
@ -78,7 +78,6 @@ public:
QVariant sizeHintRole (int col) const;
QVariant displayRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant userRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant decorationRole(const ForumModelPostEntry& fmpe, int col) const;
QVariant toolTipRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant pinnedRole (const ForumModelPostEntry& fmpe, int col) const;
@ -88,6 +87,12 @@ public:
QVariant sortRole (const ForumModelPostEntry& fmpe, int col) const;
private:
RsGxsForumGroup mForumGroup;
bool mUseChildTS;
bool mFlatView;
int mFilterColumn;
void *getParentRef(void *ref,int& row) const;
void *getChildRef(void *ref,int row) const;
//bool hasIndex(int row,int column,const QModelIndex& parent)const;
@ -99,12 +104,12 @@ private:
void update_posts(const RsGxsGroupId &group_id);
void setForumMessageSummary(const std::vector<RsGxsForumMsg>& messages);
static void computeMessagesHierarchy(const RsGxsForumGroup& forum_group,const std::vector<RsGxsForumMsg>& msgs_array,std::vector<ForumModelPostEntry>& posts);
static void generateMissingItem(const RsGxsMessageId &msgId,ForumModelPostEntry& entry);
static ForumModelIndex addEntry(std::vector<ForumModelPostEntry>& posts,const ForumModelPostEntry& entry,ForumModelIndex parent);
static void convertMsgToPostEntry(const RsGxsForumGroup &mForumGroup, const RsGxsForumMsg& msg, bool useChildTS, uint32_t filterColumn, ForumModelPostEntry& fentry);
void setPosts(const std::vector<ForumModelPostEntry>& posts);
void computeMessagesHierarchy(const RsGxsForumGroup& forum_group,const std::vector<RsGxsForumMsg>& msgs_array,std::vector<ForumModelPostEntry>& posts);
void setPosts(const RsGxsForumGroup &group, const std::vector<ForumModelPostEntry>& posts); // this method *must* be called from UI thread.
std::vector<ForumModelPostEntry> mPosts ; // store the list of posts updated from rsForums.
};

View File

@ -2942,3 +2942,8 @@ void GxsForumThreadWidget::loadRequest(const TokenQueue *queue, const TokenReque
GxsMessageFrameWidget::loadRequest(queue, req);
}
QTreeWidgetItem *GxsForumThreadWidget::generateMissingItem(const RsGxsMessageId& mid)
{
return NULL;
}

View File

@ -554,4 +554,3 @@ void GxsForumsFillThread::run()
deleteLater();
}