/usr/include/qwt/qwt_series_data.h is in libqwt-dev 6.0.0-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | /* -*- 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_SERIES_DATA_H
#define QWT_SERIES_DATA_H 1
#include "qwt_global.h"
#include "qwt_interval.h"
#include "qwt_point_3d.h"
#include "qwt_point_polar.h"
#include <qvector.h>
#include <qrect.h>
//! \brief A sample of the types (x1-x2, y) or (x, y1-y2)
class QWT_EXPORT QwtIntervalSample
{
public:
QwtIntervalSample();
QwtIntervalSample( double, const QwtInterval & );
QwtIntervalSample( double value, double min, double max );
bool operator==( const QwtIntervalSample & ) const;
bool operator!=( const QwtIntervalSample & ) const;
//! Value
double value;
//! Interval
QwtInterval interval;
};
/*!
Constructor
The value is set to 0.0, the interval is invalid
*/
inline QwtIntervalSample::QwtIntervalSample():
value( 0.0 )
{
}
//! Constructor
inline QwtIntervalSample::QwtIntervalSample(
double v, const QwtInterval &intv ):
value( v ),
interval( intv )
{
}
//! Constructor
inline QwtIntervalSample::QwtIntervalSample(
double v, double min, double max ):
value( v ),
interval( min, max )
{
}
//! Compare operator
inline bool QwtIntervalSample::operator==(
const QwtIntervalSample &other ) const
{
return value == other.value && interval == other.interval;
}
//! Compare operator
inline bool QwtIntervalSample::operator!=(
const QwtIntervalSample &other ) const
{
return !( *this == other );
}
//! \brief A sample of the types (x1...xn, y) or (x, y1..yn)
class QWT_EXPORT QwtSetSample
{
public:
QwtSetSample();
bool operator==( const QwtSetSample &other ) const;
bool operator!=( const QwtSetSample &other ) const;
//! value
double value;
//! Vector of values associated to value
QVector<double> set;
};
/*!
Constructor
The value is set to 0.0
*/
inline QwtSetSample::QwtSetSample():
value( 0.0 )
{
}
//! Compare operator
inline bool QwtSetSample::operator==( const QwtSetSample &other ) const
{
return value == other.value && set == other.set;
}
//! Compare operator
inline bool QwtSetSample::operator!=( const QwtSetSample &other ) const
{
return !( *this == other );
}
/*!
\brief Abstract interface for iterating over samples
Qwt offers several implementations of the QwtSeriesData API,
but in situations, where data of an application specific format
needs to be displayed, without having to copy it, it is recommended
to implement an individual data access.
*/
template <typename T>
class QwtSeriesData
{
public:
QwtSeriesData();
virtual ~QwtSeriesData();
//! \return Number of samples
virtual size_t size() const = 0;
/*!
Return a sample
\param i Index
\return Sample at position i
*/
virtual T sample( size_t i ) const = 0;
/*!
Calculate the bounding rect of all samples
The bounding rect is necessary for autoscaling and can be used
for a couple of painting optimizations.
qwtBoundingRect(...) offers slow implementations iterating
over the samples. For large sets it is recommended to implement
something faster f.e. by caching the bounding rect.
*/
virtual QRectF boundingRect() const = 0;
virtual void setRectOfInterest( const QRectF & );
protected:
//! Can be used to cache a calculated bounding rectangle
mutable QRectF d_boundingRect;
private:
QwtSeriesData<T> &operator=( const QwtSeriesData<T> & );
};
//! Constructor
template <typename T>
QwtSeriesData<T>::QwtSeriesData():
d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
{
}
//! Destructor
template <typename T>
QwtSeriesData<T>::~QwtSeriesData()
{
}
/*!
Set a the "rect of interest"
QwtPlotSeriesItem defines the current area of the plot canvas
as "rect of interest" ( QwtPlotSeriesItem::updateScaleDiv() ).
It can be used to implement different levels of details.
The default implementation does nothing.
*/
template <typename T>
void QwtSeriesData<T>::setRectOfInterest( const QRectF & )
{
}
/*!
\brief Template class for data, that is organized as QVector
QVector uses implicit data sharing and can be
passed around as argument efficiently.
*/
template <typename T>
class QwtArraySeriesData: public QwtSeriesData<T>
{
public:
QwtArraySeriesData();
QwtArraySeriesData( const QVector<T> & );
void setSamples( const QVector<T> & );
const QVector<T> samples() const;
virtual size_t size() const;
virtual T sample( size_t ) const;
protected:
//! Vector of samples
QVector<T> d_samples;
};
//! Constructor
template <typename T>
QwtArraySeriesData<T>::QwtArraySeriesData()
{
}
/*!
Constructor
\param samples Array of samples
*/
template <typename T>
QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
d_samples( samples )
{
}
/*!
Assign an array of samples
\param samples Array of samples
*/
template <typename T>
void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
{
QwtSeriesData<T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
d_samples = samples;
}
//! \return Array of samples
template <typename T>
const QVector<T> QwtArraySeriesData<T>::samples() const
{
return d_samples;
}
//! \return Number of samples
template <typename T>
size_t QwtArraySeriesData<T>::size() const
{
return d_samples.size();
}
/*!
Return a sample
\param i Index
\return Sample at position i
*/
template <typename T>
T QwtArraySeriesData<T>::sample( size_t i ) const
{
return d_samples[i];
}
//! Interface for iterating over an array of points
class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF>
{
public:
QwtPointSeriesData(
const QVector<QPointF> & = QVector<QPointF>() );
virtual QRectF boundingRect() const;
};
//! Interface for iterating over an array of 3D points
class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D>
{
public:
QwtPoint3DSeriesData(
const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
virtual QRectF boundingRect() const;
};
//! Interface for iterating over an array of intervals
class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
{
public:
QwtIntervalSeriesData(
const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() );
virtual QRectF boundingRect() const;
};
//! Interface for iterating over an array of samples
class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample>
{
public:
QwtSetSeriesData(
const QVector<QwtSetSample> & = QVector<QwtSetSample>() );
virtual QRectF boundingRect() const;
};
/*!
\brief Interface for iterating over two QVector<double> objects.
*/
class QWT_EXPORT QwtPointArrayData: public QwtSeriesData<QPointF>
{
public:
QwtPointArrayData( const QVector<double> &x, const QVector<double> &y );
QwtPointArrayData( const double *x, const double *y, size_t size );
virtual QRectF boundingRect() const;
virtual size_t size() const;
virtual QPointF sample( size_t i ) const;
const QVector<double> &xData() const;
const QVector<double> &yData() const;
private:
QVector<double> d_x;
QVector<double> d_y;
};
/*!
\brief Data class containing two pointers to memory blocks of doubles.
*/
class QWT_EXPORT QwtCPointerData: public QwtSeriesData<QPointF>
{
public:
QwtCPointerData( const double *x, const double *y, size_t size );
virtual QRectF boundingRect() const;
virtual size_t size() const;
virtual QPointF sample( size_t i ) const;
const double *xData() const;
const double *yData() const;
private:
const double *d_x;
const double *d_y;
size_t d_size;
};
/*!
\brief Synthetic point data
QwtSyntheticPointData provides a fixed number of points for an interval.
The points are calculated in equidistant steps in x-direction.
If the interval is invalid, the points are calculated for
the "rect of interest", what normally is the displayed area on the
plot canvas. In this mode you get different levels of detail, when
zooming in/out.
\par Example
The following example shows how to implement a sinus curve.
\verbatim
#include <cmath>
#include <qwt_series_data.h>
#include <qwt_plot_curve.h>
#include <qwt_plot.h>
#include <qapplication.h>
class SinusData: public QwtSyntheticPointData
{
public:
SinusData():
QwtSyntheticPointData(100)
{
}
virtual double y(double x) const
{
return qSin(x);
}
};
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QwtPlot plot;
plot.setAxisScale(QwtPlot::xBottom, 0.0, 10.0);
plot.setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
QwtPlotCurve *curve = new QwtPlotCurve("y = sin(x)");
curve->setData(SinusData());
curve->attach(&plot);
plot.show();
return a.exec();
}
\endverbatim
*/
class QWT_EXPORT QwtSyntheticPointData: public QwtSeriesData<QPointF>
{
public:
QwtSyntheticPointData( size_t size,
const QwtInterval & = QwtInterval() );
void setSize( size_t size );
size_t size() const;
void setInterval( const QwtInterval& );
QwtInterval interval() const;
virtual QRectF boundingRect() const;
virtual QPointF sample( size_t i ) const;
/*!
Calculate a y value for a x value
\param x x value
\return Corresponding y value
*/
virtual double y( double x ) const = 0;
virtual double x( uint index ) const;
virtual void setRectOfInterest( const QRectF & );
QRectF rectOfInterest() const;
private:
size_t d_size;
QwtInterval d_interval;
QRectF d_rectOfInterest;
QwtInterval d_intervalOfInterest;
};
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QPointF> &, int from = 0, int to = -1 );
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 );
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 );
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 );
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
#endif
|