OpendTect-6_4  6.4
uiaction.h
Go to the documentation of this file.
1 #ifndef uiaction_h
2 #define uiaction_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Nanne Hemstra
9  Date: May 2007
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "uibasemod.h"
16 
17 #include "separstr.h"
18 #include "uistring.h"
19 #include "uibaseobject.h"
20 
21 
22 class i_ActionMessenger;
23 class uiActionContainer;
24 class uiIcon;
25 class uiMenu;
26 class uiPixmap;
27 class MenuItem;
28 
29 mFDQtclass(QAction)
30 mFDQtclass(QMenu)
31 
32 
36 mExpClass(uiBase) uiAction : public CallBacker
37 {
38 friend class i_ActionMessenger;
39 public:
40  uiAction(const uiString&);
41  uiAction(const uiString&,const CallBack&);
42  uiAction(const uiString&,const CallBack&,
43  const uiIcon&);
44  uiAction(const uiString&,const CallBack&,
45  const char* icon_identifier);
46  uiAction(const uiString&,const char* icon_identifier);
47  uiAction(const MenuItem&);
48  uiAction(mQtclass(QAction*));
49  ~uiAction();
50 
51  void setText(const uiString&);
52  const uiString& text() const;
54  void setIconText(const uiString&);
55  const uiString& iconText() const;
57  void setToolTip(const uiString&);
58  const uiString& toolTip() const;
61  static void updateToolTips();
62  void setMenu(uiMenu*);
64 
65  uiMenu* getMenu() { return menu_; }
66  const uiMenu* getMenu() const { return menu_; }
67 
68  void setShortcut(const char*);
69 
70  void setIcon(const char* identifier);
71  void setIcon(const uiIcon&);
72  const char* getIconName() const { return iconfile_; }
73  void setPixmap(const uiPixmap&);
74 
75  void setCheckable(bool);
76  bool isCheckable() const;
77  void setChecked(bool);
78  bool isChecked() const;
79  void setEnabled(bool);
80  bool isEnabled() const;
81  void setVisible(bool);
82  bool isVisible() const;
83 
84  void setSeparator(bool);
85  bool isSeparator() const;
86 
87  void setParentContainer(const uiActionContainer*);
88  int getID() const;
91  mQtclass(QAction*) qaction() { return qaction_; }
92  const mQtclass(QAction*) qaction() const { return qaction_; }
93 
96 
97  void reloadIcon();
98 
99 protected:
100 
101  virtual void trigger(bool checked);
102  void translateCB(CallBacker*);
103 
104  void updateToolTip(CallBacker* = 0);
105  uiString tooltip_;
106  uiString text_;
107  uiString icontext_;
108 
109  void updateEnabled(CallBacker* = 0);
110  void updateCheckable(CallBacker* = 0);
111  void updateChecked(CallBacker* = 0);
112  void updateVisible(CallBacker* = 0);
113  bool enabled_;
114  bool checkable_;
115  bool ischecked_;
116  bool visible_;
117 
118 private:
119 
120  uiMenu* menu_;
121 
122  BufferString iconfile_;
123  const uiActionContainer* parentcontainer_;
124  i_ActionMessenger* msgr_;
125  mQtclass(QAction*) qaction_;
126 
127  bool checked_;
128 
129  int cmdrecrefnr_;
130 
131  void init(const uiString&);
132 
133 public:
135  static void addCmdRecorder(const CallBack&);
136  static void removeCmdRecorder(const CallBack&);
137  int /* refnr */ beginCmdRecEvent(const char* msg=0);
138  void endCmdRecEvent(int refnr,const char* msg=0);
139 };
140 
145 {
146 public:
147  uiActionSeparString(const char* str=0) : SeparString(str,'`') {}
148 };
149 
150 
151 /*Generalization of a menubar, a menu or a toolbar that can contain actions. */
153 {
154 public:
155  virtual ~uiActionContainer();
156 
157  int nrActions() const;
158  const ObjectSet<uiAction>& actions() const;
159  bool isEmpty() const;
160 
161  uiAction* findAction(const uiActionSeparString&);
162  uiAction* findAction(const char* itmtxt);
163  uiAction* findAction(const uiString& itmtxt);
165  uiAction* findAction(int id);
166  uiAction* findAction(const uiMenu*);
168  { return findAction(fs.str()); }
169  int getID(const uiAction*) const;
170  int getID(const mQtclass(QAction)*) const;
171 
172  int insertAction(uiAction*,int id=-1,
173  const uiAction* before = 0);
178  int insertAction(const MenuItem&);
179 
180  uiMenu* addMenu(uiMenu*,const uiMenu* before = 0);
183  uiAction* insertSeparator();
184 
185  void removeAction(uiAction*);
186  void removeAction(int id);
187  void removeAllActions();
188  void reloadIcons();
189 
190 protected:
191  uiActionContainer();
192 
193  int getFreeID() const;
194 
195  virtual void doInsertSeparator(mQtclass(QAction)* before) = 0;
196  virtual void doInsertMenu(mQtclass(QMenu)*,
197  mQtclass(QAction)* before ) = 0;
198  virtual void doInsertAction(mQtclass(QAction)*,
199  mQtclass(QAction)* before ) = 0;
200  virtual void doClear() = 0;
201  virtual void doRemoveAction(mQtclass(QAction)*) = 0;
202 
205 
206 public:
207 
208  int insertItem(uiAction* a,int id=-1,
209  const uiAction* before = 0)
210  { return insertAction( a, id, before ); }
212  int insertItem(uiMenu* mnu);
214  void removeItem(uiAction* a) { removeAction(a); }
216  void removeItem(int id) { removeAction(id); }
218 };
219 
220 #endif
#define mExpClass(module)
Definition: commondefs.h:160
To be able to send and/or receive CallBacks, inherit from this class.
Definition: callback.h:272
const char * str() const
Definition: odstring.h:48
#define mQtclass(cls)
Definition: commondefs.h:229
TypeSet< int > ids_
Definition: uiaction.h:204
OD::String that holds an existing text string.
Definition: fixedstring.h:29
bool init()
void toggled(bool checked)
Definition: i_qaction.h:49
List encoded in a string.
Definition: separstr.h:33
Definition: uistring.h:89
Definition: callback.h:254
Definition: menuhandler.h:76
void triggered(bool checked)
Definition: i_qaction.h:55
uiActionSeparString(const char *str=0)
Definition: uiaction.h:147
Definition: uiaction.h:144
ObjectSet< uiAction > actions_
Definition: uiaction.h:203
#define mFDQtclass(cls)
Definition: commondefs.h:228
Definition: uimenu.h:65
Off-screen pixel-based paint device.
Definition: uipixmap.h:34
void removeItem(int id)
Legacy.
Definition: uiaction.h:216
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
void removeItem(uiAction *a)
Legacy.
Definition: uiaction.h:214
uiAction * findAction(const FixedString &fs)
Definition: uiaction.h:167
Helper class for uiAction to relay Qt&#39;s messages.
Definition: i_qaction.h:25
int insertItem(uiAction *a, int id=-1, const uiAction *before=0)
Legacy.
Definition: uiaction.h:208
bool isEmpty(const NLAModel *mdl)
CallBacks object-oriented (object + method).
Definition: callback.h:57
friend class uiAction
Definition: i_qaction.h:28
Definition: uiaction.h:152

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019