Salome HOME
4ec9a0400fea00e28171679b61073592422ad33c
[modules/gui.git] / src / Qtx / QtxPopupMgr.h
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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
23 // File:      QtxPopupMgr.h
24 // Author:    Alexander SOLOVYOV, Sergey TELKOV
25 //
26 #ifndef QTXPOPUPMGR_H
27 #define QTXPOPUPMGR_H
28
29 #include "QtxActionMenuMgr.h"
30
31 #include <QMap>
32 #include <QVariant>
33
34 class QtxEvalExpr;
35 class QtxEvalParser;
36 class QtxPopupSelection;
37
38 class QTX_EXPORT QtxPopupMgr : public QtxActionMenuMgr
39 {
40   Q_OBJECT
41
42 public:
43   //! Menu item rule type
44   typedef enum { 
45     VisibleRule,   //!< menu item visibility state
46     EnableRule,    //!< menu item enable state
47     ToggleRule     //!< menu item toggle state
48   } RuleType;
49
50 private:
51   class PopupCreator;
52
53 public:
54   QtxPopupMgr( QObject* = 0 );
55   QtxPopupMgr( QMenu*, QObject* = 0 );
56   virtual ~QtxPopupMgr();
57
58   int                insertAction( const int, const int, const QString&, const RuleType = VisibleRule );
59   int                insertAction( QAction*, const int, const QString&, const RuleType = VisibleRule );
60
61   virtual int        registerAction( QAction*, const int, const QString& rule,
62                                      const RuleType = VisibleRule );
63   virtual void       unRegisterAction( const int );
64
65   virtual bool       isVisible( const int actId, const int place ) const;
66
67   QString            rule( QAction*, const RuleType = VisibleRule ) const;
68   QString            rule( const int, const RuleType = VisibleRule ) const;
69
70   void               setRule( QAction*, const QString&, const RuleType = VisibleRule );
71   void               setRule( const int, const QString&, const RuleType = VisibleRule );
72
73   bool               hasRule( QAction*, const RuleType = VisibleRule ) const;
74   bool               hasRule( const int, const RuleType = VisibleRule ) const;
75
76   QtxPopupSelection* selection() const;
77   void               setSelection( QtxPopupSelection* );
78
79   QMenu*             menu() const;
80   void               setMenu( QMenu* );
81
82   void               updateMenu();
83
84   virtual bool       load( const QString&, QtxActionMgr::Reader& );
85
86 protected:
87   virtual void       internalUpdate();
88   void               setParameters( QtxEvalParser*, QStringList& ) const;
89   virtual bool       isSatisfied( QAction*, const RuleType = VisibleRule ) const;
90   QtxEvalExpr*       expression( QAction*, const RuleType = VisibleRule, const bool = false ) const;
91
92 private:
93   bool               result( QtxEvalParser* p ) const;
94   QVariant           parameter( const QString&, const int = -1 ) const;
95
96 private slots:
97   void               onSelectionDestroyed( QObject* );
98
99 private:
100   typedef QMap<RuleType, QtxEvalExpr*> ExprMap;
101   typedef QMap<QAction*, ExprMap>      RuleMap;
102   typedef QMap<QString, QVariant>      CacheMap;
103
104 private:
105   RuleMap            myRules;
106   CacheMap           myCache;
107   QtxPopupSelection* mySelection;
108
109   friend class QtxPopupSelection;
110 };
111
112 class QTX_EXPORT QtxPopupSelection : public QObject
113 {
114   Q_OBJECT
115
116 public:
117   QtxPopupSelection();
118   virtual ~QtxPopupSelection();
119
120   virtual int        count() const = 0;
121   virtual QVariant   parameter( const QString& ) const;
122   virtual QVariant   parameter( const int, const QString& ) const = 0;
123
124   QString            option( const QString& ) const;
125   void               setOption( const QString&, const QString& );
126
127   QtxPopupMgr*       popupMgr() const;
128   void               setPopupMgr( QtxPopupMgr* );
129
130 private:
131   QString            equalityParam() const;
132   QString            selCountParam() const;
133
134 private:
135   typedef QMap<QString, QString> OptionsMap;
136   typedef QPointer<QtxPopupMgr>  PopupMgrPtr;
137
138 private:
139   OptionsMap         myOptions;
140   PopupMgrPtr        myPopupMgr;
141 };
142
143 #endif // QTXPOPUPMGR_H