casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlotMSPlotter.qo.h
Go to the documentation of this file.
1 //# PlotMSPlotter.qo.h: GUI for plotms.
2 //# Copyright (C) 2008
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef PLOTMSPLOTTER_QO_H_
28 #define PLOTMSPLOTTER_QO_H_
29 
30 #include <plotms/Gui/PlotMSPlotter.ui.h>
31 
36 #include <plotms/Client/Client.h>
38 
39 #include <QMainWindow>
40 #include <QToolButton>
41 #if defined(WITHOUT_DBUS)
42 #include <queue>
43 #include <mutex>
44 #include <functional>
45 #endif
46 
47 namespace casa {
48 
49 //# Forward Declarations
50 class QtProgressWidget;
51 class PlotMSApp;
52 class PlotMSAnnotatorTab;
53 class PlotMSFlaggingTab;
54 class PlotMSOptionsTab;
55 class PlotMSPlotTab;
56 class PlotMSExportTab;
57 class PlotMSThread;
58 class PlotMSToolsTab;
59 class PlotMSDataSummaryTab;
60 
61 
62 // High(ish)-level plotter class that manages the GUI (semi-) transparently to
63 // the rest of PlotMS.
64 class PlotMSPlotter : public QMainWindow, Ui::PlotterWindow,
65  public PlotDrawWatcher, public Client {
66  Q_OBJECT
67 
68 public:
69 
70  //Methods from the client interface
71  virtual bool isActionEnabled( PlotMSAction::Type type ) const;
72 
73  virtual std::vector<PlotMSPlot*> getCurrentPlots() const;
74  virtual bool plot();
75  virtual std::vector<std::vector<PMS::Axis> > getSelectedLoadAxes() const;
76  virtual std::vector<std::vector<PMS::Axis> > getSelectedReleaseAxes() const;
77  virtual PlotMSFlagging getFlagging() const;
78  virtual bool isInteractive() const;
79  virtual void canvasAdded( PlotCanvasPtr& canvas );
80  virtual void setAnnotationModeActive( PlotMSAction::Type type, bool active );
81  virtual std::vector<casacore::String> getFiles() const;
82 
83 
84  // Static //
85 
86  // Returns "about" text for the given implementation, using HTML or not.
88  bool useHTML = true);
89 
90 
91  // Non-Static //
92 
93  // Constructor that creates a plotter with the given parent using the given
94  // implementation.
95  PlotMSPlotter(PlotMSApp* parent,
97 
98  // Destructor.
100 
101 
102  // Accessor methods.
103  // <group>
105 
107 
109  // </group>
110 
111  virtual bool isDrawing() const;
112  virtual bool isClosed() const;
113 
114  // Execution Methods //
115  void setShowProgress( bool showProgressDialog);
116  // Shows/hides the GUI.
117  virtual void showGUI(bool show = true);
118 
119  // Returns true if the GUI is currently visible, false otherwise.
120  virtual bool guiShown() const;
121 
122  // Enters the plotter's execution loop, and returns its return value.
123  // Only during this execution loops will GUI windows be shown and
124  // GUI events be handled. The execution loop ends when the user clicks
125  // the "close" or "quit" buttons. This method can be called multiple
126  // times.
127  virtual int execLoop();
128 
129 
130 
131  // Runs the given operation thread, keeping GUI and progress information
132  // synchronized as necessary. The given thread will be deleted upon
133  // completion.
134  virtual void doThreadedOperation(/*PlotMSThread**/ThreadController* thread);
135 
136  // Implements PlotDrawWatcher::canvasDrawBeginning().
137  bool canvasDrawBeginning(PlotOperationPtr drawOperation,
138  bool drawingIsThreaded, int drawnLayersFlag);
140  PMSPTMethod postThreadMethod = NULL, PlotMSPlot* plot = NULL,
141  int index = -1 );
142 
143  // GUI Methods //
144 
145  // Shows/Hides the "iteration" widgets and actions on the GUI.
146  void showIterationButtons(bool show);
147 
148  // Pops up a dialog to ask the user the given question with the given
149  // window title. Returns true if the user says "Yes"; false for "No" or
150  // otherwise rejecting the dialog.
151  bool showQuestion(const casacore::String& message, const casacore::String& title);
152 
153 
154 
155 
156 
157  // Plotter Customization Methods //
158 
159  // Sets the window title to the given.
160  void setWindowTitle(const casacore::String& windowTitle);
161 
162  // Sets the status bar text to the given.
163  void setStatusText(const casacore::String& statusText);
164 
165  // Clears the status bar text.
167 
168  // Overrides QMainWindow::setToolButtonStyle().
169  void setToolButtonStyle(Qt::ToolButtonStyle style);
170 
171 
172  // Action Methods //
173 
174  // Returns a map between PlotMSApp actions and the QActions associated with
175  // them in the GUI. Triggering the QActions will trigger the proper PlotMSApp
176  // action, and the QAction will be kept properly checked as needed.
177  const QMap<PlotMSAction::Type, QAction*>& plotActionMap() const;
178 
179  // Synchronizes the given button with the given action type. (See
180  // QtActionSynchronizer class.)
181  void synchronizeAction(PlotMSAction::Type action, QAbstractButton* button);
182 
183  // Gets/Sets the text for the QAction associated with the given PlotMSApp
184  // action.
185  // <group>
187  void setActionText(PlotMSAction::Type type, const casacore::String& text);
188  // </group>
189 
190  // Gets/Sets whether the QAction associated with the given PlotMSApp action
191  // is checked. Has no effect on actions that are not checkable.
192  // <group>
193  bool actionIsChecked(PlotMSAction::Type type) const;
194  void setActionIsChecked(PlotMSAction::Type type, bool checked,
195  bool alsoTriggerAction = false);
196  // </group>
197 
198  // export a plot to a file
199  virtual bool exportPlot(const PlotExportFormat& format, const bool async);
200  virtual void setFlagging(PlotMSFlagging flag);
201  virtual void gridSizeChanged( int rowCount, int colCount );
202 
203 public slots:
204  // Shows the given error/warning message in a GUI window.
205  virtual void showError(const casacore::String& message, const casacore::String& title, bool isWarning);
206 
207  // Shows the given informational message in a GUI window.
208  virtual void showMessage(const casacore::String& message, const casacore::String& title, bool warning = false);
209 
210  // Clears the message in a GUI window.
211  virtual void clearMessage() { clearStatusText(); }
212 
213  // Slot for showing an "about" dialog.
214  void showAbout();
215 
216  // Take any clean-up actions before a Plot is made
217  // 1) unclick any zoom, pan, etc buttons to avoid bug in zoom stack
218  // 2) ... anything else needed in the future ...
219  void prepareForPlotting();
220 
221  virtual bool close();
222 
223 #if defined(WITHOUT_DBUS)
224  void grpc_handle_op( );
225  void grpc_exit_now( );
226 
227 public:
228  std::mutex grpc_queue_mutex;
229  std::queue<std::function<void()>> grpc_queue;
230 #endif
231 
232 protected:
233  // Overrides QWidget::closeEvent(), in case we're dealing with a plotter
234  // that isn't Qt and thus is in its own window (and possibly its own
235  // execution loop).
236  void closeEvent(QCloseEvent* event);
237 
238 
239 
240 private:
241  // PlotMSApp parent.
243 
244  // Flag for whether the underlying Plotter is Qt-based or not.
245  bool isQt_;
246 
247  // Flag for whether the widget is open or not
248  bool isClosed_;
249 
250 
251 
252 
253  // Widgets to be enabled/disabled during threading.
254  QList<QWidget*> itsEnableWidgets_;
255 
256  //Plot tab
258 
259  // Flagging tab (on the plot tab).
261 
262  // Tools tab.
264 
265  // Annotator tab.
267 
268  // Options tab.
270 
271  // Tool buttons on the tabs.
272  QList<QToolButton*> itsToolButtons_;
273 
274  // Widget for displaying thread progress.
276 
277  // Current thread (or NULL for none).
279 
280  // Waiting threads.
281  std::vector<PlotMSThread*> itsWaitingThreads_;
282 
283  // casacore::Map between PlotMSApp actions and QActions.
284  QMap<PlotMSAction::Type, QAction*> itsActionMap_;
285 
286  // Action synchronizer.
288 
289  // Annotator tool.
291 
292  // "About" string.
294 
296 
297  QTabWidget* tabWidget;
298 
299 
300  bool _triggerAction(/*PlotMSAction& action*/PlotMSAction::Type type);
301 
302  // Initializes the plotter with the given implementation. MUST be called
303  // from constructors.
305 
306 private slots:
307  // Method for when an action has been triggered.
308  void action_() { action(dynamic_cast<QAction*>(sender())); }
309 
310  // Method for when the given action has been triggered.
311  void action(QAction* which);
312 
313  // Slot for when the currently running thread is finished. Performs
314  // cleanup and starts next waiting thread if applicable.
315  void currentThreadFinished();
316 
317  //Summarize an MS
318  void summarize();
319 
320  //Export the current plots
321  void exportPlots();
322 
323  void tabChanged( );
324 };
326 
327 }
328 
329 #endif /* PLOTMSPLOTTER_QO_H_ */
casacore::CountedPtr< PlotMSPlotter > PlotMSPlotterPtr
void synchronizeAction(PlotMSAction::Type action, QAbstractButton *button)
Synchronizes the given button with the given action type.
void showAbout()
Slot for showing an &quot;about&quot; dialog.
QList< QWidget * > itsEnableWidgets_
Widgets to be enabled/disabled during threading.
bool canvasDrawBeginning(PlotOperationPtr drawOperation, bool drawingIsThreaded, int drawnLayersFlag)
Implements PlotDrawWatcher::canvasDrawBeginning().
virtual bool isInteractive() const
Return whether the client is interactive (a GUI) or noninteractive (a script)
virtual void setFlagging(PlotMSFlagging flag)
Flagging.
const QMap< PlotMSAction::Type, QAction * > & plotActionMap() const
Action Methods //.
virtual bool guiShown() const
Returns true if the GUI is currently visible, false otherwise.
Subclass of PlotMouseTool for drawing/managing annotations on the plot canvases of PlotMSApp...
virtual std::vector< PlotMSPlot * > getCurrentPlots() const
Return the current client plot.
virtual Type type()
Return the type enum.
void closeEvent(QCloseEvent *event)
Overrides QWidget::closeEvent(), in case we&#39;re dealing with a plotter that isn&#39;t Qt and thus is in it...
bool _triggerAction(PlotMSAction::Type type)
void setShowProgress(bool showProgressDialog)
Execution Methods //.
bool actionIsChecked(PlotMSAction::Type type) const
Gets/Sets whether the QAction associated with the given PlotMSApp action is checked.
PlotMSAnnotator itsAnnotator_
Annotator tool.
virtual PlotMSFlagging getFlagging() const
Retrieve flagging information specified by the client.
QtActionSynchronizer itsActionSynchronizer_
Action synchronizer.
Subclass of PlotMSTab that handles flagging.
PlotMSApp * getParent()
Accessor methods.
PlotMSAnnotatorTab * itsAnnotatorTab_
Annotator tab.
bool showQuestion(const casacore::String &message, const casacore::String &title)
Pops up a dialog to ask the user the given question with the given window title.
void show(const variant &v)
Subclass of PlotMSTab that handles interaction with the PlotMSAnnotator.
static casacore::String aboutText(Plotter::Implementation implementation, bool useHTML=true)
Static //.
std::vector< PlotMSThread * > itsWaitingThreads_
Waiting threads.
void setToolButtonStyle(Qt::ToolButtonStyle style)
Overrides QMainWindow::setToolButtonStyle().
bool isQt_
Flag for whether the underlying Plotter is Qt-based or not.
Controller class for plotms.
Definition: PlotMS.h:55
~PlotMSPlotter()
Destructor.
PlotMSToolsTab * itsToolsTab_
Tools tab.
void showIterationButtons(bool show)
GUI Methods //.
virtual std::vector< std::vector< PMS::Axis > > getSelectedLoadAxes() const
Retrieve the plot load axes the user has specified.
virtual void showMessage(const casacore::String &message, const casacore::String &title, bool warning=false)
Shows the given informational message in a GUI window.
virtual bool exportPlot(const PlotExportFormat &format, const bool async)
export a plot to a file
Specifies flagging parameters (including possibly flag extension) for an MS.
virtual void showError(const casacore::String &message, const casacore::String &title, bool isWarning)
Shows the given error/warning message in a GUI window.
Type
Static // Enum for implemented actions.
Definition: PlotMSAction.h:51
PlotMSOptionsTab * itsOptionsTab_
Options tab.
Implementation
Static //.
Definition: Plotter.h:48
void setStatusText(const casacore::String &statusText)
Sets the status bar text to the given.
void setActionText(PlotMSAction::Type type, const casacore::String &text)
void currentThreadFinished()
Slot for when the currently running thread is finished.
Class for a single &quot;plot&quot; concept.
Definition: PlotMSPlot.h:57
Subclass of PlotMSTab that handles options for PlotMSPlotter.
PlotMSPlotter(PlotMSApp *parent, Plotter::Implementation impl=Plotter::DEFAULT)
Non-Static //.
void setWindowTitle(const casacore::String &windowTitle)
Plotter Customization Methods //.
PlotMSThread * itsCurrentThread_
Current thread (or NULL for none).
virtual void clearMessage()
Clears the message in a GUI window.
Subclass of PlotMSTab that handles the tools for the current plot.
virtual void canvasAdded(PlotCanvasPtr &canvas)
Add a plot to those displayed.
virtual bool close()
PlotExportFormat contains parameters for exporting a canvas to a file.
Definition: PlotOptions.h:817
Abstraction for the interface between the client (possibly a GUI) and the model (plot engine) that is...
Definition: Client.h:45
virtual std::vector< std::vector< PMS::Axis > > getSelectedReleaseAxes() const
Retrieve the release axes the user has specified.
void action_()
Method for when an action has been triggered.
casacore::String actionText(PlotMSAction::Type type)
Gets/Sets the text for the QAction associated with the given PlotMSApp action.
virtual void setAnnotationModeActive(PlotMSAction::Type type, bool active)
Use to enable annotations in the GUI client.
virtual int execLoop()
Enters the plotter&#39;s execution loop, and returns its return value.
void initialize(Plotter::Implementation impl)
Initializes the plotter with the given implementation.
bool isClosed_
Flag for whether the widget is open or not.
virtual void showGUI(bool show=true)
Shows/hides the GUI.
PlotMSDataSummaryTab * itsPlotTab_
Plot tab.
virtual ThreadController * getThreadController(PlotMSAction::Type type, PMSPTMethod postThreadMethod=NULL, PlotMSPlot *plot=NULL, int index=-1)
FactoryMethod for producing a thread controller to manage a specific type of threaded operation...
void setActionIsChecked(PlotMSAction::Type type, bool checked, bool alsoTriggerAction=false)
Handles adding multiple plots to the GUI.
Abstract class to control a threaded operation from the GUI.
void PMSPTMethod(PMSPTObject, bool)
PlotMSAnnotator & getAnnotator()
PlotMSFlaggingTab * itsFlaggingTab_
Flagging tab (on the plot tab).
Abstract parent for any class that wants to be notified when the canvas is about to start drawing...
Definition: PlotCanvas.h:53
void prepareForPlotting()
Take any clean-up actions before a Plot is made 1) unclick any zoom, pan, etc buttons to avoid bug in...
String: the storage and methods of handling collections of characters.
Definition: String.h:223
QList< QToolButton * > itsToolButtons_
Tool buttons on the tabs.
virtual void doThreadedOperation(ThreadController *thread)
Runs the given operation thread, keeping GUI and progress information synchronized as necessary...
GUI for displaying progress information.
Default plotter implementation is set here.
Definition: Plotter.h:52
High(ish)-level plotter class that manages the GUI (semi-) transparently to the rest of PlotMS...
void exportPlots()
Export the current plots.
PlotMSApp * itsParent_
PlotMSApp parent.
QtProgressWidget * itsThreadProgress_
Widget for displaying thread progress.
virtual bool plot()
virtual bool isActionEnabled(PlotMSAction::Type type) const
Methods from the client interface.
virtual bool isDrawing() const
QMap< PlotMSAction::Type, QAction * > itsActionMap_
casacore::Map between PlotMSApp actions and QActions.
QtProgressWidget * getProgressWidget()
QString itsAboutString_
&quot;About&quot; string.
virtual void gridSizeChanged(int rowCount, int colCount)
This class is used to synchronize the checked state of actions with checkable buttons or other action...
void clearStatusText()
Clears the status bar text.
void summarize()
Summarize an MS.
virtual std::vector< casacore::String > getFiles() const
Return a list of files loaded in the client.
void action(QAction *which)
Method for when the given action has been triggered.
virtual bool isClosed() const