Main menu actions manager. More...
#include <QtxActionMenuMgr.h>
Classes | |
class | MenuCreator |
Menu actions creator. More... | |
class | MenuNode |
Represents a menu item inside main menu structure. More... | |
Signals | |
void | menuAboutToShow (QMenu *) |
Emitted when the menu is about to be shown. More... | |
void | menuAboutToHide (QMenu *) |
Emitted when the menu is about to be hidden. More... | |
Public Member Functions | |
QtxActionMenuMgr (QMainWindow *) | |
Constructor. More... | |
QtxActionMenuMgr (QWidget *, QObject *) | |
Constructor. More... | |
virtual | ~QtxActionMenuMgr () |
Destructor. More... | |
QWidget * | menuWidget () const |
Get the menu widget. More... | |
virtual bool | isVisible (const int, const int) const |
Check if an action with actId identifier is visible to the parent action with place identifier. More... | |
virtual void | setVisible (const int, const int, const bool) |
Set action's visibility flag. More... | |
int | insert (const int, const QString &, const int, const int=-1) |
Insert action to the menu. More... | |
int | insert (QAction *, const QString &, const int, const int=-1) |
Insert action to the menu. More... | |
int | insert (const int, const QStringList &, const int, const int=-1) |
Insert action to the menu. More... | |
int | insert (QAction *, const QStringList &, const int, const int=-1) |
Insert action to the menu. More... | |
virtual int | insert (const int, const int, const int, const int=-1) |
Insert action to the menu. More... | |
int | insert (QAction *, const int, const int, const int=-1) |
Insert action to the menu. More... | |
int | insert (const QString &, const QString &, const int, const int=-1, const int=-1) |
Create and insert menu item action to the menu. More... | |
int | insert (const QString &, const QStringList &, const int, const int=-1, const int=-1) |
Create and insert menu item action to the menu. More... | |
virtual int | insert (const QString &, const int, const int, const int=-1, const int=-1, QMenu *=0) |
Create and insert menu item action to the menu. More... | |
int | append (const int, const int, const int) |
Create and add menu item action to the end of menu. More... | |
int | append (QAction *, const int, const int) |
Create and add menu item action to the end of menu. More... | |
int | append (const QString &, const int, const int, const int=-1) |
Create and add menu item action to the end of menu. More... | |
int | prepend (const int, const int, const int) |
Create and add menu item action to the beginning of menu. More... | |
int | prepend (QAction *, const int, const int) |
Create and add menu item action to the beginning of menu. More... | |
int | prepend (const QString &, const int, const int, const int=-1) |
Create and add menu item action to the beginning of menu. More... | |
void | remove (const int) |
Remove menu item with given id. More... | |
void | remove (const int, const int, const int=-1) |
Remove menu item with given id. More... | |
void | show (const int) |
Show menu item with given id. More... | |
void | hide (const int) |
Hide menu item with given id. More... | |
bool | isShown (const int) const |
Get visibility status for menu item with given id. More... | |
void | setShown (const int, const bool) |
Set visibility status for menu item with given id. More... | |
virtual void | change (const int, const QString &) |
Change menu title for the action with given id. More... | |
virtual bool | load (const QString &, QtxActionMgr::Reader &) |
Load actions description from the file. More... | |
bool | containsMenu (const QString &, const int, const bool=false) const |
Check if the parent menu contains menu item with given title. More... | |
bool | containsMenu (const int, const int, const bool=false) const |
Check if the parent menu contains menu item with given id. More... | |
QMenu * | findMenu (const int) const |
Get menu by the specified identifier. More... | |
QMenu * | findMenu (const QString &, const int, const bool=false) const |
Get menu by the title. More... | |
bool | isEmptyEnabled (const int) const |
Check if empty menu is enabled. More... | |
void | setEmptyEnabled (const int, const bool) |
Enable/disable empty menu. More... | |
Public Member Functions inherited from QtxActionMgr | |
QtxActionMgr (QObject *parent) | |
Constructor. More... | |
virtual | ~QtxActionMgr () |
Destructor. More... | |
virtual int | registerAction (QAction *, const int=-1) |
Register an action in the internal map. More... | |
virtual void | unRegisterAction (const int) |
Unregister action from internal map. More... | |
QAction * | action (const int) const |
Get action by specified identifier. More... | |
int | actionId (const QAction *) const |
Get action identifier. More... | |
bool | contains (const int) const |
Check if an action with given id is registered in the action manager. More... | |
int | count () const |
Get total number of registered actions. More... | |
bool | isEmpty () const |
Check if there are no actions registered in the action manager. More... | |
QIntList | idList () const |
Get all registered actions identifiers. More... | |
bool | isUpdatesEnabled () const |
Check if update is enabled. More... | |
virtual void | setUpdatesEnabled (const bool) |
Enable/disable update operation. More... | |
void | update () |
Update actions. More... | |
virtual bool | isEnabled (const int) const |
Check is action with given id is enabled. More... | |
virtual void | setEnabled (const int, const bool) |
Protected Member Functions | |
void | setMenuWidget (QWidget *) |
Assign new menu widget to the menu manager. More... | |
MenuNode * | find (const int, const int, const bool=true) const |
Search menu node. More... | |
MenuNode * | find (const int, MenuNode *=0, const bool=true) const |
Search menu node. More... | |
bool | find (const int, NodeList &, MenuNode *=0) const |
Search recursively all menu nodes with given id. More... | |
MenuNode * | find (const QString &, const int, const bool=true) const |
Search menu node. More... | |
MenuNode * | find (const QString &, MenuNode *=0, const bool=true) const |
Search menu node. More... | |
bool | find (const QString &, NodeList &, MenuNode *=0) const |
Search recursively all menu nodes with given title. More... | |
int | findId (const int, const int=-1) const |
Find menu item by given ID (one-level only). More... | |
void | removeMenu (const int, MenuNode *) |
Removes menu node (with all its children). More... | |
QAction * | itemAction (const int) const |
Get action by id. More... | |
QAction * | menuAction (const int) const |
Get submenu action by id. More... | |
int | menuActionId (QAction *) const |
Get submenu action by id. More... | |
void | updateMenu (MenuNode *=0, const bool=true, const bool=true) |
Update menu. More... | |
virtual void | internalUpdate () |
Internal update. More... | |
virtual void | updateContent () |
Called when delayed content update is performed. More... | |
Protected Member Functions inherited from QtxActionMgr | |
int | generateId () const |
Generate unique action identifier. More... | |
void | triggerUpdate () |
Perform delayed update. More... | |
Private Types | |
typedef QList< MenuNode * > | NodeList |
menu nodes list More... | |
typedef QMap< int, QAction * > | MenuMap |
actions map More... | |
Private Slots | |
void | onAboutToShow () |
Called when the submenu is about to show. More... | |
void | onAboutToHide () |
Called when the submenu is about to hide. More... | |
void | onDestroyed (QObject *) |
Called when the corresponding menu object is destroyed. More... | |
Private Member Functions | |
bool | ownAction (QAction *, MenuNode *) const |
Check if action belongs to the menu manager. More... | |
bool | checkWidget (QWidget *) const |
Check if menu widget has any actions. More... | |
QWidget * | menuWidget (MenuNode *) const |
Get menu widget for the given node. More... | |
void | simplifySeparators (QWidget *) |
Remove extra separators from menu widget. More... | |
QString | clearTitle (const QString &) const |
Remove special symbols (&) from string to get clear menu title. More... | |
int | createMenu (const QStringList &, const int) |
Create and inserts menu item recursively. More... | |
void | triggerUpdate (const int, const bool rec=true) |
Perform delayed menu update. More... | |
Private Attributes | |
MenuNode * | myRoot |
root menu node More... | |
QWidget * | myMenu |
menu widget More... | |
MenuMap | myMenus |
actions map More... | |
QMap< int, bool > | myUpdateIds |
list of actions ID being updated More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from QtxActionMgr | |
static QAction * | separator (const bool=false) |
Create new separator action. More... | |
Menu manager allows using of set of action for automatic generating of application main menu and dynamic update of its contents.
Use insert(), append() and remove() methods to create main menu. Methods show(), hide() allow displaying/erasing of specified menu items.
Actions can be grouped with help of group identificator. Inside the popup or main menu bar menu items are ordered by the group identifier (ascending).
Menu manager automatically optimizes the menu by removing extra separators, hiding empty popup menus etc.
|
private |
|
private |
QtxActionMenuMgr::QtxActionMenuMgr | ( | QMainWindow * | p | ) |
p | parent main window |
References myMenu, and onDestroyed().
mw | menu widget |
p | parent object |
References myMenu, and onDestroyed().
int QtxActionMenuMgr::append | ( | const QString & | title, |
const int | pId, | ||
const int | group, | ||
const int | id = -1 |
||
) |
title | menu text |
pId | parent menu action ID |
group | group ID |
id | action ID |
References insert().
id | menu action ID |
title | new menu title |
References menuAction().
|
private |
wid | widget to be checked |
true
if widget contains action(s)
|
private |
txt | string to be processed |
bool QtxActionMenuMgr::containsMenu | ( | const QString & | title, |
const int | pid, | ||
const bool | rec = false |
||
) | const |
title | menu title |
pid | parent menu item ID |
true
if parent menu item contains such child item References find().
id | menu item ID |
pid | parent menu item ID |
true
if parent menu item contains such child item References find().
lst | list of menu names |
pId | parent menu item ID |
References insert().
|
protected |
id | menu action ID |
pId | parent menu item ID |
rec | if true perform recursive search |
|
protected |
id | menu action ID |
startNode | start menu node (if 0, search from root node) |
rec | if true perform recursive search |
References QtxActionMenuMgr::MenuNode::children, find(), and myRoot.
|
protected |
id | menu action ID |
NodeList | resulting list of menu nodes |
startNode | start menu node (if 0, search from root node) |
true
if at least one node is found References QtxActionMenuMgr::MenuNode::children, find(), QtxActionMenuMgr::MenuNode::id, and myRoot.
|
protected |
title | menu item title |
pId | parent menu item ID |
rec | if true perform recursive search |
References find().
|
protected |
title | menu item title |
startNode | start menu node (if 0, search from root node) |
rec | if true perform recursive search |
References QtxActionMenuMgr::MenuNode::children, clearTitle(), find(), itemAction(), menuAction(), and myRoot.
|
protected |
title | menu item title |
NodeList | resulting list of menu nodes |
startNode | start menu node (if 0, search from root node) |
true
if at least one node is found References QtxActionMenuMgr::MenuNode::children, clearTitle(), find(), itemAction(), menuAction(), and myRoot.
id | menu action ID |
pid | parent meun item ID |
References QtxActionMenuMgr::MenuNode::children, find(), and myRoot.
QMenu * QtxActionMenuMgr::findMenu | ( | const QString & | title, |
const int | pid, | ||
const bool | rec = false |
||
) | const |
title | menu text |
pid | parent menu item ID (to start search) |
rec | if true , perform recursive update |
References find(), QtxActionMenuMgr::MenuNode::id, and menuAction().
void QtxActionMenuMgr::hide | ( | const int | id | ) |
int QtxActionMenuMgr::insert | ( | const int | id, |
const QString & | menus, | ||
const int | group, | ||
const int | idx = -1 |
||
) |
Insert an action to the named menu. The menus parameter represents the menu name: it can be a sequence of strings, separated by '|' symbol. For example, "File|Edit" means File->Edit
submenu. If submenu doesn't exist, it will be created.
id | action ID |
menus | menu name |
group | group ID |
idx | menu index inside the menu group |
int QtxActionMenuMgr::insert | ( | QAction * | a, |
const QString & | menus, | ||
const int | group, | ||
const int | idx = -1 |
||
) |
Insert an action to the named menu. The menus parameter represents the menu name: it can be a sequence of strings, separated by '|' symbol. For example, "File|Edit" means File->Edit
submenu. If submenu doesn't exist, it will be created.
a | action |
menus | menu name |
group | group ID |
idx | menu index inside the menu group |
References insert().
int QtxActionMenuMgr::insert | ( | const int | id, |
const QStringList & | menus, | ||
const int | group, | ||
const int | idx = -1 |
||
) |
Insert an action to the named menu. The menus parameter represents the menu names list. For example, string list consisting from two items "File" and "Edit" means File->Edit
submenu. If submenu doesn't exist, it will be created.
id | action ID |
menus | menu names list |
group | group ID |
idx | menu index inside the menu group |
References createMenu(), and insert().
int QtxActionMenuMgr::insert | ( | QAction * | a, |
const QStringList & | menus, | ||
const int | group, | ||
const int | idx = -1 |
||
) |
Insert an action to the named menu. The menus parameter represents the menu names list. For example, string list consisting from two items "File" and "Edit" means File->Edit
submenu. If submenu doesn't exist, it will be created.
a | action |
menus | menu names list |
group | group ID |
idx | menu index inside the menu group |
References createMenu(), and insert().
|
virtual |
id | action ID |
pId | parent menu action ID |
group | group ID |
idx | menu index inside the menu group |
References find(), QtxActionMenuMgr::MenuNode::id, myRoot, and QtxActionMgr::triggerUpdate().
a | action |
pId | parent menu action ID |
group | group ID |
idx | menu index inside the menu group |
References insert(), and QtxActionMgr::registerAction().
int QtxActionMenuMgr::insert | ( | const QString & | title, |
const QString & | menus, | ||
const int | group, | ||
const int | id = -1 , |
||
const int | idx = -1 |
||
) |
Insert an action to the named menu. The menus parameter represents the menu name: it can be a sequence of strings, separated by '|' symbol. For example, "File|Edit" means File->Edit
submenu. If submenu doesn't exist, it will be created.
title | menu text |
menus | menu name |
group | group ID |
id | action ID |
idx | menu index inside the menu group |
References insert().
int QtxActionMenuMgr::insert | ( | const QString & | title, |
const QStringList & | menus, | ||
const int | group, | ||
const int | id = -1 , |
||
const int | idx = -1 |
||
) |
Insert an action to the named menu. The menus parameter represents the menu names list. For example, string list consisting from two items "File" and "Edit" means File->Edit
submenu. If submenu doesn't exist, it will be created.
title | menu text |
menus | menu names list |
group | group ID |
id | action ID |
idx | menu index inside the menu group |
References createMenu(), and insert().
|
virtual |
title | menu text |
pId | parent menu action ID |
group | group ID |
id | action ID |
idx | menu index inside the menu group |
References QtxActionMenuMgr::MenuNode::children, clearTitle(), find(), QtxActionMgr::generateId(), QtxActionMenuMgr::MenuNode::id, myMenus, myRoot, onAboutToHide(), onAboutToShow(), and QtxActionMgr::triggerUpdate().
|
protectedvirtual |
Customizes the menu update processing.
Reimplemented from QtxActionMgr.
Reimplemented in QtxPopupMgr.
References QtxActionMgr::isUpdatesEnabled(), myUpdateIds, and updateMenu().
bool QtxActionMenuMgr::isEmptyEnabled | ( | const int | id | ) | const |
id | menu item ID |
true
if empty menu is enabled References QtxActionMenuMgr::MenuNode::emptyEnabled, find(), and menuAction().
bool QtxActionMenuMgr::isShown | ( | const int | id | ) | const |
id | menu action ID |
true
if an item is shown References find(), and QtxActionMenuMgr::MenuNode::visible.
actId | action ID |
place | some parent action ID |
true
if an action is visible to the parent Reimplemented from QtxActionMgr.
Reimplemented in QtxPopupMgr.
References find(), and QtxActionMenuMgr::MenuNode::visible.
|
virtual |
fname | file name |
r | action reader |
true
on success and false
on error Reimplemented in QtxPopupMgr.
References QtxActionMgr::Reader::read().
|
signal |
m | menu being hidden |
|
signal |
m | menu being shown |
|
protected |
node | menu node |
References QtxActionMenuMgr::MenuNode::id, myMenu, myMenus, and myRoot.
|
privateslot |
Emits the signal menuAboutToHide(QMenu*).
References menuAboutToHide().
|
privateslot |
Emits the signal menuAboutToShow(QMenu*).
References menuAboutToShow().
|
privateslot |
Clears internal pointer to menu to disable crashes.
obj | (menu) object being destroyed |
References myMenu.
a | action being checked |
node | parent menu node |
true
if action belongs to the menu node References QtxActionMenuMgr::MenuNode::children, itemAction(), and menuAction().
int QtxActionMenuMgr::prepend | ( | const QString & | title, |
const int | pId, | ||
const int | group, | ||
const int | id = -1 |
||
) |
title | menu text |
pId | parent menu action ID |
group | group ID |
id | action ID |
References insert().
void QtxActionMenuMgr::remove | ( | const int | id | ) |
id | menu action ID |
References removeMenu(), and QtxActionMgr::update().
id | menu action ID |
pId | parent menu action ID |
group | group ID |
References QtxActionMenuMgr::MenuNode::children, find(), QtxActionMenuMgr::MenuNode::id, itemAction(), menuAction(), menuWidget(), myMenus, myRoot, and QtxActionMgr::triggerUpdate().
id | menu action ID |
startNode | parent menu node which search starts from (if 0, search starts from root) |
References QtxActionMenuMgr::MenuNode::children, and myRoot.
id | menu item ID |
enable | if true , empty menu will be enabled, otherwise empty menu will be disabled |
References QtxActionMenuMgr::MenuNode::emptyEnabled, find(), menuAction(), and updateMenu().
|
protected |
mw | new menu widget |
References myMenu, onDestroyed(), and QtxActionMgr::triggerUpdate().
id | menu action ID |
on | new visibility status |
References find(), QtxActionMenuMgr::MenuNode::id, myRoot, and QtxActionMgr::triggerUpdate().
actId | action ID |
place | some parent action ID |
v | new visibility state |
Reimplemented from QtxActionMgr.
References find(), and QtxActionMenuMgr::MenuNode::visible.
void QtxActionMenuMgr::show | ( | const int | id | ) |
|
private |
wid | menu widget to be processed |
References Qtx::simplifySeparators().
id | menu item ID |
rec | if true , perform recursive update |
References myUpdateIds, and QtxActionMgr::triggerUpdate().
|
protectedvirtual |
Customizes the content update operation.
Reimplemented from QtxActionMgr.
References find(), myRoot, myUpdateIds, and updateMenu().
|
protected |
Does nothing if update is disabled.
startNode | start menu item to be updated |
rec | if true , perform recursive update |
updParent | if true update also parent item (without recursion) |
References checkWidget(), QtxActionMenuMgr::MenuNode::children, QtxActionMenuMgr::MenuNode::emptyEnabled, QtxActionMenuMgr::MenuNode::id, QtxActionMgr::isUpdatesEnabled(), isVisible(), itemAction(), menuAction(), menuWidget(), myRoot, ownAction(), QtxActionMenuMgr::MenuNode::parent, and simplifySeparators().
|
private |
|
private |
|
private |
|
private |