#4176 Add feature to cafCmdFeatureManager to find commands matching a keyboard shortcut

This commit is contained in:
Gaute Lindkvist 2019-03-27 10:27:38 +01:00
parent ab3820fe4f
commit f066829a0f
2 changed files with 26 additions and 1 deletions

View File

@ -45,6 +45,7 @@
#include "defaultfeatures/cafCmdAddItemFeature.h"
#include <QAction>
#include <QKeySequence>
namespace caf
{
@ -313,4 +314,27 @@ std::vector<CmdFeature*> CmdFeatureManager::commandFeaturesMatchingSubString(con
return matches;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<CmdFeature*> CmdFeatureManager::commandFeaturesMatchingKeyboardShortcut(const QKeySequence& keySequence) const
{
std::vector<CmdFeature*> matches;
std::vector<std::string> keys = CommandFeatureFactory::instance()->allKeys();
for (size_t i = 0; i < keys.size(); i++)
{
caf::CmdFeature* cmdFeature = commandFeature(keys[i]);
if (cmdFeature)
{
if (cmdFeature->action()->shortcut().matches(keySequence) == QKeySequence::ExactMatch)
{
matches.push_back(cmdFeature);
}
}
}
return matches;
}
} // end namespace caf

View File

@ -45,6 +45,7 @@
#include <QStringList>
class QAction;
class QKeySequence;
namespace caf
{
@ -72,7 +73,7 @@ public:
CmdFeature* getCommandFeature(const std::string& commandId);
std::vector<CmdFeature*> commandFeaturesMatchingSubString(const std::string& subString) const;
std::vector<CmdFeature*> commandFeaturesMatchingKeyboardShortcut(const QKeySequence& keySequence) const;
private:
CmdFeatureManager();