QPLayeredCanvas.qo.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef QPLAYEREDCANVAS_QO_H_
00028 #define QPLAYEREDCANVAS_QO_H_
00029
00030 #ifdef AIPS_HAS_QWT
00031
00032 #include <casaqt/QwtPlotter/QPCanvasHelpers.qo.h>
00033 #include <casaqt/QwtPlotter/QPPlotItem.qo.h>
00034
00035 #include <qwt_plot.h>
00036
00037 #include <QPicture>
00038
00039 namespace casa {
00040
00041
00042 class QPCanvas;
00043
00044
00045
00046 class QPLayer {
00047 public:
00048
00049 QPLayer();
00050
00051
00052 virtual ~QPLayer();
00053
00054
00055
00056 virtual void clearImage() const;
00057
00058
00059
00060 virtual void initializeImage(const QSize& size,
00061 unsigned int fillValue = Qt::transparent) const;
00062
00063
00064
00065 virtual bool hasItemsToDraw() const;
00066
00067
00068
00069 virtual unsigned int itemDrawCount() const;
00070
00071
00072
00073 virtual unsigned int itemDrawSegments(unsigned int threshold =
00074 QPDrawThread::DEFAULT_SEGMENT_THRESHOLD) const;
00075
00076
00077
00078
00079 virtual void drawItems(QPainter* painter, const QRect& canvasRect,
00080 const QwtScaleMap maps[QwtPlot::axisCnt],
00081 PlotOperationPtr op = PlotOperationPtr(),
00082 unsigned int currentSegment = 0,
00083 unsigned int totalSegments = 0,
00084 unsigned int segmentThreshold =
00085 QPDrawThread::DEFAULT_SEGMENT_THRESHOLD) const;
00086
00087
00088
00089
00090 virtual void cacheItems(const QRect& canvasRect,
00091 const QwtScaleMap maps[QwtPlot::axisCnt],
00092 PlotOperationPtr op = PlotOperationPtr(),
00093 unsigned int currentSegment = 0,
00094 unsigned int totalSegments = 0,
00095 unsigned int segmentThreshold =
00096 QPDrawThread::DEFAULT_SEGMENT_THRESHOLD) const;
00097
00098
00099 virtual void drawCache(QPainter* painter, const QRect& rect) const;
00100
00101
00102
00103 QPImageCache& cachedImage();
00104 const QPImageCache& cachedImage() const;
00105
00106
00107
00108
00109
00110
00111
00112 virtual QList<QPLayerItem*> items() = 0;
00113 virtual QList<const QPLayerItem*> items() const = 0;
00114
00115
00116 protected:
00117
00118 QPImageCache m_cachedImage;
00119 };
00120
00121
00122
00123 class QPCanvasLayer : public QPLayer {
00124 public:
00125
00126 QPCanvasLayer();
00127
00128
00129 ~QPCanvasLayer();
00130
00131
00132
00133
00134 void addItem(QPPlotItem* item);
00135 void removeItem(QPPlotItem* item);
00136
00137
00138
00139 bool containsItem(QPPlotItem* item);
00140
00141
00142
00143 QList<QPPlotItem*> canvasItems() { return m_items; }
00144 QList<const QPPlotItem*> canvasItems() const;
00145
00146
00147
00148
00149
00150 QList<QPLayerItem*> items();
00151 QList<const QPLayerItem*> items() const;
00152
00153
00154 private:
00155
00156 QList<QPPlotItem*> m_items;
00157 };
00158
00159
00160
00161 class QPBaseLayer : public QPLayer {
00162 public:
00163
00164 QPBaseLayer();
00165
00166
00167 ~QPBaseLayer();
00168
00169
00170
00171
00172 void addItem(QPBaseItem* item);
00173 void removeItem(QPBaseItem* item);
00174
00175
00176
00177 bool containsItem(QPBaseItem* item);
00178
00179
00180
00181 QList<QPBaseItem*> canvasItems() { return m_items; }
00182 QList<const QPBaseItem*> canvasItems() const;
00183
00184
00185
00186
00187
00188 QList<QPLayerItem*> items();
00189 QList<const QPLayerItem*> items() const;
00190
00191
00192 private:
00193
00194 QList<QPBaseItem*> m_items;
00195 };
00196
00197
00198
00199
00200
00201 class QPLayeredCanvas : public QwtPlot {
00202 Q_OBJECT
00203
00204 friend class QPAxesCache;
00205 friend class QPCanvas;
00206 friend class QPAxis;
00207 friend class QPPlotItem;
00208 friend class QPBaseItem;
00209 friend class QPLegendHolder;
00210
00211 public:
00212
00213 static const String CLASS_NAME;
00214
00215
00216
00217 QPLayeredCanvas(QPCanvas* parent, QWidget* parentWidget = NULL);
00218
00219
00220
00221 QPLayeredCanvas(const QwtText& title, QPCanvas* parent,
00222 QWidget* parentWidget = NULL);
00223
00224
00225 ~QPLayeredCanvas();
00226
00227
00228
00229 using QwtPlot::replot;
00230
00231
00232
00233
00234
00235 QList<const QPPlotItem*> allAttachedItems() const {
00236 return allLayerItems(PlotCanvas::allLayersFlag()); }
00237
00238
00239
00240 QList<const QPPlotItem*> allLayerItems(int layersFlag) const;
00241
00242
00243 QRect canvasDrawRect() const;
00244
00245
00246
00247
00248
00249 #if QWT_VERSION >= 0x060000
00250 void print(QPainter* painter, const QRect& rect);
00251 void print(QPaintDevice& paintDev);
00252 #else
00253 using QwtPlot::print;
00254 void print(QPainter* painter, const QRect& rect,
00255 const QwtPlotPrintFilter& filter = QwtPlotPrintFilter()) const;
00256 #endif
00257
00258
00259 virtual Bool isDrawing();
00260
00261
00262
00263
00264
00265 bool eventFilter(QObject* watched, QEvent* event);
00266
00267 protected:
00268
00269
00270
00271 void attachLayeredItem(QPPlotItem* item);
00272
00273
00274 void detachLayeredItem(QPPlotItem* item);
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 void drawItems(QPainter* painter, const QRect& rect,
00285 const QwtScaleMap maps[axisCnt]);
00286 void printItems(QPainter* painter, const QRect& rect,
00287 const QwtScaleMap maps[axisCnt]);
00288
00289 #if QWT_VERSION < 0x060000
00290
00291 void drawItems(QPainter* painter, const QRect& rect,
00292 const QwtScaleMap maps[axisCnt],
00293 const QwtPlotPrintFilter& );
00294
00295
00296
00297 void printItems(QPainter* painter, const QRect& rect,
00298 const QwtScaleMap maps[axisCnt],
00299 const QwtPlotPrintFilter& ) {
00300 printItems(painter, rect, maps);
00301 }
00302 #endif
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 bool drawingIsHeld() const;
00314 void holdDrawing();
00315 void releaseDrawing();
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 void setLayerChanged(PlotCanvasLayer layer);
00326 void setLayersChanged(int layersFlag);
00327 void setAllLayersChanged() {
00328 setLayersChanged(PlotCanvas::allLayersFlag()); }
00329
00330
00331
00332 bool changedLayer(PlotCanvasLayer layer) const;
00333
00334
00335 bool anyChangedLayer() const;
00336
00337
00338
00339 int changedLayersFlag() const;
00340
00341
00342
00343
00344
00345
00346 const QPGrid& grid() const;
00347 QPGrid& grid();
00348
00349
00350
00351
00352 const QHash<PlotAxis, QPCartesianAxis*>& cartesianAxes() const;
00353 QHash<PlotAxis, QPCartesianAxis*>& cartesianAxes();
00354
00355
00356
00357 bool cartesianAxisShown(PlotAxis axis) const;
00358
00359
00360 void showCartesianAxis(PlotAxis mirrorAxis, PlotAxis secondaryAxis,
00361 bool show);
00362
00363
00364
00365
00366
00367 void installLegendFilter(QWidget* legendFrame);
00368
00369 private:
00370
00371 QPCanvas* m_parent;
00372
00373
00374
00375 QPBaseLayer m_layerBase;
00376
00377
00378 QMap<PlotCanvasLayer, QPCanvasLayer*> m_layers;
00379
00380
00381 QHash<PlotCanvasLayer, bool> m_changedLayers;
00382
00383
00384
00385 bool m_drawingHeld;
00386
00387
00388 bool m_isPrinting;
00389
00390
00391 QList<QPainter*> m_printPainters;
00392
00393
00394 mutable QPDrawThread* m_drawThread;
00395
00396
00397 bool m_redrawWaiting;
00398
00399
00400
00401 QPGrid* m_grid;
00402
00403
00404 QHash<PlotAxis, QPCartesianAxis*> m_cartAxes;
00405
00406
00407
00408 QWidget* m_legendFrame;
00409
00410
00411
00412 void initialize();
00413
00414 private slots:
00415
00416 void itemDrawingFinished();
00417 };
00418
00419 }
00420
00421 #endif
00422
00423 #endif