##// END OF EJS Templates
Adds PIMPL to qchart
Michal Klocek -
r740:344f31f1bb27
parent child
Show More
@@ -1,45 +1,45
1 #include "declarativechart.h"
1 #include "declarativechart.h"
2 #include <QPainter>
2 #include <QPainter>
3
3
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
5
6 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
6 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
7 : QDeclarativeItem(parent),
7 : QDeclarativeItem(parent),
8 m_chart(new QChart(this))
8 m_chart(new QChart(this))
9 {
9 {
10 setFlag(QGraphicsItem::ItemHasNoContents, false);
10 setFlag(QGraphicsItem::ItemHasNoContents, false);
11 }
11 }
12
12
13 DeclarativeChart::~DeclarativeChart()
13 DeclarativeChart::~DeclarativeChart()
14 {
14 {
15 delete m_chart;
15 delete m_chart;
16 }
16 }
17
17
18 DeclarativeChart::ChartTheme DeclarativeChart::theme()
18 DeclarativeChart::ChartTheme DeclarativeChart::theme()
19 {
19 {
20 return (ChartTheme) m_chart->chartTheme();
20 return (ChartTheme) m_chart->theme();
21 }
21 }
22
22
23 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
23 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
24 {
24 {
25 Q_UNUSED(oldGeometry)
25 Q_UNUSED(oldGeometry)
26
26
27 if (newGeometry.isValid()) {
27 if (newGeometry.isValid()) {
28 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
28 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
29 m_chart->resize(newGeometry.width(), newGeometry.height());
29 m_chart->resize(newGeometry.width(), newGeometry.height());
30 }
30 }
31 }
31 }
32 }
32 }
33
33
34 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
34 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
35 {
35 {
36 Q_UNUSED(option)
36 Q_UNUSED(option)
37 Q_UNUSED(widget)
37 Q_UNUSED(widget)
38
38
39 // TODO: optimized?
39 // TODO: optimized?
40 painter->setRenderHint(QPainter::Antialiasing, true);
40 painter->setRenderHint(QPainter::Antialiasing, true);
41 }
41 }
42
42
43 #include "moc_declarativechart.cpp"
43 #include "moc_declarativechart.cpp"
44
44
45 QTCOMMERCIALCHART_END_NAMESPACE
45 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,48 +1,48
1 #ifndef DECLARATIVECHART_H
1 #ifndef DECLARATIVECHART_H
2 #define DECLARATIVECHART_H
2 #define DECLARATIVECHART_H
3
3
4 #include <QtCore/QtGlobal>
4 #include <QtCore/QtGlobal>
5 #include <QDeclarativeItem>
5 #include <QDeclarativeItem>
6 #include <qchart.h>
6 #include <qchart.h>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class DeclarativeChart : public QDeclarativeItem
10 class DeclarativeChart : public QDeclarativeItem
11 // TODO: for QTQUICK2: extend QQuickPainterItem instead
11 // TODO: for QTQUICK2: extend QQuickPainterItem instead
12 //class DeclarativeChart : public QQuickPaintedItem, public Chart
12 //class DeclarativeChart : public QQuickPaintedItem, public Chart
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 Q_ENUMS(ChartTheme)
15 Q_ENUMS(ChartTheme)
16 Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme)
16 Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme)
17
17
18 public:
18 public:
19 enum ChartTheme {
19 enum ChartTheme {
20 ThemeDefault,
20 ThemeDefault,
21 ThemeLight,
21 ThemeLight,
22 ThemeBlueCerulean,
22 ThemeBlueCerulean,
23 ThemeDark,
23 ThemeDark,
24 ThemeBrownSand,
24 ThemeBrownSand,
25 ThemeBlueNcs,
25 ThemeBlueNcs,
26 ThemeIcy,
26 ThemeIcy,
27 ThemeScientific
27 ThemeScientific
28 };
28 };
29 DeclarativeChart(QDeclarativeItem *parent = 0);
29 DeclarativeChart(QDeclarativeItem *parent = 0);
30 ~DeclarativeChart();
30 ~DeclarativeChart();
31
31
32 public: // From QDeclarativeItem/QGraphicsItem
32 public: // From QDeclarativeItem/QGraphicsItem
33 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
33 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
34 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
34 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
35
35
36 public:
36 public:
37 void setTheme(ChartTheme theme) {m_chart->setChartTheme((QChart::ChartTheme) theme);}
37 void setTheme(ChartTheme theme) {m_chart->setTheme((QChart::ChartTheme) theme);}
38 ChartTheme theme();
38 ChartTheme theme();
39
39
40 public:
40 public:
41 // Extending QChart with DeclarativeChart is not possible because QObject does not support
41 // Extending QChart with DeclarativeChart is not possible because QObject does not support
42 // multi inheritance, so we now have a QChart as a member instead
42 // multi inheritance, so we now have a QChart as a member instead
43 QChart *m_chart;
43 QChart *m_chart;
44 };
44 };
45
45
46 QTCOMMERCIALCHART_END_NAMESPACE
46 QTCOMMERCIALCHART_END_NAMESPACE
47
47
48 #endif // DECLARATIVECHART_H
48 #endif // DECLARATIVECHART_H
@@ -1,33 +1,35
1 #ifndef CHARTBACKGROUND_H_
1 #ifndef CHARTBACKGROUND_H_
2 #define CHARTBACKGROUND_H_
2 #define CHARTBACKGROUND_H_
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QGraphicsRectItem>
5 #include <QGraphicsRectItem>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 class ChartBackground: public QGraphicsRectItem
9 class ChartBackground: public QGraphicsRectItem
10 {
10 {
11 public:
11 public:
12 ChartBackground(QGraphicsItem *parent =0);
12 ChartBackground(QGraphicsItem *parent =0);
13 ~ChartBackground();
13 ~ChartBackground();
14
14
15 void setDimeter(int dimater);
15 void setDimeter(int dimater);
16 int diameter() const;
16 int diameter() const;
17
17
18
18
19 protected:
19 protected:
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
21
21
22
22
23 private:
23 private:
24 int roundness(qreal size) const;
24 int roundness(qreal size) const;
25
25
26 private:
26 private:
27 int m_diameter;
27 int m_diameter;
28
28
29 };
29 };
30
30
31 QTCOMMERCIALCHART_END_NAMESPACE
32
31 #endif /* CHARTBACKGROUND_H_ */
33 #endif /* CHARTBACKGROUND_H_ */
32
34
33 QTCOMMERCIALCHART_END_NAMESPACE
35
@@ -1,385 +1,385
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 #include "chartanimator_p.h"
6 #include "chartanimator_p.h"
7 //series
7 //series
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 "qpieseries.h"
13 #include "qpieseries.h"
14 #include "qscatterseries.h"
14 #include "qscatterseries.h"
15 #include "qsplineseries.h"
15 #include "qsplineseries.h"
16 //items
16 //items
17 #include "axisitem_p.h"
17 #include "axisitem_p.h"
18 #include "areachartitem_p.h"
18 #include "areachartitem_p.h"
19 #include "barchartitem_p.h"
19 #include "barchartitem_p.h"
20 #include "stackedbarchartitem_p.h"
20 #include "stackedbarchartitem_p.h"
21 #include "percentbarchartitem_p.h"
21 #include "percentbarchartitem_p.h"
22 #include "linechartitem_p.h"
22 #include "linechartitem_p.h"
23 #include "piechartitem_p.h"
23 #include "piechartitem_p.h"
24 #include "scatterchartitem_p.h"
24 #include "scatterchartitem_p.h"
25 #include "splinechartitem_p.h"
25 #include "splinechartitem_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
29 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
30 m_chart(chart),
30 m_chart(chart),
31 m_animator(0),
31 m_animator(0),
32 m_dataset(dataset),
32 m_dataset(dataset),
33 m_chartTheme(0),
33 m_chartTheme(0),
34 m_rect(QRectF(QPoint(0,0),m_chart->size())),
34 m_rect(QRectF(QPoint(0,0),m_chart->size())),
35 m_options(QChart::NoAnimation),
35 m_options(QChart::NoAnimation),
36 m_themeForce(false)
36 m_themeForce(false)
37 {
37 {
38 createConnections();
38 createConnections();
39 setChartTheme(QChart::ChartThemeDefault,false);
39 setTheme(QChart::ChartThemeDefault,false);
40 }
40 }
41
41
42 ChartPresenter::~ChartPresenter()
42 ChartPresenter::~ChartPresenter()
43 {
43 {
44 delete m_chartTheme;
44 delete m_chartTheme;
45 }
45 }
46
46
47 void ChartPresenter::createConnections()
47 void ChartPresenter::createConnections()
48 {
48 {
49 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
49 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
50 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
50 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*)));
51 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*)));
52 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*)));
53 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
54 }
54 }
55
55
56
56
57 QRectF ChartPresenter::geometry() const
57 QRectF ChartPresenter::geometry() const
58 {
58 {
59 return m_rect;
59 return m_rect;
60 }
60 }
61
61
62 void ChartPresenter::handleGeometryChanged()
62 void ChartPresenter::handleGeometryChanged()
63 {
63 {
64 QRectF rect(QPoint(0,0),m_chart->size());
64 QRectF rect(QPoint(0,0),m_chart->size());
65 rect.adjust(m_chart->padding(),m_chart->padding(), -m_chart->padding(), -m_chart->padding());
65 rect.adjust(m_chart->padding(),m_chart->padding(), -m_chart->padding(), -m_chart->padding());
66
66
67 //rewrite zoom stack
67 //rewrite zoom stack
68 /*
68 /*
69 for(int i=0;i<m_zoomStack.count();i++){
69 for(int i=0;i<m_zoomStack.count();i++){
70 QRectF r = m_zoomStack[i];
70 QRectF r = m_zoomStack[i];
71 qreal w = rect.width()/m_rect.width();
71 qreal w = rect.width()/m_rect.width();
72 qreal h = rect.height()/m_rect.height();
72 qreal h = rect.height()/m_rect.height();
73 QPointF tl = r.topLeft();
73 QPointF tl = r.topLeft();
74 tl.setX(tl.x()*w);
74 tl.setX(tl.x()*w);
75 tl.setY(tl.y()*h);
75 tl.setY(tl.y()*h);
76 QPointF br = r.bottomRight();
76 QPointF br = r.bottomRight();
77 br.setX(br.x()*w);
77 br.setX(br.x()*w);
78 br.setY(br.y()*h);
78 br.setY(br.y()*h);
79 r.setTopLeft(tl);
79 r.setTopLeft(tl);
80 r.setBottomRight(br);
80 r.setBottomRight(br);
81 m_zoomStack[i]=r;
81 m_zoomStack[i]=r;
82 }
82 }
83 */
83 */
84 m_rect = rect;
84 m_rect = rect;
85 Q_ASSERT(m_rect.isValid());
85 Q_ASSERT(m_rect.isValid());
86 emit geometryChanged(m_rect);
86 emit geometryChanged(m_rect);
87 }
87 }
88
88
89 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
89 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
90 {
90 {
91 Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS);
91 Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS);
92
92
93 if(m_options.testFlag(QChart::GridAxisAnimations)){
93 if(m_options.testFlag(QChart::GridAxisAnimations)){
94 m_animator->addAnimation(item);
94 m_animator->addAnimation(item);
95 }
95 }
96
96
97 if(axis==m_dataset->axisX()){
97 if(axis==m_dataset->axisX()){
98 m_chartTheme->decorate(axis,true,m_themeForce);
98 m_chartTheme->decorate(axis,true,m_themeForce);
99 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
99 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
100 //initialize
100 //initialize
101 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
101 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
102
102
103 }
103 }
104 else{
104 else{
105 m_chartTheme->decorate(axis,false,m_themeForce);
105 m_chartTheme->decorate(axis,false,m_themeForce);
106 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
106 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
107 //initialize
107 //initialize
108 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
108 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
109 }
109 }
110
110
111 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
111 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
112 //initialize
112 //initialize
113 item->handleGeometryChanged(m_rect);
113 item->handleGeometryChanged(m_rect);
114 m_axisItems.insert(axis, item);
114 m_axisItems.insert(axis, item);
115 }
115 }
116
116
117 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
117 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
118 {
118 {
119 Axis* item = m_axisItems.take(axis);
119 Axis* item = m_axisItems.take(axis);
120 Q_ASSERT(item);
120 Q_ASSERT(item);
121 if(m_animator) m_animator->removeAnimation(item);
121 if(m_animator) m_animator->removeAnimation(item);
122 delete item;
122 delete item;
123 }
123 }
124
124
125
125
126 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
126 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
127 {
127 {
128 Chart *item = 0 ;
128 Chart *item = 0 ;
129
129
130 switch(series->type())
130 switch(series->type())
131 {
131 {
132 case QSeries::SeriesTypeLine: {
132 case QSeries::SeriesTypeLine: {
133
133
134 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
134 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
135 LineChartItem* line = new LineChartItem(lineSeries,this);
135 LineChartItem* line = new LineChartItem(lineSeries,this);
136 if(m_options.testFlag(QChart::SeriesAnimations)) {
136 if(m_options.testFlag(QChart::SeriesAnimations)) {
137 m_animator->addAnimation(line);
137 m_animator->addAnimation(line);
138 }
138 }
139 m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce);
139 m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce);
140 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&)));
140 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&)));
141 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
141 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
142 item = line;
142 item = line;
143 break;
143 break;
144 }
144 }
145
145
146 case QSeries::SeriesTypeArea: {
146 case QSeries::SeriesTypeArea: {
147
147
148 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
148 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
149 AreaChartItem* area = new AreaChartItem(areaSeries,this);
149 AreaChartItem* area = new AreaChartItem(areaSeries,this);
150 if(m_options.testFlag(QChart::SeriesAnimations)) {
150 if(m_options.testFlag(QChart::SeriesAnimations)) {
151 m_animator->addAnimation(area->upperLineItem());
151 m_animator->addAnimation(area->upperLineItem());
152 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
152 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
153 }
153 }
154 m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce);
154 m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce);
155 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
155 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
156 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
156 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
157 item=area;
157 item=area;
158 break;
158 break;
159 }
159 }
160
160
161 case QSeries::SeriesTypeBar: {
161 case QSeries::SeriesTypeBar: {
162 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
162 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
163 BarChartItem* bar = new BarChartItem(barSeries,this);
163 BarChartItem* bar = new BarChartItem(barSeries,this);
164 if(m_options.testFlag(QChart::SeriesAnimations)) {
164 if(m_options.testFlag(QChart::SeriesAnimations)) {
165 m_animator->addAnimation(bar);
165 m_animator->addAnimation(bar);
166 }
166 }
167 m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce);
167 m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce);
168 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
168 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
169 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
169 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
170 item=bar;
170 item=bar;
171 break;
171 break;
172 }
172 }
173
173
174 case QSeries::SeriesTypeStackedBar: {
174 case QSeries::SeriesTypeStackedBar: {
175 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
175 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
176 StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this);
176 StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this);
177 if(m_options.testFlag(QChart::SeriesAnimations)) {
177 if(m_options.testFlag(QChart::SeriesAnimations)) {
178 m_animator->addAnimation(bar);
178 m_animator->addAnimation(bar);
179 }
179 }
180 m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce);
180 m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce);
181 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
181 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
182 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
182 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
183 item=bar;
183 item=bar;
184 break;
184 break;
185 }
185 }
186
186
187 case QSeries::SeriesTypePercentBar: {
187 case QSeries::SeriesTypePercentBar: {
188 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
188 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
189 PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this);
189 PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this);
190 if(m_options.testFlag(QChart::SeriesAnimations)) {
190 if(m_options.testFlag(QChart::SeriesAnimations)) {
191 m_animator->addAnimation(bar);
191 m_animator->addAnimation(bar);
192 }
192 }
193 m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce);
193 m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce);
194 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
194 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
195 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
195 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
196 item=bar;
196 item=bar;
197 break;
197 break;
198 }
198 }
199
199
200 case QSeries::SeriesTypeScatter: {
200 case QSeries::SeriesTypeScatter: {
201 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
201 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
202 ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this);
202 ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this);
203 if(m_options.testFlag(QChart::SeriesAnimations)) {
203 if(m_options.testFlag(QChart::SeriesAnimations)) {
204 m_animator->addAnimation(scatter);
204 m_animator->addAnimation(scatter);
205 }
205 }
206 m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce);
206 m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce);
207 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&)));
207 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&)));
208 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
208 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
209 item = scatter;
209 item = scatter;
210 break;
210 break;
211 }
211 }
212
212
213 case QSeries::SeriesTypePie: {
213 case QSeries::SeriesTypePie: {
214 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
214 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
215 PieChartItem* pie = new PieChartItem(pieSeries, this);
215 PieChartItem* pie = new PieChartItem(pieSeries, this);
216 if(m_options.testFlag(QChart::SeriesAnimations)) {
216 if(m_options.testFlag(QChart::SeriesAnimations)) {
217 m_animator->addAnimation(pie);
217 m_animator->addAnimation(pie);
218 }
218 }
219 m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce);
219 m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce);
220 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&)));
220 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&)));
221 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
221 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
222 // Hide all from background when there is only piechart
222 // Hide all from background when there is only piechart
223 // TODO: refactor this ugly code... should be one setting for this
223 // TODO: refactor this ugly code... should be one setting for this
224 if (m_chartItems.count() == 0) {
224 if (m_chartItems.count() == 0) {
225 m_chart->axisX()->hide();
225 m_chart->axisX()->hide();
226 m_chart->axisY()->hide();
226 m_chart->axisY()->hide();
227 }
227 }
228 item=pie;
228 item=pie;
229 break;
229 break;
230 }
230 }
231
231
232 case QSeries::SeriesTypeSpline: {
232 case QSeries::SeriesTypeSpline: {
233 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
233 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
234 SplineChartItem* spline = new SplineChartItem(splineSeries, this);
234 SplineChartItem* spline = new SplineChartItem(splineSeries, this);
235 if(m_options.testFlag(QChart::SeriesAnimations)) {
235 if(m_options.testFlag(QChart::SeriesAnimations)) {
236 m_animator->addAnimation(spline);
236 m_animator->addAnimation(spline);
237 }
237 }
238 m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce);
238 m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce);
239 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&)));
239 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&)));
240 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
240 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
241 item=spline;
241 item=spline;
242 break;
242 break;
243 }
243 }
244 default: {
244 default: {
245 qDebug()<< "Series type" << series->type() << "not implemented.";
245 qDebug()<< "Series type" << series->type() << "not implemented.";
246 break;
246 break;
247 }
247 }
248 }
248 }
249
249
250 //initialize
250 //initialize
251 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
251 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
252 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
252 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
253 m_chartItems.insert(series,item);
253 m_chartItems.insert(series,item);
254 }
254 }
255
255
256 void ChartPresenter::handleSeriesRemoved(QSeries* series)
256 void ChartPresenter::handleSeriesRemoved(QSeries* series)
257 {
257 {
258 Chart* item = m_chartItems.take(series);
258 Chart* item = m_chartItems.take(series);
259 Q_ASSERT(item);
259 Q_ASSERT(item);
260 if(m_animator) {
260 if(m_animator) {
261 //small hack to handle area animations
261 //small hack to handle area animations
262 if(series->type()==QSeries::SeriesTypeArea){
262 if(series->type()==QSeries::SeriesTypeArea){
263 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
263 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
264 AreaChartItem* area = static_cast<AreaChartItem*>(item);
264 AreaChartItem* area = static_cast<AreaChartItem*>(item);
265 m_animator->removeAnimation(area->upperLineItem());
265 m_animator->removeAnimation(area->upperLineItem());
266 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
266 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
267 }else
267 }else
268 m_animator->removeAnimation(item);
268 m_animator->removeAnimation(item);
269 }
269 }
270 delete item;
270 delete item;
271 }
271 }
272
272
273 void ChartPresenter::setChartTheme(QChart::ChartTheme theme,bool force)
273 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
274 {
274 {
275 if(m_chartTheme && m_chartTheme->id() == theme) return;
275 if(m_chartTheme && m_chartTheme->id() == theme) return;
276 delete m_chartTheme;
276 delete m_chartTheme;
277 m_themeForce = force;
277 m_themeForce = force;
278 m_chartTheme = ChartTheme::createTheme(theme);
278 m_chartTheme = ChartTheme::createTheme(theme);
279 m_chartTheme->decorate(m_chart,m_themeForce);
279 m_chartTheme->decorate(m_chart,m_themeForce);
280 m_chartTheme->decorate(&m_chart->legend(),m_themeForce);
280 m_chartTheme->decorate(&m_chart->legend(),m_themeForce);
281 resetAllElements();
281 resetAllElements();
282 }
282 }
283
283
284 QChart::ChartTheme ChartPresenter::chartTheme()
284 QChart::ChartTheme ChartPresenter::theme()
285 {
285 {
286 return m_chartTheme->id();
286 return m_chartTheme->id();
287 }
287 }
288
288
289 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
289 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
290 {
290 {
291 if(m_options!=options) {
291 if(m_options!=options) {
292
292
293 m_options=options;
293 m_options=options;
294
294
295 if(m_options!=QChart::NoAnimation && !m_animator) {
295 if(m_options!=QChart::NoAnimation && !m_animator) {
296 m_animator= new ChartAnimator(this);
296 m_animator= new ChartAnimator(this);
297
297
298 }
298 }
299 resetAllElements();
299 resetAllElements();
300 }
300 }
301
301
302 }
302 }
303
303
304 void ChartPresenter::resetAllElements()
304 void ChartPresenter::resetAllElements()
305 {
305 {
306 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
306 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
307 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
307 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
308
308
309 foreach(QChartAxis* axis, axisList) {
309 foreach(QChartAxis* axis, axisList) {
310 handleAxisRemoved(axis);
310 handleAxisRemoved(axis);
311 handleAxisAdded(axis,m_dataset->domain(axis));
311 handleAxisAdded(axis,m_dataset->domain(axis));
312 }
312 }
313 foreach(QSeries* series, seriesList) {
313 foreach(QSeries* series, seriesList) {
314 handleSeriesRemoved(series);
314 handleSeriesRemoved(series);
315 handleSeriesAdded(series,m_dataset->domain(series));
315 handleSeriesAdded(series,m_dataset->domain(series));
316 }
316 }
317 }
317 }
318
318
319 void ChartPresenter::zoomIn()
319 void ChartPresenter::zoomIn()
320 {
320 {
321 QRectF rect = geometry();
321 QRectF rect = geometry();
322 rect.setWidth(rect.width()/2);
322 rect.setWidth(rect.width()/2);
323 rect.setHeight(rect.height()/2);
323 rect.setHeight(rect.height()/2);
324 rect.moveCenter(geometry().center());
324 rect.moveCenter(geometry().center());
325 zoomIn(rect);
325 zoomIn(rect);
326 }
326 }
327
327
328 void ChartPresenter::zoomIn(const QRectF& rect)
328 void ChartPresenter::zoomIn(const QRectF& rect)
329 {
329 {
330 QRectF r = rect.normalized();
330 QRectF r = rect.normalized();
331 r.translate(-m_chart->padding(), -m_chart->padding());
331 r.translate(-m_chart->padding(), -m_chart->padding());
332 if(m_animator) {
332 if(m_animator) {
333
333
334 QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height());
334 QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height());
335 m_animator->setState(ChartAnimator::ZoomInState,point);
335 m_animator->setState(ChartAnimator::ZoomInState,point);
336 }
336 }
337 m_dataset->zoomInDomain(r,geometry().size());
337 m_dataset->zoomInDomain(r,geometry().size());
338 if(m_animator) {
338 if(m_animator) {
339 m_animator->setState(ChartAnimator::ShowState);
339 m_animator->setState(ChartAnimator::ShowState);
340 }
340 }
341 }
341 }
342
342
343 void ChartPresenter::zoomOut()
343 void ChartPresenter::zoomOut()
344 {
344 {
345 if(m_animator)
345 if(m_animator)
346 {
346 {
347 m_animator->setState(ChartAnimator::ZoomOutState);
347 m_animator->setState(ChartAnimator::ZoomOutState);
348 }
348 }
349
349
350 QSizeF size = geometry().size();
350 QSizeF size = geometry().size();
351 QRectF rect = geometry();
351 QRectF rect = geometry();
352 rect.translate(-m_chart->padding(), -m_chart->padding());
352 rect.translate(-m_chart->padding(), -m_chart->padding());
353 m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size);
353 m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size);
354 //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
354 //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
355
355
356 if(m_animator){
356 if(m_animator){
357 m_animator->setState(ChartAnimator::ShowState);
357 m_animator->setState(ChartAnimator::ShowState);
358 }
358 }
359 }
359 }
360
360
361 void ChartPresenter::scroll(int dx,int dy)
361 void ChartPresenter::scroll(int dx,int dy)
362 {
362 {
363 if(m_animator){
363 if(m_animator){
364 if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF());
364 if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF());
365 if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF());
365 if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF());
366 if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF());
366 if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF());
367 if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF());
367 if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF());
368 }
368 }
369
369
370 m_dataset->scrollDomain(dx,dy,geometry().size());
370 m_dataset->scrollDomain(dx,dy,geometry().size());
371
371
372 if(m_animator){
372 if(m_animator){
373 m_animator->setState(ChartAnimator::ShowState);
373 m_animator->setState(ChartAnimator::ShowState);
374 }
374 }
375 }
375 }
376
376
377 QChart::AnimationOptions ChartPresenter::animationOptions() const
377 QChart::AnimationOptions ChartPresenter::animationOptions() const
378 {
378 {
379 return m_options;
379 return m_options;
380 }
380 }
381
381
382
382
383 #include "moc_chartpresenter_p.cpp"
383 #include "moc_chartpresenter_p.cpp"
384
384
385 QTCOMMERCIALCHART_END_NAMESPACE
385 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,89 +1,89
1 #ifndef CHARTPRESENTER_H_
1 #ifndef CHARTPRESENTER_H_
2 #define CHARTPRESENTER_H_
2 #define CHARTPRESENTER_H_
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
5 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
6 #include "qchartaxis.h"
6 #include "qchartaxis.h"
7 #include <QRectF>
7 #include <QRectF>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class Chart;
11 class Chart;
12 class QSeries;
12 class QSeries;
13 class ChartDataSet;
13 class ChartDataSet;
14 class Domain;
14 class Domain;
15 class Axis;
15 class Axis;
16 class ChartTheme;
16 class ChartTheme;
17 class ChartAnimator;
17 class ChartAnimator;
18
18
19 class ChartPresenter: public QObject
19 class ChartPresenter: public QObject
20 {
20 {
21 Q_OBJECT
21 Q_OBJECT
22 public:
22 public:
23 enum ZValues {
23 enum ZValues {
24 BackgroundZValue = -1,
24 BackgroundZValue = -1,
25 ShadesZValue,
25 ShadesZValue,
26 GridZValue,
26 GridZValue,
27 LineChartZValue,
27 LineChartZValue,
28 BarSeriesZValue,
28 BarSeriesZValue,
29 ScatterSeriesZValue,
29 ScatterSeriesZValue,
30 PieSeriesZValue,
30 PieSeriesZValue,
31 AxisZValue,
31 AxisZValue,
32 LegendZValue
32 LegendZValue
33 };
33 };
34
34
35 ChartPresenter(QChart* chart,ChartDataSet *dataset);
35 ChartPresenter(QChart* chart,ChartDataSet *dataset);
36 virtual ~ChartPresenter();
36 virtual ~ChartPresenter();
37
37
38 void setMargin(int margin);
38 void setMargin(int margin);
39 int margin() const;
39 int margin() const;
40
40
41 QRectF geometry() const;
41 QRectF geometry() const;
42
42
43 ChartAnimator* animator() const {return m_animator;}
43 ChartAnimator* animator() const {return m_animator;}
44 ChartTheme *theme() { return m_chartTheme; }
44 ChartTheme *chartTheme() { return m_chartTheme; }
45 ChartDataSet *dataSet() { return m_dataset; }
45 ChartDataSet *dataSet() { return m_dataset; }
46
46
47 void setChartTheme(QChart::ChartTheme theme,bool force = true);
47 void setTheme(QChart::ChartTheme theme,bool force = true);
48 QChart::ChartTheme chartTheme();
48 QChart::ChartTheme theme();
49
49
50 void setAnimationOptions(QChart::AnimationOptions options);
50 void setAnimationOptions(QChart::AnimationOptions options);
51 QChart::AnimationOptions animationOptions() const;
51 QChart::AnimationOptions animationOptions() const;
52
52
53 QGraphicsItem* rootItem() const {return m_chart;};
53 QGraphicsItem* rootItem() const {return m_chart;};
54
54
55 void zoomIn();
55 void zoomIn();
56 void zoomIn(const QRectF& rect);
56 void zoomIn(const QRectF& rect);
57 void zoomOut();
57 void zoomOut();
58 void scroll(int dx,int dy);
58 void scroll(int dx,int dy);
59
59
60 private:
60 private:
61 void createConnections();
61 void createConnections();
62 void resetAllElements();
62 void resetAllElements();
63
63
64 public slots:
64 public slots:
65 void handleSeriesAdded(QSeries* series,Domain* domain);
65 void handleSeriesAdded(QSeries* series,Domain* domain);
66 void handleSeriesRemoved(QSeries* series);
66 void handleSeriesRemoved(QSeries* series);
67 void handleAxisAdded(QChartAxis* axis,Domain* domain);
67 void handleAxisAdded(QChartAxis* axis,Domain* domain);
68 void handleAxisRemoved(QChartAxis* axis);
68 void handleAxisRemoved(QChartAxis* axis);
69 void handleGeometryChanged();
69 void handleGeometryChanged();
70
70
71 signals:
71 signals:
72 void geometryChanged(const QRectF& rect);
72 void geometryChanged(const QRectF& rect);
73
73
74 private:
74 private:
75 QChart* m_chart;
75 QChart* m_chart;
76 ChartAnimator* m_animator;
76 ChartAnimator* m_animator;
77 ChartDataSet* m_dataset;
77 ChartDataSet* m_dataset;
78 ChartTheme *m_chartTheme;
78 ChartTheme *m_chartTheme;
79 QMap<QSeries*,Chart*> m_chartItems;
79 QMap<QSeries*,Chart*> m_chartItems;
80 QMap<QChartAxis*,Axis*> m_axisItems;
80 QMap<QChartAxis*,Axis*> m_axisItems;
81 QRectF m_rect;
81 QRectF m_rect;
82 QChart::AnimationOptions m_options;
82 QChart::AnimationOptions m_options;
83 bool m_themeForce;
83 bool m_themeForce;
84
84
85 };
85 };
86
86
87 QTCOMMERCIALCHART_END_NAMESPACE
87 QTCOMMERCIALCHART_END_NAMESPACE
88
88
89 #endif /* CHARTPRESENTER_H_ */
89 #endif /* CHARTPRESENTER_H_ */
@@ -1,191 +1,191
1 #include "piechartitem_p.h"
1 #include "piechartitem_p.h"
2 #include "piesliceitem_p.h"
2 #include "piesliceitem_p.h"
3 #include "qpieslice.h"
3 #include "qpieslice.h"
4 #include "qpiesliceprivate_p.h"
4 #include "qpiesliceprivate_p.h"
5 #include "qpieseries.h"
5 #include "qpieseries.h"
6 #include "chartpresenter_p.h"
6 #include "chartpresenter_p.h"
7 #include "chartdataset_p.h"
7 #include "chartdataset_p.h"
8 #include "chartanimator_p.h"
8 #include "chartanimator_p.h"
9 #include <QDebug>
9 #include <QDebug>
10 #include <QPainter>
10 #include <QPainter>
11 #include <QTimer>
11 #include <QTimer>
12
12
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14
14
15 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
15 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
16 :ChartItem(presenter),
16 :ChartItem(presenter),
17 m_series(series)
17 m_series(series)
18 {
18 {
19 Q_ASSERT(series);
19 Q_ASSERT(series);
20 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
20 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
21 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
21 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
22 connect(series, SIGNAL(piePositionChanged()), this, SLOT(handlePieLayoutChanged()));
22 connect(series, SIGNAL(piePositionChanged()), this, SLOT(handlePieLayoutChanged()));
23 connect(series, SIGNAL(pieSizeChanged()), this, SLOT(handlePieLayoutChanged()));
23 connect(series, SIGNAL(pieSizeChanged()), this, SLOT(handlePieLayoutChanged()));
24
24
25 QTimer::singleShot(0, this, SLOT(initialize()));
25 QTimer::singleShot(0, this, SLOT(initialize()));
26
26
27 // Note: the following does not affect as long as the item does not have anything to paint
27 // Note: the following does not affect as long as the item does not have anything to paint
28 setZValue(ChartPresenter::PieSeriesZValue);
28 setZValue(ChartPresenter::PieSeriesZValue);
29 }
29 }
30
30
31 PieChartItem::~PieChartItem()
31 PieChartItem::~PieChartItem()
32 {
32 {
33 // slices deleted automatically through QGraphicsItem
33 // slices deleted automatically through QGraphicsItem
34 }
34 }
35
35
36 void PieChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
36 void PieChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
37 {
37 {
38 Q_UNUSED(painter)
38 Q_UNUSED(painter)
39 // TODO: paint shadows for all components
39 // TODO: paint shadows for all components
40 // - get paths from items & merge & offset and draw with shadow color?
40 // - get paths from items & merge & offset and draw with shadow color?
41 //painter->setBrush(QBrush(Qt::red));
41 //painter->setBrush(QBrush(Qt::red));
42 //painter->drawRect(m_debugRect);
42 //painter->drawRect(m_debugRect);
43 }
43 }
44
44
45 void PieChartItem::initialize()
45 void PieChartItem::initialize()
46 {
46 {
47 handleSlicesAdded(m_series->slices());
47 handleSlicesAdded(m_series->slices());
48 }
48 }
49
49
50 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
50 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
51 {
51 {
52 bool isEmpty = m_slices.isEmpty();
52 bool isEmpty = m_slices.isEmpty();
53
53
54 presenter()->theme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
54 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
55
55
56 foreach (QPieSlice *s, slices) {
56 foreach (QPieSlice *s, slices) {
57 PieSliceItem* item = new PieSliceItem(this);
57 PieSliceItem* item = new PieSliceItem(this);
58 m_slices.insert(s, item);
58 m_slices.insert(s, item);
59 connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
59 connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
60 connect(item, SIGNAL(clicked(Qt::MouseButtons)), s, SIGNAL(clicked(Qt::MouseButtons)));
60 connect(item, SIGNAL(clicked(Qt::MouseButtons)), s, SIGNAL(clicked(Qt::MouseButtons)));
61 connect(item, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter()));
61 connect(item, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter()));
62 connect(item, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave()));
62 connect(item, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave()));
63
63
64 PieSliceData data = sliceData(s);
64 PieSliceData data = sliceData(s);
65
65
66 if (animator())
66 if (animator())
67 animator()->addAnimation(this, s, data, isEmpty);
67 animator()->addAnimation(this, s, data, isEmpty);
68 else
68 else
69 setLayout(s, data);
69 setLayout(s, data);
70 }
70 }
71 }
71 }
72
72
73 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
73 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
74 {
74 {
75 presenter()->theme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
75 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series), false);
76
76
77 foreach (QPieSlice *s, slices) {
77 foreach (QPieSlice *s, slices) {
78 if (animator())
78 if (animator())
79 animator()->removeAnimation(this, s);
79 animator()->removeAnimation(this, s);
80 else
80 else
81 destroySlice(s);
81 destroySlice(s);
82 }
82 }
83 }
83 }
84
84
85 void PieChartItem::handlePieLayoutChanged()
85 void PieChartItem::handlePieLayoutChanged()
86 {
86 {
87 PieLayout layout = calculateLayout();
87 PieLayout layout = calculateLayout();
88 applyLayout(layout);
88 applyLayout(layout);
89 update();
89 update();
90 }
90 }
91
91
92 void PieChartItem::handleSliceChanged()
92 void PieChartItem::handleSliceChanged()
93 {
93 {
94 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
94 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
95 Q_ASSERT(m_slices.contains(slice));
95 Q_ASSERT(m_slices.contains(slice));
96 PieSliceData data = sliceData(slice);
96 PieSliceData data = sliceData(slice);
97 updateLayout(slice, data);
97 updateLayout(slice, data);
98 update();
98 update();
99 }
99 }
100
100
101 void PieChartItem::handleDomainChanged(qreal, qreal, qreal, qreal)
101 void PieChartItem::handleDomainChanged(qreal, qreal, qreal, qreal)
102 {
102 {
103 // TODO
103 // TODO
104 }
104 }
105
105
106 void PieChartItem::handleGeometryChanged(const QRectF& rect)
106 void PieChartItem::handleGeometryChanged(const QRectF& rect)
107 {
107 {
108 prepareGeometryChange();
108 prepareGeometryChange();
109 m_rect = rect;
109 m_rect = rect;
110 handlePieLayoutChanged();
110 handlePieLayoutChanged();
111 }
111 }
112
112
113 void PieChartItem::calculatePieLayout()
113 void PieChartItem::calculatePieLayout()
114 {
114 {
115 // find pie center coordinates
115 // find pie center coordinates
116 m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->pieHorizontalPosition()));
116 m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->pieHorizontalPosition()));
117 m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->pieVerticalPosition()));
117 m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->pieVerticalPosition()));
118
118
119 // find maximum radius for pie
119 // find maximum radius for pie
120 m_pieRadius = m_rect.height() / 2;
120 m_pieRadius = m_rect.height() / 2;
121 if (m_rect.width() < m_rect.height())
121 if (m_rect.width() < m_rect.height())
122 m_pieRadius = m_rect.width() / 2;
122 m_pieRadius = m_rect.width() / 2;
123
123
124 // apply size factor
124 // apply size factor
125 m_pieRadius *= m_series->pieSize();
125 m_pieRadius *= m_series->pieSize();
126 }
126 }
127
127
128 PieSliceData PieChartItem::sliceData(QPieSlice *slice)
128 PieSliceData PieChartItem::sliceData(QPieSlice *slice)
129 {
129 {
130 PieSliceData sliceData = slice->data_ptr()->m_data;
130 PieSliceData sliceData = slice->data_ptr()->m_data;
131 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
131 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
132 sliceData.m_radius = m_pieRadius;
132 sliceData.m_radius = m_pieRadius;
133 return sliceData;
133 return sliceData;
134 }
134 }
135
135
136 PieLayout PieChartItem::calculateLayout()
136 PieLayout PieChartItem::calculateLayout()
137 {
137 {
138 calculatePieLayout();
138 calculatePieLayout();
139 PieLayout layout;
139 PieLayout layout;
140 foreach (QPieSlice* s, m_series->slices()) {
140 foreach (QPieSlice* s, m_series->slices()) {
141 if (m_slices.contains(s)) // calculate layout only for those slices that are already visible
141 if (m_slices.contains(s)) // calculate layout only for those slices that are already visible
142 layout.insert(s, sliceData(s));
142 layout.insert(s, sliceData(s));
143 }
143 }
144 return layout;
144 return layout;
145 }
145 }
146
146
147 void PieChartItem::applyLayout(const PieLayout &layout)
147 void PieChartItem::applyLayout(const PieLayout &layout)
148 {
148 {
149 if (animator())
149 if (animator())
150 animator()->updateLayout(this, layout);
150 animator()->updateLayout(this, layout);
151 else
151 else
152 setLayout(layout);
152 setLayout(layout);
153 }
153 }
154
154
155 void PieChartItem::updateLayout(QPieSlice *slice, const PieSliceData &sliceData)
155 void PieChartItem::updateLayout(QPieSlice *slice, const PieSliceData &sliceData)
156 {
156 {
157 if (animator())
157 if (animator())
158 animator()->updateLayout(this, slice, sliceData);
158 animator()->updateLayout(this, slice, sliceData);
159 else
159 else
160 setLayout(slice, sliceData);
160 setLayout(slice, sliceData);
161 }
161 }
162
162
163 void PieChartItem::setLayout(const PieLayout &layout)
163 void PieChartItem::setLayout(const PieLayout &layout)
164 {
164 {
165 foreach (QPieSlice *slice, layout.keys()) {
165 foreach (QPieSlice *slice, layout.keys()) {
166 PieSliceItem *item = m_slices.value(slice);
166 PieSliceItem *item = m_slices.value(slice);
167 Q_ASSERT(item);
167 Q_ASSERT(item);
168 item->setSliceData(layout.value(slice));
168 item->setSliceData(layout.value(slice));
169 item->updateGeometry();
169 item->updateGeometry();
170 item->update();
170 item->update();
171 }
171 }
172 }
172 }
173
173
174 void PieChartItem::setLayout(QPieSlice *slice, const PieSliceData &sliceData)
174 void PieChartItem::setLayout(QPieSlice *slice, const PieSliceData &sliceData)
175 {
175 {
176 // find slice
176 // find slice
177 PieSliceItem *item = m_slices.value(slice);
177 PieSliceItem *item = m_slices.value(slice);
178 Q_ASSERT(item);
178 Q_ASSERT(item);
179 item->setSliceData(sliceData);
179 item->setSliceData(sliceData);
180 item->updateGeometry();
180 item->updateGeometry();
181 item->update();
181 item->update();
182 }
182 }
183
183
184 void PieChartItem::destroySlice(QPieSlice *slice)
184 void PieChartItem::destroySlice(QPieSlice *slice)
185 {
185 {
186 delete m_slices.take(slice);
186 delete m_slices.take(slice);
187 }
187 }
188
188
189 #include "moc_piechartitem_p.cpp"
189 #include "moc_piechartitem_p.cpp"
190
190
191 QTCOMMERCIALCHART_END_NAMESPACE
191 QTCOMMERCIALCHART_END_NAMESPACE
This diff has been collapsed as it changes many lines, (503 lines changed) Show them Hide them
@@ -1,454 +1,467
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchart_p.h"
3 #include "qlegend.h"
4 #include "chartpresenter_p.h"
5 #include "chartdataset_p.h"
6 #include "chartbackground_p.h"
7 #include <QGraphicsScene>
3 #include <QGraphicsScene>
8 #include <QGraphicsSceneResizeEvent>
4 #include <QGraphicsSceneResizeEvent>
9
5
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
7
12 /*!
8 /*!
13 \enum QChart::ChartTheme
9 \enum QChart::ChartTheme
14
10
15 This enum describes the theme used by the chart.
11 This enum describes the theme used by the chart.
16
12
17 \value ChartThemeDefault Follows the GUI style of the Operating System
13 \value ChartThemeDefault Follows the GUI style of the Operating System
18 \value ChartThemeLight
14 \value ChartThemeLight
19 \value ChartThemeBlueCerulean
15 \value ChartThemeBlueCerulean
20 \value ChartThemeDark
16 \value ChartThemeDark
21 \value ChartThemeBrownSand
17 \value ChartThemeBrownSand
22 \value ChartThemeBlueNcs
18 \value ChartThemeBlueNcs
23 \value ChartThemeIcy
19 \value ChartThemeIcy
24 \value ChartThemeScientific
20 \value ChartThemeScientific
25 \value ChartThemeCount Not really a theme; the total count of themes.
21 \value ChartThemeCount Not really a theme; the total count of themes.
26 */
22 */
27
23
28 /*!
24 /*!
29 \enum QChart::AnimationOption
25 \enum QChart::AnimationOption
30
26
31 For enabling/disabling animations. Defaults to NoAnimation.
27 For enabling/disabling animations. Defaults to NoAnimation.
32
28
33 \value NoAnimation
29 \value NoAnimation
34 \value GridAxisAnimations
30 \value GridAxisAnimations
35 \value SeriesAnimations
31 \value SeriesAnimations
36 \value AllAnimations
32 \value AllAnimations
37 */
33 */
38
34
39 /*!
35 /*!
40 \class QChart
36 \class QChart
41 \brief QtCommercial chart API.
37 \brief QtCommercial chart API.
42
38
43 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
39 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
44 representation of different types of QChartSeries and other chart related objects like
40 representation of different types of QChartSeries and other chart related objects like
45 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
41 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
46 convenience class QChartView instead of QChart.
42 convenience class QChartView instead of QChart.
47 \sa QChartView
43 \sa QChartView
48 */
44 */
49
45
50 /*!
46 /*!
51 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
47 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
52 */
48 */
53 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
49 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
54 m_backgroundItem(0),
50 d_ptr(new QChartPrivate(this))
55 m_titleItem(0),
56 m_legend(new QLegend(this)),
57 m_dataset(new ChartDataSet(this)),
58 m_presenter(new ChartPresenter(this,m_dataset)),
59 m_padding(50),
60 m_backgroundPadding(10)
61 {
51 {
62 connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
52
63 connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
53 d_ptr->m_legend = new QLegend(this);
54 d_ptr->m_dataset = new ChartDataSet(this);
55 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
56
57 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
58 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
64 }
59 }
65
60
66 /*!
61 /*!
67 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
62 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
68 */
63 */
69 QChart::~QChart()
64 QChart::~QChart()
70 {
65 {
71 //delete first presenter , since this is a root of all the graphical items
66 //delete first presenter , since this is a root of all the graphical items
72 delete m_presenter;
67 delete d_ptr->m_presenter;
73 m_presenter=0;
68 d_ptr->m_presenter=0;
74 }
69 }
75
70
76 /*!
71 /*!
77 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
72 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
78 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
73 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
79 the y axis).
74 the y axis).
80 */
75 */
81 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
76 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
82 {
77 {
83 m_dataset->addSeries(series, axisY);
78 d_ptr->m_dataset->addSeries(series, axisY);
84 }
79 }
85
80
86 /*!
81 /*!
87 Removes the \a series specified in a perameter from the QChartView.
82 Removes the \a series specified in a perameter from the QChartView.
88 It releses its ownership of the specified QChartSeries object.
83 It releses its ownership of the specified QChartSeries object.
89 It does not delete the pointed QChartSeries data object
84 It does not delete the pointed QChartSeries data object
90 \sa addSeries(), removeAllSeries()
85 \sa addSeries(), removeAllSeries()
91 */
86 */
92 void QChart::removeSeries(QSeries* series)
87 void QChart::removeSeries(QSeries* series)
93 {
88 {
94 m_dataset->removeSeries(series);
89 d_ptr->m_dataset->removeSeries(series);
95 }
90 }
96
91
97 /*!
92 /*!
98 Removes all the QChartSeries that have been added to the QChartView
93 Removes all the QChartSeries that have been added to the QChartView
99 It also deletes the pointed QChartSeries data objects
94 It also deletes the pointed QChartSeries data objects
100 \sa addSeries(), removeSeries()
95 \sa addSeries(), removeSeries()
101 */
96 */
102 void QChart::removeAllSeries()
97 void QChart::removeAllSeries()
103 {
98 {
104 m_dataset->removeAllSeries();
99 d_ptr->m_dataset->removeAllSeries();
105 }
100 }
106
101
107 /*!
102 /*!
108 Sets the \a brush that is used for painting the background of the chart area.
103 Sets the \a brush that is used for painting the background of the chart area.
109 */
104 */
110 void QChart::setBackgroundBrush(const QBrush& brush)
105 void QChart::setBackgroundBrush(const QBrush& brush)
111 {
106 {
112 createChartBackgroundItem();
107 d_ptr->createChartBackgroundItem();
113 m_backgroundItem->setBrush(brush);
108 d_ptr->m_backgroundItem->setBrush(brush);
114 m_backgroundItem->update();
109 d_ptr->m_backgroundItem->update();
115 }
110 }
116
111
117 QBrush QChart::backgroundBrush() const
112 QBrush QChart::backgroundBrush() const
118 {
113 {
119 if(!m_backgroundItem) return QBrush();
114 if(!d_ptr->m_backgroundItem) return QBrush();
120 return m_backgroundItem->brush();
115 return (d_ptr->m_backgroundItem)->brush();
121 }
116 }
122
117
123 /*!
118 /*!
124 Sets the \a pen that is used for painting the background of the chart area.
119 Sets the \a pen that is used for painting the background of the chart area.
125 */
120 */
126 void QChart::setBackgroundPen(const QPen& pen)
121 void QChart::setBackgroundPen(const QPen& pen)
127 {
122 {
128 createChartBackgroundItem();
123 d_ptr->createChartBackgroundItem();
129 m_backgroundItem->setPen(pen);
124 d_ptr->m_backgroundItem->setPen(pen);
130 m_backgroundItem->update();
125 d_ptr->m_backgroundItem->update();
131 }
126 }
132
127
133 QPen QChart::backgroundPen() const
128 QPen QChart::backgroundPen() const
134 {
129 {
135 if(!m_backgroundItem) return QPen();
130 if(!d_ptr->m_backgroundItem) return QPen();
136 return m_backgroundItem->pen();
131 return d_ptr->m_backgroundItem->pen();
137 }
132 }
138
133
139 /*!
134 /*!
140 Sets the chart \a title. The description text that is drawn above the chart.
135 Sets the chart \a title. The description text that is drawn above the chart.
141 */
136 */
142 void QChart::setTitle(const QString& title)
137 void QChart::setTitle(const QString& title)
143 {
138 {
144 createChartTitleItem();
139 d_ptr->createChartTitleItem();
145 m_titleItem->setText(title);
140 d_ptr->m_titleItem->setText(title);
146 updateLayout();
141 d_ptr->updateLayout();
147 }
142 }
148
143
149 /*!
144 /*!
150 Returns the chart title. The description text that is drawn above the chart.
145 Returns the chart title. The description text that is drawn above the chart.
151 */
146 */
152 QString QChart::title() const
147 QString QChart::title() const
153 {
148 {
154 if(m_titleItem)
149 if(d_ptr->m_titleItem)
155 return m_titleItem->text();
150 return d_ptr->m_titleItem->text();
156 else
151 else
157 return QString();
152 return QString();
158 }
153 }
159
154
160 /*!
155 /*!
161 Sets the \a font that is used for rendering the description text that is rendered above the chart.
156 Sets the \a font that is used for rendering the description text that is rendered above the chart.
162 */
157 */
163 void QChart::setTitleFont(const QFont& font)
158 void QChart::setTitleFont(const QFont& font)
164 {
159 {
165 createChartTitleItem();
160 d_ptr->createChartTitleItem();
166 m_titleItem->setFont(font);
161 d_ptr->m_titleItem->setFont(font);
167 updateLayout();
162 d_ptr->updateLayout();
168 }
163 }
169
164
170 /*!
165 /*!
171 Sets the \a brush used for rendering the title text.
166 Sets the \a brush used for rendering the title text.
172 */
167 */
173 void QChart::setTitleBrush(const QBrush &brush)
168 void QChart::setTitleBrush(const QBrush &brush)
174 {
169 {
175 createChartTitleItem();
170 d_ptr->createChartTitleItem();
176 m_titleItem->setBrush(brush);
171 d_ptr->m_titleItem->setBrush(brush);
177 updateLayout();
172 d_ptr->updateLayout();
178 }
173 }
179
174
180 /*!
175 /*!
181 Returns the brush used for rendering the title text.
176 Returns the brush used for rendering the title text.
182 */
177 */
183 QBrush QChart::titleBrush() const
178 QBrush QChart::titleBrush() const
184 {
179 {
185 if(!m_titleItem) return QBrush();
180 if(!d_ptr->m_titleItem) return QBrush();
186 return m_titleItem->brush();
181 return d_ptr->m_titleItem->brush();
187 }
188
189 void QChart::createChartBackgroundItem()
190 {
191 if(!m_backgroundItem) {
192 m_backgroundItem = new ChartBackground(this);
193 m_backgroundItem->setPen(Qt::NoPen);
194 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
195 }
196 }
197
198 void QChart::createChartTitleItem()
199 {
200 if(!m_titleItem) {
201 m_titleItem = new QGraphicsSimpleTextItem(this);
202 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
203 }
204 }
182 }
205
183
206 /*!
184 /*!
207 Sets the \a theme used by the chart for rendering the graphical representation of the data
185 Sets the \a theme used by the chart for rendering the graphical representation of the data
208 \sa ChartTheme, chartTheme()
186 \sa ChartTheme, chartTheme()
209 */
187 */
210 void QChart::setChartTheme(QChart::ChartTheme theme)
188 void QChart::setTheme(QChart::ChartTheme theme)
211 {
189 {
212 m_presenter->setChartTheme(theme);
190 d_ptr->m_presenter->setTheme(theme);
213 }
191 }
214
192
215 /*!
193 /*!
216 Returns the theme enum used by the chart.
194 Returns the theme enum used by the chart.
217 \sa ChartTheme, setChartTheme()
195 \sa ChartTheme, setChartTheme()
218 */
196 */
219 QChart::ChartTheme QChart::chartTheme() const
197 QChart::ChartTheme QChart::theme() const
220 {
198 {
221 return m_presenter->chartTheme();
199 return d_ptr->m_presenter->theme();
222 }
200 }
223
201
224 /*!
202 /*!
225 Zooms in the view by a factor of 2
203 Zooms in the view by a factor of 2
226 */
204 */
227 void QChart::zoomIn()
205 void QChart::zoomIn()
228 {
206 {
229 m_presenter->zoomIn();
207 d_ptr->m_presenter->zoomIn();
230 }
208 }
231
209
232 /*!
210 /*!
233 Zooms in the view to a maximum level at which \a rect is still fully visible.
211 Zooms in the view to a maximum level at which \a rect is still fully visible.
234 */
212 */
235 void QChart::zoomIn(const QRectF& rect)
213 void QChart::zoomIn(const QRectF& rect)
236 {
214 {
237
238 if(!rect.isValid()) return;
215 if(!rect.isValid()) return;
239 m_presenter->zoomIn(rect);
216 d_ptr->m_presenter->zoomIn(rect);
240 }
217 }
241
218
242 /*!
219 /*!
243 Restores the view zoom level to the previous one.
220 Restores the view zoom level to the previous one.
244 */
221 */
245 void QChart::zoomOut()
222 void QChart::zoomOut()
246 {
223 {
247 m_presenter->zoomOut();
224 d_ptr->m_presenter->zoomOut();
248 }
225 }
249
226
250 /*!
227 /*!
251 Returns the pointer to the x axis object of the chart
228 Returns the pointer to the x axis object of the chart
252 */
229 */
253 QChartAxis* QChart::axisX() const
230 QChartAxis* QChart::axisX() const
254 {
231 {
255 return m_dataset->axisX();
232 return d_ptr->m_dataset->axisX();
256 }
233 }
257
234
258 /*!
235 /*!
259 Returns the pointer to the y axis object of the chart
236 Returns the pointer to the y axis object of the chart
260 */
237 */
261 QChartAxis* QChart::axisY() const
238 QChartAxis* QChart::axisY() const
262 {
239 {
263 return m_dataset->axisY();
240 return d_ptr->m_dataset->axisY();
264 }
241 }
265
242
266 /*!
243 /*!
267 Returns the legend object of the chart. Ownership stays in chart.
244 Returns the legend object of the chart. Ownership stays in chart.
268 */
245 */
269 QLegend& QChart::legend() const
246 QLegend& QChart::legend() const
270 {
247 {
271 return *m_legend;
248 return *d_ptr->m_legend;
272 }
249 }
273
250
274 /*!
251 /*!
275 Gives ownership of legend to user.
252 Gives ownership of legend to user.
276 */
253 */
277 QLegend* QChart::takeLegend()
254 QLegend* QChart::takeLegend()
278 {
255 {
279 QLegend* l = m_legend;
256 QLegend* l = d_ptr->m_legend;
280 m_legend = 0;
257 d_ptr->m_legend = 0;
281 return l;
258 return l;
282 }
259 }
283
260
284 /*!
261 /*!
285 Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one
262 Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one
286 */
263 */
287 void QChart::giveLegend(QLegend* legend)
264 void QChart::giveLegend(QLegend *legend)
288 {
265 {
289 if (m_legend) {
266 if (d_ptr->m_legend) {
290 // Should not happen.
267 // Should not happen.
291 qDebug() << "Warning! Giving more than one legend to chart.";
268 qDebug() << "Warning! Giving more than one legend to chart.";
292 delete m_legend;
269 delete d_ptr->m_legend;
293 }
270 }
294
271
295 m_legend = legend;
272 d_ptr->m_legend = legend;
296
273
297 // Reconnect legend, in case not already connected.
274 // Reconnect legend, in case not already connected.
298 disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
275 disconnect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
299 disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
276 disconnect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
300 connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
277 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
301 connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
278 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
302 }
279 }
303
280
304 /*!
281 /*!
305 Resizes and updates the chart area using the \a event data
282 Resizes and updates the chart area using the \a event data
306 */
283 */
307 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
284 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
308 {
285 {
309
286 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
310 m_rect = QRectF(QPoint(0,0),event->newSize());
287 d_ptr->updateLayout();
311 updateLayout();
312 QGraphicsWidget::resizeEvent(event);
288 QGraphicsWidget::resizeEvent(event);
313 update();
289 update();
314 }
290 }
315
291
316 /*!
292 /*!
317 Sets animation \a options for the chart
293 Sets animation \a options for the chart
318 */
294 */
319 void QChart::setAnimationOptions(AnimationOptions options)
295 void QChart::setAnimationOptions(AnimationOptions options)
320 {
296 {
321 m_presenter->setAnimationOptions(options);
297 d_ptr->m_presenter->setAnimationOptions(options);
322 }
298 }
323
299
324 /*!
300 /*!
325 Returns animation options for the chart
301 Returns animation options for the chart
326 */
302 */
327 QChart::AnimationOptions QChart::animationOptions() const
303 QChart::AnimationOptions QChart::animationOptions() const
328 {
304 {
329 return m_presenter->animationOptions();
305 return d_ptr->m_presenter->animationOptions();
330 }
306 }
331
307
332 void QChart::scrollLeft()
308 void QChart::scrollLeft()
333 {
309 {
334 m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
310 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
335 }
311 }
336
312
337 void QChart::scrollRight()
313 void QChart::scrollRight()
338 {
314 {
339 m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
315 d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0);
340 }
316 }
317
341 void QChart::scrollUp()
318 void QChart::scrollUp()
342 {
319 {
343 m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1));
320 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
344 }
321 }
322
345 void QChart::scrollDown()
323 void QChart::scrollDown()
346 {
324 {
347 m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1));
325 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1));
348 }
326 }
349
327
350 void QChart::updateLayout()
328 void QChart::setPadding(int padding)
351 {
329 {
352 if(!m_rect.isValid()) return;
330 if(d_ptr->m_padding==padding) {
353
331 d_ptr->m_padding = padding;
354 QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
332 d_ptr->m_presenter->handleGeometryChanged();
355
333 d_ptr->updateLayout();
356 // recalculate title position
357 if (m_titleItem) {
358 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
359 m_titleItem->setPos(center.x(),m_rect.top()/2 + m_padding/2);
360 }
334 }
335 }
361
336
362 //recalculate background gradient
337 int QChart::padding() const
363 if (m_backgroundItem) {
338 {
364 m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding));
339 return d_ptr->m_padding;
365 }
340 }
366
341
367 // recalculate legend position
342 void QChart::setBackgroundPadding(int padding)
368 if (m_legend) {
343 {
369 if (m_legend->parentObject() == this) {
344 if(d_ptr->m_backgroundPadding!=padding) {
370 updateLegendLayout();
345 d_ptr->m_backgroundPadding = padding;
371 }
346 d_ptr->updateLayout();
372 }
347 }
373 }
348 }
374
349
375 void QChart::updateLegendLayout()
350 void QChart::setBackgroundDiameter(int diameter)
376 {
351 {
377 QRectF plotRect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
352 d_ptr->createChartBackgroundItem();
378 QRectF legendRect;
353 d_ptr->m_backgroundItem->setDimeter(diameter);
354 d_ptr->m_backgroundItem->update();
355 }
379
356
380 switch (m_legend->preferredLayout())
357 void QChart::setBackgroundVisible(bool visible)
381 {
358 {
382 case QLegend::PreferredLayoutTop:{
359 d_ptr->createChartBackgroundItem();
383 // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height());
360 d_ptr->m_backgroundItem->setVisible(visible);
384 legendRect = plotRect.adjusted(0,0,0,-m_padding - plotRect.height());
361 }
385 break;
386 }
387 case QLegend::PreferredLayoutBottom: {
388 legendRect = plotRect.adjusted(m_padding,m_padding + plotRect.height(),-m_padding,0);
389 break;
390 }
391 case QLegend::PreferredLayoutLeft: {
392 legendRect = plotRect.adjusted(0,m_padding,-m_padding - plotRect.width(),-m_padding);
393 break;
394 }
395 case QLegend::PreferredLayoutRight: {
396 legendRect = plotRect.adjusted(m_padding + plotRect.width(),m_padding,0,-m_padding);
397 break;
398 }
399 default: {
400 legendRect = plotRect;
401 break;
402 }
403 }
404
362
405 m_legend->setMaximumSize(legendRect.size());
363 bool QChart::isBackgroundVisible() const
406 m_legend->setPos(legendRect.topLeft());
364 {
365 if(!d_ptr->m_backgroundItem) return false;
366 return d_ptr->m_backgroundItem->isVisible();
407 }
367 }
408
368
369 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
409
370
410 int QChart::padding() const
371 QChartPrivate::QChartPrivate(QChart *parent):
372 q_ptr(parent),
373 m_backgroundItem(0),
374 m_titleItem(0),
375 m_legend(0),
376 m_dataset(0),
377 m_presenter(0),
378 m_padding(50),
379 m_backgroundPadding(10)
411 {
380 {
412 return m_padding;
381
413 }
382 }
414
383
415 void QChart::setPadding(int padding)
384 QChartPrivate::~QChartPrivate()
416 {
385 {
417 if(m_padding==padding){
386
418 m_padding = padding;
419 m_presenter->handleGeometryChanged();
420 updateLayout();
421 }
422 }
387 }
423
388
424 void QChart::setBackgroundPadding(int padding)
389 void QChartPrivate::createChartBackgroundItem()
425 {
390 {
426 if(m_backgroundPadding!=padding){
391 if(!m_backgroundItem) {
427 m_backgroundPadding = padding;
392 m_backgroundItem = new ChartBackground(q_ptr);
428 updateLayout();
393 m_backgroundItem->setPen(Qt::NoPen);
394 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
429 }
395 }
430 }
396 }
431
397
432 void QChart::setBackgroundDiameter(int diameter)
398 void QChartPrivate::createChartTitleItem()
433 {
399 {
434 createChartBackgroundItem();
400 if(!m_titleItem) {
435 m_backgroundItem->setDimeter(diameter);
401 m_titleItem = new QGraphicsSimpleTextItem(q_ptr);
436 m_backgroundItem->update();
402 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
403 }
437 }
404 }
438
405
439 void QChart::setBackgroundVisible(bool visible)
406 void QChartPrivate::updateLegendLayout()
440 {
407 {
441 createChartBackgroundItem();
408 QRectF plotRect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
442 m_backgroundItem->setVisible(visible);
409 QRectF legendRect;
410
411 switch (m_legend->preferredLayout())
412 {
413 case QLegend::PreferredLayoutTop: {
414 // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height());
415 legendRect = plotRect.adjusted(0,0,0,-m_padding - plotRect.height());
416 break;
417 }
418 case QLegend::PreferredLayoutBottom: {
419 legendRect = plotRect.adjusted(m_padding,m_padding + plotRect.height(),-m_padding,0);
420 break;
421 }
422 case QLegend::PreferredLayoutLeft: {
423 legendRect = plotRect.adjusted(0,m_padding,-m_padding - plotRect.width(),-m_padding);
424 break;
425 }
426 case QLegend::PreferredLayoutRight: {
427 legendRect = plotRect.adjusted(m_padding + plotRect.width(),m_padding,0,-m_padding);
428 break;
429 }
430 default: {
431 legendRect = plotRect;
432 break;
433 }
434 }
435
436 m_legend->setMaximumSize(legendRect.size());
437 m_legend->setPos(legendRect.topLeft());
443 }
438 }
444
439
445 bool QChart::isBackgroundVisible() const
440 void QChartPrivate::updateLayout()
446 {
441 {
447 if(!m_backgroundItem) return false;
442 if(!m_rect.isValid()) return;
448 return m_backgroundItem->isVisible();
443
449 }
444 QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding);
445
446 // recalculate title position
447 if (m_titleItem) {
448 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
449 m_titleItem->setPos(center.x(),m_rect.top()/2 + m_padding/2);
450 }
451
452 //recalculate background gradient
453 if (m_backgroundItem) {
454 m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding));
455 }
450
456
457 // recalculate legend position
458 if (m_legend) {
459 if (m_legend->parentObject() == q_ptr) {
460 updateLegendLayout();
461 }
462 }
463 }
451
464
452 #include "moc_qchart.cpp"
465 #include "moc_qchart.cpp"
453
466
454 QTCOMMERCIALCHART_END_NAMESPACE
467 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,124 +1,105
1 #ifndef QCHART_H
1 #ifndef QCHART_H
2 #define QCHART_H
2 #define QCHART_H
3
3
4 #include <qchartglobal.h>
4 #include <QSeries>
5 #include <qseries.h>
6 #include <QGraphicsWidget>
5 #include <QGraphicsWidget>
7 #include <QLinearGradient>
8 #include <QFont>
9
6
10 class QGraphicsSceneResizeEvent;
7 class QGraphicsSceneResizeEvent;
11
8
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
10
14 class Axis;
11 class Axis;
15 class QSeries;
12 class QSeries;
16 class PlotDomain;
17 class BarChartItem;
18 class QChartAxis;
13 class QChartAxis;
19 class ChartTheme;
20 class ChartItem;
21 class ChartDataSet;
22 class ChartPresenter;
23 class QLegend;
14 class QLegend;
24 class ChartBackground;
15 class QChartPrivate;
25
26
16
27 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
17 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
28 {
18 {
29 Q_OBJECT
19 Q_OBJECT
30 public:
20 public:
31 enum ChartTheme {
21 enum ChartTheme {
32 ChartThemeDefault,
22 ChartThemeDefault,
33 ChartThemeLight,
23 ChartThemeLight,
34 ChartThemeBlueCerulean,
24 ChartThemeBlueCerulean,
35 ChartThemeDark,
25 ChartThemeDark,
36 ChartThemeBrownSand,
26 ChartThemeBrownSand,
37 ChartThemeBlueNcs,
27 ChartThemeBlueNcs,
38 ChartThemeIcy,
28 ChartThemeIcy,
39 ChartThemeScientific,
29 ChartThemeScientific,
40 ChartThemeCount
30 ChartThemeCount
41 };
31 };
42
32
43 enum AnimationOption {
33 enum AnimationOption {
44 NoAnimation = 0x0,
34 NoAnimation = 0x0,
45 GridAxisAnimations = 0x1,
35 GridAxisAnimations = 0x1,
46 SeriesAnimations =0x2,
36 SeriesAnimations =0x2,
47 AllAnimations = 0x3
37 AllAnimations = 0x3
48 };
38 };
49 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
39 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
50
40
51 public:
41 public:
52 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
42 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
53 ~QChart();
43 ~QChart();
54
44
55 void addSeries(QSeries* series, QChartAxis* axisY = 0);
45 void addSeries(QSeries *series, QChartAxis *axisY = 0);
56 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
46 void removeSeries(QSeries *series);
57 void removeAllSeries(); // deletes series and axis
47 void removeAllSeries();
58
48
59 void setChartTheme(QChart::ChartTheme theme);
49 void setTheme(QChart::ChartTheme theme);
60 QChart::ChartTheme chartTheme() const;
50 QChart::ChartTheme theme() const;
61
51
62 void setTitle(const QString& title);
52 void setTitle(const QString& title);
63 QString title() const;
53 QString title() const;
64 void setTitleFont(const QFont& font);
54 void setTitleFont(const QFont& font);
65 QFont titleFont() const;
55 QFont titleFont() const;
66 void setTitleBrush(const QBrush &brush);
56 void setTitleBrush(const QBrush &brush);
67 QBrush titleBrush() const;
57 QBrush titleBrush() const;
68 void setBackgroundBrush(const QBrush& brush);
58 void setBackgroundBrush(const QBrush& brush);
69 QBrush backgroundBrush() const;
59 QBrush backgroundBrush() const;
70 void setBackgroundPen(const QPen& pen);
60 void setBackgroundPen(const QPen& pen);
71 QPen backgroundPen() const;
61 QPen backgroundPen() const;
72
62
73 void setBackgroundVisible(bool visible);
63 void setBackgroundVisible(bool visible);
74 bool isBackgroundVisible() const;
64 bool isBackgroundVisible() const;
75
65
76 void setAnimationOptions(AnimationOptions options);
66 void setAnimationOptions(AnimationOptions options);
77 AnimationOptions animationOptions() const;
67 AnimationOptions animationOptions() const;
78
68
79 void zoomIn();
69 void zoomIn();
80 void zoomIn(const QRectF& rect);
70 void zoomIn(const QRectF& rect);
81 void zoomOut();
71 void zoomOut();
82 void scrollLeft();
72 void scrollLeft();
83 void scrollRight();
73 void scrollRight();
84 void scrollUp();
74 void scrollUp();
85 void scrollDown();
75 void scrollDown();
86
76
87 QChartAxis* axisX() const;
77 QChartAxis* axisX() const;
88 QChartAxis* axisY() const;
78 QChartAxis* axisY() const;
89
79
90 QLegend& legend() const;
80 QLegend& legend() const;
91 QLegend* takeLegend();
81 QLegend* takeLegend();
92 void giveLegend(QLegend* legend);
82 void giveLegend(QLegend* legend);
93
83
94 int padding() const;
84 int padding() const;
95
85
96 protected:
86 protected:
97 void resizeEvent(QGraphicsSceneResizeEvent *event);
87 void resizeEvent(QGraphicsSceneResizeEvent *event);
98
88
89 protected:
90 QScopedPointer<QChartPrivate> d_ptr;
91
99 private:
92 private:
100 inline void createChartBackgroundItem();
101 inline void createChartTitleItem();
102 void setPadding(int padding);
93 void setPadding(int padding);
103 void setBackgroundPadding(int padding);
94 void setBackgroundPadding(int padding);
104 void setBackgroundDiameter(int diameter);
95 void setBackgroundDiameter(int diameter);
105 void updateLayout();
106 void updateLegendLayout();
107
96
108 private:
97 private:
109 Q_DISABLE_COPY(QChart)
98 Q_DISABLE_COPY(QChart);
110 ChartBackground* m_backgroundItem;
111 QGraphicsSimpleTextItem* m_titleItem;
112 QRectF m_rect;
113 QLegend* m_legend;
114 ChartDataSet *m_dataset;
115 ChartPresenter *m_presenter;
116 int m_padding;
117 int m_backgroundPadding;
118 };
99 };
119
100
120 QTCOMMERCIALCHART_END_NAMESPACE
101 QTCOMMERCIALCHART_END_NAMESPACE
121
102
122 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
103 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
123
104
124 #endif
105 #endif
@@ -1,416 +1,416
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 setFrameShape(QFrame::NoFrame);
46 setFrameShape(QFrame::NoFrame);
47 setBackgroundRole(QPalette::Window);
47 setBackgroundRole(QPalette::Window);
48 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
48 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
49 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
49 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
50 setScene(m_scene);
50 setScene(m_scene);
51 m_scene->addItem(m_chart);
51 m_scene->addItem(m_chart);
52 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
52 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
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 QChartView::~QChartView()
59 QChartView::~QChartView()
60 {
60 {
61 }
61 }
62
62
63 /*!
63 /*!
64 Resizes and updates the chart area using the \a event data
64 Resizes and updates the chart area using the \a event data
65 */
65 */
66 void QChartView::resizeEvent(QResizeEvent *event)
66 void QChartView::resizeEvent(QResizeEvent *event)
67 {
67 {
68 m_chart->resize(size());
68 m_chart->resize(size());
69 QGraphicsView::resizeEvent(event);
69 QGraphicsView::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 Sets the chart \a title. A description text that is drawn above the chart.
129 Sets the chart \a title. A description text that is drawn above the chart.
130 */
130 */
131 void QChartView::setChartTitle(const QString& title)
131 void QChartView::setChartTitle(const QString& title)
132 {
132 {
133 m_chart->setTitle(title);
133 m_chart->setTitle(title);
134 }
134 }
135
135
136 /*!
136 /*!
137 Returns the chart's title. A description text that is drawn above the chart.
137 Returns the chart's title. A description text that is drawn above the chart.
138 */
138 */
139 QString QChartView::chartTitle() const
139 QString QChartView::chartTitle() const
140 {
140 {
141 return m_chart->title();
141 return m_chart->title();
142 }
142 }
143
143
144 /*!
144 /*!
145 Sets the \a font that is used for rendering the description text that is rendered above the chart.
145 Sets the \a font that is used for rendering the description text that is rendered above the chart.
146 */
146 */
147 void QChartView::setChartTitleFont(const QFont& font)
147 void QChartView::setChartTitleFont(const QFont& font)
148 {
148 {
149 m_chart->setTitleFont(font);
149 m_chart->setTitleFont(font);
150 }
150 }
151
151
152 /*!
152 /*!
153 Sets the \a brush used for rendering the title text.
153 Sets the \a brush used for rendering the title text.
154 */
154 */
155 void QChartView::setChartTitleBrush(const QBrush &brush)
155 void QChartView::setChartTitleBrush(const QBrush &brush)
156 {
156 {
157 m_chart->setTitleBrush(brush);
157 m_chart->setTitleBrush(brush);
158 }
158 }
159
159
160 /*!
160 /*!
161 Returns the brush used for rendering the title text.
161 Returns the brush used for rendering the title text.
162 */
162 */
163 QBrush QChartView::chartTitleBrush()
163 QBrush QChartView::chartTitleBrush()
164 {
164 {
165 return m_chart->titleBrush();
165 return m_chart->titleBrush();
166 }
166 }
167
167
168 /*!
168 /*!
169 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
169 Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
170 */
170 */
171 void QChartView::setChartBackgroundBrush(const QBrush& brush)
171 void QChartView::setChartBackgroundBrush(const QBrush& brush)
172 {
172 {
173 m_chart->setBackgroundBrush(brush);
173 m_chart->setBackgroundBrush(brush);
174 }
174 }
175
175
176 /*!
176 /*!
177 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
177 Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
178 */
178 */
179 void QChartView::setChartBackgroundPen(const QPen& pen)
179 void QChartView::setChartBackgroundPen(const QPen& pen)
180 {
180 {
181 m_chart->setBackgroundPen(pen);
181 m_chart->setBackgroundPen(pen);
182 }
182 }
183
183
184 /*!
184 /*!
185 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
185 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
186 */
186 */
187 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
187 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
188 {
188 {
189 switch(policy) {
189 switch(policy) {
190 case VerticalRubberBand:
190 case VerticalRubberBand:
191 m_verticalRubberBand = true;
191 m_verticalRubberBand = true;
192 m_horizonalRubberBand = false;
192 m_horizonalRubberBand = false;
193 break;
193 break;
194 case HorizonalRubberBand:
194 case HorizonalRubberBand:
195 m_verticalRubberBand = false;
195 m_verticalRubberBand = false;
196 m_horizonalRubberBand = true;
196 m_horizonalRubberBand = true;
197 break;
197 break;
198 case RectangleRubberBand:
198 case RectangleRubberBand:
199 m_verticalRubberBand = true;
199 m_verticalRubberBand = true;
200 m_horizonalRubberBand = true;
200 m_horizonalRubberBand = true;
201 break;
201 break;
202 case NoRubberBand:
202 case NoRubberBand:
203 default:
203 default:
204 delete m_rubberBand;
204 delete m_rubberBand;
205 m_rubberBand=0;
205 m_rubberBand=0;
206 m_horizonalRubberBand = false;
206 m_horizonalRubberBand = false;
207 m_verticalRubberBand = false;
207 m_verticalRubberBand = false;
208 return;
208 return;
209 }
209 }
210 if(!m_rubberBand) {
210 if(!m_rubberBand) {
211 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
211 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
212 m_rubberBand->setEnabled(true);
212 m_rubberBand->setEnabled(true);
213 }
213 }
214 }
214 }
215
215
216 /*!
216 /*!
217 Returns the RubberBandPolicy that is currently being used by the widget.
217 Returns the RubberBandPolicy that is currently being used by the widget.
218 */
218 */
219 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
219 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
220 {
220 {
221 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
221 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
222 if(m_horizonalRubberBand) return HorizonalRubberBand;
222 if(m_horizonalRubberBand) return HorizonalRubberBand;
223 if(m_verticalRubberBand) return VerticalRubberBand;
223 if(m_verticalRubberBand) return VerticalRubberBand;
224 return NoRubberBand;
224 return NoRubberBand;
225 }
225 }
226
226
227 /*!
227 /*!
228 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.
228 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.
229 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
229 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
230 */
230 */
231 void QChartView::mousePressEvent(QMouseEvent *event)
231 void QChartView::mousePressEvent(QMouseEvent *event)
232 {
232 {
233 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
233 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
234
234
235 int padding = m_chart->padding();
235 int padding = m_chart->padding();
236 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
236 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
237
237
238 if (rect.contains(event->pos())) {
238 if (rect.contains(event->pos())) {
239 m_rubberBandOrigin = event->pos();
239 m_rubberBandOrigin = event->pos();
240 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
240 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
241 m_rubberBand->show();
241 m_rubberBand->show();
242 event->accept();
242 event->accept();
243 }
243 }
244 }
244 }
245 else {
245 else {
246 QGraphicsView::mousePressEvent(event);
246 QGraphicsView::mousePressEvent(event);
247 }
247 }
248 }
248 }
249
249
250 /*!
250 /*!
251 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
251 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
252 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
252 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
253 */
253 */
254 void QChartView::mouseMoveEvent(QMouseEvent *event)
254 void QChartView::mouseMoveEvent(QMouseEvent *event)
255 {
255 {
256 if(m_rubberBand && m_rubberBand->isVisible()) {
256 if(m_rubberBand && m_rubberBand->isVisible()) {
257 int padding = m_chart->padding();
257 int padding = m_chart->padding();
258 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
258 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
259 int width = event->pos().x() - m_rubberBandOrigin.x();
259 int width = event->pos().x() - m_rubberBandOrigin.x();
260 int height = event->pos().y() - m_rubberBandOrigin.y();
260 int height = event->pos().y() - m_rubberBandOrigin.y();
261 if(!m_verticalRubberBand) {
261 if(!m_verticalRubberBand) {
262 m_rubberBandOrigin.setY(rect.top());
262 m_rubberBandOrigin.setY(rect.top());
263 height = rect.height();
263 height = rect.height();
264 }
264 }
265 if(!m_horizonalRubberBand) {
265 if(!m_horizonalRubberBand) {
266 m_rubberBandOrigin.setX(rect.left());
266 m_rubberBandOrigin.setX(rect.left());
267 width= rect.width();
267 width= rect.width();
268 }
268 }
269 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
269 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
270 }
270 }
271 else {
271 else {
272 QGraphicsView::mouseMoveEvent(event);
272 QGraphicsView::mouseMoveEvent(event);
273 }
273 }
274 }
274 }
275
275
276 /*!
276 /*!
277 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
277 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
278 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
278 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
279 */
279 */
280 void QChartView::mouseReleaseEvent(QMouseEvent *event)
280 void QChartView::mouseReleaseEvent(QMouseEvent *event)
281 {
281 {
282 if(m_rubberBand) {
282 if(m_rubberBand) {
283 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
283 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
284 m_rubberBand->hide();
284 m_rubberBand->hide();
285 QRect rect = m_rubberBand->geometry();
285 QRect rect = m_rubberBand->geometry();
286 m_chart->zoomIn(rect);
286 m_chart->zoomIn(rect);
287 event->accept();
287 event->accept();
288 }
288 }
289
289
290 if(event->button()==Qt::RightButton){
290 if(event->button()==Qt::RightButton){
291 m_chart->zoomOut();
291 m_chart->zoomOut();
292 event->accept();
292 event->accept();
293 }
293 }
294 }
294 }
295 else {
295 else {
296 QGraphicsView::mouseReleaseEvent(event);
296 QGraphicsView::mouseReleaseEvent(event);
297 }
297 }
298 }
298 }
299
299
300 /*!
300 /*!
301 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
301 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
302 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
302 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
303 */
303 */
304 void QChartView::keyPressEvent(QKeyEvent *event)
304 void QChartView::keyPressEvent(QKeyEvent *event)
305 {
305 {
306 switch (event->key()) {
306 switch (event->key()) {
307 case Qt::Key_Plus:
307 case Qt::Key_Plus:
308 zoomIn();
308 zoomIn();
309 break;
309 break;
310 case Qt::Key_Minus:
310 case Qt::Key_Minus:
311 zoomOut();
311 zoomOut();
312 break;
312 break;
313 default:
313 default:
314 QGraphicsView::keyPressEvent(event);
314 QGraphicsView::keyPressEvent(event);
315 break;
315 break;
316 }
316 }
317 }
317 }
318
318
319 /*!
319 /*!
320 Sets the \a theme used by the chart for rendering the graphical representation of the data
320 Sets the \a theme used by the chart for rendering the graphical representation of the data
321 \sa QChart::ChartTheme, chartTheme()
321 \sa QChart::ChartTheme, chartTheme()
322 */
322 */
323 void QChartView::setChartTheme(QChart::ChartTheme theme)
323 void QChartView::setChartTheme(QChart::ChartTheme theme)
324 {
324 {
325 m_chart->setChartTheme(theme);
325 m_chart->setTheme(theme);
326 }
326 }
327
327
328 /*!
328 /*!
329 Returns the theme enum used by the chart.
329 Returns the theme enum used by the chart.
330 \sa setChartTheme()
330 \sa setChartTheme()
331 */
331 */
332 QChart::ChartTheme QChartView::chartTheme() const
332 QChart::ChartTheme QChartView::chartTheme() const
333 {
333 {
334 return m_chart->chartTheme();
334 return m_chart->theme();
335 }
335 }
336
336
337 /*!
337 /*!
338 Returns the pointer to the x axis object of the chart
338 Returns the pointer to the x axis object of the chart
339 */
339 */
340 QChartAxis* QChartView::axisX() const
340 QChartAxis* QChartView::axisX() const
341 {
341 {
342 return m_chart->axisX();
342 return m_chart->axisX();
343 }
343 }
344
344
345 /*!
345 /*!
346 Returns the pointer to the y axis object of the chart
346 Returns the pointer to the y axis object of the chart
347 */
347 */
348 QChartAxis* QChartView::axisY() const
348 QChartAxis* QChartView::axisY() const
349 {
349 {
350 return m_chart->axisY();
350 return m_chart->axisY();
351 }
351 }
352
352
353 /*!
353 /*!
354 Returns the pointer to legend object of the chart
354 Returns the pointer to legend object of the chart
355 */
355 */
356 QLegend& QChartView::legend() const
356 QLegend& QChartView::legend() const
357 {
357 {
358 return m_chart->legend();
358 return m_chart->legend();
359 }
359 }
360
360
361 /*!
361 /*!
362 Gives ownership of legend to user.
362 Gives ownership of legend to user.
363 */
363 */
364 QLegend* QChartView::takeLegend()
364 QLegend* QChartView::takeLegend()
365 {
365 {
366 return m_chart->takeLegend();
366 return m_chart->takeLegend();
367 }
367 }
368
368
369 /*!
369 /*!
370 Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one
370 Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one
371 */
371 */
372 void QChartView::giveLegend(QLegend* legend)
372 void QChartView::giveLegend(QLegend* legend)
373 {
373 {
374 m_chart->giveLegend(legend);
374 m_chart->giveLegend(legend);
375 }
375 }
376
376
377 /*!
377 /*!
378 Sets animation \a options for the chart
378 Sets animation \a options for the chart
379 */
379 */
380 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
380 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
381 {
381 {
382 m_chart->setAnimationOptions(options);
382 m_chart->setAnimationOptions(options);
383 }
383 }
384
384
385 /*!
385 /*!
386 Returns animation options for the chart
386 Returns animation options for the chart
387 */
387 */
388 QChart::AnimationOptions QChartView::animationOptions() const
388 QChart::AnimationOptions QChartView::animationOptions() const
389 {
389 {
390 return m_chart->animationOptions();
390 return m_chart->animationOptions();
391 }
391 }
392
392
393 void QChartView::scrollLeft()
393 void QChartView::scrollLeft()
394 {
394 {
395 m_chart->scrollLeft();
395 m_chart->scrollLeft();
396 }
396 }
397
397
398 void QChartView::scrollRight()
398 void QChartView::scrollRight()
399 {
399 {
400 m_chart->scrollRight();
400 m_chart->scrollRight();
401 }
401 }
402
402
403 void QChartView::scrollUp()
403 void QChartView::scrollUp()
404 {
404 {
405 m_chart->scrollUp();
405 m_chart->scrollUp();
406 }
406 }
407
407
408 void QChartView::scrollDown()
408 void QChartView::scrollDown()
409 {
409 {
410 m_chart->scrollDown();
410 m_chart->scrollDown();
411 }
411 }
412
412
413
413
414 #include "moc_qchartview.cpp"
414 #include "moc_qchartview.cpp"
415
415
416 QTCOMMERCIALCHART_END_NAMESPACE
416 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,159 +1,158
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
2 TARGET = QtCommercialChart
2 TARGET = QtCommercialChart
3 DESTDIR = $$CHART_BUILD_LIB_DIR
3 DESTDIR = $$CHART_BUILD_LIB_DIR
4 TEMPLATE = lib
4 TEMPLATE = lib
5 QT += core \
5 QT += core \
6 gui
6 gui
7 win32-msvc*: LIBS += User32.lib
7 win32-msvc*: LIBS += User32.lib
8 CONFIG += debug_and_release
8 CONFIG += debug_and_release
9 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
9 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
10 SOURCES += \
10 SOURCES += \
11 $$PWD/chartdataset.cpp \
11 $$PWD/chartdataset.cpp \
12 $$PWD/chartpresenter.cpp \
12 $$PWD/chartpresenter.cpp \
13 $$PWD/charttheme.cpp \
13 $$PWD/charttheme.cpp \
14 $$PWD/domain.cpp \
14 $$PWD/domain.cpp \
15 $$PWD/qchart.cpp \
15 $$PWD/qchart.cpp \
16 $$PWD/qchartview.cpp \
16 $$PWD/qchartview.cpp \
17 $$PWD/qseries.cpp \
17 $$PWD/qseries.cpp \
18 $$PWD/qlegend.cpp \
18 $$PWD/qlegend.cpp \
19 $$PWD/legendmarker.cpp \
19 $$PWD/legendmarker.cpp \
20 $$PWD/legendscrollbutton.cpp \
20 $$PWD/legendscrollbutton.cpp \
21 $$PWD/chartbackground.cpp \
21 $$PWD/chartbackground.cpp \
22 $$PWD/chart.cpp
22 $$PWD/chart.cpp
23 PRIVATE_HEADERS += \
23 PRIVATE_HEADERS += \
24 $$PWD/chartdataset_p.h \
24 $$PWD/chartdataset_p.h \
25 $$PWD/chartitem_p.h \
25 $$PWD/chartitem_p.h \
26 $$PWD/chartpresenter_p.h \
26 $$PWD/chartpresenter_p.h \
27 $$PWD/charttheme_p.h \
27 $$PWD/charttheme_p.h \
28 $$PWD/domain_p.h \
28 $$PWD/domain_p.h \
29 $$PWD/legendmarker_p.h \
29 $$PWD/legendmarker_p.h \
30 $$PWD/legendscrollbutton_p.h \
30 $$PWD/legendscrollbutton_p.h \
31 $$PWD/chartbackground_p.h \
31 $$PWD/chartbackground_p.h \
32 $$PWD/chart_p.h \
32 $$PWD/chart_p.h \
33 $$PWD/chartconfig_p.h
33 $$PWD/chartconfig_p.h \
34 $$PWD/qchart_p.h
34 PUBLIC_HEADERS += \
35 PUBLIC_HEADERS += \
35 $$PWD/qchart.h \
36 $$PWD/qchart.h \
36 $$PWD/qchartglobal.h \
37 $$PWD/qchartglobal.h \
37 $$PWD/qseries.h \
38 $$PWD/qseries.h \
38 $$PWD/qchartview.h \
39 $$PWD/qchartview.h \
39 $$PWD/qlegend.h
40 $$PWD/qlegend.h
40
41
41 include(animations/animations.pri)
42 include(animations/animations.pri)
42 include(axis/axis.pri)
43 include(axis/axis.pri)
43 include(xychart/xychart.pri)
44 include(xychart/xychart.pri)
44 include(linechart/linechart.pri)
45 include(linechart/linechart.pri)
45 include(areachart/areachart.pri)
46 include(areachart/areachart.pri)
46 include(barchart/barchart.pri)
47 include(barchart/barchart.pri)
47 include(piechart/piechart.pri)
48 include(piechart/piechart.pri)
48 include(scatterseries/scatter.pri)
49 include(scatterseries/scatter.pri)
49 include(splinechart/splinechart.pri)
50 include(splinechart/splinechart.pri)
50 include(themes/themes.pri)
51 include(themes/themes.pri)
51
52
52
53
53 HEADERS += $$PUBLIC_HEADERS
54 HEADERS += $$PUBLIC_HEADERS
54 HEADERS += $$PRIVATE_HEADERS
55 HEADERS += $$PRIVATE_HEADERS
55 HEADERS += $$THEMES
56 HEADERS += $$THEMES
56 INCLUDEPATH += linechart \
57 INCLUDEPATH += ../include
57 barchart \
58
58 themes \
59 .
60 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
59 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
61 MOC_DIR = $$CHART_BUILD_DIR/lib
60 MOC_DIR = $$CHART_BUILD_DIR/lib
62 UI_DIR = $$CHART_BUILD_DIR/lib
61 UI_DIR = $$CHART_BUILD_DIR/lib
63 RCC_DIR = $$CHART_BUILD_DIR/lib
62 RCC_DIR = $$CHART_BUILD_DIR/lib
64 DEFINES += QTCOMMERCIALCHART_LIBRARY
63 DEFINES += QTCOMMERCIALCHART_LIBRARY
65
64
66 #qt public headers
65 #qt public headers
67 #this is very primitive and lame parser , TODO: make perl script insted
66 #this is very primitive and lame parser , TODO: make perl script insted
68 !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal)
67 !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal)
69 {
68 {
70 system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR)
69 system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR)
71 win32:{
70 win32:{
72 command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal"
71 command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal"
73 }else{
72 }else{
74 command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal"
73 command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal"
75 }
74 }
76 system($$command)
75 system($$command)
77 }
76 }
78
77
79 for(file, PUBLIC_HEADERS) {
78 for(file, PUBLIC_HEADERS) {
80 name = $$split(file,'/')
79 name = $$split(file,'/')
81 name = $$last(name)
80 name = $$last(name)
82 class = "$$cat($$file)"
81 class = "$$cat($$file)"
83 class = $$find(class,class)
82 class = $$find(class,class)
84 !isEmpty(class){
83 !isEmpty(class){
85 class = $$split(class,QTCOMMERCIALCHART_EXPORT)
84 class = $$split(class,QTCOMMERCIALCHART_EXPORT)
86 class = $$member(class,1)
85 class = $$member(class,1)
87 class = $$split(class,' ')
86 class = $$split(class,' ')
88 class = $$replace(class,' ','')
87 class = $$replace(class,' ','')
89 class = $$member(class,0)
88 class = $$member(class,0)
90 win32:{
89 win32:{
91 command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
90 command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
92 }else{
91 }else{
93 command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
92 command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
94 }
93 }
95 PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class
94 PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class
96 system($$command)
95 system($$command)
97 }
96 }
98 }
97 }
99
98
100 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
99 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
101 public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS
100 public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS
102
101
103 target.path = $$[QT_INSTALL_LIBS]
102 target.path = $$[QT_INSTALL_LIBS]
104 INSTALLS += target public_headers
103 INSTALLS += target public_headers
105
104
106 install_build_public_headers.name = build_public_headers
105 install_build_public_headers.name = build_public_headers
107 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
106 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
108 install_build_public_headers.input = PUBLIC_HEADERS
107 install_build_public_headers.input = PUBLIC_HEADERS
109 install_build_public_headers.commands = $$QMAKE_COPY \
108 install_build_public_headers.commands = $$QMAKE_COPY \
110 ${QMAKE_FILE_NAME} \
109 ${QMAKE_FILE_NAME} \
111 $$CHART_BUILD_PUBLIC_HEADER_DIR
110 $$CHART_BUILD_PUBLIC_HEADER_DIR
112 install_build_public_headers.CONFIG += target_predeps \
111 install_build_public_headers.CONFIG += target_predeps \
113 no_link
112 no_link
114
113
115 install_build_private_headers.name = buld_private_headers
114 install_build_private_headers.name = buld_private_headers
116 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
115 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
117 install_build_private_headers.input = PRIVATE_HEADERS
116 install_build_private_headers.input = PRIVATE_HEADERS
118 install_build_private_headers.commands = $$QMAKE_COPY \
117 install_build_private_headers.commands = $$QMAKE_COPY \
119 ${QMAKE_FILE_NAME} \
118 ${QMAKE_FILE_NAME} \
120 $$CHART_BUILD_PRIVATE_HEADER_DIR
119 $$CHART_BUILD_PRIVATE_HEADER_DIR
121 install_build_private_headers.CONFIG += target_predeps \
120 install_build_private_headers.CONFIG += target_predeps \
122 no_link
121 no_link
123
122
124 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
123 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
125 install_build_private_headers \
124 install_build_private_headers \
126
125
127
126
128 chartversion.target = $$PWD/qchartversion_p.h
127 chartversion.target = $$PWD/qchartversion_p.h
129 unix:{
128 unix:{
130 chartversion.commands = @echo \
129 chartversion.commands = @echo \
131 "const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" \\; \
130 "const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" \\; \
132 const char *gitHead = \\\"`git rev-parse HEAD`\\\" \\; " \
131 const char *gitHead = \\\"`git rev-parse HEAD`\\\" \\; " \
133 > \
132 > \
134 $$chartversion.target;
133 $$chartversion.target;
135 }else{
134 }else{
136 chartversion.commands = @echo \
135 chartversion.commands = @echo \
137 "const char *buildTime = \"%date%_%time%\" ; \
136 "const char *buildTime = \"%date%_%time%\" ; \
138 const char *gitHead = \"unknown\" ; " \
137 const char *gitHead = \"unknown\" ; " \
139 > \
138 > \
140 $$chartversion.target
139 $$chartversion.target
141 }
140 }
142 chartversion.depends = $$HEADERS \
141 chartversion.depends = $$HEADERS \
143 $$SOURCES
142 $$SOURCES
144 PRE_TARGETDEPS += $$PWD/qchartversion_p.h
143 PRE_TARGETDEPS += $$PWD/qchartversion_p.h
145 QMAKE_CLEAN += $$PWD/qchartversion_p.h
144 QMAKE_CLEAN += $$PWD/qchartversion_p.h
146 QMAKE_EXTRA_TARGETS += chartversion
145 QMAKE_EXTRA_TARGETS += chartversion
147 unix:QMAKE_DISTCLEAN += -r \
146 unix:QMAKE_DISTCLEAN += -r \
148 $$CHART_BUILD_HEADER_DIR \
147 $$CHART_BUILD_HEADER_DIR \
149 $$CHART_BUILD_LIB_DIR
148 $$CHART_BUILD_LIB_DIR
150 win32:QMAKE_DISTCLEAN += /Q \
149 win32:QMAKE_DISTCLEAN += /Q \
151 $$CHART_BUILD_HEADER_DIR \
150 $$CHART_BUILD_HEADER_DIR \
152 $$CHART_BUILD_LIB_DIR
151 $$CHART_BUILD_LIB_DIR
153
152
154 # treat warnings as errors
153 # treat warnings as errors
155 win32-msvc*: {
154 win32-msvc*: {
156 QMAKE_CXXFLAGS += /WX
155 QMAKE_CXXFLAGS += /WX
157 } else {
156 } else {
158 QMAKE_CXXFLAGS += -Werror
157 QMAKE_CXXFLAGS += -Werror
159 }
158 }
General Comments 0
You need to be logged in to leave comments. Login now