Version: 9.12.0
QtxActionMenuMgr.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2023 CEA, EDF, 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: QtxActionMenuMgr.h
24 // Author: Alexander SOLOVYOV, Sergey TELKOV
25 //
26 #ifndef QTXACTIONMENUMGR_H
27 #define QTXACTIONMENUMGR_H
28 
29 #include "Qtx.h"
30 #include "QtxActionMgr.h"
31 
32 #include <QList>
33 
34 class QMenu;
35 class QMainWindow;
36 class QStringList;
37 
38 #ifdef WIN32
39 #pragma warning( disable:4251 )
40 #endif
41 
43 {
44  Q_OBJECT
45 
46  class MenuNode;
47 
49 
50 protected:
51  class MenuCreator;
52 
53 public:
56  virtual ~QtxActionMenuMgr();
57 
58  QWidget* menuWidget() const;
59 
60  virtual bool isVisible( const int, const int ) const;
61  virtual void setVisible( const int, const int, const bool );
62 
63  int insert( const int, const QString&, const int, const int = -1 );
64  int insert( QAction*, const QString&, const int, const int = -1 );
65 
66  int insert( const int, const QStringList&, const int, const int = -1 );
67  int insert( QAction*, const QStringList&, const int, const int = -1 );
68 
69  virtual int insert( const int, const int, const int, const int = -1 );
70  int insert( QAction*, const int, const int, const int = -1 );
71 
72  int insert( const QString&, const QString&, const int, const int = -1, const int = -1 );
73  int insert( const QString&, const QStringList&, const int, const int = -1, const int = -1 );
74  virtual int insert( const QString&, const int, const int, const int = -1, const int = -1 , QMenu* = 0);
75 
76  int append( const int, const int, const int );
77  int append( QAction*, const int, const int );
78  int append( const QString&, const int, const int, const int = -1 );
79 
80  int prepend( const int, const int, const int );
81  int prepend( QAction*, const int, const int );
82  int prepend( const QString&, const int, const int, const int = -1 );
83 
84  void remove( const int );
85  void remove( const int, const int, const int = -1 );
86 
87  void show( const int );
88  void hide( const int );
89 
90  bool isShown( const int ) const;
91  void setShown( const int, const bool );
92 
93  virtual void change( const int, const QString& );
94 
95  virtual bool load( const QString&, QtxActionMgr::Reader& );
96 
97  bool containsMenu( const QString&, const int, const bool = false ) const;
98  bool containsMenu( const int, const int, const bool = false ) const;
99 
100  QMenu* findMenu( const int ) const;
101  QMenu* findMenu( const QString&, const int, const bool = false ) const;
102 
103  bool isEmptyEnabled( const int ) const;
104  void setEmptyEnabled( const int, const bool );
105 
106 private slots:
107  void onAboutToShow();
108  void onAboutToHide();
109  void onDestroyed( QObject* );
110 
111 signals:
114 
115 protected:
116  void setMenuWidget( QWidget* );
117 
118  MenuNode* find( const int, const int, const bool = true ) const;
119  MenuNode* find( const int, MenuNode* = 0, const bool = true ) const;
120  bool find( const int, NodeList&, MenuNode* = 0 ) const;
121  MenuNode* find( const QString&, const int, const bool = true ) const;
122  MenuNode* find( const QString&, MenuNode* = 0, const bool = true ) const;
123  bool find( const QString&, NodeList&, MenuNode* = 0 ) const;
124  int findId( const int, const int = -1 ) const;
125 
126  void removeMenu( const int, MenuNode* );
127 
128  QAction* itemAction( const int ) const;
129  QAction* menuAction( const int ) const;
130  int menuActionId( QAction* ) const;
131 
132  void updateMenu( MenuNode* = 0, const bool = true, const bool = true );
133  virtual void internalUpdate();
134  virtual void updateContent();
135  virtual void actionChanged( int );
136 
137 private:
138  bool ownAction( QAction*, MenuNode* ) const;
139  bool checkWidget( QWidget* ) const;
140  QWidget* menuWidget( MenuNode* ) const;
141  void simplifySeparators( QWidget* );
142  QString clearTitle( const QString& ) const;
143  int createMenu( const QStringList&, const int );
144 
145  void triggerUpdate( const int, const bool rec = true );
146 
147 private:
148  typedef QMap<int, QAction*> MenuMap;
149 
150 private:
154  QMap<int, bool> myUpdateIds;
155 };
156 
158 {
159 public:
161  virtual ~MenuCreator();
162 
163  virtual int append( const QString&, const bool,
164  const ItemAttributes&, const int );
165 
166 private:
168 };
169 
170 
171 #endif
QMap< QString, QString > ItemAttributes
attributes map
Definition: QtxActionMgr.h:108
#define QTX_EXPORT
Definition: Qtx.h:36
For more information see QT documentation.
Definition: SUIT_Application.h:42
Menu actions creator.
Definition: QtxActionMenuMgr.h:158
virtual int append(const QString &, const bool, const ItemAttributes &, const int)
Create and append to the action manager a new action.
Definition: QtxActionMenuMgr.cxx:1284
QtxActionMenuMgr * myMgr
menu manager
Definition: QtxActionMenuMgr.h:167
virtual ~MenuCreator()
Destructor.
Definition: QtxActionMenuMgr.cxx:1272
MenuCreator(QtxActionMgr::Reader *, QtxActionMenuMgr *)
Constructor.
Definition: QtxActionMenuMgr.cxx:1263
Represents a menu item inside main menu structure.
Definition: QtxActionMenuMgr.cxx:42
Main menu actions manager.
Definition: QtxActionMenuMgr.h:43
QMap< int, QAction * > MenuMap
actions map
Definition: QtxActionMenuMgr.h:148
QWidget * myMenu
menu widget
Definition: QtxActionMenuMgr.h:152
MenuMap myMenus
actions map
Definition: QtxActionMenuMgr.h:153
QMap< int, bool > myUpdateIds
list of actions ID being updated
Definition: QtxActionMenuMgr.h:154
MenuNode * myRoot
root menu node
Definition: QtxActionMenuMgr.h:151
void menuAboutToShow(QMenu *)
Emitted when the menu is about to be shown.
QList< MenuNode * > NodeList
menu nodes list
Definition: QtxActionMenuMgr.h:46
void menuAboutToHide(QMenu *)
Emitted when the menu is about to be hidden.
Generic actions creator class.
Definition: QtxActionMgr.h:111
Generic actions description files reader class.
Definition: QtxActionMgr.h:133
Manages a set of actions accessible by unique identifier.
Definition: QtxActionMgr.h:45
virtual bool isVisible(const int, const int) const
Check if an action with actId identifier is visible to the parent action with place identifier.
Definition: QtxActionMgr.cxx:284
virtual void internalUpdate()
Internal update.
Definition: QtxActionMgr.cxx:329
virtual void updateContent()
Internal content update operation.
Definition: QtxActionMgr.cxx:423
virtual void actionChanged(int)
Internal action changing response operation.
Definition: QtxActionMgr.cxx:430
virtual void setVisible(const int, const int, const bool)
Set action's visibility flag.
Definition: QtxActionMgr.cxx:300
void triggerUpdate()
Perform delayed update.
Definition: QtxActionMgr.cxx:399