All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions
Qtilities::CoreGui::ActionProvider Class Reference

A ready to use implementation of the IActionProvider interface. More...

#include <ActionProvider.h>

Inheritance diagram for Qtilities::CoreGui::ActionProvider:
Inheritance graph
[legend]

List of all members.

Public Member Functions

QList< QtilitiesCategoryactionCategories () const
QList< QtilitiesCategoryactionGroupCategories () const
 A list of all action group categories provided through this interface.
QMap< QActionGroup
*, QtilitiesCategory
actionGroupMap (QActionGroup *action_group) const
 A map with the actions and action categories of all the action groups provided through the interface.
QList< QActionGroup * > actionGroups () const
 A list of all the action groups provided through the interface.
QMap< QAction
*, QtilitiesCategory
actionMap (IActionProvider::ActionFilterFlags action_filter=NoFilter, const QtilitiesCategory &category_filter=QtilitiesCategory()) const
 A map with the action and action category of all the actions provided through the interface.
QAction * addAction (QAction *action, const QtilitiesCategory &category_filter=QtilitiesCategory())
 Adds an action to the object implementing this interface and returns it if added successfully. Returns 0 otherwise.
QActionGroup * addActionGroup (QActionGroup *action_group, const QtilitiesCategory &category_filter=QtilitiesCategory())
 Adds an action group to the object implementing this interface and returns it if added successfully. Returns 0 otherwise.
void addActions (QList< QAction * > actions, const QtilitiesCategory &category=QtilitiesCategory())
 Adds an list of actions to the object implementing this interface.
void disableAllActions ()
 Disables all actions registered in this action provider.
void enableAllActions ()
 Enables all actions registered in this action provider.
QList< QAction * > findActionsByObjectName (const QString &match_string, Qt::MatchFlags match_flags=Qt::MatchFixedString)
 Finds an action with the specified objectName() and returns a reference to it, otherwise return 0 if it was not found.
QList< QAction * > findActionsByText (const QString &match_string, Qt::MatchFlags match_flags=Qt::MatchFixedString)
 Finds an action that has the specified text and returns a reference to it, otherwise return 0 if it was not found.
QObject * objectBase ()
 Returns the QObject* base of the interface.
const QObject * objectBase () const
 Returns a const QObject* base of the interface.
void removeAction (QAction *action)
 Removes an action from the action provider. Does not delete the action.
void removeActionCategory (const QtilitiesCategory &category)
 Removes a complete category from the action provider. Does not delete the actions.
- Public Member Functions inherited from Qtilities::CoreGui::Interfaces::IActionProvider
virtual QList< QAction * > actions (ActionFilterFlags action_filter=NoFilter, const QtilitiesCategory &category_filter=QtilitiesCategory("Hello World!")) const =0
 A list of all the actions provided through the interface.
- Public Member Functions inherited from Qtilities::Core::Interfaces::IObjectBase
QString objectOriginID () const
 Allows interfaces to provide some sort of source identification.
void setObjectOriginID (const QString &object_origin_id)
 Allows setting of the object source ID of this interface implementation.

Additional Inherited Members

- Public Types inherited from Qtilities::CoreGui::Interfaces::IActionProvider
enum  ActionFilter { NoFilter = 0, FilterDisabled = 1, FilterHidden = 2 }
 Action Filter Flag. More...

Detailed Description

A ready to use implementation of the IActionProvider interface.

In the development done using Qtilities the problem was often faced where an object (which is not a QWidget) needed to provide some actions to another object. To solve the problem the concept of action providers was introducted. Any object can become an action provider and other objects (a toolbar for example) can query the object for actions that it provides, or it can add actions to the object, in the same way that you can add actions to QWidget.

Action providers allow actions to be grouped into categories and allows you to do specialized queries on the actions provided by an object, for example you can get only a list of actions which are enabled. The Qtilities::CoreGui::Interfaces::IActionProvider interface defines the interface that action providers use and the Qtilities::CoreGui::ActionProvider class provides a default implementation of this interface.

Many classes in Qtilities are action providers and they provide actions through their actionProvider() function. An example is Qtilities::CoreGui::ObserverWidget, which provides all the actions that is created and allows you to get for example all the enabled actions for the current observer context. If you use an ObserverWidget that displays its actions in an action toolbar, you can easily add new actions to the toolbar where toolbars are created for each action category. For example:

ObserverWidget widget;
widget.actionProvider()->addAction(my_action,QtilitiesCategory("My Action Category"));
// We can get a list of actions provided by any object like this:
QList<QAction*> actions = widget.actions();
// Only enabled actions:
QList<QAction*> enabled_actions = widget.actions(IActionProvider::FilterDisabled);
// Only actions for a specific category:
QList<QAction*> actions_per_category = widget.actions(IActionProvider::NoFilter,QtilitiesCategory("My Action Category"));

Member Function Documentation

QList< QtilitiesCategory > Qtilities::CoreGui::ActionProvider::actionCategories ( ) const
virtual

The ActionProvider implementation of the IActionProvider interface will always return a sorted category list in ascending order. That is: starts with 'AAA' and ends with 'ZZZ'.

Implements Qtilities::CoreGui::Interfaces::IActionProvider.

QMap< QActionGroup *, QtilitiesCategory > Qtilities::CoreGui::ActionProvider::actionGroupMap ( QActionGroup *  action_group) const
virtual

A map with the actions and action categories of all the action groups provided through the interface.

This function can be used to visualize the actions provided through this interface.

Parameters:
action_groupThe action group for which the map is required. If no group is specified, all actions in all action groups are returned in the map.

Implements Qtilities::CoreGui::Interfaces::IActionProvider.

QMap< QAction *, QtilitiesCategory > Qtilities::CoreGui::ActionProvider::actionMap ( IActionProvider::ActionFilterFlags  action_filter = NoFilter,
const QtilitiesCategory category_filter = QtilitiesCategory() 
) const
virtual

A map with the action and action category of all the actions provided through the interface.

This function can be used to visualize the actions provided through this interface.

Parameters:
action_filterThe action filter flags to be used to filter returned actions.
category_filterOnly actions which have a category which appears in the category filter will be part of the returned list.

Implements Qtilities::CoreGui::Interfaces::IActionProvider.

QAction * Qtilities::CoreGui::ActionProvider::addAction ( QAction *  action,
const QtilitiesCategory category = QtilitiesCategory() 
)
virtual

Adds an action to the object implementing this interface and returns it if added successfully. Returns 0 otherwise.

Parameters:
actionThe action to be added.
categoryThe category under which the action should be added. By default no category is assigned. The first level of hierarchy in the category is defined by the first item in the list, and the last level of hierarchy by the last item in the list.

Implements Qtilities::CoreGui::Interfaces::IActionProvider.

QActionGroup * Qtilities::CoreGui::ActionProvider::addActionGroup ( QActionGroup *  action_group,
const QtilitiesCategory category = QtilitiesCategory() 
)
virtual

Adds an action group to the object implementing this interface and returns it if added successfully. Returns 0 otherwise.

Parameters:
action_groupThe action group to be added.
categoryThe category under which the actions in the action group should be added. By default no category is assigned. The first level of hierarchy in the category is defined by the first item in the list, and the last level of hierarchy by the last item in the list.

Implements Qtilities::CoreGui::Interfaces::IActionProvider.

void Qtilities::CoreGui::ActionProvider::addActions ( QList< QAction * >  actions,
const QtilitiesCategory category = QtilitiesCategory() 
)
virtual

Adds an list of actions to the object implementing this interface.

Parameters:
actionsThe actions to be added.
categoryThe category under which the actions should be added. By default no category is assigned. The first level of hierarchy in the category is defined by the first item in the list, and the last level of hierarchy by the last item in the list.

Implements Qtilities::CoreGui::Interfaces::IActionProvider.

QList< QAction * > Qtilities::CoreGui::ActionProvider::findActionsByObjectName ( const QString &  object_name,
Qt::MatchFlags  match_flags = Qt::MatchFixedString 
)
virtual

Finds an action with the specified objectName() and returns a reference to it, otherwise return 0 if it was not found.

Parameters:
match_stringThe match string to match.
match_flagsThe match flags to use during matching. At present Qt::MatchExactly, Qt::MatchFixedString, Qt::MatchContains, Qt::MatchStartsWith, Qt::MatchEndsWith, Qt::MatchCaseSensitive is supported.
Returns:
All actions matching the match conditions. An empty list if no action matches the match conditions.

Implements Qtilities::CoreGui::Interfaces::IActionProvider.

QList< QAction * > Qtilities::CoreGui::ActionProvider::findActionsByText ( const QString &  match_string,
Qt::MatchFlags  match_flags = Qt::MatchFixedString 
)
virtual

Finds an action that has the specified text and returns a reference to it, otherwise return 0 if it was not found.

Parameters:
match_stringThe match string to match.
match_flagsThe match flags to use during matching. All match flags except Qt::MatchRecursive and Qt::MatchWrap can be used.
Returns:
All actions matching the match conditions. An empty list if no action matches the match conditions.

Implements Qtilities::CoreGui::Interfaces::IActionProvider.

const QObject* Qtilities::CoreGui::ActionProvider::objectBase ( ) const
inlinevirtual

Returns a const QObject* base of the interface.

This function can be used in const methods, but make sure that you don't modify things that should stay const. An example where this is used is when we want to get a property on an object in a const method. This is a const operation.

Implements Qtilities::Core::Interfaces::IObjectBase.



Qtilities : Reference Documentation Back to top Copyright © 2009-2013, Jaco Naudé