Handles action shortcut customization. More...
#include <SUIT_ShortcutMgr.h>

Public Member Functions | |
| void | registerAction (const QString &theActionID, QAction *theAction) |
| Add theAction to map of managed actions. More... | |
| void | registerAction (QtxAction *theAction) |
| Add theAction to map of managed actions. QtxAction::ID() is used as action ID. More... | |
| std::set< QAction * > | getActions (const QString &theModuleID, const QString &theInModuleActionID) const |
| Get registered actions. If theInModuleActionID is meta-action ID, seeks in all modules. More... | |
| std::pair< QString, QString > | getModuleIDAndInModuleID (const QAction *theAction) const |
| Get module ID and in-module-ID of theAction. More... | |
| bool | hasAction (const QAction *theAction) const |
| QString | getActionID (const QAction *theAction) const |
| Get action ID of theActon. More... | |
| void | setActionsOfModuleEnabled (const QString &theModuleID, const bool theEnable=true) const |
| Enables/disable actions of the module. Only those actions are affected, whose parent widget is active desktop. More... | |
| void | setSectionEnabled (const QString &theInModuleActionIDPrefix, bool theEnable=true) const |
| void | setActionsWithPrefixInIDEnabled (const QString &theInModuleActionIDPrefix, bool theEnable=true) const |
| Enables/disables all registered actions whose in-module action ID begins with theInModuleActionIDPrefix. Only those actions are affected, whose parent widget is active desktop. More... | |
| void | rebindActionsToKeySequences () const |
| For all registered actions binds key sequences from myShortcutContainer. More... | |
| void | updateShortcuts () const |
| std::set< std::pair< QString, QString > > | setShortcut (const QString &theActionID, const QKeySequence &theKeySequence, bool theOverride=false) |
| Checks for conflicts. If theOverride, modifies incoming and disables all conflicting shortcuts. Then binds key sequences with corresponding registered actions. Saves changes to preferences. More... | |
| std::set< std::pair< QString, QString > > | setShortcut (const QString &theModuleID, const QString &theInModuleActionID, const QKeySequence &theKeySequence, bool theOverride=false) |
| const SUIT_ShortcutContainer & | getShortcutContainer () const |
| void | mergeShortcutContainer (const SUIT_ShortcutContainer &theContainer, bool theOverride=true, bool theTreatAbsentIncomingAsDisabled=false, bool theSaveToPreferences=true) |
| Does not perform validity checks on theModuleID and theInModuleActionID. More... | |
| const QKeySequence & | getKeySequence (const QString &theModuleID, const QString &theInModuleActionID) const |
| Get a key sequence mapped to the action. More... | |
| const std::map< QString, QKeySequence > & | getModuleShortcutsInversed (const QString &theModuleID) const |
| std::set< QString > | getShortcutModuleIDs () const |
| std::set< QString > | getIDsOfInterferingModules (const QString &theModuleID) const |
| std::shared_ptr< const SUIT_ShortcutModuleAssets > | getModuleAssets (const QString &theModuleID) const |
| const std::map< QString, std::shared_ptr< SUIT_ShortcutModuleAssets > > & | getModuleAssets () const |
| QString | getModuleName (const QString &theModuleID, const QString &theLang="") const |
| Retrieves module name, if the asset was loaded using setAssetsFromResources(). If theLang is empty, it is current language. More... | |
| std::shared_ptr< const SUIT_ShortcutItemAssets > | getActionAssets (const QString &theModuleID, const QString &theInModuleActionID, bool theTryToCreateRuntimeAssetsIfAbsent=true) const |
| std::shared_ptr< const SUIT_ShortcutItemAssets > | getActionAssets (const QString &theActionID, bool theTryToCreateRuntimeAssetsIfAbsent=true) const |
| std::shared_ptr< const SUIT_ShortcutItemAssets > | createRuntimeActionAssets (const QString &theModuleID, const QString &theInModuleActionID) const |
| Creates assets using action instance fields, if corresponding action is registered. More... | |
| QString | getActionName (const QString &theModuleID, const QString &theInModuleActionID, const QString &theLang="") const |
| Retrieves action name, if the asset is myModuleAssets. Name of module is not included. If theLang is empty, it is current language. More... | |
| QtxAction * | createAction (QObject *theParent, QObject *theReceiver, const char *theReceiverSlot, const QString &theActionID, const bool theIsToggle=false) const |
| Creates an action and sets asset data to the action. More... | |
Static Public Member Functions | |
| static void | Init () |
| Create new singleton-instance of shortcut manager, if it has not been created. More... | |
| static SUIT_ShortcutMgr * | get () |
| static bool | isKeySequenceValid (const QKeySequence &theKeySequence) |
| Checks whether the theKeySequence is platform-compatible. More... | |
| static std::pair< bool, QKeySequence > | toKeySequenceIfValid (const QString &theKeySequenceString) |
| static bool | isModuleIDValid (const QString &theModuleID) |
| Valid module ID does not contain "/" and equals to result of QString(theModuleID).simplified(). Empty module ID is valid - it is root module ID. More... | |
| static bool | isInModuleIDTokenValid (const QString &theInModuleIDToken) |
| static bool | isInModuleIDTokenMeta (const QString &theInModuleIDToken) |
| static bool | isInModuleActionIDValid (const QString &theInModuleActionID) |
| Valid in-module action ID may consist of several tokens, separated by "/": <token_0>/<token_1>...<token_N>/<token_N-1>. Each <token> must be non-empty and be equal to QString(<token>).simplified(). Token "#" is also not valid, since the character in the beginning of the last token means action is meta-action. More... | |
| static bool | isInModuleMetaActionID (const QString &theInModuleActionID) |
| static std::pair< QString, QString > | splitIntoModuleIDAndInModuleID (const QString &theActionID) |
| Extracts module ID and in-module action ID from application-unique action ID. The theActionID must be composed as <moduleID>/<inModuleActionID>. More... | |
| static QStringList | splitIntoTokens (const QString &theRelativeID) |
| Does not check validity. More... | |
| static QString | joinIntoRelativeID (const QStringList &theTokens) |
| Does not check validity. More... | |
| static bool | isActionIDValid (const QString &theActionID) |
| static QString | makeActionID (const QString &theModuleID, const QString &theInModuleActionID) |
| Creates application-unique action ID. Reverse to splitIntoModuleIDAndInModuleID. More... | |
| static void | fillContainerFromPreferences (SUIT_ShortcutContainer &theContainer, bool theDefaultOnly) |
| Sets all shortcuts from preferences to theContainer. Incoming shortcuts override existing ones. If the container has shortcut for an action, which is absent in preferences, and the existing shortcut does not conflict with incoming ones, it is untouched. See setShortcutsFromPreferences() for details. More... | |
| static void | fillContainerFromPreferences (SUIT_ShortcutContainer &theContainer, bool theDefaultOnly, const QString &theSectionNamePrefix) |
| static std::pair< std::shared_ptr< SUIT_ShortcutModuleAssets >, std::shared_ptr< SUIT_ShortcutItemAssets > > | getActionAssetsFromResources (const QString &theActionID, const std::set< QString > &theLangs={}) |
| Returns item assets as they are in asset files. Returned module assets is necessary to keep memory ownership of theAction ancestors. The module assets contain only ancestors of theActionID. More... | |
| static QString | currentLang () |
Static Public Attributes | |
| static const QString | ROOT_MODULE_ID = QString("") |
Protected Member Functions | |
| virtual | ~SUIT_ShortcutMgr () |
Private Slots | |
| void | onActionDestroyed (QObject *theObject) |
| Called when the corresponding action is destroyed. Removes destroyed action from maps of registered actions. Preserves shortcut. More... | |
| void | onAnonymousActionDestroyed (QObject *theObject) |
Private Member Functions | |
| SUIT_ShortcutMgr () | |
| SUIT_ShortcutMgr (const SUIT_ShortcutMgr &)=delete | |
| SUIT_ShortcutMgr & | operator= (const SUIT_ShortcutMgr &)=delete |
| virtual bool | eventFilter (QObject *theObject, QEvent *theEvent) |
| Overrides QObject::eventFilter(). If theEvent is QEvent::ActionAdded and the action is instance of QtxAction, registers it. More... | |
| std::set< std::pair< QString, QString > > | setShortcutNoIDChecks (const QString &theModuleID, const QString &theInModuleActionID, const QKeySequence &theKeySequence, bool theOverride) |
| Does not perform validity checks on theModuleID and theInModuleActionID. More... | |
| void | setShortcutsFromPreferences () |
| Set shortcuts from preference files. The method is intended to be called before any calls to setShortcut() or mergeShortcutContainer(). Definition of this method assumes, that shortcut settings are serialized as prerefence entries {name=<inModuleActionID>, val=<keySequence>} in dedicated section for each module, with names of sections being composed as "shortcuts_vA1.0:<moduleID>". More... | |
| void | setAssetsFromResources (QString theLanguage=QString()) |
| void | registerAnonymousShortcut (QAction *const theAction) |
| void | enableAnonymousShortcutsClashingWith (const QString &theModuleID, const bool theEnable) const |
| void | enableAnonymousShortcutsClashingWith (const QKeySequence &theKeySequence, bool theEnable) const |
| QString | anonymousShortcutsToString () const |
Static Private Member Functions | |
| static void | saveShortcutsToPreferences (const std::map< QString, std::map< QString, QKeySequence >> &theShortcutsInversed) |
| Writes shortcuts to preference files. More... | |
| static void | saveShortcutsToPreferences (const std::map< QString, std::map< QString, std::pair< QKeySequence, QKeySequence >>> &theShortcutsInversed) |
| Writes shortcuts to preference files. More... | |
Private Attributes | |
| std::map< QString, std::map< QString, std::set< QAction * > > > | myActions |
| { moduleID, { inModuleActionID, action[] }[] }[]. More... | |
| std::map< QAction *, std::pair< QString, QString > > | myActionIDs |
| { action, { moduleID, inModuleActionID } }[]. More... | |
| SUIT_ShortcutContainer | myShortcutContainer |
| Can not contain entries like { <non-root module ID>, { <meta-action ID>, actions[] } }. More... | |
| std::map< QString, std::shared_ptr< SUIT_ShortcutModuleAssets > > | myModuleAssets |
| {moduleID, moduleAssets}[]. More... | |
| bool | myAssetsLoaded |
| True, if SUIT_ShortcutMgr::setAssetsFromResources(QString) was called. More... | |
| std::set< QString > | myActiveModuleIDs |
| std::map< QAction *, QKeySequence > | myAnonymousShortcuts |
| Actions without IDs, but with hard-coded non-empty key sequences. More... | |
| std::map< QKeySequence, std::set< QAction * > > | myAnonymousShortcutsInverse |
Static Private Attributes | |
| static SUIT_ShortcutMgr * | myShortcutMgr = nullptr |
Handles action shortcut customization.
The manager is designed to detect shortcut conflicts even for actions, which are not constructed yet. To do this, data about action shortcuts should be available for the manager prior to construction of actions.
SHORTCUT PREFERENCES The data about shortcuts is stored in preference files (see SUIT_ShortcutMgr::setShortcutsFromPreferences()) as maps [action ID]->[key sequence]. It means, actions should have valid IDs (see SUIT_ShortcutMgr::isActionIDValid(const QString&)). Let's call such action identified, and actions with invalid IDs anonymous. Action IDs are language-independent.
After an action is constructed (even if it is anonymous), it must be registered by the manager. If the action is instance of QtxAction, the manager registers it automatically (see SUIT_ShortcutMgr:eventFilter(QObject* theObject, QEvent* theEvent)). Otherwise SUIT_ShortcutMgr::registerAction(const QString& theActionID, QAction* theAction) must be called.
Upon registration of an action, the manager checks, if a key sequence, assigned to the action, clashes with other shortcuts. If it does, and the action is anonymous - empty keysequnce is set to the action. If the action is identified - a keysequence from preferences is set to the action, even if incoming key sequence does not clash with other shortcuts. Absence of an action ID in preference files means default key sequence is empty.
If shortcuts are changed (via SUIT_ShortcutMgr::mergeShortcutContainer(const SUIT_ShortcutContainer&, bool, bool, bool)), the manager serizalizes the changes into user preference file and sets new key sequences to according registered actions.
ACTION ASSETS Users are not aware about action IDs, since GUI normally shows user-friendly data: action names, tooltips and icons. Let's call the data assets. Assets of an action should be available for GUI for shortcut presenting/editing (let's call the piece of GUI Shortcut Editor) even before the action is constructed. The assets should be provided is asset files (see SUIT_ShortcutMgr::setAssetsFromResources(QString)).
CONFLICT DETECTION IDENTIFIED ACTIONS/SHORTCUTS Let's call GUI module root module. Only one module, besides the root module, can be active at instance. So a key sequence must be unique within a joined temporary table of root and active module shortcuts. An action is allowed to be bound with only key sequence. Multiple actions may be registered under the same ID.
Action ID is application-unique, language-independent and must be composed as <moduleID>/<inModuleActionID>. If an action belongs to root module (e.g. 'Save As'), use empty string as <moduleID>. Let's call actions with empty module ID root actions.
<inModuleActionID> can be composed of several tokens, delimited by "/". See SUIT_ShortcutMgr::isInModuleActionIDValid(const QString&) for details. Shortcut Editor considers <inModuleActionID> as "path": <inModuleActionID> without the last token is inModuleID of parent folder or action-folder (see SUIT_ShortcutMgr::setAssetsFromResources(QString)).
META-ACTIONS There is a need to keep actions from different modules, which do the same from user' perspective, bound to the same key sequence. E.g. 'Front view' or 'Undo'. Let's call such set of actions meta-action. <inModuleActionID> of all members of a meta-action must be the same and the last token of the ID must start with "#". Meta-action is root action, when it comes to checking for conflicts. Shortcuts of meta-actions are (de)serialized to the same section of preference files as root shortcuts. Assets of meta-actions should be placed in asset files of root (GUI) module.
ANONYMOUS ACTIONS/SHORTCUTS Actions without action IDs or with invalid ones are called anonymous actions. All anonymous actions with non-empty shortcut key sequences are registered by SUIT_ShortcutMgr. If a shortcut for an anonymous action clashes with a shortcut for an action with defined ID (identified action/shortcut), the shortcut for the anonymous action is disabled, but [the anonymous action, the hard-coded key sequence] pair remains within the SUIT_ShortcutMgr. If user redefines key sequences for identified actions, and the clash is gone, SUIT_ShortcutMgr enables back the shortcut for the anonymous action.
It is not possible to reassign key sequences for anonymous actions using the Shortcut Editor GUI. It is not possible to always warn users, if a key sequence, they assigns to an identified action, disables an anonymous shortcut, because SUIT_ShortcutMgr has no data about anonymous actions until they appear in runtime. To prevent the user from relying on such warnings, they are completely disabled.
HOW TO USE 1) Come up with valid action ID for an action and: 1A) Pass the ID as an agrument to constructor of QtxAction; or 1B) Call SUIT_ShortcutMgr::registerAction(const QString& theActionID, QAction* theAction); or 1C) Construct the action using SUIT_ShortcutMgr::createAction(..). The latest option allows to avoid duplication of action assets in *.ts files. 2) Add action assets in asset files. 3) Add action default keysequence to default preference file.
DEVELOPMENT There are two macros: SHORTCUT_MGR_DBG and SHORTCUT_MGR_DEVTOOLS. SHORTCUT_MGR_DBG enables shortcut-related debug output. SHORTCUT_MGR_DEVTOOLS enables DevTools class. It assists in making anonymous actions identified and composing asset and default preference files.
More details can be found in the "SUIT_ShortcutMgr. ReadMe.md".
|
private |
References ROOT_MODULE_ID.
|
privatedelete |
|
protectedvirtual |
|
private |
References myAnonymousShortcuts, and myAnonymousShortcutsInverse.
| QtxAction * SUIT_ShortcutMgr::createAction | ( | QObject * | theParent, |
| QObject * | theReceiver, | ||
| const char * | theReceiverSlot, | ||
| const QString & | theActionID, | ||
| const bool | theIsToggle = false |
||
| ) | const |
Creates an action and sets asset data to the action.
References getActionAssets(), splitIntoModuleIDAndInModuleID(), splitIntoTokens(), and Warning().
| std::shared_ptr< const SUIT_ShortcutItemAssets > SUIT_ShortcutMgr::createRuntimeActionAssets | ( | const QString & | theModuleID, |
| const QString & | theInModuleActionID | ||
| ) | const |
Creates assets using action instance fields, if corresponding action is registered.
References SUIT_ShortcutModuleAssets::create(), currentLang(), getActions(), SUIT_ShortcutAssets::LangDependentAssets::myName, and SUIT_ShortcutAssets::LangDependentAssets::myToolTip.
|
static |
References DEFAULT_LANG, LANG_SECTION, SUIT_Session::resourceMgr(), SUIT_Session::session(), QtxResourceMgr::stringValue(), and Warning().
|
private |
References myAnonymousShortcutsInverse, and NO_KEYSEQUENCE.
|
private |
Overrides QObject::eventFilter(). If theEvent is QEvent::ActionAdded and the action is instance of QtxAction, registers it.
References SUIT_ShortcutContainer::hasShortcut(), QtxAction::ID(), myShortcutContainer, registerAction(), registerAnonymousShortcut(), ShCutDbg(), and splitIntoModuleIDAndInModuleID().
|
static |
Sets all shortcuts from preferences to theContainer. Incoming shortcuts override existing ones. If the container has shortcut for an action, which is absent in preferences, and the existing shortcut does not conflict with incoming ones, it is untouched. See setShortcutsFromPreferences() for details.
| theDefaultOnly | If true, user preferences are ignored and only default preferences are used. |
References SECTION_NAME_PREFIX.
|
static |
| theSectionNamePrefix | Prefix of section name in preference files to look in. |
List of modules with invalid IDs.
{ moduleID, {inModuleActionID, keySequence}[] }[]
Shortcuts, which have not been set, because they are in conflict with previously parsed shortcuts. { moduleID, {inModuleActionID, keySequence}[] }[]
References SUIT_Session::activeApplication(), SUIT_Application::desktop(), QtxResourceMgr::IgnoreUserValues, isInModuleActionIDValid(), isInModuleMetaActionID(), isModuleIDValid(), QtxResourceMgr::parameters(), SUIT_Session::resourceMgr(), ROOT_MODULE_ID, QtxResourceMgr::sectionsToken(), SUIT_Session::session(), SUIT_ShortcutContainer::setShortcut(), QtxResourceMgr::setWorkingMode(), ShCutDbg(), QtxResourceMgr::subSections(), toKeySequenceIfValid(), SUIT_ShortcutContainer::toString(), QtxResourceMgr::value(), Warning(), and QtxResourceMgr::workingMode().
|
static |
References Init(), and myShortcutMgr.
| std::shared_ptr< const SUIT_ShortcutItemAssets > SUIT_ShortcutMgr::getActionAssets | ( | const QString & | theActionID, |
| bool | theTryToCreateRuntimeAssetsIfAbsent = true |
||
| ) | const |
| std::shared_ptr< const SUIT_ShortcutItemAssets > SUIT_ShortcutMgr::getActionAssets | ( | const QString & | theModuleID, |
| const QString & | theInModuleActionID, | ||
| bool | theTryToCreateRuntimeAssetsIfAbsent = true |
||
| ) | const |
References makeActionID(), and ShCutDbg().
|
static |
Returns item assets as they are in asset files. Returned module assets is necessary to keep memory ownership of theAction ancestors. The module assets contain only ancestors of theActionID.
| theLangs | If empty, all languages is parsed. |
References SUIT_ShortcutModuleAssets::create(), isInModuleMetaActionID(), QtxResourceMgr::parameters(), SUIT_Session::resourceMgr(), ROOT_MODULE_ID, SECTION_NAME_ACTION_ASSET_FILE_PATHS, SUIT_Session::session(), ShCutDbg(), splitIntoModuleIDAndInModuleID(), SUIT_tools::substituteVars(), and Warning().
| QString SUIT_ShortcutMgr::getActionID | ( | const QAction * | theAction | ) | const |
Get action ID of theActon.
References makeActionID(), and myActionIDs.
| QString SUIT_ShortcutMgr::getActionName | ( | const QString & | theModuleID, |
| const QString & | theInModuleActionID, | ||
| const QString & | theLang = "" |
||
| ) | const |
Retrieves action name, if the asset is myModuleAssets. Name of module is not included. If theLang is empty, it is current language.
References getActionAssets().
| std::set< QAction * > SUIT_ShortcutMgr::getActions | ( | const QString & | theModuleID, |
| const QString & | theInModuleActionID | ||
| ) | const |
Get registered actions. If theInModuleActionID is meta-action ID, seeks in all modules.
References isInModuleMetaActionID(), myActionIDs, and myActions.
| std::set< QString > SUIT_ShortcutMgr::getIDsOfInterferingModules | ( | const QString & | theModuleID | ) | const |
References SUIT_ShortcutContainer::getIDsOfInterferingModules(), and myShortcutContainer.
| const QKeySequence & SUIT_ShortcutMgr::getKeySequence | ( | const QString & | theModuleID, |
| const QString & | theInModuleActionID | ||
| ) | const |
Get a key sequence mapped to the action.
References SUIT_ShortcutContainer::getKeySequence(), and myShortcutContainer.
|
inline |
| std::shared_ptr< const SUIT_ShortcutModuleAssets > SUIT_ShortcutMgr::getModuleAssets | ( | const QString & | theModuleID | ) | const |
References myModuleAssets.
| std::pair< QString, QString > SUIT_ShortcutMgr::getModuleIDAndInModuleID | ( | const QAction * | theAction | ) | const |
Get module ID and in-module-ID of theAction.
References myActionIDs.
| QString SUIT_ShortcutMgr::getModuleName | ( | const QString & | theModuleID, |
| const QString & | theLang = "" |
||
| ) | const |
Retrieves module name, if the asset was loaded using setAssetsFromResources(). If theLang is empty, it is current language.
References getModuleAssets().
| const std::map< QString, QKeySequence > & SUIT_ShortcutMgr::getModuleShortcutsInversed | ( | const QString & | theModuleID | ) | const |
References SUIT_ShortcutContainer::getModuleShortcutsInversed(), and myShortcutContainer.
| const SUIT_ShortcutContainer & SUIT_ShortcutMgr::getShortcutContainer | ( | ) | const |
References myShortcutContainer.
| std::set< QString > SUIT_ShortcutMgr::getShortcutModuleIDs | ( | ) | const |
References SUIT_ShortcutContainer::getIDsOfAllModules(), and myShortcutContainer.
| bool SUIT_ShortcutMgr::hasAction | ( | const QAction * | theAction | ) | const |
Returns true if theAction is registered.
References myActionIDs.
|
static |
Create new singleton-instance of shortcut manager, if it has not been created.
References SUIT_ShortcutHistorian::getContainerWithOldShortcuts(), mergeShortcutContainer(), myShortcutMgr, SUIT_ShortcutHistorian::removeOldShortcutPreferences(), setAssetsFromResources(), setShortcutsFromPreferences(), ShCutDbg(), and SUIT_ShortcutMgr().
|
static |
|
static |
Valid in-module action ID may consist of several tokens, separated by "/": <token_0>/<token_1>...<token_N>/<token_N-1>. Each <token> must be non-empty and be equal to QString(<token>).simplified(). Token "#" is also not valid, since the character in the beginning of the last token means action is meta-action.
References isInModuleIDTokenValid(), and splitIntoTokens().
|
static |
References META_ACTION_PREFIX.
|
static |
References META_ACTION_PREFIX, and TOKEN_SEPARATOR.
|
static |
References isInModuleIDTokenMeta(), and splitIntoTokens().
|
static |
Checks whether the theKeySequence is platform-compatible.
|
static |
Valid module ID does not contain "/" and equals to result of QString(theModuleID).simplified(). Empty module ID is valid - it is root module ID.
References TOKEN_SEPARATOR.
|
static |
Does not check validity.
References TOKEN_SEPARATOR.
|
static |
Creates application-unique action ID. Reverse to splitIntoModuleIDAndInModuleID.
References isInModuleActionIDValid(), isModuleIDValid(), and TOKEN_SEPARATOR.
| void SUIT_ShortcutMgr::mergeShortcutContainer | ( | const SUIT_ShortcutContainer & | theContainer, |
| bool | theOverride = true, |
||
| bool | theTreatAbsentIncomingAsDisabled = false, |
||
| bool | theSaveToPreferences = true |
||
| ) |
Does not perform validity checks on theModuleID and theInModuleActionID.
{ keySequence, {moduleID, isTheKeySequenceBound}[] }[]
References enableAnonymousShortcutsClashingWith(), getActions(), SUIT_ShortcutContainer::merge(), myActiveModuleIDs, myShortcutContainer, NO_KEYSEQUENCE, saveShortcutsToPreferences(), ShCutDbg(), and SUIT_ShortcutContainer::toString().
|
privateslot |
Called when the corresponding action is destroyed. Removes destroyed action from maps of registered actions. Preserves shortcut.
| theObject | action being destroyed. |
References myActionIDs, and myActions.
|
privateslot |
References myAnonymousShortcuts, myAnonymousShortcutsInverse, and ShCutDbg().
|
privatedelete |
| void SUIT_ShortcutMgr::rebindActionsToKeySequences | ( | ) | const |
For all registered actions binds key sequences from myShortcutContainer.
References getKeySequence(), myActionIDs, and ShCutDbg().
| void SUIT_ShortcutMgr::registerAction | ( | const QString & | theActionID, |
| QAction * | theAction | ||
| ) |
Add theAction to map of managed actions.
References getActionAssets(), getKeySequence(), SUIT_ShortcutContainer::hasShortcut(), isInModuleMetaActionID(), myActionIDs, myActions, myAssetsLoaded, myShortcutContainer, NO_KEYSEQUENCE, onActionDestroyed(), QtxResourceMgr::parameters(), registerAnonymousShortcut(), SUIT_Session::resourceMgr(), ROOT_MODULE_ID, SUIT_Session::session(), SUIT_ShortcutContainer::setShortcut(), ShCutDbg(), splitIntoModuleIDAndInModuleID(), TOKEN_SEPARATOR, and Warning().
| void SUIT_ShortcutMgr::registerAction | ( | QtxAction * | theAction | ) |
Add theAction to map of managed actions. QtxAction::ID() is used as action ID.
References QtxAction::ID(), and registerAction().
|
private |
|
staticprivate |
Writes shortcuts to preference files.
| theShortcuts | { moduleID, { inModuleActionID, keySequence }[] }[]. Empty inModuleActionIDs are ignored. |
References SUIT_Session::resourceMgr(), SECTION_NAME_PREFIX, QtxResourceMgr::sectionsToken(), SUIT_Session::session(), QtxResourceMgr::setValue(), ShCutDbg(), and Warning().
|
staticprivate |
Writes shortcuts to preference files.
| theShortcuts | { moduleID, { inModuleActionID, {oldKeySequence, newKeySequence} }[] }[]. Empty inModuleActionIDs are ignored. OldKeySequences are ignored. |
References SUIT_Session::resourceMgr(), SECTION_NAME_PREFIX, QtxResourceMgr::sectionsToken(), SUIT_Session::session(), QtxResourceMgr::setValue(), ShCutDbg(), and Warning().
| void SUIT_ShortcutMgr::setActionsOfModuleEnabled | ( | const QString & | theModuleID, |
| const bool | theEnable = true |
||
| ) | const |
Enables/disable actions of the module. Only those actions are affected, whose parent widget is active desktop.
References SUIT_Session::activeApplication(), anonymousShortcutsToString(), SUIT_Application::desktop(), enableAnonymousShortcutsClashingWith(), myActions, myActiveModuleIDs, SUIT_Session::session(), and ShCutDbg().
| void SUIT_ShortcutMgr::setActionsWithPrefixInIDEnabled | ( | const QString & | theInModuleActionIDPrefix, |
| bool | theEnable = true |
||
| ) | const |
Enables/disables all registered actions whose in-module action ID begins with theInModuleActionIDPrefix. Only those actions are affected, whose parent widget is active desktop.
References SUIT_Session::activeApplication(), SUIT_Application::desktop(), myActionIDs, and SUIT_Session::session().
|
private |
Fills myModuleAssets from asset files in theLanguage and EN.
| theLanguage | If empty, fills assets in current language and EN. |
Asset files must be structured like this: { moduleID: { "iconPath": iconPath, "langDependentAssets": { ... lang: { "name": moduleName, "tooltip": moduleTooltip }, ... }, "children": { ... actionA_IDLastToken : { "iconPath": iconPath, "langDependentAssets": { ... lang: { "name": actionName, "tooltip": actionTooltip }, ... }, "children": { // The action has nested actions. actionB_IDLastToken: { ... } } }, ... folderC_IDLastToken: { "isAction": false, // The folder is pure folder. "iconPath": iconPath, "langDependentAssets": { ... }, children: { ... } } ... } } }
The JSON above describes an action-folder with ID "moduleID/actionA_IDLastToken" and a pure folder with ID "moduleID/folderC_IDLastToken". The action-folder has a nested action with "moduleID/actionA_IDLastToken//actionB_IDLastToken". Requirements for action' and folder' IDs are the same.
References SUIT_ShortcutModuleAssets::create(), currentLang(), DEFAULT_LANG, SUIT_ShortcutAssets::forEachDescendant(), isModuleIDValid(), SUIT_ShortcutAssets::loadIcon(), SUIT_ShortcutAssets::merge(), myAssetsLoaded, SUIT_ShortcutAssets::myIcon, SUIT_ShortcutAssets::myIconPath, SUIT_ShortcutAssets::myLangDependentAssets, myModuleAssets, QtxResourceMgr::parameters(), SUIT_Session::resourceMgr(), ROOT_MODULE_ID, SECTION_NAME_ACTION_ASSET_FILE_PATHS, SUIT_Session::session(), ShCutDbg(), SUIT_tools::substituteVars(), QtxResourceMgr::value(), and Warning().
| void SUIT_ShortcutMgr::setSectionEnabled | ( | const QString & | theInModuleActionIDPrefix, |
| bool | theEnable = true |
||
| ) | const |
References setActionsOfModuleEnabled().
| std::set< std::pair< QString, QString > > SUIT_ShortcutMgr::setShortcut | ( | const QString & | theActionID, |
| const QKeySequence & | theKeySequence, | ||
| bool | theOverride = false |
||
| ) |
Checks for conflicts. If theOverride, modifies incoming and disables all conflicting shortcuts. Then binds key sequences with corresponding registered actions. Saves changes to preferences.
Redefining a key sequence for the action, if the key sequence does not conflict with other shortcuts, is not considered as a conflict.
| theInModuleActionID | The method has no effect if theInModuleActionID is empty. |
| theKeySequence | Empty theKeySequence does not cause conflicts, in this case a shortcut for the action is disabled: theInModuleActionID is added/retained in the container but mapped to empty key sequence. |
| theOverride | If true, conflicting shortcuts are disabled. |
References setShortcutNoIDChecks(), ShCutDbg(), and splitIntoModuleIDAndInModuleID().
| std::set< std::pair< QString, QString > > SUIT_ShortcutMgr::setShortcut | ( | const QString & | theModuleID, |
| const QString & | theInModuleActionID, | ||
| const QKeySequence & | theKeySequence, | ||
| bool | theOverride = false |
||
| ) |
References isInModuleActionIDValid(), isModuleIDValid(), setShortcutNoIDChecks(), and ShCutDbg().
|
private |
Does not perform validity checks on theModuleID and theInModuleActionID.
{ moduleID, {inModuleActionID, keySequence}[] }[]
{ moduleID, isTheKeySequenceBound }[]
References enableAnonymousShortcutsClashingWith(), getActions(), myActiveModuleIDs, myShortcutContainer, NO_KEYSEQUENCE, saveShortcutsToPreferences(), and SUIT_ShortcutContainer::setShortcut().
|
private |
Set shortcuts from preference files. The method is intended to be called before any calls to setShortcut() or mergeShortcutContainer(). Definition of this method assumes, that shortcut settings are serialized as prerefence entries {name=<inModuleActionID>, val=<keySequence>} in dedicated section for each module, with names of sections being composed as "shortcuts_vA1.0:<moduleID>".
E.g. in case of XML file it may look like this:
<section name="shortcuts_vA1.0:"> <parameter name="AboutDialog" value="Alt+Shift+A"> <parameter name="Edit/#Clipboard_Copy" value="Ctrl+C"> <parameter name="Edit/#Clipboard_Paste" value="Ctrl+V"> <parameter name="File/New" value="Ctrl+N"> <parameter name="File/Open" value="Ctrl+O"> </section> <section name="shortcuts_vA1.0:SHAPER"> <parameter name="Part/Dump" value=""> <parameter name="Part/Parameter" value=""> <parameter name="Part/ParametersMgr" value=""> <parameter name="Sketch" value="Ctrl+4"> <parameter name="Sketch/SketchPoint" value="Ctrl+Shift+*"> <parameter name="Sketch/SketchLine" value="Ctrl+Shift+_"> </section>
Empty inModuleActionIDs are ignored.
References fillContainerFromPreferences(), getActionAssets(), SUIT_ShortcutContainer::getIDsOfAllModules(), getModuleShortcutsInversed(), mergeShortcutContainer(), myAssetsLoaded, myShortcutContainer, ShCutDbg(), TOKEN_SEPARATOR, and Warning().
|
static |
Extracts module ID and in-module action ID from application-unique action ID. The theActionID must be composed as <moduleID>/<inModuleActionID>.
References isInModuleIDTokenValid(), and TOKEN_SEPARATOR.
|
static |
Does not check validity.
References TOKEN_SEPARATOR.
|
static |
References isKeySequenceValid().
| void SUIT_ShortcutMgr::updateShortcuts | ( | ) | const |
References rebindActionsToKeySequences().
|
private |
{ action, { moduleID, inModuleActionID } }[].
May contain entries like { <non-root module ID>, { <meta-action ID>, actions[] } }.
|
private |
{ moduleID, { inModuleActionID, action[] }[] }[].
May contain entries like { <non-root module ID>, { <meta-action ID>, actions[] } }.
|
mutableprivate |
|
private |
Actions without IDs, but with hard-coded non-empty key sequences.
Shortcuts, defined in preferences, override shortcuts of anonymous actions - if an active module has a preference shortcut, anonymous shortcuts with the same key sequence are disabled. If the root module has a preference shortcut, which is in clash with anonymous shortcuts, clashing anonymous actions are always disabled.
|
private |
|
private |
True, if SUIT_ShortcutMgr::setAssetsFromResources(QString) was called.
|
mutableprivate |
{moduleID, moduleAssets}[].
Structured assets: module assets refer to folders and actions, folders and actions refer to nested ones, etc.
|
private |
Can not contain entries like { <non-root module ID>, { <meta-action ID>, actions[] } }.
|
staticprivate |
|
static |