mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 16:39:29 -05:00
added flat mode to ForumModel
This commit is contained in:
parent
917695e832
commit
1fced4a1c3
@ -26,15 +26,32 @@ RsGxsForumModel::RsGxsForumModel(QObject *parent)
|
|||||||
initEmptyHierarchy(mPosts);
|
initEmptyHierarchy(mPosts);
|
||||||
|
|
||||||
mUseChildTS=false;
|
mUseChildTS=false;
|
||||||
mFlatView=false;
|
|
||||||
mFilteringEnabled=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<ForumModelPostEntry>& posts)
|
void RsGxsForumModel::initEmptyHierarchy(std::vector<ForumModelPostEntry>& posts)
|
||||||
{
|
{
|
||||||
|
emit layoutAboutToBeChanged();
|
||||||
|
|
||||||
posts.resize(1); // adds a sentinel item
|
posts.resize(1); // adds a sentinel item
|
||||||
posts[0].mTitle = "Root sentinel post" ;
|
posts[0].mTitle = "Root sentinel post" ;
|
||||||
posts[0].mParent = 0;
|
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
|
int RsGxsForumModel::rowCount(const QModelIndex& parent) const
|
||||||
@ -88,6 +105,9 @@ bool RsGxsForumModel::hasChildren(const QModelIndex &parent) const
|
|||||||
if(!parent.isValid())
|
if(!parent.isValid())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if(mTreeMode == TREE_MODE_FLAT)
|
||||||
|
return false;
|
||||||
|
|
||||||
void *ref = parent.internalPointer();
|
void *ref = parent.internalPointer();
|
||||||
uint32_t entry = 0;
|
uint32_t entry = 0;
|
||||||
|
|
||||||
@ -151,6 +171,9 @@ QModelIndex RsGxsForumModel::parent(const QModelIndex& index) const
|
|||||||
if(!index.isValid())
|
if(!index.isValid())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
|
if(mTreeMode == TREE_MODE_FLAT)
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
void *child_ref = index.internalPointer();
|
void *child_ref = index.internalPointer();
|
||||||
int row=0;
|
int row=0;
|
||||||
|
|
||||||
@ -178,6 +201,16 @@ void *RsGxsForumModel::getChildRef(void *ref,int row) const
|
|||||||
return NULL ;
|
return NULL ;
|
||||||
|
|
||||||
void *new_ref;
|
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())
|
if(row >= mPosts[entry].mChildren.size())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -190,6 +223,9 @@ void *RsGxsForumModel::getParentRef(void *ref,int& row) const
|
|||||||
{
|
{
|
||||||
ForumModelIndex ref_entry;
|
ForumModelIndex ref_entry;
|
||||||
|
|
||||||
|
if(mTreeMode == TREE_MODE_FLAT)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if(!convertRefPointerToTabEntry(ref,ref_entry) || ref_entry >= mPosts.size())
|
if(!convertRefPointerToTabEntry(ref,ref_entry) || ref_entry >= mPosts.size())
|
||||||
return NULL ;
|
return NULL ;
|
||||||
|
|
||||||
@ -217,6 +253,12 @@ int RsGxsForumModel::getChildrenCount(void *ref) const
|
|||||||
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mPosts.size())
|
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mPosts.size())
|
||||||
return 0 ;
|
return 0 ;
|
||||||
|
|
||||||
|
if(mTreeMode == TREE_MODE_FLAT)
|
||||||
|
if(entry == 0)
|
||||||
|
return ((int)mPosts.size())-1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
return mPosts[entry].mChildren.size();
|
return mPosts[entry].mChildren.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -941,7 +983,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou
|
|||||||
for ( std::map<RsGxsMessageId,RsGxsForumMsg>::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt)
|
for ( std::map<RsGxsMessageId,RsGxsForumMsg>::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(mFlatView || msgIt->second.mMeta.mParentId.isNull())
|
if(msgIt->second.mMeta.mParentId.isNull())
|
||||||
{
|
{
|
||||||
|
|
||||||
/* add all threads */
|
/* add all threads */
|
||||||
@ -956,7 +998,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou
|
|||||||
|
|
||||||
ForumModelIndex entry_index = addEntry(posts,entry,0);
|
ForumModelIndex entry_index = addEntry(posts,entry,0);
|
||||||
|
|
||||||
if (!mFlatView)
|
//if (!mFlatView)
|
||||||
threadStack.push_back(std::make_pair(msg.mMeta.mMsgId,entry_index)) ;
|
threadStack.push_back(std::make_pair(msg.mMeta.mMsgId,entry_index)) ;
|
||||||
|
|
||||||
//calculateExpand(msg, item);
|
//calculateExpand(msg, item);
|
||||||
|
@ -83,6 +83,10 @@ public:
|
|||||||
FilterRole = Qt::UserRole+6,
|
FilterRole = Qt::UserRole+6,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum TreeMode{ TREE_MODE_FLAT = 0x00,
|
||||||
|
TREE_MODE_TREE = 0x01,
|
||||||
|
};
|
||||||
|
|
||||||
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
|
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
|
||||||
QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const;
|
QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const;
|
||||||
|
|
||||||
@ -114,6 +118,7 @@ public:
|
|||||||
|
|
||||||
// This method will asynchroneously update the data
|
// This method will asynchroneously update the data
|
||||||
void setForum(const RsGxsGroupId& forumGroup);
|
void setForum(const RsGxsGroupId& forumGroup);
|
||||||
|
void setTreeMode(TreeMode mode) ;
|
||||||
|
|
||||||
void setTextColorRead (QColor color) { mTextColorRead = color;}
|
void setTextColorRead (QColor color) { mTextColorRead = color;}
|
||||||
void setTextColorUnread (QColor color) { mTextColorUnread = color;}
|
void setTextColorUnread (QColor color) { mTextColorUnread = color;}
|
||||||
@ -165,8 +170,8 @@ private:
|
|||||||
RsGxsForumGroup mForumGroup;
|
RsGxsForumGroup mForumGroup;
|
||||||
|
|
||||||
bool mUseChildTS;
|
bool mUseChildTS;
|
||||||
bool mFlatView;
|
|
||||||
bool mFilteringEnabled;
|
bool mFilteringEnabled;
|
||||||
|
TreeMode mTreeMode;
|
||||||
|
|
||||||
void *getParentRef(void *ref,int& row) const;
|
void *getParentRef(void *ref,int& row) const;
|
||||||
void *getChildRef(void *ref,int row) const;
|
void *getChildRef(void *ref,int row) const;
|
||||||
|
@ -365,9 +365,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
|
|||||||
|
|
||||||
mInMsgAsReadUnread = false;
|
mInMsgAsReadUnread = false;
|
||||||
|
|
||||||
//mThreadCompareRole = new RSTreeWidgetItemCompareRole;
|
|
||||||
//mThreadCompareRole->setRole(RsGxsForumModel::COLUMN_THREAD_DATE, ROLE_THREAD_SORT);
|
|
||||||
|
|
||||||
mThreadModel = new RsGxsForumModel(this);
|
mThreadModel = new RsGxsForumModel(this);
|
||||||
mThreadProxyModel = new ForumPostSortFilterProxyModel(ui->threadTreeWidget->header(),this);
|
mThreadProxyModel = new ForumPostSortFilterProxyModel(ui->threadTreeWidget->header(),this);
|
||||||
mThreadProxyModel->setSourceModel(mThreadModel);
|
mThreadProxyModel->setSourceModel(mThreadModel);
|
||||||
@ -400,7 +397,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
|
|||||||
ui->newmessageButton->setText(tr("Reply"));
|
ui->newmessageButton->setText(tr("Reply"));
|
||||||
ui->newthreadButton->setText(tr("New thread"));
|
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->threadTreeWidget, SIGNAL(clicked(QModelIndex)), this, SLOT(clickedThread(QModelIndex)));
|
||||||
connect(ui->viewBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changedViewBox()));
|
connect(ui->viewBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changedViewBox()));
|
||||||
|
|
||||||
@ -2652,18 +2648,19 @@ void GxsForumThreadWidget::saveImage()
|
|||||||
|
|
||||||
void GxsForumThreadWidget::changedViewBox()
|
void GxsForumThreadWidget::changedViewBox()
|
||||||
{
|
{
|
||||||
#ifdef TODO
|
|
||||||
if (mInProcessSettings) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// save index
|
// save index
|
||||||
Settings->setValueToGroup("ForumThreadWidget", "viewBox", ui->viewBox->currentIndex());
|
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();
|
case VIEW_FLAT: mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_FLAT);
|
||||||
#endif
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxsForumThreadWidget::filterColumnChanged(int column)
|
void GxsForumThreadWidget::filterColumnChanged(int column)
|
||||||
|
Loading…
Reference in New Issue
Block a user