ProjectExplorer: Improve issues pane behavior

... when the user clicks a link. Apparently, the (unintended?) default
item view behavior is to move the scrollbar so that the top of the
current item becomes visible, which we don't want here.

Fixes: QTCREATORBUG-25101
Change-Id: I4c99ff09ba762b7b375b0bdefd8cebfbda69b0ea
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2020-12-16 17:41:28 +01:00
parent 4654550ff4
commit 74b773e68f

View File

@@ -78,6 +78,7 @@ class TaskView : public Utils::ListView
{ {
public: public:
TaskView(QWidget *parent = nullptr); TaskView(QWidget *parent = nullptr);
void setCurrentAndScrollTo(const QModelIndex &index);
~TaskView() override; ~TaskView() override;
private: private:
@@ -202,6 +203,7 @@ TaskView::TaskView(QWidget *parent)
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
setMouseTracking(true); setMouseTracking(true);
setAutoScroll(false); // QTCREATORBUG-25101
QFontMetrics fm(font()); QFontMetrics fm(font());
int vStepSize = fm.height() + 3; int vStepSize = fm.height() + 3;
@@ -211,6 +213,12 @@ TaskView::TaskView(QWidget *parent)
verticalScrollBar()->setSingleStep(vStepSize); verticalScrollBar()->setSingleStep(vStepSize);
} }
void TaskView::setCurrentAndScrollTo(const QModelIndex &index)
{
scrollTo(index);
setCurrentIndex(index);
}
TaskView::~TaskView() = default; TaskView::~TaskView() = default;
void TaskView::resizeEvent(QResizeEvent *e) void TaskView::resizeEvent(QResizeEvent *e)
@@ -553,7 +561,7 @@ void TaskWindow::showTask(unsigned int id)
int sourceRow = d->m_model->rowForId(id); int sourceRow = d->m_model->rowForId(id);
QModelIndex sourceIdx = d->m_model->index(sourceRow, 0); QModelIndex sourceIdx = d->m_model->index(sourceRow, 0);
QModelIndex filterIdx = d->m_filter->mapFromSource(sourceIdx); QModelIndex filterIdx = d->m_filter->mapFromSource(sourceIdx);
d->m_listview->setCurrentIndex(filterIdx); d->m_listview->setCurrentAndScrollTo(filterIdx);
popup(Core::IOutputPane::ModeSwitch); popup(Core::IOutputPane::ModeSwitch);
} }
@@ -682,7 +690,7 @@ void TaskWindow::setFocus()
if (d->m_filter->rowCount()) { if (d->m_filter->rowCount()) {
d->m_listview->setFocus(); d->m_listview->setFocus();
if (d->m_listview->currentIndex() == QModelIndex()) if (d->m_listview->currentIndex() == QModelIndex())
d->m_listview->setCurrentIndex(d->m_filter->index(0,0, QModelIndex())); d->m_listview->setCurrentAndScrollTo(d->m_filter->index(0,0, QModelIndex()));
} }
} }
@@ -715,7 +723,7 @@ void TaskWindow::goToNext()
} else { } else {
currentIndex = d->m_filter->index(0, 0); currentIndex = d->m_filter->index(0, 0);
} }
d->m_listview->setCurrentIndex(currentIndex); d->m_listview->setCurrentAndScrollTo(currentIndex);
triggerDefaultHandler(currentIndex); triggerDefaultHandler(currentIndex);
} }
@@ -738,7 +746,7 @@ void TaskWindow::goToPrev()
} else { } else {
currentIndex = d->m_filter->index(0, 0); currentIndex = d->m_filter->index(0, 0);
} }
d->m_listview->setCurrentIndex(currentIndex); d->m_listview->setCurrentAndScrollTo(currentIndex);
triggerDefaultHandler(currentIndex); triggerDefaultHandler(currentIndex);
} }