libXpertMassCore and libXpertMassGui Developer Documentation
  • libXpertMassGui
  • ActionManager
  • MsXpS::libXpertMassGui::ActionManager Class

    class MsXpS::libXpertMassGui::ActionManager

    The ActionManager class provides a management system for relating QAction and QKeySequence. More...

    Header: #include <MsXpS/libXpertMassGui/ActionManager.hpp>
    Inherits: QObject

    Public Types

    struct ActionId

    Public Functions

    ActionManager(QObject *parent = nullptr)
    virtual ~ActionManager()
    int actionCount() const
    QList<std::pair<MsXpS::libXpertMassGui::ActionManager::ActionId, QAction *>> conflictingItems(const QKeySequence &key_sequence, const MsXpS::libXpertMassGui::ActionManager::ActionId &exclude_action_id = {}) const
    QAction *getAction(const MsXpS::libXpertMassGui::ActionManager::ActionId &action_id) const
    const QMap<MsXpS::libXpertMassGui::ActionManager::ActionId, QAction *> &getActionMap() const
    QKeySequence getShortcut(const MsXpS::libXpertMassGui::ActionManager::ActionId &action_id)
    QAction *installAction(const MsXpS::libXpertMassGui::ActionManager::ActionId &action_id, const QKeySequence &key_sequence = QKeySequence())
    bool isInConflict(const QKeySequence &key_sequence, const MsXpS::libXpertMassGui::ActionManager::ActionId &exclude_action_id = {}, bool *was_found_p = nullptr) const
    void loadActionData()
    void saveActionData() const
    void setShortcut(const MsXpS::libXpertMassGui::ActionManager::ActionId &action_id, const QKeySequence &key_sequence)
    QString toString()

    Detailed Description

    The QAction-based operations are associated to ActionId instances that identify the action and relate it to a QKeySequence keyboard key combination. This class is used to let the user define the shortcuts to actions.

    The member map is protected:

    QMap<ActionId, QAction *> m_actions

    Member Function Documentation

    [explicit] ActionManager::ActionManager(QObject *parent = nullptr)

    Constructs an ActionManager using parent for parentship.

    [virtual noexcept] ActionManager::~ActionManager()

    Destructs the ActionManager.

    int ActionManager::actionCount() const

    Return the number of items in the member map that relates ActionId to QACtion instances.

    QList<std::pair<MsXpS::libXpertMassGui::ActionManager::ActionId, QAction *>> ActionManager::conflictingItems(const QKeySequence &key_sequence, const MsXpS::libXpertMassGui::ActionManager::ActionId &exclude_action_id = {}) const

    Returns a list of conflicting items.

    A member map item is conflicting with key_sequence if it maps a QAction with that same shortcut sequence.

    The map is searched for items that map a QAction having key_sequence as the QKeySequence shortcut. If any one of the map items map an ActionId identical to exclude_action_id, that map item is skipped because this is the way to ensure that a new item is updated in the map.

    See also isInConflict().

    QAction *ActionManager::getAction(const MsXpS::libXpertMassGui::ActionManager::ActionId &action_id) const

    Returns the action that is mapped to action_id.

    const QMap<MsXpS::libXpertMassGui::ActionManager::ActionId, QAction *> &ActionManager::getActionMap() const

    Returns a const reference to the member map.

    The map relates ActionId instances to their associated QAction instances (as pointers).

    QKeySequence ActionManager::getShortcut(const MsXpS::libXpertMassGui::ActionManager::ActionId &action_id)

    Return the shortcut associated to action_id.

    If no action can be found matching action_id, then an empty QKeySequence instance is returned.

    QAction *ActionManager::installAction(const MsXpS::libXpertMassGui::ActionManager::ActionId &action_id, const QKeySequence &key_sequence = QKeySequence())

    Installs an action described in action_id, that will be bound to key_sequence.

    Installing an action encompasses multiple steps. The general idea is that this function is called in code that is setting up a QAction and that QAction might benefit from a shortcut (a QKeySequence) as defined by the user and stored in the settings of the program that uses this library.

    The first step is thus to check if action_id is found in the member map of <ActionId, QAction *> pairs. If found, then the corresponding QAction pointer is returned (with no modification: if its shortcut is empty, that shortcut was meant by the user to stay empty).

    If no action_id is found in the member map, then a new QAction is allocated and the key_sequence is set to it as shortcut.

    action_id is mapped to the QAction that is returned.

    Returns the QAction.

    bool ActionManager::isInConflict(const QKeySequence &key_sequence, const MsXpS::libXpertMassGui::ActionManager::ActionId &exclude_action_id = {}, bool *was_found_p = nullptr) const

    Returns true if key_sequence is in conflict with any item in the member map.

    Iterates in all the items of the member map and checks if any of the corresponding action has a shortcut identical to key_sequence. Whenever a map item relates has a key identical to exclude_action_id, that item is skipped while was_found_p is set to true (if non-nullptr).

    If one map item maps an action with the same QKeySequence as key_sequence, true is returned immediately.

    If key_sequence is empty, false is returned as it is considered to never conflict.

    If no map item maps an action with the same QKeySequence as key_sequence, false is returned.

    void ActionManager::loadActionData()

    Loads the action data from the QSettings-based settings.

    The action data are read from the file referenced by static datum libXpertMassCore::Utils::configSettingsFilePath in QSettings::IniFormat format.

    The action data are loaded from the configuration settings file in the form of a string list. The strings are parsed and the member map's is filled by calling installAction().

    void ActionManager::saveActionData() const

    Saves the action data to the QSettings-based settings.

    The action data are written to in the file referenced by static datum libXpertMassCore::Utils::configSettingsFilePath in QSettings::IniFormat format.

    The member m_actions map's items are iterated into and for each map item, the corresponding ActionId and QAction shortcut are written to the settings.

    void ActionManager::setShortcut(const MsXpS::libXpertMassGui::ActionManager::ActionId &action_id, const QKeySequence &key_sequence)

    Sets key_sequence as the shortcut for action_id.

    A QAction must have been created already and must be found as an item mapped to action_id.

    QString ActionManager::toString()

    Crafts a string representing this instance and returns it.