##// END OF EJS Templates
Remove obsolete setBackgroundColor form QChart
Remove obsolete setBackgroundColor form QChart

File last commit:

r131:7f17c1eef296
r137:c3223f1ab305
Show More
xylinechartitem.cpp
213 lines | 4.9 KiB | text/x-c | CppLexer
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include "xylinechartitem_p.h"
#include "qxychartseries.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>
#include <QStyleOptionGraphicsItem>
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactor current draft to fit int current design specs...
r21
Michal Klocek
Refactors qchart , adds line animation...
r131 XYLineChartItem::XYLineChartItem(ChartPresenter* presenter, QXYChartSeries* series,QGraphicsItem *parent):ChartItem(parent),
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
Refactors qchart , adds line animation...
r131 QObject::connect(series,SIGNAL(changed(int)),this,SLOT(handleSeriesChanged(int)));
Michal Klocek
Refactor current draft to fit int current design specs...
r21 }
Michal Klocek
Refactors qchart , adds line animation...
r131 QRectF XYLineChartItem::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
Refactors qchart , adds line animation...
r131 QPainterPath XYLineChartItem::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 void XYLineChartItem::setSize(const QSizeF& size)
{
m_size=size;
m_dirtyGeometry=true;
Michal Klocek
Add zoom support...
r67 }
Michal Klocek
Refactor xyplotdata...
r25
Michal Klocek
Refactors qchart , adds line animation...
r131 void XYLineChartItem::setDomain(const Domain& domain)
{
m_domain=domain;
m_dirtyDomain=true;
}
void XYLineChartItem::setSeries(QXYChartSeries* series)
{
m_series = series;
m_dirtyData=true;
}
void XYLineChartItem::addPoints(const QVector<QPointF>& points)
{
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);
item->setPos(point.x()-1,point.y()-1);
m_points << item;
}
}
void XYLineChartItem::addPoint(const QPointF& point)
{
m_data << point;
QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
item->setPos(point.x()-1,point.y()-1);
m_points << item;
}
void XYLineChartItem::removePoint(const QPointF& point)
{
Q_ASSERT(m_data.count() == m_points.count());
int index = m_data.lastIndexOf(point,0);
m_data.remove(index);
delete(m_points.takeAt(index));
}
void XYLineChartItem::setPoint(const QPointF& oldPoint,const QPointF& newPoint)
{
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);
}
}
void XYLineChartItem::setPoint(int index,const QPointF& point)
{
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);
}
void XYLineChartItem::clear()
{
qDeleteAll(m_points);
m_points.clear();
m_hash.clear();
m_path = QPainterPath();
m_rect = QRect();
m_data.clear();
}
void XYLineChartItem::clearView()
{
qDeleteAll(m_points);
m_points.clear();
m_path = QPainterPath();
m_rect = QRect();
m_data.clear();
}
void XYLineChartItem::handleSeriesChanged(int index)
Michal Klocek
Add zoom support...
r67 {
Michal Klocek
Refactors qchart , adds line animation...
r131 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);
}
Tero Ahola
One more alternative for changing themes
r108 }
void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Michal Klocek
Refactors qchart , adds line animation...
r131 Q_UNUSED(widget);
Q_UNUSED(option);
painter->drawPath(m_path);
Michal Klocek
Add zoom support...
r67 }
Tero Ahola
One more alternative for changing themes
r108
Michal Klocek
Refactors qchart , adds line animation...
r131 void XYLineChartItem::calculatePoint(QPointF& point, int index, const QXYChartSeries* 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
void XYLineChartItem::calculatePoints(QVector<QPointF>& points, QHash<int,int>& hash,const QXYChartSeries* series,const QSizeF& size, const Domain& domain) const
{
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;
if(x<0 || x > size.width()) continue;
qreal y = (series->y(i) - domain.m_minY)*-deltaY + size.height();
if(y<0 || y > size.height()) continue;
hash[i] = points.size();
points << QPointF(x,y);
}
}
void XYLineChartItem::updateDomain()
{
clear();
calculatePoints(m_data,m_hash,m_series,m_size, m_domain);
addPoints(m_data);
m_dirtyGeometry = true;
}
void XYLineChartItem::updateData()
{
//for now the same
updateDomain();
}
Michal Klocek
Add zoom support...
r67 void XYLineChartItem::updateGeometry()
{
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
Refactors qchart , adds line animation...
r131 void XYLineChartItem::updateItem()
{
if(m_dirtyDomain) {
updateDomain();
m_dirtyData = false;
}
if(m_dirtyData) {
updateData();
m_dirtyData = false;
}
if(m_dirtyGeometry) {
updateGeometry();
m_dirtyGeometry = false;
}
update();
}
#include "moc_xylinechartitem_p.cpp"
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_END_NAMESPACE