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 QPAXIS_QO_H_
00028 #define QPAXIS_QO_H_
00029
00030 #ifdef AIPS_HAS_QWT
00031
00032 #include <graphics/GenericPlotter/PlotOptions.h>
00033 #include <graphics/GenericPlotter/PlotLogger.h>
00034 #include <graphics/GenericPlotter/Plotter.h>
00035 #include <casaqt/QwtPlotter/QPImageCache.h>
00036 #include <casaqt/QwtPlotter/QPLayeredCanvas.qo.h>
00037 #include <casaqt/QwtPlotter/QPExportCanvas.h>
00038 #include <casaqt/QwtPlotter/QPOptions.h>
00039 #include <casaqt/QwtPlotter/AxisListener.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 ExternalAxisWidget;
00053
00054
00055
00056 class QPAxis : public QFrame, public QPExportCanvas, public AxisListener {
00057 Q_OBJECT
00058
00059 friend class QPAxesCache;
00060 friend class QPDrawThread;
00061 friend class QPLayeredCanvas;
00062 friend class QPPlotItem;
00063 friend class QPPlotter;
00064
00065 public:
00066
00067
00068
00069 static double zOrder;
00070
00071
00072 static const String CLASS_NAME;
00073
00074
00075
00076 static const String DRAW_NAME;
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 QPAxis(PlotAxis axis, QPPlotter* parent, QwtPlot* associatedPlot,
00087 bool leftAxisInternal, bool bottomAxisInternal,
00088 bool rightAxisInternal );
00089
00090
00091 virtual ~QPAxis();
00092
00093
00094
00095
00096 bool legendShown() const{return false;};
00097
00098
00099 void showLegend(bool , LegendPosition ){}
00100
00101
00102 LegendPosition legendPosition() const {
00103 return PlotCanvas::INT_URIGHT;
00104 }
00105
00106
00107 void setLegendPosition(LegendPosition ){}
00108
00109
00110 PlotLinePtr legendLine() const {
00111 return PlotLinePtr();
00112 }
00113
00114 virtual void setMinimumSizeHint( int width, int height );
00115
00116
00117 void setLegendLine(const PlotLine& ){}
00118
00119
00120 PlotAreaFillPtr legendFill() const {
00121 return PlotAreaFillPtr();
00122 }
00123
00124
00125 void setLegendFill(const PlotAreaFill& ){}
00126
00127
00128 PlotFontPtr legendFont() const {
00129 return PlotFontPtr();
00130 }
00131
00132
00133 void setLegendFont(const PlotFont& ){}
00134
00135
00136 virtual void setCommonAxes( bool , bool ){}
00137
00138
00139 std::pair<int, int> size() const;
00140 virtual void setMinimumSize( int width, int height ){
00141 QFrame::setMinimumSize( width, height );
00142 }
00143
00144 bool isDrawing( );
00145
00146 virtual void show(){
00147 QFrame::show();
00148 }
00149
00150 virtual void hide(){
00151 QFrame::show();
00152 }
00153
00154
00155 String title() const;
00156
00157
00158 void setTitle(const String& title);
00159
00160
00161 PlotFontPtr titleFont() const;
00162
00163
00164 void setTitleFont(const PlotFont& font);
00165
00166
00167 PlotAreaFillPtr background() const;
00168
00169
00170 void setBackground(const PlotAreaFill& areaFill);
00171
00172
00173 PlotCursor cursor() const;
00174
00175
00176 void setCursor(PlotCursor cursor);
00177
00178
00179
00180 void refresh();
00181 void refresh(int drawLayersFlag);
00182
00183
00184
00185 bool isQWidget() const { return true; }
00186
00187
00188
00189
00190 PlotAxisBitset shownAxes() const;
00191
00192
00193
00194 void showAxes(PlotAxisBitset axes);
00195
00196
00197 PlotAxisScale axisScale(PlotAxis axis) const;
00198
00199
00200 void setAxisScale(PlotAxis axis, PlotAxisScale scale);
00201
00202
00203 bool axisReferenceValueSet(PlotAxis axis) const;
00204
00205
00206 double axisReferenceValue(PlotAxis axis) const;
00207
00208
00209 void setAxisReferenceValue(PlotAxis axis, bool on, double value = 0);
00210
00211
00212 bool cartesianAxisShown(PlotAxis axis) const;
00213
00214
00215 void showCartesianAxis(PlotAxis mirrorAxis, PlotAxis secondaryAxis,
00216 bool show = true, bool hideNormalAxis = true);
00217
00218
00219 String axisLabel(PlotAxis axis) const;
00220
00221
00222 void setAxisLabel(PlotAxis axis, const String& title);
00223
00224
00225 PlotFontPtr axisFont(PlotAxis axis) const;
00226
00227
00228 void setAxisFont(PlotAxis axis, const PlotFont& font);
00229
00230
00231 bool colorBarShown(PlotAxis axis = Y_RIGHT) const;
00232
00233
00234 void showColorBar(bool show = true, PlotAxis axis = Y_RIGHT);
00235
00236
00237
00238 prange_t axisRange(PlotAxis axis) const;
00239
00240
00241 void setAxisRange(PlotAxis axis, double from, double to);
00242
00243
00244 void setAxesRanges(PlotAxis xAxis, double xFrom, double xTo,
00245 PlotAxis yAxis, double yFrom, double yTo);
00246
00247
00248 bool axesAutoRescale() const;
00249
00250
00251 void setAxesAutoRescale(bool autoRescale = true);
00252
00253
00254 void rescaleAxes();
00255
00256
00257 bool axesRatioLocked() const;
00258
00259
00260 void setAxesRatioLocked(bool locked = true);
00261
00262
00263
00264 int cachedAxesStackSizeLimit() const;
00265
00266
00267 void setCachedAxesStackSizeLimit(int sizeInKilobytes);
00268
00269
00270 std::pair<int, int> cachedAxesStackImageSize() const;
00271
00272
00273 void setCachedAxesStackImageSize(int width, int height);
00274
00275
00276
00277
00278
00279
00280 bool plotItem(PlotItemPtr item, PlotCanvasLayer layer = MAIN);
00281
00282
00283 std::vector<PlotItemPtr> allPlotItems() const;
00284
00285
00286 std::vector<PlotItemPtr> layerPlotItems(PlotCanvasLayer layer) const;
00287
00288
00289 unsigned int numPlotItems() const;
00290
00291
00292 unsigned int numLayerPlotItems(PlotCanvasLayer layer) const;
00293
00294
00295 void removePlotItems(const std::vector<PlotItemPtr>& items);
00296
00297
00298 void clearPlotItems();
00299
00300
00301 void clearPlots();
00302
00303 virtual void setNotUsed(){}
00304
00305
00306 void clearLayer(PlotCanvasLayer layer);
00307
00308
00309
00310 void holdDrawing();
00311
00312
00313 void releaseDrawing();
00314
00315
00316 bool drawingIsHeld() const;
00317
00318
00319
00320 void setSelectLineShown(bool shown = true);
00321
00322
00323 PlotLinePtr selectLine() const;
00324
00325
00326 void setSelectLine(const PlotLine& line);
00327
00328
00329
00330 bool gridShown(bool* xMajor = NULL, bool* xMinor = NULL,
00331 bool* yMajor = NULL, bool* yMinor = NULL) const;
00332
00333
00334 void showGrid(bool xMajor, bool xMinor, bool yMajor,bool yMinor);
00335
00336
00337 PlotLinePtr gridMajorLine() const;
00338
00339
00340 void setGridMajorLine(const PlotLine& line);
00341
00342
00343 PlotLinePtr gridMinorLine() const;
00344
00345
00346 void setGridMinorLine(const PlotLine& line);
00347
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 virtual bool print( QPrinter& printer );
00389 virtual QImage grabImageFromCanvas(const PlotExportFormat& format );
00390 virtual bool print( QPainter* painter, PlotAreaFillPtr paf, double widgetWidth,
00391 double widgetHeight, int axisWidth, int axisHeight, int rowIndex, int colIndex,
00392 QRect imageRect );
00393 virtual bool printRect( QPainter* painter, QRect rect);
00394 virtual const QPalette& palette() const;
00395 virtual QPalette::ColorRole backgroundRole() const;
00396 virtual bool isAxis() const {
00397 return true;
00398 }
00399 virtual bool isVertical() const {
00400 bool vertical = false;
00401 if ( axisType == QwtPlot::yLeft || axisType == QwtPlot::yRight ){
00402 vertical = true;
00403 }
00404 return vertical;
00405 }
00406
00407 protected:
00408
00409
00410
00411 void setQPPlotter(QPPlotter* parent);
00412
00413
00414 virtual PlotLoggerPtr logger() const;
00415
00416
00417
00418 void logObject(const String& className, void* address, bool creation,
00419 const String& message = String());
00420
00421
00422
00423 void logMethod(const String& className, const String& methodName,
00424 bool entering, const String& message = String());
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434 private:
00435
00436 QPPlotter* m_parent;
00437
00438 QwtPlot::Axis axisType;
00439
00440
00441 std::vector<PlotLogObject> m_queuedLogs;
00442
00443
00444
00445 bool m_axesRatioLocked;
00446
00447
00448 std::vector<double> m_axesRatios;
00449
00450
00451
00452 String m_dateFormat;
00453 String m_relativeDateFormat;
00454
00455
00456
00457 ExternalAxisWidget* axisWidget;
00458
00459
00460
00461 PlotCoordinate globalPosToPixelCoord(int x, int y);
00462 PlotCoordinate globalPosToPixelCoord(QMouseEvent* event) {
00463 return globalPosToPixelCoord(event->globalX(), event->globalY()); }
00464 PlotCoordinate globalPosToPixelCoord(QWheelEvent* event) {
00465 return globalPosToPixelCoord(event->globalX(), event->globalY()); }
00466
00467
00468
00469
00470
00471
00472
00473 static unsigned int axisIndex(PlotAxis a);
00474 static PlotAxis axisIndex(unsigned int i);
00475
00476
00477
00478 virtual int canvasWidth() const{
00479 return width();
00480 }
00481 virtual int canvasHeight() const {
00482 return height();
00483 }
00484
00485
00486 };
00487
00488 }
00489
00490 #endif
00491
00492 #endif