##// END OF EJS Templates
Fixes wrong shades zvalues
Michal Klocek -
r184:2e4df5890251
parent child
Show More
@@ -1,56 +1,56
1 1 #include <QApplication>
2 2 #include <QMainWindow>
3 3 #include <qchartview.h>
4 4 #include <qlinechartseries.h>
5 5 #include <qchart.h>
6 6 #include <qchartaxis.h>
7 7 #include <cmath>
8 8
9 9 QTCOMMERCIALCHART_USE_NAMESPACE
10 10
11 11 #define PI 3.14159265358979
12 12
13 13 int main(int argc, char *argv[])
14 14 {
15 15 QApplication a(argc, argv);
16 16
17 17 QMainWindow window;
18 18
19 19 QLineChartSeries* series0 = new QLineChartSeries();
20 20 QPen blue(Qt::blue);
21 21 blue.setWidth(3);
22 22 series0->setPen(blue);
23 23 QLineChartSeries* series1 = new QLineChartSeries();
24 24 QPen red(Qt::red);
25 25 red.setWidth(3);
26 26 series1->setPen(red);
27 27
28 28 int numPoints = 100;
29 29
30 30 for (int x = 0; x <= numPoints; ++x) {
31 31 series0->add(x, fabs(sin(PI/50*x)*100));
32 32 series1->add(x, fabs(cos(PI/50*x)*100));
33 33 }
34 34
35 35 QChartView* chartView = new QChartView(&window);
36 36
37 37 chartView->setRenderHint(QPainter::Antialiasing);
38 38 chartView->setTitle("Basic line chart example");
39 39 chartView->addSeries(series0);
40 40 chartView->addSeries(series1);
41 41 chartView->setChartBackgroundBrush(Qt::white);
42 42
43 43 QChartAxis axis = chartView->defaultAxisX();
44 44 axis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide);
45 45 axis.setGridPen(Qt::DashLine);
46 46
47 47 chartView->setDefaultAxisX(axis);
48 //axis.setShadesBrush(Qt::gray);
48 axis.setShadesBrush(Qt::gray);
49 49 chartView->setDefaultAxisY(axis);
50 50
51 51 window.setCentralWidget(chartView);
52 52 window.resize(400, 300);
53 53 window.show();
54 54
55 55 return a.exec();
56 56 }
@@ -1,289 +1,318
1 1 #include "axisitem_p.h"
2 2 #include "qchartaxis.h"
3 3 #include <QPainter>
4 4 #include <QDebug>
5 5
6 6 static int label_padding = 5;
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) :
11 11 ChartItem(parent),
12 12 m_ticks(4),
13 13 m_type(type),
14 14 m_labelsAngle(0),
15 15 m_shadesEnabled(true),
16 m_grid(this),
17 m_shades(this),
18 m_labels(this)
16 m_grid(parent),
17 m_shades(parent),
18 m_labels(parent)
19 19 {
20 20 //initial initialization
21 m_shades.setZValue(0);
22 m_grid.setZValue(2);
21 23 createItems();
22 24 }
23 25
24 26 AxisItem::~AxisItem()
25 27 {
26 28 }
27 29
28 30 QRectF AxisItem::boundingRect() const
29 31 {
30 32 return m_rect;
31 33 }
32 34
33 35 void AxisItem::createItems()
34 36 {
35 37 for (int i = 0; i <= m_ticks; ++i) {
36 38 m_grid.addToGroup(new QGraphicsLineItem(this));
37 39 m_labels.addToGroup(new QGraphicsSimpleTextItem(this));
38 40 if(i%2) m_shades.addToGroup(new QGraphicsRectItem(this));
39 41 }
40 42 }
41 43
42 44 void AxisItem::clear()
43 45 {
44 46 foreach(QGraphicsItem* item , m_shades.childItems()) {
45 47 delete item;
46 48 }
47 49
48 50 foreach(QGraphicsItem* item , m_grid.childItems()) {
49 51 delete item;
50 52 }
51 53
52 54 foreach(QGraphicsItem* item , m_labels.childItems()) {
53 55 delete item;
54 56 }
55 57
56 58 }
57 59
58 60 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
59 61 {
60 62
61 63 }
62 64
63 65 void AxisItem::updateDomain()
64 66 {
65 67
66 68 QList<QGraphicsItem *> lines = m_grid.childItems();
67 69 QList<QGraphicsItem *> labels = m_labels.childItems();
68 70 QList<QGraphicsItem *> shades = m_shades.childItems();
69 71
70 72 switch (m_type)
71 73 {
72 74 case X_AXIS:
73 75 {
74 76 const qreal deltaX = m_rect.width() / m_ticks;
75 77
78 m_axis.setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
79
76 80 for (int i = 0; i <= m_ticks; ++i) {
77 81
78 82 int x = i * deltaX + m_rect.left();
79 83
80 84 qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks);
81 85
82 86 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
83 87 lineItem->setLine(x, m_rect.top(), x, m_rect.bottom());
84 88
85 89 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
86 90 labelItem->setText(QString::number(label));
87 91 QPointF center = labelItem->boundingRect().center();
88 92 labelItem->setTransformOriginPoint(center.x(), center.y());
89 93 labelItem->setPos(x - center.x(), m_rect.bottom() + label_padding);
90 94
91 95 if(i%2){
92 96 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
93 97 rectItem->setRect(x,m_rect.top(),deltaX,m_rect.height());
94 98 }
95 99 }
96 100 }
97 101 break;
98 102
99 103 case Y_AXIS:
100 104 {
101 105 const qreal deltaY = m_rect.height()/ m_ticks;
102 106
107 m_axis.setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
108
103 109 for (int i = 0; i <= m_ticks; ++i) {
104 110
105 111 int y = i * -deltaY + m_rect.bottom();
106 112
107 113 qreal label = m_domain.m_minY + (i * m_domain.spanY()/ m_ticks);
108 114
109 115 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
110 116 lineItem->setLine(m_rect.left() , y, m_rect.right(), y);
111 117
112 118 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
113 119 labelItem->setText(QString::number(label));
114 120 QPointF center = labelItem->boundingRect().center();
115 121 labelItem->setTransformOriginPoint(center.x(), center.y());
116 122 labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , y-center.y());
117 123
118 124
119 125 if(i%2){
120 126 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
121 127 rectItem->setRect(m_rect.left(),y,m_rect.width(),deltaY);
122 128 }
123 129 }
124 130 }
125 131 break;
126 132 default:
127 133 qDebug()<<"Unknown axis type";
128 134 break;
129 135 }
130 136 }
131 137
132 138 void AxisItem::handleAxisChanged(const QChartAxis& axis)
133 139 {
140 if(axis.isAxisVisible()) {
141 setAxisOpacity(100);
142 }
143 else {
144 setAxisOpacity(0);
145 }
146
134 147 if(axis.isGridVisible()) {
135 148 setGridOpacity(100);
136 149 }
137 150 else {
138 151 setGridOpacity(0);
139 152 }
140 153
141 154 if(axis.isLabelsVisible())
142 155 {
143 156 setLabelsOpacity(100);
144 157 }
145 158 else {
146 159 setLabelsOpacity(0);
147 160 }
148 161
149 162 if(axis.isShadesVisible()) {
150 163 setShadesOpacity(100);
151 164 }
152 165 else {
153 166 setShadesOpacity(0);
154 167 }
155 168
156 169 switch(axis.labelsOrientation())
157 170 {
158 171 case QChartAxis::LabelsOrientationHorizontal:
159 172 setLabelsAngle(0);
160 173 break;
161 174 case QChartAxis::LabelsOrientationVertical:
162 175 setLabelsAngle(90);
163 176 break;
164 177 case QChartAxis::LabelsOrientationSlide:
165 178 setLabelsAngle(-45);
166 179 break;
167 180 default:
168 181 break;
169 182 }
170 183
184 setAxisPen(axis.axisPen());
171 185 setLabelsPen(axis.labelsPen());
172 186 setLabelsBrush(axis.labelsBrush());
173 187 setLabelsFont(axis.labelFont());
174 188 setGridPen(axis.gridPen());
175 189 setShadesPen(axis.shadesPen());
176 190 setShadesBrush(axis.shadesBrush());
177 191
178 192 }
179 193
180 194 void AxisItem::handleDomainChanged(const Domain& domain)
181 195 {
182 196 m_domain = domain;
183 197 updateDomain();
184 198 update();
185 199 }
186 200
187 201 void AxisItem::handleGeometryChanged(const QRectF& rect)
188 202 {
189 203 m_rect = rect;
190 204 updateDomain();
191 205 update();
192 206 }
193 207
208 void AxisItem::setAxisOpacity(qreal opacity)
209 {
210 m_axis.setOpacity(opacity);
211 }
212
213 qreal AxisItem::axisOpacity() const
214 {
215 return m_axis.opacity();
216 }
217
194 218 void AxisItem::setGridOpacity(qreal opacity)
195 219 {
196 220 m_grid.setOpacity(opacity);
197 221 }
198 222
199 223
200 224 qreal AxisItem::gridOpacity() const
201 225 {
202 226 return m_grid.opacity();
203 227 }
204 228
205 229 void AxisItem::setLabelsOpacity(qreal opacity)
206 230 {
207 231 m_labels.setOpacity(opacity);
208 232 }
209 233
210 234 qreal AxisItem::labelsOpacity() const
211 235 {
212 236 return m_labels.opacity();
213 237 }
214 238
215 239 void AxisItem::setShadesOpacity(qreal opacity)
216 240 {
217 241 m_shades.setOpacity(opacity);
218 242 }
219 243
220 244 qreal AxisItem::shadesOpacity() const
221 245 {
222 246 return m_shades.opacity();
223 247 }
224 248
225 249 void AxisItem::setLabelsAngle(int angle)
226 250 {
227 251 foreach(QGraphicsItem* item , m_labels.childItems()) {
228 252 QPointF center = item->boundingRect().center();
229 253 item->setRotation(angle);
230 254 }
231 255
232 256 m_labelsAngle=angle;
233 257 }
234 258
235 259 void AxisItem::setLabelsPen(const QPen& pen)
236 260 {
237 261 foreach(QGraphicsItem* item , m_labels.childItems()) {
238 262 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
239 263 }
240 264 }
241 265
242 266 void AxisItem::setLabelsBrush(const QBrush& brush)
243 267 {
244 268 foreach(QGraphicsItem* item , m_labels.childItems()) {
245 269 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
246 270 }
247 271 }
248 272
249 273 void AxisItem::setLabelsFont(const QFont& font)
250 274 {
251 275 foreach(QGraphicsItem* item , m_labels.childItems()) {
252 276 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
253 277 }
254 278 }
255 279
256 280 void AxisItem::setShadesBrush(const QBrush& brush)
257 281 {
258 282 foreach(QGraphicsItem* item , m_shades.childItems()) {
259 283 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
260 284 }
261 285 }
262 286
263 287 void AxisItem::setShadesPen(const QPen& pen)
264 288 {
265 289 foreach(QGraphicsItem* item , m_shades.childItems()) {
266 290 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
267 291 }
268 292 }
269 293
294 void AxisItem::setAxisPen(const QPen& pen)
295 {
296 m_axis.setPen(pen);
297 }
298
270 299 void AxisItem::setGridPen(const QPen& pen)
271 300 {
272 301 foreach(QGraphicsItem* item , m_grid.childItems()) {
273 302 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
274 303 }
275 304 }
276 305
277 306 void AxisItem::setTicks(int count)
278 307 {
279 308 if(count!=m_ticks){
280 309 clear();
281 310 m_ticks=count;
282 311 createItems();
283 312 }
284 313 }
285 314
286 315 //TODO "nice numbers algorithm"
287 316 #include "moc_axisitem_p.cpp"
288 317
289 318 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,75 +1,80
1 1 #ifndef AXISITEM_H_
2 2 #define AXISITEM_H_
3 3
4 4 #include "domain_p.h"
5 5 #include "chartitem_p.h"
6 6 #include <QGraphicsItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QChartAxis;
11 11
12 12 class AxisItem : public QObject, public ChartItem
13 13 {
14 14 Q_OBJECT
15 15 public:
16 16 enum AxisType{X_AXIS,Y_AXIS};
17 17
18 18 AxisItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0);
19 19 ~AxisItem();
20 20
21 21 //from QGraphicsItem
22 22 QRectF boundingRect() const;
23 23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
24 24
25 25 AxisType axisType() const {return m_type;};
26 26
27 void setAxisOpacity(qreal opacity);
28 qreal axisOpacity() const;
29
27 30 void setGridOpacity(qreal opacity);
28 31 qreal gridOpacity() const;
29 32
30 33 void setLabelsOpacity(qreal opacity);
31 34 qreal labelsOpacity() const;
32 35
33 36 void setShadesOpacity(qreal opacity);
34 37 qreal shadesOpacity() const;
35 38
36 39 void setLabelsAngle(int angle);
37 40 int labelsAngle()const { return m_labelsAngle; }
38 41
39 42 void setTicks(int count);
40 43 int ticks() const { return m_ticks;}
41 44
42 45 void setShadesBrush(const QBrush& brush);
43 46 void setShadesPen(const QPen& pen);
44 47
48 void setAxisPen(const QPen& pen);
45 49 void setGridPen(const QPen& pen);
46 50
47 51 void setLabelsPen(const QPen& pen);
48 52 void setLabelsBrush(const QBrush& brush);
49 53 void setLabelsFont(const QFont& font);
50 54
51 55 public slots:
52 56 void handleAxisChanged(const QChartAxis& axis);
53 57 void handleDomainChanged(const Domain& domain);
54 58 void handleGeometryChanged(const QRectF& size);
55 59 protected:
56 60 void updateDomain();
57 61 private:
58 62 void clear();
59 63 void createItems();
60 64 private:
61 65 AxisType m_type;
62 66 int m_ticks;
63 67 Domain m_domain;
64 68 QRectF m_rect;
65 69 int m_labelsAngle;
66 70 bool m_shadesEnabled;
67 71 QGraphicsItemGroup m_grid;
68 72 QGraphicsItemGroup m_shades;
69 73 QGraphicsItemGroup m_labels;
74 QGraphicsLineItem m_axis;
70 75
71 76 };
72 77
73 78 QTCOMMERCIALCHART_END_NAMESPACE
74 79
75 80 #endif /* AXISITEM_H_ */
@@ -1,245 +1,246
1 1 #include "charttheme_p.h"
2 2 #include "qchart.h"
3 3 #include "qchartaxis.h"
4 4
5 5
6 6 //series
7 7 #include "barchartseries.h"
8 8 #include "stackedbarchartseries.h"
9 9 #include "percentbarchartseries.h"
10 10 #include "qlinechartseries.h"
11 11 #include "qscatterseries.h"
12 12 #include "qpieseries.h"
13 13
14 14 //items
15 15 #include "axisitem_p.h"
16 16 #include "bargroup.h"
17 17 #include "stackedbargroup.h"
18 18 #include "linechartitem_p.h"
19 19 #include "percentbargroup.h"
20 20 #include "scatterpresenter.h"
21 21 #include "piepresenter.h"
22 22
23 23 //themes
24 24 #include "chartthemevanilla_p.h"
25 25 #include "chartthemeicy_p.h"
26 26 #include "chartthemegrayscale_p.h"
27 27 #include "chartthemescientific_p.h"
28 28
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 /* TODO
33 33 case QChart::ChartThemeUnnamed1:
34 34 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
35 35 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
36 36 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
37 37 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
38 38 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
39 39
40 40 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
41 41 m_gradientEndColor = QColor(QRgb(0xffafafaf));
42 42 */
43 43
44 44 ChartTheme::ChartTheme(QChart::ChartTheme id)
45 45 {
46 46 m_id = id;
47 47 m_seriesColor.append(QRgb(0xff000000));
48 48 m_seriesColor.append(QRgb(0xff707070));
49 49 m_gradientStartColor = QColor(QRgb(0xffffffff));
50 50 m_gradientEndColor = QColor(QRgb(0xffafafaf));
51 51 }
52 52
53 53
54 54 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
55 55 {
56 56 switch(theme) {
57 57 case QChart::ChartThemeDefault:
58 58 return new ChartTheme();
59 59 case QChart::ChartThemeVanilla:
60 60 return new ChartThemeVanilla();
61 61 case QChart::ChartThemeIcy:
62 62 return new ChartThemeIcy();
63 63 case QChart::ChartThemeGrayscale:
64 64 return new ChartThemeGrayscale();
65 65 case QChart::ChartThemeScientific:
66 66 return new ChartThemeScientific();
67 67 }
68 68 }
69 69
70 70 void ChartTheme::decorate(QChart* chart)
71 71 {
72 72 QLinearGradient backgroundGradient;
73 73 backgroundGradient.setColorAt(0.0, m_gradientStartColor);
74 74 backgroundGradient.setColorAt(1.0, m_gradientEndColor);
75 75 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
76 76 chart->setChartBackgroundBrush(backgroundGradient);
77 77 }
78 78 //TODO helper to by removed later
79 79 void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count)
80 80 {
81 81 switch(series->type())
82 82 {
83 83 case QChartSeries::SeriesTypeLine: {
84 84 QLineChartSeries* s = static_cast<QLineChartSeries*>(series);
85 85 LineChartItem* i = static_cast<LineChartItem*>(item);
86 86 decorate(i,s,count);
87 87 break;
88 88 }
89 89 case QChartSeries::SeriesTypeBar: {
90 90 BarChartSeries* b = static_cast<BarChartSeries*>(series);
91 91 BarGroup* i = static_cast<BarGroup*>(item);
92 92 decorate(i,b,count);
93 93 break;
94 94 }
95 95 case QChartSeries::SeriesTypeStackedBar: {
96 96 StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series);
97 97 StackedBarGroup* i = static_cast<StackedBarGroup*>(item);
98 98 decorate(i,s,count);
99 99 break;
100 100 }
101 101 case QChartSeries::SeriesTypePercentBar: {
102 102 PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series);
103 103 PercentBarGroup* i = static_cast<PercentBarGroup*>(item);
104 104 decorate(i,s,count);
105 105 break;
106 106 }
107 107 case QChartSeries::SeriesTypePie: {
108 108 QPieSeries* s = static_cast<QPieSeries*>(series);
109 109 PiePresenter* i = static_cast<PiePresenter*>(item);
110 110 decorate(i,s,count);
111 111 break;
112 112 }
113 113 default:
114 114 qDebug()<<"Wrong item to be decorated by theme";
115 115 break;
116 116 }
117 117
118 118 }
119 119
120 120 void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count)
121 121 {
122 122 QPen pen;
123 123 if(pen != series->pen()){
124 124 item->setPen(series->pen());
125 125 return;
126 126 }
127 127 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
128 128 pen.setWidthF(2);
129 129 item->setPen(pen);
130 130 }
131 131
132 132 void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count)
133 133 {
134 134 // TODO: better way to descide series color and remove hard coded colors.
135 135 item->resetBrushes();
136 136 for (int i=0; i<m_seriesColor.count(); i++) {
137 137 QBrush brush(m_seriesColor.at(i));
138 138 item->addBrush(brush);
139 139 }
140 140 item->addBrush(QBrush(QColor(255,0,0,128)));
141 141 item->addBrush(QBrush(QColor(255,255,0,128)));
142 142 item->addBrush(QBrush(QColor(0,255,0,128)));
143 143 item->addBrush(QBrush(QColor(0,0,255,128)));
144 144 item->addBrush(QBrush(QColor(255,128,0,128)));
145 145 }
146 146
147 147 void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count)
148 148 {
149 149 // TODO: better way to descide series color and remove hard coded colors.
150 150 item->resetBrushes();
151 151 for (int i=0; i<m_seriesColor.count(); i++) {
152 152 QBrush brush(m_seriesColor.at(i));
153 153 item->addBrush(brush);
154 154 }
155 155 item->addBrush(QBrush(QColor(255,0,0,128)));
156 156 item->addBrush(QBrush(QColor(255,255,0,128)));
157 157 item->addBrush(QBrush(QColor(0,255,0,128)));
158 158 item->addBrush(QBrush(QColor(0,0,255,128)));
159 159 item->addBrush(QBrush(QColor(255,128,0,128)));
160 160 }
161 161
162 162 void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count)
163 163 {
164 164 // TODO: better way to descide series color and remove hard coded colors.
165 165 item->resetBrushes();
166 166 for (int i=0; i<m_seriesColor.count(); i++) {
167 167 QBrush brush(m_seriesColor.at(i));
168 168 item->addBrush(brush);
169 169 }
170 170 item->addBrush(QBrush(QColor(255,0,0,128)));
171 171 item->addBrush(QBrush(QColor(255,255,0,128)));
172 172 item->addBrush(QBrush(QColor(0,255,0,128)));
173 173 item->addBrush(QBrush(QColor(0,0,255,128)));
174 174 item->addBrush(QBrush(QColor(255,128,0,128)));
175 175 }
176 176
177 177 void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count)
178 178 {
179 179 Q_ASSERT(presenter);
180 180 Q_ASSERT(series);
181 181
182 182 presenter->m_markerPen.setColor(m_seriesColor.at(count % m_seriesColor.size()));
183 183
184 184 // QPen pen;
185 185 // if(pen != series->pen()){
186 186 // item->setPen(series->pen());
187 187 // return;
188 188 // }
189 189 // pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
190 190 // pen.setWidthF(2);
191 191 // item->setPen(pen);
192 192 }
193 193
194 194 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/)
195 195 {
196 196 // create a list of slice colors based on current theme
197 197 int i = 0;
198 198 QList<QColor> colors;
199 199 while (colors.count() < series->count()) {
200 200
201 201 // get base color
202 202 QColor c = m_seriesColor[i++];
203 203 i = i % m_seriesColor.count();
204 204
205 205 // -1 means achromatic color -> cannot manipulate lightness
206 206 // TODO: find a better way to randomize lightness
207 207 if (c.toHsv().hue() == -1)
208 208 qWarning() << "ChartTheme::decorate() warning: achromatic theme color";
209 209
210 210 // randomize lightness
211 211 qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter
212 212 c = c.lighter(f);
213 213
214 214 // find duplicates
215 215 bool isUnique = true;
216 216 foreach (QColor color, colors) {
217 217 if (c == color)
218 218 isUnique = false;
219 219 }
220 220
221 221 // add to array if unique
222 222 //if (isUnique)
223 223 colors << c;
224 224 }
225 225
226 226 // finally update colors
227 227 foreach (QPieSliceId id, series->ids()) {
228 228 QPieSlice s = series->slice(id);
229 229 s.setPen(QPen(Qt::black)); // TODO: get from theme
230 230 s.setBrush(colors.takeFirst());
231 231 series->update(s);
232 232 }
233 233 }
234 234
235 235
236 236 void ChartTheme::decorate(QChartAxis& axis,AxisItem* item)
237 237 {
238 238 //TODO: dummy defults for now
239 239
240 240 axis.setLabelsBrush(Qt::black);
241 241 axis.setLabelsPen(Qt::NoPen);
242 axis.setShadesPen(Qt::NoPen);
242 243 item->handleAxisChanged(axis);
243 244 }
244 245
245 246 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,86 +1,81
1 1 #include "qchartaxis.h"
2 2
3 3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 5 QChartAxis::QChartAxis():
6 6 m_axisVisible(true),
7 7 m_gridVisible(true),
8 8 m_labelsVisible(true),
9 9 m_shadesVisible(true)
10 10 {
11 11 // TODO Auto-generated constructor stub
12 12
13 13 }
14 14
15 15 QChartAxis::~QChartAxis()
16 16 {
17 17 // TODO Auto-generated destructor stub
18 18 }
19 19
20 20 void QChartAxis::setAxisPen(const QPen& pen)
21 21 {
22 22 m_axisPen=pen;
23 23 }
24 24
25 void QChartAxis::setAxisBrush(const QBrush& brush)
26 {
27 m_axisBrush=brush;
28 }
29
30 25 void QChartAxis::setAxisVisible(bool visible)
31 26 {
32 27 m_axisVisible=visible;
33 28 }
34 29
35 30 void QChartAxis::setGridVisible(bool visible)
36 31 {
37 32 m_gridVisible=visible;
38 33 }
39 34
40 35 void QChartAxis::setGridPen(const QPen& pen)
41 36 {
42 37 m_gridPen=pen;
43 38 }
44 39
45 40 void QChartAxis::setLabelsVisible(bool visible)
46 41 {
47 42 m_labelsVisible=visible;
48 43 }
49 44
50 45 void QChartAxis::setLabelsPen(const QPen& pen)
51 46 {
52 47 m_labelsPen=pen;
53 48 }
54 49
55 50 void QChartAxis::setLabelsBrush(const QBrush& brush)
56 51 {
57 52 m_labelsBrush=brush;
58 53 }
59 54
60 55 void QChartAxis::setLabelsFont(const QFont& font)
61 56 {
62 57 m_labelsFont=font;
63 58 }
64 59
65 60 void QChartAxis::setLabelsOrientation(LabelsOrientation orientation)
66 61 {
67 62 m_labelsOrientation=orientation;
68 63 }
69 64
70 65 void QChartAxis::setShadesVisible(bool visible)
71 66 {
72 67 m_shadesVisible=visible;
73 68 }
74 69
75 70 void QChartAxis::setShadesPen(const QPen& pen)
76 71 {
77 72 m_shadesPen=pen;
78 73 }
79 74
80 75 void QChartAxis::setShadesBrush(const QBrush& brush)
81 76 {
82 77 m_shadesBrush=brush;
83 78 }
84 79
85 80
86 81 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now