casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QPPlotter.qo.h
Go to the documentation of this file.
1 //# QPPlotter.qo.h: Qwt implementation of generic Plotter class.
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 QPPLOTTER_QO_H_
28 #define QPPLOTTER_QO_H_
29 
30 #ifdef AIPS_HAS_QWT
31 
33 #include <casaqt/QwtPlotter/QPPlotter.ui.h>
34 
38 
39 
40 #include <QtGui>
41 
42 namespace casa {
43 
44 //# Forward Declarations
45 class QPExportCanvas;
46 class QPCanvas;
47 class QPAxis;
48 class PlotFactory;
49 
50 // Implementation of Plotter for Qwt plotter. A QWidget that can be used as a
51 // main window.
52 class QPPlotter : public QWidget, Ui::PlotterUI, public Plotter {
53  Q_OBJECT
54 
55  friend class QPCanvas;
56  friend class QPAxis;
57 
58 public:
59  // Static //
60 
61  // Provides access to a global list of Qt colors.
62  static QStringList GLOBAL_COLORS;
63 
64  // Convenient access to class name (QPPlotter).
65  static const casacore::String CLASS_NAME;
66 
67 
68  // Non-Static //
69 
70  // Constructor that creates a plotter with a single canvas (or none for
71  // NULL). Uses the given log event flags (see PlotLogger::Event) if given,
72  // and the parent QWidget if given.
73  QPPlotter(QPCanvas* canvas = NULL,
74  int logEventFlags = PlotLogger::NO_EVENTS,
75  QWidget* parent = NULL);
76 
77  // Constructor that creates a plotter with the given layout (or none for
78  // null). Uses the given log event flags (see PlotLogger::Event) if given,
79  // and the parent QWidget if given.
80  QPPlotter(PlotCanvasLayoutPtr layout,
81  int logEventFlags = PlotLogger::NO_EVENTS,
82  QWidget* parent = NULL);
83 
84  // Destructor.
85  ~QPPlotter();
86 
87 
88 
89  // Plotter Methods //
90 
91  // Implements Plotter::showGUI().
92  void showGUI(bool showGUI = true);
93  bool isGuiShown() const;
94 
95  //Kludge for updating the plot when we are in Non-GUI mode.
96  void updateScriptGui();
97 
98  // Implements Plotter::size().
99  std::pair<int, int> size() const;
100 
101  // Implements Plotter::setSize().
102  void setSize(int width, int height);
103 
104  // Implements Plotter::windowTitle().
105  casacore::String windowTitle() const;
106 
107  // Implements Plotter::setWindowTitle().
108  void setWindowTitle(const casacore::String& newTitle);
109 
110  // Implements Plotter::canvasAreaSize().
111  std::pair<int, int> canvasAreaSize() const;
112 
113  // Implements Plotter::setCanvasSize().
114  void setCanvasSize(int width, int height, bool resizeWindow = true);
115 
116  // Implements Plotter::displayDPI().
117  int displayDPI() const;
118 
119  // Implements Plotter::isQWidget().
120  bool isQWidget() const { return true; }
121 
122  // Implements Plotter::cursor().
123  PlotCursor cursor() const;
124 
125  // Implements Plotter::setCursor().
126  void setCursor(PlotCursor cursor);
127 
128  // Implements Plotter::refresh().
129  void refresh();
130 
131  // Implements Plotter::close().
132  void close();
133 
134  std::vector<QPExportCanvas*> getGridComponents();
135 
136  // Implements Plotter::canvasLayout().
137  PlotCanvasLayoutPtr canvasLayout();
138 
139  // Implements Plotter::setCanvasLayout().
140  void setCanvasLayout(PlotCanvasLayoutPtr layout);
141 
142  // Implements Plotter::canvasLayoutChanged().
143  void canvasLayoutChanged(PlotCanvasLayout& layout);
144 
145  // Implements Plotter::dateFormat().
146  const casacore::String& dateFormat() const;
147 
148  // Implements Plotter::setDateFormat().
149  void setDateFormat(const casacore::String& dateFormat);
150 
151  // Implements Plotter::relativeDateFormat().
152  const casacore::String& relativeDateFormat() const;
153 
154  // Implements Plotter::setRelativeDateFormat().
155  void setRelativeDateFormat(const casacore::String& dateFormat);
156 
157 
158  // Implements Plotter::defaultPanelShown().
159  bool defaultPanelShown(DefaultPanel panel);
160 
161  // Implements Plotter::showDefaultPanel().
162  void showDefaultPanel(DefaultPanel panel, bool show = true);
163 
164  // Implements Plotter::addPanel().
165  int addPanel(PlotPanelPtr panel);
166 
167  // Implements Plotter::allPanels().
168  std::vector<PlotPanelPtr> allPanels();
169 
170  // Implements Plotter::numPanels().
171  unsigned int numPanels();
172 
173  // Implements Plotter::getPanel().
174  PlotPanelPtr getPanel(int index);
175 
176  // Implements Plotter::panelIndex().
177  int panelIndex(PlotPanelPtr panel);
178 
179  // Implements Plotter::clearPanels().
180  void clearPanels();
181 
182  // Implements Plotter::removePanel().
183  void removePanel(PlotPanelPtr annotation);
184 
185  // Implements Plotter::removePanel().
186  void removePanel(int id);
187 
188  // Implements Plotter::removeLastPanel().
189  void removeLastPanel();
190 
191 
192  // Implements Plotter::implementation().
193  Implementation implementation() const { return QWT; }
194 
195  // Implements Plotter::implementationFactory().
196  PlotFactory* implementationFactory() const;
197 
198  // Implements Plotter::exportToFile().
199  bool exportToFile(const PlotExportFormat& format);
200 
201  // Implements Plotter::fileChooserDialog().
202  casacore::String fileChooserDialog(const casacore::String& title = "File Chooser",
203  const casacore::String& directory = "");
204 
205 
206  // Implements Plotter::registerResizeHandler().
207  void registerResizeHandler(PlotResizeEventHandlerPtr handler);
208 
209  // Implements Plotter::allResizeHandlers().
210  std::vector<PlotResizeEventHandlerPtr> allResizeHandlers() const;
211 
212  // Implements Plotter::unregisterResizeHandlers().
213  void unregisterResizeHandler(PlotResizeEventHandlerPtr handler);
214 
215 
216  // Returns the frame used to hold the canvases.
217  // <group>
218  const QWidget* canvasWidget() const;
219  QWidget* canvasWidget();
220  // </group>
221  // Returns the frame used to hold the page header.
222  const QWidget* pageHeaderWidget() const;
223  QWidget* pageHeaderWidget();
224 
225  QPHeaderTable* pageHeaderTable();
226 
227  // Overrides QWidget::sizeHint() to return an invalid size.
228  QSize sizeHint() const;
229 
230  // Overrides QWidget::minimumSizeHint() to return an invalid size.
231  QSize minimumSizeHint() const;
232 
233  // Implements Plotter::makeSquarePlot to set width=height
234  virtual void makeSquarePlot(bool square, bool waveplot=false);
235  inline int plotWidth() { return m_plotWidth; }
236  inline int plotHeight() { return m_plotHeight; }
237 
238  virtual bool exportPlot(const PlotExportFormat& format );
239 
240  //Return the number of rows and columns in the current grid.
241  int getRowCount();
242  int getColCount();
243 
244  // Implements Plotter::refreshPageHeaderDataModel(PageHeaderDataModelPtr dataModel)
245  void refreshPageHeaderDataModel(PageHeaderDataModelPtr dataModel);
246  void setHeaderTableDataModel(QAbstractItemModel *model);
247  void refreshPageHeader();
248 
249 protected:
250  // For catching resize events.
251  void resizeEvent(QResizeEvent* event);
252 
253  // Logs the given object creation/destruction event, if needed.
254  void logObject(const casacore::String& className, void* address, bool creation,
255  const casacore::String& message = casacore::String());
256 
257  // Logs the given method enter/exit event, if needed.
258  void logMethod(const casacore::String& className, const casacore::String& methodName,
259  bool entering, const casacore::String& message = casacore::String());
260 
261 private:
262  // Page Header Table
263  QPHeaderTable *headerTable;
264  QAbstractItemModel *newHeaderTableDataModel;
265 
266  // Canvas layout.
267  PlotCanvasLayoutPtr m_layout;
268 
269  // Standard tools for canvases.
270  std::vector<PlotStandardMouseToolGroupPtr> m_canvasTools;
271 
272  // Registered handlers.
273  std::vector<PlotResizeEventHandlerPtr> m_resizeHandlers;
274 
275  // Panels.
276  std::vector<PlotPanelPtr> m_panels;
277 
278  // Flag for whether a resize event should be emitted.
279  bool m_emitResize;
280  bool m_guiShown;
281 
282  // Date formats.
283  // <group>
284  casacore::String m_dateFormat;
285  casacore::String m_relativeDateFormat;
286  // </group>
287 
288  QList<QPAxis*> externalAxes;
289 
290  // Sets up the canvas QFrame for the current layout.
291  void setupCanvasFrame();
292 
293  // Initializes GUI (to be called from constructors).
294  void initialize();
295 
296  void clearExternalAxes();
297  void emptyLayout();
298 
299  // for exports
300  int m_plotWidth;
301  int m_plotHeight;
302 
303  // Static //
304 
305  // Used to initialize GLOBAL_COLORS.
306  // <group>
307  static bool __initColors;
308  static bool initColors();
309  // </group>
310 
311  //Returns true if the given axis is drawn by the Qwt plot; false if
312  //the drawing is external and custom.
313  // <group>
314  bool isLeftAxisInternal() const;
315  bool isBottomAxisInternal() const;
316  bool isRightAxisInternal() const;
317  bool isTopAxisInternal() const;
318  // </group>
319 
320  //Reset the size hints of the canvases this plotter holds based on its current size.
321  void resetCanvasMinSizeHints();
322 private slots:
323  // Default panel: hand tool changed.
324  void handToolChanged(bool on);
325 
326  // Default panel: tracker toggled.
327  void trackerTurned(bool on);
328 
329  // Default panel: legend toggled.
330  void legendTurned(bool on);
331 
332  // Default panel: legend position changed.
333  void legendPositionChanged() { legendTurned(legendBox->isChecked()); }
334 
335  // Default panel: export button pushed.
336  void exportCanvases();
337 };
338 
339 }
340 
341 #endif
342 
343 #endif /*QPPLOTTER_QO_H_*/
static const int NO_EVENTS
No events.
Definition: PlotLogger.h:361
SMART POINTER DEFINITIONS *typedef casacore::CountedPtr< PlotCanvasLayout > PlotCanvasLayoutPtr
size_t size() const
void show(const variant &v)
SMART POINTER DEFINITIONS *typedef casacore::CountedPtr< PlotPanel > PlotPanelPtr
Definition: PlotPanel.h:188
PlotCursor
Enum for cursors.
Definition: PlotOptions.h:94
casacore::CountedPtr< PlotResizeEventHandler > PlotResizeEventHandlerPtr
TableExprNode square(const TableExprNode &node)
Definition: ExprNode.h:1303
String: the storage and methods of handling collections of characters.
Definition: String.h:223
GRID LAYOUT CLASSES casacore::Coordinate for a grid layout
casacore::CountedPtr< PageHeaderDataModel > PageHeaderDataModelPtr