diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp index 3e72f3659..abf2a15f2 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp @@ -26,15 +26,32 @@ RsGxsForumModel::RsGxsForumModel(QObject *parent) initEmptyHierarchy(mPosts); mUseChildTS=false; - mFlatView=false; mFilteringEnabled=false; } +void RsGxsForumModel::setTreeMode(TreeMode mode) +{ + if(mode == mTreeMode) + return; + + emit layoutAboutToBeChanged(); + + mTreeMode = mode; + + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); + emit layoutChanged(); +} + void RsGxsForumModel::initEmptyHierarchy(std::vector& posts) { + emit layoutAboutToBeChanged(); + posts.resize(1); // adds a sentinel item posts[0].mTitle = "Root sentinel post" ; posts[0].mParent = 0; + + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); + emit layoutChanged(); } int RsGxsForumModel::rowCount(const QModelIndex& parent) const @@ -88,6 +105,9 @@ bool RsGxsForumModel::hasChildren(const QModelIndex &parent) const if(!parent.isValid()) return true; + if(mTreeMode == TREE_MODE_FLAT) + return false; + void *ref = parent.internalPointer(); uint32_t entry = 0; @@ -151,6 +171,9 @@ QModelIndex RsGxsForumModel::parent(const QModelIndex& index) const if(!index.isValid()) return QModelIndex(); + if(mTreeMode == TREE_MODE_FLAT) + return QModelIndex(); + void *child_ref = index.internalPointer(); int row=0; @@ -178,6 +201,16 @@ void *RsGxsForumModel::getChildRef(void *ref,int row) const return NULL ; void *new_ref; + + if(mTreeMode == TREE_MODE_FLAT) + if(entry == 0) + { + convertTabEntryToRefPointer(row+1,new_ref); + return new_ref; + } + else + return NULL ; + if(row >= mPosts[entry].mChildren.size()) return NULL; @@ -190,6 +223,9 @@ void *RsGxsForumModel::getParentRef(void *ref,int& row) const { ForumModelIndex ref_entry; + if(mTreeMode == TREE_MODE_FLAT) + return NULL; + if(!convertRefPointerToTabEntry(ref,ref_entry) || ref_entry >= mPosts.size()) return NULL ; @@ -217,7 +253,13 @@ int RsGxsForumModel::getChildrenCount(void *ref) const if(!convertRefPointerToTabEntry(ref,entry) || entry >= mPosts.size()) return 0 ; - return mPosts[entry].mChildren.size(); + if(mTreeMode == TREE_MODE_FLAT) + if(entry == 0) + return ((int)mPosts.size())-1; + else + return 0; + else + return mPosts[entry].mChildren.size(); } QVariant RsGxsForumModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -941,7 +983,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou for ( std::map::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt) { - if(mFlatView || msgIt->second.mMeta.mParentId.isNull()) + if(msgIt->second.mMeta.mParentId.isNull()) { /* add all threads */ @@ -956,7 +998,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou ForumModelIndex entry_index = addEntry(posts,entry,0); - if (!mFlatView) + //if (!mFlatView) threadStack.push_back(std::make_pair(msg.mMeta.mMsgId,entry_index)) ; //calculateExpand(msg, item); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumModel.h b/retroshare-gui/src/gui/gxsforums/GxsForumModel.h index 539f1a400..60e38fa9b 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumModel.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumModel.h @@ -83,6 +83,10 @@ public: FilterRole = Qt::UserRole+6, }; + enum TreeMode{ TREE_MODE_FLAT = 0x00, + TREE_MODE_TREE = 0x01, + }; + QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;} QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const; @@ -114,6 +118,7 @@ public: // This method will asynchroneously update the data void setForum(const RsGxsGroupId& forumGroup); + void setTreeMode(TreeMode mode) ; void setTextColorRead (QColor color) { mTextColorRead = color;} void setTextColorUnread (QColor color) { mTextColorUnread = color;} @@ -165,8 +170,8 @@ private: RsGxsForumGroup mForumGroup; bool mUseChildTS; - bool mFlatView; bool mFilteringEnabled; + TreeMode mTreeMode; void *getParentRef(void *ref,int& row) const; void *getChildRef(void *ref,int row) const; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 60d0e7c15..0258cf29b 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -365,9 +365,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget mInMsgAsReadUnread = false; - //mThreadCompareRole = new RSTreeWidgetItemCompareRole; - //mThreadCompareRole->setRole(RsGxsForumModel::COLUMN_THREAD_DATE, ROLE_THREAD_SORT); - mThreadModel = new RsGxsForumModel(this); mThreadProxyModel = new ForumPostSortFilterProxyModel(ui->threadTreeWidget->header(),this); mThreadProxyModel->setSourceModel(mThreadModel); @@ -400,7 +397,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget ui->newmessageButton->setText(tr("Reply")); ui->newthreadButton->setText(tr("New thread")); - //connect(ui->threadTreeWidget, SIGNAL(clicked(QModelIndex)), this, SLOT(changedThread(QModelIndex))); connect(ui->threadTreeWidget, SIGNAL(clicked(QModelIndex)), this, SLOT(clickedThread(QModelIndex))); connect(ui->viewBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changedViewBox())); @@ -2652,18 +2648,19 @@ void GxsForumThreadWidget::saveImage() void GxsForumThreadWidget::changedViewBox() { -#ifdef TODO - if (mInProcessSettings) { - return; - } - // save index Settings->setValueToGroup("ForumThreadWidget", "viewBox", ui->viewBox->currentIndex()); - ui->threadTreeWidget->clear(); + switch(ui->viewBox->currentIndex()) + { + default: + case VIEW_THREADED: + case VIEW_LAST_POST: mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_TREE); + break; - insertThreads(); -#endif + case VIEW_FLAT: mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_FLAT); + break; + } } void GxsForumThreadWidget::filterColumnChanged(int column)