diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index b6011a67c..f664842ce 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -582,16 +582,47 @@ static void removeMessages(std::map > &ms } } +void GxsForumThreadWidget::saveExpandedItems(QList& expanded_items) const +{ + expanded_items.clear(); + + for(int row = 0; row < mThreadProxyModel->rowCount(); ++row) + { + std::string path = mThreadProxyModel->index(row,0).data(Qt::DisplayRole).toString().toStdString(); + + recursSaveExpandedItems(mThreadProxyModel->index(row,0),expanded_items); + } +} + +void GxsForumThreadWidget::recursSaveExpandedItems(const QModelIndex& index, QList& expanded_items) const +{ + if(ui->threadTreeWidget->isExpanded(index)) + { + for(int row=0;rowrowCount(index);++row) + recursSaveExpandedItems(index.child(row,0),expanded_items) ; + + RsGxsMessageId message_id(index.sibling(index.row(),RsGxsForumModel::COLUMN_THREAD_MSGID).data(Qt::UserRole).toString().toStdString()); + expanded_items.push_back(message_id); + } +} + +void GxsForumThreadWidget::recursRestoreExpandedItems(const QModelIndex& index, const QList& expanded_items) +{ + for(auto it(expanded_items.begin());it!=expanded_items.end();++it) + ui->threadTreeWidget->setExpanded( mThreadProxyModel->mapFromSource(mThreadModel->getIndexOfMessage(*it)) ,true) ; +} + void GxsForumThreadWidget::updateDisplay(bool complete) { - if(mUpdating) - return; + if(mUpdating) + return; if (complete) { /* Fill complete */ + saveExpandedItems(mSavedExpandedMessages); - mUpdating=true; + mUpdating=true; updateGroupData(); mThreadModel->setForum(groupId()); insertMessage(); @@ -600,37 +631,44 @@ void GxsForumThreadWidget::updateDisplay(bool complete) return; } + else + { - bool updateGroup = false; - const std::set &grpIdsMeta = getGrpIdsMeta(); + bool updateGroup = false; + const std::set &grpIdsMeta = getGrpIdsMeta(); - if(grpIdsMeta.find(groupId())!=grpIdsMeta.end()) - updateGroup = true; + if(grpIdsMeta.find(groupId())!=grpIdsMeta.end()) + updateGroup = true; - const std::set &grpIds = getGrpIds(); - if (grpIds.find(groupId())!=grpIds.end()){ - updateGroup = true; - /* Update threads */ - mUpdating=true; - mThreadModel->setForum(groupId()); - } else { - std::map > msgIds; - getAllMsgIds(msgIds); + const std::set &grpIds = getGrpIds(); - if (!mIgnoredMsgId.empty()) { - /* Filter ignored messages */ - removeMessages(msgIds, mIgnoredMsgId); + if (grpIds.find(groupId())!=grpIds.end()){ + updateGroup = true; + /* Update threads */ + mUpdating=true; + mThreadModel->setForum(groupId()); + } + else + { + std::map > msgIds; + getAllMsgIds(msgIds); + + if (!mIgnoredMsgId.empty()) /* Filter ignored messages */ + removeMessages(msgIds, mIgnoredMsgId); + + if (msgIds.find(groupId()) != msgIds.end()) + { + mUpdating=true; + + saveExpandedItems(mSavedExpandedMessages); + + mThreadModel->setForum(groupId()); /* Update threads */ + } } - if (msgIds.find(groupId()) != msgIds.end()) - { - mUpdating=true; - mThreadModel->setForum(groupId()); /* Update threads */ - } - } + if (updateGroup) + updateGroupData(); - if (updateGroup) { - updateGroupData(); } } @@ -1531,10 +1569,6 @@ void GxsForumThreadWidget::replyForumMessageData(const RsGxsForumMsg &msg) { CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId,RsGxsMessageId()); -// QTextDocument doc ; -// doc.setHtml(QString::fromUtf8(msg.mMsg.c_str()) ); -// std::string cited_text(doc.toPlainText().toStdString()) ; - RsHtml::makeQuotedText(ui->postText); cfm->insertPastedText(RsHtml::makeQuotedText(ui->postText)) ; @@ -1651,11 +1685,14 @@ void GxsForumThreadWidget::postForumLoading() ui->threadTreeWidget->selectionModel()->reset(); mThreadId.clear(); } + // we also need to restore expanded threads ui->forumName->setText(QString::fromUtf8(mForumGroup.mMeta.mGroupName.c_str())); ui->threadTreeWidget->sortByColumn(RsGxsForumModel::COLUMN_THREAD_DATE, Qt::DescendingOrder); ui->threadTreeWidget->update(); + recursRestoreExpandedItems(mThreadProxyModel->mapFromSource(mThreadModel->root()),mSavedExpandedMessages); + mUpdating = false; } void GxsForumThreadWidget::updateGroupData() @@ -1665,7 +1702,6 @@ void GxsForumThreadWidget::updateGroupData() mSubscribeFlags = 0; mSignFlags = 0; - //mThreadId.clear(); mForumDescription.clear(); ui->threadTreeWidget->selectionModel()->clear(); ui->threadTreeWidget->selectionModel()->reset(); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h index 4a01628a1..9dba7efb5 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h @@ -152,6 +152,10 @@ private: void insertMessage(); void insertGroupData(); + void recursRestoreExpandedItems(const QModelIndex& index, const QList& expanded_items); + void recursSaveExpandedItems(const QModelIndex& index, QList& expanded_items) const; + void saveExpandedItems(QList& expanded_items) const; + int getSelectedMsgCount(QList *pRows, QList *pRowsRead, QList *pRowsUnread); void setMsgReadStatus(QList &rows, bool read); void markMsgAsReadUnread(bool read, bool children, bool forum); @@ -159,7 +163,7 @@ private: void togglethreadview_internal(); - bool filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn); + //bool filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn); void processSettings(bool bLoad); @@ -197,6 +201,7 @@ private: RsGxsForumModel *mThreadModel; QSortFilterProxyModel *mThreadProxyModel; + QList mSavedExpandedMessages; Ui::GxsForumThreadWidget *ui; };