qlineseries.cpp
224 lines
| 4.1 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r349 | #include "qlineseries.h" | ||
Michal Klocek
|
r21 | |||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
Michal Klocek
|
r21 | |||
Michal Klocek
|
r331 | /*! | ||
Michal Klocek
|
r350 | \class QLineSeries | ||
\brief The QLineSeries class is used for making line charts. | ||||
Michal Klocek
|
r331 | |||
\mainclass | ||||
A line chart is used to show information as a series of data points | ||||
connected by straight lines. | ||||
\image linechart.png | ||||
Michal Klocek
|
r369 | Creating basic line chart is simple: | ||
\code | ||||
QLineSeries* series = new QLineSeries(); | ||||
series->add(0, 6); | ||||
series->add(2, 4); | ||||
... | ||||
chartView->addSeries(series); | ||||
\endcode | ||||
Michal Klocek
|
r331 | */ | ||
/*! | ||||
Michal Klocek
|
r360 | \fn virtual QSeriesType QLineSeries::type() const | ||
Michal Klocek
|
r331 | \brief Returns type of series. | ||
Michal Klocek
|
r360 | \sa QSeries, QSeriesType | ||
Michal Klocek
|
r331 | */ | ||
/*! | ||||
Michal Klocek
|
r350 | \fn QPen QLineSeries::pen() const | ||
Michal Klocek
|
r331 | \brief Returns the pen used to draw line for this series. | ||
\sa setPen() | ||||
*/ | ||||
/*! | ||||
Michal Klocek
|
r367 | \fn bool QLineSeries::pointsVisible() const | ||
Michal Klocek
|
r331 | \brief Returns if the points are drawn for this series. | ||
\sa setPointsVisible() | ||||
*/ | ||||
/*! | ||||
Michal Klocek
|
r389 | \fn void QLineSeries::pointReplaced(int index) | ||
Michal Klocek
|
r374 | \brief \internal \a index | ||
*/ | ||||
/*! | ||||
\fn void QLineSeries::pointAdded(int index) | ||||
\brief \internal \a index | ||||
*/ | ||||
/*! | ||||
\fn void QLineSeries::pointRemoved(int index) | ||||
Michal Klocek
|
r331 | \brief \internal \a index | ||
*/ | ||||
Michal Klocek
|
r392 | /*! | ||
\fn void QLineSeries::updated(int index) | ||||
\brief \internal | ||||
*/ | ||||
Michal Klocek
|
r331 | /*! | ||
Constructs empty series object which is a child of \a parent. | ||||
When series object is added to QChartView or QChart instance ownerships is transfered. | ||||
*/ | ||||
Michal Klocek
|
r360 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), | ||
Michal Klocek
|
r185 | m_pointsVisible(false) | ||
Michal Klocek
|
r21 | { | ||
} | ||||
Michal Klocek
|
r331 | /*! | ||
Destroys the object. Series added to QChartView or QChart instances are owned by those, | ||||
and are deleted when mentioned object are destroyed. | ||||
*/ | ||||
Michal Klocek
|
r349 | QLineSeries::~QLineSeries() | ||
Michal Klocek
|
r21 | { | ||
} | ||||
Michal Klocek
|
r331 | /*! | ||
Adds data point \a x \a y to the series. Points are connected with lines on the chart. | ||||
*/ | ||||
Michal Klocek
|
r349 | void QLineSeries::add(qreal x,qreal y) | ||
Michal Klocek
|
r21 | { | ||
Michal Klocek
|
r372 | Q_ASSERT(m_x.size() == m_y.size()); | ||
Michal Klocek
|
r21 | m_x<<x; | ||
m_y<<y; | ||||
Michal Klocek
|
r374 | emit pointAdded(m_x.size()-1); | ||
Michal Klocek
|
r131 | } | ||
Michal Klocek
|
r331 | /*! | ||
This is an overloaded function. | ||||
Adds data \a point to the series. Points are connected with lines on the chart. | ||||
*/ | ||||
Michal Klocek
|
r349 | void QLineSeries::add(const QPointF& point) | ||
Michal Klocek
|
r331 | { | ||
Michal Klocek
|
r374 | add(point.x(),point.y()); | ||
Michal Klocek
|
r331 | } | ||
/*! | ||||
Michal Klocek
|
r348 | Modifies \a y value for given \a x a value. | ||
Michal Klocek
|
r331 | */ | ||
Michal Klocek
|
r349 | void QLineSeries::replace(qreal x,qreal y) | ||
Michal Klocek
|
r131 | { | ||
Michal Klocek
|
r348 | int index = m_x.indexOf(x); | ||
Michal Klocek
|
r131 | m_x[index]=x; | ||
m_y[index]=y; | ||||
Michal Klocek
|
r389 | emit pointReplaced(index); | ||
Michal Klocek
|
r21 | } | ||
Michal Klocek
|
r331 | /*! | ||
This is an overloaded function. | ||||
Michal Klocek
|
r348 | Replaces current y value of for given \a point x value with \a point y value. | ||
Michal Klocek
|
r331 | */ | ||
Michal Klocek
|
r349 | void QLineSeries::replace(const QPointF& point) | ||
Michal Klocek
|
r331 | { | ||
Michal Klocek
|
r374 | replace(point.x(),point.y()); | ||
Michal Klocek
|
r331 | } | ||
Michal Klocek
|
r348 | /*! | ||
Removes current \a x and y value. | ||||
*/ | ||||
Michal Klocek
|
r349 | void QLineSeries::remove(qreal x) | ||
Michal Klocek
|
r348 | { | ||
Michal Klocek
|
r374 | int index = m_x.indexOf(x); | ||
m_x.remove(index); | ||||
m_y.remove(index); | ||||
emit pointRemoved(index); | ||||
Michal Klocek
|
r348 | } | ||
/*! | ||||
Michal Klocek
|
r351 | Removes current \a point x value. Note \a point y value is ignored. | ||
Michal Klocek
|
r348 | */ | ||
Michal Klocek
|
r349 | void QLineSeries::remove(const QPointF& point) | ||
Michal Klocek
|
r348 | { | ||
Michal Klocek
|
r374 | remove(point.x()); | ||
Michal Klocek
|
r348 | } | ||
Michal Klocek
|
r331 | |||
/*! | ||||
Clears all the data. | ||||
*/ | ||||
Michal Klocek
|
r349 | void QLineSeries::clear() | ||
Michal Klocek
|
r21 | { | ||
m_x.clear(); | ||||
m_y.clear(); | ||||
} | ||||
Michal Klocek
|
r331 | /*! | ||
\internal \a pos | ||||
*/ | ||||
Michal Klocek
|
r349 | qreal QLineSeries::x(int pos) const | ||
Michal Klocek
|
r21 | { | ||
return m_x.at(pos); | ||||
} | ||||
Michal Klocek
|
r331 | /*! | ||
\internal \a pos | ||||
*/ | ||||
Michal Klocek
|
r349 | qreal QLineSeries::y(int pos) const | ||
Michal Klocek
|
r21 | { | ||
return m_y.at(pos); | ||||
} | ||||
Michal Klocek
|
r331 | /*! | ||
Returns number of data points within series. | ||||
*/ | ||||
Michal Klocek
|
r349 | int QLineSeries::count() const | ||
Michal Klocek
|
r21 | { | ||
Q_ASSERT(m_x.size() == m_y.size()); | ||||
return m_x.size(); | ||||
} | ||||
Michal Klocek
|
r331 | /*! | ||
Sets \a pen used for drawing given series.. | ||||
*/ | ||||
Michal Klocek
|
r349 | void QLineSeries::setPen(const QPen& pen) | ||
Michal Klocek
|
r85 | { | ||
Michal Klocek
|
r392 | if(pen!=m_pen){ | ||
Michal Klocek
|
r85 | m_pen=pen; | ||
Michal Klocek
|
r392 | emit updated(); | ||
} | ||||
Michal Klocek
|
r85 | } | ||
Michal Klocek
|
r331 | /*! | ||
Sets if data points are \a visible and should be drawn on line. | ||||
*/ | ||||
Michal Klocek
|
r349 | void QLineSeries::setPointsVisible(bool visible) | ||
Michal Klocek
|
r331 | { | ||
Michal Klocek
|
r392 | if(m_pointsVisible!=visible){ | ||
Michal Klocek
|
r331 | m_pointsVisible=visible; | ||
Michal Klocek
|
r392 | emit updated(); | ||
} | ||||
Michal Klocek
|
r331 | } | ||
Michal Klocek
|
r349 | QDebug operator<< (QDebug debug, const QLineSeries series) | ||
Michal Klocek
|
r21 | { | ||
Q_ASSERT(series.m_x.size() == series.m_y.size()); | ||||
int size = series.m_x.size(); | ||||
for (int i=0;i<size;i++) { | ||||
debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; | ||||
} | ||||
return debug.space(); | ||||
} | ||||
Michal Klocek
|
r372 | /*! | ||
Stream operator for adding a data \a point to the series. | ||||
\sa add() | ||||
*/ | ||||
QLineSeries& QLineSeries::operator<< (const QPointF &point) | ||||
{ | ||||
add(point); | ||||
return *this; | ||||
} | ||||
Michal Klocek
|
r331 | |||
Michal Klocek
|
r349 | #include "moc_qlineseries.cpp" | ||
Michal Klocek
|
r131 | |||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||