##// END OF EJS Templates
added example for stacked bar chart.
sauimone -
r95:9f20814aa978
parent child
Show More
@@ -1,5 +1,6
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 SUBDIRS += linechart \
2 SUBDIRS += linechart \
3 zoomlinechart \
3 zoomlinechart \
4 colorlinechart \
4 colorlinechart \
5 barchart
5 barchart \
6 stackedbarchart
@@ -1,49 +1,45
1 #ifndef BARCHARTSERIES_H
1 #ifndef BARCHARTSERIES_H
2 #define BARCHARTSERIES_H
2 #define BARCHARTSERIES_H
3
3
4 #include <QList>
4 #include <QList>
5 //#include <QRectF>
6 #include <QAbstractItemModel>
5 #include <QAbstractItemModel>
7 #include "qchartseries.h"
6 #include "qchartseries.h"
8 #include "qchartglobal.h"
7 #include "qchartglobal.h"
9
8
10 // TODO: Can this class be combined with series?
9 // TODO: Can this class be combined with series?
11 class BarGroup;
10 class BarGroup;
12
11
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14
13
15 // Container for series
14 // Container for series
16 class QTCOMMERCIALCHART_EXPORT BarChartSeries : public QChartSeries
15 class QTCOMMERCIALCHART_EXPORT BarChartSeries : public QChartSeries
17 {
16 {
18 Q_OBJECT
17 Q_OBJECT
19 public:
18 public:
20 BarChartSeries(QObject* parent=0);
19 BarChartSeries(QObject* parent=0);
21
20
22 // from QChartSeries
21 // from QChartSeries
23 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
24
23
25 // TODO: Better data model?
24 // TODO: Better data model?
26 virtual bool setData(QAbstractItemModel* model);
25 virtual bool setData(QAbstractItemModel* model);
27
26
28 // Methods to find out minimum and maximum values of data
27 // Methods to find out minimum and maximum values of data
29 int min();
28 int min();
30 int max();
29 int max();
31 int countSeries();
30 int countSeries();
32 int countColumns(); // Count items in one series.
31 int countColumns(); // Count items in one series.
33 int countTotalItems();
32 int countTotalItems();
34 int valueAt(int row, int column);
33 int valueAt(int row, int column);
35
34
36 public Q_SLOTS:
35 public Q_SLOTS:
37
36
38 // TODO: wrong place for this... series don't know anything about layout
39 // void chartSizeChanged(QRectF rect);
40
41 private:
37 private:
42
38
43 QAbstractItemModel* mModel;
39 QAbstractItemModel* mModel;
44 BarGroup* mBarGroup;
40 BarGroup* mBarGroup;
45 };
41 };
46
42
47 QTCOMMERCIALCHART_END_NAMESPACE
43 QTCOMMERCIALCHART_END_NAMESPACE
48
44
49 #endif // BARCHARTSERIES_H
45 #endif // BARCHARTSERIES_H
@@ -1,404 +1,427
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartseries.h"
2 #include "qchartseries.h"
3 #include "qscatterseries.h"
3 #include "qscatterseries.h"
4 #include "qscatterseries_p.h"
4 #include "qscatterseries_p.h"
5 #include "qpieseries.h"
5 #include "qpieseries.h"
6 #include "qxychartseries.h"
6 #include "qxychartseries.h"
7 #include "qchartaxis.h"
7 #include "qchartaxis.h"
8 #include "barchartseries.h"
8 #include "barchartseries.h"
9 #include "bargroup.h"
9 #include "bargroup.h"
10 #include "stackedbarchartseries.h"
11 #include "stackedbargroup.h"
10
12
11 #include "xylinechartitem_p.h"
13 #include "xylinechartitem_p.h"
12 #include "plotdomain_p.h"
14 #include "plotdomain_p.h"
13 #include "axisitem_p.h"
15 #include "axisitem_p.h"
14 #include <QGraphicsScene>
16 #include <QGraphicsScene>
15 #include <QDebug>
17 #include <QDebug>
16
18
17 QTCOMMERCIALCHART_BEGIN_NAMESPACE
19 QTCOMMERCIALCHART_BEGIN_NAMESPACE
18
20
19 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
21 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
20 m_backgroundItem(0),
22 m_backgroundItem(0),
21 m_titleItem(0),
23 m_titleItem(0),
22 m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)),
24 m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)),
23 m_plotDataIndex(0),
25 m_plotDataIndex(0),
24 m_marginSize(0)
26 m_marginSize(0)
25 {
27 {
26 // TODO: the default theme?
28 // TODO: the default theme?
27 setTheme(QChart::ChartThemeDefault);
29 setTheme(QChart::ChartThemeDefault);
28
30
29 PlotDomain domain;
31 PlotDomain domain;
30 m_plotDomainList<<domain;
32 m_plotDomainList<<domain;
31 m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this);
33 m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this);
32 m_chartItems<<m_axisXItem;
34 m_chartItems<<m_axisXItem;
33 m_chartItems<<m_axisYItem.at(0);
35 m_chartItems<<m_axisYItem.at(0);
34 }
36 }
35
37
36 QChart::~QChart(){}
38 QChart::~QChart(){}
37
39
38 QRectF QChart::boundingRect() const
40 QRectF QChart::boundingRect() const
39 {
41 {
40 return m_rect;
42 return m_rect;
41 }
43 }
42
44
43 void QChart::addSeries(QChartSeries* series)
45 void QChart::addSeries(QChartSeries* series)
44 {
46 {
45 // TODO: we should check the series not already added
47 // TODO: we should check the series not already added
46
48
47 m_chartSeries << series;
49 m_chartSeries << series;
48
50
49 switch(series->type())
51 switch(series->type())
50 {
52 {
51 case QChartSeries::SeriesTypeLine: {
53 case QChartSeries::SeriesTypeLine: {
52
54
53 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
55 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
54 // Use color defined by theme in case the series does not define a custom color
56 // Use color defined by theme in case the series does not define a custom color
55
57
56 if (!xyseries->pen().color().isValid() && m_themeColors.count()) //TODO: wtf
58 if (!xyseries->pen().color().isValid() && m_themeColors.count()) //TODO: wtf
57 xyseries->setPen(nextColor());
59 xyseries->setPen(nextColor());
58
60
59 m_plotDataIndex = 0 ;
61 m_plotDataIndex = 0 ;
60 m_plotDomainList.resize(1);
62 m_plotDomainList.resize(1);
61
63
62 PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
64 PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
63
65
64 for (int i = 0 ; i < xyseries->count() ; i++)
66 for (int i = 0 ; i < xyseries->count() ; i++)
65 {
67 {
66 qreal x = xyseries->x(i);
68 qreal x = xyseries->x(i);
67 qreal y = xyseries->y(i);
69 qreal y = xyseries->y(i);
68 domain.m_minX = qMin(domain.m_minX,x);
70 domain.m_minX = qMin(domain.m_minX,x);
69 domain.m_minY = qMin(domain.m_minY,y);
71 domain.m_minY = qMin(domain.m_minY,y);
70 domain.m_maxX = qMax(domain.m_maxX,x);
72 domain.m_maxX = qMax(domain.m_maxX,x);
71 domain.m_maxY = qMax(domain.m_maxY,y);
73 domain.m_maxY = qMax(domain.m_maxY,y);
72 }
74 }
73
75
74 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
76 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
75 m_chartItems<<item;
77 m_chartItems<<item;
76
78
77 foreach(ChartItem* i ,m_chartItems)
79 foreach(ChartItem* i ,m_chartItems)
78 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
80 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
79
81
80 break;
82 break;
81 }
83 }
82 case QChartSeries::SeriesTypeBar: {
84 case QChartSeries::SeriesTypeBar: {
83
85
84 qDebug() << "barSeries added";
86 qDebug() << "barSeries added";
85 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
87 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
86 BarGroup* barGroup = new BarGroup(*barSeries,this);
88 BarGroup* barGroup = new BarGroup(*barSeries,this);
87
89
88 // Add some fugly colors for 5 fist series...
90 // Add some fugly colors for 5 fist series...
89 barGroup->addColor(QColor(255,0,0,128));
91 barGroup->addColor(QColor(255,0,0,128));
90 barGroup->addColor(QColor(255,255,0,128));
92 barGroup->addColor(QColor(255,255,0,128));
91 barGroup->addColor(QColor(0,255,0,128));
93 barGroup->addColor(QColor(0,255,0,128));
92 barGroup->addColor(QColor(0,0,255,128));
94 barGroup->addColor(QColor(0,0,255,128));
93 barGroup->addColor(QColor(255,128,0,128));
95 barGroup->addColor(QColor(255,128,0,128));
94
96
95 m_chartItems<<barGroup;
97 m_chartItems<<barGroup;
96 childItems().append(barGroup);
98 childItems().append(barGroup);
97 break;
99 break;
98 }
100 }
101 case QChartSeries::SeriesTypeStackedBar: {
102
103 qDebug() << "barSeries added";
104 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
105 StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this);
106
107 // Add some fugly colors for 5 fist series...
108 stackedBarGroup->addColor(QColor(255,0,0,128));
109 stackedBarGroup->addColor(QColor(255,255,0,128));
110 stackedBarGroup->addColor(QColor(0,255,0,128));
111 stackedBarGroup->addColor(QColor(0,0,255,128));
112 stackedBarGroup->addColor(QColor(255,128,0,128));
113
114 m_chartItems<<stackedBarGroup;
115 childItems().append(stackedBarGroup);
116 break;
117 }
99 case QChartSeries::SeriesTypeScatter: {
118 case QChartSeries::SeriesTypeScatter: {
100 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
119 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
101 scatterSeries->d->setParentItem(this);
120 scatterSeries->d->setParentItem(this);
102 // Set pre-defined colors in case the series has no colors defined
121 // Set pre-defined colors in case the series has no colors defined
103 if (!scatterSeries->markerColor().isValid())
122 if (!scatterSeries->markerColor().isValid())
104 scatterSeries->setMarkerColor(nextColor());
123 scatterSeries->setMarkerColor(nextColor());
105 connect(this, SIGNAL(sizeChanged(QRectF)),
124 connect(this, SIGNAL(sizeChanged(QRectF)),
106 scatterSeries, SLOT(chartSizeChanged(QRectF)));
125 scatterSeries, SLOT(chartSizeChanged(QRectF)));
107 // QColor nextColor = m_themeColors.takeFirst();
126 // QColor nextColor = m_themeColors.takeFirst();
108 // nextColor.setAlpha(150); // TODO: default opacity?
127 // nextColor.setAlpha(150); // TODO: default opacity?
109 // scatterSeries->setMarkerColor(nextColor);
128 // scatterSeries->setMarkerColor(nextColor);
110 break;
129 break;
111 }
130 }
112 case QChartSeries::SeriesTypePie: {
131 case QChartSeries::SeriesTypePie: {
113 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
132 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
114 for (int i(0); i < pieSeries->sliceCount(); i++) {
133 for (int i(0); i < pieSeries->sliceCount(); i++) {
115 if (!pieSeries->sliceColor(i).isValid())
134 if (!pieSeries->sliceColor(i).isValid())
116 pieSeries->setSliceColor(i, nextColor());
135 pieSeries->setSliceColor(i, nextColor());
117 }
136 }
118 connect(this, SIGNAL(sizeChanged(QRectF)),
137 connect(this, SIGNAL(sizeChanged(QRectF)),
119 pieSeries, SLOT(chartSizeChanged(QRectF)));
138 pieSeries, SLOT(chartSizeChanged(QRectF)));
120
139
121 // Set pre-defined colors in case the series has no colors defined
140 // Set pre-defined colors in case the series has no colors defined
122 // TODO: how to define the color for all the slices of a pie?
141 // TODO: how to define the color for all the slices of a pie?
123 // for (int (i); i < pieSeries.sliceCount(); i++)
142 // for (int (i); i < pieSeries.sliceCount(); i++)
124 break;
143 break;
125 }
144 }
126 }
145 }
127 }
146 }
128
147
129 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
148 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
130 {
149 {
131 // TODO: support also other types; not only scatter and pie
150 // TODO: support also other types; not only scatter and pie
132
151
133 QChartSeries *series(0);
152 QChartSeries *series(0);
134
153
135 switch (type) {
154 switch (type) {
136 case QChartSeries::SeriesTypeLine: {
155 case QChartSeries::SeriesTypeLine: {
137 series = QXYChartSeries::create();
156 series = QXYChartSeries::create();
138 break;
157 break;
139 }
158 }
140 case QChartSeries::SeriesTypeBar: {
159 case QChartSeries::SeriesTypeBar: {
141 series = new BarChartSeries(this);
160 series = new BarChartSeries(this);
142 break;
161 break;
143 }
162 }
163 case QChartSeries::SeriesTypeStackedBar: {
164 series = new StackedBarChartSeries(this);
165 break;
166 }
144 case QChartSeries::SeriesTypeScatter: {
167 case QChartSeries::SeriesTypeScatter: {
145 series = new QScatterSeries(this);
168 series = new QScatterSeries(this);
146 break;
169 break;
147 }
170 }
148 case QChartSeries::SeriesTypePie: {
171 case QChartSeries::SeriesTypePie: {
149 series = new QPieSeries(this);
172 series = new QPieSeries(this);
150 break;
173 break;
151 }
174 }
152 default:
175 default:
153 Q_ASSERT(false);
176 Q_ASSERT(false);
154 break;
177 break;
155 }
178 }
156
179
157 addSeries(series);
180 addSeries(series);
158 return series;
181 return series;
159 }
182 }
160
183
161 void QChart::setSize(const QSize& size)
184 void QChart::setSize(const QSize& size)
162 {
185 {
163 m_rect = QRect(QPoint(0,0),size);
186 m_rect = QRect(QPoint(0,0),size);
164 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
187 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
165
188
166 //recaculate title
189 //recaculate title
167 if(m_titleItem){
190 if(m_titleItem){
168 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
191 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
169 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
192 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
170
193
171 }
194 }
172
195
173 //recalculate background gradient
196 //recalculate background gradient
174 if(m_backgroundItem){
197 if(m_backgroundItem){
175 m_backgroundItem->setRect(rect);
198 m_backgroundItem->setRect(rect);
176 if(m_bacgroundOrinetation==HorizonatlGradientOrientation)
199 if(m_bacgroundOrinetation==HorizonatlGradientOrientation)
177 m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(),0);
200 m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(),0);
178 else
201 else
179 m_backgroundGradient.setFinalStop(0,m_backgroundItem->rect().height());
202 m_backgroundGradient.setFinalStop(0,m_backgroundItem->rect().height());
180
203
181 m_backgroundItem->setBrush(m_backgroundGradient);
204 m_backgroundItem->setBrush(m_backgroundGradient);
182 }
205 }
183
206
184 //resize elements
207 //resize elements
185 foreach (ChartItem* item ,m_chartItems) {
208 foreach (ChartItem* item ,m_chartItems) {
186 item->setPos(rect.topLeft());
209 item->setPos(rect.topLeft());
187 item->setSize(rect.size());
210 item->setSize(rect.size());
188
211
189 }
212 }
190 // TODO: TTD for setting scale
213 // TODO: TTD for setting scale
191 //emit scaleChanged(100, 100);
214 //emit scaleChanged(100, 100);
192 // TODO: calculate the origo
215 // TODO: calculate the origo
193 // TODO: not sure if emitting a signal here is the best from performance point of view
216 // TODO: not sure if emitting a signal here is the best from performance point of view
194 emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
217 emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
195
218
196 update();
219 update();
197 }
220 }
198
221
199 void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation)
222 void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation)
200 {
223 {
201
224
202 if(!m_backgroundItem){
225 if(!m_backgroundItem){
203 m_backgroundItem = new QGraphicsRectItem(this);
226 m_backgroundItem = new QGraphicsRectItem(this);
204 m_backgroundItem->setZValue(-1);
227 m_backgroundItem->setZValue(-1);
205 }
228 }
206
229
207 m_bacgroundOrinetation = orientation;
230 m_bacgroundOrinetation = orientation;
208 m_backgroundGradient.setColorAt( 0.0, startColor);
231 m_backgroundGradient.setColorAt( 0.0, startColor);
209 m_backgroundGradient.setColorAt( 1.0, endColor);
232 m_backgroundGradient.setColorAt( 1.0, endColor);
210 m_backgroundGradient.setStart(0,0);
233 m_backgroundGradient.setStart(0,0);
211
234
212 if(orientation == VerticalGradientOrientation){
235 if(orientation == VerticalGradientOrientation){
213 m_backgroundGradient.setFinalStop(0,m_rect.height());
236 m_backgroundGradient.setFinalStop(0,m_rect.height());
214 }else{
237 }else{
215 m_backgroundGradient.setFinalStop(m_rect.width(),0);
238 m_backgroundGradient.setFinalStop(m_rect.width(),0);
216 }
239 }
217
240
218 m_backgroundItem->setBrush(m_backgroundGradient);
241 m_backgroundItem->setBrush(m_backgroundGradient);
219 m_backgroundItem->setPen(Qt::NoPen);
242 m_backgroundItem->setPen(Qt::NoPen);
220 m_backgroundItem->update();
243 m_backgroundItem->update();
221 }
244 }
222
245
223 void QChart::setTitle(const QString& title,const QFont& font)
246 void QChart::setTitle(const QString& title,const QFont& font)
224 {
247 {
225 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
248 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
226 m_titleItem->setPlainText(title);
249 m_titleItem->setPlainText(title);
227 m_titleItem->setFont(font);
250 m_titleItem->setFont(font);
228 }
251 }
229
252
230 int QChart::margin() const
253 int QChart::margin() const
231 {
254 {
232 return m_marginSize;
255 return m_marginSize;
233 }
256 }
234
257
235 void QChart::setMargin(int margin)
258 void QChart::setMargin(int margin)
236 {
259 {
237 m_marginSize = margin;
260 m_marginSize = margin;
238 }
261 }
239
262
240 void QChart::setTheme(QChart::ChartThemeId theme)
263 void QChart::setTheme(QChart::ChartThemeId theme)
241 {
264 {
242 // if (theme != m_currentTheme) {
265 // if (theme != m_currentTheme) {
243 m_themeColors.clear();
266 m_themeColors.clear();
244
267
245 // TODO: define color themes
268 // TODO: define color themes
246 switch (theme) {
269 switch (theme) {
247 case QChart::ChartThemeDefault:
270 case QChart::ChartThemeDefault:
248 // TODO: define the default theme based on the OS
271 // TODO: define the default theme based on the OS
249 m_themeColors.append(QColor(QRgb(0xff000000)));
272 m_themeColors.append(QColor(QRgb(0xff000000)));
250 m_themeColors.append(QColor(QRgb(0xff707070)));
273 m_themeColors.append(QColor(QRgb(0xff707070)));
251 setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
274 setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
252 break;
275 break;
253 case QChart::ChartThemeVanilla:
276 case QChart::ChartThemeVanilla:
254 m_themeColors.append(QColor(217, 197, 116));
277 m_themeColors.append(QColor(217, 197, 116));
255 m_themeColors.append(QColor(214, 168, 150));
278 m_themeColors.append(QColor(214, 168, 150));
256 m_themeColors.append(QColor(160, 160, 113));
279 m_themeColors.append(QColor(160, 160, 113));
257 m_themeColors.append(QColor(210, 210, 52));
280 m_themeColors.append(QColor(210, 210, 52));
258 m_themeColors.append(QColor(136, 114, 58));
281 m_themeColors.append(QColor(136, 114, 58));
259
282
260 setBackground(QColor(QRgb(0xff9d844d)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
283 setBackground(QColor(QRgb(0xff9d844d)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
261 break;
284 break;
262 case QChart::ChartThemeIcy:
285 case QChart::ChartThemeIcy:
263 m_themeColors.append(QColor(0, 3, 165));
286 m_themeColors.append(QColor(0, 3, 165));
264 m_themeColors.append(QColor(49, 52, 123));
287 m_themeColors.append(QColor(49, 52, 123));
265 m_themeColors.append(QColor(71, 114, 187));
288 m_themeColors.append(QColor(71, 114, 187));
266 m_themeColors.append(QColor(48, 97, 87));
289 m_themeColors.append(QColor(48, 97, 87));
267 m_themeColors.append(QColor(19, 71, 90));
290 m_themeColors.append(QColor(19, 71, 90));
268 m_themeColors.append(QColor(110, 70, 228));
291 m_themeColors.append(QColor(110, 70, 228));
269
292
270 setBackground(QColor(QRgb(0xffe4ffff)), QColor(QRgb(0xffe4ffff)), VerticalGradientOrientation);
293 setBackground(QColor(QRgb(0xffe4ffff)), QColor(QRgb(0xffe4ffff)), VerticalGradientOrientation);
271 break;
294 break;
272 case QChart::ChartThemeGrayscale:
295 case QChart::ChartThemeGrayscale:
273 m_themeColors.append(QColor(0, 0, 0));
296 m_themeColors.append(QColor(0, 0, 0));
274 m_themeColors.append(QColor(50, 50, 50));
297 m_themeColors.append(QColor(50, 50, 50));
275 m_themeColors.append(QColor(100, 100, 100));
298 m_themeColors.append(QColor(100, 100, 100));
276 m_themeColors.append(QColor(140, 140, 140));
299 m_themeColors.append(QColor(140, 140, 140));
277 m_themeColors.append(QColor(180, 180, 180));
300 m_themeColors.append(QColor(180, 180, 180));
278
301
279 setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
302 setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
280 break;
303 break;
281 case QChart::ChartThemeUnnamed1:
304 case QChart::ChartThemeUnnamed1:
282 m_themeColors.append(QColor(QRgb(0xff3fa9f5)));
305 m_themeColors.append(QColor(QRgb(0xff3fa9f5)));
283 m_themeColors.append(QColor(QRgb(0xff7AC943)));
306 m_themeColors.append(QColor(QRgb(0xff7AC943)));
284 m_themeColors.append(QColor(QRgb(0xffFF931E)));
307 m_themeColors.append(QColor(QRgb(0xffFF931E)));
285 m_themeColors.append(QColor(QRgb(0xffFF1D25)));
308 m_themeColors.append(QColor(QRgb(0xffFF1D25)));
286 m_themeColors.append(QColor(QRgb(0xffFF7BAC)));
309 m_themeColors.append(QColor(QRgb(0xffFF7BAC)));
287
310
288 setBackground(QColor(QRgb(0xfff3dc9e)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
311 setBackground(QColor(QRgb(0xfff3dc9e)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
289 break;
312 break;
290 default:
313 default:
291 Q_ASSERT(false);
314 Q_ASSERT(false);
292 break;
315 break;
293 }
316 }
294
317
295 if(m_backgroundItem){
318 if(m_backgroundItem){
296 m_backgroundItem->setBrush(m_backgroundGradient);
319 m_backgroundItem->setBrush(m_backgroundGradient);
297 m_backgroundItem->setPen(Qt::NoPen);
320 m_backgroundItem->setPen(Qt::NoPen);
298 }
321 }
299
322
300 foreach(QChartSeries* series, m_chartSeries) {
323 foreach(QChartSeries* series, m_chartSeries) {
301 // TODO: other series interested on themes?
324 // TODO: other series interested on themes?
302 if (series->type() == QChartSeries::SeriesTypeLine) {
325 if (series->type() == QChartSeries::SeriesTypeLine) {
303 QXYChartSeries *lineseries = reinterpret_cast<QXYChartSeries *>(series);
326 QXYChartSeries *lineseries = reinterpret_cast<QXYChartSeries *>(series);
304 lineseries->setPen(nextColor());
327 lineseries->setPen(nextColor());
305 } else if (series->type() == QChartSeries::SeriesTypeScatter) {
328 } else if (series->type() == QChartSeries::SeriesTypeScatter) {
306 QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
329 QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
307 scatter->setMarkerColor(nextColor());
330 scatter->setMarkerColor(nextColor());
308 } else if (series->type() == QChartSeries::SeriesTypePie) {
331 } else if (series->type() == QChartSeries::SeriesTypePie) {
309 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
332 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
310 for (int i(0); i < pieSeries->sliceCount(); i++)
333 for (int i(0); i < pieSeries->sliceCount(); i++)
311 pieSeries->setSliceColor(i, nextColor());
334 pieSeries->setSliceColor(i, nextColor());
312 }
335 }
313 }
336 }
314 update();
337 update();
315 }
338 }
316
339
317 QColor QChart::nextColor()
340 QColor QChart::nextColor()
318 {
341 {
319 QColor nextColor = m_themeColors.first();
342 QColor nextColor = m_themeColors.first();
320 m_themeColors.move(0, m_themeColors.size() - 1);
343 m_themeColors.move(0, m_themeColors.size() - 1);
321 return nextColor;
344 return nextColor;
322 }
345 }
323
346
324 void QChart::zoomInToRect(const QRect& rectangle)
347 void QChart::zoomInToRect(const QRect& rectangle)
325 {
348 {
326
349
327 if(!rectangle.isValid()) return;
350 if(!rectangle.isValid()) return;
328
351
329 qreal margin = this->margin();
352 qreal margin = this->margin();
330
353
331 QRect rect = rectangle.normalized();
354 QRect rect = rectangle.normalized();
332 rect.translate(-margin, -margin);
355 rect.translate(-margin, -margin);
333
356
334 PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
357 PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
335
358
336 PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin);
359 PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin);
337
360
338 m_plotDomainList.resize(m_plotDataIndex + 1);
361 m_plotDomainList.resize(m_plotDataIndex + 1);
339 m_plotDomainList<<domain;
362 m_plotDomainList<<domain;
340 m_plotDataIndex++;
363 m_plotDataIndex++;
341
364
342 foreach (ChartItem* item ,m_chartItems)
365 foreach (ChartItem* item ,m_chartItems)
343 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
366 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
344 update();
367 update();
345 }
368 }
346
369
347 void QChart::zoomIn()
370 void QChart::zoomIn()
348 {
371 {
349 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
372 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
350 m_plotDataIndex++;
373 m_plotDataIndex++;
351 foreach (ChartItem* item ,m_chartItems)
374 foreach (ChartItem* item ,m_chartItems)
352 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
375 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
353 update();
376 update();
354 } else {
377 } else {
355 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
378 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
356 rect.setWidth(rect.width()/2);
379 rect.setWidth(rect.width()/2);
357 rect.setHeight(rect.height()/2);
380 rect.setHeight(rect.height()/2);
358 rect.moveCenter(m_rect.center());
381 rect.moveCenter(m_rect.center());
359 zoomInToRect(rect);
382 zoomInToRect(rect);
360 }
383 }
361 }
384 }
362
385
363 void QChart::zoomOut()
386 void QChart::zoomOut()
364 {
387 {
365 if (m_plotDataIndex > 0) {
388 if (m_plotDataIndex > 0) {
366 m_plotDataIndex--;
389 m_plotDataIndex--;
367 foreach (ChartItem* item ,m_chartItems)
390 foreach (ChartItem* item ,m_chartItems)
368 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
391 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
369 update();
392 update();
370 }
393 }
371 }
394 }
372
395
373 void QChart::zoomReset()
396 void QChart::zoomReset()
374 {
397 {
375 if (m_plotDataIndex > 0) {
398 if (m_plotDataIndex > 0) {
376 m_plotDataIndex = 0;
399 m_plotDataIndex = 0;
377 foreach (ChartItem* item ,m_chartItems)
400 foreach (ChartItem* item ,m_chartItems)
378 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
401 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
379 update();
402 update();
380 }
403 }
381 }
404 }
382
405
383 void QChart::setAxisX(const QChartAxis& axis)
406 void QChart::setAxisX(const QChartAxis& axis)
384 {
407 {
385 setAxis(m_axisXItem,axis);
408 setAxis(m_axisXItem,axis);
386 }
409 }
387 void QChart::setAxisY(const QChartAxis& axis)
410 void QChart::setAxisY(const QChartAxis& axis)
388 {
411 {
389 setAxis(m_axisYItem.at(0),axis);
412 setAxis(m_axisYItem.at(0),axis);
390 }
413 }
391
414
392 void QChart::setAxisY(const QList<QChartAxis>& axis)
415 void QChart::setAxisY(const QList<QChartAxis>& axis)
393 {
416 {
394 //TODO not implemented
417 //TODO not implemented
395 }
418 }
396
419
397 void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
420 void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
398 {
421 {
399 item->setVisible(axis.isAxisVisible());
422 item->setVisible(axis.isAxisVisible());
400 }
423 }
401
424
402 #include "moc_qchart.cpp"
425 #include "moc_qchart.cpp"
403
426
404 QTCOMMERCIALCHART_END_NAMESPACE
427 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,95 +1,95
1 !include( ../common.pri ) {
1 !include( ../common.pri ) {
2 error( Couldn't find the common.pri file! )
2 error( Couldn't find the common.pri file! )
3 }
3 }
4
4
5 TARGET = QtCommercialChart
5 TARGET = QtCommercialChart
6 DESTDIR = $$CHART_BUILD_LIB_DIR
6 DESTDIR = $$CHART_BUILD_LIB_DIR
7 TEMPLATE = lib
7 TEMPLATE = lib
8 QT += core \
8 QT += core \
9 gui
9 gui
10
10
11 CONFIG += debug_and_release
11 CONFIG += debug_and_release
12 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
12 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
13
13
14 SOURCES += \
14 SOURCES += \
15 barchart/barchartseries.cpp \
15 barchart/barchartseries.cpp \
16 barchart/bargroup.cpp \
16 barchart/bargroup.cpp \
17 barchart/bar.cpp \
17 barchart/bar.cpp \
18 barchart/stackedbarchartseries.cpp \
19 barchart/stackedbargroup.cpp \
18 xylinechart/qxychartseries.cpp \
20 xylinechart/qxychartseries.cpp \
19 xylinechart/xylinechartitem.cpp \
21 xylinechart/xylinechartitem.cpp \
20 plotdomain.cpp \
22 plotdomain.cpp \
21 qscatterseries.cpp \
23 qscatterseries.cpp \
22 qpieseries.cpp \
24 qpieseries.cpp \
23 qchart.cpp \
25 qchart.cpp \
24 axisitem.cpp \
26 axisitem.cpp \
25 qchartwidget.cpp \
27 qchartwidget.cpp \
26 pieslice.cpp \
28 pieslice.cpp \
27 qchartview.cpp \
29 qchartview.cpp \
28 qchartseries.cpp \
30 qchartseries.cpp \
29 qchartaxis.cpp \
31 qchartaxis.cpp
30 barchart/stackedbarchartseries.cpp \
31 barchart/stackedbargroup.cpp
32
32
33 PRIVATE_HEADERS += \
33 PRIVATE_HEADERS += \
34 xylinechart/xylinechartitem_p.h \
34 xylinechart/xylinechartitem_p.h \
35 plotdomain_p.h \
35 plotdomain_p.h \
36 qscatterseries_p.h \
36 qscatterseries_p.h \
37 pieslice.h \
37 pieslice.h \
38 axisitem_p.h \
38 axisitem_p.h \
39 chartitem_p.h
39 chartitem_p.h
40
40
41 PUBLIC_HEADERS += \
41 PUBLIC_HEADERS += \
42 qchartseries.h \
42 qchartseries.h \
43 qscatterseries.h \
43 qscatterseries.h \
44 qpieseries.h \
44 qpieseries.h \
45 qchart.h \
45 qchart.h \
46 qchartwidget.h \
46 qchartwidget.h \
47 qchartglobal.h \
47 qchartglobal.h \
48 xylinechart/qxychartseries.h \
48 xylinechart/qxychartseries.h \
49 barchart/barchartseries.h \
49 barchart/barchartseries.h \
50 barchart/bargroup.h \
50 barchart/bargroup.h \
51 barchart/stackedbarchartseries.h \
52 barchart/stackedbargroup.h \
51 qchartview.h \
53 qchartview.h \
52 qchartaxis.h
54 qchartaxis.h
53
55
54 HEADERS += $$PUBLIC_HEADERS \
56 HEADERS += $$PUBLIC_HEADERS
55 barchart/stackedbarchartseries.h \
56 barchart/stackedbargroup.h
57 HEADERS += $$PRIVATE_HEADERS
57 HEADERS += $$PRIVATE_HEADERS
58
58
59 INCLUDEPATH += xylinechart \
59 INCLUDEPATH += xylinechart \
60 barchart \
60 barchart \
61 .
61 .
62
62
63 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
63 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
64 MOC_DIR = $$CHART_BUILD_DIR/lib
64 MOC_DIR = $$CHART_BUILD_DIR/lib
65 UI_DIR = $$CHART_BUILD_DIR/lib
65 UI_DIR = $$CHART_BUILD_DIR/lib
66 RCC_DIR = $$CHART_BUILD_DIR/lib
66 RCC_DIR = $$CHART_BUILD_DIR/lib
67
67
68
68
69 DEFINES += QTCOMMERCIALCHART_LIBRARY
69 DEFINES += QTCOMMERCIALCHART_LIBRARY
70
70
71 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
71 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
72 public_headers.files = $$PUBLIC_HEADERS
72 public_headers.files = $$PUBLIC_HEADERS
73 target.path = $$[QT_INSTALL_LIBS]
73 target.path = $$[QT_INSTALL_LIBS]
74 INSTALLS += target \
74 INSTALLS += target \
75 public_headers
75 public_headers
76
76
77
77
78 install_build_headers.name = bild_headers
78 install_build_headers.name = bild_headers
79 install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h
79 install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h
80 install_build_headers.input = PUBLIC_HEADERS
80 install_build_headers.input = PUBLIC_HEADERS
81 install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR
81 install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR
82 install_build_headers.CONFIG += target_predeps no_link
82 install_build_headers.CONFIG += target_predeps no_link
83 QMAKE_EXTRA_COMPILERS += install_build_headers
83 QMAKE_EXTRA_COMPILERS += install_build_headers
84
84
85 chartversion.target = qchartversion_p.h
85 chartversion.target = qchartversion_p.h
86 chartversion.commands = @echo "build_time" > $$chartversion.target;
86 chartversion.commands = @echo "build_time" > $$chartversion.target;
87 chartversion.depends = $$HEADERS $$SOURCES
87 chartversion.depends = $$HEADERS $$SOURCES
88 PRE_TARGETDEPS += qchartversion_p.h
88 PRE_TARGETDEPS += qchartversion_p.h
89 QMAKE_CLEAN+= qchartversion_p.h
89 QMAKE_CLEAN+= qchartversion_p.h
90 QMAKE_EXTRA_TARGETS += chartversion
90 QMAKE_EXTRA_TARGETS += chartversion
91
91
92 unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
92 unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
93 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
93 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
94
94
95
95
General Comments 0
You need to be logged in to leave comments. Login now