mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-11 23:49:38 -05:00
keep focus on current item when changing view mode
This commit is contained in:
parent
f17fae4519
commit
11ecd6fbd1
@ -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
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user