Add Save Selected Post in current Forum when switch to other.

This commit is contained in:
Phenom 2020-11-25 19:56:07 +01:00
parent 1ee38877ca
commit ee6f83aab4
2 changed files with 90 additions and 69 deletions

View File

@ -908,6 +908,7 @@ void GxsForumThreadWidget::changedThread(QModelIndex index)
return;
mThreadId = mOrigThreadId = new_id;
mLastSelectedPosts[groupId()] = new_id;
#ifdef DEBUG_FORUMS
std::cerr << "Switched to new thread ID " << mThreadId << std::endl;
@ -1504,9 +1505,12 @@ bool GxsForumThreadWidget::navigate(const RsGxsMessageId &msgId)
QModelIndex indx = mThreadProxyModel->mapFromSource(source_index);
ui->threadTreeWidget->setCurrentIndex(indx);
ui->threadTreeWidget->selectionModel()->setCurrentIndex(indx,QItemSelectionModel::ClearAndSelect);
ui->threadTreeWidget->scrollTo(ui->threadTreeWidget->currentIndex());//May change if model reloaded
ui->threadTreeWidget->setFocus();
mNavigatePendingMsgId.clear();
return true;
}
@ -1813,6 +1817,17 @@ void GxsForumThreadWidget::changedViewBox()
mThreadModel->setSortMode(RsGxsForumModel::SORT_MODE_CHILDREN_PUBLISH_TS);
else
mThreadModel->setSortMode(RsGxsForumModel::SORT_MODE_PUBLISH_TS);
if( (mLastSelectedPosts.count(groupId()) > 0)
&& !mLastSelectedPosts[groupId()].isNull()
&& mThreadModel->getIndexOfMessage(mLastSelectedPosts[groupId()]).isValid())
{
QModelIndex source_index = mThreadModel->getIndexOfMessage(mLastSelectedPosts[groupId()]);
QModelIndex index = mThreadProxyModel->mapFromSource(source_index);
ui->threadTreeWidget->selectionModel()->setCurrentIndex(index,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
ui->threadTreeWidget->scrollTo(ui->threadTreeWidget->currentIndex());//May change if model reloaded
}
}
void GxsForumThreadWidget::filterColumnChanged(int column)
@ -1877,19 +1892,24 @@ void GxsForumThreadWidget::postForumLoading()
#ifdef DEBUG_FORUMS
std::cerr << "Post forum loading..." << std::endl;
#endif
if(!mNavigatePendingMsgId.isNull() && mThreadModel->getIndexOfMessage(mNavigatePendingMsgId).isValid())
if (!mNavigatePendingMsgId.isNull())
navigate(mNavigatePendingMsgId);
else if( (mLastSelectedPosts.count(groupId()) > 0)
&& !mLastSelectedPosts[groupId()].isNull()
&& mThreadModel->getIndexOfMessage(mLastSelectedPosts[groupId()]).isValid())
{
#ifdef DEBUG_FORUMS
std::cerr << "Pending msg navigation: " << mNavigatePendingMsgId << ". Using it as new thread Id" << std::endl;
std::cerr << "Last selected msg navigation: " << mLastSelectedPosts[groupId()].toStdString() << ". Using it as new thread Id" << std::endl;
#endif
QModelIndex source_index = mThreadModel->getIndexOfMessage(mNavigatePendingMsgId);
QModelIndex source_index = mThreadModel->getIndexOfMessage(mLastSelectedPosts[groupId()]);
QModelIndex index = mThreadProxyModel->mapFromSource(source_index);
ui->threadTreeWidget->selectionModel()->setCurrentIndex(index,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
ui->threadTreeWidget->scrollTo(ui->threadTreeWidget->currentIndex());//May change if model reloaded
mNavigatePendingMsgId.clear();
}
else
{

View File

@ -224,6 +224,7 @@ private:
QColor mBackgroundColorPinned;
QColor mBackgroundColorFiltered;
std::map<RsGxsGroupId,RsGxsMessageId> mLastSelectedPosts;
RsGxsMessageId mNavigatePendingMsgId;
QList<RsGxsMessageId> mIgnoredMsgId;