mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
fixed saving/restoring of expanded items in forum model
This commit is contained in:
parent
11b4981bd4
commit
600a3d8e16
@ -582,6 +582,36 @@ static void removeMessages(std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &ms
|
||||
}
|
||||
}
|
||||
|
||||
void GxsForumThreadWidget::saveExpandedItems(QList<RsGxsMessageId>& 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<RsGxsMessageId>& expanded_items) const
|
||||
{
|
||||
if(ui->threadTreeWidget->isExpanded(index))
|
||||
{
|
||||
for(int row=0;row<mThreadProxyModel->rowCount(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<RsGxsMessageId>& 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)
|
||||
@ -590,6 +620,7 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
|
||||
if (complete) {
|
||||
/* Fill complete */
|
||||
|
||||
saveExpandedItems(mSavedExpandedMessages);
|
||||
|
||||
mUpdating=true;
|
||||
updateGroupData();
|
||||
@ -600,6 +631,8 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
bool updateGroup = false;
|
||||
const std::set<RsGxsGroupId> &grpIdsMeta = getGrpIdsMeta();
|
||||
@ -608,29 +641,34 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
|
||||
updateGroup = true;
|
||||
|
||||
const std::set<RsGxsGroupId> &grpIds = getGrpIds();
|
||||
|
||||
if (grpIds.find(groupId())!=grpIds.end()){
|
||||
updateGroup = true;
|
||||
/* Update threads */
|
||||
mUpdating=true;
|
||||
mThreadModel->setForum(groupId());
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > msgIds;
|
||||
getAllMsgIds(msgIds);
|
||||
|
||||
if (!mIgnoredMsgId.empty()) {
|
||||
/* Filter ignored messages */
|
||||
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 (updateGroup) {
|
||||
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();
|
||||
|
@ -152,6 +152,10 @@ private:
|
||||
void insertMessage();
|
||||
void insertGroupData();
|
||||
|
||||
void recursRestoreExpandedItems(const QModelIndex& index, const QList<RsGxsMessageId>& expanded_items);
|
||||
void recursSaveExpandedItems(const QModelIndex& index, QList<RsGxsMessageId>& expanded_items) const;
|
||||
void saveExpandedItems(QList<RsGxsMessageId>& expanded_items) const;
|
||||
|
||||
int getSelectedMsgCount(QList<QTreeWidgetItem*> *pRows, QList<QTreeWidgetItem*> *pRowsRead, QList<QTreeWidgetItem*> *pRowsUnread);
|
||||
void setMsgReadStatus(QList<QTreeWidgetItem*> &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<RsGxsMessageId> mSavedExpandedMessages;
|
||||
|
||||
Ui::GxsForumThreadWidget *ui;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user