summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-02-24 10:51:50 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-24 10:24:25 +0000
commit6f8bc64090b670e113ea126be1e83a9e1178c5e5 (patch)
tree8c6b9eeaf44f2429af366fcee548f15c90de4755
parent54aa540e1e2a14e94993ba967441fb9b18066a6b (diff)
Qt Linguist: Fix the phrase view suggestion shortcuts to work
Remove class GuessShortcut which had a bug (connect to wrong signal of QShortcut) by a lambda expression. Do not create a shortcut for phrase 10 which resulted in CTRL+':'. Change-Id: I26f35ece1bcdd2e75a56b8e4f1f69987a8054e52 Reviewed-by: Kai Koehne <kai.koehne@qt.io> (cherry picked from commit 4ad7a232cce5fd4e5ec88c2df46ca1e564772913) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/linguist/linguist/mainwindow.cpp1
-rw-r--r--src/linguist/linguist/phraseview.cpp9
-rw-r--r--src/linguist/linguist/phraseview.h27
3 files changed, 8 insertions, 29 deletions
diff --git a/src/linguist/linguist/mainwindow.cpp b/src/linguist/linguist/mainwindow.cpp
index 30d3acea0..de6fd5875 100644
--- a/src/linguist/linguist/mainwindow.cpp
+++ b/src/linguist/linguist/mainwindow.cpp
@@ -73,6 +73,7 @@
#include <QProcess>
#include <QRegularExpression>
#include <QScreen>
+#include <QShortcut>
#include <QSettings>
#include <QSortFilterProxyModel>
#include <QStackedWidget>
diff --git a/src/linguist/linguist/phraseview.cpp b/src/linguist/linguist/phraseview.cpp
index 9c7a4f966..b145b6fc9 100644
--- a/src/linguist/linguist/phraseview.cpp
+++ b/src/linguist/linguist/phraseview.cpp
@@ -37,6 +37,7 @@
#include <QHeaderView>
#include <QKeyEvent>
#include <QSettings>
+#include <QShortcut>
#include <QTreeView>
#include <QWidget>
#include <QDebug>
@@ -67,8 +68,12 @@ PhraseView::PhraseView(MultiDataModel *model, QList<QHash<QString, QList<Phrase
setRootIsDecorated(false);
setItemsExpandable(false);
- for (int i = 0; i < 10; i++)
- (void) new GuessShortcut(i, this, &PhraseView::guessShortcut);
+ for (int i = 0; i < 9; ++i) {
+ const auto key = static_cast<Qt::Key>(int(Qt::Key_1) + i);
+ auto shortCut = new QShortcut(Qt::CTRL | key, this);
+ connect(shortCut, &QShortcut::activated, this,
+ [i, this]() { this->guessShortcut(i); });
+ }
header()->setSectionResizeMode(QHeaderView::Interactive);
header()->setSectionsClickable(true);
diff --git a/src/linguist/linguist/phraseview.h b/src/linguist/linguist/phraseview.h
index 118bc250a..b21d28410 100644
--- a/src/linguist/linguist/phraseview.h
+++ b/src/linguist/linguist/phraseview.h
@@ -30,7 +30,6 @@
#define PHRASEVIEW_H
#include <QList>
-#include <QShortcut>
#include <QTreeView>
#include "phrase.h"
@@ -41,32 +40,6 @@ static const int DefaultMaxCandidates = 5;
class MultiDataModel;
class PhraseModel;
-class GuessShortcut : public QShortcut
-{
- Q_OBJECT
-public:
- template<class Obj, typename Func>
- GuessShortcut(int nkey, Obj *parent, Func member)
- : QShortcut(parent), nrkey(nkey)
- {
- const auto key = static_cast<Qt::Key>(int(Qt::Key_1) + nrkey);
- setKey(Qt::CTRL | key);
- connect(this, &GuessShortcut::activated,
- this, &GuessShortcut::keyActivated);
- connect(this, &GuessShortcut::activated,
- parent, member);
- }
-
-private slots:
- void keyActivated() { emit activated(nrkey); }
-
-signals:
- void activated(int nkey);
-
-private:
- int nrkey;
-};
-
class PhraseView : public QTreeView
{
Q_OBJECT