QCAD
Open Source 2D CAD
RGuiAction.h
Go to the documentation of this file.
1 
20 #ifndef RGUIACTION_H
21 #define RGUIACTION_H
22 
23 #include "core_global.h"
24 
25 #include <QFileInfo>
26 #include <QMap>
27 #include <QMetaType>
28 #include <QString>
29 #include <QStringList>
30 #include <QList>
31 #include <QAction>
32 
33 #include "RTransactionListener.h"
34 #include "RFocusListener.h"
35 #include "RSelectionListener.h"
36 
37 class QToolBar;
38 
39 class RDocument;
40 class RDocumentInterface;
41 
61  public QAction,
62  public RFocusListener,
63  public RTransactionListener,
64  public RSelectionListener {
65 
66 Q_OBJECT
67 
68 public:
69  typedef void (*FactoryFunction)(RGuiAction*);
70 
71 public:
72  RGuiAction(const QString& oriText, QObject* parent = 0);
73  virtual ~RGuiAction();
74 
75  void setText(const QString& oriText);
76 
81  virtual void initTexts();
82 
83  virtual void init();
84 
85  static QString formatToolTip(const QString& oriText, const QString& shortcut);
86  QString getToolTip(const QString& oriText, const QString& shortcut);
87 
88  void setDocumentInterface(RDocumentInterface* di);
90 
91 
97  void setShortcut(const QKeySequence& shortcut);
98  void setDefaultShortcut(const QKeySequence& shortcut);
99  void setShortcuts(const QList<QKeySequence>& shortcuts);
100  void setDefaultShortcuts(const QList<QKeySequence>& shortcuts);
101  QList<QKeySequence> getDefaultShortcuts();
102  void setShortcutText(const QString& oriText);
103  QString getShortcutText();
104 
105  static void setGroupSortOrderStatic(QAction* a, int sortOrder);
106  static void setGroupSortOrderOverrideStatic(QAction* a, const QString& widgetName, int sortOrder);
107  static int getGroupSortOrderStatic(const QAction* a, const QWidget* w = NULL);
108 
109  static void setSortOrderStatic(QAction* a, int sortOrder);
110  static void setSortOrderOverrideStatic(QAction* a, const QString& widgetName, int sortOrder);
111  static int getSortOrderStatic(const QAction* a, const QWidget* w = NULL);
112 
113  void setGroupSortOrder(int sortOrder);
114  void setGroupSortOrderOverride(const QString& widgetName, int sortOrder);
115  int getGroupSortOrder(const QWidget* w = NULL);
116 
117  void setSortOrder(int sortOrder);
118  void setSortOrderOverride(const QString& widgetName, int sortOrder);
119  int getSortOrder(const QWidget* w = NULL);
120 
121  void addToMenu(QMenu* menu);
122  void addToToolBar(QToolBar* tb);
123 
124  static void fixSeparators(const QWidget* w);
125  static void addSeparatorToWidget(QAction* a, QWidget* w);
126  static void addToWidget(QAction* a, QWidget* w);
127  static void removeFromWidget(QAction* a, QWidget* w);
128 
132  virtual void setIcon(const QString& iconFile);
133 
134  void disableIcon();
135  bool isIconDisabled();
136 
141  virtual void setToolTip(const QString& tip);
142 
147  virtual void setStatusTip(const QString& tip);
148 
152  virtual void setEnabled(bool on);
153 
157  virtual void setEnabledOverride(bool on, int override);
158 
162  virtual void setChecked(bool on);
163 
164  static void triggerGroupDefault(const QString& group);
165  static void triggerGroupDefaults();
166 
170  virtual bool isChecked();
171 
176  void setRequiresDocument(bool on) {
177  requiresDocument = on;
178  }
179 
185  return requiresDocument;
186  }
187 
192  void setRequiresSelection(bool on);
193 
199  return requiresSelection;
200  }
201 
203  requiresUndoableTransaction = on;
204  }
205 
207  return requiresUndoableTransaction;
208  }
209 
211  requiresRedoableTransaction = on;
212  }
213 
215  return requiresRedoableTransaction;
216  }
217 
218  void setOverride() {
219  override = true;
220  }
221 
222  bool isOverride() {
223  return override;
224  }
225 
226  void setNoState(bool checkable = false) {
227  noState = true;
228  setCheckable(checkable);
229  }
230 
231  bool hasNoState() {
232  return noState;
233  }
234 
235  void setUniqueGroup(const QString& ug) {
236  uniqueGroup = ug;
237  }
238 
239  QString getUniqueGroup() {
240  return uniqueGroup;
241  }
242 
248  QString getMainCommand() {
249  return mainCommand;
250  }
251 
255  QStringList getCommands() {
256  return commandList;
257  }
258 
259  QStringList getDefaultCommands() {
260  return defaultCommandList;
261  }
262 
263  void setDefaultCommands(const QStringList& cmds);
264  void setCommands(const QStringList& cmds);
265 
269  void setFactory(FactoryFunction f);
270 
275  void setScriptFile(const QString& sf, bool isSecondary = false);
276 
280  QString getScriptFile() const {
281  return scriptFile;
282  }
283 
284  QString getScriptClass() const {
285  return QFileInfo(scriptFile).baseName();
286  }
287 
288  virtual void setGroup(const QString& title);
289  QString getGroup();
290 
291  void setGroupDefault(bool on);
292  bool isGroupDefault();
293 
294 // void setSeparatorGroup(const QString& title);
295 // QString getSeparatorGroup();
296 
300  static QList<RGuiAction*> getActions() {
301  return actions;
302  }
303 
304  static bool triggerByCommand(const QString& cmd);
305  static RGuiAction* getByScriptFile(const QString& scriptFile);
306  static RGuiAction* getByClassName(const QString& className);
307  static bool triggerByScriptFile(const QString& scriptFile);
308 
309  static QStringList getAvailableCommands(bool primaryOnly=false);
310  static QStringList getAvailableCommands(const QString& start, bool primaryOnly=false);
311 
312  static void clear();
313 
314  virtual void updateTransactionListener(RDocument* document, RTransaction* transaction = NULL);
315  virtual void updateSelectionListener(RDocumentInterface* documentInterface);
316  virtual void updateFocus(RDocumentInterface* documentInterface);
317 
318  void addArgument(const QString& arg);
319  QStringList getArguments();
320  void clearArguments();
321 
322  static void setWidgetNamesStatic(QAction* a, const QStringList& widgetNames);
323  static QStringList getWidgetNamesStatic(const QAction *a);
324 
325  void setWidgetNames(const QStringList& widgetNames);
326  QStringList getWidgetNames() const;
327 
328 public slots:
332  bool slotTrigger(const QString& command = QString::null);
333 
334 signals:
335  void postTriggered();
336 
337 protected:
338  static QMap<QString, RGuiAction*> actionsByCommand;
339  static QMap<QString, RGuiAction*> actionsByPrimaryCommand;
340  static QMap<QString, RGuiAction*> actionsByScriptFile;
341  static QMultiMap<QString, RGuiAction*> actionsByGroup;
342  static QList<RGuiAction*> actions;
343 
344  FactoryFunction factory;
345  QString oriText;
346  QString scriptFile;
347  QString mainCommand;
348  QStringList commandList;
349  QStringList defaultCommandList;
350  QString group;
352 
357  bool override;
358  bool noState;
359  QString uniqueGroup;
360  QStringList arguments;
361 
362  QList<QKeySequence> defaultShortcuts;
363  QString shortcutText;
364  QString toolTip;
368 };
369 
372 
373 #endif
Abstract base class for classes that are interested in the current transaction stack.
Definition: RTransactionListener.h:38
void setUniqueGroup(const QString &ug)
Definition: RGuiAction.h:235
QString oriText
Definition: RGuiAction.h:345
RDocumentInterface * documentInterface
Definition: RGuiAction.h:367
bool isOverride()
Definition: RGuiAction.h:222
bool requiresDocument
Definition: RGuiAction.h:353
bool requiresSelection
Definition: RGuiAction.h:354
QString getScriptClass() const
Definition: RGuiAction.h:284
bool requiresUndoableTransaction
Definition: RGuiAction.h:355
#define QCADCORE_EXPORT
Definition: core_global.h:10
bool getRequiresSelection()
Definition: RGuiAction.h:198
QString shortcutText
Definition: RGuiAction.h:363
bool noState
Definition: RGuiAction.h:358
Transaction implementation.
Definition: RTransaction.h:70
static QMap< QString, RGuiAction * > actionsByCommand
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RGuiAction.h:338
bool requiresRedoableTransaction
Definition: RGuiAction.h:356
QString toolTip
Definition: RGuiAction.h:364
static QMap< QString, RGuiAction * > actionsByScriptFile
Definition: RGuiAction.h:340
bool getRequiresDocument()
Definition: RGuiAction.h:184
static QList< RGuiAction * > getActions()
Definition: RGuiAction.h:300
Abstract base class for classes that are interested in the current clipboard contents and want to be ...
Definition: RSelectionListener.h:36
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:63
QStringList arguments
Definition: RGuiAction.h:360
Q_DECLARE_METATYPE(RMath *)
QList< QKeySequence > defaultShortcuts
Definition: RGuiAction.h:362
void getDocumentInterface()
Definition: simple.js:21
QString group
Definition: RGuiAction.h:350
void setRequiresRedoableTransaction(bool on)
Definition: RGuiAction.h:210
QString getScriptFile() const
Definition: RGuiAction.h:280
int enabledOverride
Definition: RGuiAction.h:366
QStringList defaultCommandList
Definition: RGuiAction.h:349
void setOverride()
Definition: RGuiAction.h:218
static QMultiMap< QString, RGuiAction * > actionsByGroup
Definition: RGuiAction.h:341
virtual void updateFocus(RDocumentInterface *di)=0
Called by the document whenever the focus changed from one MDI to another.
bool hasNoState()
Definition: RGuiAction.h:231
bool iconDisabled
Definition: RGuiAction.h:365
QString uniqueGroup
Definition: RGuiAction.h:359
FactoryFunction factory
Definition: RGuiAction.h:344
static QList< RGuiAction * > actions
Definition: RGuiAction.h:342
Abstract base class for classes that are interested in the current focus.
Definition: RFocusListener.h:36
void setRequiresDocument(bool on)
If on is true, this action requires a document to be open.
Definition: RGuiAction.h:176
void setRequiresUndoableTransaction(bool on)
Definition: RGuiAction.h:202
bool getRequiresUndoableTransaction()
Definition: RGuiAction.h:206
bool groupDefault
Definition: RGuiAction.h:351
Abstract base class for GUI action classes.
Definition: RGuiAction.h:60
QStringList getCommands()
Definition: RGuiAction.h:255
QString mainCommand
Definition: RGuiAction.h:347
QString getMainCommand()
Definition: RGuiAction.h:248
Interface for interaction between a graphics document and a user.
Definition: RDocumentInterface.h:82
bool getRequiresRedoableTransaction()
Definition: RGuiAction.h:214
QStringList commandList
Definition: RGuiAction.h:348
void init(void basePath)
Definition: AddBlockInit.js:2
void setNoState(bool checkable=false)
Definition: RGuiAction.h:226
void getArguments(void args, void shortFlag, void longFlag)
Definition: arguments.js:23
virtual void updateSelectionListener(RDocumentInterface *documentInterface)=0
Called by the document whenever the current clipboard changes.
QString getUniqueGroup()
Definition: RGuiAction.h:239
static QMap< QString, RGuiAction * > actionsByPrimaryCommand
Definition: RGuiAction.h:339
QStringList getDefaultCommands()
Definition: RGuiAction.h:259
virtual void updateTransactionListener(RDocument *document, RTransaction *transaction=NULL)=0
Called by the document whenever the current transaction stack changes.
QString scriptFile
Definition: RGuiAction.h:346