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 QPCANVAS_QO_H_
00028 #define QPCANVAS_QO_H_
00029
00030 #ifdef AIPS_HAS_QWT
00031
00032 #include <casaqt/QwtConfig.h>
00033 #include <graphics/GenericPlotter/PlotOptions.h>
00034 #include <graphics/GenericPlotter/PlotLogger.h>
00035 #include <graphics/GenericPlotter/Plotter.h>
00036 #include <casaqt/QwtPlotter/QPImageCache.h>
00037 #include <casaqt/QwtPlotter/QPLayeredCanvas.qo.h>
00038 #include <casaqt/QwtPlotter/QPExportCanvas.h>
00039 #include <casaqt/QwtPlotter/QPOptions.h>
00040 #include <casaqt/QwtPlotter/QPPlotItem.qo.h>
00041
00042 #include <qwt_plot_picker.h>
00043
00044 #include <QtGui>
00045
00046 #include <vector>
00047
00048 namespace casa {
00049
00050
00051 class QPPlotter;
00052 class AxisListener;
00053
00054
00055
00056
00057 class QPCanvas : public QFrame, public QPExportCanvas {
00058 Q_OBJECT
00059
00060 friend class QPAxesCache;
00061 friend class QPDrawThread;
00062 friend class QPLayeredCanvas;
00063 friend class QPPlotItem;
00064 friend class QPPlotter;
00065
00066 public:
00067
00068
00069
00070 static double zOrder;
00071
00072
00073 static const String CLASS_NAME;
00074
00075
00076
00077 static const String DRAW_NAME;
00078
00079
00080
00081
00082
00083
00084
00085
00086 QPCanvas(QPPlotter* parent = NULL);
00087
00088
00089 ~QPCanvas();
00090
00091
00092
00093 using PlotCanvas::setBackground;
00094 using PlotCanvas::setSelectLine;
00095 using PlotCanvas::setTitleFont;
00096 using PlotCanvas::showAxes;
00097 using PlotCanvas::showCartesianAxis;
00098 using PlotCanvas::setAxisFont;
00099 using PlotCanvas::setAxisRange;
00100 using PlotCanvas::setAxesRanges;
00101 using PlotCanvas::showGrid;
00102 using PlotCanvas::setGridMajorLine;
00103 using PlotCanvas::setGridMinorLine;
00104 using PlotCanvas::setLegendLine;
00105 using PlotCanvas::setLegendFill;
00106 using PlotCanvas::setLegendFont;
00107
00108
00109
00110
00111
00112
00113 std::pair<int, int> size() const;
00114 virtual void setMinimumSize( int width, int height ){
00115 QFrame::setMinimumSize( width, height );
00116 }
00117
00118 virtual void show(){
00119 QFrame::show();
00120 }
00121
00122 virtual void hide(){
00123 QFrame::setVisible( false );
00124 }
00125
00126
00127 String title() const;
00128
00129
00130 void setTitle(const String& title);
00131
00132
00133 PlotFontPtr titleFont() const;
00134
00135
00136 void setTitleFont(const PlotFont& font);
00137
00138
00139 PlotAreaFillPtr background() const;
00140
00141
00142 void setBackground(const PlotAreaFill& areaFill);
00143
00144
00145 PlotCursor cursor() const;
00146
00147
00148 void setCursor(PlotCursor cursor);
00149
00150
00151
00152 void refresh();
00153 void refresh(int drawLayersFlag);
00154
00155
00156
00157 bool isQWidget() const { return true; }
00158
00159
00160
00161
00162 PlotAxisBitset shownAxes() const;
00163
00164
00165
00166 void showAxes(PlotAxisBitset axes);
00167
00168
00169 PlotAxisScale axisScale(PlotAxis axis) const;
00170
00171
00172 void setAxisScale(PlotAxis axis, PlotAxisScale scale);
00173
00174
00175 bool axisReferenceValueSet(PlotAxis axis) const;
00176
00177
00178 double axisReferenceValue(PlotAxis axis) const;
00179
00180
00181 void setAxisReferenceValue(PlotAxis axis, bool on, double value = 0);
00182
00183
00184 bool cartesianAxisShown(PlotAxis axis) const;
00185
00186
00187 void showCartesianAxis(PlotAxis mirrorAxis, PlotAxis secondaryAxis,
00188 bool show = true, bool hideNormalAxis = true);
00189
00190
00191 String axisLabel(PlotAxis axis) const;
00192
00193
00194 void setAxisLabel(PlotAxis axis, const String& title);
00195
00196
00197 PlotFontPtr axisFont(PlotAxis axis) const;
00198
00199
00200 void setAxisFont(PlotAxis axis, const PlotFont& font);
00201
00202
00203 bool colorBarShown(PlotAxis axis = Y_RIGHT) const;
00204
00205
00206 void showColorBar(bool show = true, PlotAxis axis = Y_RIGHT);
00207
00208
00209
00210 prange_t axisRange(PlotAxis axis) const;
00211
00212
00213 void setAxisRange(PlotAxis axis, double from, double to);
00214
00215
00216 void setAxesRanges(PlotAxis xAxis, double xFrom, double xTo,
00217 PlotAxis yAxis, double yFrom, double yTo);
00218
00219
00220 bool axesAutoRescale() const;
00221
00222
00223 void setAxesAutoRescale(bool autoRescale = true);
00224
00225
00226 void rescaleAxes();
00227
00228
00229 bool axesRatioLocked() const;
00230
00231
00232 void setAxesRatioLocked(bool locked = true);
00233
00234
00235
00236 int cachedAxesStackSizeLimit() const;
00237
00238
00239 void setCachedAxesStackSizeLimit(int sizeInKilobytes);
00240
00241
00242 std::pair<int, int> cachedAxesStackImageSize() const;
00243
00244
00245 void setCachedAxesStackImageSize(int width, int height);
00246
00247
00248
00249
00250
00251
00252 bool plotItem(PlotItemPtr item, PlotCanvasLayer layer = MAIN);
00253
00254
00255 std::vector<PlotItemPtr> allPlotItems() const;
00256
00257
00258 std::vector<PlotItemPtr> layerPlotItems(PlotCanvasLayer layer) const;
00259
00260
00261 unsigned int numPlotItems() const;
00262
00263
00264 unsigned int numLayerPlotItems(PlotCanvasLayer layer) const;
00265
00266
00267 void removePlotItems(const std::vector<PlotItemPtr>& items);
00268
00269
00270 void clearPlotItems();
00271
00272
00273 void clearPlots();
00274
00275
00276 void clearLayer(PlotCanvasLayer layer);
00277
00278
00279
00280 void holdDrawing();
00281
00282
00283 void releaseDrawing();
00284
00285
00286 bool drawingIsHeld() const;
00287
00288
00289
00290 void setSelectLineShown(bool shown = true);
00291
00292
00293 PlotLinePtr selectLine() const;
00294
00295
00296 void setSelectLine(const PlotLine& line);
00297
00298
00299
00300 bool gridShown(bool* xMajor = NULL, bool* xMinor = NULL,
00301 bool* yMajor = NULL, bool* yMinor = NULL) const;
00302
00303
00304 void showGrid(bool xMajor, bool xMinor, bool yMajor,bool yMinor);
00305
00306
00307 PlotLinePtr gridMajorLine() const;
00308
00309
00310 void setGridMajorLine(const PlotLine& line);
00311
00312
00313 PlotLinePtr gridMinorLine() const;
00314
00315
00316 void setGridMinorLine(const PlotLine& line);
00317
00318
00319
00320 bool legendShown() const;
00321
00322
00323 void showLegend(bool on = true, LegendPosition position = EXT_BOTTOM);
00324
00325
00326 LegendPosition legendPosition() const;
00327
00328
00329 void setLegendPosition(LegendPosition position);
00330
00331
00332 PlotLinePtr legendLine() const;
00333
00334
00335 void setLegendLine(const PlotLine& line);
00336
00337
00338 PlotAreaFillPtr legendFill() const;
00339
00340
00341 void setLegendFill(const PlotAreaFill& area);
00342
00343
00344 PlotFontPtr legendFont() const;
00345
00346
00347 void setLegendFont(const PlotFont& font);
00348
00349
00350
00351 bool autoIncrementColors() const;
00352
00353
00354 void setAutoIncrementColors(bool autoInc = true);
00355
00356
00357 bool exportToFile(const PlotExportFormat& format);
00358
00359
00360 String fileChooserDialog(const String& title = "File Chooser",
00361 const String& directory = "");
00362
00363
00364 const String& dateFormat() const;
00365
00366
00367 void setDateFormat(const String& dateFormat);
00368
00369
00370 const String& relativeDateFormat() const;
00371
00372
00373 void setRelativeDateFormat(const String& dateFormat);
00374
00375
00376 PlotCoordinate convertCoordinate(const PlotCoordinate& coord,
00377 PlotCoordinate::System newSystem = PlotCoordinate::WORLD) const;
00378
00379
00380 std::vector<double> textWidthHeightDescent(const String& text,
00381 PlotFontPtr font) const;
00382
00383
00384 int implementation() const { return Plotter::QWT; }
00385
00386
00387 PlotFactory* implementationFactory() const;
00388
00389
00390
00391
00392
00393
00394 QPLayeredCanvas& asQwtPlot();
00395 const QPLayeredCanvas& asQwtPlot() const;
00396
00397
00398
00399 QwtPlotPicker& getSelecter();
00400
00401
00402
00403 void reinstallTrackerFilter();
00404
00405
00406 QSize sizeHint() const;
00407
00408
00409 QSize minimumSizeHint() const;
00410
00411
00412
00413
00414
00415 virtual void setMinimumSizeHint( int width, int height );
00416
00417 virtual void setCommonAxes( bool commonX, bool commonY );
00418 void addAxisListener( AxisListener* listener );
00419 void clearAxisListeners();
00420
00421 virtual bool isDrawing();
00422 protected:
00423
00424
00425
00426 void setQPPlotter(QPPlotter* parent);
00427
00428
00429 virtual PlotLoggerPtr logger() const;
00430
00431
00432
00433 void logObject(const String& className, void* address, bool creation,
00434 const String& message = String());
00435
00436
00437
00438 void logMethod(const String& className, const String& methodName,
00439 bool entering, const String& message = String());
00440
00441
00442
00443 QPAxesCache& axesCache();
00444 const QPAxesCache& axesCache() const;
00445
00446
00447
00448 void mousePressEvent(QMouseEvent* event);
00449
00450
00451 void mouseReleaseEvent(QMouseEvent* event);
00452
00453
00454 void mouseDoubleClickEvent(QMouseEvent* event);
00455
00456
00457 void keyReleaseEvent(QKeyEvent* event);
00458
00459
00460 void wheelEvent(QWheelEvent* event);
00461
00462
00463 void resizeEvent(QResizeEvent* event);
00464
00465 bool isThreading() const;
00466
00467
00468 private:
00469
00470 QPPlotter* m_parent;
00471
00472
00473 std::vector<PlotLogObject> m_queuedLogs;
00474
00475
00476 QPLayeredCanvas m_canvas;
00477
00478
00479 std::vector<std::pair<PlotItemPtr, QPPlotItem*> > m_plotItems;
00480
00481
00482 std::vector<std::pair<PlotItemPtr, QPPlotItem*> > m_layeredItems;
00483
00484
00485 QPScaleDraw* m_scaleDraws[QwtPlot::axisCnt];
00486
00487
00488 bool m_axesRatioLocked;
00489
00490 bool isCommonAxis( PlotAxis axis ) const;
00491 bool commonX;
00492 bool commonY;
00493
00494
00495 std::vector<double> m_axesRatios;
00496
00497
00498 QPAxesCache m_stackCache;
00499
00500
00501 bool m_autoIncColors;
00502
00503
00504 std::vector<int> m_usedColors;
00505
00506
00507 QwtPlotPicker m_picker;
00508
00509
00510
00511 QPMouseFilter m_mouseFilter;
00512
00513
00514
00515 QPLegendHolder* m_legend;
00516 QPFont m_legendFont;
00517 bool m_legendFontSet;
00518
00519
00520
00521 bool m_inDraggingMode;
00522
00523 QList<AxisListener*> axisListeners;
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536 String m_dateFormat;
00537 String m_relativeDateFormat;
00538
00539
00540
00541
00542
00543 PlotCoordinate globalPosToPixelCoord(int x, int y);
00544 PlotCoordinate globalPosToPixelCoord(QMouseEvent* event) {
00545 return globalPosToPixelCoord(event->globalX(), event->globalY()); }
00546 PlotCoordinate globalPosToPixelCoord(QWheelEvent* event) {
00547 return globalPosToPixelCoord(event->globalX(), event->globalY()); }
00548
00549
00550
00551 virtual bool print( QPrinter& printer );
00552 virtual bool print( QPainter* painter, PlotAreaFillPtr paf, double widthWidth,
00553 double widgetHeight, int externalAxisWidth, int externalAxisHeight,
00554 int rowIndex, int colIndex, QRect imageRect );
00555 virtual bool printRect( QPainter* painter, QRect rect);
00556
00557 virtual int canvasWidth() const{
00558 return width();
00559 }
00560 virtual int canvasHeight() const {
00561 return height();
00562 }
00563 virtual const QPalette& palette() const {
00564 return asQwtPlot().palette();
00565 }
00566 virtual QPalette::ColorRole backgroundRole() const{
00567 return asQwtPlot().backgroundRole();
00568 }
00569
00570
00571 QImage grabImageFromCanvas( const PlotExportFormat& format );
00572
00573
00574
00575
00576
00577 static unsigned int axisIndex(PlotAxis a);
00578 static PlotAxis axisIndex(unsigned int i);
00579
00580
00581 const QwtScaleDiv* getAxisScaleDiv(int axisId) const;
00582
00583 QSize minSizeHint;
00584
00585
00586 private slots:
00587
00588
00589
00590 void regionSelected(const QwtDoubleRect&);
00591 void regionSelected2(const QRectF&);
00592
00593
00594
00595
00596
00597 void trackerMouseEvent(QMouseEvent* event);
00598
00599 void enableAxis( QwtPlot::Axis axis, bool enable );
00600 };
00601
00602 }
00603
00604 #endif
00605
00606 #endif