##// END OF EJS Templates
QML demo with dynamic data
QML demo with dynamic data

File last commit:

r1230:39fc8bad4e45
r1240:897a83c64309
Show More
xychart.cpp
216 lines | 6.1 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
Michal Klocek
Refactors animation handling for xyseries
r1217 **
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
Jani Honkonen
Add license headers
r794
Michal Klocek
Refactor xychartitem -> xychart
r1218 #include "xychart_p.h"
Michal Klocek
Add missing files from previous commit
r466 #include "qxyseries.h"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "qxyseries_p.h"
Michal Klocek
Add missing files from previous commit
r466 #include "chartpresenter_p.h"
Michal Klocek
Animation refactor...
r530 #include "chartanimator_p.h"
Michal Klocek
Add missing files from previous commit
r466 #include <QPainter>
Marek Rosa
QXYSeries: support for removing data from model when using custom mapping
r1055 #include <QAbstractItemModel>
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 #include "qxymodelmapper.h"
Michal Klocek
Add missing files from previous commit
r466
QTCOMMERCIALCHART_BEGIN_NAMESPACE
//TODO: optimize : remove points which are not visible
Michal Klocek
Refactor xychartitem -> xychart
r1218 XYChart::XYChart(QXYSeries *series, ChartPresenter *presenter):Chart(presenter),
Michal Klocek
Refactors animation handling for xyseries
r1217 m_minX(0),
m_maxX(0),
m_minY(0),
m_maxY(0),
m_series(series),
m_animation(0)
{
QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
QObject::connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
QObject::connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
QObject::connect(series->d_func(),SIGNAL(reinitialized()),this,SLOT(handleReinitialized()));
QObject::connect(this,SIGNAL(clicked(QPointF)),series,SIGNAL(clicked(QPointF)));
}
Michal Klocek
Refactor xychartitem -> xychart
r1218 void XYChart::setGeometryPoints(QVector<QPointF>& points)
Michal Klocek
Refactors animation handling for xyseries
r1217 {
m_points = points;
}
Michal Klocek
Refactor xychartitem -> xychart
r1218 void XYChart::setClipRect(const QRectF &rect)
Michal Klocek
Refactors animation handling for xyseries
r1217 {
m_clipRect = rect;
}
Michal Klocek
Refactor xychartitem -> xychart
r1218 void XYChart::setAnimation(XYAnimation* animation)
Michal Klocek
Add missing files from previous commit
r466 {
Michal Klocek
Refactors animation handling for xyseries
r1217 m_animation=animation;
Michal Klocek
Add missing files from previous commit
r466 }
Michal Klocek
Refactor xychartitem -> xychart
r1218 QPointF XYChart::calculateGeometryPoint(const QPointF &point) const
Michal Klocek
Add missing files from previous commit
r466 {
const qreal deltaX = m_size.width()/(m_maxX-m_minX);
const qreal deltaY = m_size.height()/(m_maxY-m_minY);
qreal x = (point.x() - m_minX)* deltaX;
qreal y = (point.y() - m_minY)*-deltaY + m_size.height();
return QPointF(x,y);
}
Michal Klocek
Refactor xychartitem -> xychart
r1218 QPointF XYChart::calculateGeometryPoint(int index) const
Michal Klocek
Add missing files from previous commit
r466 {
const qreal deltaX = m_size.width()/(m_maxX-m_minX);
const qreal deltaY = m_size.height()/(m_maxY-m_minY);
Michal Klocek
Fixes and improvments to series API...
r1057 const QList<QPointF>& vector = m_series->points();
qreal x = (vector[index].x() - m_minX)* deltaX;
qreal y = (vector[index].y() - m_minY)*-deltaY + m_size.height();
Michal Klocek
Add missing files from previous commit
r466 return QPointF(x,y);
}
Michal Klocek
Refactor xychartitem -> xychart
r1218 QVector<QPointF> XYChart::calculateGeometryPoints() const
Michal Klocek
Add missing files from previous commit
r466 {
const qreal deltaX = m_size.width()/(m_maxX-m_minX);
const qreal deltaY = m_size.height()/(m_maxY-m_minY);
Michal Klocek
Fixes and improvments to series API...
r1057 QVector<QPointF> result;
result.resize(m_series->count());
const QList<QPointF>& vector = m_series->points();
Michal Klocek
Add missing files from previous commit
r466 for (int i = 0; i < m_series->count(); ++i) {
Michal Klocek
Fixes and improvments to series API...
r1057 qreal x = (vector[i].x() - m_minX)* deltaX;
qreal y = (vector[i].y() - m_minY)*-deltaY + m_size.height();
result[i].setX(x);
result[i].setY(y);
Michal Klocek
Add missing files from previous commit
r466 }
Michal Klocek
Fixes and improvments to series API...
r1057 return result;
Michal Klocek
Add missing files from previous commit
r466 }
Michal Klocek
Refactor xychartitem -> xychart
r1218 QPointF XYChart::calculateDomainPoint(const QPointF &point) const
Michal Klocek
Adds clicked(Point) to lineSeries, changes visible points handling
r544 {
const qreal deltaX = m_size.width()/(m_maxX-m_minX);
const qreal deltaY = m_size.height()/(m_maxY-m_minY);
qreal x = point.x()/deltaX +m_minX;
qreal y = (point.y()-m_size.height())/(-deltaY)+ m_minY;
return QPointF(x,y);
}
Michal Klocek
Refactor xychartitem -> xychart
r1218 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
Michal Klocek
Add missing files from previous commit
r466 {
Michal Klocek
Refactors animation handling for xyseries
r1217 if (m_animation) {
m_animation->setValues(oldPoints, newPoints, index);
animator()->startAnimation(m_animation);
}
else {
setGeometryPoints(newPoints);
updateGeometry();
Michal Klocek
Animation refactor...
r530 }
Michal Klocek
Add missing files from previous commit
r466 }
//handlers
Michal Klocek
Refactor xychartitem -> xychart
r1218 void XYChart::handlePointAdded(int index)
Michal Klocek
Add missing files from previous commit
r466 {
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 Q_ASSERT(index<m_series->count());
Q_ASSERT(index>=0);
Marek Rosa
Removed unfinished model related methods from PieSeries
r1018 QVector<QPointF> points = m_points;
QPointF point;
Marek Rosa
Removed all the unfinished model functionality from XYSeries and BarSeries
r990 point = calculateGeometryPoint(index);
points.insert(index, point);
Michal Klocek
Refactors animation handling for xyseries
r1217
if(m_animation) {
m_animation->setAnimationType(XYAnimation::LineDrawAnimation);
}
updateChart(m_points,points,index);
Michal Klocek
Add missing files from previous commit
r466 }
Marek Rosa
QXYSeries: support for adding data to model when using custom mapping
r1054
Michal Klocek
Refactor xychartitem -> xychart
r1218 void XYChart::handlePointRemoved(int index)
Michal Klocek
Adds big fat pimpl to series classes...
r938 {
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 Q_ASSERT(index<m_series->count() + 1);
Q_ASSERT(index>=0);
Marek Rosa
Removed unfinished model related methods from PieSeries
r1018 QVector<QPointF> points = m_points;
Marek Rosa
Removed all the unfinished model functionality from XYSeries and BarSeries
r990 points.remove(index);
Michal Klocek
Refactors animation handling for xyseries
r1217
if(m_animation) {
m_animation->setAnimationType(XYAnimation::LineDrawAnimation);
}
updateChart(m_points,points,index);
Michal Klocek
Add missing files from previous commit
r466 }
Michal Klocek
Refactor xychartitem -> xychart
r1218 void XYChart::handlePointReplaced(int index)
Michal Klocek
Add missing files from previous commit
r466 {
Q_ASSERT(index<m_series->count());
Q_ASSERT(index>=0);
QPointF point = calculateGeometryPoint(index);
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 QVector<QPointF> points = m_points;
Marek Rosa
QXYSeries: model data orientation added. QBarSeries: some model data function placeholders
r527 points.replace(index,point);
Michal Klocek
Refactors animation handling for xyseries
r1217
if(m_animation) {
m_animation->setAnimationType(XYAnimation::MoveDownAnimation);
}
updateChart(m_points,points,index);
Michal Klocek
Add missing files from previous commit
r466 }
Michal Klocek
Refactor xychartitem -> xychart
r1218 void XYChart::handleReinitialized()
Marek Rosa
XYSeries model support refactored
r1085 {
QVector<QPointF> points = calculateGeometryPoints();
Michal Klocek
Refactors animation handling for xyseries
r1217
if(m_animation) {
m_animation->setAnimationType(XYAnimation::LineDrawAnimation);
}
updateChart(m_points,points);
Marek Rosa
XYSeries model support refactored
r1085 }
Michal Klocek
Refactor xychartitem -> xychart
r1218 void XYChart::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
Michal Klocek
Add missing files from previous commit
r466 {
m_minX=minX;
m_maxX=maxX;
m_minY=minY;
m_maxY=maxY;
sauimone
minor code review issues. indent, spaces, brackets etc.
r743 if (isEmpty()) return;
Michal Klocek
Add missing files from previous commit
r466 QVector<QPointF> points = calculateGeometryPoints();
Michal Klocek
Refactors animation handling for xyseries
r1217
if(m_animation) {
Michal Klocek
prevents flipping in xyseries animation
r1220 m_animation->setAnimationType(XYAnimation::MoveDownAnimation);
Michal Klocek
Refactors animation handling for xyseries
r1217 }
updateChart(m_points,points);
Michal Klocek
Add missing files from previous commit
r466 }
Michal Klocek
Refactor xychartitem -> xychart
r1218 void XYChart::handleGeometryChanged(const QRectF &rect)
Michal Klocek
Add missing files from previous commit
r466 {
Marek Rosa
XYSeries model with limits working.
r833 Q_ASSERT(rect.isValid());
m_size=rect.size();
m_clipRect=rect.translated(-rect.topLeft());
Michal Klocek
Refactor xychartitem -> xychart
r1218 m_origin=rect.topLeft();
Michal Klocek
Add missing files from previous commit
r466
sauimone
minor code review issues. indent, spaces, brackets etc.
r743 if (isEmpty()) return;
Marek Rosa
XYSeries model with limits working.
r833 QVector<QPointF> points = calculateGeometryPoints();
Michal Klocek
Refactors animation handling for xyseries
r1217 if(m_animation) {
m_animation->setAnimationType(XYAnimation::LineDrawAnimation);
}
updateChart(m_points,points);
Michal Klocek
Add missing files from previous commit
r466 }
Michal Klocek
Refactor xychartitem -> xychart
r1218 bool XYChart::isEmpty()
Michal Klocek
Add missing files from previous commit
r466 {
Michal Klocek
Bugfixes for spline vector allocation issues
r1082 return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty();
Michal Klocek
Add missing files from previous commit
r466 }
Michal Klocek
Refactor xychartitem -> xychart
r1218 #include "moc_xychart_p.cpp"
Michal Klocek
Add missing files from previous commit
r466
QTCOMMERCIALCHART_END_NAMESPACE