pqPythonMacroSupervisor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: pqPythonMacroSupervisor.h
5 
6  Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
7  All rights reserved.
8 
9  ParaView is a free software; you can redistribute it and/or modify it
10  under the terms of the ParaView license version 1.2.
11 
12  See License_v1.2.txt for the full ParaView license.
13  A copy of this license can be obtained by contacting
14  Kitware Inc.
15  28 Corporate Drive
16  Clifton Park, NY 12065
17  USA
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 =========================================================================*/
32 #ifndef _pqPythonMacroSupervisor_h
33 #define _pqPythonMacroSupervisor_h
34 
35 #include "pqPythonModule.h"
36 #include <QList>
37 #include <QMap>
38 #include <QObject>
39 #include <QPointer>
40 #include <QString>
41 
42 class QAction;
43 
45 {
46  Q_OBJECT
47 public:
48  pqPythonMacroSupervisor(QObject* p = 0);
49  ~pqPythonMacroSupervisor() override;
50 
51  // Description:
52  // Add a widget to be given macro actions. QActions representing script macros
53  // will be added to the widget. This could be a QToolBar, QMenu, or other type
54  // of widget.
55  void addWidgetForRunMacros(QWidget* widget);
56 
57  // Description:
58  // Add a widget to be given macro actions. QActions representing script macros
59  // will be added to the widget. This could be a QToolBar, QMenu, or other type
60  // of widget.
61  void addWidgetForEditMacros(QWidget* widget);
62 
63  // Description:
64  // Add a widget to be given macro actions. QActions representing script macros
65  // will be added to the widget. This could be a QToolBar, QMenu, or other type
66  // of widget.
67  void addWidgetForDeleteMacros(QWidget* widget);
68 
69  // Description:
70  // Lookup and return a macro action by filename.
71  // If it does not exist, return null.
72  QAction* getMacro(const QString& fileName);
73 
74  // Description:
75  // Looks in pqSettings to get the stored macros. In the returned map,
76  // the keys are filenames and values are macro names.
77  static QMap<QString, QString> getStoredMacros();
78 
79  // Description:
80  // Removes a macro with the given filename from pqSettings, if it exists.
81  static void removeStoredMacro(const QString& filename);
82 
83  // Description:
84  // Get a macro name from the fileName
85  static QString macroNameFromFileName(const QString& filename);
86 
87  static QStringList getMacrosFilePaths();
88 
89 Q_SIGNALS:
90 
91  // Description:
92  // Emitted when a macro has been triggered.
93  void executeScriptRequested(const QString& filename);
94 
95  // Description:
96  // Emitted when a macro has to be edited
97  void onEditMacro(const QString& filename);
98 
99 public Q_SLOTS:
100 
101  // Description:
102  // Add an action with the given name and filename. If there is already
103  // a macro with the given filename it's macroname will be updated to the
104  // one given. Macro names do not have to be unique. Note, this does not
105  // store the macro in pqSettings, you must still call storeMacro yourself.
106  void addMacro(const QString& macroName, const QString& filename);
107  void addMacro(const QString& filename);
108 
109  // Description:
110  // Remove an action with the given filename. Note, this does not remove
111  // the macro from pqSettings, you must call removeStoredMacro yourself.
112  void removeMacro(const QString& filename);
113 
114  // Description:
115  // Update Macro list widgets and actions...
116  void updateMacroList();
117 
118 protected Q_SLOTS:
119 
120  // Description:
121  // If the sender is a QAction managed by this class, the filename will be
122  // looked up and the signal requestExecuteScript will be emitted.
123  void onMacroTriggered();
124 
125  // Description:
126  // If the sender is a QAction managed by this class, the filename will be
127  // moved (deleted), and the macro will be removed
128  void onDeleteMacroTriggered();
129 
130  // Description:
131  // If the sender is a QAction managed by this class, the macro file will be
132  // open in a python edit
133  void onEditMacroTriggered();
134 
135 protected:
136  // Description:
137  // Add a widget to be given macro actions. QActions representing script macros
138  // will be added to the widget. This could be a QToolBar, QMenu, or other type
139  // of widget.
140  void addWidgetForMacros(QWidget* widget, int actionType); // 0:run, 1:edit, 2:delete
141 
142  // Description:
143  // Removes all actions and re-adds actions for each macro stored.
144  void resetActions();
145 
146 private:
147  class pqInternal;
148  pqInternal* Internal;
149 };
150 
151 #endif // ifndef _pqPythonMacroSupervisor_h
#define PQPYTHON_EXPORT