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