##// END OF EJS Templates
Add documentation to pie
Add documentation to pie

File last commit:

r262:461b2e61910e
r314:9957a05c8211
Show More
linechartitem.cpp
210 lines | 5.0 KiB | text/x-c | CppLexer
Michal Klocek
Fix naming convention for lineseries...
r144 #include "linechartitem_p.h"
#include "qlinechartseries.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
Adds cliping and proper zoom handling for line chart
r150 //TODO: optimazie : remove points which are not visible
Michal Klocek
Fix naming convention for lineseries...
r144 LineChartItem::LineChartItem(ChartPresenter* presenter, QLineChartSeries* series,QGraphicsItem *parent):ChartItem(parent),
Michal Klocek
Refactors qchart , adds line animation...
r131 m_presenter(presenter),
m_series(series),
m_dirtyData(false),
m_dirtyGeometry(false),
m_dirtyDomain(false)
Michal Klocek
Refactor current draft to fit int current design specs...
r21 {
Michal Klocek
Adds ZOrder enum to presenter
r262 setZValue(ChartPresenter::LineChartZValue);
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
Refactors qchart , adds line animation...
r131
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::addPoints(const QVector<QPointF>& points)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
m_data = points;
for(int i=0; i<m_data.size();i++){
const QPointF& point =m_data[i];
QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
Michal Klocek
Adds cliping and proper zoom handling for line chart
r150 item->setPos(point.x()-1,point.y()-1);;
Michal Klocek
Add pointsVisible setting for line series
r185 if(!m_clipRect.contains(point) || !m_series->isPointsVisible()) item->setVisible(false);
Michal Klocek
Refactors qchart , adds line animation...
r131 m_points << item;
}
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::addPoint(const QPointF& point)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
m_data << point;
QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
Michal Klocek
Adds cliping and proper zoom handling for line chart
r150 m_clipRect.contains(point);
Michal Klocek
Refactors qchart , adds line animation...
r131 item->setPos(point.x()-1,point.y()-1);
Michal Klocek
Add pointsVisible setting for line series
r185 if(!m_clipRect.contains(point) || !m_series->isPointsVisible()) item->setVisible(false);
Michal Klocek
Refactors qchart , adds line animation...
r131 m_points << item;
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::removePoint(const QPointF& point)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Q_ASSERT(m_data.count() == m_points.count());
int index = m_data.lastIndexOf(point,0);
m_data.remove(index);
delete(m_points.takeAt(index));
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::setPoint(const QPointF& oldPoint,const QPointF& newPoint)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Q_ASSERT(m_data.count() == m_points.count());
int index = m_data.lastIndexOf(oldPoint,0);
if(index > -1){
m_data.replace(index,newPoint);
QGraphicsItem* item = m_points.at(index);
item->setPos(newPoint.x()-1,newPoint.y()-1);
}
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::setPoint(int index,const QPointF& point)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Q_ASSERT(m_data.count() == m_points.count());
Q_ASSERT(index>=0);
m_data.replace(index,point);
QGraphicsItem* item = m_points.at(index);
item->setPos(point.x()-1,point.y()-1);
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::clear()
Michal Klocek
Refactors qchart , adds line animation...
r131 {
qDeleteAll(m_points);
m_points.clear();
m_hash.clear();
m_path = QPainterPath();
m_rect = QRect();
m_data.clear();
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::clearView()
Michal Klocek
Refactors qchart , adds line animation...
r131 {
qDeleteAll(m_points);
m_points.clear();
m_path = QPainterPath();
m_rect = QRect();
m_data.clear();
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Tero Ahola
One more alternative for changing themes
r108 {
Tero Ahola
Fixed issue with multiple QML charts...
r213 Q_UNUSED(widget);
Michal Klocek
Refactors qchart , adds line animation...
r131 Q_UNUSED(option);
Tero Ahola
Fixed issue with multiple QML charts...
r213 painter->save();
Michal Klocek
Refactored for MVP...
r139 painter->setPen(m_pen);
Michal Klocek
Adds cliping and proper zoom handling for line chart
r150 painter->setClipRect(m_clipRect);
Tero Ahola
Fixed issue with multiple QML charts...
r213 painter->drawPath(m_path);
painter->restore();
Michal Klocek
Add zoom support...
r67 }
Tero Ahola
One more alternative for changing themes
r108
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::calculatePoint(QPointF& point, int index, const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 {
Michal Klocek
Refactors qchart , adds line animation...
r131 const qreal deltaX = size.width()/domain.spanX();
const qreal deltaY = size.height()/domain.spanY();
qreal x = (series->x(index) - domain.m_minX)* deltaX;
qreal y = (series->y(index) - domain.m_minY)*-deltaY + size.height();
point.setX(x);
point.setY(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 naming convention for lineseries...
r144 void LineChartItem::calculatePoints(QVector<QPointF>& points, QHash<int,int>& hash,const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const
Michal Klocek
Refactors qchart , adds line animation...
r131 {
const qreal deltaX = size.width()/domain.spanX();
const qreal deltaY = size.height()/domain.spanY();
for (int i = 0; i < series->count(); ++i) {
qreal x = (series->x(i) - domain.m_minX)* deltaX;
qreal y = (series->y(i) - domain.m_minY)*-deltaY + size.height();
hash[i] = points.size();
points << QPointF(x,y);
}
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::updateDomain()
Michal Klocek
Refactors qchart , adds line animation...
r131 {
clear();
Michal Klocek
Adds cliping and proper zoom handling for line chart
r150 prepareGeometryChange();
Michal Klocek
Refactors qchart , adds line animation...
r131 calculatePoints(m_data,m_hash,m_series,m_size, m_domain);
addPoints(m_data);
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::updateData()
Michal Klocek
Refactors qchart , adds line animation...
r131 {
//for now the same
updateDomain();
}
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::updateGeometry()
Michal Klocek
Add zoom support...
r67 {
Michal Klocek
Refactor xyplotdata...
r25
Michal Klocek
Refactors qchart , adds line animation...
r131 if(m_data.size()==0) return;
Michal Klocek
Refactor xyplotdata...
r25
Michal Klocek
Refactors qchart , adds line animation...
r131 prepareGeometryChange();
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 QPainterPath path;
Michal Klocek
Refactors qchart , adds line animation...
r131 const QPointF& point = m_data.at(0);
path.moveTo(point);
Michal Klocek
Refactor xyplotdata...
r25
Michal Klocek
Refactors qchart , adds line animation...
r131 foreach( const QPointF& point , m_data) {
path.lineTo(point);
Michal Klocek
Add zoom support...
r67 }
Michal Klocek
Refactor current draft to fit int current design specs...
r21
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
Fix naming convention for lineseries...
r144 void LineChartItem::handleModelChanged(int index)
Michal Klocek
Refactored for MVP...
r139 {
Q_ASSERT(index<m_series->count());
if(m_hash.contains(index)){
int i = m_hash.value(index);
QPointF point;
calculatePoint(point,index,m_series,m_size,m_domain);
setPoint(i,point);
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Refactored for MVP...
r139 update();
}
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Fix naming convention for lineseries...
r144 void LineChartItem::handleDomainChanged(const Domain& domain)
Michal Klocek
Refactored for MVP...
r139 {
m_domain = domain;
updateDomain();
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 {
Q_ASSERT(rect.isValid());
m_size=rect.size();
Michal Klocek
Adds cliping and proper zoom handling for line chart
r150 m_clipRect=rect.translated(-rect.topLeft());
Michal Klocek
Refactored for MVP...
r139 updateDomain();
updateGeometry();
setPos(rect.topLeft());
update();
}
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