casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QPAxis.qo.h
Go to the documentation of this file.
1 //# QPAxis.qo.h: Qwt implementation of generic PlotCanvas 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 QPAXIS_QO_H_
28 #define QPAXIS_QO_H_
29 
30 #ifdef AIPS_HAS_QWT
31 
41 
42 #include <qwt_plot_picker.h>
43 
44 #include <QtGui>
45 
46 #include <vector>
47 
48 namespace casa {
49 
50 //# Forward declarations
51 class QPPlotter;
52 class ExternalAxisWidget;
53 
54 // Implementation of PlotCanvas for the Qwt plotter. Mainly consists of
55 // wrappers and containers around a QwtPlot object.
56 class QPAxis : public QFrame, public QPExportCanvas, public AxisListener {
57  Q_OBJECT
58 
59  friend class QPAxesCache;
60  friend class QPDrawThread;
61  friend class QPLayeredCanvas;
62  friend class QPPlotItem;
63  friend class QPPlotter;
64 
65 public:
66  // Static //
67 
68  // Keep a z-order variable to increment for subsequent items.
69  static double zOrder;
70 
71  // Convenient access to class name (QPCanvas).
72  static const casacore::String CLASS_NAME;
73 
74  // Convenient access to "origin" names for logging.
75  // <group>
76  static const casacore::String DRAW_NAME;
77 
78  // </group>
79 
80 
81 
82 
83  // Non-Static //
84 
85  // Constructor which takes (optional) parent QPPlotter.
86  QPAxis(PlotAxis axis, QPPlotter* parent, QwtPlot* associatedPlot,
87  bool leftAxisInternal, bool bottomAxisInternal,
88  bool rightAxisInternal );
89 
90  // Destructor.
91  virtual ~QPAxis();
92 
93 
94 
95  // Implements PlotCanvas::legendShown().
96  bool legendShown() const{return false;};
97 
98  // Implements PlotCanvas::showLegend().
99  void showLegend(bool /*on = true*/, LegendPosition /*position = EXT_BOTTOM*/){}
100 
101  // Implements PlotCanvas::legendPosition().
102  LegendPosition legendPosition() const {
103  return PlotCanvas::INT_URIGHT;
104  }
105 
106  // Implements PlotCanvas::setLegendPosition().
107  void setLegendPosition(LegendPosition /*position*/){}
108 
109  // Implements PlotCanvas::legendLine().
110  PlotLinePtr legendLine() const {
111  return PlotLinePtr();
112  }
113 
114  virtual void setMinimumSizeHint( int width, int height );
115 
116  // Implements PlotCanvas::setLegendLine().
117  void setLegendLine(const PlotLine& /*line*/){}
118 
119  // Implements PlotCanvas::legendFill().
120  PlotAreaFillPtr legendFill() const {
121  return PlotAreaFillPtr();
122  }
123 
124  // Implements PlotCanvas::setLegendFill().
125  void setLegendFill(const PlotAreaFill& /*area*/){}
126 
127  // Implements PlotCanvas::legendFont().
128  PlotFontPtr legendFont() const {
129  return PlotFontPtr();
130  }
131 
132  // Implements PlotCanvas::setLegendFont().
133  void setLegendFont(const PlotFont& /*font*/){}
134 
135  // PlotCanvas Methods //
136  virtual void setCommonAxes( bool /*commonX*/, bool /*commonY*/ ){}
137 
138  // Implements PlotCanvas::size().
139  std::pair<int, int> size() const;
140  virtual void setMinimumSize( int width, int height ){
141  QFrame::setMinimumSize( width, height );
142  }
143 
144  bool isDrawing( );
145 
146  virtual void show(){
147  QFrame::show();
148  }
149 
150  virtual void hide(){
151  QFrame::show();
152  }
153 
154  // Implements PlotCanvas::title().
155  casacore::String title() const;
156 
157  // Implements PlotCanvas::setTitle().
158  void setTitle(const casacore::String& title);
159 
160  // Implements PlotCanvas::titleFont().
161  PlotFontPtr titleFont() const;
162 
163  // Implements PlotCanvas::setTitleFont().
164  void setTitleFont(const PlotFont& font);
165 
166  // Implements PlotCanvas::background().
167  PlotAreaFillPtr background() const;
168 
169  // Implements PlotCanvas::setBackground().
170  void setBackground(const PlotAreaFill& areaFill);
171 
172  // Implements PlotCanvas::cursor().
173  PlotCursor cursor() const;
174 
175  // Implements PlotCanvas::setCursor().
176  void setCursor(PlotCursor cursor);
177 
178  // Implements PlotCanvas::refresh().
179  // <group>
180  void refresh();
181  void refresh(int drawLayersFlag);
182  // </group>
183 
184  // Implements PlotCanvas::isQWidget().
185  bool isQWidget() const { return true; }
186 
187 
188  // Implements PlotCanvas::shownAxes().
189  // Returns a bit set (really an int) of bits defined by PlotAxis enum or'd together
190  PlotAxisBitset shownAxes() const;
191 
192  // Implements PlotCanvas::showAxes().
193  // Takes a bit set, as an int, of bits defined by PlotAxis enum or'd together
194  void showAxes(PlotAxisBitset axes);
195 
196  // Implements PlotCanvas::axisScale().
197  PlotAxisScale axisScale(PlotAxis axis) const;
198 
199  // Implements PlotCanvas::setAxisScale().
200  void setAxisScale(PlotAxis axis, PlotAxisScale scale, casacore::uInt base=10);
201 
202  // Implements PlotCanvas::setAxisScaleSortDirection().
203  bool setAxisScaleSortDirection(PlotAxis axis, SortDirection direction);
204  std::pair<bool,SortDirection> axisScaleSortDirection(PlotAxis axis) const;
205 
206  void setAxisScaleAngleFormat(PlotAxis axis, AngleFormat format);
207  AngleFormat axisScaleAngleFormat(PlotAxis axis) const;
208 
209  // Implements PlotCanvas::axisReferenceValueSet().
210  bool axisReferenceValueSet(PlotAxis axis) const;
211 
212  // Implements PlotCanvas::axisReferenceValueValue().
213  double axisReferenceValue(PlotAxis axis) const;
214 
215  // Implements PlotCanvas::setAxisReferenceValue().
216  void setAxisReferenceValue(PlotAxis axis, bool on, double value = 0);
217 
218  // Implements PlotCanvas::cartesianAxisShown().
219  bool cartesianAxisShown(PlotAxis axis) const;
220 
221  // Implements PlotCanvas::showCartesianAxis().
222  void showCartesianAxis(PlotAxis mirrorAxis, PlotAxis secondaryAxis,
223  bool show = true, bool hideNormalAxis = true);
224 
225  // Implements PlotCanvas::axisLabel().
226  casacore::String axisLabel(PlotAxis axis) const;
227 
228  // Implements PlotCanvas::setAxisLabel().
229  void setAxisLabel(PlotAxis axis, const casacore::String& title);
230 
231  // Implements PlotCanvas::axisFont().
232  PlotFontPtr axisFont(PlotAxis axis) const;
233 
234  // Implements PlotCanvas::setAxisFont().
235  void setAxisFont(PlotAxis axis, const PlotFont& font);
236 
237  // Implements PlotCanvas::colorBarShown().
238  bool colorBarShown(PlotAxis axis = Y_RIGHT) const;
239 
240  // Implements PlotCanvas::showColorBar().
241  void showColorBar(bool show = true, PlotAxis axis = Y_RIGHT);
242 
243 
244  // Implements PlotCanvas::axisRange().
245  prange_t axisRange(PlotAxis axis) const;
246 
247  // Implements PlotCanvas::setAxisRange().
248  void setAxisRange(PlotAxis axis, double from, double to);
249 
250  // Implements PlotCanvas::invertAxis().
251  void invertAxis(PlotAxis axis);
252 
253  // Overrides PlotCanvas::setAxesRanges().
254  void setAxesRanges(PlotAxis xAxis, double xFrom, double xTo,
255  PlotAxis yAxis, double yFrom, double yTo);
256 
257  // Implements PlotCanvas::axesAutoRescale().
258  bool axesAutoRescale() const;
259 
260  // Implements PlotCanvas::setAxesAutoRescale().
261  void setAxesAutoRescale(bool autoRescale = true);
262 
263  // Implements PlotCanvas::rescaleAxes().
264  void rescaleAxes();
265 
266  // Implements PlotCanvas::axesRatioLocked().
267  bool axesRatioLocked() const;
268 
269  // Implements PlotCanvas::setAxesRatioLocked().
270  void setAxesRatioLocked(bool locked = true);
271 
272 
273  // Implements PlotCanvas::cachedAxesStackSizeLimit().
274  int cachedAxesStackSizeLimit() const;
275 
276  // Implements PlotCanvas::setCachedAxesStackSizeLimit().
277  void setCachedAxesStackSizeLimit(int sizeInKilobytes);
278 
279  // Overrides PlotCanvas::cachedAxesStackImageSize().
280  std::pair<int, int> cachedAxesStackImageSize() const;
281 
282  // Overrides PlotCanvas::setCachedAxesStackImageSize().
283  void setCachedAxesStackImageSize(int width, int height);
284 
285 
286  // Implements PlotCanvas::plotItem(). If the given items is NOT an
287  // instance of a QPPlotItem, a copy of the given items is made. The
288  // original item is NOT kept by the canvas, so any subsequent changes to
289  // the original items will not be reflected on the canvas.
290  bool plotItem(PlotItemPtr item, PlotCanvasLayer layer = MAIN);
291 
292  // Implements PlotCanvas::allPlotItems().
293  std::vector<PlotItemPtr> allPlotItems() const;
294 
295  // Implements PlotCanvas::layerPlotItems().
296  std::vector<PlotItemPtr> layerPlotItems(PlotCanvasLayer layer) const;
297 
298  // Overrides PlotCanvas::numPlotItems().
299  unsigned int numPlotItems() const;
300 
301  // Overrides PlotCanvas::numLayerPlotItems().
302  unsigned int numLayerPlotItems(PlotCanvasLayer layer) const;
303 
304  // Implements PlotCanvas::removePlotItems().
305  void removePlotItems(const std::vector<PlotItemPtr>& items);
306 
307  // Overrides PlotCanvas::clearPlotItems().
308  void clearPlotItems();
309 
310  // Overrides PlotCanvas::clearPlots().
311  void clearPlots();
312 
313  virtual void setNotUsed(){}
314 
315  // Overrides PlotCanvas::clearLayer().
316  void clearLayer(PlotCanvasLayer layer);
317 
318 
319  // Implements PlotCanvas::holdDrawing().
320  void holdDrawing();
321 
322  // Implements PlotCanvas::releaseDrawing().
323  void releaseDrawing();
324 
325  // Implements PlotCanvas::drawingIsHeld().
326  bool drawingIsHeld() const;
327 
328 
329  // Implements PlotCanvas::setSelectLineShown().
330  void setSelectLineShown(bool shown = true);
331 
332  // Implements PlotCanvas::selectLine().
333  PlotLinePtr selectLine() const;
334 
335  // Implements PlotCanvas::setSelectLine().
336  void setSelectLine(const PlotLine& line);
337 
338 
339  // Implements PlotCanvas::gridShown().
340  bool gridShown(bool* xMajor = NULL, bool* xMinor = NULL,
341  bool* yMajor = NULL, bool* yMinor = NULL) const;
342 
343  // Implements PlotCanvas::showGrid().
344  void showGrid(bool xMajor, bool xMinor, bool yMajor,bool yMinor);
345 
346  // Implements PlotCanvas::gridMajorLine().
347  PlotLinePtr gridMajorLine() const;
348 
349  // Implements PlotCanvas::setGridMajorLine().
350  void setGridMajorLine(const PlotLine& line);
351 
352  // Implements PlotCanvas::gridMinorLine().
353  PlotLinePtr gridMinorLine() const;
354 
355  // Implements PlotCanvas::setGridMinorLine().
356  void setGridMinorLine(const PlotLine& line);
357 
358 
359 
360  // Implements PlotCanvas::autoIncrementColors().
361  bool autoIncrementColors() const;
362 
363  // Implements PlotCanvas::setAutoIncrementColors().
364  void setAutoIncrementColors(bool autoInc = true);
365 
366  // Implements PlotCanvas::exportToFile().
367  bool exportToFile(const PlotExportFormat& format);
368 
369  // Implements PlotCanvas::fileChooserDialog().
370  casacore::String fileChooserDialog(const casacore::String& title = "File Chooser",
371  const casacore::String& directory = "");
372 
373  // Implements PlotCanvas::dateFormat().
374  const casacore::String& dateFormat() const;
375 
376  // Implements PlotCanvas::setDateFormat().
377  void setDateFormat(const casacore::String& dateFormat);
378 
379  // Implements PlotCanvas::relativeDateFormat().
380  const casacore::String& relativeDateFormat() const;
381 
382  // Implements PlotCanvas::setRelativeDateFormat().
383  void setRelativeDateFormat(const casacore::String& dateFormat);
384 
385  // Implements PlotCanvas::convertCoordinate().
386  PlotCoordinate convertCoordinate(const PlotCoordinate& coord,
387  PlotCoordinate::System newSystem = PlotCoordinate::WORLD) const;
388 
389  // Implements PlotCanvas::textWidthHeightDescent().
390  std::vector<double> textWidthHeightDescent(const casacore::String& text,
391  PlotFontPtr font) const;
392 
393  // Implements PlotCanvas::implementation().
394  int implementation() const { return Plotter::QWT; }
395 
396  // Implements PlotCanvas::implementationFactory().
397  PlotFactory* implementationFactory() const;
398  virtual bool print( QPrinter& printer );
399  virtual QImage grabImageFromCanvas(const PlotExportFormat& format );
400  virtual bool print( QPainter* painter, PlotAreaFillPtr paf, double widgetWidth,
401  double widgetHeight, int axisWidth, int axisHeight, int rowIndex, int colIndex,
402  QRect imageRect );
403  virtual bool printRect( QPainter* painter, QRect rect);
404  virtual const QPalette& palette() const;
405  virtual QPalette::ColorRole backgroundRole() const;
406  virtual bool isAxis() const {
407  return true;
408  }
409  virtual bool isVertical() const {
410  bool vertical = false;
411  if ( axisType == QwtPlot::yLeft || axisType == QwtPlot::yRight ){
412  vertical = true;
413  }
414  return vertical;
415  }
416 
417 protected:
418  // Sets the parent QPPlotter to the given. This MUST be done when a canvas
419  // is added to the plotter so that it can use the plotter's logger if
420  // needed.
421  void setQPPlotter(QPPlotter* parent);
422 
423  // Returns the parent's logger.
424  virtual PlotLoggerPtr logger() const;
425 
426  // See QPPlotter::logObject(). If called before setQPPlotter() is called,
427  // creates a queue that is then posted when setQPPlotter() is called.
428  void logObject(const casacore::String& className, void* address, bool creation,
429  const casacore::String& message = casacore::String());
430 
431  // See QPPlotter::logMethod(). Does NOT queue messages if called before
432  // setQPPlotter() is called.
433  void logMethod(const casacore::String& className, const casacore::String& methodName,
434  bool entering, const casacore::String& message = casacore::String());
435 
436  // Provides access to the cached axes stack.
437  // <group>
438  //QPAxesCache& axesCache();
439  //const QPAxesCache& axesCache() const;
440  // </group>
441 
442 
443 
444 private:
445  // Parent QPPlotter.
446  QPPlotter* m_parent;
447 
448  QwtPlot::Axis axisType;
449 
450  // Queued log messages before parent is set.
451  std::vector<PlotLogObject> m_queuedLogs;
452 
453 
454  // Whether the axes ratio is locked or not.
455  bool m_axesRatioLocked;
456 
457  // Used for recalculating axes ranges if the ratio is locked.
458  std::vector<double> m_axesRatios;
459 
460  // Date formats.
461  // <group>
462  casacore::String m_dateFormat;
463  casacore::String m_relativeDateFormat;
464  // </group>
465 
466  //External Axis
467  ExternalAxisWidget* axisWidget;
468 
469  // Converts the given Qt global position to a pixel PlotCoordinate.
470  // <group>
471  PlotCoordinate globalPosToPixelCoord(int x, int y);
472  PlotCoordinate globalPosToPixelCoord(QMouseEvent* event) {
473  return globalPosToPixelCoord(event->globalX(), event->globalY()); }
474  PlotCoordinate globalPosToPixelCoord(QWheelEvent* event) {
475  return globalPosToPixelCoord(event->globalX(), event->globalY()); }
476  // </group>
477 
478 
479 
480  // Converts between axes bitset flags (1,2,4,8 in PlotAxis and vector indices (0-3).
481  // (Does not deal with bitsets for combinations of axes, only single axis)
482  // <group>
483  static unsigned int axisIndex(PlotAxis a);
484  static PlotAxis axisIndex(unsigned int i);
485  // </group>
486 
487 
488  virtual int canvasWidth() const{
489  return width();
490  }
491  virtual int canvasHeight() const {
492  return height();
493  }
494 
495 
496 };
497 
498 }
499 
500 #endif
501 
502 #endif /*QPCANVAS_QO_H_*/
casacore::CountedPtr< PlotAreaFill > PlotAreaFillPtr
Definition: PlotOptions.h:364
casacore::CountedPtr< PlotLine > PlotLinePtr
Definition: PlotOptions.h:446
unsigned int PlotAxisBitset
Set of bit flags to indicate combinations of sides, used (as of this writing) for indicating which ax...
Definition: PlotOptions.h:70
size_t size() const
void show(const variant &v)
virtual void setSelectLine(PlotLinePtr line)
Sets the selection line to the given.
PlotCursor
Enum for cursors.
Definition: PlotOptions.h:94
PlotAxis
Enum for the four plot axes.
Definition: PlotOptions.h:62
casacore::CountedPtr< PlotFont > PlotFontPtr
Definition: PlotOptions.h:291
casacore::CountedPtr< PlotLogger > PlotLoggerPtr
Definition: PlotLogger.h:534
std::pair< double, double > prange_t
Typedef for range, which is two doubles (min and max).
Definition: PlotOptions.h:41
casacore::CountedPtr< PlotItem > PlotItemPtr
Definition: PlotItem.h:98
SortDirection
Definition: PlotOptions.h:52
AngleFormat
Enum for angle formats.
Definition: PlotOptions.h:87
String: the storage and methods of handling collections of characters.
Definition: String.h:223
PlotAxisScale
Enum for possible axis scales.
Definition: PlotOptions.h:78
PlotCanvasLayer
The canvas is composed of multiple layers, where changing/adding items from one layer will not affect...
Definition: PlotOptions.h:109
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51