From 59220b5c856066e7a1acda144f95216f207cd1e4 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 22 Nov 2018 10:44:06 +0100 Subject: [PATCH] fixed layout of internal data in ForumModel --- .../src/gui/gxsforums/GxsForumModel.cpp | 65 ++++++++++++++++++- .../src/gui/gxsforums/GxsForumModel.h | 8 +++ 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp index 796d80d6f..c077bea6c 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp @@ -7,7 +7,7 @@ #include "GxsForumModel.h" #include "retroshare/rsgxsforums.h" -#define DEBUG_FORUMMODEL +//#define DEBUG_FORUMMODEL #define COLUMN_THREAD_TITLE 0 #define COLUMN_THREAD_READ 1 @@ -29,7 +29,8 @@ std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsew RsGxsForumModel::RsGxsForumModel(QObject *parent) : QAbstractItemModel(parent) { - mPosts.resize(1); // adds a sentinel item + initEmptyHierarchy(mPosts); + mFilterColumn=0; mUseChildTS=false; @@ -60,6 +61,13 @@ RsGxsForumModel::RsGxsForumModel(QObject *parent) // meta.mMsgName = std::string("message ") + QString::number(N+1).toStdString() ; } +void RsGxsForumModel::initEmptyHierarchy(std::vector& posts) +{ + posts.resize(1); // adds a sentinel item + posts[0].mTitle = "Root sentinel post" ; + posts[0].mParent = 0; +} + int RsGxsForumModel::rowCount(const QModelIndex& parent) const { if(parent.column() > 0) @@ -454,6 +462,16 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector& post posts[N].mParent = parent; posts[parent].mChildren.push_back(N); + std::cerr << "Added new entry " << N << " children of " << parent << std::endl; + + if(N == parent) + std::cerr << "(EE) trying to add a post as its own parent!" << std::endl; return ForumModelIndex(N); } @@ -530,8 +552,11 @@ void RsGxsForumModel::generateMissingItem(const RsGxsMessageId &msgId,ForumModel void RsGxsForumModel::convertMsgToPostEntry(const RsGxsForumGroup& mForumGroup,const RsGxsForumMsg& msg, bool useChildTS, uint32_t filterColumn,ForumModelPostEntry& fentry) { + fentry.mTitle = msg.mMeta.mMsgName; + fentry.mAuthorId = msg.mMeta.mAuthorId; fentry.mMsgId = msg.mMeta.mMsgId; fentry.mPublishTs = msg.mMeta.mPublishTs; + fentry.mPostFlags = 0; fentry.mStatus = msg.mMeta.mMsgStatus; if(mForumGroup.mPinnedPosts.ids.find(msg.mMeta.mMsgId) != mForumGroup.mPinnedPosts.ids.end()) @@ -623,7 +648,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou // int steps = count / PROGRESSBAR_MAX; int step = 0; - posts.clear(); + initEmptyHierarchy(posts); QMap > > mPostVersions ; // ThreadList contains the list of parent threads. The algorithm below iterates through all messages @@ -894,6 +919,40 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou #endif } +static void recursPrintModel(const std::vector& entries,ForumModelIndex index,int depth) +{ + const ForumModelPostEntry& e(entries[index]); + + std::cerr << std::string(depth*2,' ') << e.mAuthorId.toStdString() << " " << QString("%1").arg((uint32_t)e.mPostFlags,8,16,QChar('0')).toStdString() + << " " << QDateTime::fromSecsSinceEpoch(e.mPublishTs).toString().toStdString() << " \"" << e.mTitle << "\"" << std::endl; + + for(uint32_t i=0;i& msgs_array,std::vector& posts); void setPosts(const RsGxsForumGroup &group, const std::vector& posts); // this method *must* be called from UI thread. + void initEmptyHierarchy(std::vector& posts); std::vector mPosts ; // store the list of posts updated from rsForums. };