@@ -45,7 +45,7 int main(int argc, char *argv[]) | |||||
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); |
@@ -13,11 +13,13 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 | |||
@@ -73,6 +75,8 void AxisItem::updateDomain() | |||||
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(); | |
@@ -100,6 +104,8 void AxisItem::updateDomain() | |||||
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(); | |
@@ -131,6 +137,13 void AxisItem::updateDomain() | |||||
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 | } | |
@@ -168,6 +181,7 void AxisItem::handleAxisChanged(const QChartAxis& axis) | |||||
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()); | |
@@ -191,6 +205,16 void AxisItem::handleGeometryChanged(const QRectF& rect) | |||||
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); | |
@@ -267,6 +291,11 void AxisItem::setShadesPen(const QPen& 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()) { |
@@ -24,6 +24,9 public: | |||||
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 | |||
@@ -42,6 +45,7 public: | |||||
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); | |
@@ -67,6 +71,7 private: | |||||
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 |
@@ -239,6 +239,7 void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) | |||||
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 |
@@ -22,11 +22,6 void QChartAxis::setAxisPen(const QPen& pen) | |||||
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; |
General Comments 0
You need to be logged in to leave comments.
Login now