Newer
Older
const QwtSeriesData<QPointF> *series = data();
const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
for ( uint i = 0; i < numSamples; i++ )
{
const QPointF sample = series->sample( i );
const double cx = xMap.transform( sample.x() ) - pos.x();
const double cy = yMap.transform( sample.y() ) - pos.y();
const double f = qwtSqr( cx ) + qwtSqr( cy );
if ( f < dmin )
{
\param index Index of the legend entry
( ignored as there is only one )
\param size Icon size
\sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
*/
QwtGraphic QwtPlotCurve::legendIcon( int index,
const QSizeF &size ) const
{
Q_UNUSED( index );
QwtGraphic graphic;
graphic.setDefaultSize( size );
graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true );
QPainter painter( &graphic );
painter.setRenderHint( QPainter::Antialiasing,
testRenderHint( QwtPlotItem::RenderAntialiased ) );
if ( d_data->legendAttributes == 0 ||
d_data->legendAttributes & QwtPlotCurve::LegendShowBrush )
{
QBrush brush = d_data->brush;
if ( brush.style() == Qt::NoBrush &&
d_data->legendAttributes == 0 )
{
if ( style() != QwtPlotCurve::NoCurve )
{
brush = QBrush( pen().color() );
}
else if ( d_data->symbol &&
( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
{
brush = QBrush( d_data->symbol->pen().color() );
}
}
if ( brush.style() != Qt::NoBrush )
{
QRectF r( 0, 0, size.width(), size.height() );
painter.fillRect( r, brush );
}
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine )
{
if ( pen() != Qt::NoPen )
{
QPen pn = pen();
pn.setCapStyle( Qt::FlatCap );
const double y = 0.5 * size.height();
QwtPainter::drawLine( &painter, 0.0, y, size.width(), y );
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
{
if ( d_data->symbol )
{
QRectF r( 0, 0, size.width(), size.height() );
d_data->symbol->drawSymbol( &painter, r );
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
return graphic;
}
/*!
Initialize data with an array of points.
\param samples Vector of points
\note QVector is implicitly shared
\note QPolygonF is derived from QVector<QPointF>
*/
void QwtPlotCurve::setSamples( const QVector<QPointF> &samples )
{
setData( new QwtPointSeriesData( samples ) );
}
/*!
Assign a series of points
setSamples() is just a wrapper for setData() without any additional
value - beside that it is easier to find for the developer.
\param data Data
\warning The item takes ownership of the data object, deleting
it when its not used anymore.
*/
void QwtPlotCurve::setSamples( QwtSeriesData<QPointF> *data )
{
setData( data );
}
#ifndef QWT_NO_COMPAT
/*!
\brief Initialize the data by pointing to memory blocks which
are not managed by QwtPlotCurve.
setRawSamples is provided for efficiency.
It is important to keep the pointers
during the lifetime of the underlying QwtCPointerData class.
\param xData pointer to x data
\param yData pointer to y data
\param size size of x and y
\sa QwtCPointerData
*/
void QwtPlotCurve::setRawSamples(
const double *xData, const double *yData, int size )
{
setData( new QwtCPointerData( xData, yData, size ) );
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
/*!
Set data by copying x- and y-values from specified memory blocks.
Contrary to setRawSamples(), this function makes a 'deep copy' of
the data.
\param xData pointer to x values
\param yData pointer to y values
\param size size of xData and yData
\sa QwtPointArrayData
*/
void QwtPlotCurve::setSamples(
const double *xData, const double *yData, int size )
{
setData( new QwtPointArrayData( xData, yData, size ) );
}
/*!
\brief Initialize data with x- and y-arrays (explicitly shared)
\param xData x data
\param yData y data
\sa QwtPointArrayData
*/
void QwtPlotCurve::setSamples( const QVector<double> &xData,
const QVector<double> &yData )
{
setData( new QwtPointArrayData( xData, yData ) );
}
#endif // !QWT_NO_COMPAT