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 QPPLOTITEM_H_
00028 #define QPPLOTITEM_H_
00029
00030 #ifdef AIPS_HAS_QWT
00031
00032 #include <casaqt/QwtPlotter/QPImageCache.h>
00033 #include <graphics/GenericPlotter/PlotLogger.h>
00034 #include <graphics/GenericPlotter/PlotOperation.h>
00035 #include <graphics/GenericPlotter/PlotItem.h>
00036
00037 #include <QHash>
00038 #include <QPainter>
00039 #include <QThread>
00040
00041 #include <qwt_plot.h>
00042 #include <casaqt/QwtConfig.h>
00043
00044 namespace casa {
00045
00046
00047 class QPCanvas;
00048
00049
00050
00051
00052 class QPLayerItem : public QwtPlotItem {
00053 friend class QPCanvas;
00054 friend class QPLayeredCanvas;
00055 friend class QPDrawThread;
00056
00057 public:
00058
00059 QPLayerItem();
00060
00061
00062 virtual ~QPLayerItem();
00063
00064
00065
00066 #if QWT_VERSION >= 0x060000
00067 virtual void draw(QPainter* p, const QwtScaleMap& xMap,
00068 const QwtScaleMap& yMap, const QRectF& canvasRect) const;
00069 #else
00070 virtual void draw(QPainter* p, const QwtScaleMap& xMap,
00071 const QwtScaleMap& yMap, const QRect& canvasRect) const;
00072 #endif
00073
00074
00075 virtual unsigned int itemDrawSegments(unsigned int segmentThreshold) const;
00076
00077
00078
00079
00080
00081
00082 virtual void itemChanged() = 0;
00083
00084
00085
00086
00087 virtual bool shouldDraw() const = 0;
00088
00089
00090 virtual unsigned int itemDrawCount() const = 0;
00091
00092
00093 virtual String itemTitle() const = 0;
00094
00095 protected:
00096
00097
00098
00099
00100 #if QWT_VERSION >= 0x060000
00101 virtual void draw_(QPainter* p, const QwtScaleMap& xMap,
00102 const QwtScaleMap& yMap, const QRectF& drawRect,
00103 unsigned int drawIndex, unsigned int drawCount) const = 0;
00104 #else
00105 virtual void draw_(QPainter* p, const QwtScaleMap& xMap,
00106 const QwtScaleMap& yMap, const QRect& drawRect,
00107 unsigned int drawIndex, unsigned int drawCount) const = 0;
00108 #endif
00109 };
00110
00111
00112
00113
00114 class QPPlotItem : public virtual PlotItem, public QPLayerItem {
00115 friend class QPCanvas;
00116 friend class QPDrawThread;
00117
00118 public:
00119
00120
00121
00122 static const String DRAW_NAME;
00123
00124 using QPLayerItem::draw;
00125
00126
00127 static bool isQPPlotItem(const PlotItemPtr item);
00128
00129
00130
00131
00132
00133 static QPPlotItem* cloneItem(const PlotItemPtr item, bool* wasCloned=NULL);
00134
00135
00136
00137 static bool sameType(QPPlotItem* item1, QPPlotItem* item2);
00138
00139
00140
00141 static bool isPlot(QPPlotItem* item);
00142
00143
00144
00145
00146
00147 QPPlotItem();
00148
00149
00150 virtual ~QPPlotItem();
00151
00152
00153
00154
00155
00156 PlotCanvas* canvas() const;
00157
00158
00159 String title() const;
00160
00161
00162 void setTitle(const String& newTitle);
00163
00164
00165 virtual bool isQWidget() const { return false; }
00166
00167
00168 PlotAxis xAxis() const;
00169
00170
00171 PlotAxis yAxis() const;
00172
00173
00174 void setXAxis(PlotAxis x);
00175
00176
00177 void setYAxis(PlotAxis y);
00178
00179
00180
00181
00182
00183
00184 virtual void itemChanged();
00185
00186
00187 virtual bool shouldDraw() const { return isValid(); }
00188
00189
00190 unsigned int itemDrawCount() const{ return shouldDraw()? drawCount() : 0; }
00191
00192
00193 String itemTitle() const { return title(); }
00194
00195
00196
00197
00198
00199 PlotCanvasLayer canvasLayer() const { return m_layer; }
00200
00201
00202
00203 const QwtText& qwtTitle() const { return QwtPlotItem::title(); }
00204 void setQwtTitle(const QwtText& text) { QwtPlotItem::setTitle(text); }
00205 QwtPlot::Axis qwtXAxis() const{return QwtPlot::Axis(QwtPlotItem::xAxis());}
00206 QwtPlot::Axis qwtYAxis() const{return QwtPlot::Axis(QwtPlotItem::yAxis());}
00207 void qwtAttach(QwtPlot* plot) { QwtPlotItem::attach(plot); }
00208 void qwtDetach() { QwtPlotItem::detach(); }
00209
00210
00211
00212
00213
00214
00215 virtual QwtDoubleRect boundingRect() const = 0;
00216
00217 #if QWT_VERSION < 0x060000
00218
00219
00220 virtual QWidget* legendItem() const = 0;
00221 #endif
00222
00223 protected:
00224
00225 QPCanvas* m_canvas;
00226
00227
00228
00229 bool m_loggedCreation;
00230
00231
00232 PlotCanvasLayer m_layer;
00233
00234
00235
00236
00237 void attach(QPCanvas* canvas, PlotCanvasLayer layer);
00238 void detach();
00239
00240
00241
00242 PlotLoggerPtr logger() const;
00243
00244
00245
00246 void logDestruction();
00247
00248
00249 void logMethod(const String& methodName, bool entering,
00250 const String& message = String()) const;
00251
00252
00253 PlotOperationPtr drawOperation() const;
00254
00255
00256
00257
00258
00259 virtual const String& className() const = 0;
00260 };
00261
00262
00263
00264
00265
00266
00267
00268 class QPDrawThread : public QThread {
00269 Q_OBJECT
00270
00271 public:
00272
00273
00274
00275 static const String CLASS_NAME;
00276
00277
00278 static const unsigned int DEFAULT_SEGMENT_THRESHOLD;
00279
00280
00281
00282 static bool itemSortByZ(const QPLayerItem* item1,const QPLayerItem* item2);
00283
00284
00285
00286
00287
00288
00289 static void drawItem(const QPLayerItem* item, QPainter* painter,
00290 const QRect& rect, const QwtScaleMap maps[QwtPlot::axisCnt]);
00291 static void drawItem(const QPLayerItem* item, QPainter* painter,
00292 const QRect& rect, const QwtScaleMap maps[QwtPlot::axisCnt],
00293 unsigned int drawIndex, unsigned int drawCount);
00294 static void drawItems(const QList<const QPLayerItem*>& items,
00295 QPainter* painter, const QRect& rect,
00296 const QwtScaleMap maps[QwtPlot::axisCnt],
00297 PlotOperationPtr op = PlotOperationPtr(),
00298 unsigned int currentSegment = 0, unsigned int totalSegments = 0,
00299 unsigned int segmentThreshold =
00300 QPDrawThread::DEFAULT_SEGMENT_THRESHOLD);
00301 static void drawItems(const QList<const QPPlotItem*>& items,
00302 QPainter* painter, const QRect& rect,
00303 const QwtScaleMap maps[QwtPlot::axisCnt],
00304 PlotOperationPtr op = PlotOperationPtr(),
00305 unsigned int currentSegment = 0, unsigned int totalSegments = 0,
00306 unsigned int segmentThreshold =
00307 QPDrawThread::DEFAULT_SEGMENT_THRESHOLD);
00308
00309
00310
00311
00312
00313
00314
00315
00316 QPDrawThread(const QList<const QPPlotItem*>& items,
00317 const QwtScaleMap maps[QwtPlot::axisCnt], QSize imageSize,
00318 unsigned int segmentTreshold = DEFAULT_SEGMENT_THRESHOLD);
00319
00320
00321 ~QPDrawThread();
00322
00323
00324
00325 unsigned int totalSegments() const;
00326
00327
00328
00329
00330 void run();
00331
00332
00333
00334
00335 QPImageCache drawResult(PlotCanvasLayer layer, bool clearResult = true);
00336
00337
00338 int getId() const {
00339 return id;
00340 }
00341
00342 public slots:
00343
00344
00345 void cancel();
00346
00347 private:
00348 int id;
00349
00350
00351 QList<const QPPlotItem*> m_items;
00352
00353
00354 QwtScaleMap m_axesMaps[QwtPlot::axisCnt];
00355
00356
00357 QHash<PlotCanvasLayer, QPImageCache*> m_images;
00358
00359
00360 unsigned int m_segmentThreshold;
00361
00362
00363 bool m_cancelFlag;
00364 };
00365
00366 }
00367
00368 #endif
00369
00370 #endif