Merge pull request #2129 from PhenomRetroShare/Add_SaveSelectedPostInForum

Add Save Selected Post in current Forum when switch to other.
This commit is contained in:
csoler 2020-11-26 20:22:36 +01:00 committed by GitHub
commit c58e332acd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 90 additions and 69 deletions

View File

@ -908,6 +908,7 @@ void GxsForumThreadWidget::changedThread(QModelIndex index)
return; return;
mThreadId = mOrigThreadId = new_id; mThreadId = mOrigThreadId = new_id;
mLastSelectedPosts[groupId()] = new_id;
#ifdef DEBUG_FORUMS #ifdef DEBUG_FORUMS
std::cerr << "Switched to new thread ID " << mThreadId << std::endl; std::cerr << "Switched to new thread ID " << mThreadId << std::endl;
@ -1492,22 +1493,25 @@ void GxsForumThreadWidget::expandSubtree() {
bool GxsForumThreadWidget::navigate(const RsGxsMessageId &msgId) bool GxsForumThreadWidget::navigate(const RsGxsMessageId &msgId)
{ {
QModelIndex source_index = mThreadModel->getIndexOfMessage(msgId); QModelIndex source_index = mThreadModel->getIndexOfMessage(msgId);
if(!source_index.isValid()) if(!source_index.isValid())
{ {
std::cerr << "(EE) Cannot navigate to msg " << msgId << " in forum " << mForumGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl; std::cerr << "(EE) Cannot navigate to msg " << msgId << " in forum " << mForumGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl;
mNavigatePendingMsgId = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading. mNavigatePendingMsgId = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading.
return true; // we have to return true here, otherwise the caller will intepret the async loading as an error. return true; // we have to return true here, otherwise the caller will intepret the async loading as an error.
} }
QModelIndex indx = mThreadProxyModel->mapFromSource(source_index); 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->scrollTo(ui->threadTreeWidget->currentIndex());//May change if model reloaded
ui->threadTreeWidget->setFocus(); ui->threadTreeWidget->setFocus();
return true;
mNavigatePendingMsgId.clear();
return true;
} }
void GxsForumThreadWidget::copyMessageLink() void GxsForumThreadWidget::copyMessageLink()
@ -1797,22 +1801,33 @@ void GxsForumThreadWidget::saveImage()
void GxsForumThreadWidget::changedViewBox() void GxsForumThreadWidget::changedViewBox()
{ {
ui->threadTreeWidget->selectionModel()->clear(); ui->threadTreeWidget->selectionModel()->clear();
ui->threadTreeWidget->selectionModel()->reset(); ui->threadTreeWidget->selectionModel()->reset();
mThreadId.clear(); mThreadId.clear();
// save index // save index
Settings->setValueToGroup("ForumThreadWidget", "viewBox", ui->viewBox->currentIndex()); Settings->setValueToGroup("ForumThreadWidget", "viewBox", ui->viewBox->currentIndex());
if(ui->viewBox->currentIndex() == VIEW_FLAT) if(ui->viewBox->currentIndex() == VIEW_FLAT)
mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_FLAT); mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_FLAT);
else else
mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_TREE); mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_TREE);
if(ui->viewBox->currentIndex() == VIEW_LAST_POST) if(ui->viewBox->currentIndex() == VIEW_LAST_POST)
mThreadModel->setSortMode(RsGxsForumModel::SORT_MODE_CHILDREN_PUBLISH_TS); mThreadModel->setSortMode(RsGxsForumModel::SORT_MODE_CHILDREN_PUBLISH_TS);
else else
mThreadModel->setSortMode(RsGxsForumModel::SORT_MODE_PUBLISH_TS); 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) void GxsForumThreadWidget::filterColumnChanged(int column)
@ -1868,67 +1883,72 @@ void GxsForumThreadWidget::filterItems(const QString& text)
void GxsForumThreadWidget::postForumLoading() void GxsForumThreadWidget::postForumLoading()
{ {
if(groupId().isNull()) if(groupId().isNull())
{ {
ui->nextUnreadButton->setEnabled(false); ui->nextUnreadButton->setEnabled(false);
return; return;
} }
#ifdef DEBUG_FORUMS #ifdef DEBUG_FORUMS
std::cerr << "Post forum loading..." << std::endl; std::cerr << "Post forum loading..." << std::endl;
#endif #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 #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 #endif
QModelIndex source_index = mThreadModel->getIndexOfMessage(mNavigatePendingMsgId); QModelIndex source_index = mThreadModel->getIndexOfMessage(mLastSelectedPosts[groupId()]);
QModelIndex index = mThreadProxyModel->mapFromSource(source_index); QModelIndex index = mThreadProxyModel->mapFromSource(source_index);
ui->threadTreeWidget->selectionModel()->setCurrentIndex(index,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); ui->threadTreeWidget->selectionModel()->setCurrentIndex(index,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
ui->threadTreeWidget->scrollTo(ui->threadTreeWidget->currentIndex());//May change if model reloaded ui->threadTreeWidget->scrollTo(ui->threadTreeWidget->currentIndex());//May change if model reloaded
mNavigatePendingMsgId.clear(); }
} else
else {
{
QModelIndex source_index = mThreadModel->getIndexOfMessage(mThreadId); QModelIndex source_index = mThreadModel->getIndexOfMessage(mThreadId);
if(!mThreadId.isNull() && source_index.isValid()) if(!mThreadId.isNull() && source_index.isValid())
{ {
QModelIndex index = mThreadProxyModel->mapFromSource(source_index); QModelIndex index = mThreadProxyModel->mapFromSource(source_index);
ui->threadTreeWidget->selectionModel()->setCurrentIndex(index,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); ui->threadTreeWidget->selectionModel()->setCurrentIndex(index,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
ui->threadTreeWidget->scrollTo(ui->threadTreeWidget->currentIndex());//May change if model reloaded ui->threadTreeWidget->scrollTo(ui->threadTreeWidget->currentIndex());//May change if model reloaded
#ifdef DEBUG_FORUMS #ifdef DEBUG_FORUMS
std::cerr << " re-selecting index of message " << mThreadId << " to " << source_index.row() << "," << source_index.column() << " " << (void*)source_index.internalPointer() << std::endl; std::cerr << " re-selecting index of message " << mThreadId << " to " << source_index.row() << "," << source_index.column() << " " << (void*)source_index.internalPointer() << std::endl;
#endif #endif
} }
else else
{ {
#ifdef DEBUG_FORUMS #ifdef DEBUG_FORUMS
std::cerr << " previously message " << mThreadId << " not visible anymore -> de-selecting" << std::endl; std::cerr << " previously message " << mThreadId << " not visible anymore -> de-selecting" << std::endl;
#endif #endif
ui->threadTreeWidget->selectionModel()->clear(); ui->threadTreeWidget->selectionModel()->clear();
ui->threadTreeWidget->selectionModel()->reset(); ui->threadTreeWidget->selectionModel()->reset();
mThreadId.clear(); mThreadId.clear();
//blank(); //blank();
} }
// we also need to restore expanded threads // we also need to restore expanded threads
} }
ui->newthreadButton->show(); ui->newthreadButton->show();
ui->forumName->setText(QString::fromUtf8(mForumGroup.mMeta.mGroupName.c_str())); ui->forumName->setText(QString::fromUtf8(mForumGroup.mMeta.mGroupName.c_str()));
ui->threadTreeWidget->sortByColumn(RsGxsForumModel::COLUMN_THREAD_DATE, Qt::DescendingOrder); ui->threadTreeWidget->sortByColumn(RsGxsForumModel::COLUMN_THREAD_DATE, Qt::DescendingOrder);
ui->threadTreeWidget->update(); ui->threadTreeWidget->update();
ui->viewBox->setEnabled(true); ui->viewBox->setEnabled(true);
ui->filterLineEdit->setEnabled(true); ui->filterLineEdit->setEnabled(true);
recursRestoreExpandedItems(mThreadProxyModel->mapFromSource(mThreadModel->root()),mSavedExpandedMessages); recursRestoreExpandedItems(mThreadProxyModel->mapFromSource(mThreadModel->root()),mSavedExpandedMessages);
//mUpdating = false; //mUpdating = false;
ui->nextUnreadButton->setEnabled(true); ui->nextUnreadButton->setEnabled(true);
} }
void GxsForumThreadWidget::updateGroupData() void GxsForumThreadWidget::updateGroupData()

View File

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