Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / Qtx / QtxPopupMgr.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      QtxPopupMgr.h
23 // Author:    Alexander SOLOVYOV, Sergey TELKOV
24 //
25 #ifndef QTXPOPUPMGR_H
26 #define QTXPOPUPMGR_H
27
28 #include "QtxActionMenuMgr.h"
29
30 #include <QMap>
31 #include <QVariant>
32
33 class QtxEvalExpr;
34 class QtxEvalParser;
35 class QtxPopupSelection;
36
37 class QTX_EXPORT QtxPopupMgr : public QtxActionMenuMgr
38 {
39   Q_OBJECT
40
41 public:
42   //! Menu item rule type
43   typedef enum { 
44     VisibleRule,   //!< menu item visibility state
45     EnableRule,    //!< menu item enable state
46     ToggleRule     //!< menu item toggle state
47   } RuleType;
48
49 private:
50   class PopupCreator;
51
52 public:
53   QtxPopupMgr( QObject* = 0 );
54   QtxPopupMgr( QMenu*, QObject* = 0 );
55   virtual ~QtxPopupMgr();
56
57   int                insertAction( const int, const int, const QString&, const RuleType = VisibleRule );
58   int                insertAction( QAction*, const int, const QString&, const RuleType = VisibleRule );
59
60   virtual int        registerAction( QAction*, const int, const QString& rule,
61                                      const RuleType = VisibleRule );
62   virtual void       unRegisterAction( const int );
63
64   virtual bool       isVisible( const int actId, const int place ) const;
65
66   QString            rule( QAction*, const RuleType = VisibleRule ) const;
67   QString            rule( const int, const RuleType = VisibleRule ) const;
68
69   void               setRule( QAction*, const QString&, const RuleType = VisibleRule );
70   void               setRule( const int, const QString&, const RuleType = VisibleRule );
71
72   bool               hasRule( QAction*, const RuleType = VisibleRule ) const;
73   bool               hasRule( const int, const RuleType = VisibleRule ) const;
74
75   QtxPopupSelection* selection() const;
76   void               setSelection( QtxPopupSelection* );
77
78   QMenu*             menu() const;
79   void               setMenu( QMenu* );
80
81   void               updateMenu();
82
83   virtual bool       load( const QString&, QtxActionMgr::Reader& );
84
85 protected:
86   virtual void       internalUpdate();
87   void               setParameters( QtxEvalParser*, QStringList& ) const;
88   virtual bool       isSatisfied( QAction*, const RuleType = VisibleRule ) const;
89   QtxEvalExpr*       expression( QAction*, const RuleType = VisibleRule, const bool = false ) const;
90
91 private:
92   bool               result( QtxEvalParser* p ) const;
93   QVariant           parameter( const QString&, const int = -1 ) const;
94
95 private slots:
96   void               onSelectionDestroyed( QObject* );
97
98 private:
99   typedef QMap<RuleType, QtxEvalExpr*> ExprMap;
100   typedef QMap<QAction*, ExprMap>      RuleMap;
101   typedef QMap<QString, QVariant>      CacheMap;
102
103 private:
104   RuleMap            myRules;
105   CacheMap           myCache;
106   QtxPopupSelection* mySelection;
107 };
108
109 class QTX_EXPORT QtxPopupSelection : public QObject
110 {
111   Q_OBJECT
112
113 public:
114   QtxPopupSelection();
115   virtual ~QtxPopupSelection();
116
117   virtual int        count() const = 0;
118   virtual QVariant   parameter( const QString& ) const;
119   virtual QVariant   parameter( const int, const QString& ) const = 0;
120
121   QString            option( const QString& ) const;
122   void               setOption( const QString&, const QString& );
123
124 private:
125   QString            equalityParam() const;
126   QString            selCountParam() const;
127
128 private:
129   typedef QMap<QString, QString> OptionsMap;
130
131 private:
132   OptionsMap         myOptions;
133 };
134
135 #endif // QTXPOPUPMGR_H