You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
251 lines
6.6 KiB
251 lines
6.6 KiB
15 years ago
|
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
||
|
* Qwt Widget Library
|
||
|
* Copyright (C) 1997 Josef Wilgen
|
||
|
* Copyright (C) 2002 Uwe Rathmann
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the Qwt License, Version 1.0
|
||
|
*****************************************************************************/
|
||
|
|
||
|
#ifndef QWT_PLOT_CURVE_H
|
||
|
#define QWT_PLOT_CURVE_H
|
||
|
|
||
|
#include <qpen.h>
|
||
|
#include <qstring.h>
|
||
|
#include "qwt_global.h"
|
||
|
#include "qwt_plot_item.h"
|
||
|
#include "qwt_text.h"
|
||
|
#include "qwt_polygon.h"
|
||
|
#include "qwt_data.h"
|
||
|
|
||
|
class QPainter;
|
||
|
class QwtScaleMap;
|
||
|
class QwtSymbol;
|
||
|
class QwtCurveFitter;
|
||
|
|
||
|
/*!
|
||
|
\brief A class which draws curves
|
||
|
|
||
|
This class can be used to display data as a curve in the x-y plane.
|
||
|
It supports different display styles, spline interpolation and symbols.
|
||
|
|
||
|
\par Usage
|
||
|
<dl><dt>A. Assign curve properties</dt>
|
||
|
<dd>When a curve is created, it is configured to draw black solid lines
|
||
14 years ago
|
with QwtPlotCurve::Lines and no symbols. You can change this by calling
|
||
15 years ago
|
setPen(), setStyle() and setSymbol().</dd>
|
||
|
<dt>B. Assign or change data.</dt>
|
||
|
<dd>Data can be set in two ways:<ul>
|
||
|
<li>setData() is overloaded to initialize the x and y data by
|
||
|
copying from different data structures with different kind of copy semantics.
|
||
|
<li>setRawData() only stores the pointers and size information
|
||
|
and is provided for backwards compatibility. This function is less safe (you
|
||
|
must not delete the data while they are attached), but has been more
|
||
|
efficient, and has been more convenient for dynamically changing data.
|
||
|
Use of setData() in combination with a problem-specific subclass
|
||
|
of QwtData is always preferrable.</ul></dd>
|
||
|
<dt>C. Draw</dt>
|
||
|
<dd>draw() maps the data into pixel coordinates and paints them.
|
||
|
</dd></dl>
|
||
|
|
||
|
\par Example:
|
||
|
see examples/curvdemo
|
||
|
|
||
|
\sa QwtData, QwtSymbol, QwtScaleMap
|
||
|
*/
|
||
|
class QWT_EXPORT QwtPlotCurve: public QwtPlotItem
|
||
|
{
|
||
|
public:
|
||
14 years ago
|
enum CurveType {
|
||
15 years ago
|
Yfx,
|
||
|
Xfy
|
||
|
};
|
||
|
|
||
14 years ago
|
/*!
|
||
|
Curve styles.
|
||
15 years ago
|
\sa setStyle
|
||
|
*/
|
||
14 years ago
|
enum CurveStyle {
|
||
15 years ago
|
NoCurve,
|
||
|
|
||
|
Lines,
|
||
|
Sticks,
|
||
|
Steps,
|
||
|
Dots,
|
||
|
|
||
|
UserCurve = 100
|
||
|
};
|
||
|
|
||
14 years ago
|
/*!
|
||
|
Curve attributes.
|
||
15 years ago
|
\sa setCurveAttribute, testCurveAttribute
|
||
|
*/
|
||
14 years ago
|
enum CurveAttribute {
|
||
15 years ago
|
Inverted = 1,
|
||
|
Fitted = 2
|
||
|
};
|
||
|
|
||
14 years ago
|
/*!
|
||
|
Paint attributes
|
||
15 years ago
|
\sa setPaintAttribute, testPaintAttribute
|
||
|
*/
|
||
14 years ago
|
enum PaintAttribute {
|
||
15 years ago
|
PaintFiltered = 1,
|
||
|
ClipPolygons = 2
|
||
|
};
|
||
|
|
||
|
explicit QwtPlotCurve();
|
||
|
explicit QwtPlotCurve(const QwtText &title);
|
||
|
explicit QwtPlotCurve(const QString &title);
|
||
|
|
||
|
virtual ~QwtPlotCurve();
|
||
|
|
||
|
virtual int rtti() const;
|
||
|
|
||
|
void setCurveType(CurveType);
|
||
|
CurveType curveType() const;
|
||
|
|
||
|
void setPaintAttribute(PaintAttribute, bool on = true);
|
||
|
bool testPaintAttribute(PaintAttribute) const;
|
||
|
|
||
|
void setRawData(const double *x, const double *y, int size);
|
||
|
void setData(const double *xData, const double *yData, int size);
|
||
|
void setData(const QwtArray<double> &xData, const QwtArray<double> &yData);
|
||
|
#if QT_VERSION < 0x040000
|
||
|
void setData(const QwtArray<QwtDoublePoint> &data);
|
||
|
#else
|
||
|
void setData(const QPolygonF &data);
|
||
|
#endif
|
||
|
void setData(const QwtData &data);
|
||
14 years ago
|
|
||
15 years ago
|
int closestPoint(const QPoint &pos, double *dist = NULL) const;
|
||
|
|
||
|
QwtData &data();
|
||
|
const QwtData &data() const;
|
||
|
|
||
|
int dataSize() const;
|
||
|
inline double x(int i) const;
|
||
|
inline double y(int i) const;
|
||
|
|
||
|
virtual QwtDoubleRect boundingRect() const;
|
||
|
|
||
|
//! boundingRect().left()
|
||
14 years ago
|
inline double minXValue() const {
|
||
|
return boundingRect().left();
|
||
|
}
|
||
15 years ago
|
//! boundingRect().right()
|
||
14 years ago
|
inline double maxXValue() const {
|
||
|
return boundingRect().right();
|
||
|
}
|
||
15 years ago
|
//! boundingRect().top()
|
||
14 years ago
|
inline double minYValue() const {
|
||
|
return boundingRect().top();
|
||
|
}
|
||
15 years ago
|
//! boundingRect().bottom()
|
||
14 years ago
|
inline double maxYValue() const {
|
||
|
return boundingRect().bottom();
|
||
|
}
|
||
15 years ago
|
|
||
|
void setCurveAttribute(CurveAttribute, bool on = true);
|
||
|
bool testCurveAttribute(CurveAttribute) const;
|
||
|
|
||
|
void setPen(const QPen &);
|
||
|
const QPen &pen() const;
|
||
|
|
||
|
void setBrush(const QBrush &);
|
||
|
const QBrush &brush() const;
|
||
|
|
||
|
void setBaseline(double ref);
|
||
|
double baseline() const;
|
||
|
|
||
|
void setStyle(CurveStyle style);
|
||
|
CurveStyle style() const;
|
||
|
|
||
|
void setSymbol(const QwtSymbol &s);
|
||
|
const QwtSymbol& symbol() const;
|
||
|
|
||
|
void setCurveFitter(QwtCurveFitter *);
|
||
|
QwtCurveFitter *curveFitter() const;
|
||
|
|
||
14 years ago
|
virtual void draw(QPainter *p,
|
||
|
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
||
|
const QRect &) const;
|
||
15 years ago
|
|
||
14 years ago
|
virtual void draw(QPainter *p,
|
||
|
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
||
|
int from, int to) const;
|
||
15 years ago
|
|
||
|
void draw(int from, int to) const;
|
||
|
|
||
|
virtual void updateLegend(QwtLegend *) const;
|
||
|
|
||
|
protected:
|
||
|
|
||
|
void init();
|
||
|
|
||
|
virtual void drawCurve(QPainter *p, int style,
|
||
14 years ago
|
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
||
|
int from, int to) const;
|
||
15 years ago
|
|
||
|
virtual void drawSymbols(QPainter *p, const QwtSymbol &,
|
||
14 years ago
|
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
||
|
int from, int to) const;
|
||
15 years ago
|
|
||
|
void drawLines(QPainter *p,
|
||
14 years ago
|
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
||
|
int from, int to) const;
|
||
15 years ago
|
void drawSticks(QPainter *p,
|
||
14 years ago
|
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
||
|
int from, int to) const;
|
||
15 years ago
|
void drawDots(QPainter *p,
|
||
14 years ago
|
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
||
|
int from, int to) const;
|
||
15 years ago
|
void drawSteps(QPainter *p,
|
||
14 years ago
|
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
||
|
int from, int to) const;
|
||
15 years ago
|
|
||
|
void fillCurve(QPainter *,
|
||
14 years ago
|
const QwtScaleMap &, const QwtScaleMap &,
|
||
|
QwtPolygon &) const;
|
||
15 years ago
|
void closePolyline(const QwtScaleMap &, const QwtScaleMap &,
|
||
14 years ago
|
QwtPolygon &) const;
|
||
15 years ago
|
|
||
|
private:
|
||
|
QwtData *d_xy;
|
||
|
|
||
|
class PrivateData;
|
||
|
PrivateData *d_data;
|
||
|
};
|
||
|
|
||
|
//! \return the the curve data
|
||
|
inline QwtData &QwtPlotCurve::data()
|
||
|
{
|
||
|
return *d_xy;
|
||
|
}
|
||
|
|
||
|
//! \return the the curve data
|
||
|
inline const QwtData &QwtPlotCurve::data() const
|
||
|
{
|
||
|
return *d_xy;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\param i index
|
||
|
\return x-value at position i
|
||
|
*/
|
||
14 years ago
|
inline double QwtPlotCurve::x(int i) const
|
||
|
{
|
||
|
return d_xy->x(i);
|
||
15 years ago
|
}
|
||
|
|
||
|
/*!
|
||
|
\param i index
|
||
|
\return y-value at position i
|
||
|
*/
|
||
14 years ago
|
inline double QwtPlotCurve::y(int i) const
|
||
|
{
|
||
|
return d_xy->y(i);
|
||
15 years ago
|
}
|
||
|
|
||
|
#endif
|