@@ -63,6 +63,7 int main(int argc, char *argv[]) | |||
|
63 | 63 | QChartAxis* axisY = chartView->axisY(); |
|
64 | 64 | axisY->setLabelsAngle(45); |
|
65 | 65 | axisY->setShadesBrush(Qt::yellow); |
|
66 | axisY->setShadesVisible(true); | |
|
66 | 67 | axisY->setGridLineVisible(false); |
|
67 | 68 | |
|
68 | 69 | QChartAxisCategories* categoriesY = axisY->categories(); |
@@ -33,10 +33,11 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char | |||
|
33 | 33 | m_chartTheme(0), |
|
34 | 34 | m_zoomIndex(0), |
|
35 | 35 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
36 | m_options(QChart::NoAnimation) | |
|
36 | m_options(QChart::NoAnimation), | |
|
37 | m_themeForce(false) | |
|
37 | 38 | { |
|
38 | 39 | createConnections(); |
|
39 | setChartTheme(QChart::ChartThemeDefault); | |
|
40 | setChartTheme(QChart::ChartThemeDefault,false); | |
|
40 | 41 | } |
|
41 | 42 | |
|
42 | 43 | ChartPresenter::~ChartPresenter() |
@@ -94,14 +95,14 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |||
|
94 | 95 | } |
|
95 | 96 | |
|
96 | 97 | if(axis==m_dataset->axisX()){ |
|
97 | m_chartTheme->decorate(axis,true); | |
|
98 | m_chartTheme->decorate(axis,true,m_themeForce); | |
|
98 | 99 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
99 | 100 | //initialize |
|
100 | 101 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
101 | 102 | |
|
102 | 103 | } |
|
103 | 104 | else{ |
|
104 | m_chartTheme->decorate(axis,false); | |
|
105 | m_chartTheme->decorate(axis,false,m_themeForce); | |
|
105 | 106 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
106 | 107 | //initialize |
|
107 | 108 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
@@ -135,7 +136,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
135 | 136 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
136 | 137 | m_animator->addAnimation(line); |
|
137 | 138 | } |
|
138 | m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series)); | |
|
139 | m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce); | |
|
139 | 140 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); |
|
140 | 141 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
141 | 142 | item = line; |
@@ -150,7 +151,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
150 | 151 | m_animator->addAnimation(area->upperLineItem()); |
|
151 | 152 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); |
|
152 | 153 | } |
|
153 | m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series)); | |
|
154 | m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce); | |
|
154 | 155 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); |
|
155 | 156 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
156 | 157 | item=area; |
@@ -163,7 +164,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
163 | 164 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
164 | 165 | // m_animator->addAnimation(bar); |
|
165 | 166 | } |
|
166 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries)); | |
|
167 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); | |
|
167 | 168 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
168 | 169 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
169 | 170 | item=bar; |
@@ -176,7 +177,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
176 | 177 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
177 | 178 | // m_animator->addAnimation(bar); |
|
178 | 179 | } |
|
179 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries)); | |
|
180 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); | |
|
180 | 181 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
181 | 182 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
182 | 183 | item=bar; |
@@ -189,7 +190,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
189 | 190 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
190 | 191 | // m_animator->addAnimation(bar); |
|
191 | 192 | } |
|
192 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries)); | |
|
193 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); | |
|
193 | 194 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
194 | 195 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
195 | 196 | item=bar; |
@@ -202,7 +203,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
202 | 203 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
203 | 204 | m_animator->addAnimation(scatter); |
|
204 | 205 | } |
|
205 | m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series)); | |
|
206 | m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce); | |
|
206 | 207 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); |
|
207 | 208 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
208 | 209 | item = scatter; |
@@ -215,7 +216,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
215 | 216 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
216 | 217 | m_animator->addAnimation(pie); |
|
217 | 218 | } |
|
218 | m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series)); | |
|
219 | m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce); | |
|
219 | 220 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); |
|
220 | 221 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
221 | 222 | // Hide all from background when there is only piechart |
@@ -223,7 +224,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
223 | 224 | if (m_chartItems.count() == 0) { |
|
224 | 225 | m_chart->axisX()->hide(); |
|
225 | 226 | m_chart->axisY()->hide(); |
|
226 |
m_chart->set |
|
|
227 | m_chart->setBackgroundVisible(false); | |
|
227 | 228 | } |
|
228 | 229 | item=pie; |
|
229 | 230 | break; |
@@ -235,7 +236,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
235 | 236 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
236 | 237 | m_animator->addAnimation(spline); |
|
237 | 238 | } |
|
238 | m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series)); | |
|
239 | m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce); | |
|
239 | 240 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); |
|
240 | 241 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
241 | 242 | item=spline; |
@@ -271,13 +272,14 void ChartPresenter::handleSeriesRemoved(QSeries* series) | |||
|
271 | 272 | delete item; |
|
272 | 273 | } |
|
273 | 274 | |
|
274 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
|
275 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme,bool force) | |
|
275 | 276 | { |
|
276 | 277 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
277 | 278 | delete m_chartTheme; |
|
279 | m_themeForce = force; | |
|
278 | 280 | m_chartTheme = ChartTheme::createTheme(theme); |
|
279 | m_chartTheme->decorate(m_chart); | |
|
280 | m_chartTheme->decorate(m_chart->legend()); | |
|
281 | m_chartTheme->decorate(m_chart,m_themeForce); | |
|
282 | m_chartTheme->decorate(m_chart->legend(),m_themeForce); | |
|
281 | 283 | resetAllElements(); |
|
282 | 284 | } |
|
283 | 285 |
@@ -41,7 +41,7 public: | |||
|
41 | 41 | QRectF geometry() const; |
|
42 | 42 | ChartAnimator* animator() const {return m_animator;}; |
|
43 | 43 | |
|
44 | void setChartTheme(QChart::ChartTheme theme); | |
|
44 | void setChartTheme(QChart::ChartTheme theme,bool force = true); | |
|
45 | 45 | QChart::ChartTheme chartTheme(); |
|
46 | 46 | |
|
47 | 47 | void setAnimationOptions(QChart::AnimationOptions options); |
@@ -77,6 +77,7 private: | |||
|
77 | 77 | QVector<QRectF> m_zoomStack; |
|
78 | 78 | QRectF m_rect; |
|
79 | 79 | QChart::AnimationOptions m_options; |
|
80 | bool m_themeForce; | |
|
80 | 81 | |
|
81 | 82 | }; |
|
82 | 83 |
@@ -75,82 +75,110 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |||
|
75 | 75 | } |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | void ChartTheme::decorate(QChart* chart) | |
|
78 | void ChartTheme::decorate(QChart* chart,bool force) | |
|
79 | 79 | { |
|
80 | if (m_backgroundShades == BackgroundShadesNone) { | |
|
81 | chart->setChartBackgroundBrush(m_chartBackgroundGradient); | |
|
82 | } else { | |
|
83 |
|
|
|
80 | QPen pen; | |
|
81 | QBrush brush; | |
|
82 | ||
|
83 | if(brush == chart->backgroundBrush() || force) | |
|
84 | { | |
|
85 | if (m_backgroundShades == BackgroundShadesNone) { | |
|
86 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
|
87 | } | |
|
88 | else { | |
|
89 | chart->setBackgroundBrush(Qt::NoBrush); | |
|
90 | } | |
|
84 | 91 | } |
|
85 |
chart->set |
|
|
86 |
chart->set |
|
|
92 | chart->setTitleFont(m_masterFont); | |
|
93 | chart->setTitleBrush(m_titleBrush); | |
|
87 | 94 | } |
|
88 | 95 | |
|
89 | void ChartTheme::decorate(QLegend* legend) | |
|
96 | void ChartTheme::decorate(QLegend* legend,bool force) | |
|
90 | 97 | { |
|
91 | legend->setBackgroundBrush(m_chartBackgroundGradient); | |
|
98 | QPen pen; | |
|
99 | QBrush brush; | |
|
100 | ||
|
101 | if (pen == legend->pen() || force){ | |
|
102 | //TODO:: legend->setPen(); | |
|
103 | } | |
|
104 | ||
|
105 | ||
|
106 | if (brush == legend->brush() || force) { | |
|
107 | legend->setBrush(m_chartBackgroundGradient); | |
|
108 | } | |
|
92 | 109 | } |
|
93 | 110 | |
|
94 | void ChartTheme::decorate(QAreaSeries* series, int index) | |
|
111 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) | |
|
95 | 112 | { |
|
96 | 113 | QPen pen; |
|
97 | 114 | QBrush brush; |
|
98 | 115 | |
|
99 | if (pen == series->pen()){ | |
|
116 | if (pen == series->pen() || force){ | |
|
100 | 117 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
101 | 118 | pen.setWidthF(2); |
|
102 | 119 | series->setPen(pen); |
|
103 | 120 | } |
|
104 | 121 | |
|
105 | if (brush == series->brush()) { | |
|
122 | if (brush == series->brush() || force) { | |
|
106 | 123 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
107 | 124 | series->setBrush(brush); |
|
108 | 125 | } |
|
109 | 126 | } |
|
110 | 127 | |
|
111 | 128 | |
|
112 | void ChartTheme::decorate(QLineSeries* series,int index) | |
|
129 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) | |
|
113 | 130 | { |
|
114 | 131 | QPen pen; |
|
115 | if(pen == series->pen()){ | |
|
132 | if(pen == series->pen() || force ){ | |
|
116 | 133 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
117 | 134 | pen.setWidthF(2); |
|
118 | 135 | series->setPen(pen); |
|
119 | 136 | } |
|
120 | 137 | } |
|
121 | 138 | |
|
122 | void ChartTheme::decorate(QBarSeries* series,int index) | |
|
139 | void ChartTheme::decorate(QBarSeries* series,int index,bool force) | |
|
123 | 140 | { |
|
141 | QBrush brush; | |
|
124 | 142 | QList<QBarSet*> sets = series->barSets(); |
|
143 | ||
|
125 | 144 | for (int i=0; i<sets.count(); i++) { |
|
126 | 145 | qreal pos = 0.5; |
|
127 | 146 | if (sets.count() > 1) |
|
128 | 147 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
148 | ||
|
149 | if(brush == sets.at(i)->brush() || force ){ | |
|
129 | 150 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
130 | 151 | sets.at(i)->setBrush(QBrush(c)); |
|
131 | ||
|
152 | } | |
|
132 | 153 | // Pick label color as far as possible from bar color (within gradient). |
|
133 | 154 | // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) |
|
134 | 155 | // TODO: better picking of label color? |
|
156 | QColor c; | |
|
157 | ||
|
135 | 158 | if (pos < 0.3) { |
|
136 | 159 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
137 | 160 | } else { |
|
138 | 161 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
139 | 162 | } |
|
140 | 163 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
164 | ||
|
141 | 165 | } |
|
142 | 166 | } |
|
143 | 167 | |
|
144 | void ChartTheme::decorate(QStackedBarSeries* series,int index) | |
|
168 | void ChartTheme::decorate(QStackedBarSeries* series,int index,bool force) | |
|
145 | 169 | { |
|
170 | QBrush brush; | |
|
146 | 171 | QList<QBarSet*> sets = series->barSets(); |
|
172 | ||
|
147 | 173 | for (int i=0; i<sets.count(); i++) { |
|
148 | 174 | qreal pos = 0.5; |
|
149 | 175 | if (sets.count() > 1) |
|
150 | 176 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
177 | if(brush == sets.at(i)->brush() || force){ | |
|
151 | 178 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
152 | 179 | sets.at(i)->setBrush(QBrush(c)); |
|
153 | ||
|
180 | } | |
|
181 | QColor c; | |
|
154 | 182 | if (pos < 0.3) { |
|
155 | 183 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
156 | 184 | } else { |
@@ -160,16 +188,21 void ChartTheme::decorate(QStackedBarSeries* series,int index) | |||
|
160 | 188 | } |
|
161 | 189 | } |
|
162 | 190 | |
|
163 | void ChartTheme::decorate(QPercentBarSeries* series,int index) | |
|
191 | void ChartTheme::decorate(QPercentBarSeries* series,int index,bool force) | |
|
164 | 192 | { |
|
193 | QBrush brush; | |
|
165 | 194 | QList<QBarSet*> sets = series->barSets(); |
|
195 | ||
|
166 | 196 | for (int i=0; i<sets.count(); i++) { |
|
167 | 197 | qreal pos = 0.5; |
|
168 | 198 | if (sets.count() > 1) |
|
169 | 199 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
200 | ||
|
201 | if(brush == sets.at(i)->brush() || force){ | |
|
170 | 202 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
171 | 203 | sets.at(i)->setBrush(QBrush(c)); |
|
172 | ||
|
204 | } | |
|
205 | QColor c; | |
|
173 | 206 | if (pos < 0.3) { |
|
174 | 207 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
175 | 208 | } else { |
@@ -179,64 +212,99 void ChartTheme::decorate(QPercentBarSeries* series,int index) | |||
|
179 | 212 | } |
|
180 | 213 | } |
|
181 | 214 | |
|
182 | void ChartTheme::decorate(QScatterSeries* series, int index) | |
|
215 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) | |
|
183 | 216 | { |
|
184 | 217 | |
|
185 | 218 | QPen pen; |
|
186 | 219 | QBrush brush; |
|
187 | 220 | |
|
188 | if (pen == series->pen()) { | |
|
221 | if (pen == series->pen() || force) { | |
|
189 | 222 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
190 | 223 | pen.setWidthF(2); |
|
191 | 224 | series->setPen(pen); |
|
192 | 225 | } |
|
193 | 226 | |
|
194 | if (brush == series->brush()) { | |
|
227 | if (brush == series->brush() || force) { | |
|
195 | 228 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
196 | 229 | series->setBrush(brush); |
|
197 | 230 | } |
|
198 | 231 | } |
|
199 | 232 | |
|
200 | void ChartTheme::decorate(QPieSeries* series, int index) | |
|
233 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) | |
|
201 | 234 | { |
|
202 | 235 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
236 | ||
|
237 | QPen pen; | |
|
238 | QBrush brush; | |
|
239 | ||
|
203 | 240 | for (int i(0); i < series->slices().count(); i++) { |
|
204 | 241 | qreal pos = (qreal) i / (qreal) series->count(); |
|
242 | if( pen == series->slices().at(i)->slicePen() || force){ | |
|
205 | 243 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); |
|
206 | 244 | series->slices().at(i)->setSlicePen(penColor); |
|
245 | } | |
|
246 | if( brush == series->slices().at(i)->sliceBrush() || force){ | |
|
207 | 247 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
208 | 248 | series->slices().at(i)->setSliceBrush(brushColor); |
|
249 | } | |
|
209 | 250 | } |
|
210 | 251 | } |
|
211 | 252 | |
|
212 | void ChartTheme::decorate(QSplineSeries* series, int index) | |
|
253 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) | |
|
213 | 254 | { |
|
214 | 255 | QPen pen; |
|
215 | if(pen == series->pen()){ | |
|
256 | if(pen == series->pen() || force){ | |
|
216 | 257 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
217 | 258 | pen.setWidthF(2); |
|
218 | 259 | series->setPen(pen); |
|
219 | 260 | } |
|
220 | 261 | } |
|
221 | 262 | |
|
222 | void ChartTheme::decorate(QChartAxis* axis,bool axisX) | |
|
263 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) | |
|
223 | 264 | { |
|
265 | QPen pen; | |
|
266 | QBrush brush; | |
|
267 | QFont font; | |
|
268 | ||
|
224 | 269 | if (axis->isAxisVisible()) { |
|
225 | axis->setLabelsBrush(m_axisLabelBrush); | |
|
226 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
|
227 | if (m_backgroundShades == BackgroundShadesBoth | |
|
228 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
|
229 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) { | |
|
230 | axis->setShadesPen(m_backgroundShadesPen); | |
|
231 | axis->setShadesBrush(m_backgroundShadesBrush); | |
|
232 | } else { | |
|
233 | // The shades not supposed to be shown for this axis, clear possible brush and pen | |
|
234 | axis->setShadesPen(Qt::NoPen); | |
|
235 | axis->setShadesBrush(Qt::NoBrush); | |
|
270 | ||
|
271 | if(brush == axis->labelsBrush() || force){ | |
|
272 | axis->setLabelsBrush(m_axisLabelBrush); | |
|
273 | } | |
|
274 | if(pen == axis->labelsPen() || force){ | |
|
275 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
|
276 | } | |
|
277 | ||
|
278 | ||
|
279 | if (axis->shadesVisible() || force) { | |
|
280 | ||
|
281 | if(brush == axis->shadesBrush() || force){ | |
|
282 | axis->setShadesBrush(m_backgroundShadesBrush); | |
|
283 | } | |
|
284 | ||
|
285 | if(pen == axis->shadesPen() || force){ | |
|
286 | axis->setShadesPen(m_backgroundShadesPen); | |
|
287 | } | |
|
288 | ||
|
289 | if(force && (m_backgroundShades == BackgroundShadesBoth | |
|
290 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
|
291 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
|
292 | axis->setShadesVisible(true); | |
|
293 | ||
|
294 | } | |
|
295 | } | |
|
296 | ||
|
297 | if(pen == axis->axisPen() || force){ | |
|
298 | axis->setAxisPen(m_axisLinePen); | |
|
299 | } | |
|
300 | ||
|
301 | if(pen == axis->gridLinePen() || force){ | |
|
302 | axis->setGridLinePen(m_gridLinePen); | |
|
303 | } | |
|
304 | ||
|
305 | if(font == axis->labelsFont() || force){ | |
|
306 | axis->setLabelsFont(m_masterFont); | |
|
236 | 307 | } |
|
237 | axis->setAxisPen(m_axisLinePen); | |
|
238 | axis->setGridLinePen(m_gridLinePen); | |
|
239 | axis->setLabelsFont(m_masterFont); | |
|
240 | 308 | } |
|
241 | 309 | } |
|
242 | 310 |
@@ -42,18 +42,18 protected: | |||
|
42 | 42 | public: |
|
43 | 43 | static ChartTheme* createTheme(QChart::ChartTheme theme); |
|
44 | 44 | QChart::ChartTheme id() const {return m_id;} |
|
45 | void decorate(QChart* chart); | |
|
46 | void decorate(QLegend* legend); | |
|
45 | void decorate(QChart* chart,bool force = true); | |
|
46 | void decorate(QLegend* legend,bool force = true); | |
|
47 | 47 | //void decorate(ChartItem* item, QSeries* series,int index); |
|
48 | void decorate(QBarSeries* series, int index); | |
|
49 | void decorate(QStackedBarSeries* series, int index); | |
|
50 | void decorate(QPercentBarSeries* series, int index); | |
|
51 | void decorate(QLineSeries* series, int index); | |
|
52 | void decorate(QAreaSeries* series, int index); | |
|
53 | void decorate(QScatterSeries* series, int index); | |
|
54 | void decorate(QPieSeries* series, int index); | |
|
55 | void decorate(QSplineSeries* series, int index); | |
|
56 | void decorate(QChartAxis* axis, bool axisX); | |
|
48 | void decorate(QBarSeries* series, int index,bool force = true); | |
|
49 | void decorate(QStackedBarSeries* series, int index,bool force = true); | |
|
50 | void decorate(QPercentBarSeries* series, int index,bool force = true); | |
|
51 | void decorate(QLineSeries* series, int index,bool force = true); | |
|
52 | void decorate(QAreaSeries* series, int index,bool force = true); | |
|
53 | void decorate(QScatterSeries* series, int index,bool force = true); | |
|
54 | void decorate(QPieSeries* series, int index,bool force = true); | |
|
55 | void decorate(QSplineSeries* series, int index,bool force = true); | |
|
56 | void decorate(QChartAxis* axis, bool axisX,bool force = true); | |
|
57 | 57 | |
|
58 | 58 | public: // utils |
|
59 | 59 | void generateSeriesGradients(); |
@@ -104,27 +104,39 void QChart::removeAllSeries() | |||
|
104 | 104 | /*! |
|
105 | 105 | Sets the \a brush that is used for painting the background of the chart area. |
|
106 | 106 | */ |
|
107 |
void QChart::set |
|
|
107 | void QChart::setBackgroundBrush(const QBrush& brush) | |
|
108 | 108 | { |
|
109 | 109 | createChartBackgroundItem(); |
|
110 | 110 | m_backgroundItem->setBrush(brush); |
|
111 | 111 | m_backgroundItem->update(); |
|
112 | 112 | } |
|
113 | 113 | |
|
114 | QBrush QChart::backgroundBrush() const | |
|
115 | { | |
|
116 | if(!m_backgroundItem) return QBrush(); | |
|
117 | return m_backgroundItem->brush(); | |
|
118 | } | |
|
119 | ||
|
114 | 120 | /*! |
|
115 | 121 | Sets the \a pen that is used for painting the background of the chart area. |
|
116 | 122 | */ |
|
117 |
void QChart::set |
|
|
123 | void QChart::setBackgroundPen(const QPen& pen) | |
|
118 | 124 | { |
|
119 | 125 | createChartBackgroundItem(); |
|
120 | 126 | m_backgroundItem->setPen(pen); |
|
121 | 127 | m_backgroundItem->update(); |
|
122 | 128 | } |
|
123 | 129 | |
|
130 | QPen QChart::backgroundPen() const | |
|
131 | { | |
|
132 | if(!m_backgroundItem) return QPen(); | |
|
133 | return m_backgroundItem->pen(); | |
|
134 | } | |
|
135 | ||
|
124 | 136 | /*! |
|
125 | 137 | Sets the chart \a title. The description text that is drawn above the chart. |
|
126 | 138 | */ |
|
127 |
void QChart::set |
|
|
139 | void QChart::setTitle(const QString& title) | |
|
128 | 140 | { |
|
129 | 141 | createChartTitleItem(); |
|
130 | 142 | m_titleItem->setText(title); |
@@ -134,7 +146,7 void QChart::setChartTitle(const QString& title) | |||
|
134 | 146 | /*! |
|
135 | 147 | Returns the chart title. The description text that is drawn above the chart. |
|
136 | 148 | */ |
|
137 |
QString QChart:: |
|
|
149 | QString QChart::title() const | |
|
138 | 150 | { |
|
139 | 151 | if(m_titleItem) |
|
140 | 152 | return m_titleItem->text(); |
@@ -145,7 +157,7 QString QChart::chartTitle() const | |||
|
145 | 157 | /*! |
|
146 | 158 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
147 | 159 | */ |
|
148 |
void QChart::set |
|
|
160 | void QChart::setTitleFont(const QFont& font) | |
|
149 | 161 | { |
|
150 | 162 | createChartTitleItem(); |
|
151 | 163 | m_titleItem->setFont(font); |
@@ -155,7 +167,7 void QChart::setChartTitleFont(const QFont& font) | |||
|
155 | 167 | /*! |
|
156 | 168 | Sets the \a brush used for rendering the title text. |
|
157 | 169 | */ |
|
158 |
void QChart::set |
|
|
170 | void QChart::setTitleBrush(const QBrush &brush) | |
|
159 | 171 | { |
|
160 | 172 | createChartTitleItem(); |
|
161 | 173 | m_titleItem->setBrush(brush); |
@@ -165,9 +177,9 void QChart::setChartTitleBrush(const QBrush &brush) | |||
|
165 | 177 | /*! |
|
166 | 178 | Returns the brush used for rendering the title text. |
|
167 | 179 | */ |
|
168 |
QBrush QChart:: |
|
|
180 | QBrush QChart::titleBrush() const | |
|
169 | 181 | { |
|
170 | createChartTitleItem(); | |
|
182 | if(!m_titleItem) return QBrush(); | |
|
171 | 183 | return m_titleItem->brush(); |
|
172 | 184 | } |
|
173 | 185 | |
@@ -365,6 +377,19 void QChart::setBackgroundDiameter(int diameter) | |||
|
365 | 377 | m_backgroundItem->update(); |
|
366 | 378 | } |
|
367 | 379 | |
|
380 | void QChart::setBackgroundVisible(bool visible) | |
|
381 | { | |
|
382 | createChartBackgroundItem(); | |
|
383 | m_backgroundItem->setVisible(visible); | |
|
384 | } | |
|
385 | ||
|
386 | bool QChart::isBackgroundVisible() const | |
|
387 | { | |
|
388 | if(!m_backgroundItem) return false; | |
|
389 | return m_backgroundItem->isVisible(); | |
|
390 | } | |
|
391 | ||
|
392 | ||
|
368 | 393 | #include "moc_qchart.cpp" |
|
369 | 394 | |
|
370 | 395 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -58,13 +58,19 public: | |||
|
58 | 58 | void setChartTheme(QChart::ChartTheme theme); |
|
59 | 59 | QChart::ChartTheme chartTheme() const; |
|
60 | 60 | |
|
61 |
void set |
|
|
62 |
QString |
|
|
63 |
void set |
|
|
64 | void setChartTitleBrush(const QBrush &brush); | |
|
65 | QBrush chartTitleBrush(); | |
|
66 | void setChartBackgroundBrush(const QBrush& brush); | |
|
67 |
void set |
|
|
61 | void setTitle(const QString& title); | |
|
62 | QString title() const; | |
|
63 | void setTitleFont(const QFont& font); | |
|
64 | QFont titleFont() const; | |
|
65 | void setTitleBrush(const QBrush &brush); | |
|
66 | QBrush titleBrush() const; | |
|
67 | void setBackgroundBrush(const QBrush& brush); | |
|
68 | QBrush backgroundBrush() const; | |
|
69 | void setBackgroundPen(const QPen& pen); | |
|
70 | QPen backgroundPen() const; | |
|
71 | ||
|
72 | void setBackgroundVisible(bool visible); | |
|
73 | bool isBackgroundVisible() const; | |
|
68 | 74 | |
|
69 | 75 | void setAnimationOptions(AnimationOptions options); |
|
70 | 76 | AnimationOptions animationOptions() const; |
@@ -129,7 +129,7 void QChartView::zoomOut() | |||
|
129 | 129 | */ |
|
130 | 130 | void QChartView::setChartTitle(const QString& title) |
|
131 | 131 | { |
|
132 |
m_chart->set |
|
|
132 | m_chart->setTitle(title); | |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | /*! |
@@ -137,7 +137,7 void QChartView::setChartTitle(const QString& title) | |||
|
137 | 137 | */ |
|
138 | 138 | QString QChartView::chartTitle() const |
|
139 | 139 | { |
|
140 |
return m_chart-> |
|
|
140 | return m_chart->title(); | |
|
141 | 141 | } |
|
142 | 142 | |
|
143 | 143 | /*! |
@@ -145,7 +145,7 QString QChartView::chartTitle() const | |||
|
145 | 145 | */ |
|
146 | 146 | void QChartView::setChartTitleFont(const QFont& font) |
|
147 | 147 | { |
|
148 |
m_chart->set |
|
|
148 | m_chart->setTitleFont(font); | |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | /*! |
@@ -153,7 +153,7 void QChartView::setChartTitleFont(const QFont& font) | |||
|
153 | 153 | */ |
|
154 | 154 | void QChartView::setChartTitleBrush(const QBrush &brush) |
|
155 | 155 | { |
|
156 |
m_chart->set |
|
|
156 | m_chart->setTitleBrush(brush); | |
|
157 | 157 | } |
|
158 | 158 | |
|
159 | 159 | /*! |
@@ -161,7 +161,7 void QChartView::setChartTitleBrush(const QBrush &brush) | |||
|
161 | 161 | */ |
|
162 | 162 | QBrush QChartView::chartTitleBrush() |
|
163 | 163 | { |
|
164 |
return m_chart-> |
|
|
164 | return m_chart->titleBrush(); | |
|
165 | 165 | } |
|
166 | 166 | |
|
167 | 167 | /*! |
@@ -169,7 +169,7 QBrush QChartView::chartTitleBrush() | |||
|
169 | 169 | */ |
|
170 | 170 | void QChartView::setChartBackgroundBrush(const QBrush& brush) |
|
171 | 171 | { |
|
172 |
m_chart->set |
|
|
172 | m_chart->setBackgroundBrush(brush); | |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | /*! |
@@ -177,7 +177,7 void QChartView::setChartBackgroundBrush(const QBrush& brush) | |||
|
177 | 177 | */ |
|
178 | 178 | void QChartView::setChartBackgroundPen(const QPen& pen) |
|
179 | 179 | { |
|
180 |
m_chart->set |
|
|
180 | m_chart->setBackgroundPen(pen); | |
|
181 | 181 | } |
|
182 | 182 | |
|
183 | 183 | /*! |
@@ -27,7 +27,7 QLegend::QLegend(QGraphicsItem *parent) | |||
|
27 | 27 | ,mSize(0,0) |
|
28 | 28 | ,mMinimumSize(50,20) // TODO: magic numbers |
|
29 | 29 | ,mMaximumSize(150,100) |
|
30 |
,m |
|
|
30 | ,m_brush(Qt::darkGray) // TODO: from theme? | |
|
31 | 31 | ,mPreferredLayout(QLegend::PreferredLayoutVertical) |
|
32 | 32 | { |
|
33 | 33 | // setVisible(false); |
@@ -40,7 +40,8 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q | |||
|
40 | 40 | Q_UNUSED(widget) |
|
41 | 41 | |
|
42 | 42 | painter->setOpacity(0.5); |
|
43 |
painter->set |
|
|
43 | painter->setPen(m_pen); | |
|
44 | painter->setBrush(m_brush); | |
|
44 | 45 | painter->drawRect(boundingRect()); |
|
45 | 46 | } |
|
46 | 47 | |
@@ -49,14 +50,30 QRectF QLegend::boundingRect() const | |||
|
49 | 50 | return QRectF(mPos,mSize); |
|
50 | 51 | } |
|
51 | 52 | |
|
52 |
void QLegend::setB |
|
|
53 | void QLegend::setBrush(const QBrush& brush) | |
|
53 | 54 | { |
|
54 | mBackgroundBrush = brush; | |
|
55 | if(m_brush!=brush){ | |
|
56 | m_brush = brush; | |
|
57 | update(); | |
|
58 | } | |
|
59 | } | |
|
60 | ||
|
61 | QBrush QLegend::brush() const | |
|
62 | { | |
|
63 | return m_brush; | |
|
64 | } | |
|
65 | ||
|
66 | void QLegend::setPen(const QPen& pen) | |
|
67 | { | |
|
68 | if(m_pen!=pen){ | |
|
69 | m_pen = pen; | |
|
70 | update(); | |
|
71 | } | |
|
55 | 72 | } |
|
56 | 73 | |
|
57 |
Q |
|
|
74 | QPen QLegend::pen() const | |
|
58 | 75 | { |
|
59 |
return m |
|
|
76 | return m_pen; | |
|
60 | 77 | } |
|
61 | 78 | |
|
62 | 79 | void QLegend::setPreferredLayout(QLegend::PreferredLayout preferred) |
@@ -30,8 +30,11 public: | |||
|
30 | 30 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
31 | 31 | QRectF boundingRect() const; |
|
32 | 32 | |
|
33 |
void setB |
|
|
34 |
QBrush b |
|
|
33 | void setBrush(const QBrush& brush); | |
|
34 | QBrush brush() const; | |
|
35 | ||
|
36 | void setPen(const QPen& pen); | |
|
37 | QPen pen() const; | |
|
35 | 38 | |
|
36 | 39 | void setPreferredLayout(QLegend::PreferredLayout preferred); |
|
37 | 40 | |
@@ -74,7 +77,8 private: | |||
|
74 | 77 | // QList<QSeries*> mSeriesList; |
|
75 | 78 | QList<LegendMarker*> mMarkers; |
|
76 | 79 | |
|
77 |
QBrush m |
|
|
80 | QBrush m_brush; | |
|
81 | QPen m_pen; | |
|
78 | 82 | QLegend::PreferredLayout mPreferredLayout; |
|
79 | 83 | }; |
|
80 | 84 |
General Comments 0
You need to be logged in to leave comments.
Login now