SciDAVis  1.D4
Public Slots | Public Member Functions | Private Attributes
ActionManager Class Reference

Manages QActions and their shortcuts. More...

#include <ActionManager.h>

List of all members.

Public Slots

void removeAction (QAction *action)
void removeAction (QObject *action)

Public Member Functions

 ActionManager ()
QString actionText (const QString &internal_name) const
void addAction (QAction *action, const QString &internal_name)
 CLASS_ACCESSOR (QString, d_title, title, Title)
QList< QString > internalNames () const
void setShortcuts (const QString &internal_name, const QList< QKeySequence > &sequences)
QList< QKeySequence > shortcuts (const QString &internal_name) const
 ~ActionManager ()

Private Attributes

QMap< QString, QList< QAction * > * > d_action_registry
QMap< QString, QList
< QKeySequence > > 
QMap< QString, QString > d_action_texts
QString d_title

Detailed Description

Manages QActions and their shortcuts.

An ActionManager object is meant to manage all actions for one widget class. All actions are addressed by their internal name (a string that must be unique within the widget class). The manager stores multiple QActions per internal name, i.e., one action per instance of the widget class. The text of the action is the localized string of the action while the internal name is never translated as it is meant to be used to identify the action in the configuration of the application. The localized text is taken from the last added action or removed action for each internal name. The managed widgets can change their language as often as needed but should have the same language all the time. Otherwise, the language of actionText() will depend on the order of the action addition. Actions that are deleted (e.g., when their widget is deleted) are automatically removed from the manager. The keyboard shortcuts assigned to an internal name are preserved even when no action of the type exists. If setShortcuts() has been called before addAction() the action's shortcuts are replaced in addAction(). If setShortcuts() has not been called before the first call to addAction() (for a specific name that is) the shortcuts of the first added action will be taken for all other added actions.

The typical usage of ActionManager is:

There is one more thing to consider: As long as addShortcut() is called and addAction() is not, actionText() will return the internal name instead of the localized name. It might therefore be a good idea to create an instance of the corresponding widget at application startup, create all actions for it, and immediately delete it again.

Constructor & Destructor Documentation

ActionManager::ActionManager ( )
ActionManager::~ActionManager ( )

References d_action_registry.

Member Function Documentation

QString ActionManager::actionText ( const QString &  internal_name) const
void ActionManager::addAction ( QAction *  action,
const QString &  internal_name 
ActionManager::CLASS_ACCESSOR ( QString  ,
d_title  ,
title  ,
QList< QString > ActionManager::internalNames ( ) const

References d_action_registry.

void ActionManager::removeAction ( QAction *  action)

References d_action_registry, and d_action_texts.

Referenced by addAction(), and removeAction().

void ActionManager::removeAction ( QObject *  action)

References removeAction().

void ActionManager::setShortcuts ( const QString &  internal_name,
const QList< QKeySequence > &  sequences 
QList< QKeySequence > ActionManager::shortcuts ( const QString &  internal_name) const

References d_action_shortcuts.

Member Data Documentation

QMap< QString, QList<QAction *> * > ActionManager::d_action_registry
QMap< QString, QList<QKeySequence> > ActionManager::d_action_shortcuts

Referenced by addAction(), setShortcuts(), and shortcuts().

QMap< QString, QString > ActionManager::d_action_texts

Referenced by actionText(), addAction(), and removeAction().

QString ActionManager::d_title

The documentation for this class was generated from the following files: