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 <ActionManager.hpp>
    Inherits: QObject

    Public Functions

    ActionManager(QObject *parent = nullptr)
    virtual ~ActionManager()
    QAction *getAction(const MsXpS::libXpertMassGui::ActionId &action_id) const
    QAction *installAction(const MsXpS::libXpertMassGui::ActionId &action_id, const QKeySequence &key_sequence = QKeySequence())
    bool isInConflict(const QKeySequence &key_sequence, const MsXpS::libXpertMassGui::ActionId &exclude_action_id = {}, bool *was_found_p = nullptr) const
    void loadActionData()
    void saveActionData() const
    void setShortcut(const MsXpS::libXpertMassGui::ActionId &action_id, const QKeySequence &key_sequence)

    Detailed Description

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

    Member Function Documentation

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

    Constructs an ActionManager using parent for parentship.

    [virtual noexcept] ActionManager::~ActionManager()

    Destructs the ActionManager.

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

    Returns the action that is mapped to action_id.

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

    Installs an action according to action_id, text (the label) and 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 this program.

    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.

    text is the description of the created QAction. action_id is mapped to the QAction that is returned.

    Returns the QAction.

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

    Checks if key_sequence is in conflic with any item in the member map.

    Iterates in all the items of the member m_actions map and checks if any of the corresponding action has a shortcut identical to key_sequence. Whenever a map item relates to exclude_action_id, that item is skipped.

    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 member m_actions map's items are iterated into and for each map item, the shortcut is loaded from the settings and set to the corresponding action.

    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::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.