@@ -0,0 +1,20 | |||
|
1 | #include "charttheme_p.h" | |
|
2 | ||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
4 | ||
|
5 | class ChartThemeGrayscale: public ChartTheme | |
|
6 | { | |
|
7 | public: | |
|
8 | ChartThemeGrayscale() | |
|
9 | { | |
|
10 | m_seriesColor.append(QRgb(0xFF869299)); | |
|
11 | m_seriesColor.append(QRgb(0xFFA5BDCC)); | |
|
12 | m_seriesColor.append(QRgb(0xFFE8FFFC)); | |
|
13 | m_seriesColor.append(QRgb(0xFFCCC2C2)); | |
|
14 | ||
|
15 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
|
16 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
17 | } | |
|
18 | }; | |
|
19 | ||
|
20 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,20 | |||
|
1 | #include "charttheme_p.h" | |
|
2 | ||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
4 | ||
|
5 | class ChartThemeIcy: public ChartTheme | |
|
6 | { | |
|
7 | public: | |
|
8 | ChartThemeIcy() | |
|
9 | { | |
|
10 | m_seriesColor.append(QRgb(0xFF0D2673)); | |
|
11 | m_seriesColor.append(QRgb(0xFF2685BF)); | |
|
12 | m_seriesColor.append(QRgb(0xFF3DADD9)); | |
|
13 | m_seriesColor.append(QRgb(0xFF62C3D9)); | |
|
14 | ||
|
15 | m_gradientStartColor = QColor(QRgb(0xffBDE3F2)); | |
|
16 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
17 | } | |
|
18 | }; | |
|
19 | ||
|
20 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,20 | |||
|
1 | #include "charttheme_p.h" | |
|
2 | ||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
4 | ||
|
5 | class ChartThemeScientific: public ChartTheme | |
|
6 | { | |
|
7 | public: | |
|
8 | ChartThemeScientific() | |
|
9 | { | |
|
10 | m_seriesColor.append(QRgb(0xFF000000)); | |
|
11 | m_seriesColor.append(QRgb(0xFFFFAD00)); | |
|
12 | m_seriesColor.append(QRgb(0xFF596A75)); | |
|
13 | m_seriesColor.append(QRgb(0xFF474747)); | |
|
14 | ||
|
15 | m_gradientStartColor = QColor(QRgb(0xffafafaf)); | |
|
16 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
17 | } | |
|
18 | }; | |
|
19 | ||
|
20 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,21 | |||
|
1 | #include "charttheme_p.h" | |
|
2 | ||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
4 | ||
|
5 | class ChartThemeVanilla: public ChartTheme | |
|
6 | { | |
|
7 | public: | |
|
8 | ChartThemeVanilla() | |
|
9 | { | |
|
10 | m_seriesColor.append(QColor(217, 197, 116)); | |
|
11 | m_seriesColor.append(QColor(214, 168, 150)); | |
|
12 | m_seriesColor.append(QColor(160, 160, 113)); | |
|
13 | m_seriesColor.append(QColor(210, 210, 52)); | |
|
14 | m_seriesColor.append(QColor(136, 114, 58)); | |
|
15 | ||
|
16 | m_gradientStartColor = QColor(QRgb(0xff9d844d)); | |
|
17 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
18 | } | |
|
19 | }; | |
|
20 | ||
|
21 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -2,6 +2,7 | |||
|
2 | 2 | #include "qchartaxis.h" |
|
3 | 3 | #include "chartpresenter_p.h" |
|
4 | 4 | #include "chartdataset_p.h" |
|
5 | #include "charttheme_p.h" | |
|
5 | 6 | //series |
|
6 | 7 | #include "barchartseries.h" |
|
7 | 8 | #include "stackedbarchartseries.h" |
@@ -25,10 +26,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
25 | 26 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
26 | 27 | m_chart(chart), |
|
27 | 28 | m_dataset(dataset), |
|
29 | m_chartTheme(0), | |
|
28 | 30 | m_domainIndex(0), |
|
29 | 31 | m_marginSize(0), |
|
30 | 32 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
31 | 33 | { |
|
34 | setTheme(QChart::ChartThemeDefault); | |
|
32 | 35 | createConnections(); |
|
33 | 36 | createDeafultAxis(); |
|
34 | 37 | } |
@@ -82,7 +85,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
82 | 85 | case QChartSeries::SeriesTypeLine: { |
|
83 | 86 | QXYChartSeries* lineSeries = static_cast<QXYChartSeries*>(series); |
|
84 | 87 | XYLineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
85 | item->setPen(lineSeries->pen()); | |
|
88 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
|
86 | 89 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
87 | 90 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
88 | 91 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
@@ -93,14 +96,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
93 | 96 | case QChartSeries::SeriesTypeBar: { |
|
94 | 97 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
95 | 98 | BarGroup* item = new BarGroup(*barSeries,m_chart); |
|
96 | ||
|
97 | // Add some fugly colors for 5 fist series... | |
|
98 | item->addColor(QColor(255,0,0,128)); | |
|
99 | item->addColor(QColor(255,255,0,128)); | |
|
100 | item->addColor(QColor(0,255,0,128)); | |
|
101 | item->addColor(QColor(0,0,255,128)); | |
|
102 | item->addColor(QColor(255,128,0,128)); | |
|
103 | ||
|
99 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
|
104 | 100 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
105 | 101 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
106 | 102 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
@@ -113,13 +109,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
113 | 109 | |
|
114 | 110 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
115 | 111 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); |
|
116 | ||
|
117 | // Add some fugly colors for 5 fist series... | |
|
118 | item->addColor(QColor(255,0,0,128)); | |
|
119 | item->addColor(QColor(255,255,0,128)); | |
|
120 | item->addColor(QColor(0,255,0,128)); | |
|
121 | item->addColor(QColor(0,0,255,128)); | |
|
122 | item->addColor(QColor(255,128,0,128)); | |
|
112 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
|
123 | 113 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
124 | 114 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
125 | 115 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
@@ -131,13 +121,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
131 | 121 | |
|
132 | 122 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
133 | 123 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); |
|
134 | ||
|
135 | // Add some fugly colors for 5 fist series... | |
|
136 | item->addColor(QColor(255,0,0,128)); | |
|
137 | item->addColor(QColor(255,255,0,128)); | |
|
138 | item->addColor(QColor(0,255,0,128)); | |
|
139 | item->addColor(QColor(0,0,255,128)); | |
|
140 | item->addColor(QColor(255,128,0,128)); | |
|
124 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
|
141 | 125 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
142 | 126 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
143 | 127 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
@@ -219,6 +203,29 void ChartPresenter::zoomReset() | |||
|
219 | 203 | m_dataset->clearDomains(); |
|
220 | 204 | } |
|
221 | 205 | |
|
206 | void ChartPresenter::setTheme(QChart::ChartThemeId theme) | |
|
207 | { | |
|
208 | delete m_chartTheme; | |
|
209 | ||
|
210 | m_chartTheme = ChartTheme::createTheme(theme); | |
|
211 | ||
|
212 | m_chartTheme->decorate(m_chart); | |
|
213 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); | |
|
214 | ||
|
215 | int index=0; | |
|
216 | while (i.hasNext()) { | |
|
217 | i.next(); | |
|
218 | index++; | |
|
219 | m_chartTheme->decorate(i.value(),i.key(),index); | |
|
220 | } | |
|
221 | } | |
|
222 | ||
|
223 | ||
|
224 | QChart::ChartThemeId ChartPresenter::theme() | |
|
225 | { | |
|
226 | return (QChart::ChartThemeId) 0; | |
|
227 | } | |
|
228 | ||
|
222 | 229 | /* |
|
223 | 230 | void ChartPresenter::setAxisX(const QChartAxis& axis) |
|
224 | 231 | { |
@@ -2,6 +2,7 | |||
|
2 | 2 | #define CHARTPRESENTER_H_ |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |
|
5 | 6 | #include <QRectF> |
|
6 | 7 | |
|
7 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -9,9 +10,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
9 | 10 | class ChartItem; |
|
10 | 11 | class QChartSeries; |
|
11 | 12 | class ChartDataSet; |
|
12 | class QChart; | |
|
13 | //class QChart; | |
|
13 | 14 | class Domain; |
|
14 | 15 | class AxisItem; |
|
16 | class ChartTheme; | |
|
15 | 17 | |
|
16 | 18 | class ChartPresenter: public QObject |
|
17 | 19 | { |
@@ -35,6 +37,9 public: | |||
|
35 | 37 | void zoomOut(); |
|
36 | 38 | void zoomReset(); |
|
37 | 39 | |
|
40 | void setTheme(QChart::ChartThemeId theme); | |
|
41 | QChart::ChartThemeId theme(); | |
|
42 | ||
|
38 | 43 | private: |
|
39 | 44 | void createConnections(); |
|
40 | 45 | void createDeafultAxis(); |
@@ -55,9 +60,11 private: | |||
|
55 | 60 | ChartDataSet* m_dataset; |
|
56 | 61 | QVector<Domain> m_domains; |
|
57 | 62 | QList<AxisItem*> m_axis; |
|
63 | ChartTheme *m_chartTheme; | |
|
58 | 64 | int m_domainIndex; |
|
59 | 65 | int m_marginSize; |
|
60 | 66 | QRectF m_rect; |
|
67 | ||
|
61 | 68 | }; |
|
62 | 69 | |
|
63 | 70 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,64 +1,29 | |||
|
1 | 1 | #include "charttheme_p.h" |
|
2 | 2 | #include "qchart.h" |
|
3 | 3 | |
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
5 | ||
|
6 | void ChartThemeData::setTheme(int theme) | |
|
7 | { | |
|
8 | m_seriesThemes.clear(); | |
|
9 | m_seriesIndex = 0; | |
|
10 | m_currentTheme = theme; | |
|
11 | 4 | |
|
12 | switch (theme) { | |
|
13 | case QChart::ChartThemeDefault: | |
|
14 | // line: solid, dashed, dotted | |
|
15 | // line width: 1 | |
|
16 | // line color (and opacity) | |
|
17 | // line shadow (on/off) | |
|
18 | // marker shape: "x", "o", "." | |
|
19 | // TODO: define the default theme based on the OS | |
|
20 | m_seriesThemes.append(SeriesTheme(QRgb(0xff000000), 2)); | |
|
21 | m_seriesThemes.append(SeriesTheme(QRgb(0xff707070), 2)); | |
|
22 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
|
23 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
24 | break; | |
|
25 | case QChart::ChartThemeVanilla: | |
|
26 | m_seriesThemes.append(SeriesTheme(QColor(217, 197, 116), 6)); | |
|
27 | m_seriesThemes.append(SeriesTheme(QColor(214, 168, 150), 4)); | |
|
28 | m_seriesThemes.append(SeriesTheme(QColor(160, 160, 113), 6)); | |
|
29 | m_seriesThemes.append(SeriesTheme(QColor(210, 210, 52), 4)); | |
|
30 | m_seriesThemes.append(SeriesTheme(QColor(136, 114, 58), 6)); | |
|
5 | //series | |
|
6 | #include "barchartseries.h" | |
|
7 | #include "stackedbarchartseries.h" | |
|
8 | #include "percentbarchartseries.h" | |
|
9 | #include "qxychartseries.h" | |
|
10 | //items | |
|
11 | #include "axisitem_p.h" | |
|
12 | #include "bargroup.h" | |
|
13 | #include "stackedbargroup.h" | |
|
14 | #include "xylinechartitem_p.h" | |
|
15 | #include "percentbargroup.h" | |
|
31 | 16 | |
|
32 | m_gradientStartColor = QColor(QRgb(0xff9d844d)); | |
|
33 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
34 | break; | |
|
35 | case QChart::ChartThemeIcy: | |
|
36 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF0D2673), 2)); | |
|
37 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF2685BF), 2)); | |
|
38 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF3DADD9), 3)); | |
|
39 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF62C3D9), 2)); | |
|
17 | //themes | |
|
18 | #include "chartthemevanilla_p.h" | |
|
19 | #include "chartthemeicy_p.h" | |
|
20 | #include "chartthemegrayscale_p.h" | |
|
21 | #include "chartthemescientific_p.h" | |
|
40 | 22 | |
|
41 | m_gradientStartColor = QColor(QRgb(0xffBDE3F2)); | |
|
42 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
43 | break; | |
|
44 | case QChart::ChartThemeGrayscale: | |
|
45 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF869299), 2)); | |
|
46 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFA5BDCC), 2)); | |
|
47 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFE8FFFC), 3)); | |
|
48 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFCCC2C2), 2)); | |
|
49 | 23 | |
|
50 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
|
51 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
52 | break; | |
|
53 | case QChart::ChartThemeScientific: | |
|
54 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF000000), 3)); | |
|
55 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFFFAD00), 2)); | |
|
56 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF596A75), 2)); | |
|
57 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF474747), 2)); | |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
58 | 25 | |
|
59 | m_gradientStartColor = QColor(QRgb(0xffafafaf)); | |
|
60 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
61 | break; | |
|
26 | /* TODO | |
|
62 | 27 | case QChart::ChartThemeUnnamed1: |
|
63 | 28 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
64 | 29 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
@@ -68,45 +33,110 void ChartThemeData::setTheme(int theme) | |||
|
68 | 33 |
|
|
69 | 34 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
70 | 35 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
36 | */ | |
|
37 | ||
|
38 | ChartTheme::ChartTheme() | |
|
39 | { | |
|
40 | m_seriesColor.append(QRgb(0xff000000)); | |
|
41 | m_seriesColor.append(QRgb(0xff707070)); | |
|
42 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
|
43 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
44 | } | |
|
45 | ||
|
46 | ||
|
47 | ChartTheme* ChartTheme::createTheme(QChart::ChartThemeId theme) | |
|
48 | { | |
|
49 | switch(theme) { | |
|
50 | case QChart::ChartThemeDefault: | |
|
51 | return new ChartTheme(); | |
|
52 | case QChart::ChartThemeVanilla: | |
|
53 | return new ChartThemeVanilla(); | |
|
54 | case QChart::ChartThemeIcy: | |
|
55 | return new ChartThemeIcy(); | |
|
56 | case QChart::ChartThemeGrayscale: | |
|
57 | return new ChartThemeGrayscale(); | |
|
58 | case QChart::ChartThemeScientific: | |
|
59 | return new ChartThemeScientific(); | |
|
60 | } | |
|
61 | } | |
|
62 | ||
|
63 | void ChartTheme::decorate(QChart* chart) | |
|
64 | { | |
|
65 | QLinearGradient backgroundGradient; | |
|
66 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); | |
|
67 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); | |
|
68 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
|
69 | chart->setChartBackgroundBrush(backgroundGradient); | |
|
70 | } | |
|
71 | //TODO helper to by removed later | |
|
72 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) | |
|
73 | { | |
|
74 | switch(series->type()) | |
|
75 | { | |
|
76 | case QChartSeries::SeriesTypeLine: { | |
|
77 | QXYChartSeries* s = static_cast<QXYChartSeries*>(series); | |
|
78 | XYLineChartItem* i = static_cast<XYLineChartItem*>(item); | |
|
79 | decorate(i,s,count); | |
|
80 | break; | |
|
81 | } | |
|
82 | case QChartSeries::SeriesTypeBar: { | |
|
83 | BarChartSeries* b = static_cast<BarChartSeries*>(series); | |
|
84 | BarGroup* i = static_cast<BarGroup*>(item); | |
|
85 | decorate(i,b,count); | |
|
86 | break; | |
|
87 | } | |
|
88 | case QChartSeries::SeriesTypeStackedBar: { | |
|
89 | StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series); | |
|
90 | StackedBarGroup* i = static_cast<StackedBarGroup*>(item); | |
|
91 | decorate(i,s,count); | |
|
92 | break; | |
|
93 | } | |
|
94 | case QChartSeries::SeriesTypePercentBar: { | |
|
95 | PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series); | |
|
96 | PercentBarGroup* i = static_cast<PercentBarGroup*>(item); | |
|
97 | decorate(i,s,count); | |
|
71 | 98 | break; |
|
99 | } | |
|
72 | 100 | default: |
|
73 | Q_ASSERT(false); | |
|
101 | qDebug()<<"Wrong item to be decorated by theme"; | |
|
74 | 102 | break; |
|
75 | 103 | } |
|
104 | ||
|
76 | 105 | } |
|
77 | 106 | |
|
78 | ChartTheme::ChartTheme(QObject *parent) : | |
|
79 | QObject(parent), | |
|
80 | d(new ChartThemeData()) | |
|
107 | void ChartTheme::decorate(XYLineChartItem* item, QXYChartSeries* series,int count) | |
|
81 | 108 | { |
|
82 | d->m_currentTheme = QChart::ChartThemeInvalid; | |
|
83 | d->m_seriesIndex = 0; | |
|
109 | item->setPen(series->pen()); | |
|
84 | 110 | } |
|
85 | 111 | |
|
86 | void ChartTheme::setTheme(int theme) | |
|
112 | void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) | |
|
87 | 113 | { |
|
88 | if (theme != d->m_currentTheme) { | |
|
89 | d->setTheme(theme); | |
|
90 | foreach (ChartThemeObserver *o, d->m_observers) | |
|
91 | o->themeChanged(this); | |
|
92 | } | |
|
114 | item->addColor(QColor(255,0,0,128)); | |
|
115 | item->addColor(QColor(255,255,0,128)); | |
|
116 | item->addColor(QColor(0,255,0,128)); | |
|
117 | item->addColor(QColor(0,0,255,128)); | |
|
118 | item->addColor(QColor(255,128,0,128)); | |
|
93 | 119 | } |
|
94 | 120 | |
|
95 | SeriesTheme ChartTheme::themeForSeries() | |
|
121 | void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) | |
|
96 | 122 | { |
|
97 | if (d->m_seriesThemes.count() == 0) { | |
|
98 | return SeriesTheme(); | |
|
99 | } else { | |
|
100 | // Get the next available theme for the series; if no more themes available start over | |
|
101 | // beginning from the first theme in the list | |
|
102 | SeriesTheme nextTheme = | |
|
103 | d->m_seriesThemes[d->m_seriesIndex % d->m_seriesThemes.count()]; | |
|
104 | d->m_seriesIndex++; | |
|
105 | return nextTheme; | |
|
106 | } | |
|
123 | // Add some fugly colors for 5 fist series... | |
|
124 | item->addColor(QColor(255,0,0,128)); | |
|
125 | item->addColor(QColor(255,255,0,128)); | |
|
126 | item->addColor(QColor(0,255,0,128)); | |
|
127 | item->addColor(QColor(0,0,255,128)); | |
|
128 | item->addColor(QColor(255,128,0,128)); | |
|
107 | 129 | } |
|
108 | 130 | |
|
131 | void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) | |
|
132 | { | |
|
133 | // Add some fugly colors for 5 fist series... | |
|
134 | item->addColor(QColor(255,0,0,128)); | |
|
135 | item->addColor(QColor(255,255,0,128)); | |
|
136 | item->addColor(QColor(0,255,0,128)); | |
|
137 | item->addColor(QColor(0,0,255,128)); | |
|
138 | item->addColor(QColor(255,128,0,128)); | |
|
139 | } | |
|
109 | 140 | |
|
110 | #include "moc_charttheme_p.cpp" | |
|
111 | 141 | |
|
112 | 142 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -2,81 +2,40 | |||
|
2 | 2 | #define CHARTTHEME_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | #include <QObject> | |
|
6 | #include <QSharedData> | |
|
5 | #include "qchart.h" | |
|
7 | 6 | #include <QColor> |
|
8 | #include <QLinearGradient> | |
|
9 | #include <QPen> | |
|
10 | 7 | |
|
11 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | 9 | |
|
13 |
class Chart |
|
|
14 | ||
|
15 | class ChartThemeObserver | |
|
16 | { | |
|
17 | public: | |
|
18 | virtual void themeChanged(ChartTheme *theme) = 0; | |
|
19 | }; | |
|
20 | ||
|
21 | /*! | |
|
22 | * The theme specific settings for the appearance of a series. TODO: These can be overridden by setting | |
|
23 | * custom settings to a QChartSeries object. | |
|
24 | */ | |
|
25 | struct SeriesTheme { | |
|
26 | public: | |
|
27 | SeriesTheme() : | |
|
28 | linePen(QPen()), | |
|
29 | markerPen(QPen()) {} | |
|
30 | SeriesTheme(QColor lineColor, qreal lineWidth/*, QPen marker*/) : | |
|
31 | linePen(QPen(QBrush(lineColor), lineWidth)), | |
|
32 | markerPen(linePen) {} | |
|
33 | ||
|
34 | //const QBrush & brush, qreal width, Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap, Qt::PenJoinStyle join = Qt::BevelJo | |
|
35 | // TODO: | |
|
36 | //QColor lineColor; | |
|
37 | QPen linePen; | |
|
38 | //QBrush lineBrush; | |
|
39 | QPen markerPen; | |
|
40 | //QBrush markerBrush; | |
|
41 | }; | |
|
42 | ||
|
43 | /*! | |
|
44 | * Explicitly shared data class for the themes. | |
|
45 | */ | |
|
46 | class ChartThemeData : public QSharedData | |
|
10 | class ChartItem; | |
|
11 | class QChartSeries; | |
|
12 | class XYLineChartItem; | |
|
13 | class QXYChartSeries; | |
|
14 | class BarGroup; | |
|
15 | class BarChartSeries; | |
|
16 | class StackedBarGroup; | |
|
17 | class StackedBarChartSeries; | |
|
18 | class PercentBarChartSeries; | |
|
19 | class PercentBarGroup; | |
|
20 | ||
|
21 | class ChartTheme | |
|
47 | 22 | { |
|
23 | protected: | |
|
24 | explicit ChartTheme(); | |
|
48 | 25 | public: |
|
49 | ChartThemeData() : m_currentTheme(0) {} | |
|
50 | ~ChartThemeData() {} | |
|
51 | ||
|
52 | public: | |
|
53 | void setTheme(int theme); | |
|
54 | ||
|
55 | public: | |
|
56 | int m_currentTheme; | |
|
57 | QList<ChartThemeObserver *> m_observers; | |
|
26 | static ChartTheme* createTheme(QChart::ChartThemeId theme); | |
|
27 | void decorate(QChart* chart); | |
|
28 | void decorate(ChartItem* item, QChartSeries* series,int count); | |
|
29 | void decorate(XYLineChartItem* item, QXYChartSeries*, int count); | |
|
30 | void decorate(BarGroup* item, BarChartSeries* series,int count); | |
|
31 | void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count); | |
|
32 | void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count); | |
|
33 | ||
|
34 | protected: | |
|
58 | 35 | QColor m_gradientStartColor; |
|
59 | 36 | QColor m_gradientEndColor; |
|
60 |
QList< |
|
|
61 | int m_seriesIndex; | |
|
62 | }; | |
|
37 | QList<QColor> m_seriesColor; | |
|
63 | 38 | |
|
64 | class ChartTheme : public QObject | |
|
65 | { | |
|
66 | Q_OBJECT | |
|
67 | public: | |
|
68 | explicit ChartTheme(QObject *parent = 0); | |
|
69 | explicit ChartTheme(const ChartTheme &other, QObject *parent = 0) : QObject(parent), d(other.d) {} | |
|
70 | void operator =(const ChartTheme &other) { d = other.d; } | |
|
71 | ||
|
72 | void setTheme(int theme); | |
|
73 | SeriesTheme themeForSeries(); | |
|
74 | void addObserver(ChartThemeObserver *o) { d->m_observers << o; } | |
|
75 | ||
|
76 | public: | |
|
77 | // All the graphical elements of a QChart share the same theme settings | |
|
78 | // so let's use explicitly shared data | |
|
79 | QExplicitlySharedDataPointer<ChartThemeData> d; | |
|
80 | 39 | }; |
|
81 | 40 | |
|
82 | 41 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -58,6 +58,7 void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option | |||
|
58 | 58 | QPieSlice data = (static_cast<PiePresentation*>(parentItem()))->m_pieSeries->slice(m_seriesIndex); |
|
59 | 59 | painter->setBrush(data.m_color); |
|
60 | 60 | |
|
61 | ||
|
61 | 62 | //painter->setBrush(m_theme.linePen.color()); |
|
62 | 63 | |
|
63 | 64 | // From Qt docs: |
@@ -27,6 +27,7 private: | |||
|
27 | 27 | int m_seriesIndex; |
|
28 | 28 | qreal m_startAngle; |
|
29 | 29 | qreal m_span; |
|
30 | QRectF m_rect; | |
|
30 | 31 | //SeriesTheme m_theme; |
|
31 | 32 | }; |
|
32 | 33 |
@@ -17,7 +17,6 | |||
|
17 | 17 | #include "percentbarchartseries.h" |
|
18 | 18 | #include "qxychartseries.h" |
|
19 | 19 | |
|
20 | ||
|
21 | 20 | #include <QGraphicsScene> |
|
22 | 21 | #include <QGraphicsSceneResizeEvent> |
|
23 | 22 | #include <QDebug> |
@@ -27,17 +26,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
27 | 26 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
28 | 27 |
|
|
29 | 28 |
|
|
30 | m_axisXItem(0), | |
|
31 | m_chartTheme(new ChartTheme(this)), | |
|
32 | //m_dataset(0), | |
|
33 | 29 |
|
|
34 | //m_presenter(0) | |
|
35 | 30 |
|
|
36 | 31 | { |
|
37 | // TODO: the default theme? | |
|
38 | setTheme(QChart::ChartThemeDefault); | |
|
39 | //m_chartItems << m_axisXItem; | |
|
40 | //m_chartItems << m_axisYItem.at(0); | |
|
41 | 32 | } |
|
42 | 33 | |
|
43 | 34 | QChart::~QChart(){} |
@@ -47,6 +38,7 void QChart::addSeries(QChartSeries* series) | |||
|
47 | 38 | m_dataset->addSeries(series); |
|
48 | 39 | } |
|
49 | 40 | |
|
41 | //TODO on review, is it really needed ?? | |
|
50 | 42 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
51 | 43 | { |
|
52 | 44 | // TODO: support also other types; not only scatter and pie |
@@ -130,32 +122,12 void QChart::setMargin(int margin) | |||
|
130 | 122 | |
|
131 | 123 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
132 | 124 | { |
|
133 |
m_ |
|
|
134 | ||
|
135 | QLinearGradient backgroundGradient; | |
|
136 | backgroundGradient.setColorAt(0.0, m_chartTheme->d->m_gradientStartColor); | |
|
137 | backgroundGradient.setColorAt(1.0, m_chartTheme->d->m_gradientEndColor); | |
|
138 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
|
139 | setChartBackgroundBrush(backgroundGradient); | |
|
140 | ||
|
141 | // TODO: Move the controlling of the series presentations into private implementation of the | |
|
142 | // series instead of QChart controlling themes for each | |
|
143 | // In other words, the following should be used when creating xy series: | |
|
144 | // m_chartTheme->addObserver(xyseries) | |
|
145 | foreach (QChartSeries *series, m_chartSeries) { | |
|
146 | if (series->type() == QChartSeries::SeriesTypeLine) { | |
|
147 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); | |
|
148 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); | |
|
149 | xyseries->setPen(seriesTheme.linePen); | |
|
150 | } | |
|
151 | } | |
|
152 | ||
|
153 | update(); | |
|
125 | m_presenter->setTheme(theme); | |
|
154 | 126 | } |
|
155 | 127 | |
|
156 | 128 | QChart::ChartThemeId QChart::theme() |
|
157 | 129 | { |
|
158 |
return (QChart::ChartThemeId) m_ |
|
|
130 | return (QChart::ChartThemeId) m_presenter->theme(); | |
|
159 | 131 | } |
|
160 | 132 | |
|
161 | 133 | void QChart::zoomInToRect(const QRectF& rectangle) |
@@ -180,11 +152,11 void QChart::zoomReset() | |||
|
180 | 152 | |
|
181 | 153 | void QChart::setAxisX(const QChartAxis& axis) |
|
182 | 154 | { |
|
183 | setAxis(m_axisXItem,axis); | |
|
155 | ||
|
184 | 156 | } |
|
185 | 157 | void QChart::setAxisY(const QChartAxis& axis) |
|
186 | 158 | { |
|
187 | setAxis(m_axisYItem.at(0),axis); | |
|
159 | ||
|
188 | 160 | } |
|
189 | 161 | |
|
190 | 162 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
@@ -194,7 +166,7 void QChart::setAxisY(const QList<QChartAxis>& axis) | |||
|
194 | 166 | |
|
195 | 167 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) |
|
196 | 168 | { |
|
197 | item->setVisible(axis.isAxisVisible()); | |
|
169 | ||
|
198 | 170 | } |
|
199 | 171 | |
|
200 | 172 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
@@ -218,8 +190,6 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |||
|
218 | 190 | update(); |
|
219 | 191 | } |
|
220 | 192 | |
|
221 | ||
|
222 | ||
|
223 | 193 | #include "moc_qchart.cpp" |
|
224 | 194 | |
|
225 | 195 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -41,7 +41,7 public: | |||
|
41 | 41 | ChartThemeIcy, |
|
42 | 42 | ChartThemeGrayscale, |
|
43 | 43 | ChartThemeScientific, |
|
44 | ChartThemeUnnamed1 | |
|
44 | //ChartThemeUnnamed1 | |
|
45 | 45 | }; |
|
46 | 46 | |
|
47 | 47 | public: |
@@ -82,14 +82,7 private: | |||
|
82 | 82 | Q_DISABLE_COPY(QChart) |
|
83 | 83 | QGraphicsRectItem* m_backgroundItem; |
|
84 | 84 | QGraphicsTextItem* m_titleItem; |
|
85 | AxisItem* m_axisXItem; | |
|
86 | QList<AxisItem*> m_axisYItem; | |
|
87 | 85 | QRectF m_rect; |
|
88 | QList<QChartSeries *> m_chartSeries; | |
|
89 | QList<ChartItem *> m_chartItems; | |
|
90 | ChartTheme *m_chartTheme; | |
|
91 | ||
|
92 | ||
|
93 | 86 | ChartDataSet *m_dataset; |
|
94 | 87 | ChartPresenter *m_presenter; |
|
95 | 88 | }; |
@@ -46,7 +46,7 void QScatterSeriesPrivate::setSize(const QSizeF &size) | |||
|
46 | 46 | |
|
47 | 47 | void QScatterSeriesPrivate::themeChanged(ChartTheme *theme) |
|
48 | 48 | { |
|
49 | m_theme = theme->themeForSeries(); | |
|
49 | //m_theme = theme->themeForSeries(); | |
|
50 | 50 | } |
|
51 | 51 | |
|
52 | 52 | void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain) |
@@ -73,7 +73,7 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsI | |||
|
73 | 73 | painter->setPen(pen); |
|
74 | 74 | } |
|
75 | 75 | else |
|
76 | painter->setPen(m_theme.markerPen); | |
|
76 | //painter->setPen(m_theme.markerPen); | |
|
77 | 77 | // brush.setColor(m_theme..lineColor); |
|
78 | 78 | |
|
79 | 79 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize |
@@ -12,7 +12,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
12 | 12 | /*! |
|
13 | 13 | * The PIMPL class of QScatterSeries. |
|
14 | 14 | */ |
|
15 |
class QScatterSeriesPrivate : public ChartItem |
|
|
15 | class QScatterSeriesPrivate : public ChartItem | |
|
16 | 16 | { |
|
17 | 17 | public: |
|
18 | 18 | QScatterSeriesPrivate(QGraphicsItem *parent); |
@@ -38,7 +38,7 public: | |||
|
38 | 38 | QList<qreal> m_scenex; |
|
39 | 39 | QList<qreal> m_sceney; |
|
40 | 40 | QColor m_markerColor; |
|
41 | SeriesTheme m_theme; | |
|
41 | //SeriesTheme m_theme; | |
|
42 | 42 | PlotDomain m_visibleChartArea; |
|
43 | 43 | }; |
|
44 | 44 |
@@ -78,12 +78,21 PUBLIC_HEADERS += \ | |||
|
78 | 78 | qchartview.h \ |
|
79 | 79 | qchartaxis.h |
|
80 | 80 | |
|
81 | THEMES += \ | |
|
82 | themes/chartthemeicy_p.h \ | |
|
83 | themes/chartthemegrayscale_p.h \ | |
|
84 | themes/chartthemescientific_p.h \ | |
|
85 | themes/chartthemevanilla_p.h \ | |
|
86 | ||
|
87 | ||
|
81 | 88 | HEADERS += $$PUBLIC_HEADERS |
|
82 | 89 | HEADERS += $$PRIVATE_HEADERS |
|
90 | HEADERS += $$THEMES | |
|
83 | 91 | |
|
84 | 92 | INCLUDEPATH += xylinechart \ |
|
85 | 93 | barchart \ |
|
86 | 94 | piechart \ |
|
95 | themes \ | |
|
87 | 96 | . |
|
88 | 97 | |
|
89 | 98 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
General Comments 0
You need to be logged in to leave comments.
Login now