##// END OF EJS Templates
Renamed SplinePresenter to SplineChartItem
Renamed SplinePresenter to SplineChartItem

File last commit:

r439:86afa1b4ff5f
r460:c1b7acf3f56f
Show More
linechartitem.cpp
239 lines | 5.6 KiB | text/x-c | CppLexer
Michal Klocek
Fix naming convention for lineseries...
r144 #include "linechartitem_p.h"
Michal Klocek
Rename QLineChartSeries to QLineSeries
r349 #include "qlineseries.h"
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "chartpresenter_p.h"
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include <QPainter>
Michal Klocek
Fix naming convention for lineseries...
r144
Michal Klocek
Refactor current draft to fit int current design specs...
r21
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactor current draft to fit int current design specs...
r21
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 //TODO: optimize : remove points which are not visible
Michal Klocek
Adds cliping and proper zoom handling for line chart
r150
Michal Klocek
Refactor domain model...
r439 LineChartItem::LineChartItem(QLineSeries* series,QGraphicsItem *parent):ChartItem(parent),
m_minX(0),
m_maxX(0),
m_minY(0),
m_maxY(0),
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 m_series(series),
m_items(this)
Michal Klocek
Refactor current draft to fit int current design specs...
r21 {
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 //m_items.setZValue(ChartPresenter::LineChartZValue);
Michal Klocek
Adds ZOrder enum to presenter
r262 setZValue(ChartPresenter::LineChartZValue);
Michal Klocek
Adds area chart...
r421
QObject::connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
QObject::connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
QObject::connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated()));
Michal Klocek
Refactor domain model...
r439
handleUpdated();
Michal Klocek
Refactor current draft to fit int current design specs...
r21 }
Michal Klocek
Fix naming convention for lineseries...
r144 QRectF LineChartItem::boundingRect() const
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 {
Michal Klocek
Refactors qchart , adds line animation...
r131 return m_rect;
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 }
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix naming convention for lineseries...
r144 QPainterPath LineChartItem::shape() const
Michal Klocek
Add zoom support...
r67 {
Michal Klocek
Refactors qchart , adds line animation...
r131 return m_path;
}
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Rewrite animation hadnling in line series...
r389 void LineChartItem::createPoints(int count)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Rewrite animation hadnling in line series...
r389 for (int i = 0; i < count; ++i) {
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3);
Michal Klocek
Rewrite animation hadnling in line series...
r389 m_items.addToGroup(item);
Michal Klocek
Refactors qchart , adds line animation...
r131 }
}
Michal Klocek
Rewrite animation hadnling in line series...
r389 void LineChartItem::clearPoints(int count)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Rewrite animation hadnling in line series...
r389 QList<QGraphicsItem *> items = m_items.childItems();
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Rewrite animation hadnling in line series...
r389 for (int i = 0; i < count; ++i) {
delete(items.takeLast());
Michal Klocek
Refactors qchart , adds line animation...
r131 }
}
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QPointF LineChartItem::calculateGeometryPoint(int index) const
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 {
Michal Klocek
Refactor domain model...
r439 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
const qreal deltaY = m_size.height()/(m_maxY-m_minY);
qreal x = (m_series->x(index) - m_minX)* deltaX;
qreal y = (m_series->y(index) - m_minY)*-deltaY + m_size.height();
Michal Klocek
Rewrite animation hadnling in line series...
r389 return QPointF(x,y);
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 }
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QVector<QPointF> LineChartItem::calculateGeometryPoints() const
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactor domain model...
r439 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
const qreal deltaY = m_size.height()/(m_maxY-m_minY);
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QVector<QPointF> points;
points.reserve(m_series->count());
Michal Klocek
Rewrite animation hadnling in line series...
r389 for (int i = 0; i < m_series->count(); ++i) {
Michal Klocek
Refactor domain model...
r439 qreal x = (m_series->x(i) - m_minX)* deltaX;
qreal y = (m_series->y(i) - m_minY)*-deltaY + m_size.height();
Michal Klocek
Refactors qchart , adds line animation...
r131 points << QPointF(x,y);
}
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 return points;
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 void LineChartItem::updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 applyGeometry(newPoints);
oldPoints = newPoints;
}
Michal Klocek
Rewrite animation hadnling in line series...
r389
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 void LineChartItem::updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint)
{
oldPoints.replace(index,newPoint);
applyGeometry(oldPoints);
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Rewrite animation hadnling in line series...
r389 void LineChartItem::applyGeometry(QVector<QPointF>& points)
Michal Klocek
Add zoom support...
r67 {
Michal Klocek
Rewrite animation hadnling in line series...
r389 if(points.size()==0) return;
Michal Klocek
Refactor xyplotdata...
r25
Michal Klocek
Rewrite animation hadnling in line series...
r389 QList<QGraphicsItem*> items = m_items.childItems();
Michal Klocek
Refactor xyplotdata...
r25
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 QPainterPath path;
Michal Klocek
Rewrite animation hadnling in line series...
r389 const QPointF& point = points.at(0);
Michal Klocek
Refactors qchart , adds line animation...
r131 path.moveTo(point);
Michal Klocek
Rewrite animation hadnling in line series...
r389 QGraphicsItem* item = items.at(0);
item->setPos(point.x()-1,point.y()-1);
Michal Klocek
Refactor domain model...
r439 if(!m_clipRect.contains(point)) {
item->setVisible(false);
}else{
item->setVisible(true);
}
Michal Klocek
Rewrite animation hadnling in line series...
r389
for(int i=1 ; i< points.size();i++) {
QGraphicsItem* item = items.at(i);
const QPointF& point = points.at(i);
item->setPos(point.x()-1,point.y()-1);
Michal Klocek
Refactor domain model...
r439 if(!m_clipRect.contains(point)) {
item->setVisible(false);
}else{
item->setVisible(true);
}
Michal Klocek
Refactors qchart , adds line animation...
r131 path.lineTo(point);
Michal Klocek
Add zoom support...
r67 }
Michal Klocek
Refactor current draft to fit int current design specs...
r21
Michal Klocek
Rewrite animation hadnling in line series...
r389 prepareGeometryChange();
Michal Klocek
Refactors qchart , adds line animation...
r131 m_path = path;
m_rect = path.boundingRect();
Michal Klocek
Refactor current draft to fit int current design specs...
r21 }
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::setPen(const QPen& pen)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactored for MVP...
r139 m_pen = pen;
}
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactored for MVP...
r139 //handlers
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Rewrite animation hadnling in line series...
r389 void LineChartItem::handlePointAdded(int index)
Michal Klocek
Refactored for MVP...
r139 {
Q_ASSERT(index<m_series->count());
Michal Klocek
Rewrite animation hadnling in line series...
r389 Q_ASSERT(index>=0);
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QPointF point = calculateGeometryPoint(index);
createPoints(1);
QVector<QPointF> points = m_points;
points.insert(index,point);
updateItem(m_points,points);
update();
Michal Klocek
Rewrite animation hadnling in line series...
r389 }
void LineChartItem::handlePointRemoved(int index)
{
Q_ASSERT(index<m_series->count());
Q_ASSERT(index>=0);
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QPointF point = calculateGeometryPoint(index);
clearPoints(1);
QVector<QPointF> points = m_points;
points.remove(index);
updateItem(m_points,points);
update();
Michal Klocek
Rewrite animation hadnling in line series...
r389 }
void LineChartItem::handlePointReplaced(int index)
{
Q_ASSERT(index<m_series->count());
Q_ASSERT(index>=0);
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QPointF point = calculateGeometryPoint(index);
updateItem(m_points,index,point);
Michal Klocek
Refactored for MVP...
r139 update();
}
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactor domain model...
r439 void LineChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
Michal Klocek
Refactored for MVP...
r139 {
Michal Klocek
Refactor domain model...
r439 m_minX=minX;
m_maxX=maxX;
m_minY=minY;
m_maxY=maxY;
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391
Michal Klocek
Refactor domain model...
r439 if( (m_maxX - m_minX) == 0|| (m_maxY - m_minY) == 0) return;
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 if(!m_clipRect.isValid()) return;
Michal Klocek
Rewrite animation hadnling in line series...
r389
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QVector<QPointF> points = calculateGeometryPoints();
int diff = m_points.size() - points.size();
if(diff>0) {
clearPoints(diff);
}
else if(diff<0) {
Michal Klocek
Refactor domain model...
r439 createPoints(-diff);
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 }
updateItem(m_points,points);
Michal Klocek
Refactors qchart , adds line animation...
r131 update();
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::handleGeometryChanged(const QRectF& rect)
Michal Klocek
Refactored for MVP...
r139 {
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 Q_ASSERT(rect.isValid());
m_size=rect.size();
m_clipRect=rect.translated(-rect.topLeft());
setPos(rect.topLeft());
Michal Klocek
Rewrite animation hadnling in line series...
r389
Michal Klocek
Refactor domain model...
r439 if( (m_maxX - m_minX) == 0|| (m_maxY - m_minY) == 0) return;
Michal Klocek
Rewrite animation hadnling in line series...
r389
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QVector<QPointF> points = calculateGeometryPoints();
int diff = m_points.size() - points.size();
if(diff>0) {
clearPoints(diff);
}
else if(diff<0) {
createPoints(-diff);
}
updateItem(m_points,points);
update();
Michal Klocek
Rewrite animation hadnling in line series...
r389 }
Michal Klocek
Adds updated handling for line series
r392 void LineChartItem::handleUpdated()
Michal Klocek
Rewrite animation hadnling in line series...
r389 {
m_items.setVisible(m_series->pointsVisible());
setPen(m_series->pen());
Michal Klocek
Refactored for MVP...
r139 update();
}
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 //painter
void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(option);
painter->save();
painter->setPen(m_pen);
painter->setClipRect(m_clipRect);
painter->drawPath(m_path);
painter->restore();
}
Michal Klocek
Refactored for MVP...
r139
Michal Klocek
Fix naming convention for lineseries...
r144 #include "moc_linechartitem_p.cpp"
Michal Klocek
Refactors qchart , adds line animation...
r131
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_END_NAMESPACE