Popup menu manager. More...
#include <QtxPopupMgr.h>
Classes | |
class | PopupCreator |
Popup menu actions creator. More... | |
Public Types | |
enum | RuleType { VisibleRule, EnableRule, ToggleRule } |
Menu item rule type. More... | |
Public Member Functions | |
QtxPopupMgr (QObject *=0) | |
Constructor. More... | |
QtxPopupMgr (QMenu *, QObject *=0) | |
Constructor. More... | |
virtual | ~QtxPopupMgr () |
Destructor. More... | |
int | insertAction (const int, const int, const QString &, const RuleType=VisibleRule) |
Insert action to the popup menu manager. More... | |
int | insertAction (QAction *, const int, const QString &, const RuleType=VisibleRule) |
Insert action to the popup menu manager. More... | |
virtual int | registerAction (QAction *, const int, const QString &rule, const RuleType=VisibleRule) |
Register an action and return its identifier. More... | |
virtual void | unRegisterAction (const int) |
Unregister action from internal map. More... | |
virtual bool | isVisible (const int actId, const int place) const |
Check if the menu item is visible. More... | |
QString | rule (QAction *, const RuleType=VisibleRule) const |
Get rule of type type for the action a. More... | |
QString | rule (const int, const RuleType=VisibleRule) const |
Get rule of type type for the action id. More... | |
void | setRule (QAction *, const QString &, const RuleType=VisibleRule) |
Set rule of type type for the action a. More... | |
void | setRule (const int, const QString &, const RuleType=VisibleRule) |
Set rule of type type for the action id. More... | |
bool | hasRule (QAction *, const RuleType=VisibleRule) const |
bool | hasRule (const int, const RuleType=VisibleRule) const |
QtxPopupSelection * | selection () const |
Get selection. More... | |
void | setSelection (QtxPopupSelection *) |
Set selection. More... | |
QMenu * | menu () const |
Get popup menu. More... | |
void | setMenu (QMenu *) |
Get popup menu. More... | |
void | updateMenu () |
Update popup according to the current selection. More... | |
virtual bool | load (const QString &, QtxActionMgr::Reader &) |
Load actions description from the file. More... | |
Public Member Functions inherited from QtxActionMenuMgr | |
QtxActionMenuMgr (QMainWindow *) | |
Constructor. More... | |
QtxActionMenuMgr (QWidget *, QObject *) | |
Constructor. More... | |
virtual | ~QtxActionMenuMgr () |
Destructor. More... | |
QWidget * | menuWidget () const |
Get the menu widget. 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... | |
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... | |
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 | |
virtual void | internalUpdate () |
Perform internal update of the popup menu according to the current selection. More... | |
void | setParameters (QtxEvalParser *, QStringList &) const |
Fill the parser with parameters of the expression. More... | |
virtual bool | isSatisfied (QAction *, const RuleType=VisibleRule) const |
Check the rule for the action. More... | |
QtxEvalExpr * | expression (QAction *, const RuleType=VisibleRule, const bool=false) const |
Get an syntax expression for the action according to the specified rule type. More... | |
Protected Member Functions inherited from QtxActionMenuMgr | |
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 | 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 QMap< RuleType, QtxEvalExpr * > | ExprMap |
typedef QMap< QAction *, ExprMap > | RuleMap |
typedef QMap< QString, QVariant > | CacheMap |
Private Slots | |
void | onSelectionDestroyed (QObject *) |
Called when selection is destroyed. More... | |
Private Member Functions | |
bool | result (QtxEvalParser *p) const |
Calculate an expression. More... | |
QVariant | parameter (const QString &, const int=-1) const |
Private Attributes | |
RuleMap | myRules |
CacheMap | myCache |
QtxPopupSelection * | mySelection |
Friends | |
class | QtxPopupSelection |
Additional Inherited Members | |
Signals inherited from QtxActionMenuMgr | |
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... | |
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 context popup menu by reuquest and dynamic update of its contents.
Use insert() methods to add menu items to the popup menu.
The visibility, enable and toggle state of the menu item is controlled by the syntaxic rules, which can be set with setRule() methods. The rules are parsed automatically with help of QtxEvalParser class.
QtxPopupSelection class is used as back-end for getting value of each parameter found in the rule by the expression parser. Use setSelection() and selection() to set/get the selection instance for the popup menu manager.
Popup menu manager automatically optimizes the menu by removing extra separators, hiding empty popup submenus etc.
|
private |
|
private |
|
private |
QtxPopupMgr::QtxPopupMgr | ( | QObject * | parent = 0 | ) |
object | parent object |
popup | popup menu |
object | parent object |
|
virtual |
|
protected |
a | action |
ruleType | rule type (QtxPopupMgr::RuleType) |
create | if true an expression does not exist, create it |
References myRules.
bool QtxPopupMgr::hasRule | ( | QAction * | a, |
const RuleType | t = VisibleRule |
||
) | const |
a | - action |
t | - rule type |
References expression().
bool QtxPopupMgr::hasRule | ( | const int | id, |
const RuleType | t = VisibleRule |
||
) | const |
id | - action id |
t | - rule type |
References QtxActionMgr::action(), and hasRule().
int QtxPopupMgr::insertAction | ( | const int | id, |
const int | pId, | ||
const QString & | rule, | ||
const RuleType | ruleType = VisibleRule |
||
) |
id | action ID |
pId | parent menu action ID |
rule | syntax rule |
ruleType | rule type (QtxPopupMgr::RuleType) |
References QtxActionMgr::action(), QtxActionMenuMgr::insert(), and setRule().
int QtxPopupMgr::insertAction | ( | QAction * | a, |
const int | pId, | ||
const QString & | rule, | ||
const RuleType | ruleType = VisibleRule |
||
) |
a | action |
pId | parent menu action ID |
rule | syntax rule |
ruleType | rule type (QtxPopupMgr::RuleType) |
References QtxActionMenuMgr::insert(), and setRule().
|
protectedvirtual |
Reimplemented from QtxActionMenuMgr.
References QtxActionMenuMgr::internalUpdate(), isSatisfied(), myCache, myRules, and ToggleRule.
|
protectedvirtual |
act | action |
ruleType | rule type (QtxPopupMgr::RuleType) |
true
if current selection satisfies the action rule References QtxEvalParser::clearParameters(), QtxPopupSelection::count(), expression(), mySelection, parameter(), QtxEvalExpr::parser(), result(), QtxEvalParser::setParameter(), and setParameters().
id | action ID |
place | some parent action ID |
true
if the action is visible Reimplemented from QtxActionMenuMgr.
References QtxActionMgr::action(), hasRule(), isSatisfied(), and QtxActionMenuMgr::isVisible().
|
virtual |
fname | file name |
r | action reader |
true
on success and false
on error Reimplemented from QtxActionMenuMgr.
References QtxActionMgr::Reader::read().
QMenu * QtxPopupMgr::menu | ( | ) | const |
References QtxActionMenuMgr::menuWidget().
|
privateslot |
Prevents crashes when the selection object is destroyed outside the popup manager.
o | selection object being destroyed |
References mySelection.
References myCache, QtxPopupSelection::parameter(), and selection().
|
virtual |
If id is less than 0, the identifier for the action is generated automatically. If action with given id is already registered, it will be re-registered. If required id is already in use, new identifier is generatied; in this case returning value will different from required one.
act | action to be registered |
id | action ID |
rule | syntax rule |
ruleType | rule type (QtxPopupMgr::RuleType) |
References QtxActionMgr::registerAction(), and setRule().
|
private |
p | expression parser |
true
if parser has finished work without errors References QtxEvalParser::calculate(), QtxEvalParser::error(), and QtxEvalExpr::OK.
QString QtxPopupMgr::rule | ( | QAction * | a, |
const RuleType | ruleType = VisibleRule |
||
) | const |
a | action |
ruleType | rule type (QtxPopupMgr::RuleType) |
References QtxEvalExpr::expression(), and expression().
QString QtxPopupMgr::rule | ( | const int | id, |
const RuleType | ruleType = VisibleRule |
||
) | const |
id | action ID |
ruleType | rule type (QtxPopupMgr::RuleType) |
References QtxActionMgr::action(), and rule().
QtxPopupSelection * QtxPopupMgr::selection | ( | ) | const |
References mySelection.
void QtxPopupMgr::setMenu | ( | QMenu * | menu | ) |
menu | popup menu |
References QtxActionMenuMgr::setMenuWidget().
|
protected |
The values of the parameters are given from the selection object (QtxPopupSelection).
p | expression parser |
returning | list of parameters names which are not retrieved from the selection |
References mySelection, parameter(), QtxEvalParser::parameters(), and QtxEvalParser::setParameter().
void QtxPopupMgr::setRule | ( | QAction * | a, |
const QString & | rule, | ||
const RuleType | ruleType = VisibleRule |
||
) |
a | action |
rule | rule |
ruleType | rule type (QtxPopupMgr::RuleType) |
References expression(), and QtxEvalExpr::setExpression().
void QtxPopupMgr::setRule | ( | const int | id, |
const QString & | rule, | ||
const RuleType | ruleType = VisibleRule |
||
) |
id | action ID |
rule | rule |
ruleType | rule type (QtxPopupMgr::RuleType) |
References QtxActionMgr::action(), and setRule().
void QtxPopupMgr::setSelection | ( | QtxPopupSelection * | sel | ) |
sel | new selection object |
References mySelection, onSelectionDestroyed(), QtxPopupSelection::setPopupMgr(), and QtxActionMgr::triggerUpdate().
|
virtual |
id | action ID |
Reimplemented from QtxActionMgr.
References QtxActionMgr::action(), myRules, and QtxActionMgr::unRegisterAction().
void QtxPopupMgr::updateMenu | ( | ) |
References internalUpdate().
|
friend |
|
private |
|
private |
|
private |