From 3f0f5cff99f731278968be58ffdbd4bf046b585a Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sun, 6 Mar 2022 20:44:52 +0800 Subject: [PATCH] Minor code change according to suggestions --- src/Gui/Action.cpp | 11 +++++------ src/Gui/ShortcutManager.cpp | 7 ++++--- src/Gui/Workbench.cpp | 20 -------------------- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index e81503b3c0..9c33eb0c19 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -1378,11 +1378,10 @@ struct CmdInfo { }; static std::vector _Commands; static int _CommandRevision; +static const int CommandNameRole = Qt::UserRole; class CommandModel : public QAbstractItemModel { -public: - public: CommandModel(QObject* parent) : QAbstractItemModel(parent) @@ -1450,7 +1449,7 @@ public: } return info.tooltip; - case Qt::UserRole: + case CommandNameRole: return QByteArray(info.cmd->getName()); default: @@ -1481,9 +1480,7 @@ CommandCompleter::CommandCompleter(QLineEdit *lineedit, QObject *parent) : QCompleter(parent) { this->setModel(new CommandModel(this)); -#if QT_VERSION>=QT_VERSION_CHECK(5,2,0) this->setFilterMode(Qt::MatchContains); -#endif this->setCaseSensitivity(Qt::CaseInsensitive); this->setCompletionMode(QCompleter::PopupCompletion); this->setWidget(lineedit); @@ -1547,12 +1544,14 @@ bool CommandCompleter::eventFilter(QObject *o, QEvent *ev) void CommandCompleter::onCommandActivated(const QModelIndex &index) { - QByteArray name = completionModel()->data(index, Qt::UserRole).toByteArray(); + QByteArray name = completionModel()->data(index, CommandNameRole).toByteArray(); Q_EMIT commandActivated(name); } void CommandCompleter::onTextChanged(const QString &txt) { + // Do not activate completer if less than 3 characters for better + // performance. if (txt.size() < 3 || !widget()) return; diff --git a/src/Gui/ShortcutManager.cpp b/src/Gui/ShortcutManager.cpp index 6541e395b5..a1f3f24658 100644 --- a/src/Gui/ShortcutManager.cpp +++ b/src/Gui/ShortcutManager.cpp @@ -404,6 +404,8 @@ void ShortcutManager::setTopPriority(const char *cmdName) void ShortcutManager::onTimer() { + timer.stop(); + QAction *found = nullptr; int priority = -INT_MAX; int seq_length = 0; @@ -427,8 +429,8 @@ void ShortcutManager::onTimer() if (lastFocus && lastFocus == QApplication::focusWidget()) { // We are here because we have withheld some previous triggered action. // We then disabled the action, and faked the same key strokes in order - // to wait for more for potential match of longer key sequence. We use - // a timer to end the wait and triggered the pending action. + // to wait for more potential match of longer key sequence. We use + // a timer to end the wait and trigger the pending action. // // However, Qt's internal shorcutmap state machine is still armed with // our fake key strokes. So we try to fake some more obscure symbol key @@ -449,7 +451,6 @@ void ShortcutManager::onTimer() } } } - timer.stop(); } #include "moc_ShortcutManager.cpp" diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index c72e35e264..914543943b 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -311,26 +311,6 @@ void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::ReferenceHasGroup("Shortcut")) { - hGrp = hGrp->GetGroup("Shortcut"); - // Get all user defined shortcuts - const CommandManager& cCmdMgr = Application::Instance->commandManager(); - std::vector > items = hGrp->GetASCIIMap(); - for (const auto & item : items) { - Command* cmd = cCmdMgr.getCommandByName(item.first.c_str()); - if (cmd && cmd->getAction()) { - // may be UTF-8 encoded - QString str = QString::fromUtf8(item.second.c_str()); - QKeySequence shortcut = str; - cmd->getAction()->setShortcut(shortcut.toString(QKeySequence::NativeText)); - cmd->recreateTooltip(item.first.c_str(), cmd->getAction()); // The tooltip has the shortcut in it... - } - } - } -#endif } void Workbench::setupContextMenu(const char* recipient,MenuItem* item) const