Newer
Older
}
polyline = ::clipPolygon(painter, d_data->paintAttributes, polyline);
QwtPainter::drawPolyline(painter, polyline);
if ( d_data->brush.style() != Qt::NoBrush )
fillCurve(painter, xMap, yMap, polyline);
}
/*!
\brief Specify an attribute for drawing the curve
The attributes can be used to modify the drawing style.
The following attributes are defined:<dl>
<dt>Fitted</dt>
<dd>For Lines only. A QwtCurveFitter tries to
interpolate/smooth the curve, before it is painted.
Note that curve fitting requires temorary memory
for calculating coefficients and additional points.
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
If painting in Fitted mode is slow it might be better
to fit the points, before they are passed to QwtPlotCurve.
</dd>
<dt>Inverted</dt>
<dd>For Steps only. Draws a step function
from the right to the left.</dd></dl>
\param attribute Curve attribute
\param on On/Off
/sa testCurveAttribute(), setCurveFitter()
*/
void QwtPlotCurve::setCurveAttribute(CurveAttribute attribute, bool on)
{
if ( bool(d_data->attributes & attribute) == on )
return;
if ( on )
d_data->attributes |= attribute;
else
d_data->attributes &= ~attribute;
itemChanged();
}
/*!
\return true, if attribute is enabled
\sa setCurveAttribute()
*/
bool QwtPlotCurve::testCurveAttribute(CurveAttribute attribute) const
{
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
return d_data->attributes & attribute;
}
/*!
Assign the curve type
<dt>QwtPlotCurve::Yfx
<dd>Draws y as a function of x (the default). The
baseline is interpreted as a horizontal line
with y = baseline().</dd>
<dt>QwtPlotCurve::Xfy
<dd>Draws x as a function of y. The baseline is
interpreted as a vertical line with x = baseline().</dd>
The baseline is used for aligning the sticks, or
filling the curve with a brush.
\sa curveType()
*/
void QwtPlotCurve::setCurveType(CurveType curveType)
{
if ( d_data->curveType != curveType ) {
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
d_data->curveType = curveType;
itemChanged();
}
}
/*!
Return the curve type
\sa setCurveType()
*/
QwtPlotCurve::CurveType QwtPlotCurve::curveType() const
{
return d_data->curveType;
}
void QwtPlotCurve::setCurveFitter(QwtCurveFitter *curveFitter)
{
delete d_data->curveFitter;
d_data->curveFitter = curveFitter;
itemChanged();
}
QwtCurveFitter *QwtPlotCurve::curveFitter() const
{
return d_data->curveFitter;
}
/*!
Fill the area between the curve and the baseline with
the curve brush
\param painter Painter
\param xMap x map
\param yMap y map
\param pa Polygon
\sa setBrush(), setBaseline(), setCurveType()
*/
void QwtPlotCurve::fillCurve(QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
QwtPolygon &pa) const
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
{
if ( d_data->brush.style() == Qt::NoBrush )
return;
closePolyline(xMap, yMap, pa);
if ( pa.count() <= 2 ) // a line can't be filled
return;
QBrush b = d_data->brush;
if ( !b.color().isValid() )
b.setColor(d_data->pen.color());
painter->save();
painter->setPen(QPen(Qt::NoPen));
painter->setBrush(b);
QwtPainter::drawPolygon(painter, pa);
painter->restore();
}
/*!
\brief Complete a polygon to be a closed polygon
including the area between the original polygon
and the baseline.
\param xMap X map
\param yMap Y map
\param pa Polygon to be completed
*/
void QwtPlotCurve::closePolyline(
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
QwtPolygon &pa) const
{
const int sz = pa.size();
if ( sz < 2 )
return;
pa.resize(sz + 2);
if ( d_data->curveType == QwtPlotCurve::Xfy ) {
xMap.transform(d_data->reference), pa.point(sz - 1).y());
xMap.transform(d_data->reference), pa.point(0).y());
} else {
pa.point(sz - 1).x(), yMap.transform(d_data->reference));
pa.point(0).x(), yMap.transform(d_data->reference));
}
}
/*!
\brief Draw symbols
\param painter Painter
\param symbol Curve symbol
\param xMap x map
\param yMap y map
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa setSymbol(), draw(), drawCurve()
*/
void QwtPlotCurve::drawSymbols(QPainter *painter, const QwtSymbol &symbol,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
int from, int to) const
{
painter->setBrush(symbol.brush());
const QwtMetricsMap &metricsMap = QwtPainter::metricsMap();
QPen pen = symbol.pen();
#if SCALE_PEN
if ( pen.width() > 0 )
pen.setWidth(metricsMap.screenToLayoutX(pen.width()));
#endif
painter->setPen(pen);
QRect rect;
rect.setSize(metricsMap.screenToLayout(symbol.size()));
if ( to > from && d_data->paintAttributes & PaintFiltered ) {
const QRect window = painter->window();
if ( window.isEmpty() )
return;
PrivateData::PixelMatrix pixelMatrix(window);
for (int i = from; i <= to; i++) {
if ( pixelMatrix.testPixel(pi) ) {
rect.moveCenter(pi);
symbol.draw(painter, rect);
}
}
} else {
for (int i = from; i <= to; i++) {
const int xi = xMap.transform(x(i));
const int yi = yMap.transform(y(i));
rect.moveCenter(QPoint(xi, yi));
symbol.draw(painter, rect);
}
}
}
/*!
\brief Set the value of the baseline
The baseline is needed for filling the curve with a brush or
The default value is 0.0. The interpretation
of the baseline depends on the CurveType. With QwtPlotCurve::Yfx,
the baseline is interpreted as a horizontal line at y = baseline(),
with QwtPlotCurve::Yfy, it is interpreted as a vertical line at
x = baseline().
\param reference baseline
\sa baseline(), setBrush(), setStyle(), setCurveType()
*/
void QwtPlotCurve::setBaseline(double reference)
{
if ( d_data->reference != reference ) {
d_data->reference = reference;
itemChanged();
}
}
/*!
Return the value of the baseline
\sa setBaseline
*/
double QwtPlotCurve::baseline() const
{
return d_data->reference;
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
}
/*!
Return the size of the data arrays
\sa setData()
*/
int QwtPlotCurve::dataSize() const
{
return d_xy->size();
}
int QwtPlotCurve::closestPoint(const QPoint &pos, double *dist) const
{
if ( plot() == NULL || dataSize() <= 0 )
return -1;
const QwtScaleMap xMap = plot()->canvasMap(xAxis());
const QwtScaleMap yMap = plot()->canvasMap(yAxis());
int index = -1;
double dmin = 1.0e10;
for (int i=0; i < dataSize(); i++) {
const double cx = xMap.xTransform(x(i)) - pos.x();
const double cy = yMap.xTransform(y(i)) - pos.y();
const double f = qwtSqr(cx) + qwtSqr(cy);
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
index = i;
dmin = f;
}
}
if ( dist )
*dist = sqrt(dmin);
return index;
}
//! Update the widget that represents the curve on the legend
void QwtPlotCurve::updateLegend(QwtLegend *legend) const
{
if ( !legend )
return;
QwtPlotItem::updateLegend(legend);
QWidget *widget = legend->find(this);
if ( !widget || !widget->inherits("QwtLegendItem") )
return;
QwtLegendItem *legendItem = (QwtLegendItem *)widget;
#if QT_VERSION < 0x040000
const bool doUpdate = legendItem->isUpdatesEnabled();
#else
const bool doUpdate = legendItem->updatesEnabled();
#endif
legendItem->setUpdatesEnabled(false);
const int policy = legend->displayPolicy();
if (policy == QwtLegend::FixedIdentifier) {
int mode = legend->identifierMode();
if (mode & QwtLegendItem::ShowLine)
legendItem->setCurvePen(pen());
if (mode & QwtLegendItem::ShowSymbol)
legendItem->setSymbol(symbol());
if (mode & QwtLegendItem::ShowText)
legendItem->setText(title());
else
legendItem->setText(QwtText());
legendItem->setIdentifierMode(mode);
} else if (policy == QwtLegend::AutoIdentifier) {
if (QwtPlotCurve::NoCurve != style()) {
legendItem->setCurvePen(pen());
mode |= QwtLegendItem::ShowLine;
}
if (QwtSymbol::NoSymbol != symbol().style()) {
legendItem->setSymbol(symbol());
mode |= QwtLegendItem::ShowSymbol;
}
legendItem->setText(title());
mode |= QwtLegendItem::ShowText;