From 0078bb08022c9055a074d1f13a1ca70fa575967d Mon Sep 17 00:00:00 2001 From: con <qtc-committer@nokia.com> Date: Fri, 8 Oct 2010 13:18:35 +0200 Subject: [PATCH] Avoid use of QKeySequence::isEmpty in checks in command implementations. isEmpty is the wrong thing to check when setting the default shortcut. In addition, registering commands should not set their shortcut automatically (that should be defined solely by the default shortcut and reading the settings, which is done later). --- .../actionmanager/actionmanager.cpp | 5 ---- .../coreplugin/actionmanager/command.cpp | 27 +++++++++---------- .../coreplugin/actionmanager/command_p.h | 5 ++-- src/plugins/coreplugin/modemanager.cpp | 3 +++ 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/plugins/coreplugin/actionmanager/actionmanager.cpp b/src/plugins/coreplugin/actionmanager/actionmanager.cpp index 993555d20dd..96888ad819e 100644 --- a/src/plugins/coreplugin/actionmanager/actionmanager.cpp +++ b/src/plugins/coreplugin/actionmanager/actionmanager.cpp @@ -377,8 +377,6 @@ Command *ActionManagerPrivate::registerOverridableAction(QAction *action, const #endif a->setAction(baseAction); m_mainWnd->addAction(baseAction); - a->setKeySequence(a->keySequence()); - a->setDefaultKeySequence(QKeySequence()); } else if (checkUnique) { qWarning() << "registerOverridableAction: id" << id << "is already registered."; } @@ -417,9 +415,6 @@ Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const Id &i else sc->setContext(context); - sc->setKeySequence(shortcut->key()); - sc->setDefaultKeySequence(QKeySequence()); - return sc; } diff --git a/src/plugins/coreplugin/actionmanager/command.cpp b/src/plugins/coreplugin/actionmanager/command.cpp index 2c37d312492..ccf4ccd56ee 100644 --- a/src/plugins/coreplugin/actionmanager/command.cpp +++ b/src/plugins/coreplugin/actionmanager/command.cpp @@ -200,12 +200,14 @@ using namespace Core::Internal; */ CommandPrivate::CommandPrivate(int id) - : m_attributes(0), m_id(id) + : m_attributes(0), m_id(id), m_isKeyInitialized(false) { } void CommandPrivate::setDefaultKeySequence(const QKeySequence &key) { + if (!m_isKeyInitialized) + setKeySequence(key); m_defaultKey = key; } @@ -214,6 +216,12 @@ QKeySequence CommandPrivate::defaultKeySequence() const return m_defaultKey; } +void CommandPrivate::setKeySequence(const QKeySequence &key) +{ + Q_UNUSED(key) + m_isKeyInitialized = true; +} + void CommandPrivate::setDefaultText(const QString &text) { m_defaultText = text; @@ -306,15 +314,9 @@ Core::Context Shortcut::context() const return m_context; } -void Shortcut::setDefaultKeySequence(const QKeySequence &key) -{ - if (m_shortcut->key().isEmpty()) - setKeySequence(key); - CommandPrivate::setDefaultKeySequence(key); -} - void Shortcut::setKeySequence(const QKeySequence &key) { + CommandPrivate::setKeySequence(key); m_shortcut->setKey(key); emit keySequenceChanged(); } @@ -405,15 +407,9 @@ QList<CommandLocation> Action::locations() const return m_locations; } -void Action::setDefaultKeySequence(const QKeySequence &key) -{ - if (m_action->shortcut().isEmpty()) - setKeySequence(key); - CommandPrivate::setDefaultKeySequence(key); -} - void Action::setKeySequence(const QKeySequence &key) { + CommandPrivate::setKeySequence(key); m_action->setShortcut(key); updateToolTipWithKeySequence(); emit keySequenceChanged(); @@ -538,3 +534,4 @@ void Action::setActive(bool state) emit activeStateChanged(); } } + diff --git a/src/plugins/coreplugin/actionmanager/command_p.h b/src/plugins/coreplugin/actionmanager/command_p.h index 12ed105afdc..a7bac35da14 100644 --- a/src/plugins/coreplugin/actionmanager/command_p.h +++ b/src/plugins/coreplugin/actionmanager/command_p.h @@ -53,6 +53,8 @@ public: void setDefaultKeySequence(const QKeySequence &key); QKeySequence defaultKeySequence() const; + void setKeySequence(const QKeySequence &key); + void setDefaultText(const QString &text); QString defaultText() const; @@ -78,6 +80,7 @@ protected: int m_id; QKeySequence m_defaultKey; QString m_defaultText; + bool m_isKeyInitialized; }; class Shortcut : public CommandPrivate @@ -88,7 +91,6 @@ public: QString name() const; - void setDefaultKeySequence(const QKeySequence &key); void setKeySequence(const QKeySequence &key); QKeySequence keySequence() const; @@ -116,7 +118,6 @@ public: QString name() const; - void setDefaultKeySequence(const QKeySequence &key); void setKeySequence(const QKeySequence &key); QKeySequence keySequence() const; diff --git a/src/plugins/coreplugin/modemanager.cpp b/src/plugins/coreplugin/modemanager.cpp index 1b0a14e3298..8d086473f42 100644 --- a/src/plugins/coreplugin/modemanager.cpp +++ b/src/plugins/coreplugin/modemanager.cpp @@ -198,6 +198,9 @@ void ModeManager::objectAdded(QObject *obj) connect(cmd, SIGNAL(keySequenceChanged()), this, SLOT(updateModeToolTip())); for (int i = 0; i < d->m_modeShortcuts.size(); ++i) { Command *currentCmd = d->m_modeShortcuts.at(i); + // we need this hack with currentlyHasDefaultSequence + // because we call setDefaultShortcut multiple times on the same cmd + // and still expect the current shortcut to change with it bool currentlyHasDefaultSequence = (currentCmd->keySequence() == currentCmd->defaultKeySequence()); #ifdef Q_WS_MAC -- GitLab