Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QtxPopupMgr Class Reference

Popup menu manager. More...

#include <QtxPopupMgr.h>

Inheritance diagram for QtxPopupMgr:
Inheritance graph

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
 
QtxPopupSelectionselection () const
 Get selection. More...
 
void setSelection (QtxPopupSelection *)
 Set selection. More...
 
QMenumenu () 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...
 
QWidgetmenuWidget () 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...
 
QMenufindMenu (const int) const
 Get menu by the specified identifier. More...
 
QMenufindMenu (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...
 
QActionaction (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...
 
QtxEvalExprexpression (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...
 
MenuNodefind (const int, const int, const bool=true) const
 Search menu node. More...
 
MenuNodefind (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...
 
MenuNodefind (const QString &, const int, const bool=true) const
 Search menu node. More...
 
MenuNodefind (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...
 
QActionitemAction (const int) const
 Get action by id. More...
 
QActionmenuAction (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 *, ExprMapRuleMap
 
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
 
QtxPopupSelectionmySelection
 

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 QActionseparator (const bool=false)
 Create new separator action. More...
 

Detailed Description

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.

Member Typedef Documentation

typedef QMap<QString, QVariant> QtxPopupMgr::CacheMap
private
typedef QMap<RuleType, QtxEvalExpr*> QtxPopupMgr::ExprMap
private
typedef QMap<QAction*, ExprMap> QtxPopupMgr::RuleMap
private

Member Enumeration Documentation

Enumerator
VisibleRule 

menu item visibility state

EnableRule 

menu item enable state

ToggleRule 

menu item toggle state

Constructor & Destructor Documentation

QtxPopupMgr::QtxPopupMgr ( QObject parent = 0)
Parameters
objectparent object
QtxPopupMgr::QtxPopupMgr ( QMenu popup,
QObject parent = 0 
)
Parameters
popuppopup menu
objectparent object
QtxPopupMgr::~QtxPopupMgr ( )
virtual

Member Function Documentation

QtxEvalExpr * QtxPopupMgr::expression ( QAction a,
const RuleType  ruleType = VisibleRule,
const bool  create = false 
) const
protected
Parameters
aaction
ruleTyperule type (QtxPopupMgr::RuleType)
createif true an expression does not exist, create it
Returns
syntax expression

References myRules.

bool QtxPopupMgr::hasRule ( QAction a,
const RuleType  t = VisibleRule 
) const
Returns
true if action has rule of given type
Parameters
a- action
t- rule type

References expression().

bool QtxPopupMgr::hasRule ( const int  id,
const RuleType  t = VisibleRule 
) const
Returns
true if action with given id has rule of given type
Parameters
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 
)
Parameters
idaction ID
pIdparent menu action ID
rulesyntax rule
ruleTyperule type (QtxPopupMgr::RuleType)
Returns
action ID

References QtxActionMgr::action(), QtxActionMenuMgr::insert(), and setRule().

int QtxPopupMgr::insertAction ( QAction a,
const int  pId,
const QString &  rule,
const RuleType  ruleType = VisibleRule 
)
Parameters
aaction
pIdparent menu action ID
rulesyntax rule
ruleTyperule type (QtxPopupMgr::RuleType)
Returns
action ID

References QtxActionMenuMgr::insert(), and setRule().

void QtxPopupMgr::internalUpdate ( )
protectedvirtual
bool QtxPopupMgr::isSatisfied ( QAction act,
const RuleType  ruleType = VisibleRule 
) const
protectedvirtual
Parameters
actaction
ruleTyperule type (QtxPopupMgr::RuleType)
Returns
true if current selection satisfies the action rule

References QtxEvalParser::clearParameters(), QtxPopupSelection::count(), expression(), mySelection, parameter(), QtxEvalExpr::parser(), result(), QtxEvalParser::setParameter(), and setParameters().

bool QtxPopupMgr::isVisible ( const int  id,
const int  place 
) const
virtual
Parameters
idaction ID
placesome parent action ID
Returns
true if the action is visible

Reimplemented from QtxActionMenuMgr.

References QtxActionMgr::action(), hasRule(), isSatisfied(), and QtxActionMenuMgr::isVisible().

bool QtxPopupMgr::load ( const QString &  fname,
QtxActionMgr::Reader r 
)
virtual
Parameters
fnamefile name
raction reader
Returns
true on success and false on error

Reimplemented from QtxActionMenuMgr.

References QtxActionMgr::Reader::read().

QMenu * QtxPopupMgr::menu ( ) const
Returns
popup menu

References QtxActionMenuMgr::menuWidget().

void QtxPopupMgr::onSelectionDestroyed ( QObject o)
privateslot

Prevents crashes when the selection object is destroyed outside the popup manager.

Parameters
oselection object being destroyed

References mySelection.

QVariant QtxPopupMgr::parameter ( const QString &  name,
const int  idx = -1 
) const
private
int QtxPopupMgr::registerAction ( QAction act,
const int  id,
const QString &  rule,
const RuleType  ruleType = VisibleRule 
)
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.

Parameters
actaction to be registered
idaction ID
rulesyntax rule
ruleTyperule type (QtxPopupMgr::RuleType)
Returns
action ID (the same as id or generated one)

References QtxActionMgr::registerAction(), and setRule().

bool QtxPopupMgr::result ( QtxEvalParser p) const
private
Parameters
pexpression parser
Returns
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
Parameters
aaction
ruleTyperule type (QtxPopupMgr::RuleType)
Returns
rule of required type

References QtxEvalExpr::expression(), and expression().

QString QtxPopupMgr::rule ( const int  id,
const RuleType  ruleType = VisibleRule 
) const
Parameters
idaction ID
ruleTyperule type (QtxPopupMgr::RuleType)
Returns
rule of required type

References QtxActionMgr::action(), and rule().

QtxPopupSelection * QtxPopupMgr::selection ( ) const
Returns
current selection object

References mySelection.

void QtxPopupMgr::setMenu ( QMenu menu)
Parameters
menupopup menu

References QtxActionMenuMgr::setMenuWidget().

void QtxPopupMgr::setParameters ( QtxEvalParser p,
QStringList &  specific 
) const
protected

The values of the parameters are given from the selection object (QtxPopupSelection).

Parameters
pexpression parser
returninglist of parameters names which are not retrieved from the selection
See Also
selection()

References mySelection, parameter(), QtxEvalParser::parameters(), and QtxEvalParser::setParameter().

void QtxPopupMgr::setRule ( QAction a,
const QString &  rule,
const RuleType  ruleType = VisibleRule 
)
Parameters
aaction
rulerule
ruleTyperule type (QtxPopupMgr::RuleType)
Returns
rule of required type

References expression(), and QtxEvalExpr::setExpression().

void QtxPopupMgr::setRule ( const int  id,
const QString &  rule,
const RuleType  ruleType = VisibleRule 
)
Parameters
idaction ID
rulerule
ruleTyperule type (QtxPopupMgr::RuleType)
Returns
rule of required type

References QtxActionMgr::action(), and setRule().

void QtxPopupMgr::setSelection ( QtxPopupSelection sel)
void QtxPopupMgr::unRegisterAction ( const int  id)
virtual
Parameters
idaction ID

Reimplemented from QtxActionMgr.

References QtxActionMgr::action(), myRules, and QtxActionMgr::unRegisterAction().

void QtxPopupMgr::updateMenu ( )

References internalUpdate().

Friends And Related Function Documentation

friend class QtxPopupSelection
friend

Member Data Documentation

CacheMap QtxPopupMgr::myCache
private
RuleMap QtxPopupMgr::myRules
private
QtxPopupSelection* QtxPopupMgr::mySelection
private

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