casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PlotMSPlotter.qo.h
Go to the documentation of this file.
00001 //# PlotMSPlotter.qo.h: GUI for plotms.
00002 //# Copyright (C) 2008
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: $
00027 #ifndef PLOTMSPLOTTER_QO_H_
00028 #define PLOTMSPLOTTER_QO_H_
00029 
00030 #include <plotms/Gui/PlotMSPlotter.ui.h>
00031 
00032 #include <casaqt/QtUtilities/QtActionGroup.qo.h>
00033 #include <graphics/GenericPlotter/PlotFactory.h>
00034 #include <plotms/Actions/PlotMSAction.h>
00035 #include <plotms/Gui/PlotMSAnnotator.h>
00036 
00037 #include <QMainWindow>
00038 #include <QToolButton>
00039 
00040 #include <casa/namespace.h>
00041 
00042 namespace casa {
00043 
00044 //# Forward Declarations
00045 class QtProgressWidget;
00046 class PlotMSApp;
00047 class PlotMSAnnotatorTab;
00048 class PlotMSFlaggingTab;
00049 class PlotMSOptionsTab;
00050 class PlotMSPlotTab;
00051 class PlotMSThread;
00052 class PlotMSToolsTab;
00053 
00054 
00055 // High(ish)-level plotter class that manages the GUI (semi-) transparently to
00056 // the rest of PlotMS.
00057 class PlotMSPlotter : public QMainWindow, Ui::PlotterWindow,
00058                       public PlotDrawWatcher {
00059     Q_OBJECT
00060     
00061 public:
00062     // Static //
00063     
00064     // Returns "about" text for the given implementation, using HTML or not.
00065     static String aboutText(Plotter::Implementation implementation,
00066                             bool useHTML = true);
00067     
00068     
00069     // Non-Static //
00070     
00071     // Constructor that creates a plotter with the given parent using the given
00072     // implementation.
00073     PlotMSPlotter(PlotMSApp* parent,
00074                   Plotter::Implementation impl = Plotter::DEFAULT);
00075     
00076     // Destructor.
00077     ~PlotMSPlotter();
00078     
00079     
00080     // Accessor methods.
00081     // <group>
00082     PlotMSApp* getParent() { return itsParent_; }
00083     PlotFactoryPtr getFactory() { return itsFactory_; }
00084     PlotterPtr getPlotter() { return itsPlotter_; }
00085     QtProgressWidget* getProgressWidget() { return itsThreadProgress_; }
00086     PlotMSPlotTab* getPlotTab() { return itsPlotTab_; }
00087     PlotMSToolsTab* getToolsTab() { return itsToolsTab_; }
00088     PlotMSOptionsTab* getOptionsTab() { return itsOptionsTab_; }
00089     PlotMSFlaggingTab* getFlaggingTab() { return itsFlaggingTab_; }
00090     PlotMSAnnotator& getAnnotator() { return itsAnnotator_; }
00091     // </group>
00092 
00093     bool isDrawing() const;
00094     bool isClosed() const;
00095 
00096     // Execution Methods //
00097     
00098     // Shows/hides the GUI.
00099     void showGUI(bool show = true);
00100     
00101     // Returns true if the GUI is currently visible, false otherwise.
00102     bool guiShown() const;
00103     
00104     // Enters the plotter's execution loop, and returns its return value.
00105     // Only during this execution loops will GUI windows be shown and
00106     // GUI events be handled.  The execution loop ends when the user clicks
00107     // the "close" or "quit" buttons.  This method can be called multiple
00108     // times.
00109     int execLoop();
00110     
00111     // See showGUI() and execLoop().
00112     int showAndExec(bool show = true) {
00113         showGUI(show);
00114         return execLoop();
00115     }
00116     
00117     // Runs the given operation thread, keeping GUI and progress information
00118     // synchronized as necessary.  The given thread will be deleted upon
00119     // completion.
00120     void doThreadedOperation(PlotMSThread* thread);
00121     
00122     // Implements PlotDrawWatcher::canvasDrawBeginning().
00123     bool canvasDrawBeginning(PlotOperationPtr drawOperation,
00124                 bool drawingIsThreaded, int drawnLayersFlag);
00125     
00126     
00127     // GUI Methods //
00128     
00129     // Shows/Hides the "iteration" widgets and actions on the GUI.
00130     void showIterationButtons(bool show);
00131     
00132     // Pops up a dialog to ask the user the given question with the given
00133     // window title.  Returns true if the user says "Yes"; false for "No" or
00134     // otherwise rejecting the dialog.
00135     bool showQuestion(const String& message, const String& title);
00136     
00137     // Holds/Releases drawing on all visible plot canvases.
00138     // <group>
00139     void holdDrawing();
00140     void releaseDrawing();
00141     // </group>
00142     
00143     // Returns true if drawing is being held on ALL visible plot canvases,
00144     // false otherwise.
00145     bool allDrawingHeld() const;
00146 
00147     // Returns all currently shown canvases in the plotter.
00148     vector<PlotCanvasPtr> currentCanvases();
00149     
00150     
00151     // Plotter Customization Methods //
00152     
00153     // Sets the window title to the given.
00154     void setWindowTitle(const String& windowTitle);
00155     
00156     // Sets the status bar text to the given.
00157     void setStatusText(const String& statusText);
00158     
00159     // Clears the status bar text.
00160     void clearStatusText() { setStatusText(""); }
00161     
00162     // Overrides QMainWindow::setToolButtonStyle().
00163     void setToolButtonStyle(Qt::ToolButtonStyle style);
00164     
00165     
00166     // Action Methods //
00167     
00168     // Returns a map between PlotMSApp actions and the QActions associated with
00169     // them in the GUI.  Triggering the QActions will trigger the proper PlotMSApp
00170     // action, and the QAction will be kept properly checked as needed.
00171     const QMap<PlotMSAction::Type, QAction*>& plotActionMap() const;
00172     
00173     // Synchronizes the given button with the given action type.  (See
00174     // QtActionSynchronizer class.)
00175     void synchronizeAction(PlotMSAction::Type action, QAbstractButton* button);
00176     
00177     // Gets/Sets the text for the QAction associated with the given PlotMSApp
00178     // action.
00179     // <group>
00180     String actionText(PlotMSAction::Type type);
00181     void setActionText(PlotMSAction::Type type, const String& text);
00182     // </group>
00183     
00184     // Gets/Sets whether the QAction associated with the given PlotMSApp action
00185     // is checked.  Has no effect on actions that are not checkable.
00186     // <group>
00187     bool actionIsChecked(PlotMSAction::Type type) const;
00188     void setActionIsChecked(PlotMSAction::Type type, bool checked,
00189             bool alsoTriggerAction = false);
00190     // </group>
00191     
00192     // export a plot to a file
00193     bool exportPlot(const PlotExportFormat& format, const bool interactive, const bool async);
00194     
00195 public slots:
00196     // Shows the given error/warning message in a GUI window.
00197     void showError(const String& message, const String& title, bool isWarning);
00198     
00199     // Shows the given informational message in a GUI window.
00200     void showMessage(const String& message, const String& title);
00201     
00202     // Slot for showing an "about" dialog.
00203     void showAbout();
00204     
00205     // Take any clean-up actions before a Plot is made
00206     // 1) unclick any zoom, pan, etc buttons to avoid bug in zoom stack
00207     // 2) ... anything else needed in the future ...
00208     void prepareForPlotting();
00209     
00210     
00211 protected:
00212     // Overrides QWidget::closeEvent(), in case we're dealing with a plotter
00213     // that isn't Qt and thus is in its own window (and possibly its own
00214     // execution loop).
00215     void closeEvent(QCloseEvent* event);
00216     
00217 private:
00218     // PlotMSApp parent.
00219     PlotMSApp* itsParent_;
00220     
00221     // Flag for whether the underlying Plotter is Qt-based or not.
00222     bool isQt_;
00223 
00224     // Flag for whether the widget is open or not
00225     bool isClosed_;
00226     
00227     // Plot factory.
00228     PlotFactoryPtr itsFactory_;
00229     
00230     // Plotter.
00231     PlotterPtr itsPlotter_;
00232     
00233     // Widgets to be enabled/disabled during threading.
00234     QList<QWidget*> itsEnableWidgets_;
00235     
00236     // Plot tab.
00237     PlotMSPlotTab* itsPlotTab_;
00238     
00239     // Flagging tab (on the plot tab).
00240     PlotMSFlaggingTab* itsFlaggingTab_;
00241     
00242     // Tools tab.
00243     PlotMSToolsTab* itsToolsTab_;
00244     
00245     // Annotator tab.
00246     PlotMSAnnotatorTab* itsAnnotatorTab_;
00247     
00248     // Options tab.
00249     PlotMSOptionsTab* itsOptionsTab_;
00250     
00251     // Tool buttons on the tabs.
00252     QList<QToolButton*> itsToolButtons_;
00253     
00254     // Widget for displaying thread progress.
00255     QtProgressWidget* itsThreadProgress_;
00256     
00257     // Current thread (or NULL for none).
00258     PlotMSThread* itsCurrentThread_;
00259     
00260     // Waiting threads.
00261     vector<PlotMSThread*> itsWaitingThreads_;
00262     
00263     // Map between PlotMSApp actions and QActions.
00264     QMap<PlotMSAction::Type, QAction*> itsActionMap_;
00265     
00266     // Action synchronizer.
00267     QtActionSynchronizer itsActionSynchronizer_;
00268     
00269     // Annotator tool.
00270     PlotMSAnnotator itsAnnotator_;
00271     
00272     // "About" string.
00273     QString itsAboutString_;
00274     
00275     
00276     bool _triggerAction(PlotMSAction& action);
00277     
00278     // Initializes the plotter with the given implementation.  MUST be called
00279     // from constructors.
00280     void initialize(Plotter::Implementation impl);
00281     
00282 private slots:    
00283     // Method for when an action has been triggered.
00284     void action_() { action(dynamic_cast<QAction*>(sender())); }
00285     
00286     // Method for when the given action has been triggered.
00287     void action(QAction* which);
00288 
00289     // Slot for when the currently running thread is finished.  Performs
00290     // cleanup and starts next waiting thread if applicable.
00291     void currentThreadFinished();
00292 };
00293 typedef CountedPtr<PlotMSPlotter> PlotMSPlotterPtr;
00294 
00295 }
00296 
00297 #endif /* PLOTMSPLOTTER_QO_H_ */