ClangTools: Go to location on enter/space

Change-Id: I865a445207bf161213761b607f1f447b79ef7359
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Nikolai Kosjar
2018-05-11 10:01:22 +02:00
parent 23df884f4a
commit 1251eb87bb
2 changed files with 24 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ DiagnosticView::DiagnosticView(QWidget *parent)
m_suppressAction = new QAction(tr("Suppress This Diagnostic"), this);
connect(m_suppressAction, &QAction::triggered,
this, &DiagnosticView::suppressCurrentDiagnostic);
installEventFilter(this);
}
void DiagnosticView::suppressCurrentDiagnostic()
@@ -80,5 +81,27 @@ QList<QAction *> DiagnosticView::customActions() const
return QList<QAction *>() << m_suppressAction;
}
bool DiagnosticView::eventFilter(QObject *watched, QEvent *event)
{
switch (event->type()) {
case QEvent::KeyRelease: {
const int key = static_cast<QKeyEvent *>(event)->key();
switch (key) {
case Qt::Key_Return:
case Qt::Key_Enter:
case Qt::Key_Space:
const QModelIndex current = currentIndex();
const QModelIndex location = model()->index(current.row(),
LocationColumn,
current.parent());
emit clicked(location);
}
return true;
}
default:
return QObject::eventFilter(watched, event);
}
}
} // namespace Internal
} // namespace ClangTools

View File

@@ -41,6 +41,7 @@ private:
void suppressCurrentDiagnostic();
QList<QAction *> customActions() const;
bool eventFilter(QObject *watched, QEvent *event) override;
QAction *m_suppressAction;
};