23 #ifndef SUIT_SHORTCUTMGR_H
24 #define SUIT_SHORTCUTMGR_H
30 #include <QKeySequence>
31 #include <QStringList>
45 #pragma warning( disable: 4251 )
52 #ifdef SHORTCUT_MGR_DBG
76 std::set<QString> getIDsOfInterferingModules(
const QString& theModuleID)
const;
78 std::set<QString> getIDsOfAllModules()
const;
93 std::set<std::pair<QString, QString>> setShortcut(
95 const QString& theInModuleActionID,
96 const QKeySequence& theKeySequence,
105 std::set<std::pair<QString, QString>> getConflicts(
107 const QString& theInModuleActionID,
108 const QKeySequence& theKeySequence
113 const QKeySequence& getKeySequence(QString theModuleID,
const QString& theInModuleActionID)
const;
117 bool hasShortcut(QString theModuleID,
const QString& theInModuleActionID)
const;
120 const std::map<QString, QKeySequence>& getModuleShortcutsInversed(
const QString& theModuleID)
const;
124 const std::map<QString, QKeySequence> getModuleShortcutsInversed(
const QString& theModuleID,
const QString& theInModuleActionIDPrefix)
const;
134 std::map<QString, std::map<QString, std::pair<QKeySequence, QKeySequence>>> merge(
137 bool theTreatAbsentIncomingAsDisabled =
false
140 bool hasKeySequence(
const QString& theModuleID,
const QKeySequence& theKeySequence)
const;
143 QString toString()
const;
175 bool fromJSON(
const QJsonObject& theJsonObject);
176 void toJSON(QJsonObject& oJsonObject)
const;
193 const std::map<QString, std::shared_ptr<SUIT_ShortcutItemAssets>>& children()
const;
199 std::shared_ptr<SUIT_ShortcutItemAssets> findDescendantItem(
const QString& theRelativeID)
const;
207 std::shared_ptr<SUIT_ShortcutItemAssets> descendantItem(
const QString& theRelativeID,
bool theIsAction =
true);
215 bool fromJSONOwnProps(
const QJsonObject& theJsonObject,
const std::set<QString>& theLangs = {});
221 bool fromJSON(
const QJsonObject& theJsonObject,
bool theParseDescendants =
true,
const std::set<QString>& theLangs = {});
227 bool fromJSON(
const QJsonObject& theJsonObject,
const QString& theRelativeID,
const std::set<QString>& theLangs = {});
229 void toJSON(QJsonObject& oJsonObject)
const;
245 void loadIcon(
bool theReload =
false);
254 void forEachDescendant(
const std::function<
void(std::shared_ptr<SUIT_ShortcutItemAssets>)>& theFunc)
const;
257 void forEachDescendant(
const std::function<
void(std::shared_ptr<const SUIT_ShortcutItemAssets>)>& theFunc)
const;
259 QString toString()
const;
262 QStringList getLangs()
const;
263 void clearAllLangsExcept(
const QString& theLang);
270 virtual const QString&
bestName(
const QString& theLang = QString())
const = 0;
275 virtual const QString& bestToolTip(
const QString& theLang = QString())
const;
288 std::map<QString, std::shared_ptr<SUIT_ShortcutItemAssets>>
myChildren;
301 static std::shared_ptr<SUIT_ShortcutModuleAssets> create(
const QString& theModuleID);
310 const QString& bestName(
const QString& theLang = QString())
const;
312 QString description()
const;
324 static void loadDefaultIcons();
336 SUIT_ShortcutItemAssets(std::shared_ptr<SUIT_ShortcutModuleAssets> theModule,
const QString& theIDLastToken,
bool theIsAction =
true);
340 SUIT_ShortcutItemAssets(std::shared_ptr<SUIT_ShortcutItemAssets> theParentItem,
const QString& theIDLastToken,
bool theIsAction =
true);
343 static std::shared_ptr<SUIT_ShortcutItemAssets> create(std::shared_ptr<SUIT_ShortcutAssets> theParentItemOrModule,
const QString& theIDLastToken,
bool theIsAction =
true);
365 const QString&
bestName(
const QString& theLang = QString())
const;
368 const QString& bestPath(
const QString theLang = QString())
const;
372 bool isAction()
const;
373 bool isFolder()
const;
374 std::shared_ptr<SUIT_ShortcutAssets> parent()
const;
375 std::shared_ptr<SUIT_ShortcutModuleAssets> module()
const;
378 QString actionID()
const;
381 const QIcon& icon()
const;
502 static bool isKeySequenceValid(
const QKeySequence& theKeySequence);
505 static std::pair<bool, QKeySequence> toKeySequenceIfValid(
const QString& theKeySequenceString);
509 static bool isModuleIDValid(
const QString& theModuleID);
511 static bool isInModuleIDTokenValid(
const QString& theInModuleIDToken);
513 static bool isInModuleIDTokenMeta(
const QString& theInModuleIDToken);
519 static bool isInModuleActionIDValid(
const QString& theInModuleActionID);
522 static bool isInModuleMetaActionID(
const QString& theInModuleActionID);
527 static std::pair<QString, QString> splitIntoModuleIDAndInModuleID(
const QString& theActionID);
530 static QStringList splitIntoTokens(
const QString& theRelativeID);
533 static QString joinIntoRelativeID(
const QStringList& theTokens);
536 static bool isActionIDValid(
const QString& theActionID);
540 static QString makeActionID(
const QString& theModuleID,
const QString& theInModuleActionID);
550 static void fillContainerFromPreferences(
SUIT_ShortcutContainer& theContainer,
bool theDefaultOnly,
const QString& theSectionNamePrefix);
555 static std::pair<std::shared_ptr<SUIT_ShortcutModuleAssets>, std::shared_ptr<SUIT_ShortcutItemAssets>>
556 getActionAssetsFromResources(
const QString& theActionID,
const std::set<QString>& theLangs = {});
559 static QString currentLang();
563 void registerAction(
const QString& theActionID,
QAction* theAction);
566 void registerAction(
QtxAction* theAction);
569 std::set<QAction*> getActions(
const QString& theModuleID,
const QString& theInModuleActionID)
const;
573 std::pair<QString, QString> getModuleIDAndInModuleID(
const QAction* theAction)
const;
576 bool hasAction(
const QAction* theAction)
const;
580 QString getActionID(
const QAction* theAction)
const;
584 void setActionsOfModuleEnabled(
const QString& theModuleID,
const bool theEnable =
true)
const;
586 [[deprecated(
"Use setActionsOfModuleEnabled(const QString&, bool) instead.")]]
587 void setSectionEnabled(
const QString& theInModuleActionIDPrefix,
bool theEnable =
true)
const;
591 void setActionsWithPrefixInIDEnabled(
const QString& theInModuleActionIDPrefix,
bool theEnable =
true)
const;
594 void rebindActionsToKeySequences()
const;
596 [[deprecated(
"Use rebindActionsToKeySequences() instead.")]]
597 void updateShortcuts()
const;
609 std::set<std::pair<QString, QString>> setShortcut(
const QString& theActionID,
const QKeySequence& theKeySequence,
bool theOverride =
false);
610 std::set<std::pair<QString, QString>> setShortcut(
const QString& theModuleID,
const QString& theInModuleActionID,
const QKeySequence& theKeySequence,
bool theOverride =
false);
615 void mergeShortcutContainer(
const SUIT_ShortcutContainer& theContainer,
bool theOverride =
true,
bool theTreatAbsentIncomingAsDisabled =
false,
bool theSaveToPreferences =
true);
618 const QKeySequence& getKeySequence(
const QString& theModuleID,
const QString& theInModuleActionID)
const;
621 const std::map<QString, QKeySequence>& getModuleShortcutsInversed(
const QString& theModuleID)
const;
624 std::set<QString> getShortcutModuleIDs()
const;
628 std::set<QString> getIDsOfInterferingModules(
const QString& theModuleID)
const;
630 std::shared_ptr<const SUIT_ShortcutModuleAssets> getModuleAssets(
const QString& theModuleID)
const;
631 const std::map<QString, std::shared_ptr<SUIT_ShortcutModuleAssets>>&
getModuleAssets()
const {
return myModuleAssets; }
634 QString getModuleName(
const QString& theModuleID,
const QString& theLang =
"")
const;
636 std::shared_ptr<const SUIT_ShortcutItemAssets> getActionAssets(
const QString& theModuleID,
const QString& theInModuleActionID,
bool theTryToCreateRuntimeAssetsIfAbsent =
true)
const;
638 std::shared_ptr<const SUIT_ShortcutItemAssets> getActionAssets(
const QString& theActionID,
bool theTryToCreateRuntimeAssetsIfAbsent =
true)
const;
641 std::shared_ptr<const SUIT_ShortcutItemAssets> createRuntimeActionAssets(
const QString& theModuleID,
const QString& theInModuleActionID)
const;
644 QString getActionName(
const QString& theModuleID,
const QString& theInModuleActionID,
const QString& theLang =
"")
const;
647 QtxAction* createAction(
QObject* theParent,
QObject* theReceiver,
const char* theReceiverSlot,
const QString& theActionID,
const bool theIsToggle =
false)
const;
655 void onActionDestroyed(
QObject* theObject);
657 void onAnonymousActionDestroyed(
QObject* theObject);
662 virtual bool eventFilter(
QObject* theObject,
QEvent* theEvent);
665 std::set<std::pair<QString, QString>> setShortcutNoIDChecks(
const QString& theModuleID,
const QString& theInModuleActionID,
const QKeySequence& theKeySequence,
bool theOverride);
697 void setShortcutsFromPreferences();
701 static void saveShortcutsToPreferences(
const std::map<QString, std::map<QString, QKeySequence>>& theShortcutsInversed);
706 static void saveShortcutsToPreferences(
const std::map<QString, std::map<QString, std::pair<QKeySequence, QKeySequence>>>& theShortcutsInversed);
761 void setAssetsFromResources(QString theLanguage = QString());
763 void registerAnonymousShortcut(
QAction*
const theAction);
764 void enableAnonymousShortcutsClashingWith(
const QString& theModuleID,
const bool theEnable)
const;
765 void enableAnonymousShortcutsClashingWith(
const QKeySequence& theKeySequence,
bool theEnable)
const;
766 QString anonymousShortcutsToString()
const;
772 std::map<QString, std::map<QString, std::set<QAction*>>>
myActions;
786 mutable std::map<QString, std::shared_ptr<SUIT_ShortcutModuleAssets>>
myModuleAssets;
878 static bool isPairOfNewAndOldActionIDsValid(
const QString& theSectionPrefixNew,
const QString& theSectionPrefixOld);
880 AIDSMutation(
const QString& theSectionPrefixNew,
const QString& theSectionPrefixOld);
881 AIDSMutation(
const QJsonObject& theJsonObject,
const bool theParseMap =
true);
914 bool doOldShortcutPreferencesExist()
const;
918 QString getActionID(
const QString& theOldActionID,
const QString& theOldSectionPrefix)
const;
923 std::pair<bool, QKeySequence> getOldUserDefinedKeySequence(
const QString& theActionID)
const;
928 void removeOldShortcutPreferences();
931 void parseMutations();
936 std::pair<bool, QKeySequence> getKeySequenceFromSection(
const QString& theActionID,
const QString& theSectionPrefix)
const;
972 AssetsAndSearchData(std::shared_ptr<const SUIT_ShortcutItemAssets> theAssets =
nullptr,
double theMatchMetrics = std::numeric_limits<double>::infinity());
974 void setMatchMetrics(
double theMatchMetrics);
977 std::shared_ptr<const SUIT_ShortcutItemAssets>
myAssets;
979 void toJSON(QJsonObject& oJsonObject)
const;
980 QString toString()
const;
988 static double matchKeySequenceString(
const QString& theQuery,
const QString& theKeySequence);
1005 bool setIncludedModuleIDs(std::set<QString> theIncludedModuleIDs,
bool doNotUpdateResults =
false);
1009 bool includeDisabledActions(
bool theOn,
bool doNotUpdateResults =
false);
1014 bool setFieldsToMatch(
const std::set<SUIT_ActionSearcher::MatchField>& theFields,
bool doNotUpdateResults =
false);
1019 std::pair<bool, bool> setKeySequenceGetter(
1020 const std::function<QString(
const QString&,
const QString&)>& theKeySequenceGetter = std::function<QString(
const QString&,
const QString&)>(),
1021 bool doNotUpdateResults =
false
1026 bool setCaseSensitive(
bool theOn,
bool doNotUpdateResults =
false);
1029 bool setQuery(
const QString& theQuery);
1030 inline const QString& getQuery()
const;
1032 const std::map<QString, std::map<QString, SUIT_ActionSearcher::AssetsAndSearchData>>& getSearchResults()
const;
1038 std::pair<bool, bool> filter();
1042 std::pair<bool, bool> filterResults();
1046 bool extendResults();
1050 QString toString()
const;
1063 std::map<QString, std::map<QString, SUIT_ActionSearcher::AssetsAndSearchData>>
mySearchResults;
1068 #pragma warning( default: 4251 )
#define SUIT_EXPORT
Definition: SUIT.h:36
bool ShCutDbg()
Definition: SUIT_ShortcutMgr.h:51
For more information see QT documentation.
Definition: SUIT_Application.h:42
Generic action class.
Definition: QtxAction.h:39
Definition: SUIT_ShortcutMgr.h:970
double myMatchMetrics
Ideally it should be number of weighted character permutations. Now it is just a number of characters...
Definition: SUIT_ShortcutMgr.h:984
std::shared_ptr< const SUIT_ShortcutItemAssets > myAssets
Definition: SUIT_ShortcutMgr.h:975
double matchMetrics() const
Definition: SUIT_ShortcutMgr.h:975
Searches in data, provided in action asset files and shortcut preferences.
Definition: SUIT_ShortcutMgr.h:960
SUIT_ActionSearcher(const SUIT_ActionSearcher &)=delete
std::set< SUIT_ActionSearcher::MatchField > myFieldsToMatch
Definition: SUIT_ShortcutMgr.h:1056
std::set< QString > myIncludedModuleIDs
Definition: SUIT_ShortcutMgr.h:1053
bool areDisabledActionsIncluded() const
Definition: SUIT_ShortcutMgr.h:1010
std::function< QString(const QString &, const QString &)> myKeySequenceGetter
Definition: SUIT_ShortcutMgr.h:1060
::SUIT_tools::SUIT_SentenceMatcher * myMatcher
Definition: SUIT_ShortcutMgr.h:1057
SUIT_ActionSearcher & operator=(const SUIT_ActionSearcher &)=delete
bool myIncludeDisabledActions
Definition: SUIT_ShortcutMgr.h:1054
std::map< QString, std::map< QString, SUIT_ActionSearcher::AssetsAndSearchData > > mySearchResults
Definition: SUIT_ShortcutMgr.h:1063
MatchField
Definition: SUIT_ShortcutMgr.h:962
@ ToolTip
Definition: SUIT_ShortcutMgr.h:965
@ ID
Definition: SUIT_ShortcutMgr.h:963
@ Name
Definition: SUIT_ShortcutMgr.h:964
Base class for GUI-related assets of module, action or folder. Used by Shortcut Manager,...
Definition: SUIT_ShortcutMgr.h:161
virtual const QString & bestName(const QString &theLang=QString()) const =0
static const QString PROP_ID_CHILDREN
Definition: SUIT_ShortcutMgr.h:185
virtual bool fromJSONOtherProps(const QJsonObject &theJsonObject)
Parses properties of SUIT_ShortcutAssets subclasses.
Definition: SUIT_ShortcutMgr.h:240
virtual int depth() const =0
std::map< QString, LangDependentAssets > myLangDependentAssets
Definition: SUIT_ShortcutMgr.h:280
std::map< QString, std::shared_ptr< SUIT_ShortcutItemAssets > > myChildren
Definition: SUIT_ShortcutMgr.h:288
QString myIconPath
Definition: SUIT_ShortcutMgr.h:281
virtual QString description() const =0
const QString myModuleID
Definition: SUIT_ShortcutMgr.h:278
Type
Definition: SUIT_ShortcutMgr.h:164
virtual void merge(const SUIT_ShortcutAssets &theOther, bool theOverride)
Definition: SUIT_ShortcutMgr.cxx:1080
virtual SUIT_ShortcutAssets::Type type() const =0
QIcon myIcon
Definition: SUIT_ShortcutMgr.h:284
static const QString PROP_ID_ICON_PATH
Definition: SUIT_ShortcutMgr.h:184
static const QString PROP_ID_LANG_DEPENDENT_ASSETS
Definition: SUIT_ShortcutMgr.h:183
virtual void toJSONVirtual(QJsonObject &oJsonObject) const
Definition: SUIT_ShortcutMgr.h:242
Provides means to keep and edit shortcuts in compliance with the application logics....
Definition: SUIT_ShortcutMgr.h:70
std::map< QString, std::map< QString, QKeySequence > > myShortcutsInversed
{ moduleID, { inModuleActionID, keySequence }[] }[].
Definition: SUIT_ShortcutMgr.h:152
std::map< QString, std::map< QKeySequence, QString > > myShortcuts
{ moduleID, { keySequence, inModuleActionID }[] }[].
Definition: SUIT_ShortcutMgr.h:148
Describes how action IDs evolved between consequtive versions of action ID sets. PS....
Definition: SUIT_ShortcutMgr.h:871
std::map< QString, QString > myOldToNewActionIDMap
The map only keeps changes between AIDS versions.
Definition: SUIT_ShortcutMgr.h:907
static const QString PROP_ID_PREFIX_NEW
Definition: SUIT_ShortcutMgr.h:875
static const QString PROP_ID_PREFIX_OLD
Definition: SUIT_ShortcutMgr.h:874
QString mySectionPrefixNew
New name prefix of a section in user preference files.
Definition: SUIT_ShortcutMgr.h:899
static const QString PROP_ID_OLD_TO_NEW_ACTION_ID_MAP
Definition: SUIT_ShortcutMgr.h:876
std::map< QString, QString > myNewToOldActionIDMap
The map only keeps changes between AIDS versions.
Definition: SUIT_ShortcutMgr.h:903
const std::map< QString, QString > & getNewToOldActionIDMap() const
Definition: SUIT_ShortcutMgr.h:885
const QString & getSectionPrefixOld() const
Definition: SUIT_ShortcutMgr.h:883
const std::map< QString, QString > & getOldToNewActionIDMap() const
Definition: SUIT_ShortcutMgr.h:886
const QString & getSectionPrefixNew() const
Definition: SUIT_ShortcutMgr.h:884
QString mySectionPrefixOld
Old name prefix of a section in user preference files.
Definition: SUIT_ShortcutMgr.h:896
static const QString PROP_ID_MUTATIONS
Definition: SUIT_ShortcutMgr.h:873
Sometimes developers change IDs of actions. And at the moment of release of these changes users may a...
Definition: SUIT_ShortcutMgr.h:861
std::map< QString, SUIT_ShortcutContainer > myShortcutContainers
{sectionNamePrefixOld, shortcutContainer}[].
Definition: SUIT_ShortcutMgr.h:943
const SUIT_ShortcutContainer & getContainerWithOldShortcuts() const
Definition: SUIT_ShortcutMgr.h:925
SUIT_ShortcutContainer myShortcutContainer
Merged myShortcutContainers.
Definition: SUIT_ShortcutMgr.h:946
std::list< std::pair< QString, SUIT_ShortcutHistorian::AIDSMutation > > myOldPrefixToMutationList
{sectionNamePrefixOld, mutation}[].
Definition: SUIT_ShortcutMgr.h:940
static const std::vector< QString > SECTION_PREFIX_EVOLUTION
{name prefix of a section in user preference files}[].
Definition: SUIT_ShortcutMgr.h:865
May represent not just an action, but also a folder within item tree of a module. May also represent ...
Definition: SUIT_ShortcutMgr.h:320
static QIcon DEFAUT_ICON_FOLDER
Definition: SUIT_ShortcutMgr.h:329
std::weak_ptr< SUIT_ShortcutAssets > myParent
Definition: SUIT_ShortcutMgr.h:384
std::map< QString, QString > myBestPaths
{lang, bestPath}[]
Definition: SUIT_ShortcutMgr.h:396
const QString myInModuleID
Definition: SUIT_ShortcutMgr.h:390
SUIT_ShortcutItemAssets(const SUIT_ShortcutItemAssets &)=delete
~SUIT_ShortcutItemAssets()=default
static QIcon DEFAUT_ICON_FOLDER_ACTION
Definition: SUIT_ShortcutMgr.h:330
bool myIsAction
Definition: SUIT_ShortcutMgr.h:386
static QIcon DEFAUT_ICON_ACTION
Definition: SUIT_ShortcutMgr.h:328
const int myDepth
Definition: SUIT_ShortcutMgr.h:393
SUIT_ShortcutAssets::Type type() const
Definition: SUIT_ShortcutMgr.h:349
static const QString PROP_ID_IS_ACTION
Definition: SUIT_ShortcutMgr.h:325
const QString myIDLastToken
Definition: SUIT_ShortcutMgr.h:389
Handles action shortcut customization.
Definition: SUIT_ShortcutMgr.h:482
std::map< QString, std::map< QString, std::set< QAction * > > > myActions
{ moduleID, { inModuleActionID, action[] }[] }[].
Definition: SUIT_ShortcutMgr.h:772
std::map< QKeySequence, std::set< QAction * > > myAnonymousShortcutsInverse
Definition: SUIT_ShortcutMgr.h:799
const std::map< QString, std::shared_ptr< SUIT_ShortcutModuleAssets > > & getModuleAssets() const
Definition: SUIT_ShortcutMgr.h:631
std::map< QString, std::shared_ptr< SUIT_ShortcutModuleAssets > > myModuleAssets
{moduleID, moduleAssets}[].
Definition: SUIT_ShortcutMgr.h:786
SUIT_ShortcutMgr & operator=(const SUIT_ShortcutMgr &)=delete
std::map< QAction *, std::pair< QString, QString > > myActionIDs
{ action, { moduleID, inModuleActionID } }[].
Definition: SUIT_ShortcutMgr.h:775
SUIT_ShortcutMgr(const SUIT_ShortcutMgr &)=delete
static SUIT_ShortcutMgr * myShortcutMgr
Definition: SUIT_ShortcutMgr.h:769
std::map< QAction *, QKeySequence > myAnonymousShortcuts
Actions without IDs, but with hard-coded non-empty key sequences.
Definition: SUIT_ShortcutMgr.h:797
SUIT_ShortcutContainer myShortcutContainer
Can not contain entries like { <non-root module ID>, { <meta-action ID>, actions[] } }.
Definition: SUIT_ShortcutMgr.h:778
std::set< QString > myActiveModuleIDs
Definition: SUIT_ShortcutMgr.h:791
bool myAssetsLoaded
True, if SUIT_ShortcutMgr::setAssetsFromResources(QString) was called.
Definition: SUIT_ShortcutMgr.h:789
static const QString ROOT_MODULE_ID
Definition: SUIT_ShortcutMgr.h:494
GUI-related module assets.
Definition: SUIT_ShortcutMgr.h:294
int depth() const
Definition: SUIT_ShortcutMgr.h:304
SUIT_ShortcutAssets::Type type() const
Definition: SUIT_ShortcutMgr.h:305
~SUIT_ShortcutModuleAssets()=default
SUIT_ShortcutModuleAssets(const SUIT_ShortcutModuleAssets &)=delete
Definition: SUIT_ShortcutMgr.h:171
QString myName
Definition: SUIT_ShortcutMgr.h:178
QString myToolTip
Definition: SUIT_ShortcutMgr.h:179
static const QString PROP_ID_TOOLTIP
Definition: SUIT_ShortcutMgr.h:173
static const QString PROP_ID_NAME
Definition: SUIT_ShortcutMgr.h:172