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