##// END OF EJS Templates
Refactor animation to fit line,spline,scatter...
Michal Klocek -
r476:b6fb05e4e56f
parent child
Show More
@@ -0,0 +1,100
1 #ifndef XYCHARTANIMATIONITEM_P_H_
2 #define XYCHARTANIMATIONITEM_P_H_
3 #include "qchartglobal.h"
4 #include "xychartanimator_p.h"
5 #include <QPointF>
6 #include <QTimer>
7 #include <QGraphicsItem>
8
9 Q_DECLARE_METATYPE(QVector<QPointF>)
10
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
13
14 const static int duration = 1000;
15
16 template <class T , class U>
17 class XYChartAnimationItem : public T {
18
19 public:
20 XYChartAnimationItem(U *series, QGraphicsItem *parent = 0);
21 virtual ~XYChartAnimationItem();
22
23 void animationStarted();
24
25 protected:
26 virtual void updatePoints(QVector<QPointF>& newPoints);
27 virtual void updatePoint(QVector<QPointF>& newPoints);
28
29 private:
30 XYChartAnimator<T,U> *m_animation;
31 QVector<QPointF> m_points;
32 bool m_dirty;
33 };
34
35 template <class T, class U>
36 XYChartAnimationItem<T,U>::XYChartAnimationItem(U *series,QGraphicsItem *parent):
37 T(series,parent),
38 m_animation(new XYChartAnimator<T,U>(this,this)),
39 m_dirty(false)
40 {
41 }
42
43 template <class T, class U>
44 XYChartAnimationItem<T,U>::~XYChartAnimationItem()
45 {
46 }
47
48 template <class T, class U>
49 void XYChartAnimationItem<T,U>::updatePoints(QVector<QPointF>& newPoints)
50 {
51 QVector<QPointF> oldPoints = T::points();
52
53 if(newPoints.count()==0) return;
54 oldPoints.resize(newPoints.size());
55
56 if(m_animation->state()!=QAbstractAnimation::Stopped){
57 m_animation->stop();
58 }
59
60 m_animation->setDuration(duration);
61 m_animation->setEasingCurve(QEasingCurve::InOutBack);
62 m_animation->setKeyValueAt(0.0, qVariantFromValue(oldPoints));
63 m_animation->setKeyValueAt(1.0, qVariantFromValue(newPoints));
64 QTimer::singleShot(0,m_animation,SLOT(start()));
65
66 m_points = newPoints;
67 m_dirty=false;
68 }
69
70 template <class T, class U>
71 void XYChartAnimationItem<T,U>::updatePoint(QVector<QPointF>& newPoints)
72 {
73
74 if(m_animation->state()!=QAbstractAnimation::Stopped) {
75 m_animation->stop();
76 m_dirty=true;
77 }
78
79 if(m_dirty) {
80 m_points=newPoints;
81 m_dirty=false;
82 }
83
84 m_animation->setDuration(duration);
85 m_animation->setEasingCurve(QEasingCurve::InOutBack);
86 m_animation->setKeyValueAt(0.0, qVariantFromValue(m_points));
87 m_animation->setKeyValueAt(1.0, qVariantFromValue(newPoints));
88
89 QTimer::singleShot(0,m_animation,SLOT(start()));
90 }
91
92 template <class T, class U>
93 void XYChartAnimationItem<T,U>::animationStarted()
94 {
95 m_dirty=true;
96 }
97
98 QTCOMMERCIALCHART_END_NAMESPACE
99
100 #endif
@@ -0,0 +1,96
1 #ifndef XYCHARTANIMATOR_P_H_
2 #define XYCHARTANIMATOR_P_H_
3 #include "qchartglobal.h"
4 #include <QVariantAnimation>
5 #include <QPointF>
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
9 template <class T, class U>
10 class XYChartAnimationItem;
11
12
13 template <class T, class U>
14 class XYChartAnimator : public QVariantAnimation
15 {
16 public:
17 enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation };
18 XYChartAnimator(XYChartAnimationItem<T,U> *item, QObject *parent = 0 );
19 ~XYChartAnimator();
20
21 protected:
22 QVariant interpolated(const QVariant &start, const QVariant & end, qreal progress ) const;
23 void updateCurrentValue (const QVariant & value );
24 void updateState ( QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
25
26 private:
27 XYChartAnimationItem<T,U> *m_item;
28 Animation m_type;
29 };
30
31 template <class T, class U>
32 XYChartAnimator<T,U>::XYChartAnimator(XYChartAnimationItem<T,U> *item , QObject *parent):QVariantAnimation(parent),
33 m_item(item),
34 m_type(MoveDownAnimation)
35 {
36 }
37
38 template <class T,class U>
39 XYChartAnimator<T,U>::~XYChartAnimator()
40 {
41 }
42
43 template <class T, class U>
44 QVariant XYChartAnimator<T,U>::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const
45 {
46 QVector<QPointF> startVector = qVariantValue<QVector<QPointF> >(start);
47 QVector<QPointF> endVector = qVariantValue<QVector<QPointF> >(end);
48 QVector<QPointF> result;
49
50 switch(m_type) {
51
52 case MoveDownAnimation: {
53
54 Q_ASSERT(startVector.count() == endVector.count());
55 for(int i =0;i< startVector.count();i++) {
56 qreal x = startVector[i].x() + ((endVector[i].x()- startVector[i].x()) * progress);
57 qreal y = startVector[i].y() + ((endVector[i].y()- startVector[i].y()) * progress);
58 result << QPointF(x,y);
59 }
60
61 }
62 break;
63 case LineDrawAnimation:{
64 for(int i =0;i< endVector.count()* qBound(0.0, progress, 1.0);i++) {
65 result << endVector[i];
66 }
67 }
68 break;
69 default:
70 qWarning()<<"Unknow type of animation";
71 break;
72 }
73
74 return qVariantFromValue(result);
75 }
76
77 template <class T, class U>
78 void XYChartAnimator<T,U>::updateCurrentValue (const QVariant & value )
79 {
80 QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value);
81 if(state()!=QAbstractAnimation::Stopped){ //workaround
82 m_item->setGeometry(vector);
83 }
84 }
85
86 template <class T, class U>
87 void XYChartAnimator<T,U>::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
88 {
89 Q_UNUSED(oldState)
90 if (newState==QAbstractAnimation::Running) m_item->animationStarted();
91 QVariantAnimation::updateState(newState,oldState);
92 }
93
94 QTCOMMERCIALCHART_END_NAMESPACE
95
96 #endif /* XYCHARTANIMATOR_P_H_ */
@@ -1,59 +1,70
1 #include "chartview.h"
1 #include "chartview.h"
2 #include <qlineseries.h>
2 #include <qlineseries.h>
3 #include <qscatterseries.h>
4 #include <qsplineseries.h>
3 #include <QTime>
5 #include <QTime>
4
6
5 ChartView::ChartView(QWidget* parent):QChartView(parent),
7 ChartView::ChartView(QWidget* parent):QChartView(parent),
6 m_index(0)
8 m_index(0)
7 {
9 {
10 setChartTitle("Three random line charts");
11
8 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
12 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
9 m_timer.setInterval(3000);
13 m_timer.setInterval(3000);
10
14
11 QTime now = QTime::currentTime();
15 QTime now = QTime::currentTime();
12 qsrand((uint)now.msec());
16 qsrand((uint)now.msec());
13
17
14 QLineSeries* series0 = new QLineSeries(this);
18 QLineSeries* series0 = new QLineSeries(this);
15 QPen blue(Qt::blue);
19 QPen blue(Qt::blue);
16 blue.setWidth(3);
20 blue.setWidth(3);
17 series0->setPen(blue);
21 series0->setPen(blue);
18 QLineSeries* series1 = new QLineSeries(this);
22 QScatterSeries* series1 = new QScatterSeries(this);
19 QPen red(Qt::red);
23 QPen red(Qt::red);
20 red.setWidth(3);
24 red.setWidth(3);
21 series1->setPen(red);
25 series1->setPen(red);
22 QLineSeries* series2 = new QLineSeries(this);
26 series1->setBrush(Qt::white);
27 QSplineSeries* series2 = new QSplineSeries(this);
23 QPen green(Qt::green);
28 QPen green(Qt::green);
24 green.setWidth(3);
29 green.setWidth(3);
25 series2->setPen(green);
30 series2->setPen(green);
26
31
27 int numPoints = 10;
32 int numPoints = 10;
28
33
29 for (int x = 0; x <= numPoints; ++x) {
34 for (int x = 0; x <= numPoints; ++x) {
30 series0->add(x, qrand() % 100);
35 qreal y = qrand() % 100;
31 series1->add(x, qrand() % 100);
36 series0->add(x,y);
32 series2->add(x, qrand() % 100);
37 series1->add(x,y);
38 series2->add(x,y);
33 }
39 }
34
40
35 addSeries(series0);
36
37 m_series<<series0;
41 m_series<<series0;
42 m_titles<<chartTitle()+": LineChart";
38 m_series<<series1;
43 m_series<<series1;
44 m_titles<<chartTitle()+": ScatterChart";
39 m_series<<series2;
45 m_series<<series2;
46 m_titles<<chartTitle()+": SplineChart";
47
48 addSeries(series0);
49 setChartTitle(m_titles.at(0));
40
50
41 m_timer.start();
51 m_timer.start();
42 }
52 }
43
53
44 ChartView::~ChartView()
54 ChartView::~ChartView()
45 {
55 {
46 if(m_series.size()==0) return;
56 if(m_series.size()==0) return;
47 removeSeries(m_series.at(m_index));
57 removeSeries(m_series.at(m_index));
48 qDeleteAll(m_series);
58 qDeleteAll(m_series);
49 }
59 }
50
60
51 void ChartView::handleTimeout()
61 void ChartView::handleTimeout()
52 {
62 {
53 if(m_series.size()==0) return;
63 if(m_series.size()==0) return;
54
64
55 removeSeries(m_series.at(m_index));
65 removeSeries(m_series.at(m_index));
56 m_index++;
66 m_index++;
57 m_index=m_index%m_series.size();
67 m_index=m_index%m_series.size();
58 addSeries(m_series.at(m_index));
68 addSeries(m_series.at(m_index));
69 setChartTitle(m_titles.at(m_index));
59 }
70 }
@@ -1,25 +1,26
1 #ifndef CHARTVIEW_H_
1 #ifndef CHARTVIEW_H_
2 #define CHARTVIEW_H_
2 #define CHARTVIEW_H_
3
3
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <QTimer>
5 #include <QTimer>
6
6
7 QTCOMMERCIALCHART_USE_NAMESPACE
7 QTCOMMERCIALCHART_USE_NAMESPACE
8
8
9 class ChartView: public QChartView
9 class ChartView: public QChartView
10 {
10 {
11 Q_OBJECT
11 Q_OBJECT
12 public:
12 public:
13 ChartView(QWidget* parent=0);
13 ChartView(QWidget* parent=0);
14 virtual ~ChartView();
14 virtual ~ChartView();
15
15
16 public slots:
16 public slots:
17 void handleTimeout();
17 void handleTimeout();
18
18
19 private:
19 private:
20 QTimer m_timer;
20 QTimer m_timer;
21 QList<QSeries*> m_series;
21 QList<QSeries*> m_series;
22 QStringList m_titles;
22 int m_index;
23 int m_index;
23 };
24 };
24
25
25 #endif /* CHARTVIEW_H_ */
26 #endif /* CHARTVIEW_H_ */
@@ -1,17 +1,16
1 #include "chartview.h"
1 #include "chartview.h"
2 #include <QApplication>
2 #include <QApplication>
3 #include <QMainWindow>
3 #include <QMainWindow>
4
4
5 int main(int argc, char *argv[])
5 int main(int argc, char *argv[])
6 {
6 {
7 QApplication a(argc, argv);
7 QApplication a(argc, argv);
8 QMainWindow window;
8 QMainWindow window;
9 ChartView chartView(&window);
9 ChartView chartView(&window);
10 chartView.setRenderHint(QPainter::Antialiasing);
10 chartView.setRenderHint(QPainter::Antialiasing);
11 chartView.setChartTitle("Three random line charts");
12 chartView.setAnimationOptions(QChart::AllAnimations);
11 chartView.setAnimationOptions(QChart::AllAnimations);
13 window.setCentralWidget(&chartView);
12 window.setCentralWidget(&chartView);
14 window.resize(400, 300);
13 window.resize(400, 300);
15 window.show();
14 window.show();
16 return a.exec();
15 return a.exec();
17 }
16 }
@@ -1,371 +1,386
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include "chartdataset_p.h"
4 #include "chartdataset_p.h"
5 #include "charttheme_p.h"
5 #include "charttheme_p.h"
6 //series
6 //series
7 #include "qbarseries.h"
7 #include "qbarseries.h"
8 #include "qstackedbarseries.h"
8 #include "qstackedbarseries.h"
9 #include "qpercentbarseries.h"
9 #include "qpercentbarseries.h"
10 #include "qlineseries.h"
10 #include "qlineseries.h"
11 #include "qareaseries.h"
11 #include "qareaseries.h"
12 #include "qpieseries.h"
12 #include "qpieseries.h"
13 #include "qscatterseries.h"
13 #include "qscatterseries.h"
14 #include "qsplineseries.h"
14 #include "qsplineseries.h"
15 //items
15 //items
16 #include "axisitem_p.h"
16 #include "axisitem_p.h"
17 #include "axisanimationitem_p.h"
17 #include "axisanimationitem_p.h"
18 #include "areachartitem_p.h"
18 #include "areachartitem_p.h"
19 #include "barpresenter_p.h"
19 #include "barpresenter_p.h"
20 #include "stackedbarpresenter_p.h"
20 #include "stackedbarpresenter_p.h"
21 #include "percentbarpresenter_p.h"
21 #include "percentbarpresenter_p.h"
22 #include "linechartitem_p.h"
22 #include "linechartitem_p.h"
23 #include "linechartanimationitem_p.h"
24 #include "piepresenter_p.h"
23 #include "piepresenter_p.h"
25 #include "scatterchartitem_p.h"
24 #include "scatterchartitem_p.h"
26 #include "splinechartitem_p.h"
25 #include "splinechartitem_p.h"
27
26
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
28
30 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
29 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
31 m_chart(chart),
30 m_chart(chart),
32 m_dataset(dataset),
31 m_dataset(dataset),
33 m_chartTheme(0),
32 m_chartTheme(0),
34 m_zoomIndex(0),
33 m_zoomIndex(0),
35 m_marginSize(0),
34 m_marginSize(0),
36 m_rect(QRectF(QPoint(0,0),m_chart->size())),
35 m_rect(QRectF(QPoint(0,0),m_chart->size())),
37 m_options(QChart::NoAnimation)
36 m_options(QChart::NoAnimation)
38 {
37 {
39 createConnections();
38 createConnections();
40 setChartTheme(QChart::ChartThemeDefault);
39 setChartTheme(QChart::ChartThemeDefault);
41 }
40 }
42
41
43 ChartPresenter::~ChartPresenter()
42 ChartPresenter::~ChartPresenter()
44 {
43 {
45 }
44 }
46
45
47 void ChartPresenter::createConnections()
46 void ChartPresenter::createConnections()
48 {
47 {
49 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
48 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
50 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
49 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
51 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
50 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
52 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
51 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
53 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
52 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
54 }
53 }
55
54
56
55
57 QRectF ChartPresenter::geometry() const
56 QRectF ChartPresenter::geometry() const
58 {
57 {
59 return m_rect;
58 return m_rect;
60 }
59 }
61
60
62 void ChartPresenter::handleGeometryChanged()
61 void ChartPresenter::handleGeometryChanged()
63 {
62 {
64 QRectF rect(QPoint(0,0),m_chart->size());
63 QRectF rect(QPoint(0,0),m_chart->size());
65 rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
64 rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
66
65
67 //rewrite zoom stack
66 //rewrite zoom stack
68 for(int i=0;i<m_zoomStack.count();i++){
67 for(int i=0;i<m_zoomStack.count();i++){
69 QRectF r = m_zoomStack[i];
68 QRectF r = m_zoomStack[i];
70 qreal w = rect.width()/m_rect.width();
69 qreal w = rect.width()/m_rect.width();
71 qreal h = rect.height()/m_rect.height();
70 qreal h = rect.height()/m_rect.height();
72 QPointF tl = r.topLeft();
71 QPointF tl = r.topLeft();
73 tl.setX(tl.x()*w);
72 tl.setX(tl.x()*w);
74 tl.setY(tl.y()*h);
73 tl.setY(tl.y()*h);
75 QPointF br = r.bottomRight();
74 QPointF br = r.bottomRight();
76 br.setX(br.x()*w);
75 br.setX(br.x()*w);
77 br.setY(br.y()*h);
76 br.setY(br.y()*h);
78 r.setTopLeft(tl);
77 r.setTopLeft(tl);
79 r.setBottomRight(br);
78 r.setBottomRight(br);
80 m_zoomStack[i]=r;
79 m_zoomStack[i]=r;
81 }
80 }
82
81
83 m_rect = rect;
82 m_rect = rect;
84 Q_ASSERT(m_rect.isValid());
83 Q_ASSERT(m_rect.isValid());
85 emit geometryChanged(m_rect);
84 emit geometryChanged(m_rect);
86 }
85 }
87
86
88 int ChartPresenter::margin() const
87 int ChartPresenter::margin() const
89 {
88 {
90 return m_marginSize;
89 return m_marginSize;
91 }
90 }
92
91
93 void ChartPresenter::setMargin(int margin)
92 void ChartPresenter::setMargin(int margin)
94 {
93 {
95 m_marginSize = margin;
94 m_marginSize = margin;
96 }
95 }
97
96
98 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
97 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
99 {
98 {
100
99
101 AxisItem* item ;
100 AxisItem* item ;
102
101
103 if(!m_options.testFlag(QChart::GridAxisAnimations))
102 if(!m_options.testFlag(QChart::GridAxisAnimations))
104 {
103 {
105 item = new AxisItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
104 item = new AxisItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
106 }else{
105 }else{
107 item = new AxisAnimationItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
106 item = new AxisAnimationItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
108 }
107 }
109 if(axis==m_dataset->axisX()){
108 if(axis==m_dataset->axisX()){
110 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal)));
109 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal)));
111 //initialize
110 //initialize
112 item->handleRangeChanged(domain->minX(),domain->maxX());
111 item->handleRangeChanged(domain->minX(),domain->maxX());
113 item->handleTicksCountChanged(4);
112 item->handleTicksCountChanged(4);
114 }
113 }
115 else{
114 else{
116 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal)));
115 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal)));
117 //initialize
116 //initialize
118 item->handleRangeChanged(domain->minY(),domain->maxY());
117 item->handleRangeChanged(domain->minY(),domain->maxY());
119 item->handleTicksCountChanged(4);
118 item->handleTicksCountChanged(4);
120 }
119 }
121
120
122 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
121 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
123 //initialize
122 //initialize
124 item->handleGeometryChanged(m_rect);
123 item->handleGeometryChanged(m_rect);
125 m_chartTheme->decorate(axis,item);
124 m_chartTheme->decorate(axis,item);
126 m_axisItems.insert(axis,item);
125 m_axisItems.insert(axis,item);
127 }
126 }
128
127
129 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
128 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
130 {
129 {
131 AxisItem* item = m_axisItems.take(axis);
130 AxisItem* item = m_axisItems.take(axis);
132 Q_ASSERT(item);
131 Q_ASSERT(item);
133 delete item;
132 delete item;
134 }
133 }
135
134
136
135
137 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
136 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
138 {
137 {
139 switch(series->type())
138 switch(series->type())
140 {
139 {
141 case QSeries::SeriesTypeLine: {
140 case QSeries::SeriesTypeLine: {
142
141
143 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
142 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
144 LineChartItem* item;
143 LineChartItem* item;
145 if(m_options.testFlag(QChart::SeriesAnimations)){
144 if(m_options.testFlag(QChart::SeriesAnimations)){
146 item = new LineChartAnimationItem(lineSeries,m_chart);
145 item = new LineChartAnimationItem(lineSeries,m_chart);
147 }else{
146 }else{
148 item = new LineChartItem(lineSeries,m_chart);
147 item = new LineChartItem(lineSeries,m_chart);
149 }
148 }
150 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
149 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
151 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
150 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
152 //initialize
151 //initialize
153 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
152 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
154 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
153 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
155 //decorate
154 //decorate
156 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
155 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
157 m_chartItems.insert(series,item);
156 m_chartItems.insert(series,item);
158 break;
157 break;
159 }
158 }
160
159
161 case QSeries::SeriesTypeArea: {
160 case QSeries::SeriesTypeArea: {
162
161
163 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
162 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
164 AreaChartItem* item;
163 AreaChartItem* item;
165 if(m_options.testFlag(QChart::SeriesAnimations)) {
164 if(m_options.testFlag(QChart::SeriesAnimations)) {
166 item = new AreaChartItem(areaSeries,m_chart);
165 item = new AreaChartItem(areaSeries,m_chart);
167 }
166 }
168 else {
167 else {
169 item = new AreaChartItem(areaSeries,m_chart);
168 item = new AreaChartItem(areaSeries,m_chart);
170 }
169 }
171 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
170 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
172 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
171 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
173 //initialize
172 //initialize
174 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
173 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
175 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
174 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
176 //decorate
175 //decorate
177 m_chartTheme->decorate(item,areaSeries,m_chartItems.count());
176 m_chartTheme->decorate(item,areaSeries,m_chartItems.count());
178 m_chartItems.insert(series,item);
177 m_chartItems.insert(series,item);
179 break;
178 break;
180 }
179 }
181
180
182 case QSeries::SeriesTypeBar: {
181 case QSeries::SeriesTypeBar: {
183 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
182 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
184 BarPresenter* item = new BarPresenter(barSeries,m_chart);
183 BarPresenter* item = new BarPresenter(barSeries,m_chart);
185 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
184 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
186 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
185 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
187 // QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
186 // QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
188 m_chartItems.insert(series,item);
187 m_chartItems.insert(series,item);
189 // m_axisXItem->setVisible(false);
188 // m_axisXItem->setVisible(false);
190 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
189 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
191 break;
190 break;
192 }
191 }
193
192
194 case QSeries::SeriesTypeStackedBar: {
193 case QSeries::SeriesTypeStackedBar: {
195
194
196 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
195 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
197 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
196 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
198 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
197 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
199 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
198 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
200 // QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
199 // QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
201 m_chartItems.insert(series,item);
200 m_chartItems.insert(series,item);
202 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
201 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
203 break;
202 break;
204 }
203 }
205
204
206 case QSeries::SeriesTypePercentBar: {
205 case QSeries::SeriesTypePercentBar: {
207
206
208 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
207 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
209 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
208 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
210 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
209 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
211 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
210 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
212 // QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
211 // QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
213 m_chartItems.insert(series,item);
212 m_chartItems.insert(series,item);
214 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
213 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
215 break;
214 break;
216 }
215 }
217 case QSeries::SeriesTypeScatter: {
216 case QSeries::SeriesTypeScatter: {
218 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
217 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
219 ScatterChartItem *scatterPresenter = new ScatterChartItem(scatterSeries, m_chart);
218 ScatterChartItem *item;
219 if(m_options.testFlag(QChart::SeriesAnimations)) {
220 item = new ScatterChartAnimationItem(scatterSeries,m_chart);
221 } else {
222 item = new ScatterChartItem(scatterSeries, m_chart);
223 }
220 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
224 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
221 scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
225 item, SLOT(handleGeometryChanged(const QRectF&)));
222 QObject::connect(domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),
226 QObject::connect(domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),
223 scatterPresenter, SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
227 item, SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
224 m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count());
228 //initialize
225 m_chartItems.insert(scatterSeries, scatterPresenter);
226 if (m_rect.isValid())
229 if (m_rect.isValid())
227 scatterPresenter->handleGeometryChanged(m_rect);
230 item->handleGeometryChanged(m_rect);
228 scatterPresenter->handleDomainChanged(domain->minX(), domain->maxX(), domain->minY(), domain->maxY());
231 item->handleDomainChanged(domain->minX(), domain->maxX(), domain->minY(), domain->maxY());
232 //decorate
233 m_chartTheme->decorate(item, scatterSeries, m_chartItems.count());
234 m_chartItems.insert(scatterSeries, item);
235
229 break;
236 break;
230 }
237 }
231 case QSeries::SeriesTypePie: {
238 case QSeries::SeriesTypePie: {
232 QPieSeries *s = qobject_cast<QPieSeries *>(series);
239 QPieSeries *s = qobject_cast<QPieSeries *>(series);
233 PiePresenter* pie = new PiePresenter(m_chart, s);
240 PiePresenter* pie = new PiePresenter(m_chart, s);
234 m_chartTheme->decorate(pie, s, m_chartItems.count());
241 m_chartTheme->decorate(pie, s, m_chartItems.count());
235 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
242 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
236
243
237 // Hide all from background when there is only piechart
244 // Hide all from background when there is only piechart
238 // TODO: refactor this ugly code... should be one setting for this
245 // TODO: refactor this ugly code... should be one setting for this
239 if (m_chartItems.count() == 0) {
246 if (m_chartItems.count() == 0) {
240 m_chart->axisX()->setAxisVisible(false);
247 m_chart->axisX()->setAxisVisible(false);
241 m_chart->axisY()->setAxisVisible(false);
248 m_chart->axisY()->setAxisVisible(false);
242 m_chart->axisX()->setGridVisible(false);
249 m_chart->axisX()->setGridVisible(false);
243 m_chart->axisY()->setGridVisible(false);
250 m_chart->axisY()->setGridVisible(false);
244 m_chart->axisX()->setLabelsVisible(false);
251 m_chart->axisX()->setLabelsVisible(false);
245 m_chart->axisY()->setLabelsVisible(false);
252 m_chart->axisY()->setLabelsVisible(false);
246 m_chart->axisX()->setShadesVisible(false);
253 m_chart->axisX()->setShadesVisible(false);
247 m_chart->axisY()->setShadesVisible(false);
254 m_chart->axisY()->setShadesVisible(false);
248 m_chart->setChartBackgroundBrush(Qt::transparent);
255 m_chart->setChartBackgroundBrush(Qt::transparent);
249 }
256 }
250
257
251 m_chartItems.insert(series, pie);
258 m_chartItems.insert(series, pie);
252 pie->handleGeometryChanged(m_rect);
259 pie->handleGeometryChanged(m_rect);
253 break;
260 break;
254 }
261 }
255
262
256 case QSeries::SeriesTypeSpline: {
263 case QSeries::SeriesTypeSpline: {
264
257 QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series);
265 QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series);
258 SplineChartItem* splinePresenter = new SplineChartItem(splineSeries, m_chart);
266 SplineChartItem* item;
259 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), splinePresenter, SLOT(handleGeometryChanged(const QRectF&)));
267 if(m_options.testFlag(QChart::SeriesAnimations)) {
260 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),splinePresenter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
268 item = new SplineChartAnimationItem(splineSeries, m_chart);
269 } else {
270 item = new SplineChartItem(splineSeries, m_chart);
271 }
272 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), item, SLOT(handleGeometryChanged(const QRectF&)));
273 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
261 //initialize
274 //initialize
262 splinePresenter->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
275 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
263 m_chartTheme->decorate(splinePresenter, splineSeries, m_chartItems.count());
276 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
264 m_chartItems.insert(splineSeries, splinePresenter);
277 //decorate
278 m_chartTheme->decorate(item, splineSeries, m_chartItems.count());
279 m_chartItems.insert(splineSeries, item);
265 break;
280 break;
266 }
281 }
267 default: {
282 default: {
268 qDebug()<< "Series type" << series->type() << "not implemented.";
283 qDebug()<< "Series type" << series->type() << "not implemented.";
269 break;
284 break;
270 }
285 }
271 }
286 }
272
287
273 zoomReset();
288 zoomReset();
274 }
289 }
275
290
276 void ChartPresenter::handleSeriesRemoved(QSeries* series)
291 void ChartPresenter::handleSeriesRemoved(QSeries* series)
277 {
292 {
278 ChartItem* item = m_chartItems.take(series);
293 ChartItem* item = m_chartItems.take(series);
279 delete item;
294 delete item;
280 }
295 }
281
296
282 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
297 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
283 {
298 {
284 delete m_chartTheme;
299 delete m_chartTheme;
285
300
286 m_chartTheme = ChartTheme::createTheme(theme);
301 m_chartTheme = ChartTheme::createTheme(theme);
287
302
288 m_chartTheme->decorate(m_chart);
303 m_chartTheme->decorate(m_chart);
289 QMapIterator<QSeries*,ChartItem*> i(m_chartItems);
304 QMapIterator<QSeries*,ChartItem*> i(m_chartItems);
290
305
291 int index=0;
306 int index=0;
292 while (i.hasNext()) {
307 while (i.hasNext()) {
293 i.next();
308 i.next();
294 m_chartTheme->decorate(i.value(),i.key(),index);
309 m_chartTheme->decorate(i.value(),i.key(),index);
295 index++;
310 index++;
296 }
311 }
297
312
298 QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems);
313 QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems);
299 while (j.hasNext()) {
314 while (j.hasNext()) {
300 j.next();
315 j.next();
301 m_chartTheme->decorate(j.key(),j.value());
316 m_chartTheme->decorate(j.key(),j.value());
302 }
317 }
303 }
318 }
304
319
305 QChart::ChartTheme ChartPresenter::chartTheme()
320 QChart::ChartTheme ChartPresenter::chartTheme()
306 {
321 {
307 return m_chartTheme->id();
322 return m_chartTheme->id();
308 }
323 }
309
324
310 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
325 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
311 {
326 {
312 if(m_options!=options) {
327 if(m_options!=options) {
313
328
314 m_options=options;
329 m_options=options;
315
330
316 //recreate elements
331 //recreate elements
317 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
332 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
318 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
333 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
319
334
320 foreach(QChartAxis* axis, axisList) {
335 foreach(QChartAxis* axis, axisList) {
321 handleAxisRemoved(axis);
336 handleAxisRemoved(axis);
322 handleAxisAdded(axis,m_dataset->domain(axis));
337 handleAxisAdded(axis,m_dataset->domain(axis));
323 }
338 }
324 foreach(QSeries* series, seriesList) {
339 foreach(QSeries* series, seriesList) {
325 handleSeriesRemoved(series);
340 handleSeriesRemoved(series);
326 handleSeriesAdded(series,m_dataset->domain(series));
341 handleSeriesAdded(series,m_dataset->domain(series));
327 }
342 }
328 }
343 }
329 }
344 }
330
345
331 void ChartPresenter::zoomIn()
346 void ChartPresenter::zoomIn()
332 {
347 {
333 QRectF rect = geometry();
348 QRectF rect = geometry();
334 rect.setWidth(rect.width()/2);
349 rect.setWidth(rect.width()/2);
335 rect.setHeight(rect.height()/2);
350 rect.setHeight(rect.height()/2);
336 rect.moveCenter(geometry().center());
351 rect.moveCenter(geometry().center());
337 zoomIn(rect);
352 zoomIn(rect);
338 }
353 }
339
354
340 void ChartPresenter::zoomIn(const QRectF& rect)
355 void ChartPresenter::zoomIn(const QRectF& rect)
341 {
356 {
342 QRectF r = rect.normalized();
357 QRectF r = rect.normalized();
343 r.translate(-m_marginSize, -m_marginSize);
358 r.translate(-m_marginSize, -m_marginSize);
344 m_dataset->zoomInDomain(r,geometry().size());
359 m_dataset->zoomInDomain(r,geometry().size());
345 m_zoomStack<<r;
360 m_zoomStack<<r;
346 m_zoomIndex++;
361 m_zoomIndex++;
347 }
362 }
348
363
349 void ChartPresenter::zoomOut()
364 void ChartPresenter::zoomOut()
350 {
365 {
351 if(m_zoomIndex==0) return;
366 if(m_zoomIndex==0) return;
352 m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
367 m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
353 m_zoomIndex--;
368 m_zoomIndex--;
354 m_zoomStack.resize(m_zoomIndex);
369 m_zoomStack.resize(m_zoomIndex);
355 }
370 }
356
371
357 void ChartPresenter::zoomReset()
372 void ChartPresenter::zoomReset()
358 {
373 {
359 m_zoomIndex=0;
374 m_zoomIndex=0;
360 m_zoomStack.resize(m_zoomIndex);
375 m_zoomStack.resize(m_zoomIndex);
361 }
376 }
362
377
363 QChart::AnimationOptions ChartPresenter::animationOptions() const
378 QChart::AnimationOptions ChartPresenter::animationOptions() const
364 {
379 {
365 return m_options;
380 return m_options;
366 }
381 }
367
382
368
383
369 #include "moc_chartpresenter_p.cpp"
384 #include "moc_chartpresenter_p.cpp"
370
385
371 QTCOMMERCIALCHART_END_NAMESPACE
386 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,328 +1,329
1 #include "charttheme_p.h"
1 #include "charttheme_p.h"
2 #include "qchart.h"
2 #include "qchart.h"
3 #include "qchartaxis.h"
3 #include "qchartaxis.h"
4 #include <QTime>
4 #include <QTime>
5
5
6 //series
6 //series
7 #include "qbarset.h"
7 #include "qbarset.h"
8 #include "qbarseries.h"
8 #include "qbarseries.h"
9 #include "qstackedbarseries.h"
9 #include "qstackedbarseries.h"
10 #include "qpercentbarseries.h"
10 #include "qpercentbarseries.h"
11 #include "qlineseries.h"
11 #include "qlineseries.h"
12 #include "qareaseries.h"
12 #include "qareaseries.h"
13 #include "qscatterseries.h"
13 #include "qscatterseries.h"
14 #include "qpieseries.h"
14 #include "qpieseries.h"
15 #include "qpieslice.h"
15 #include "qpieslice.h"
16 #include "qsplineseries.h"
16 #include "qsplineseries.h"
17
17
18 //items
18 //items
19 #include "axisitem_p.h"
19 #include "axisitem_p.h"
20 #include "barpresenter_p.h"
20 #include "barpresenter_p.h"
21 #include "stackedbarpresenter_p.h"
21 #include "stackedbarpresenter_p.h"
22 #include "percentbarpresenter_p.h"
22 #include "percentbarpresenter_p.h"
23 #include "linechartitem_p.h"
23 #include "linechartitem_p.h"
24 #include "areachartitem_p.h"
24 #include "areachartitem_p.h"
25 #include "scatterchartitem_p.h"
25 #include "scatterchartitem_p.h"
26 #include "piepresenter_p.h"
26 #include "piepresenter_p.h"
27 #include "splinechartitem_p.h"
27 #include "splinechartitem_p.h"
28
28
29 //themes
29 //themes
30 #include "chartthemevanilla_p.h"
30 #include "chartthemevanilla_p.h"
31 #include "chartthemeicy_p.h"
31 #include "chartthemeicy_p.h"
32 #include "chartthemegrayscale_p.h"
32 #include "chartthemegrayscale_p.h"
33 #include "chartthemescientific_p.h"
33 #include "chartthemescientific_p.h"
34
34
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 /* TODO
38 /* TODO
39 case QChart::ChartThemeUnnamed1:
39 case QChart::ChartThemeUnnamed1:
40 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
40 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
41 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
41 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
42 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
42 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
43 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
43 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
44 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
44 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
45
45
46 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
46 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
47 m_gradientEndColor = QColor(QRgb(0xffafafaf));
47 m_gradientEndColor = QColor(QRgb(0xffafafaf));
48 */
48 */
49
49
50 ChartTheme::ChartTheme(QChart::ChartTheme id)
50 ChartTheme::ChartTheme(QChart::ChartTheme id)
51 {
51 {
52 m_id = id;
52 m_id = id;
53 m_seriesColor.append(QRgb(0xff000000));
53 m_seriesColor.append(QRgb(0xff000000));
54 m_seriesColor.append(QRgb(0xff707070));
54 m_seriesColor.append(QRgb(0xff707070));
55 m_gradientStartColor = QColor(QRgb(0xffffffff));
55 m_gradientStartColor = QColor(QRgb(0xffffffff));
56 m_gradientEndColor = QColor(QRgb(0xffafafaf));
56 m_gradientEndColor = QColor(QRgb(0xffafafaf));
57
57
58 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
58 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
59 }
59 }
60
60
61
61
62 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
62 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
63 {
63 {
64 switch(theme) {
64 switch(theme) {
65 case QChart::ChartThemeDefault:
65 case QChart::ChartThemeDefault:
66 return new ChartTheme();
66 return new ChartTheme();
67 case QChart::ChartThemeVanilla:
67 case QChart::ChartThemeVanilla:
68 return new ChartThemeVanilla();
68 return new ChartThemeVanilla();
69 case QChart::ChartThemeIcy:
69 case QChart::ChartThemeIcy:
70 return new ChartThemeIcy();
70 return new ChartThemeIcy();
71 case QChart::ChartThemeGrayscale:
71 case QChart::ChartThemeGrayscale:
72 return new ChartThemeGrayscale();
72 return new ChartThemeGrayscale();
73 case QChart::ChartThemeScientific:
73 case QChart::ChartThemeScientific:
74 return new ChartThemeScientific();
74 return new ChartThemeScientific();
75 }
75 }
76 }
76 }
77
77
78 void ChartTheme::decorate(QChart* chart)
78 void ChartTheme::decorate(QChart* chart)
79 {
79 {
80 QLinearGradient backgroundGradient;
80 QLinearGradient backgroundGradient;
81 backgroundGradient.setColorAt(0.0, m_gradientStartColor);
81 backgroundGradient.setColorAt(0.0, m_gradientStartColor);
82 backgroundGradient.setColorAt(1.0, m_gradientEndColor);
82 backgroundGradient.setColorAt(1.0, m_gradientEndColor);
83 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
83 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
84 chart->setChartBackgroundBrush(backgroundGradient);
84 chart->setChartBackgroundBrush(backgroundGradient);
85 }
85 }
86 //TODO helper to by removed later
86 //TODO helper to by removed later
87 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count)
87 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count)
88 {
88 {
89 switch(series->type())
89 switch(series->type())
90 {
90 {
91 case QSeries::SeriesTypeLine: {
91 case QSeries::SeriesTypeLine: {
92 QLineSeries* s = static_cast<QLineSeries*>(series);
92 QLineSeries* s = static_cast<QLineSeries*>(series);
93 LineChartItem* i = static_cast<LineChartItem*>(item);
93 LineChartItem* i = static_cast<LineChartItem*>(item);
94 decorate(i,s,count);
94 decorate(i,s,count);
95 break;
95 break;
96 }
96 }
97 case QSeries::SeriesTypeArea: {
97 case QSeries::SeriesTypeArea: {
98 QAreaSeries* s = static_cast<QAreaSeries*>(series);
98 QAreaSeries* s = static_cast<QAreaSeries*>(series);
99 AreaChartItem* i = static_cast<AreaChartItem*>(item);
99 AreaChartItem* i = static_cast<AreaChartItem*>(item);
100 decorate(i,s,count);
100 decorate(i,s,count);
101 break;
101 break;
102 }
102 }
103 case QSeries::SeriesTypeBar: {
103 case QSeries::SeriesTypeBar: {
104 QBarSeries* b = static_cast<QBarSeries*>(series);
104 QBarSeries* b = static_cast<QBarSeries*>(series);
105 BarPresenter* i = static_cast<BarPresenter*>(item);
105 BarPresenter* i = static_cast<BarPresenter*>(item);
106 decorate(i,b,count);
106 decorate(i,b,count);
107 break;
107 break;
108 }
108 }
109 case QSeries::SeriesTypeStackedBar: {
109 case QSeries::SeriesTypeStackedBar: {
110 QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series);
110 QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series);
111 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
111 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
112 decorate(i,s,count);
112 decorate(i,s,count);
113 break;
113 break;
114 }
114 }
115 case QSeries::SeriesTypePercentBar: {
115 case QSeries::SeriesTypePercentBar: {
116 QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series);
116 QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series);
117 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
117 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
118 decorate(i,s,count);
118 decorate(i,s,count);
119 break;
119 break;
120 }
120 }
121 case QSeries::SeriesTypeScatter: {
121 case QSeries::SeriesTypeScatter: {
122 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
122 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
123 Q_ASSERT(s);
123 Q_ASSERT(s);
124 ScatterChartItem* i = static_cast<ScatterChartItem*>(item);
124 ScatterChartItem* i = static_cast<ScatterChartItem*>(item);
125 Q_ASSERT(i);
125 Q_ASSERT(i);
126 decorate(i, s, count);
126 decorate(i, s, count);
127 break;
127 break;
128 }
128 }
129 case QSeries::SeriesTypePie: {
129 case QSeries::SeriesTypePie: {
130 QPieSeries* s = static_cast<QPieSeries*>(series);
130 QPieSeries* s = static_cast<QPieSeries*>(series);
131 PiePresenter* i = static_cast<PiePresenter*>(item);
131 PiePresenter* i = static_cast<PiePresenter*>(item);
132 decorate(i,s,count);
132 decorate(i,s,count);
133 break;
133 break;
134 }
134 }
135 default:
135 default:
136 qDebug()<<"Wrong item to be decorated by theme";
136 qDebug()<<"Wrong item to be decorated by theme";
137 break;
137 break;
138 }
138 }
139
139
140 }
140 }
141
141
142 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count)
142 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count)
143 {
143 {
144 QPen pen;
144 QPen pen;
145 QBrush brush;
145 QBrush brush;
146
146
147 if(pen != series->pen()){
147 if(pen != series->pen()){
148 item->setPen(series->pen());
148 item->setPen(series->pen());
149 }else{
149 }else{
150 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
150 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
151 pen.setWidthF(2);
151 pen.setWidthF(2);
152 item->setPen(pen);
152 item->setPen(pen);
153 }
153 }
154
154
155 if(brush != series->brush()){
155 if(brush != series->brush()){
156 item->setBrush(series->brush());
156 item->setBrush(series->brush());
157 }else{
157 }else{
158 QBrush brush(m_seriesColor.at(count%m_seriesColor.size()));
158 QBrush brush(m_seriesColor.at(count%m_seriesColor.size()));
159 item->setBrush(brush);
159 item->setBrush(brush);
160 }
160 }
161 }
161 }
162
162
163
163
164 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
164 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
165 {
165 {
166 QPen pen;
166 QPen pen;
167 if(pen != series->pen()){
167 if(pen != series->pen()){
168 item->setPen(series->pen());
168 item->setLinePen(series->pen());
169 return;
169 return;
170 }
170 }
171 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
171 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
172 pen.setWidthF(2);
172 pen.setWidthF(2);
173 item->setPen(pen);
173 item->setLinePen(pen);
174 }
174 }
175
175
176 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
176 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
177 {
177 {
178 QList<QBarSet*> sets = series->barSets();
178 QList<QBarSet*> sets = series->barSets();
179 for (int i=0; i<series->barsetCount(); i++) {
179 for (int i=0; i<series->barsetCount(); i++) {
180 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
180 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
181 }
181 }
182 }
182 }
183
183
184 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
184 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
185 {
185 {
186 QList<QBarSet*> sets = series->barSets();
186 QList<QBarSet*> sets = series->barSets();
187 for (int i=0; i<series->barsetCount(); i++) {
187 for (int i=0; i<series->barsetCount(); i++) {
188 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
188 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
189 }
189 }
190 }
190 }
191
191
192 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
192 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
193 {
193 {
194 QList<QBarSet*> sets = series->barSets();
194 QList<QBarSet*> sets = series->barSets();
195 for (int i=0; i<series->barsetCount(); i++) {
195 for (int i=0; i<series->barsetCount(); i++) {
196 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
196 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
197 }
197 }
198 }
198 }
199
199
200 void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int count)
200 void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int count)
201 {
201 {
202 Q_ASSERT(item);
202 Q_ASSERT(item);
203 Q_ASSERT(series);
203 Q_ASSERT(series);
204
204
205 QColor color = m_seriesColor.at(count % m_seriesColor.size());
205 QColor color = m_seriesColor.at(count % m_seriesColor.size());
206 // TODO: define alpha in the theme? or in the series?
206 // TODO: define alpha in the theme? or in the series?
207 //color.setAlpha(120);
207 //color.setAlpha(120);
208
208
209 QBrush brush(color, Qt::SolidPattern);
209 QBrush brush(color, Qt::SolidPattern);
210 item->setBrush(Qt::blue);
210 item->setBrush(Qt::blue);
211
211
212 QPen pen(brush, 3);
212 QPen pen(brush, 3);
213 pen.setColor(color);
213 pen.setColor(color);
214 item->setPen(pen);
214 item->setPen(pen);
215 }
215 }
216
216
217 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/)
217 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/)
218 {
218 {
219 // create a list of slice colors based on current theme
219 // create a list of slice colors based on current theme
220 int i = 0;
220 int i = 0;
221 QList<QColor> colors;
221 QList<QColor> colors;
222 while (colors.count() < series->count()) {
222 while (colors.count() < series->count()) {
223
223
224 // get base color
224 // get base color
225 QColor c = m_seriesColor[i++];
225 QColor c = m_seriesColor[i++];
226 i = i % m_seriesColor.count();
226 i = i % m_seriesColor.count();
227
227
228 // dont use black colors... looks bad
228 // dont use black colors... looks bad
229 if (c == Qt::black)
229 if (c == Qt::black)
230 continue;
230 continue;
231
231
232 // by default use the "raw" theme color
232 // by default use the "raw" theme color
233 if (!colors.contains(c)) {
233 if (!colors.contains(c)) {
234 colors << c;
234 colors << c;
235 continue;
235 continue;
236 }
236 }
237 // ...ok we need to generate something that looks like the same color
237 // ...ok we need to generate something that looks like the same color
238 // but different lightness
238 // but different lightness
239
239
240 int tryCount = 0;
240 int tryCount = 0;
241 while (tryCount++ < 100) {
241 while (tryCount++ < 100) {
242
242
243 // find maximum value we can raise the lightness
243 // find maximum value we can raise the lightness
244 int lMax = 255;
244 int lMax = 255;
245 if (lMax > 255 - c.red())
245 if (lMax > 255 - c.red())
246 lMax = 255 - c.red();
246 lMax = 255 - c.red();
247 if (lMax > 255 - c.green())
247 if (lMax > 255 - c.green())
248 lMax = 255 - c.green();
248 lMax = 255 - c.green();
249 if (lMax > 255 - c.blue())
249 if (lMax > 255 - c.blue())
250 lMax = 255 - c.blue();
250 lMax = 255 - c.blue();
251
251
252 // find maximum value we can make it darker
252 // find maximum value we can make it darker
253 int dMax = 255;
253 int dMax = 255;
254 if (dMax > c.red())
254 if (dMax > c.red())
255 dMax = c.red();
255 dMax = c.red();
256 if (dMax > c.green())
256 if (dMax > c.green())
257 dMax = c.green();
257 dMax = c.green();
258 if (dMax > c.blue())
258 if (dMax > c.blue())
259 dMax = c.blue();
259 dMax = c.blue();
260
260
261 int max = dMax + lMax;
261 int max = dMax + lMax;
262 if (max == 0) {
262 if (max == 0) {
263 // no room to make color lighter or darker...
263 // no room to make color lighter or darker...
264 qDebug() << "cannot generate a color for pie!";
264 qDebug() << "cannot generate a color for pie!";
265 break;
265 break;
266 }
266 }
267
267
268 // generate random color
268 // generate random color
269 int r = c.red() - dMax;
269 int r = c.red() - dMax;
270 int g = c.green() - dMax;
270 int g = c.green() - dMax;
271 int b = c.blue() - dMax;
271 int b = c.blue() - dMax;
272 int d = qrand() % max;
272 int d = qrand() % max;
273 c.setRgb(r+d, g+d, b+d);
273 c.setRgb(r+d, g+d, b+d);
274
274
275 // found a unique color?
275 // found a unique color?
276 if (!colors.contains(c))
276 if (!colors.contains(c))
277 break;
277 break;
278 }
278 }
279
279
280 qDebug() << "generated a color for pie" << c;
280 qDebug() << "generated a color for pie" << c;
281 colors << c;
281 colors << c;
282 }
282 }
283
283
284 // finally update colors
284 // finally update colors
285 foreach (QPieSlice* s, series->slices()) {
285 foreach (QPieSlice* s, series->slices()) {
286 QColor c = colors.takeFirst();
286 QColor c = colors.takeFirst();
287 s->setSlicePen(c);
287 s->setSlicePen(c);
288 s->setSliceBrush(c);
288 s->setSliceBrush(c);
289 }
289 }
290 }
290 }
291
291
292
292
293 void ChartTheme::decorate(QChartAxis* axis,AxisItem* item)
293 void ChartTheme::decorate(QChartAxis* axis,AxisItem* item)
294 {
294 {
295 //TODO: dummy defults for now
295 //TODO: dummy defults for now
296 axis->setLabelsBrush(Qt::black);
296 axis->setLabelsBrush(Qt::black);
297 axis->setLabelsPen(Qt::NoPen);
297 axis->setLabelsPen(Qt::NoPen);
298 axis->setShadesPen(Qt::NoPen);
298 axis->setShadesPen(Qt::NoPen);
299 axis->setShadesOpacity(0.5);
299 axis->setShadesOpacity(0.5);
300 }
300 }
301
301
302 void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int count)
302 void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int count)
303 {
303 {
304 Q_ASSERT(item);
304 Q_ASSERT(item);
305 Q_ASSERT(series);
305 Q_ASSERT(series);
306
306
307 QPen pen;
307 QPen pen;
308
308 if(pen != series->pen()){
309 if(pen != series->pen()){
309 item->setPen(series->pen());
310 item->setLinePen(series->pen());
310 return;
311 }else{
311 }
312 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
312 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
313 pen.setWidthF(series->pen().widthF());
313 pen.setWidthF(series->pen().widthF());
314 item->setPen(pen);
314 item->setLinePen(series->pen());
315 }
315
316
316 // QColor color = m_seriesColor.at(count % m_seriesColor.size());
317 // QColor color = m_seriesColor.at(count % m_seriesColor.size());
317 // TODO: define alpha in the theme? or in the series?
318 // TODO: define alpha in the theme? or in the series?
318 //color.setAlpha(120);
319 //color.setAlpha(120);
319
320
320 // QBrush brush(color, Qt::SolidPattern);
321 // QBrush brush(color, Qt::SolidPattern);
321 // presenter->m_markerBrush = brush;
322 // presenter->m_markerBrush = brush;
322
323
323 // QPen pen(brush, 3);
324 // QPen pen(brush, 3);
324 // pen.setColor(color);
325 // pen.setColor(color);
325 // presenter->m_markerPen = pen;
326 // presenter->m_markerPen = pen;
326 }
327 }
327
328
328 QTCOMMERCIALCHART_END_NAMESPACE
329 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,14 +1,12
1 INCLUDEPATH += $$PWD
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3
4 SOURCES += \
4 SOURCES += \
5 $$PWD/linechartanimationitem.cpp \
6 $$PWD/linechartitem.cpp \
5 $$PWD/linechartitem.cpp \
7 $$PWD/qlineseries.cpp
6 $$PWD/qlineseries.cpp
8
7
9 PRIVATE_HEADERS += \
8 PRIVATE_HEADERS += \
10 $$PWD/linechartitem_p.h \
9 $$PWD/linechartitem_p.h
11 $$PWD/linechartanimationitem_p.h
12
10
13 PUBLIC_HEADERS += \
11 PUBLIC_HEADERS += \
14 $$PWD/qlineseries.h No newline at end of file
12 $$PWD/qlineseries.h
@@ -1,112 +1,111
1 #include "linechartanimationitem_p.h"
1 #include "linechartanimationitem_p.h"
2 #include "linechartitem_p.h"
2 #include "linechartitem_p.h"
3 #include <QPropertyAnimation>
3 #include <QPropertyAnimation>
4 #include <QTimer>
4 #include <QTimer>
5
5
6 Q_DECLARE_METATYPE(QVector<QPointF>)
6 Q_DECLARE_METATYPE(QVector<QPointF>)
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 const static int duration = 500;
10 const static int duration = 500;
11
11
12 LineChartAnimationItem::LineChartAnimationItem(QLineSeries* series,QGraphicsItem *parent):
12 LineChartAnimationItem::LineChartAnimationItem(QLineSeries* series,QGraphicsItem *parent):
13 LineChartItem(series,parent),
13 LineChartItem(series,parent),
14 m_animation(new LineChartAnimatator(this,this)),
14 m_animation(new LineChartAnimatator(this,this)),
15 m_dirty(false)
15 m_dirty(false)
16 {
16 {
17 }
17 }
18
18
19 LineChartAnimationItem::~LineChartAnimationItem()
19 LineChartAnimationItem::~LineChartAnimationItem()
20 {
20 {
21 }
21 }
22
22
23 void LineChartAnimationItem::updatePoints(QVector<QPointF>& newPoints)
23 void LineChartAnimationItem::updatePoints(QVector<QPointF>& newPoints)
24 {
24 {
25 QVector<QPointF> oldPoints = points();
25 QVector<QPointF> oldPoints = points();
26 LineChartItem::updatePoints(newPoints);
26 LineChartItem::updatePoints(newPoints);
27
27
28 if(newPoints.count()==0) return;
28 if(newPoints.count()==0) return;
29 oldPoints.resize(newPoints.size());
29 oldPoints.resize(newPoints.size());
30
30
31 if(m_animation->state()!=QAbstractAnimation::Stopped){
31 if(m_animation->state()!=QAbstractAnimation::Stopped){
32 m_animation->stop();
32 m_animation->stop();
33 }
33 }
34
34
35 m_animation->setDuration(duration);
35 m_animation->setDuration(duration);
36 m_animation->setEasingCurve(QEasingCurve::InOutBack);
36 m_animation->setEasingCurve(QEasingCurve::InOutBack);
37 m_animation->setKeyValueAt(0.0, qVariantFromValue(oldPoints));
37 m_animation->setKeyValueAt(0.0, qVariantFromValue(oldPoints));
38 m_animation->setKeyValueAt(1.0, qVariantFromValue(newPoints));
38 m_animation->setKeyValueAt(1.0, qVariantFromValue(newPoints));
39 QTimer::singleShot(0,m_animation,SLOT(start()));
39 QTimer::singleShot(0,m_animation,SLOT(start()));
40
40
41
42 m_points = newPoints;
41 m_points = newPoints;
43 m_dirty=false;
42 m_dirty=false;
44
43
45 }
44 }
46
45
47 void LineChartAnimationItem::updatePoint(int index,QPointF& newPoint)
46 void LineChartAnimationItem::updatePoint(int index,QPointF& newPoint)
48 {
47 {
49
48
50 if(m_animation->state()!=QAbstractAnimation::Stopped){
49 if(m_animation->state()!=QAbstractAnimation::Stopped){
51 m_animation->stop();
50 m_animation->stop();
52 m_dirty=true;
51 m_dirty=true;
53 }
52 }
54
53
55 if(m_dirty){
54 if(m_dirty){
56 m_points=points();
55 m_points=points();
57 m_dirty=false;
56 m_dirty=false;
58 }
57 }
59
58
60 LineChartItem::updatePoint(index,newPoint);
59 LineChartItem::updatePoint(index,newPoint);
61
60
62 m_animation->setDuration(duration);
61 m_animation->setDuration(duration);
63 m_animation->setEasingCurve(QEasingCurve::InOutBack);
62 m_animation->setEasingCurve(QEasingCurve::InOutBack);
64 m_animation->setKeyValueAt(0.0, qVariantFromValue(m_points));
63 m_animation->setKeyValueAt(0.0, qVariantFromValue(m_points));
65 m_animation->setKeyValueAt(1.0, qVariantFromValue( points()));
64 m_animation->setKeyValueAt(1.0, qVariantFromValue( points()));
66
65
67 QTimer::singleShot(0,this,SLOT(startAnimation()));
66 QTimer::singleShot(0,this,SLOT(startAnimation()));
68
67
69
68
70 }
69 }
71
70
72 void LineChartAnimationItem::startAnimation()
71 void LineChartAnimationItem::startAnimation()
73 {
72 {
74 m_dirty=true;
73 m_dirty=true;
75 m_animation->start();
74 m_animation->start();
76 }
75 }
77
76
78 LineChartAnimatator::LineChartAnimatator(LineChartAnimationItem *item , QObject *parent):QVariantAnimation(parent),
77 LineChartAnimatator::LineChartAnimatator(LineChartAnimationItem *item , QObject *parent):QVariantAnimation(parent),
79 m_item(item)
78 m_item(item)
80 {
79 {
81 }
80 }
82
81
83 LineChartAnimatator::~LineChartAnimatator()
82 LineChartAnimatator::~LineChartAnimatator()
84 {
83 {
85 }
84 }
86
85
87 QVariant LineChartAnimatator::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const
86 QVariant LineChartAnimatator::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const
88 {
87 {
89 QVector<QPointF> startVector = qVariantValue<QVector<QPointF> >(start);
88 QVector<QPointF> startVector = qVariantValue<QVector<QPointF> >(start);
90 QVector<QPointF> endVecotr = qVariantValue<QVector<QPointF> >(end);
89 QVector<QPointF> endVecotr = qVariantValue<QVector<QPointF> >(end);
91 QVector<QPointF> result;
90 QVector<QPointF> result;
92 Q_ASSERT(startVector.count() == endVecotr.count());
91 Q_ASSERT(startVector.count() == endVecotr.count());
93
92
94 for(int i =0 ;i< startVector.count();i++){
93 for(int i =0 ;i< startVector.count();i++){
95 qreal x = startVector[i].x() + ((endVecotr[i].x()- startVector[i].x()) * progress);//qBound(0.0, progress, 1.0));
94 qreal x = startVector[i].x() + ((endVecotr[i].x()- startVector[i].x()) * progress);//qBound(0.0, progress, 1.0));
96 qreal y = startVector[i].y() + ((endVecotr[i].y()- startVector[i].y()) * progress);//qBound(0.0, progress, 1.0));
95 qreal y = startVector[i].y() + ((endVecotr[i].y()- startVector[i].y()) * progress);//qBound(0.0, progress, 1.0));
97 result << QPointF(x,y);
96 result << QPointF(x,y);
98 }
97 }
99 return qVariantFromValue(result);
98 return qVariantFromValue(result);
100 }
99 }
101
100
102 void LineChartAnimatator::updateCurrentValue (const QVariant & value )
101 void LineChartAnimatator::updateCurrentValue (const QVariant & value )
103 {
102 {
104 QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value);
103 QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value);
105 if(state()!=QAbstractAnimation::Stopped){ //workaround
104 if(state()!=QAbstractAnimation::Stopped){ //workaround
106 m_item->setGeometry(vector);
105 m_item->setGeometry(vector);
107 }
106 }
108 }
107 }
109
108
110 #include "moc_linechartanimationitem_p.cpp"
109 #include "moc_linechartanimationitem_p.cpp"
111
110
112 QTCOMMERCIALCHART_END_NAMESPACE
111 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,124 +1,123
1 #include "linechartitem_p.h"
1 #include "linechartitem_p.h"
2 #include "qlineseries.h"
2 #include "qlineseries.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include <QPainter>
4 #include <QPainter>
5
5
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 //TODO: optimize : remove points which are not visible
9 //TODO: optimize : remove points which are not visible
10
10
11 LineChartItem::LineChartItem(QLineSeries* series,QGraphicsItem *parent):XYChartItem(series,parent),
11 LineChartItem::LineChartItem(QLineSeries* series,QGraphicsItem *parent):XYChartItem(series,parent),
12 m_series(series),
12 m_series(series),
13 m_items(this)
13 m_items(this)
14 {
14 {
15 //m_items.setZValue(ChartPresenter::LineChartZValue);
15 //m_items.setZValue(ChartPresenter::LineChartZValue);
16 setZValue(ChartPresenter::LineChartZValue);
16 setZValue(ChartPresenter::LineChartZValue);
17 QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated()));
17 QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated()));
18
18
19 handleUpdated();
19 handleUpdated();
20 }
20 }
21
21
22 QRectF LineChartItem::boundingRect() const
22 QRectF LineChartItem::boundingRect() const
23 {
23 {
24 return m_rect;
24 return m_rect;
25 }
25 }
26
26
27 QPainterPath LineChartItem::shape() const
27 QPainterPath LineChartItem::shape() const
28 {
28 {
29 return m_path;
29 return m_path;
30 }
30 }
31
31
32 void LineChartItem::createPoints(int count)
32 void LineChartItem::createPoints(int count)
33 {
33 {
34 for (int i = 0; i < count; ++i) {
34 for (int i = 0; i < count; ++i) {
35 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3);
35 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3);
36 m_items.addToGroup(item);
36 m_items.addToGroup(item);
37 }
37 }
38 }
38 }
39
39
40 void LineChartItem::deletePoints(int count)
40 void LineChartItem::deletePoints(int count)
41 {
41 {
42 QList<QGraphicsItem *> items = m_items.childItems();
42 QList<QGraphicsItem *> items = m_items.childItems();
43
43
44 for (int i = 0; i < count; ++i) {
44 for (int i = 0; i < count; ++i) {
45 delete(items.takeLast());
45 delete(items.takeLast());
46 }
46 }
47 }
47 }
48
48
49 void LineChartItem::setGeometry(QVector<QPointF>& points)
49 void LineChartItem::setGeometry(QVector<QPointF>& points)
50 {
50 {
51 if(points.size()==0) return;
51 if(points.size()==0) return;
52
52
53 int diff = XYChartItem::points().size() - points.size();
53 int diff = XYChartItem::points().size() - points.size();
54
54
55 if(diff>0) {
55 if(diff>0) {
56 deletePoints(diff);
56 deletePoints(diff);
57 }
57 }
58 else if(diff<0) {
58 else if(diff<0) {
59 createPoints(-diff);
59 createPoints(-diff);
60 }
60 }
61
61
62 QList<QGraphicsItem*> items = m_items.childItems();
62 QList<QGraphicsItem*> items = m_items.childItems();
63
63
64 QPainterPath path;
64 QPainterPath path;
65 const QPointF& point = points.at(0);
65 const QPointF& point = points.at(0);
66 path.moveTo(point);
66 path.moveTo(point);
67 QGraphicsItem* item = items.at(0);
67 QGraphicsItem* item = items.at(0);
68 item->setPos(point.x()-1,point.y()-1);
68 item->setPos(point.x()-1,point.y()-1);
69 if(!clipRect().contains(point)) {
69 if(!clipRect().contains(point)) {
70 item->setVisible(false);
70 item->setVisible(false);
71 }
71 }
72 else {
72 else {
73 item->setVisible(true);
73 item->setVisible(true);
74 }
74 }
75
75
76 for(int i=1; i< points.size();i++) {
76 for(int i=1; i< points.size();i++) {
77 QGraphicsItem* item = items.at(i);
77 QGraphicsItem* item = items.at(i);
78 const QPointF& point = points.at(i);
78 const QPointF& point = points.at(i);
79 item->setPos(point.x()-1,point.y()-1);
79 item->setPos(point.x()-1,point.y()-1);
80 if(!clipRect().contains(point)) {
80 if(!clipRect().contains(point)) {
81 item->setVisible(false);
81 item->setVisible(false);
82 }
82 }
83 else {
83 else {
84 item->setVisible(true);
84 item->setVisible(true);
85 }
85 }
86 path.lineTo(point);
86 path.lineTo(point);
87 }
87 }
88
88
89 prepareGeometryChange();
89 prepareGeometryChange();
90 m_path = path;
90 m_path = path;
91 m_rect = path.boundingRect();
91 m_rect = path.boundingRect();
92
92
93 XYChartItem::setGeometry(points);
93 XYChartItem::setGeometry(points);
94 }
94 }
95
95
96 void LineChartItem::setPen(const QPen& pen)
96 void LineChartItem::setLinePen(const QPen& pen)
97 {
97 {
98 m_pen = pen;
98 m_pen = pen;
99 }
99 }
100
100
101
102 void LineChartItem::handleUpdated()
101 void LineChartItem::handleUpdated()
103 {
102 {
104 m_items.setVisible(m_series->pointsVisible());
103 m_items.setVisible(m_series->pointsVisible());
105 setPen(m_series->pen());
104 setLinePen(m_series->pen());
106 update();
105 update();
107 }
106 }
108
107
109 //painter
108 //painter
110
109
111 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
110 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
112 {
111 {
113 Q_UNUSED(widget);
112 Q_UNUSED(widget);
114 Q_UNUSED(option);
113 Q_UNUSED(option);
115 painter->save();
114 painter->save();
116 painter->setPen(m_pen);
115 painter->setPen(m_pen);
117 painter->setClipRect(clipRect());
116 painter->setClipRect(clipRect());
118 painter->drawPath(m_path);
117 painter->drawPath(m_path);
119 painter->restore();
118 painter->restore();
120 }
119 }
121
120
122 #include "moc_linechartitem_p.cpp"
121 #include "moc_linechartitem_p.cpp"
123
122
124 QTCOMMERCIALCHART_END_NAMESPACE
123 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,51 +1,54
1 #ifndef LINECHARTITEM_H
1 #ifndef LINECHARTITEM_H
2 #define LINECHARTITEM_H
2 #define LINECHARTITEM_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "xychartitem_p.h"
5 #include "xychartitem_p.h"
6 #include "xychartanimationitem_p.h"
6 #include <QPen>
7 #include <QPen>
7
8
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10
10 class ChartPresenter;
11 class ChartPresenter;
11 class QLineSeries;
12 class QLineSeries;
12
13
13 class LineChartItem : public XYChartItem
14 class LineChartItem : public XYChartItem
14 {
15 {
15 Q_OBJECT
16 Q_OBJECT
16 public:
17 public:
17 explicit LineChartItem(QLineSeries* series,QGraphicsItem *parent = 0);
18 explicit LineChartItem(QLineSeries* series,QGraphicsItem *parent = 0);
18 ~ LineChartItem(){};
19 ~ LineChartItem(){};
19
20
20 //from QGraphicsItem
21 //from QGraphicsItem
21 QRectF boundingRect() const;
22 QRectF boundingRect() const;
22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 QPainterPath shape() const;
24 QPainterPath shape() const;
24
25
25 void setPen(const QPen& pen);
26 void setLinePen(const QPen& pen);
26 void setPointsVisible(bool visible);
27 void setPointsVisible(bool visible);
27
28
28 public slots:
29 public slots:
29 void handleUpdated();
30 void handleUpdated();
30
31
31 protected:
32 protected:
32 virtual void setGeometry(QVector<QPointF>& points);
33 virtual void setGeometry(QVector<QPointF>& points);
33
34
34 private:
35 private:
35 void createPoints(int count);
36 void createPoints(int count);
36 void deletePoints(int count);
37 void deletePoints(int count);
37
38
38 private:
39 private:
39 QLineSeries* m_series;
40 QLineSeries* m_series;
40 QGraphicsItemGroup m_items;
41 QGraphicsItemGroup m_items;
41 QPainterPath m_path;
42 QPainterPath m_path;
42 QRectF m_rect;
43 QRectF m_rect;
43 QPen m_pen;
44 QPen m_pen;
44
45
45 friend class LineChartAnimatator;
46 template<class,class> friend class XYChartAnimator;
46
47
47 };
48 };
48
49
50 typedef XYChartAnimationItem<LineChartItem,QLineSeries> LineChartAnimationItem;
51
49 QTCOMMERCIALCHART_END_NAMESPACE
52 QTCOMMERCIALCHART_END_NAMESPACE
50
53
51 #endif
54 #endif
@@ -1,277 +1,288
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include "chartdataset_p.h"
4 #include "chartdataset_p.h"
5 #include <QGraphicsScene>
5 #include <QGraphicsScene>
6 #include <QGraphicsSceneResizeEvent>
6 #include <QGraphicsSceneResizeEvent>
7 #include <QDebug>
7 #include <QDebug>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 /*!
11 /*!
12 \enum QChart::ChartTheme
12 \enum QChart::ChartTheme
13
13
14 This enum describes the theme used by the chart.
14 This enum describes the theme used by the chart.
15
15
16 \value ChartThemeDefault
16 \value ChartThemeDefault
17 \value ChartThemeVanilla
17 \value ChartThemeVanilla
18 \value ChartThemeIcy
18 \value ChartThemeIcy
19 \value ChartThemeGrayscale
19 \value ChartThemeGrayscale
20 \value ChartThemeScientific
20 \value ChartThemeScientific
21 */
21 */
22
22
23 /*!
23 /*!
24 \enum QChart::AnimationOption
24 \enum QChart::AnimationOption
25
25
26 For enabling/disabling animations. Defaults to NoAnimation.
26 For enabling/disabling animations. Defaults to NoAnimation.
27
27
28 \value NoAnimation
28 \value NoAnimation
29 \value GridAxisAnimations
29 \value GridAxisAnimations
30 \value SeriesAnimations
30 \value SeriesAnimations
31 \value AllAnimations
31 \value AllAnimations
32 */
32 */
33
33
34 /*!
34 /*!
35 \class QChart
35 \class QChart
36 \brief QtCommercial chart API.
36 \brief QtCommercial chart API.
37
37
38 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
38 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
39 representation of different types of QChartSeries and other chart related objects like
39 representation of different types of QChartSeries and other chart related objects like
40 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
40 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
41 convenience class QChartView instead of QChart.
41 convenience class QChartView instead of QChart.
42 \sa QChartView
42 \sa QChartView
43 */
43 */
44
44
45 /*!
45 /*!
46 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
46 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
47 */
47 */
48 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
48 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
49 m_backgroundItem(0),
49 m_backgroundItem(0),
50 m_titleItem(0),
50 m_titleItem(0),
51 m_dataset(new ChartDataSet(this)),
51 m_dataset(new ChartDataSet(this)),
52 m_presenter(new ChartPresenter(this,m_dataset))
52 m_presenter(new ChartPresenter(this,m_dataset))
53 {
53 {
54 }
54 }
55
55
56 /*!
56 /*!
57 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
57 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
58 */
58 */
59 QChart::~QChart()
59 QChart::~QChart()
60 {
60 {
61 }
61 }
62
62
63 /*!
63 /*!
64 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
64 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
65 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
65 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
66 the y axis).
66 the y axis).
67 */
67 */
68 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
68 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
69 {
69 {
70 m_dataset->addSeries(series, axisY);
70 m_dataset->addSeries(series, axisY);
71 }
71 }
72
72
73 /*!
73 /*!
74 Removes the \a series specified in a perameter from the QChartView.
74 Removes the \a series specified in a perameter from the QChartView.
75 It releses its ownership of the specified QChartSeries object.
75 It releses its ownership of the specified QChartSeries object.
76 It does not delete the pointed QChartSeries data object
76 It does not delete the pointed QChartSeries data object
77 \sa addSeries(), removeAllSeries()
77 \sa addSeries(), removeAllSeries()
78 */
78 */
79 void QChart::removeSeries(QSeries* series)
79 void QChart::removeSeries(QSeries* series)
80 {
80 {
81 m_dataset->removeSeries(series);
81 m_dataset->removeSeries(series);
82 }
82 }
83
83
84 /*!
84 /*!
85 Removes all the QChartSeries that have been added to the QChartView
85 Removes all the QChartSeries that have been added to the QChartView
86 It also deletes the pointed QChartSeries data objects
86 It also deletes the pointed QChartSeries data objects
87 \sa addSeries(), removeSeries()
87 \sa addSeries(), removeSeries()
88 */
88 */
89 void QChart::removeAllSeries()
89 void QChart::removeAllSeries()
90 {
90 {
91 m_dataset->removeAllSeries();
91 m_dataset->removeAllSeries();
92 }
92 }
93
93
94 /*!
94 /*!
95 Sets the \a brush that is used for painting the background of the chart area.
95 Sets the \a brush that is used for painting the background of the chart area.
96 */
96 */
97 void QChart::setChartBackgroundBrush(const QBrush& brush)
97 void QChart::setChartBackgroundBrush(const QBrush& brush)
98 {
98 {
99 createChartBackgroundItem();
99 createChartBackgroundItem();
100 m_backgroundItem->setBrush(brush);
100 m_backgroundItem->setBrush(brush);
101 m_backgroundItem->update();
101 m_backgroundItem->update();
102 }
102 }
103
103
104 /*!
104 /*!
105 Sets the \a pen that is used for painting the background of the chart area.
105 Sets the \a pen that is used for painting the background of the chart area.
106 */
106 */
107 void QChart::setChartBackgroundPen(const QPen& pen)
107 void QChart::setChartBackgroundPen(const QPen& pen)
108 {
108 {
109 createChartBackgroundItem();
109 createChartBackgroundItem();
110 m_backgroundItem->setPen(pen);
110 m_backgroundItem->setPen(pen);
111 m_backgroundItem->update();
111 m_backgroundItem->update();
112 }
112 }
113
113
114 /*!
114 /*!
115 Sets the chart \a title. The description text that is rendered above the chart.
115 Sets the chart \a title. The description text that is rendered above the chart.
116 */
116 */
117 void QChart::setChartTitle(const QString& title)
117 void QChart::setChartTitle(const QString& title)
118 {
118 {
119 createChartTitleItem();
119 createChartTitleItem();
120 m_titleItem->setPlainText(title);
120 m_titleItem->setText(title);
121 }
122
123 /*!
124 Gets the chart \a title. The description text that is rendered above the chart.
125 */
126 QString QChart::chartTitle() const
127 {
128 if(m_titleItem)
129 return m_titleItem->text();
130 else
131 return QString();
121 }
132 }
122
133
123 /*!
134 /*!
124 Sets the \a font that is used for rendering the description text that is rendered above the chart.
135 Sets the \a font that is used for rendering the description text that is rendered above the chart.
125 */
136 */
126 void QChart::setChartTitleFont(const QFont& font)
137 void QChart::setChartTitleFont(const QFont& font)
127 {
138 {
128 createChartTitleItem();
139 createChartTitleItem();
129 m_titleItem->setFont(font);
140 m_titleItem->setFont(font);
130 }
141 }
131
142
132 void QChart::createChartBackgroundItem()
143 void QChart::createChartBackgroundItem()
133 {
144 {
134 if(!m_backgroundItem) {
145 if(!m_backgroundItem) {
135 m_backgroundItem = new QGraphicsRectItem(this);
146 m_backgroundItem = new QGraphicsRectItem(this);
136 m_backgroundItem->setPen(Qt::NoPen);
147 m_backgroundItem->setPen(Qt::NoPen);
137 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
148 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
138 }
149 }
139 }
150 }
140
151
141 void QChart::createChartTitleItem()
152 void QChart::createChartTitleItem()
142 {
153 {
143 if(!m_titleItem) {
154 if(!m_titleItem) {
144 m_titleItem = new QGraphicsTextItem(this);
155 m_titleItem = new QGraphicsSimpleTextItem(this);
145 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
156 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
146 }
157 }
147 }
158 }
148
159
149 /*!
160 /*!
150 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
161 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
151 \sa setMargin()
162 \sa setMargin()
152 */
163 */
153 int QChart::margin() const
164 int QChart::margin() const
154 {
165 {
155 return m_presenter->margin();
166 return m_presenter->margin();
156 }
167 }
157
168
158 /*!
169 /*!
159 Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
170 Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
160 \sa margin()
171 \sa margin()
161 */
172 */
162 void QChart::setMargin(int margin)
173 void QChart::setMargin(int margin)
163 {
174 {
164 m_presenter->setMargin(margin);
175 m_presenter->setMargin(margin);
165 }
176 }
166
177
167 /*!
178 /*!
168 Sets the \a theme used by the chart for rendering the graphical representation of the data
179 Sets the \a theme used by the chart for rendering the graphical representation of the data
169 \sa ChartTheme, chartTheme()
180 \sa ChartTheme, chartTheme()
170 */
181 */
171 void QChart::setChartTheme(QChart::ChartTheme theme)
182 void QChart::setChartTheme(QChart::ChartTheme theme)
172 {
183 {
173 m_presenter->setChartTheme(theme);
184 m_presenter->setChartTheme(theme);
174 }
185 }
175
186
176 /*!
187 /*!
177 Returns the theme enum used by the chart.
188 Returns the theme enum used by the chart.
178 \sa ChartTheme, setChartTheme()
189 \sa ChartTheme, setChartTheme()
179 */
190 */
180 QChart::ChartTheme QChart::chartTheme() const
191 QChart::ChartTheme QChart::chartTheme() const
181 {
192 {
182 return m_presenter->chartTheme();
193 return m_presenter->chartTheme();
183 }
194 }
184
195
185 /*!
196 /*!
186 Zooms in the view by a factor of 2
197 Zooms in the view by a factor of 2
187 */
198 */
188 void QChart::zoomIn()
199 void QChart::zoomIn()
189 {
200 {
190 m_presenter->zoomIn();
201 m_presenter->zoomIn();
191 }
202 }
192
203
193 /*!
204 /*!
194 Zooms in the view to a maximum level at which \a rect is still fully visible.
205 Zooms in the view to a maximum level at which \a rect is still fully visible.
195 */
206 */
196 void QChart::zoomIn(const QRectF& rect)
207 void QChart::zoomIn(const QRectF& rect)
197 {
208 {
198
209
199 if(!rect.isValid()) return;
210 if(!rect.isValid()) return;
200 m_presenter->zoomIn(rect);
211 m_presenter->zoomIn(rect);
201 }
212 }
202
213
203 /*!
214 /*!
204 Restores the view zoom level to the previous one.
215 Restores the view zoom level to the previous one.
205 */
216 */
206 void QChart::zoomOut()
217 void QChart::zoomOut()
207 {
218 {
208 m_presenter->zoomOut();
219 m_presenter->zoomOut();
209 }
220 }
210
221
211 /*!
222 /*!
212 Resets to the default view.
223 Resets to the default view.
213 */
224 */
214 void QChart::zoomReset()
225 void QChart::zoomReset()
215 {
226 {
216 m_presenter->zoomReset();
227 m_presenter->zoomReset();
217 }
228 }
218
229
219 /*!
230 /*!
220 Returns the pointer to the x axis object of the chart
231 Returns the pointer to the x axis object of the chart
221 */
232 */
222 QChartAxis* QChart::axisX() const
233 QChartAxis* QChart::axisX() const
223 {
234 {
224 return m_dataset->axisX();
235 return m_dataset->axisX();
225 }
236 }
226
237
227 /*!
238 /*!
228 Returns the pointer to the y axis object of the chart
239 Returns the pointer to the y axis object of the chart
229 */
240 */
230 QChartAxis* QChart::axisY() const
241 QChartAxis* QChart::axisY() const
231 {
242 {
232 return m_dataset->axisY();
243 return m_dataset->axisY();
233 }
244 }
234
245
235 /*!
246 /*!
236 Resizes and updates the chart area using the \a event data
247 Resizes and updates the chart area using the \a event data
237 */
248 */
238 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
249 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
239 {
250 {
240
251
241 m_rect = QRectF(QPoint(0,0),event->newSize());
252 m_rect = QRectF(QPoint(0,0),event->newSize());
242 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
253 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
243
254
244 // recalculate title position
255 // recalculate title position
245 if (m_titleItem) {
256 if (m_titleItem) {
246 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
257 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
247 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
258 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
248 }
259 }
249
260
250 //recalculate background gradient
261 //recalculate background gradient
251 if (m_backgroundItem) {
262 if (m_backgroundItem) {
252 m_backgroundItem->setRect(rect);
263 m_backgroundItem->setRect(rect);
253 }
264 }
254
265
255 QGraphicsWidget::resizeEvent(event);
266 QGraphicsWidget::resizeEvent(event);
256 update();
267 update();
257 }
268 }
258
269
259 /*!
270 /*!
260 Sets animation \a options for the chart
271 Sets animation \a options for the chart
261 */
272 */
262 void QChart::setAnimationOptions(AnimationOptions options)
273 void QChart::setAnimationOptions(AnimationOptions options)
263 {
274 {
264 m_presenter->setAnimationOptions(options);
275 m_presenter->setAnimationOptions(options);
265 }
276 }
266
277
267 /*!
278 /*!
268 Returns animation options for the chart
279 Returns animation options for the chart
269 */
280 */
270 QChart::AnimationOptions QChart::animationOptions() const
281 QChart::AnimationOptions QChart::animationOptions() const
271 {
282 {
272 return m_presenter->animationOptions();
283 return m_presenter->animationOptions();
273 }
284 }
274
285
275 #include "moc_qchart.cpp"
286 #include "moc_qchart.cpp"
276
287
277 QTCOMMERCIALCHART_END_NAMESPACE
288 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,95 +1,96
1 #ifndef QCHART_H
1 #ifndef QCHART_H
2 #define QCHART_H
2 #define QCHART_H
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <qseries.h>
5 #include <qseries.h>
6 #include <QGraphicsWidget>
6 #include <QGraphicsWidget>
7 #include <QLinearGradient>
7 #include <QLinearGradient>
8 #include <QFont>
8 #include <QFont>
9
9
10 class QGraphicsSceneResizeEvent;
10 class QGraphicsSceneResizeEvent;
11
11
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
13
14 class AxisItem;
14 class AxisItem;
15 class QSeries;
15 class QSeries;
16 class PlotDomain;
16 class PlotDomain;
17 class BarPresenter;
17 class BarPresenter;
18 class QChartAxis;
18 class QChartAxis;
19 class ChartTheme;
19 class ChartTheme;
20 class ChartItem;
20 class ChartItem;
21 class ChartDataSet;
21 class ChartDataSet;
22 class ChartPresenter;
22 class ChartPresenter;
23
23
24 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
24 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
25 {
25 {
26 Q_OBJECT
26 Q_OBJECT
27 public:
27 public:
28 enum ChartTheme {
28 enum ChartTheme {
29 ChartThemeDefault,
29 ChartThemeDefault,
30 ChartThemeVanilla,
30 ChartThemeVanilla,
31 ChartThemeIcy,
31 ChartThemeIcy,
32 ChartThemeGrayscale,
32 ChartThemeGrayscale,
33 ChartThemeScientific
33 ChartThemeScientific
34 //ChartThemeUnnamed1
34 //ChartThemeUnnamed1
35 /*! The default theme follows the GUI style of the Operating System */
35 /*! The default theme follows the GUI style of the Operating System */
36 };
36 };
37
37
38 enum AnimationOption {
38 enum AnimationOption {
39 NoAnimation = 0x0,
39 NoAnimation = 0x0,
40 GridAxisAnimations = 0x1,
40 GridAxisAnimations = 0x1,
41 SeriesAnimations =0x2,
41 SeriesAnimations =0x2,
42 AllAnimations = 0x3
42 AllAnimations = 0x3
43 };
43 };
44 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
44 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
45
45
46 public:
46 public:
47 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
47 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
48 ~QChart();
48 ~QChart();
49
49
50 void addSeries(QSeries* series, QChartAxis* axisY = 0);
50 void addSeries(QSeries* series, QChartAxis* axisY = 0);
51 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
51 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
52 void removeAllSeries(); // deletes series and axis
52 void removeAllSeries(); // deletes series and axis
53
53
54 void setMargin(int margin);
54 void setMargin(int margin);
55 int margin() const;
55 int margin() const;
56 void setChartTheme(QChart::ChartTheme theme);
56 void setChartTheme(QChart::ChartTheme theme);
57 QChart::ChartTheme chartTheme() const;
57 QChart::ChartTheme chartTheme() const;
58
58
59 void setChartTitle(const QString& title);
59 void setChartTitle(const QString& title);
60 QString chartTitle() const;
60 void setChartTitleFont(const QFont& font);
61 void setChartTitleFont(const QFont& font);
61 void setChartBackgroundBrush(const QBrush& brush);
62 void setChartBackgroundBrush(const QBrush& brush);
62 void setChartBackgroundPen(const QPen& pen);
63 void setChartBackgroundPen(const QPen& pen);
63
64
64 void setAnimationOptions(AnimationOptions options);
65 void setAnimationOptions(AnimationOptions options);
65 AnimationOptions animationOptions() const;
66 AnimationOptions animationOptions() const;
66
67
67 void zoomIn();
68 void zoomIn();
68 void zoomIn(const QRectF& rect);
69 void zoomIn(const QRectF& rect);
69 void zoomOut();
70 void zoomOut();
70 void zoomReset();
71 void zoomReset();
71
72
72 QChartAxis* axisX() const;
73 QChartAxis* axisX() const;
73 QChartAxis* axisY() const;
74 QChartAxis* axisY() const;
74
75
75 protected:
76 protected:
76 void resizeEvent(QGraphicsSceneResizeEvent *event);
77 void resizeEvent(QGraphicsSceneResizeEvent *event);
77
78
78 private:
79 private:
79 inline void createChartBackgroundItem();
80 inline void createChartBackgroundItem();
80 inline void createChartTitleItem();
81 inline void createChartTitleItem();
81
82
82 private:
83 private:
83 Q_DISABLE_COPY(QChart)
84 Q_DISABLE_COPY(QChart)
84 QGraphicsRectItem* m_backgroundItem;
85 QGraphicsRectItem* m_backgroundItem;
85 QGraphicsTextItem* m_titleItem;
86 QGraphicsSimpleTextItem* m_titleItem;
86 QRectF m_rect;
87 QRectF m_rect;
87 ChartDataSet *m_dataset;
88 ChartDataSet *m_dataset;
88 ChartPresenter *m_presenter;
89 ChartPresenter *m_presenter;
89 };
90 };
90
91
91 QTCOMMERCIALCHART_END_NAMESPACE
92 QTCOMMERCIALCHART_END_NAMESPACE
92
93
93 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
94 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
94
95
95 #endif
96 #endif
@@ -1,351 +1,359
1 #include "qchartview.h"
1 #include "qchartview.h"
2 #include "qchart.h"
2 #include "qchart.h"
3 #include "qchartaxis.h"
3 #include "qchartaxis.h"
4 #include <QGraphicsView>
4 #include <QGraphicsView>
5 #include <QGraphicsScene>
5 #include <QGraphicsScene>
6 #include <QRubberBand>
6 #include <QRubberBand>
7 #include <QResizeEvent>
7 #include <QResizeEvent>
8 #include <QDebug>
8 #include <QDebug>
9
9
10 /*!
10 /*!
11 \enum QChartView::RubberBandPolicy
11 \enum QChartView::RubberBandPolicy
12
12
13 This enum describes the different types of rubber bands that can be used for zoom rect selection
13 This enum describes the different types of rubber bands that can be used for zoom rect selection
14
14
15 \value NoRubberBand
15 \value NoRubberBand
16 \value VerticalRubberBand
16 \value VerticalRubberBand
17 \value HorizonalRubberBand
17 \value HorizonalRubberBand
18 \value RectangleRubberBand
18 \value RectangleRubberBand
19 */
19 */
20
20
21 /*!
21 /*!
22 \class QChartView
22 \class QChartView
23 \brief Standalone charting widget.
23 \brief Standalone charting widget.
24
24
25 QChartView is a standalone widget that can display charts. It does not require separate
25 QChartView is a standalone widget that can display charts. It does not require separate
26 QGraphicsScene to work. It manages the graphical representation of different types of
26 QGraphicsScene to work. It manages the graphical representation of different types of
27 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
27 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
28 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
28 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
29
29
30 \sa QChart
30 \sa QChart
31 */
31 */
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 /*!
35 /*!
36 Constructs a chartView object which is a child of a\a parent.
36 Constructs a chartView object which is a child of a\a parent.
37 */
37 */
38 QChartView::QChartView(QWidget *parent) :
38 QChartView::QChartView(QWidget *parent) :
39 QGraphicsView(parent),
39 QGraphicsView(parent),
40 m_scene(new QGraphicsScene(this)),
40 m_scene(new QGraphicsScene(this)),
41 m_chart(new QChart()),
41 m_chart(new QChart()),
42 m_rubberBand(0),
42 m_rubberBand(0),
43 m_verticalRubberBand(false),
43 m_verticalRubberBand(false),
44 m_horizonalRubberBand(false)
44 m_horizonalRubberBand(false)
45 {
45 {
46 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
46 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
47 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
47 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
48 setScene(m_scene);
48 setScene(m_scene);
49 m_chart->setMargin(50);
49 m_chart->setMargin(50);
50 m_scene->addItem(m_chart);
50 m_scene->addItem(m_chart);
51 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
51 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
52 }
52 }
53
53
54
54
55 /*!
55 /*!
56 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
56 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
57 */
57 */
58 QChartView::~QChartView()
58 QChartView::~QChartView()
59 {
59 {
60 }
60 }
61
61
62 /*!
62 /*!
63 Resizes and updates the chart area using the \a event data
63 Resizes and updates the chart area using the \a event data
64 */
64 */
65 void QChartView::resizeEvent(QResizeEvent *event)
65 void QChartView::resizeEvent(QResizeEvent *event)
66 {
66 {
67 m_scene->setSceneRect(0,0,size().width(),size().height());
67 m_scene->setSceneRect(0,0,size().width(),size().height());
68 m_chart->resize(size());
68 m_chart->resize(size());
69 QWidget::resizeEvent(event);
69 QWidget::resizeEvent(event);
70 }
70 }
71
71
72 /*!
72 /*!
73 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
73 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
74 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
74 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
75 the y axis).
75 the y axis).
76 \sa removeSeries(), removeAllSeries()
76 \sa removeSeries(), removeAllSeries()
77 */
77 */
78 void QChartView::addSeries(QSeries* series,QChartAxis *axisY)
78 void QChartView::addSeries(QSeries* series,QChartAxis *axisY)
79 {
79 {
80 m_chart->addSeries(series,axisY);
80 m_chart->addSeries(series,axisY);
81 }
81 }
82
82
83 /*!
83 /*!
84 Removes the \a series specified in a perameter from the QChartView.
84 Removes the \a series specified in a perameter from the QChartView.
85 It releses its ownership of the specified QChartSeries object.
85 It releses its ownership of the specified QChartSeries object.
86 It does not delete the pointed QChartSeries data object
86 It does not delete the pointed QChartSeries data object
87 \sa addSeries(), removeAllSeries()
87 \sa addSeries(), removeAllSeries()
88 */
88 */
89 void QChartView::removeSeries(QSeries* series)
89 void QChartView::removeSeries(QSeries* series)
90 {
90 {
91 m_chart->removeSeries(series);
91 m_chart->removeSeries(series);
92 }
92 }
93
93
94 /*!
94 /*!
95 Removes all the QChartSeries that have been added to the QChartView
95 Removes all the QChartSeries that have been added to the QChartView
96 It also deletes the pointed QChartSeries data objects
96 It also deletes the pointed QChartSeries data objects
97 \sa addSeries(), removeSeries()
97 \sa addSeries(), removeSeries()
98 */
98 */
99 void QChartView::removeAllSeries()
99 void QChartView::removeAllSeries()
100 {
100 {
101 m_chart->removeAllSeries();
101 m_chart->removeAllSeries();
102 }
102 }
103
103
104 /*!
104 /*!
105 Zooms in the view by a factor of 2
105 Zooms in the view by a factor of 2
106 */
106 */
107 void QChartView::zoomIn()
107 void QChartView::zoomIn()
108 {
108 {
109 m_chart->zoomIn();
109 m_chart->zoomIn();
110 }
110 }
111
111
112 /*!
112 /*!
113 Zooms in the view to a maximum level at which \a rect is still fully visible.
113 Zooms in the view to a maximum level at which \a rect is still fully visible.
114 */
114 */
115 void QChartView::zoomIn(const QRect& rect)
115 void QChartView::zoomIn(const QRect& rect)
116 {
116 {
117 m_chart->zoomIn(rect);
117 m_chart->zoomIn(rect);
118 }
118 }
119
119
120 /*!
120 /*!
121 Restores the view zoom level to the previous one.
121 Restores the view zoom level to the previous one.
122 */
122 */
123 void QChartView::zoomOut()
123 void QChartView::zoomOut()
124 {
124 {
125 m_chart->zoomOut();
125 m_chart->zoomOut();
126 }
126 }
127
127
128 /*!
128 /*!
129 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
129 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
130 */
130 */
131 int QChartView::margin() const
131 int QChartView::margin() const
132 {
132 {
133 return m_chart->margin();
133 return m_chart->margin();
134 }
134 }
135
135
136 /*!
136 /*!
137 Sets the chart \a title. A description text that is rendered above the chart.
137 Sets the chart \a title. A description text that is rendered above the chart.
138 */
138 */
139 void QChartView::setChartTitle(const QString& title)
139 void QChartView::setChartTitle(const QString& title)
140 {
140 {
141 m_chart->setChartTitle(title);
141 m_chart->setChartTitle(title);
142 }
142 }
143
143
144 /*!
144 /*!
145 Gets the chart \a title. A description text that is rendered above the chart.
146 */
147 QString QChartView::chartTitle() const
148 {
149 return m_chart->chartTitle();
150 }
151
152 /*!
145 Sets the \a font that is used for rendering the description text that is rendered above the chart.
153 Sets the \a font that is used for rendering the description text that is rendered above the chart.
146 */
154 */
147 void QChartView::setChartTitleFont(const QFont& font)
155 void QChartView::setChartTitleFont(const QFont& font)
148 {
156 {
149 m_chart->setChartTitleFont(font);
157 m_chart->setChartTitleFont(font);
150 }
158 }
151
159
152 /*!
160 /*!
153 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
161 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
154 */
162 */
155 void QChartView::setChartBackgroundBrush(const QBrush& brush)
163 void QChartView::setChartBackgroundBrush(const QBrush& brush)
156 {
164 {
157 m_chart->setChartBackgroundBrush(brush);
165 m_chart->setChartBackgroundBrush(brush);
158 }
166 }
159
167
160 /*!
168 /*!
161 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
169 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
162 */
170 */
163 void QChartView::setChartBackgroundPen(const QPen& pen)
171 void QChartView::setChartBackgroundPen(const QPen& pen)
164 {
172 {
165 m_chart->setChartBackgroundPen(pen);
173 m_chart->setChartBackgroundPen(pen);
166 }
174 }
167
175
168 /*!
176 /*!
169 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
177 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
170 */
178 */
171 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
179 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
172 {
180 {
173 switch(policy) {
181 switch(policy) {
174 case VerticalRubberBand:
182 case VerticalRubberBand:
175 m_verticalRubberBand = true;
183 m_verticalRubberBand = true;
176 m_horizonalRubberBand = false;
184 m_horizonalRubberBand = false;
177 break;
185 break;
178 case HorizonalRubberBand:
186 case HorizonalRubberBand:
179 m_verticalRubberBand = false;
187 m_verticalRubberBand = false;
180 m_horizonalRubberBand = true;
188 m_horizonalRubberBand = true;
181 break;
189 break;
182 case RectangleRubberBand:
190 case RectangleRubberBand:
183 m_verticalRubberBand = true;
191 m_verticalRubberBand = true;
184 m_horizonalRubberBand = true;
192 m_horizonalRubberBand = true;
185 break;
193 break;
186 case NoRubberBand:
194 case NoRubberBand:
187 default:
195 default:
188 delete m_rubberBand;
196 delete m_rubberBand;
189 m_rubberBand=0;
197 m_rubberBand=0;
190 m_horizonalRubberBand = false;
198 m_horizonalRubberBand = false;
191 m_verticalRubberBand = false;
199 m_verticalRubberBand = false;
192 return;
200 return;
193 }
201 }
194 if(!m_rubberBand) {
202 if(!m_rubberBand) {
195 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
203 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
196 m_rubberBand->setEnabled(true);
204 m_rubberBand->setEnabled(true);
197 }
205 }
198 }
206 }
199
207
200 /*!
208 /*!
201 Returns the RubberBandPolicy that is currently being used by the widget.
209 Returns the RubberBandPolicy that is currently being used by the widget.
202 */
210 */
203 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
211 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
204 {
212 {
205 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
213 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
206 if(m_horizonalRubberBand) return HorizonalRubberBand;
214 if(m_horizonalRubberBand) return HorizonalRubberBand;
207 if(m_verticalRubberBand) return VerticalRubberBand;
215 if(m_verticalRubberBand) return VerticalRubberBand;
208 return NoRubberBand;
216 return NoRubberBand;
209 }
217 }
210
218
211 /*!
219 /*!
212 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
220 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
213 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
221 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
214 */
222 */
215 void QChartView::mousePressEvent(QMouseEvent *event)
223 void QChartView::mousePressEvent(QMouseEvent *event)
216 {
224 {
217 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
225 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
218
226
219 int margin = m_chart->margin();
227 int margin = m_chart->margin();
220 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
228 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
221
229
222 if (rect.contains(event->pos())) {
230 if (rect.contains(event->pos())) {
223 m_rubberBandOrigin = event->pos();
231 m_rubberBandOrigin = event->pos();
224 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
232 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
225 m_rubberBand->show();
233 m_rubberBand->show();
226 event->accept();
234 event->accept();
227 }
235 }
228 }
236 }
229 else {
237 else {
230 QGraphicsView::mousePressEvent(event);
238 QGraphicsView::mousePressEvent(event);
231 }
239 }
232 }
240 }
233
241
234 /*!
242 /*!
235 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
243 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
236 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
244 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
237 */
245 */
238 void QChartView::mouseMoveEvent(QMouseEvent *event)
246 void QChartView::mouseMoveEvent(QMouseEvent *event)
239 {
247 {
240 if(m_rubberBand && m_rubberBand->isVisible()) {
248 if(m_rubberBand && m_rubberBand->isVisible()) {
241 int margin = m_chart->margin();
249 int margin = m_chart->margin();
242 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
250 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
243 int width = event->pos().x() - m_rubberBandOrigin.x();
251 int width = event->pos().x() - m_rubberBandOrigin.x();
244 int height = event->pos().y() - m_rubberBandOrigin.y();
252 int height = event->pos().y() - m_rubberBandOrigin.y();
245 if(!m_verticalRubberBand) {
253 if(!m_verticalRubberBand) {
246 m_rubberBandOrigin.setY(rect.top());
254 m_rubberBandOrigin.setY(rect.top());
247 height = rect.height();
255 height = rect.height();
248 }
256 }
249 if(!m_horizonalRubberBand) {
257 if(!m_horizonalRubberBand) {
250 m_rubberBandOrigin.setX(rect.left());
258 m_rubberBandOrigin.setX(rect.left());
251 width= rect.width();
259 width= rect.width();
252 }
260 }
253 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
261 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
254 }
262 }
255 else {
263 else {
256 QGraphicsView::mouseMoveEvent(event);
264 QGraphicsView::mouseMoveEvent(event);
257 }
265 }
258 }
266 }
259
267
260 /*!
268 /*!
261 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
269 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
262 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
270 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
263 */
271 */
264 void QChartView::mouseReleaseEvent(QMouseEvent *event)
272 void QChartView::mouseReleaseEvent(QMouseEvent *event)
265 {
273 {
266 if(m_rubberBand) {
274 if(m_rubberBand) {
267 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
275 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
268 m_rubberBand->hide();
276 m_rubberBand->hide();
269 QRect rect = m_rubberBand->geometry();
277 QRect rect = m_rubberBand->geometry();
270 m_chart->zoomIn(rect);
278 m_chart->zoomIn(rect);
271 event->accept();
279 event->accept();
272 }
280 }
273
281
274 if(event->button()==Qt::RightButton)
282 if(event->button()==Qt::RightButton)
275 m_chart->zoomReset();
283 m_chart->zoomReset();
276 }
284 }
277 else {
285 else {
278 QGraphicsView::mouseReleaseEvent(event);
286 QGraphicsView::mouseReleaseEvent(event);
279 }
287 }
280 }
288 }
281
289
282 /*!
290 /*!
283 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
291 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
284 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
292 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
285 */
293 */
286 void QChartView::keyPressEvent(QKeyEvent *event)
294 void QChartView::keyPressEvent(QKeyEvent *event)
287 {
295 {
288 switch (event->key()) {
296 switch (event->key()) {
289 case Qt::Key_Plus:
297 case Qt::Key_Plus:
290 zoomIn();
298 zoomIn();
291 break;
299 break;
292 case Qt::Key_Minus:
300 case Qt::Key_Minus:
293 zoomOut();
301 zoomOut();
294 break;
302 break;
295 default:
303 default:
296 QGraphicsView::keyPressEvent(event);
304 QGraphicsView::keyPressEvent(event);
297 break;
305 break;
298 }
306 }
299 }
307 }
300
308
301 /*!
309 /*!
302 Sets the \a theme used by the chart for rendering the graphical representation of the data
310 Sets the \a theme used by the chart for rendering the graphical representation of the data
303 \sa QChart::ChartTheme, chartTheme()
311 \sa QChart::ChartTheme, chartTheme()
304 */
312 */
305 void QChartView::setChartTheme(QChart::ChartTheme theme)
313 void QChartView::setChartTheme(QChart::ChartTheme theme)
306 {
314 {
307 m_chart->setChartTheme(theme);
315 m_chart->setChartTheme(theme);
308 }
316 }
309
317
310 /*!
318 /*!
311 Returns the theme enum used by the chart.
319 Returns the theme enum used by the chart.
312 \sa setChartTheme()
320 \sa setChartTheme()
313 */
321 */
314 QChart::ChartTheme QChartView::chartTheme() const
322 QChart::ChartTheme QChartView::chartTheme() const
315 {
323 {
316 return m_chart->chartTheme();
324 return m_chart->chartTheme();
317 }
325 }
318
326
319 /*!
327 /*!
320 Returns the pointer to the x axis object of the chart
328 Returns the pointer to the x axis object of the chart
321 */
329 */
322 QChartAxis* QChartView::axisX() const
330 QChartAxis* QChartView::axisX() const
323 {
331 {
324 return m_chart->axisX();
332 return m_chart->axisX();
325 }
333 }
326
334
327 /*!
335 /*!
328 Returns the pointer to the y axis object of the chart
336 Returns the pointer to the y axis object of the chart
329 */
337 */
330 QChartAxis* QChartView::axisY() const
338 QChartAxis* QChartView::axisY() const
331 {
339 {
332 return m_chart->axisY();
340 return m_chart->axisY();
333 }
341 }
334
342
335 /*!
343 /*!
336 Sets animation \a options for the chart
344 Sets animation \a options for the chart
337 */
345 */
338 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
346 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
339 {
347 {
340 m_chart->setAnimationOptions(options);
348 m_chart->setAnimationOptions(options);
341 }
349 }
342
350
343 /*!
351 /*!
344 Returns animation options for the chart
352 Returns animation options for the chart
345 */
353 */
346 QChart::AnimationOptions QChartView::animationOptions() const
354 QChart::AnimationOptions QChartView::animationOptions() const
347 {
355 {
348 return m_chart->animationOptions();
356 return m_chart->animationOptions();
349 }
357 }
350
358
351 QTCOMMERCIALCHART_END_NAMESPACE
359 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,74 +1,75
1 #ifndef QCHARTWIDGET_H
1 #ifndef QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qseries.h"
5 #include "qseries.h"
6 #include "qchart.h"
6 #include "qchart.h"
7 #include <QGraphicsView>
7 #include <QGraphicsView>
8
8
9 class QGraphicsScene;
9 class QGraphicsScene;
10 class QRubberBand;
10 class QRubberBand;
11
11
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
13
14 class QChart;
14 class QChart;
15
15
16 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
16 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
17 {
17 {
18 public:
18 public:
19 enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand };
19 enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand };
20
20
21 explicit QChartView(QWidget *parent = 0);
21 explicit QChartView(QWidget *parent = 0);
22 ~QChartView();
22 ~QChartView();
23
23
24 //implement from QWidget
24 //implement from QWidget
25 void resizeEvent(QResizeEvent *event);
25 void resizeEvent(QResizeEvent *event);
26
26
27 void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership
27 void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership
28 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
28 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
29 void removeAllSeries(); // deletes series and axis
29 void removeAllSeries(); // deletes series and axis
30 int margin() const;
30 int margin() const;
31
31
32 void setChartTitle(const QString& title);
32 void setChartTitle(const QString& title);
33 QString chartTitle() const;
33 void setChartTitleFont(const QFont& font);
34 void setChartTitleFont(const QFont& font);
34 void setChartBackgroundBrush(const QBrush& brush);
35 void setChartBackgroundBrush(const QBrush& brush);
35 void setChartBackgroundPen(const QPen& pen);
36 void setChartBackgroundPen(const QPen& pen);
36
37
37 void zoomIn();
38 void zoomIn();
38 void zoomIn(const QRect& rect);
39 void zoomIn(const QRect& rect);
39 void zoomOut();
40 void zoomOut();
40
41
41 void setRubberBandPolicy(const RubberBandPolicy );
42 void setRubberBandPolicy(const RubberBandPolicy );
42 RubberBandPolicy rubberBandPolicy() const;
43 RubberBandPolicy rubberBandPolicy() const;
43
44
44 void setChartTheme(QChart::ChartTheme theme);
45 void setChartTheme(QChart::ChartTheme theme);
45 QChart::ChartTheme chartTheme() const;
46 QChart::ChartTheme chartTheme() const;
46
47
47 void setAnimationOptions(QChart::AnimationOptions options);
48 void setAnimationOptions(QChart::AnimationOptions options);
48 QChart::AnimationOptions animationOptions() const;
49 QChart::AnimationOptions animationOptions() const;
49
50
50 QChartAxis* axisX() const;
51 QChartAxis* axisX() const;
51 QChartAxis* axisY() const;
52 QChartAxis* axisY() const;
52
53
53 protected:
54 protected:
54 void mousePressEvent(QMouseEvent *event);
55 void mousePressEvent(QMouseEvent *event);
55 void mouseMoveEvent(QMouseEvent *event);
56 void mouseMoveEvent(QMouseEvent *event);
56 void mouseReleaseEvent(QMouseEvent *event);
57 void mouseReleaseEvent(QMouseEvent *event);
57 void keyPressEvent(QKeyEvent *event);
58 void keyPressEvent(QKeyEvent *event);
58
59
59
60
60 private:
61 private:
61 QGraphicsScene *m_scene;
62 QGraphicsScene *m_scene;
62 QChart* m_chart;
63 QChart* m_chart;
63 QPoint m_rubberBandOrigin;
64 QPoint m_rubberBandOrigin;
64 QRubberBand* m_rubberBand;
65 QRubberBand* m_rubberBand;
65 bool m_verticalRubberBand;
66 bool m_verticalRubberBand;
66 bool m_horizonalRubberBand;
67 bool m_horizonalRubberBand;
67 Q_DISABLE_COPY(QChartView)
68 Q_DISABLE_COPY(QChartView)
68
69
69
70
70 };
71 };
71
72
72 QTCOMMERCIALCHART_END_NAMESPACE
73 QTCOMMERCIALCHART_END_NAMESPACE
73
74
74 #endif // QCHARTWIDGET_H
75 #endif // QCHARTWIDGET_H
@@ -1,178 +1,178
1 #include "scatterchartitem_p.h"
1 #include "scatterchartitem_p.h"
2 #include "qscatterseries.h"
2 #include "qscatterseries.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include <QPainter>
4 #include <QPainter>
5 #include <QGraphicsScene>
5 #include <QGraphicsScene>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsObject *parent) :
9 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *parent) :
10 XYChartItem(series,parent),
10 XYChartItem(series,parent),
11 m_series(series),
11 m_series(series),
12 m_items(this),
12 m_items(this),
13 m_shape(QScatterSeries::MarkerShapeRectangle),
13 m_shape(QScatterSeries::MarkerShapeRectangle),
14 m_size(10)
14 m_size(10)
15
15
16 {
16 {
17 Q_ASSERT(parent);
17 Q_ASSERT(parent);
18 Q_ASSERT(series);
18 Q_ASSERT(series);
19
19
20 connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated()));
20 connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated()));
21
21
22 setZValue(ChartPresenter::ScatterSeriesZValue);
22 setZValue(ChartPresenter::ScatterSeriesZValue);
23 setFlags(QGraphicsItem::ItemHasNoContents);
23 setFlags(QGraphicsItem::ItemHasNoContents);
24 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
24 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
25
25
26 handleUpdated();
26 handleUpdated();
27
27
28 // TODO: how to draw a drop shadow?
28 // TODO: how to draw a drop shadow?
29 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
29 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
30 // dropShadow->setOffset(2.0);
30 // dropShadow->setOffset(2.0);
31 // dropShadow->setBlurRadius(2.0);
31 // dropShadow->setBlurRadius(2.0);
32 // setGraphicsEffect(dropShadow);
32 // setGraphicsEffect(dropShadow);
33 }
33 }
34
34
35
35
36 QRectF ScatterChartItem::boundingRect() const
36 QRectF ScatterChartItem::boundingRect() const
37 {
37 {
38 return m_rect;
38 return m_rect;
39 }
39 }
40
40
41 void ScatterChartItem::createPoints(int count)
41 void ScatterChartItem::createPoints(int count)
42 {
42 {
43 for (int i = 0; i < count; ++i) {
43 for (int i = 0; i < count; ++i) {
44
44
45 QGraphicsItem *item;
45 QGraphicsItem *item;
46
46
47 switch (m_shape) {
47 switch (m_shape) {
48 case QScatterSeries::MarkerShapeDefault:
48 case QScatterSeries::MarkerShapeDefault:
49 // Fallthrough, defaults to circle
49 // Fallthrough, defaults to circle
50 case QScatterSeries::MarkerShapeCircle:
50 case QScatterSeries::MarkerShapeCircle:
51 item = new QGraphicsEllipseItem(0,0,m_size,m_size);
51 item = new QGraphicsEllipseItem(0,0,m_size,m_size);
52 break;
52 break;
53 case QScatterSeries::MarkerShapeRectangle:
53 case QScatterSeries::MarkerShapeRectangle:
54 item = new QGraphicsRectItem(0,0,m_size,m_size);
54 item = new QGraphicsRectItem(0,0,m_size,m_size);
55 break;
55 break;
56 case QScatterSeries::MarkerShapeRoundedRectangle:
56 case QScatterSeries::MarkerShapeRoundedRectangle:
57 //m_path.addRoundedRect(x, y, size, size, size / 4.0, size / 4.0);
57 //m_path.addRoundedRect(x, y, size, size, size / 4.0, size / 4.0);
58 break;
58 break;
59 case QScatterSeries::MarkerShapeTiltedRectangle:
59 case QScatterSeries::MarkerShapeTiltedRectangle:
60 // TODO: tilt the rectangle
60 // TODO: tilt the rectangle
61 //m_path.addRect(x, y, size, size);
61 //m_path.addRect(x, y, size, size);
62 //break;
62 //break;
63 case QScatterSeries::MarkerShapeTriangle:
63 case QScatterSeries::MarkerShapeTriangle:
64 //QPolygonF polygon;
64 //QPolygonF polygon;
65 //polygon << QPointF(0.0, -size) << QPointF(size / 2.0, 0.0) << QPointF(-size / 2, 0.0);
65 //polygon << QPointF(0.0, -size) << QPointF(size / 2.0, 0.0) << QPointF(-size / 2, 0.0);
66 // TODO: the position is not exactly right...
66 // TODO: the position is not exactly right...
67 //m_path.addPolygon(polygon.translated(x + size / 2.0, y + size));
67 //m_path.addPolygon(polygon.translated(x + size / 2.0, y + size));
68 break;
68 break;
69 }
69 }
70 m_items.addToGroup(item);
70 m_items.addToGroup(item);
71 }
71 }
72 }
72 }
73
73
74 void ScatterChartItem::deletePoints(int count)
74 void ScatterChartItem::deletePoints(int count)
75 {
75 {
76 QList<QGraphicsItem *> items = m_items.childItems();
76 QList<QGraphicsItem *> items = m_items.childItems();
77
77
78 for (int i = 0; i < count; ++i) {
78 for (int i = 0; i < count; ++i) {
79 delete(items.takeLast());
79 delete(items.takeLast());
80 }
80 }
81 }
81 }
82
82
83 /*
83 /*
84
84
85 void ScatterChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
85 void ScatterChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
86 {
86 {
87
87
88 QPointF clickedPoint(
88 QPointF clickedPoint(
89 m_minX + (event->lastPos().x() / m_clippingRect.width()) * (m_maxX-m_minX),
89 m_minX + (event->lastPos().x() / m_clippingRect.width()) * (m_maxX-m_minX),
90 m_maxY - (event->lastPos().y() / m_clippingRect.height()) * (m_maxY-m_minY));
90 m_maxY - (event->lastPos().y() / m_clippingRect.height()) * (m_maxY-m_minY));
91 emit clicked(clickedPoint);
91 emit clicked(clickedPoint);
92
92
93 }
93 }
94 */
94 */
95
95
96 void ScatterChartItem::setGeometry(QVector<QPointF>& points)
96 void ScatterChartItem::setGeometry(QVector<QPointF>& points)
97 {
97 {
98 if(points.size()==0) return;
98 if(points.size()==0) return;
99
99
100 int diff = XYChartItem::points().size() - points.size();
100 int diff = XYChartItem::points().size() - points.size();
101
101
102 if(diff>0) {
102 if(diff>0) {
103 deletePoints(diff);
103 deletePoints(diff);
104 }
104 }
105 else if(diff<0) {
105 else if(diff<0) {
106 createPoints(-diff);
106 createPoints(-diff);
107 }
107 }
108
108
109 if(diff!=0) handleUpdated();
109 if(diff!=0) handleUpdated();
110
110
111 QList<QGraphicsItem*> items = m_items.childItems();
111 QList<QGraphicsItem*> items = m_items.childItems();
112
112
113 for(int i=0; i< points.size();i++) {
113 for(int i=0; i< points.size();i++) {
114 QGraphicsItem* item = items.at(i);
114 QGraphicsItem* item = items.at(i);
115 const QPointF& point = points.at(i);
115 const QPointF& point = points.at(i);
116 item->setPos(point.x()-1,point.y()-1);
116 item->setPos(point.x()-1,point.y()-1);
117 if(!clipRect().contains(point)) {
117 if(!clipRect().contains(point)) {
118 item->setVisible(false);
118 item->setVisible(false);
119 }
119 }
120 else {
120 else {
121 item->setVisible(true);
121 item->setVisible(true);
122 }
122 }
123 }
123 }
124
124
125 prepareGeometryChange();
125 prepareGeometryChange();
126 m_rect = clipRect();
126 m_rect = clipRect();
127 XYChartItem::setGeometry(points);
127 XYChartItem::setGeometry(points);
128 }
128 }
129
129
130
130
131 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
131 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
132 {
132 {
133 Q_UNUSED(painter);
133 Q_UNUSED(painter);
134 Q_UNUSED(option);
134 Q_UNUSED(option);
135 Q_UNUSED(widget);
135 Q_UNUSED(widget);
136 }
136 }
137
137
138 void ScatterChartItem::setPen(const QPen& pen)
138 void ScatterChartItem::setPen(const QPen& pen)
139 {
139 {
140 foreach(QGraphicsItem* item , m_items.childItems()) {
140 foreach(QGraphicsItem* item , m_items.childItems()) {
141 static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen);
141 static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen);
142 }
142 }
143 }
143 }
144
144
145 void ScatterChartItem::setBrush(const QBrush& brush)
145 void ScatterChartItem::setBrush(const QBrush& brush)
146 {
146 {
147 foreach(QGraphicsItem* item , m_items.childItems()) {
147 foreach(QGraphicsItem* item , m_items.childItems()) {
148 static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush);
148 static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush);
149 }
149 }
150 }
150 }
151
151
152 void ScatterChartItem::handleUpdated()
152 void ScatterChartItem::handleUpdated()
153 {
153 {
154
154
155 int count = m_items.childItems().count();
155 int count = m_items.childItems().count();
156
156
157 if(count==0) return;
157 if(count==0) return;
158
158
159 bool recreate = m_size != m_series->size() || m_shape != m_series->shape();
159 bool recreate = m_size != m_series->size() || m_shape != m_series->shape();
160
160
161 //TODO: only rewrite on size change
161 //TODO: only rewrite on size change
162
162
163 m_size = m_series->size();
163 m_size = m_series->size();
164 m_shape = m_series->shape();
164 m_shape = m_series->shape();
165
165
166 if(recreate){
166 if(recreate){
167 deletePoints(count);
167 deletePoints(count);
168 createPoints(count);
168 createPoints(count);
169 }
169 }
170
170
171 setPen(m_series->pen());
171 setPen(m_series->pen());
172 setBrush(m_series->brush());
172 setBrush(m_series->brush());
173
173
174 }
174 }
175
175
176 #include "moc_scatterchartitem_p.cpp"
176 #include "moc_scatterchartitem_p.cpp"
177
177
178 QTCOMMERCIALCHART_END_NAMESPACE
178 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,50 +1,55
1 #ifndef SCATTERPRESENTER_H
1 #ifndef SCATTERPRESENTER_H
2 #define SCATTERPRESENTER_H
2 #define SCATTERPRESENTER_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "xychartitem_p.h"
5 #include "xychartitem_p.h"
6 #include <QObject>
6 #include "xychartanimationitem_p.h"
7 #include <QGraphicsItem>
7 #include <QPen>
8 #include <QPen>
8
9
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
11
11 class QScatterSeries;
12 class QScatterSeries;
12
13
13 class ScatterChartItem : public XYChartItem
14 class ScatterChartItem : public XYChartItem
14 {
15 {
15 Q_OBJECT
16 Q_OBJECT
16 public:
17 public:
17 explicit ScatterChartItem(QScatterSeries *series, QGraphicsObject *parent = 0);
18 explicit ScatterChartItem(QScatterSeries *series, QGraphicsItem *parent = 0);
18
19
19 public:
20 public:
20 //from QGraphicsItem
21 //from QGraphicsItem
21 QRectF boundingRect() const;
22 QRectF boundingRect() const;
22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23
24
24 void setPen(const QPen& pen);
25 void setPen(const QPen& pen);
25 void setBrush(const QBrush& brush);
26 void setBrush(const QBrush& brush);
26
27
27 signals:
28 signals:
28 void clicked(QPointF coordinates);
29 void clicked(QPointF coordinates);
29
30
30 public slots:
31 public slots:
31 void handleUpdated();
32 void handleUpdated();
32
33
33 private:
34 private:
34 void createPoints(int count);
35 void createPoints(int count);
35 void deletePoints(int count);
36 void deletePoints(int count);
36
37
37 protected:
38 protected:
38 virtual void setGeometry(QVector<QPointF>& points);
39 virtual void setGeometry(QVector<QPointF>& points);
39
40
40 private:
41 private:
41 QScatterSeries *m_series;
42 QScatterSeries *m_series;
42 QGraphicsItemGroup m_items;
43 QGraphicsItemGroup m_items;
43 int m_shape;
44 int m_shape;
44 int m_size;
45 int m_size;
45 QRectF m_rect;
46 QRectF m_rect;
47
48 template<class,class> friend class XYChartAnimator;
46 };
49 };
47
50
51 typedef XYChartAnimationItem<ScatterChartItem,QScatterSeries> ScatterChartAnimationItem;
52
48 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
49
54
50 #endif // SCATTERPRESENTER_H
55 #endif // SCATTERPRESENTER_H
@@ -1,84 +1,103
1 #include "splinechartitem_p.h"
1 #include "splinechartitem_p.h"
2 #include "chartpresenter_p.h"
2 #include <QPainter>
3 #include <QPainter>
3
4
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
6
6 SplineChartItem::SplineChartItem(QSplineSeries* series, QGraphicsObject *parent) :
7 SplineChartItem::SplineChartItem(QSplineSeries* series, QGraphicsItem *parent) :
7 XYChartItem(series, parent),
8 XYChartItem(series, parent),
8 m_series(series)
9 m_series(series)
9 {
10 {
11 setZValue(ChartPresenter::LineChartZValue);
12 QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated()));
13 handleUpdated();
10 }
14 }
11
15
12 QRectF SplineChartItem::boundingRect() const
16 QRectF SplineChartItem::boundingRect() const
13 {
17 {
14 return m_rect;
18 return m_rect;
15 }
19 }
16
20
17 QPainterPath SplineChartItem::shape() const
21 QPainterPath SplineChartItem::shape() const
18 {
22 {
19 return m_path;
23 return m_path;
20 }
24 }
21
25
22 QPointF SplineChartItem::calculateGeometryControlPoint(int index) const
26 QPointF SplineChartItem::calculateGeometryControlPoint(int index) const
23 {
27 {
24 return XYChartItem::calculateGeometryPoint(m_series->controlPoint(index));
28 return XYChartItem::calculateGeometryPoint(m_series->controlPoint(index));
25 }
29 }
26
30
27 void SplineChartItem::setGeometry(QVector<QPointF>& points)
31 void SplineChartItem::setGeometry(QVector<QPointF>& points)
28 {
32 {
33
29 if(points.size()==0) return;
34 if(points.size()==0) return;
30
35
31 QPainterPath splinePath;
36 QPainterPath splinePath;
32 const QPointF& point = points.at(0);
37 const QPointF& point = points.at(0);
33 splinePath.moveTo(point);
38 splinePath.moveTo(point);
34
39
35 for (int i = 0; i < points.size() - 1; i++)
40 for (int i = 0; i < points.size() - 1; i++)
36 {
41 {
37 const QPointF& point = points.at(i + 1);
42 const QPointF& point = points.at(i + 1);
38 splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point);
43 splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point);
39 }
44 }
40
45
41 prepareGeometryChange();
46 prepareGeometryChange();
42 m_path = splinePath;
47 m_path = splinePath;
43 m_rect = splinePath.boundingRect();
48 m_rect = splinePath.boundingRect();
44 XYChartItem::setGeometry(points);
49 XYChartItem::setGeometry(points);
45 }
50 }
46
51
47 void SplineChartItem::setPen(const QPen& pen)
52 void SplineChartItem::setLinePen(const QPen& pen)
48 {
53 {
49 m_pen = pen;
54 m_pen = pen;
55 qDebug()<<pen;
50 }
56 }
51
57
58 //handlers
59
60 void SplineChartItem::handleUpdated()
61 {
62 //m_items.setVisible(m_series->pointsVisible());
63 setLinePen(m_series->pen());
64 update();
65 }
66
67 //painter
52
68
53 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
69 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
54 {
70 {
55 Q_UNUSED(widget);
71 Q_UNUSED(widget);
56 Q_UNUSED(option);
72 Q_UNUSED(option);
57 painter->save();
73 painter->save();
58 painter->setClipRect(clipRect());
74 painter->setClipRect(clipRect());
75 painter->setPen(m_pen);
59 painter->drawPath(m_path);
76 painter->drawPath(m_path);
60
77
61 const QVector<QPointF> points = XYChartItem::points();
78 const QVector<QPointF> points = XYChartItem::points();
62
79
63 for (int i = 0; i < points.size() - 1; i++)
80 for (int i = 0; i < points.size() - 1; i++)
64 {
81 {
65 painter->setPen(Qt::red);
82 painter->setPen(Qt::red);
66 painter->drawEllipse(points[i], 2, 2);
83 painter->drawEllipse(points[i], 2, 2);
67
84
68 painter->setPen(Qt::blue);
85 painter->setPen(Qt::blue);
69 // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i));
86 // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i));
70 // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1));
87 // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1));
71 // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4);
88 // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4);
72 // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4);
89 // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4);
73 }
90 }
74 if (points.count() > 0)
91 if (points.count() > 0)
75 {
92 {
76 painter->setPen(Qt::red);
93 painter->setPen(Qt::red);
77 painter->drawEllipse(points[points.count() - 1], 2, 2);
94 painter->drawEllipse(points[points.count() - 1], 2, 2);
78 }
95 }
79 painter->restore();
96 painter->restore();
80 }
97 }
81
98
99
100
82 #include "moc_splinechartitem_p.cpp"
101 #include "moc_splinechartitem_p.cpp"
83
102
84 QTCOMMERCIALCHART_END_NAMESPACE
103 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,40 +1,47
1 #ifndef SPLINECHARTITEM_P_H
1 #ifndef SPLINECHARTITEM_P_H
2 #define SPLINECHARTITEM_P_H
2 #define SPLINECHARTITEM_P_H
3
3
4 #include "chartitem_p.h"
5 #include <QObject>
6 #include "qsplineseries.h"
4 #include "qsplineseries.h"
7 #include "xychartitem_p.h"
5 #include "xychartitem_p.h"
6 #include "xychartanimationitem_p.h"
7 #include <QGraphicsItem>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class SplineChartItem : public XYChartItem
11 class SplineChartItem : public XYChartItem
12 {
12 {
13 Q_OBJECT
13 Q_OBJECT
14 public:
14 public:
15 SplineChartItem(QSplineSeries* series, QGraphicsObject *parent = 0);
15 SplineChartItem(QSplineSeries* series, QGraphicsItem *parent = 0);
16
16
17 //from QGraphicsItem
17 //from QGraphicsItem
18 QRectF boundingRect() const;
18 QRectF boundingRect() const;
19 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
19 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
20 QPainterPath shape() const;
20 QPainterPath shape() const;
21
21
22 void setPen(const QPen& pen);
22 void setLinePen(const QPen& pen);
23 void setPointsVisible(bool visible);
23 void setPointsVisible(bool visible);
24
24
25 public slots:
26 void handleUpdated();
27
25 protected:
28 protected:
26 void setGeometry(QVector<QPointF>& points);
29 void setGeometry(QVector<QPointF>& points);
27
30
28 private:
31 private:
29 QPointF calculateGeometryControlPoint(int index) const;
32 QPointF calculateGeometryControlPoint(int index) const;
30
33
31 private:
34 private:
32 QSplineSeries* m_series;
35 QSplineSeries* m_series;
33 QPainterPath m_path;
36 QPainterPath m_path;
34 QRectF m_rect;
37 QRectF m_rect;
35 QPen m_pen;
38 QPen m_pen;
39
40 template<class,class> friend class XYChartAnimator;
36 };
41 };
37
42
43 typedef XYChartAnimationItem<SplineChartItem,QSplineSeries> SplineChartAnimationItem;
44
38 QTCOMMERCIALCHART_END_NAMESPACE
45 QTCOMMERCIALCHART_END_NAMESPACE
39
46
40 #endif // SPLINECHARTITEM_P_H
47 #endif // SPLINECHARTITEM_P_H
@@ -1,12 +1,14
1 INCLUDEPATH += $$PWD
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3
4 SOURCES += \
4 SOURCES += \
5 $$PWD/xychartitem.cpp \
5 $$PWD/xychartitem.cpp \
6 $$PWD/qxyseries.cpp
6 $$PWD/qxyseries.cpp
7
7
8 PRIVATE_HEADERS += \
8 PRIVATE_HEADERS += \
9 $$PWD/xychartitem_p.h \
9 $$PWD/xychartitem_p.h \
10 $$PWD/xychartanimationitem_p.h \
11 $$PWD/xychartanimator_p.h
10
12
11 PUBLIC_HEADERS += \
13 PUBLIC_HEADERS += \
12 $$PWD/qxyseries.h No newline at end of file
14 $$PWD/qxyseries.h
@@ -1,143 +1,142
1 #include "xychartitem_p.h"
1 #include "xychartitem_p.h"
2 #include "qxyseries.h"
2 #include "qxyseries.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include <QPainter>
4 #include <QPainter>
5
5
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 //TODO: optimize : remove points which are not visible
9 //TODO: optimize : remove points which are not visible
10
10
11 XYChartItem::XYChartItem(QXYSeries* series,QGraphicsItem *parent):ChartItem(parent),
11 XYChartItem::XYChartItem(QXYSeries* series,QGraphicsItem *parent):ChartItem(parent),
12 m_minX(0),
12 m_minX(0),
13 m_maxX(0),
13 m_maxX(0),
14 m_minY(0),
14 m_minY(0),
15 m_maxY(0),
15 m_maxY(0),
16 m_series(series)
16 m_series(series)
17 {
17 {
18 QObject::connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
18 QObject::connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
19 QObject::connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
19 QObject::connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
20 QObject::connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
20 QObject::connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
21
21
22 }
22 }
23
23
24 QPointF XYChartItem::calculateGeometryPoint(const QPointF& point) const
24 QPointF XYChartItem::calculateGeometryPoint(const QPointF& point) const
25 {
25 {
26 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
26 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
27 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
27 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
28 qreal x = (point.x() - m_minX)* deltaX;
28 qreal x = (point.x() - m_minX)* deltaX;
29 qreal y = (point.y() - m_minY)*-deltaY + m_size.height();
29 qreal y = (point.y() - m_minY)*-deltaY + m_size.height();
30 return QPointF(x,y);
30 return QPointF(x,y);
31 }
31 }
32
32
33
33
34 QPointF XYChartItem::calculateGeometryPoint(int index) const
34 QPointF XYChartItem::calculateGeometryPoint(int index) const
35 {
35 {
36 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
36 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
37 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
37 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
38 qreal x = (m_series->x(index) - m_minX)* deltaX;
38 qreal x = (m_series->x(index) - m_minX)* deltaX;
39 qreal y = (m_series->y(index) - m_minY)*-deltaY + m_size.height();
39 qreal y = (m_series->y(index) - m_minY)*-deltaY + m_size.height();
40 return QPointF(x,y);
40 return QPointF(x,y);
41 }
41 }
42
42
43 QVector<QPointF> XYChartItem::calculateGeometryPoints() const
43 QVector<QPointF> XYChartItem::calculateGeometryPoints() const
44 {
44 {
45 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
45 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
46 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
46 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
47
47
48 QVector<QPointF> points;
48 QVector<QPointF> points;
49 points.reserve(m_series->count());
49 points.reserve(m_series->count());
50 for (int i = 0; i < m_series->count(); ++i) {
50 for (int i = 0; i < m_series->count(); ++i) {
51 qreal x = (m_series->x(i) - m_minX)* deltaX;
51 qreal x = (m_series->x(i) - m_minX)* deltaX;
52 qreal y = (m_series->y(i) - m_minY)*-deltaY + m_size.height();
52 qreal y = (m_series->y(i) - m_minY)*-deltaY + m_size.height();
53 points << QPointF(x,y);
53 points << QPointF(x,y);
54 }
54 }
55 return points;
55 return points;
56 }
56 }
57
57
58
59 void XYChartItem::updatePoints(QVector<QPointF>& points)
58 void XYChartItem::updatePoints(QVector<QPointF>& points)
60 {
59 {
61 setGeometry(points);
60 setGeometry(points);
62 }
61 }
63
62
64 void XYChartItem::updatePoint(int index,QPointF& newPoint)
63 void XYChartItem::updatePoint(QVector<QPointF>& points)
65 {
64 {
66 m_points.replace(index,newPoint);
65 setGeometry(points);
67 setGeometry(m_points);
68 }
66 }
69
67
70 void XYChartItem::setGeometry(QVector<QPointF>& points)
68 void XYChartItem::setGeometry(QVector<QPointF>& points)
71 {
69 {
72 m_points = points;
70 m_points = points;
73 }
71 }
74
72
75 //handlers
73 //handlers
76
74
77 void XYChartItem::handlePointAdded(int index)
75 void XYChartItem::handlePointAdded(int index)
78 {
76 {
79 Q_ASSERT(index<m_series->count());
77 Q_ASSERT(index<m_series->count());
80 Q_ASSERT(index>=0);
78 Q_ASSERT(index>=0);
81
79
82 QPointF point = calculateGeometryPoint(index);
80 QPointF point = calculateGeometryPoint(index);
83 QVector<QPointF> points = m_points;
81 QVector<QPointF> points = m_points;
84 points.insert(index,point);
82 points.insert(index,point);
85 updatePoints(points);
83 updatePoints(points);
86 update();
84 update();
87 }
85 }
88 void XYChartItem::handlePointRemoved(int index)
86 void XYChartItem::handlePointRemoved(int index)
89 {
87 {
90 Q_ASSERT(index<m_series->count());
88 Q_ASSERT(index<m_series->count());
91 Q_ASSERT(index>=0);
89 Q_ASSERT(index>=0);
92
93 QPointF point = calculateGeometryPoint(index);
90 QPointF point = calculateGeometryPoint(index);
94 QVector<QPointF> points = m_points;
91 QVector<QPointF> points = m_points;
95 points.remove(index);
92 points.remove(index);
96 updatePoints(points);
93 updatePoints(points);
97 update();
94 update();
98 }
95 }
99
96
100 void XYChartItem::handlePointReplaced(int index)
97 void XYChartItem::handlePointReplaced(int index)
101 {
98 {
102 Q_ASSERT(index<m_series->count());
99 Q_ASSERT(index<m_series->count());
103 Q_ASSERT(index>=0);
100 Q_ASSERT(index>=0);
104 QPointF point = calculateGeometryPoint(index);
101 QPointF point = calculateGeometryPoint(index);
105 updatePoint(index,point);
102 QVector<QPointF> points = m_points;
103 m_points.replace(index,point);
104 updatePoint(points);
106 update();
105 update();
107 }
106 }
108
107
109 void XYChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
108 void XYChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
110 {
109 {
111 m_minX=minX;
110 m_minX=minX;
112 m_maxX=maxX;
111 m_maxX=maxX;
113 m_minY=minY;
112 m_minY=minY;
114 m_maxY=maxY;
113 m_maxY=maxY;
115
114
116 if(isEmpty()) return;
115 if(isEmpty()) return;
117 QVector<QPointF> points = calculateGeometryPoints();
116 QVector<QPointF> points = calculateGeometryPoints();
118 updatePoints(points);
117 updatePoints(points);
119 update();
118 update();
120 }
119 }
121
120
122 void XYChartItem::handleGeometryChanged(const QRectF& rect)
121 void XYChartItem::handleGeometryChanged(const QRectF& rect)
123 {
122 {
124 Q_ASSERT(rect.isValid());
123 Q_ASSERT(rect.isValid());
125 m_size=rect.size();
124 m_size=rect.size();
126 m_clipRect=rect.translated(-rect.topLeft());
125 m_clipRect=rect.translated(-rect.topLeft());
127 setPos(rect.topLeft());
126 setPos(rect.topLeft());
128
127
129 if(isEmpty()) return;
128 if(isEmpty()) return;
130 QVector<QPointF> points = calculateGeometryPoints();
129 QVector<QPointF> points = calculateGeometryPoints();
131 updatePoints(points);
130 updatePoints(points);
132 update();
131 update();
133 }
132 }
134
133
135
134
136 bool XYChartItem::isEmpty()
135 bool XYChartItem::isEmpty()
137 {
136 {
138 return !m_clipRect.isValid() || m_maxX - m_minX == 0 || m_maxY - m_minY ==0 ;
137 return !m_clipRect.isValid() || m_maxX - m_minX == 0 || m_maxY - m_minY ==0 ;
139 }
138 }
140
139
141 #include "moc_xychartitem_p.cpp"
140 #include "moc_xychartitem_p.cpp"
142
141
143 QTCOMMERCIALCHART_END_NAMESPACE
142 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,55 +1,58
1 #ifndef XYCHARTITEM_H
1 #ifndef XYCHARTITEM_H
2 #define XYCHARTITEM_H
2 #define XYCHARTITEM_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "chartitem_p.h"
5 #include "chartitem_p.h"
6 #include <QPen>
6 #include <QPen>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class ChartPresenter;
10 class ChartPresenter;
11 class QXYSeries;
11 class QXYSeries;
12
12
13 class XYChartItem : public QObject , public ChartItem
13 class XYChartItem : public QObject , public ChartItem
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16 public:
16 public:
17 explicit XYChartItem(QXYSeries* series,QGraphicsItem *parent = 0);
17 explicit XYChartItem(QXYSeries* series,QGraphicsItem *parent = 0);
18 ~ XYChartItem(){};
18 ~ XYChartItem(){};
19
19
20 QVector<QPointF> points() const {return m_points;}
20 QVector<QPointF> points() const {return m_points;}
21 QRectF clipRect() const { return m_clipRect;}
21 QRectF clipRect() const { return m_clipRect;}
22
22
23 public slots:
23 public slots:
24 void handlePointAdded(int index);
24 void handlePointAdded(int index);
25 void handlePointRemoved(int index);
25 void handlePointRemoved(int index);
26 void handlePointReplaced(int index);
26 void handlePointReplaced(int index);
27 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
27 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
28 void handleGeometryChanged(const QRectF& size);
28 void handleGeometryChanged(const QRectF& size);
29
29
30 protected:
30 protected:
31 virtual void updatePoints(QVector<QPointF>& points);
31 virtual void updatePoints(QVector<QPointF>& points);
32 virtual void updatePoint(int index,QPointF& newPoint);
32 virtual void updatePoint(QVector<QPointF>& points);
33 virtual void setGeometry(QVector<QPointF>& points);
33 virtual void setGeometry(QVector<QPointF>& points);
34
34 QPointF calculateGeometryPoint(const QPointF& point) const;
35 QPointF calculateGeometryPoint(const QPointF& point) const;
35 QPointF calculateGeometryPoint(int index) const;
36 QPointF calculateGeometryPoint(int index) const;
36 QVector<QPointF> calculateGeometryPoints() const;
37 QVector<QPointF> calculateGeometryPoints() const;
37
38
38 private:
39 private:
39 inline bool isEmpty();
40 inline bool isEmpty();
40
41
41 private:
42 private:
42 qreal m_minX;
43 qreal m_minX;
43 qreal m_maxX;
44 qreal m_maxX;
44 qreal m_minY;
45 qreal m_minY;
45 qreal m_maxY;
46 qreal m_maxY;
46 QXYSeries* m_series;
47 QXYSeries* m_series;
47 QSizeF m_size;
48 QSizeF m_size;
48 QRectF m_clipRect;
49 QRectF m_clipRect;
49 QVector<QPointF> m_points;
50 QVector<QPointF> m_points;
50
51
52 template<class,class> friend class XYChartAnimator;
53
51 };
54 };
52
55
53 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
54
57
55 #endif
58 #endif
General Comments 0
You need to be logged in to leave comments. Login now