keep focus on current item when changing view mode

This commit is contained in:
csoler 2020-08-29 14:13:03 +02:00
parent f17fae4519
commit 11ecd6fbd1
2 changed files with 26 additions and 0 deletions

View File

@ -460,8 +460,29 @@ void GxsChannelPostsWidgetWithModel::postContextMenu(const QPoint&)
menu.exec(QCursor::pos());
}
RsGxsMessageId GxsChannelPostsWidgetWithModel::getCurrentItemId() const
{
RsGxsMessageId selected_msg_id ;
QModelIndex index = ui->postsTree->selectionModel()->currentIndex();
if(index.isValid())
selected_msg_id = index.data(Qt::UserRole).value<RsGxsChannelPost>().mMeta.mMsgId ;
return selected_msg_id;
}
void GxsChannelPostsWidgetWithModel::selectItem(const RsGxsMessageId& msg_id)
{
auto index = mChannelPostsModel->getIndexOfMessage(msg_id);
ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect);
ui->postsTree->scrollTo(index);//May change if model reloaded
}
void GxsChannelPostsWidgetWithModel::switchView()
{
auto msg_id = getCurrentItemId();
if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID)
{
whileBlocking(ui->list_TB)->setChecked(true);
@ -484,6 +505,9 @@ void GxsChannelPostsWidgetWithModel::switchView()
for(int i=0;i<mChannelPostsModel->columnCount();++i)
ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(i,font(),ui->postsTree->width()));
selectItem(msg_id);
ui->postsTree->setFocus();
ui->postsTree->dataChanged(QModelIndex(),QModelIndex()); // forces update of the whole tree
}

View File

@ -159,6 +159,8 @@ public slots:
private:
void processSettings(bool load);
RsGxsMessageId getCurrentItemId() const;
void selectItem(const RsGxsMessageId& msg_id);
void setAutoDownload(bool autoDl);
static bool filterItem(FeedItem *feedItem, const QString &text, int filter);