diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-02-24 10:51:50 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-24 10:24:25 +0000 |
commit | 4c93b7fa36968daf589221085208ab36018638db (patch) | |
tree | bc081b3dd23d82ad23b124a3c03565f20eb6d777 | |
parent | 2e850459b790533237bdf1a1cabccc3c216709f8 (diff) | |
download | qttools-4c93b7fa36968daf589221085208ab36018638db.tar.gz |
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.cpp | 1 | ||||
-rw-r--r-- | src/linguist/linguist/phraseview.cpp | 9 | ||||
-rw-r--r-- | src/linguist/linguist/phraseview.h | 27 |
3 files changed, 8 insertions, 29 deletions
diff --git a/src/linguist/linguist/mainwindow.cpp b/src/linguist/linguist/mainwindow.cpp index 63e4247ef..fb3049c01 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 |