Salome HOME
8a82362f079342e054c7442df986aceca61a3a2f
[modules/gui.git] / src / Qtx / QtxActionMgr.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 // File:      QtxActionMgr.h
20 // Author:    Alexander SOLOVYEV, Sergey TELKOV
21
22 #ifndef QTXACTIONMGR_H
23 #define QTXACTIONMGR_H
24
25 #include "Qtx.h"
26
27 #include <qmap.h>
28 #include <qobject.h>
29 #include <qguardedptr.h>
30
31 class QAction;
32 class QDomNode;
33
34
35 #ifdef WIN32
36 #pragma warning( disable:4251 )
37 #endif
38
39
40 /*!
41   \class QtxActionMgr
42   Contains set of actions accessible by id.
43   Base class for menu, popup creators and other action containers.
44 */
45 class QTX_EXPORT QtxActionMgr : public QObject
46 {
47   Q_OBJECT 
48
49   class SeparatorAction;
50
51 public:
52   class Reader;
53   class XMLReader;
54
55 protected:
56   class Creator;
57
58 public:
59   QtxActionMgr( QObject* parent );
60   virtual ~QtxActionMgr();
61
62   virtual int      registerAction( QAction*, const int = -1 );
63   virtual void     unRegisterAction( const int );
64
65   QAction*         action( const int ) const;
66   int              actionId( const QAction* ) const;
67   bool             contains( const int ) const;
68
69   int              count() const;
70   bool             isEmpty() const;
71   void             idList( QIntList& ) const;
72
73   bool             isUpdatesEnabled() const;
74   virtual void     setUpdatesEnabled( const bool );
75
76   virtual bool     isVisible( const int, const int ) const;
77   virtual void     setVisible( const int, const int, const bool );
78
79   void             update();
80
81   virtual bool     isEnabled( const int ) const;
82   virtual void     setEnabled( const int, const bool );
83
84   static QAction*  separator( const bool = false );
85
86 protected:
87   virtual void     internalUpdate();
88   int              generateId() const;
89
90 private:
91   typedef QGuardedPtr<QAction> ActionPtr;
92   typedef QMap<int, ActionPtr> ActionMap;
93
94 private:
95   bool             myUpdate;
96   ActionMap        myActions;
97 };
98
99
100 QTX_EXPORT typedef QMap<QString, QString> ItemAttributes;
101
102 /*!
103   \class QtxActionMgr::Creator
104   Allows to fill automatically action manager with actions created by data from file
105 */
106 class QtxActionMgr::Creator
107 {
108 public:
109   Creator( QtxActionMgr::Reader* );
110   virtual ~Creator();
111
112   Reader* reader() const;
113
114   virtual int append( const QString&, const bool,
115                       const ItemAttributes&, const int ) = 0;
116   virtual void connect( QAction* ) const;
117
118   virtual bool loadPixmap( const QString&, QPixmap& ) const;
119
120 protected:
121   static int     intValue( const ItemAttributes&, const QString&, const int );
122   static QString strValue( const ItemAttributes&, const QString&,
123                                       const QString& = QString::null );
124 private:
125   QtxActionMgr::Reader*  myReader;
126 };
127
128 /*!
129   \class QtxActionMgr::Reader
130   This class is used to read files of some format
131   to create actions and to fill action manager automatically
132 */
133 class QtxActionMgr::Reader
134 {
135 public:
136   QTX_EXPORT Reader();
137   QTX_EXPORT virtual ~Reader();
138
139   QTX_EXPORT QStringList  options() const;
140   QTX_EXPORT QString      option( const QString&, const QString& = QString::null ) const;
141   QTX_EXPORT void         setOption( const QString&, const QString& );
142
143   QTX_EXPORT virtual bool read( const QString&, Creator& ) const = 0;
144
145 private:
146   QMap< QString, QString > myOptions;
147 };
148
149 /*!
150   \class QtxActionMgr::Reader
151   This class is used to read files of XML format
152   to create actions and to fill action manager automatically
153 */
154 class QtxActionMgr::XMLReader : public Reader
155 {
156 public:
157   QTX_EXPORT XMLReader( const QString&, const QString&, const QString& );
158   QTX_EXPORT virtual ~XMLReader();
159
160   QTX_EXPORT virtual bool read( const QString&, Creator& ) const;
161
162 protected:
163   QTX_EXPORT virtual void read( const QDomNode&, const int, Creator& ) const;
164   QTX_EXPORT virtual bool isNodeSimilar( const QDomNode&, const QString& ) const;
165 };
166
167
168 #endif