00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef QWT_PLOT_H
00011 #define QWT_PLOT_H
00012
00013 #include <qframe.h>
00014 #include "qwt_global.h"
00015 #include "qwt_array.h"
00016 #include "qwt_grid.h"
00017 #include "qwt_autoscl.h"
00018 #include "qwt_scldraw.h"
00019 #include "qwt_symbol.h"
00020 #include "qwt_curve.h"
00021 #include "qwt_marker.h"
00022 #include "qwt_plot_printfilter.h"
00023 #include "qwt_plot_classes.h"
00024 #include "qwt_plot_dict.h"
00025
00026 class QLabel;
00027 class QwtPlotLayout;
00028 class QwtScale;
00029 class QwtLegend;
00030
00080 class QWT_EXPORT QwtPlot: public QFrame
00081 {
00082 friend class QwtPlotItem;
00083 friend class QwtPlotCanvas;
00084 friend class QwtPlotPrintFilter;
00085
00086 Q_OBJECT
00087
00088 Q_ENUMS( Axis )
00089
00090 Q_PROPERTY( QColor canvasBackground READ canvasBackground
00091 WRITE setCanvasBackground )
00092 Q_PROPERTY( int canvasLineWidth READ canvasLineWidth
00093 WRITE setCanvasLineWidth )
00094
00095 Q_PROPERTY( bool xBottomAxis READ xBottomAxisEnabled
00096 WRITE enableXBottomAxis )
00097 Q_PROPERTY( bool xTopAxis READ xTopAxisEnabled WRITE enableXTopAxis )
00098 Q_PROPERTY( bool yLeftAxis READ yLeftAxisEnabled WRITE enableYLeftAxis )
00099 Q_PROPERTY( bool yRightAxis READ yRightAxisEnabled WRITE enableYRightAxis )
00100
00101 Q_PROPERTY( int nCurves READ read_nCurves WRITE write_nCurves )
00102 Q_PROPERTY( int nMarker READ read_nMarker WRITE write_nMarker )
00103
00104 Q_PROPERTY( QString title READ title WRITE setTitle )
00105 Q_PROPERTY( QFont titleFont READ titleFont WRITE setTitleFont )
00106
00107 public:
00109 enum Axis { yLeft, yRight, xBottom, xTop, axisCnt };
00110
00111 QwtPlot(QWidget *p = 0, const char *name = 0);
00112 QwtPlot(const QString &title, QWidget *p = 0, const char *name = 0);
00113 virtual ~QwtPlot();
00114
00115 void write_nCurves(int n) { nCurves = n; }
00116 void write_nMarker(int n) { nMarker = n; }
00117 int read_nCurves() const { return nCurves; };
00118 int read_nMarker() const { return nMarker; };
00119
00120 void enableXBottomAxis(bool b) {enableAxis(xBottom,b);}
00121 bool xBottomAxisEnabled() const {return axisEnabled(xBottom);};
00122 void enableXTopAxis(bool b) {enableAxis(xTop,b);}
00123 bool xTopAxisEnabled() const {return axisEnabled(xTop);};
00124 void enableYRightAxis(bool b) {enableAxis(yRight,b);}
00125 bool yRightAxisEnabled() const {return axisEnabled(yRight);};
00126 void enableYLeftAxis(bool b) {enableAxis(yLeft,b);}
00127 bool yLeftAxisEnabled() const {return axisEnabled(yLeft);};
00128
00129 void setAutoReplot(bool tf = TRUE);
00130 bool autoReplot() const;
00131
00132 void print(QPaintDevice &p,
00133 const QwtPlotPrintFilter & = QwtPlotPrintFilter()) const;
00134 virtual void print(QPainter *, const QRect &rect,
00135 const QwtPlotPrintFilter & = QwtPlotPrintFilter()) const;
00136
00137 void clear();
00138
00139
00140
00141 void enableOutline(bool tf);
00142 bool outlineEnabled() const;
00143 void setOutlineStyle(Qwt::Shape os);
00144 Qwt::Shape outlineStyle() const;
00145 void setOutlinePen(const QPen &pn);
00146 const QPen& outlinePen() const;
00147
00148
00149
00150 QwtPlotLayout *plotLayout();
00151 const QwtPlotLayout *plotLayout() const;
00152
00153 void setMargin(int margin);
00154 int margin() const;
00155
00156
00157
00158 void setTitle(const QString &t);
00159 QString title() const;
00160 void setTitleFont (const QFont &f);
00161 QFont titleFont() const;
00162
00163 QLabel *titleLabel();
00164 const QLabel *titleLabel() const;
00165
00166
00167
00168 QwtPlotCanvas *canvas();
00169 const QwtPlotCanvas *canvas() const;
00170
00171 void setCanvasBackground (const QColor &c);
00172 const QColor& canvasBackground() const;
00173
00174 void setCanvasLineWidth(int w);
00175 int canvasLineWidth() const;
00176
00177 QwtPlotCurveIterator curveIterator() const;
00178 QwtPlotMarkerIterator markerIterator() const;
00179
00180 QwtDiMap canvasMap(int axis) const;
00181
00182 double invTransform(int axis, int pos) const;
00183 int transform(int axis, double value) const;
00184
00185
00186
00187 long insertCurve(QwtPlotCurve *);
00188 long insertCurve(const QString &title,
00189 int xAxis = xBottom, int yAxis = yLeft);
00190
00191 QwtPlotCurve *curve(long key);
00192 const QwtPlotCurve *curve(long key) const;
00193
00194 bool removeCurve(long key);
00195 void removeCurves();
00196
00197 QwtArray<long> curveKeys() const;
00198
00199 long closestCurve(int xpos, int ypos, int &dist) const;
00200 long closestCurve(int xpos, int ypos, int &dist,
00201 double &xval, double &yval, int &index) const;
00202
00203 bool setCurveBaseline(long key, double ref);
00204 double curveBaseline(long key) const;
00205
00206 bool setCurveData(long key, const double *x, const double *y, int size);
00207 bool setCurveRawData(long key, const double *x, const double *y, int size);
00208
00209 bool setCurveOptions(long key, int t);
00210 int curveOptions(long key) const;
00211
00212 bool setCurvePen(long key, const QPen &pen);
00213 QPen curvePen(long key) const;
00214
00215 bool setCurveBrush(long key, const QBrush &brush);
00216 QBrush curveBrush(long key) const;
00217
00218 bool setCurveSplineSize(long key, int s);
00219 int curveSplineSize(long key) const;
00220
00221 bool setCurveStyle(long key, int s, int options = 0);
00222 int curveStyle(long key) const;
00223
00224 bool setCurveSymbol(long key, const QwtSymbol &s);
00225 QwtSymbol curveSymbol(long key) const;
00226
00227 bool setCurveTitle(long key, const QString &s);
00228 QString curveTitle(long key) const;
00229
00230 bool setCurveXAxis(long key, int axis);
00231 int curveXAxis(long key) const;
00232 bool setCurveYAxis(long key, int axis);
00233 int curveYAxis(long key) const;
00234
00235 void drawCurve(long key, int from, int to);
00236
00237
00238
00239 void enableGridX(bool tf = TRUE);
00240 void enableGridXMin(bool tf = TRUE);
00241 void enableGridY(bool tf = TRUE);
00242 void enableGridYMin(bool tf = TRUE);
00243
00244 void setGridXAxis(int axis);
00245 int gridXAxis() const;
00246 void setGridYAxis(int axis);
00247 int gridYAxis() const;
00248
00249 void setGridPen(const QPen &p);
00250 void setGridMajPen(const QPen &p);
00251 const QPen& gridMajPen() const;
00252 void setGridMinPen(const QPen &p);
00253 const QPen& gridMinPen() const;
00254
00255 QwtPlotGrid &grid();
00256 const QwtPlotGrid &grid() const;
00257
00258
00259
00260 void setAxisAutoScale(int axis);
00261 bool axisAutoScale(int axis) const;
00262
00263 void enableAxis(int axis, bool tf = TRUE);
00264 bool axisEnabled(int axis) const;
00265
00266 void changeAxisOptions(int axis, int opt, bool value);
00267 void setAxisOptions(int axis, int opt);
00268 int axisOptions(int axis) const;
00269
00270 void setAxisFont(int axis, const QFont &f);
00271 QFont axisFont(int axis) const;
00272
00273 void setAxisMargins(int axis, double mlo, double mhi);
00274 bool axisMargins(int axis, double &mlo, double &mhi) const;
00275
00276 void setAxisScale(int axis, double min, double max, double step = 0);
00277 void setAxisScaleDraw(int axis, QwtScaleDraw *);
00278 const QwtScaleDiv *axisScale(int axis) const;
00279 const QwtScaleDraw *axisScaleDraw(int axis) const;
00280 const QwtScale *axis(int axis) const;
00281
00282 void setAxisLabelFormat(int axis, char f, int prec, int fieldwidth = 0);
00283 void axisLabelFormat(int axis, char &f, int &prec, int &fieldwidth) const;
00284
00285 void setAxisLabelAlignment(int axis, int alignment);
00286 void setAxisLabelRotation(int axis, double rotation);
00287
00288 void setAxisTitle(int axis, const QString &t);
00289 const QString& axisTitle(int axis) const;
00290 void setAxisTitleFont(int axis, const QFont &f);
00291 QFont axisTitleFont(int axis) const;
00292 void setAxisTitleAlignment(int axis, int align);
00293 int axisTitleAlignment(int axis) const;
00294
00295 void setAxisMaxMinor(int axis, int maxMinor);
00296 int axisMaxMajor(int axis) const;
00297 void setAxisMaxMajor(int axis, int maxMajor);
00298 int axisMaxMinor(int axis) const;
00299
00300 void setAxisReference(int axis, double value);
00301 double axisReference(int axis) const;
00302
00303
00304
00305 long insertMarker(QwtPlotMarker *);
00306 long insertMarker(const QString &label = QString::null,
00307 int xAxis = xBottom, int yAxis = yLeft);
00308 long insertLineMarker(const QString &label, int axis);
00309
00310 QwtPlotMarker *marker(long key);
00311 const QwtPlotMarker *marker(long key) const;
00312
00313 bool removeMarker(long key);
00314 void removeMarkers();
00315
00316 long closestMarker(int xpos, int ypos, int &dist) const;
00317 QwtArray<long> markerKeys() const;
00318
00319 bool setMarkerXAxis(long key, int axis);
00320 int markerXAxis(long key) const;
00321 bool setMarkerYAxis(long key, int axis);
00322 int markerYAxis(long key) const;
00323
00324 bool setMarkerPos(long key, double xval, double yVal);
00325 bool setMarkerXPos(long key, double val);
00326 bool setMarkerYPos(long key, double val);
00327 void markerPos(long key, double &mx, double &my) const;
00328
00329 bool setMarkerFont(long key, const QFont &f);
00330 QFont markerFont(long key) const;
00331 bool setMarkerPen(long key, const QPen &p);
00332
00333 bool setMarkerLabel(long key, const QString &txt);
00334 const QString& markerLabel(long key) const;
00335 bool setMarkerLabelAlign(long key, int align);
00336 int markerLabelAlign(long key) const;
00337 bool setMarkerLabelPen(long key, const QPen &p);
00338 QPen markerLabelPen(long key) const;
00339
00340 bool setMarkerLinePen(long key, const QPen &p);
00341 QPen markerLinePen(long key) const;
00342 bool setMarkerLineStyle(long key, QwtMarker::LineStyle st);
00343 QwtMarker::LineStyle markerLineStyle(long key) const;
00344
00345 bool setMarkerSymbol(long key, const QwtSymbol &s);
00346 QwtSymbol markerSymbol(long key) const;
00347
00348
00349
00350 void setAutoLegend(bool enabled);
00351 bool autoLegend() const;
00352
00353 void enableLegend(bool tf, long curveKey = -1);
00354 bool legendEnabled(long curveKey) const;
00355
00356 void setLegendPos(int pos, double ratio = 0.0);
00357 int legendPos() const;
00358
00359 void setLegendFont(const QFont &f);
00360 const QFont legendFont() const;
00361
00362 void setLegendFrameStyle(int st);
00363 int legendFrameStyle() const;
00364
00365 QwtLegend *legend();
00366 const QwtLegend *legend() const;
00367
00368 void setLegendDisplayPolicy(int policy, int mode = -1);
00369
00370
00371 virtual QSize sizeHint() const;
00372 virtual QSize minimumSizeHint() const;
00373 virtual QSizePolicy sizePolicy() const;
00374
00375 virtual bool event(QEvent *);
00376
00377 public slots:
00378 virtual void replot();
00379
00380 protected slots:
00381 virtual void lgdClicked();
00382
00383 signals:
00392 void plotMousePressed(const QMouseEvent &e);
00393
00403 void plotMouseReleased(const QMouseEvent &e);
00404
00413 void plotMouseMoved(const QMouseEvent &e);
00414
00421 void legendClicked(long key);
00422
00423 protected:
00424 void autoRefresh();
00425 static bool axisValid(int axis);
00426
00427 virtual void drawCanvas(QPainter *);
00428 virtual void drawCanvasItems(QPainter *, const QRect &,
00429 const QwtDiMap map[], const QwtPlotPrintFilter &) const;
00430 virtual void drawContents( QPainter* p );
00431
00432 virtual void updateTabOrder();
00433
00434 void updateAxes();
00435 void updateLayout();
00436
00437 virtual void resizeEvent(QResizeEvent *e);
00438
00439 virtual void insertLegendItem(long curveKey);
00440 virtual void updateLegendItem(long curveKey);
00441 virtual void printLegendItem(QPainter *,
00442 const QWidget *, const QRect &) const;
00443
00444 virtual void printTitle(QPainter *, const QRect &) const;
00445 virtual void printScale(QPainter *, int axis, int startDist, int endDist,
00446 int baseDist, const QRect &) const;
00447 virtual void printCanvas(QPainter *, const QwtDiMap map[], const QRect &,
00448 const QwtPlotPrintFilter &) const;
00449 virtual void printLegend(QPainter *, const QRect &) const;
00450
00451 private:
00452 void initAxes();
00453 long newCurveKey();
00454 long newMarkerKey();
00455 void initPlot(const QString &title = QString::null);
00456
00457 QLabel *d_lblTitle;
00458 QwtPlotCanvas *d_canvas;
00459 QwtLegend *d_legend;
00460 QwtPlotLayout *d_layout;
00461
00462 bool d_axisEnabled[axisCnt];
00463 QwtScale *d_scale[axisCnt];
00464 QwtAutoScale d_as[axisCnt];
00465 QwtScaleDiv d_sdiv[axisCnt];
00466
00467 QwtCurveDict *d_curves;
00468 QwtMarkerDict *d_markers;
00469 QwtPlotGrid *d_grid;
00470
00471 bool d_autoReplot;
00472 bool d_autoLegend;
00473
00474 int nCurves;
00475 int nMarker;
00476 };
00477
00478 #endif