@@ -1,407 +1,406 | |||||
1 | #include "axisitem_p.h" |
|
1 | #include "axisitem_p.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartanimator_p.h" |
|
4 | #include "chartanimator_p.h" | |
5 | #include <QPainter> |
|
5 | #include <QPainter> | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 |
|
7 | |||
8 | static int label_padding = 5; |
|
8 | static int label_padding = 5; | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | AxisItem::AxisItem(QChartAxis* axis,ChartPresenter* presenter,AxisType type,QGraphicsItem* parent) : |
|
12 | AxisItem::AxisItem(QChartAxis* axis,ChartPresenter* presenter,AxisType type,QGraphicsItem* parent) : | |
13 | ChartItem(parent), |
|
13 | ChartItem(parent), | |
14 | m_presenter(presenter), |
|
14 | m_presenter(presenter), | |
15 | m_chartAxis(axis), |
|
15 | m_chartAxis(axis), | |
16 | m_type(type), |
|
16 | m_type(type), | |
17 | m_labelsAngle(0), |
|
17 | m_labelsAngle(0), | |
18 | m_grid(parent), |
|
18 | m_grid(parent), | |
19 | m_shades(parent), |
|
19 | m_shades(parent), | |
20 | m_labels(parent), |
|
20 | m_labels(parent), | |
21 | m_axis(parent), |
|
21 | m_axis(parent), | |
22 | m_min(0), |
|
22 | m_min(0), | |
23 | m_max(0), |
|
23 | m_max(0), | |
24 | m_ticksCount(0) |
|
24 | m_ticksCount(0) | |
25 | { |
|
25 | { | |
26 | //initial initialization |
|
26 | //initial initialization | |
27 | m_axis.setZValue(ChartPresenter::AxisZValue); |
|
27 | m_axis.setZValue(ChartPresenter::AxisZValue); | |
28 | m_shades.setZValue(ChartPresenter::ShadesZValue); |
|
28 | m_shades.setZValue(ChartPresenter::ShadesZValue); | |
29 | m_grid.setZValue(ChartPresenter::GridZValue); |
|
29 | m_grid.setZValue(ChartPresenter::GridZValue); | |
30 | setFlags(QGraphicsItem::ItemHasNoContents); |
|
30 | setFlags(QGraphicsItem::ItemHasNoContents); | |
31 |
|
31 | |||
32 | QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
32 | QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); | |
33 | QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); |
|
33 | QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); | |
34 |
|
34 | |||
35 | handleAxisUpdated(); |
|
35 | handleAxisUpdated(); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | AxisItem::~AxisItem() |
|
38 | AxisItem::~AxisItem() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QRectF AxisItem::boundingRect() const |
|
42 | QRectF AxisItem::boundingRect() const | |
43 | { |
|
43 | { | |
44 | return QRectF(); |
|
44 | return QRectF(); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void AxisItem::createItems(int count) |
|
47 | void AxisItem::createItems(int count) | |
48 | { |
|
48 | { | |
49 |
|
49 | |||
50 | if(m_axis.children().size()==0) |
|
50 | if(m_axis.children().size()==0) | |
51 | m_axis.addToGroup(new QGraphicsLineItem()); |
|
51 | m_axis.addToGroup(new QGraphicsLineItem()); | |
52 | for (int i = 0; i < count; ++i) { |
|
52 | for (int i = 0; i < count; ++i) { | |
53 | m_grid.addToGroup(new QGraphicsLineItem()); |
|
53 | m_grid.addToGroup(new QGraphicsLineItem()); | |
54 | m_labels.addToGroup(new QGraphicsSimpleTextItem()); |
|
54 | m_labels.addToGroup(new QGraphicsSimpleTextItem()); | |
55 | m_axis.addToGroup(new QGraphicsLineItem()); |
|
55 | m_axis.addToGroup(new QGraphicsLineItem()); | |
56 | if((m_grid.childItems().size())%2 && m_grid.childItems().size()>2) m_shades.addToGroup(new QGraphicsRectItem()); |
|
56 | if((m_grid.childItems().size())%2 && m_grid.childItems().size()>2) m_shades.addToGroup(new QGraphicsRectItem()); | |
57 | } |
|
57 | } | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void AxisItem::deleteItems(int count) |
|
60 | void AxisItem::deleteItems(int count) | |
61 | { |
|
61 | { | |
62 | QList<QGraphicsItem *> lines = m_grid.childItems(); |
|
62 | QList<QGraphicsItem *> lines = m_grid.childItems(); | |
63 | QList<QGraphicsItem *> labels = m_labels.childItems(); |
|
63 | QList<QGraphicsItem *> labels = m_labels.childItems(); | |
64 | QList<QGraphicsItem *> shades = m_shades.childItems(); |
|
64 | QList<QGraphicsItem *> shades = m_shades.childItems(); | |
65 | QList<QGraphicsItem *> axis = m_axis.childItems(); |
|
65 | QList<QGraphicsItem *> axis = m_axis.childItems(); | |
66 |
|
66 | |||
67 | for (int i = 0; i < count; ++i) { |
|
67 | for (int i = 0; i < count; ++i) { | |
68 | if(lines.size()%2 && lines.size()>1) delete(shades.takeLast()); |
|
68 | if(lines.size()%2 && lines.size()>1) delete(shades.takeLast()); | |
69 | delete(lines.takeLast()); |
|
69 | delete(lines.takeLast()); | |
70 | delete(labels.takeLast()); |
|
70 | delete(labels.takeLast()); | |
71 | delete(axis.takeLast()); |
|
71 | delete(axis.takeLast()); | |
72 | } |
|
72 | } | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void AxisItem::updateLayout(QVector<qreal>& layout) |
|
75 | void AxisItem::updateLayout(QVector<qreal>& layout) | |
76 | { |
|
76 | { | |
77 | if(m_animator){ |
|
77 | if(m_animator){ | |
78 | m_animator->applyLayout(this,layout); |
|
78 | m_animator->applyLayout(this,layout); | |
79 | } |
|
79 | } | |
80 | else setLayout(layout); |
|
80 | else setLayout(layout); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | QStringList AxisItem::createLabels(int ticks, qreal min, qreal max) const |
|
83 | QStringList AxisItem::createLabels(int ticks, qreal min, qreal max) const | |
84 | { |
|
84 | { | |
85 | Q_ASSERT(max>=min); |
|
85 | Q_ASSERT(max>=min); | |
86 | Q_ASSERT(ticks>0); |
|
86 | Q_ASSERT(ticks>0); | |
87 |
|
87 | |||
88 | QStringList labels; |
|
88 | QStringList labels; | |
89 |
|
89 | |||
90 | QChartAxisCategories* categories = m_chartAxis->categories(); |
|
90 | QChartAxisCategories* categories = m_chartAxis->categories(); | |
91 |
|
91 | |||
92 | for(int i=0; i< ticks; i++) { |
|
92 | for(int i=0; i< ticks; i++) { | |
93 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
93 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
94 | if(categories->count()==0) { |
|
94 | if(categories->count()==0) { | |
95 | labels << QString::number(value); |
|
95 | labels << QString::number(value); | |
96 | } |
|
96 | } | |
97 | else { |
|
97 | else { | |
98 |
|
98 | |||
99 | QString label = categories->label(value); |
|
99 | QString label = categories->label(value); | |
100 | labels << label; |
|
100 | labels << label; | |
101 | } |
|
101 | } | |
102 | } |
|
102 | } | |
103 | return labels; |
|
103 | return labels; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void AxisItem::setAxisOpacity(qreal opacity) |
|
106 | void AxisItem::setAxisOpacity(qreal opacity) | |
107 | { |
|
107 | { | |
108 | m_axis.setOpacity(opacity); |
|
108 | m_axis.setOpacity(opacity); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | qreal AxisItem::axisOpacity() const |
|
111 | qreal AxisItem::axisOpacity() const | |
112 | { |
|
112 | { | |
113 | return m_axis.opacity(); |
|
113 | return m_axis.opacity(); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void AxisItem::setGridOpacity(qreal opacity) |
|
116 | void AxisItem::setGridOpacity(qreal opacity) | |
117 | { |
|
117 | { | |
118 | m_grid.setOpacity(opacity); |
|
118 | m_grid.setOpacity(opacity); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | qreal AxisItem::gridOpacity() const |
|
121 | qreal AxisItem::gridOpacity() const | |
122 | { |
|
122 | { | |
123 | return m_grid.opacity(); |
|
123 | return m_grid.opacity(); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void AxisItem::setLabelsOpacity(qreal opacity) |
|
126 | void AxisItem::setLabelsOpacity(qreal opacity) | |
127 | { |
|
127 | { | |
128 | m_labels.setOpacity(opacity); |
|
128 | m_labels.setOpacity(opacity); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | qreal AxisItem::labelsOpacity() const |
|
131 | qreal AxisItem::labelsOpacity() const | |
132 | { |
|
132 | { | |
133 | return m_labels.opacity(); |
|
133 | return m_labels.opacity(); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void AxisItem::setShadesOpacity(qreal opacity) |
|
136 | void AxisItem::setShadesOpacity(qreal opacity) | |
137 | { |
|
137 | { | |
138 | m_shades.setOpacity(opacity); |
|
138 | m_shades.setOpacity(opacity); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | qreal AxisItem::shadesOpacity() const |
|
141 | qreal AxisItem::shadesOpacity() const | |
142 | { |
|
142 | { | |
143 | return m_shades.opacity(); |
|
143 | return m_shades.opacity(); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | void AxisItem::setLabelsAngle(int angle) |
|
146 | void AxisItem::setLabelsAngle(int angle) | |
147 | { |
|
147 | { | |
148 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
148 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
149 | QPointF center = item->boundingRect().center(); |
|
149 | QPointF center = item->boundingRect().center(); | |
150 | item->setRotation(angle); |
|
150 | item->setRotation(angle); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | m_labelsAngle=angle; |
|
153 | m_labelsAngle=angle; | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void AxisItem::setLabelsPen(const QPen& pen) |
|
156 | void AxisItem::setLabelsPen(const QPen& pen) | |
157 | { |
|
157 | { | |
158 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
158 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
159 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
159 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
160 | } |
|
160 | } | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void AxisItem::setLabelsBrush(const QBrush& brush) |
|
163 | void AxisItem::setLabelsBrush(const QBrush& brush) | |
164 | { |
|
164 | { | |
165 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
165 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
166 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
166 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
167 | } |
|
167 | } | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void AxisItem::setLabelsFont(const QFont& font) |
|
170 | void AxisItem::setLabelsFont(const QFont& font) | |
171 | { |
|
171 | { | |
172 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
172 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
173 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
173 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
174 | } |
|
174 | } | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | void AxisItem::setShadesBrush(const QBrush& brush) |
|
177 | void AxisItem::setShadesBrush(const QBrush& brush) | |
178 | { |
|
178 | { | |
179 | foreach(QGraphicsItem* item , m_shades.childItems()) { |
|
179 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
180 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
180 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
181 | } |
|
181 | } | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | void AxisItem::setShadesPen(const QPen& pen) |
|
184 | void AxisItem::setShadesPen(const QPen& pen) | |
185 | { |
|
185 | { | |
186 | foreach(QGraphicsItem* item , m_shades.childItems()) { |
|
186 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
187 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
187 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | void AxisItem::setAxisPen(const QPen& pen) |
|
191 | void AxisItem::setAxisPen(const QPen& pen) | |
192 | { |
|
192 | { | |
193 | foreach(QGraphicsItem* item , m_axis.childItems()) { |
|
193 | foreach(QGraphicsItem* item , m_axis.childItems()) { | |
194 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
194 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
195 | } |
|
195 | } | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | void AxisItem::setGridPen(const QPen& pen) |
|
198 | void AxisItem::setGridPen(const QPen& pen) | |
199 | { |
|
199 | { | |
200 | foreach(QGraphicsItem* item , m_grid.childItems()) { |
|
200 | foreach(QGraphicsItem* item , m_grid.childItems()) { | |
201 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
201 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
202 | } |
|
202 | } | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | QVector<qreal> AxisItem::calculateLayout() const |
|
205 | QVector<qreal> AxisItem::calculateLayout() const | |
206 | { |
|
206 | { | |
207 | Q_ASSERT(m_ticksCount>=2); |
|
207 | Q_ASSERT(m_ticksCount>=2); | |
208 |
|
208 | |||
209 | QVector<qreal> points; |
|
209 | QVector<qreal> points; | |
210 | points.resize(m_ticksCount); |
|
210 | points.resize(m_ticksCount); | |
211 |
|
211 | |||
212 | switch (m_type) |
|
212 | switch (m_type) | |
213 | { |
|
213 | { | |
214 | case X_AXIS: |
|
214 | case X_AXIS: | |
215 | { |
|
215 | { | |
216 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); |
|
216 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); | |
217 | for (int i = 0; i < m_ticksCount; ++i) { |
|
217 | for (int i = 0; i < m_ticksCount; ++i) { | |
218 | int x = i * deltaX + m_rect.left(); |
|
218 | int x = i * deltaX + m_rect.left(); | |
219 | points[i] = x; |
|
219 | points[i] = x; | |
220 | } |
|
220 | } | |
221 | } |
|
221 | } | |
222 | break; |
|
222 | break; | |
223 | case Y_AXIS: |
|
223 | case Y_AXIS: | |
224 | { |
|
224 | { | |
225 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); |
|
225 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); | |
226 | for (int i = 0; i < m_ticksCount; ++i) { |
|
226 | for (int i = 0; i < m_ticksCount; ++i) { | |
227 | int y = i * -deltaY + m_rect.bottom(); |
|
227 | int y = i * -deltaY + m_rect.bottom(); | |
228 | points[i] = y; |
|
228 | points[i] = y; | |
229 | } |
|
229 | } | |
230 | } |
|
230 | } | |
231 | break; |
|
231 | break; | |
232 | } |
|
232 | } | |
233 | return points; |
|
233 | return points; | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void AxisItem::setLayout(QVector<qreal>& layout) |
|
236 | void AxisItem::setLayout(QVector<qreal>& layout) | |
237 | { |
|
237 | { | |
238 | int diff = m_layoutVector.size() - layout.size(); |
|
238 | int diff = m_layoutVector.size() - layout.size(); | |
239 |
|
239 | |||
240 | if(diff>0) { |
|
240 | if(diff>0) { | |
241 | deleteItems(diff); |
|
241 | deleteItems(diff); | |
242 | } |
|
242 | } | |
243 | else if(diff<0) { |
|
243 | else if(diff<0) { | |
244 | createItems(-diff); |
|
244 | createItems(-diff); | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | if(diff!=0) handleAxisUpdated(); |
|
247 | if(diff!=0) handleAxisUpdated(); | |
248 |
|
248 | |||
249 | QStringList ticksList = createLabels(layout.size(),m_min,m_max); |
|
249 | QStringList ticksList = createLabels(layout.size(),m_min,m_max); | |
250 |
|
250 | |||
251 | QList<QGraphicsItem *> lines = m_grid.childItems(); |
|
251 | QList<QGraphicsItem *> lines = m_grid.childItems(); | |
252 | QList<QGraphicsItem *> labels = m_labels.childItems(); |
|
252 | QList<QGraphicsItem *> labels = m_labels.childItems(); | |
253 | QList<QGraphicsItem *> shades = m_shades.childItems(); |
|
253 | QList<QGraphicsItem *> shades = m_shades.childItems(); | |
254 | QList<QGraphicsItem *> axis = m_axis.childItems(); |
|
254 | QList<QGraphicsItem *> axis = m_axis.childItems(); | |
255 |
|
255 | |||
256 | Q_ASSERT(labels.size() == ticksList.size()); |
|
256 | Q_ASSERT(labels.size() == ticksList.size()); | |
257 | Q_ASSERT(layout.size() == ticksList.size()); |
|
257 | Q_ASSERT(layout.size() == ticksList.size()); | |
258 |
|
258 | |||
259 | switch (m_type) |
|
259 | switch (m_type) | |
260 | { |
|
260 | { | |
261 | case X_AXIS: |
|
261 | case X_AXIS: | |
262 | { |
|
262 | { | |
263 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
263 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
264 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
264 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
265 |
|
265 | |||
266 | for (int i = 0; i < layout.size(); ++i) { |
|
266 | for (int i = 0; i < layout.size(); ++i) { | |
267 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
267 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
268 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
268 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
269 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
269 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
270 | labelItem->setText(ticksList.at(i)); |
|
270 | labelItem->setText(ticksList.at(i)); | |
271 | QPointF center = labelItem->boundingRect().center(); |
|
271 | QPointF center = labelItem->boundingRect().center(); | |
272 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
272 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
273 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
273 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
274 | if((i+1)%2 && i>1) { |
|
274 | if((i+1)%2 && i>1) { | |
275 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
275 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
276 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); |
|
276 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
277 | } |
|
277 | } | |
278 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
278 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
279 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); |
|
279 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
280 | } |
|
280 | } | |
281 | } |
|
281 | } | |
282 | break; |
|
282 | break; | |
283 |
|
283 | |||
284 | case Y_AXIS: |
|
284 | case Y_AXIS: | |
285 | { |
|
285 | { | |
286 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
286 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
287 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
287 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
288 |
|
288 | |||
289 | for (int i = 0; i < layout.size(); ++i) { |
|
289 | for (int i = 0; i < layout.size(); ++i) { | |
290 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
290 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
291 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
291 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
292 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
292 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
293 | labelItem->setText(ticksList.at(i)); |
|
293 | labelItem->setText(ticksList.at(i)); | |
294 | QPointF center = labelItem->boundingRect().center(); |
|
294 | QPointF center = labelItem->boundingRect().center(); | |
295 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
295 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
296 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y()); |
|
296 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y()); | |
297 | if((i+1)%2 && i>1) { |
|
297 | if((i+1)%2 && i>1) { | |
298 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
298 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
299 | rectItem->setRect(m_rect.left(),layout[i-1],m_rect.width(),layout[i-1]-layout[i]); |
|
299 | rectItem->setRect(m_rect.left(),layout[i-1],m_rect.width(),layout[i-1]-layout[i]); | |
300 | } |
|
300 | } | |
301 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
301 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
302 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
302 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
303 | } |
|
303 | } | |
304 | } |
|
304 | } | |
305 | break; |
|
305 | break; | |
306 | default: |
|
306 | default: | |
307 | qDebug()<<"Unknown axis type"; |
|
307 | qDebug()<<"Unknown axis type"; | |
308 | break; |
|
308 | break; | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | m_layoutVector=layout; |
|
311 | m_layoutVector=layout; | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | bool AxisItem::isEmpty() |
|
314 | bool AxisItem::isEmpty() | |
315 | { |
|
315 | { | |
316 | return m_rect.isEmpty() || m_min==m_max || m_ticksCount==0; |
|
316 | return m_rect.isEmpty() || m_min==m_max || m_ticksCount==0; | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | //handlers |
|
319 | //handlers | |
320 |
|
320 | |||
321 | void AxisItem::handleAxisCategoriesUpdated() |
|
321 | void AxisItem::handleAxisCategoriesUpdated() | |
322 | { |
|
322 | { | |
323 | if(isEmpty()) return; |
|
323 | if(isEmpty()) return; | |
324 | updateLayout(m_layoutVector); |
|
324 | updateLayout(m_layoutVector); | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | void AxisItem::handleAxisUpdated() |
|
327 | void AxisItem::handleAxisUpdated() | |
328 | { |
|
328 | { | |
329 |
|
329 | |||
330 | if(isEmpty()) return; |
|
330 | if(isEmpty()) return; | |
331 |
|
331 | |||
332 | if(m_chartAxis->isAxisVisible()) { |
|
332 | if(m_chartAxis->isAxisVisible()) { | |
333 | setAxisOpacity(100); |
|
333 | setAxisOpacity(100); | |
334 | } |
|
334 | } | |
335 | else { |
|
335 | else { | |
336 | setAxisOpacity(0); |
|
336 | setAxisOpacity(0); | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | if(m_chartAxis->isGridLineVisible()) { |
|
339 | if(m_chartAxis->isGridLineVisible()) { | |
340 | setGridOpacity(100); |
|
340 | setGridOpacity(100); | |
341 | } |
|
341 | } | |
342 | else { |
|
342 | else { | |
343 | setGridOpacity(0); |
|
343 | setGridOpacity(0); | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | if(m_chartAxis->labelsVisible()) |
|
346 | if(m_chartAxis->labelsVisible()) | |
347 | { |
|
347 | { | |
348 | setLabelsOpacity(100); |
|
348 | setLabelsOpacity(100); | |
349 | } |
|
349 | } | |
350 | else { |
|
350 | else { | |
351 | setLabelsOpacity(0); |
|
351 | setLabelsOpacity(0); | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | if(m_chartAxis->shadesVisible()) { |
|
354 | if(m_chartAxis->shadesVisible()) { | |
355 | setShadesOpacity(m_chartAxis->shadesOpacity()); |
|
355 | setShadesOpacity(m_chartAxis->shadesOpacity()); | |
356 | } |
|
356 | } | |
357 | else { |
|
357 | else { | |
358 | setShadesOpacity(0); |
|
358 | setShadesOpacity(0); | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
361 | setLabelsAngle(m_chartAxis->labelsAngle()); | |
362 | setAxisPen(m_chartAxis->axisPen()); |
|
362 | setAxisPen(m_chartAxis->axisPen()); | |
363 | setLabelsPen(m_chartAxis->labelsPen()); |
|
363 | setLabelsPen(m_chartAxis->labelsPen()); | |
364 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
364 | setLabelsBrush(m_chartAxis->labelsBrush()); | |
365 | setLabelsFont(m_chartAxis->labelsFont()); |
|
365 | setLabelsFont(m_chartAxis->labelsFont()); | |
366 | setGridPen(m_chartAxis->gridLinePen()); |
|
366 | setGridPen(m_chartAxis->gridLinePen()); | |
367 | setShadesPen(m_chartAxis->shadesPen()); |
|
367 | setShadesPen(m_chartAxis->shadesPen()); | |
368 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
368 | setShadesBrush(m_chartAxis->shadesBrush()); | |
369 |
|
369 | |||
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | void AxisItem::handleRangeChanged(qreal min, qreal max,int tickCount) |
|
372 | void AxisItem::handleRangeChanged(qreal min, qreal max,int tickCount) | |
373 | { |
|
373 | { | |
374 | qDebug()<<min<<max<<tickCount; |
|
|||
375 | if(min==max || tickCount<2) return; |
|
374 | if(min==max || tickCount<2) return; | |
376 |
|
375 | |||
377 | m_min = min; |
|
376 | m_min = min; | |
378 | m_max = max; |
|
377 | m_max = max; | |
379 | m_ticksCount= tickCount; |
|
378 | m_ticksCount= tickCount; | |
380 |
|
379 | |||
381 | if(isEmpty()) return; |
|
380 | if(isEmpty()) return; | |
382 | QVector<qreal> layout = calculateLayout(); |
|
381 | QVector<qreal> layout = calculateLayout(); | |
383 | updateLayout(layout); |
|
382 | updateLayout(layout); | |
384 |
|
383 | |||
385 | } |
|
384 | } | |
386 |
|
385 | |||
387 | void AxisItem::handleGeometryChanged(const QRectF& rect) |
|
386 | void AxisItem::handleGeometryChanged(const QRectF& rect) | |
388 | { |
|
387 | { | |
389 | m_rect = rect; |
|
388 | m_rect = rect; | |
390 | if(isEmpty()) return; |
|
389 | if(isEmpty()) return; | |
391 | QVector<qreal> layout = calculateLayout(); |
|
390 | QVector<qreal> layout = calculateLayout(); | |
392 | updateLayout(layout); |
|
391 | updateLayout(layout); | |
393 | } |
|
392 | } | |
394 |
|
393 | |||
395 | //painter |
|
394 | //painter | |
396 |
|
395 | |||
397 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
396 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
398 | { |
|
397 | { | |
399 | Q_UNUSED(painter); |
|
398 | Q_UNUSED(painter); | |
400 | Q_UNUSED(option); |
|
399 | Q_UNUSED(option); | |
401 | Q_UNUSED(widget); |
|
400 | Q_UNUSED(widget); | |
402 | } |
|
401 | } | |
403 |
|
402 | |||
404 | //TODO "nice numbers algorithm" |
|
403 | //TODO "nice numbers algorithm" | |
405 | #include "moc_axisitem_p.cpp" |
|
404 | #include "moc_axisitem_p.cpp" | |
406 |
|
405 | |||
407 | QTCOMMERCIALCHART_END_NAMESPACE |
|
406 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,397 +1,396 | |||||
1 | #include "qchartaxis.h" |
|
1 | #include "qchartaxis.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QChartAxis |
|
6 | \class QChartAxis | |
7 | \brief The QChartAxis class is used for manipulating chart's axis |
|
7 | \brief The QChartAxis class is used for manipulating chart's axis | |
8 | and for adding optional axes to the chart. |
|
8 | and for adding optional axes to the chart. | |
9 | \mainclass |
|
9 | \mainclass | |
10 |
|
10 | |||
11 | There is only one x Axis, however there can be multiple y axes. |
|
11 | There is only one x Axis, however there can be multiple y axes. | |
12 | Each chart series can be bound to exactly one Y axis and the share common X axis. |
|
12 | Each chart series can be bound to exactly one Y axis and the share common X axis. | |
13 | Axis can be setup to show axis line with ticks, gird lines and shades. |
|
13 | Axis can be setup to show axis line with ticks, gird lines and shades. | |
14 |
|
14 | |||
15 | */ |
|
15 | */ | |
16 |
|
16 | |||
17 | /*! |
|
17 | /*! | |
18 | \fn bool QChartAxis::isAxisVisible() const |
|
18 | \fn bool QChartAxis::isAxisVisible() const | |
19 | \brief Returns if axis is visible |
|
19 | \brief Returns if axis is visible | |
20 | \sa setAxisVisible() |
|
20 | \sa setAxisVisible() | |
21 | */ |
|
21 | */ | |
22 |
|
22 | |||
23 | /*! |
|
23 | /*! | |
24 | \fn QPen QChartAxis::axisPen() const |
|
24 | \fn QPen QChartAxis::axisPen() const | |
25 | \brief Returns pen used to draw axis and ticks. |
|
25 | \brief Returns pen used to draw axis and ticks. | |
26 | \sa setAxisPen() |
|
26 | \sa setAxisPen() | |
27 | */ |
|
27 | */ | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \fn bool QChartAxis::isGridLineVisible() const |
|
31 | \fn bool QChartAxis::isGridLineVisible() const | |
32 | \brief Returns if grid is visible |
|
32 | \brief Returns if grid is visible | |
33 | \sa setGridLineVisible() |
|
33 | \sa setGridLineVisible() | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \fn QPen QChartAxis::gridLinePen() const |
|
37 | \fn QPen QChartAxis::gridLinePen() const | |
38 | \brief Returns pen used to draw grid. |
|
38 | \brief Returns pen used to draw grid. | |
39 | \sa setGridLinePen() |
|
39 | \sa setGridLinePen() | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \fn bool QChartAxis::labelsVisible() const |
|
43 | \fn bool QChartAxis::labelsVisible() const | |
44 | \brief Returns if grid is visible |
|
44 | \brief Returns if grid is visible | |
45 | \sa setLabelsVisible() |
|
45 | \sa setLabelsVisible() | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \fn QPen QChartAxis::labelsPen() const |
|
49 | \fn QPen QChartAxis::labelsPen() const | |
50 | \brief Returns the pen used to labels. |
|
50 | \brief Returns the pen used to labels. | |
51 | \sa setLabelsPen() |
|
51 | \sa setLabelsPen() | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | \fn QBrush QChartAxis::labelsBrush() const |
|
55 | \fn QBrush QChartAxis::labelsBrush() const | |
56 | \brief Returns brush used to draw labels. |
|
56 | \brief Returns brush used to draw labels. | |
57 | \sa setLabelsBrush() |
|
57 | \sa setLabelsBrush() | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \fn QFont QChartAxis::labelsFont() const |
|
61 | \fn QFont QChartAxis::labelsFont() const | |
62 | \brief Returns font used to draw labels. |
|
62 | \brief Returns font used to draw labels. | |
63 | \sa setLabelsFont() |
|
63 | \sa setLabelsFont() | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | \fn QFont QChartAxis::labelsAngle() const |
|
67 | \fn QFont QChartAxis::labelsAngle() const | |
68 | \brief Returns angle used to draw labels. |
|
68 | \brief Returns angle used to draw labels. | |
69 | \sa setLabelsAngle() |
|
69 | \sa setLabelsAngle() | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \fn bool QChartAxis::shadesVisible() const |
|
73 | \fn bool QChartAxis::shadesVisible() const | |
74 | \brief Returns if shades are visible. |
|
74 | \brief Returns if shades are visible. | |
75 | \sa setShadesVisible() |
|
75 | \sa setShadesVisible() | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \fn qreal QChartAxis::shadesOpacity() const |
|
79 | \fn qreal QChartAxis::shadesOpacity() const | |
80 | \brief Returns opacity of shades. |
|
80 | \brief Returns opacity of shades. | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \fn QPen QChartAxis::shadesPen() const |
|
84 | \fn QPen QChartAxis::shadesPen() const | |
85 | \brief Returns pen used to draw shades. |
|
85 | \brief Returns pen used to draw shades. | |
86 | \sa setShadesPen() |
|
86 | \sa setShadesPen() | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \fn QBrush QChartAxis::shadesBrush() const |
|
90 | \fn QBrush QChartAxis::shadesBrush() const | |
91 | \brief Returns brush used to draw shades. |
|
91 | \brief Returns brush used to draw shades. | |
92 | \sa setShadesBrush() |
|
92 | \sa setShadesBrush() | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \fn qreal QChartAxis::min() const |
|
96 | \fn qreal QChartAxis::min() const | |
97 | \brief Returns minimum value on the axis. |
|
97 | \brief Returns minimum value on the axis. | |
98 | \sa setMin() |
|
98 | \sa setMin() | |
99 | */ |
|
99 | */ | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | \fn qreal QChartAxis::max() const |
|
102 | \fn qreal QChartAxis::max() const | |
103 | \brief Returns maximim value on the axis. |
|
103 | \brief Returns maximim value on the axis. | |
104 | \sa setMax() |
|
104 | \sa setMax() | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \fn void QChartAxis::minChanged(qreal min) |
|
108 | \fn void QChartAxis::minChanged(qreal min) | |
109 | \brief Axis emits signal when \a min of axis has changed. |
|
109 | \brief Axis emits signal when \a min of axis has changed. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QChartAxis::maxChanged(qreal max) |
|
113 | \fn void QChartAxis::maxChanged(qreal max) | |
114 | \brief Axis emits signal when \a max of axis has changed. |
|
114 | \brief Axis emits signal when \a max of axis has changed. | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \fn void QChartAxis::rangeChanged(qreal min, qreal max) |
|
118 | \fn void QChartAxis::rangeChanged(qreal min, qreal max) | |
119 | \brief Axis emits signal when \a min or \a max of axis has changed. |
|
119 | \brief Axis emits signal when \a min or \a max of axis has changed. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn int QChartAxis::ticksCount() const |
|
123 | \fn int QChartAxis::ticksCount() const | |
124 | \brief Return number of ticks on the axis |
|
124 | \brief Return number of ticks on the axis | |
125 | \sa setTicksCount() |
|
125 | \sa setTicksCount() | |
126 | */ |
|
126 | */ | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | \fn void QChartAxis::updated() |
|
129 | \fn void QChartAxis::updated() | |
130 | \brief \internal |
|
130 | \brief \internal | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max) |
|
134 | \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max) | |
135 | \brief \internal \a min \a max |
|
135 | \brief \internal \a min \a max | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
139 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
140 | QChatView or QChart when axis added. |
|
140 | QChatView or QChart when axis added. | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | QChartAxis::QChartAxis(QObject* parent):QObject(parent), |
|
143 | QChartAxis::QChartAxis(QObject* parent):QObject(parent), | |
144 | m_axisVisible(true), |
|
144 | m_axisVisible(true), | |
145 | m_gridLineVisible(true), |
|
145 | m_gridLineVisible(true), | |
146 | m_labelsVisible(true), |
|
146 | m_labelsVisible(true), | |
147 | m_labelsAngle(0), |
|
147 | m_labelsAngle(0), | |
148 | m_shadesVisible(false), |
|
148 | m_shadesVisible(false), | |
149 | m_shadesOpacity(1.0), |
|
149 | m_shadesOpacity(1.0), | |
150 | m_min(0), |
|
150 | m_min(0), | |
151 | m_max(0), |
|
151 | m_max(0), | |
152 | m_ticksCount(5) |
|
152 | m_ticksCount(5) | |
153 | { |
|
153 | { | |
154 |
|
154 | |||
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
158 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | QChartAxis::~QChartAxis() |
|
161 | QChartAxis::~QChartAxis() | |
162 | { |
|
162 | { | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | Sets \a pen used to draw axis line and ticks. |
|
166 | Sets \a pen used to draw axis line and ticks. | |
167 | */ |
|
167 | */ | |
168 | void QChartAxis::setAxisPen(const QPen& pen) |
|
168 | void QChartAxis::setAxisPen(const QPen& pen) | |
169 | { |
|
169 | { | |
170 | if (pen != m_axisPen) { |
|
170 | if (pen != m_axisPen) { | |
171 | m_axisPen=pen; |
|
171 | m_axisPen=pen; | |
172 | emit updated(); |
|
172 | emit updated(); | |
173 | } |
|
173 | } | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | Sets if axis and ticks are \a visible. |
|
177 | Sets if axis and ticks are \a visible. | |
178 | */ |
|
178 | */ | |
179 | void QChartAxis::setAxisVisible(bool visible) |
|
179 | void QChartAxis::setAxisVisible(bool visible) | |
180 | { |
|
180 | { | |
181 | if (m_axisVisible!=visible) { |
|
181 | if (m_axisVisible!=visible) { | |
182 | m_axisVisible=visible; |
|
182 | m_axisVisible=visible; | |
183 | emit updated(); |
|
183 | emit updated(); | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | Sets if grid line is \a visible. |
|
188 | Sets if grid line is \a visible. | |
189 | */ |
|
189 | */ | |
190 | void QChartAxis::setGridLineVisible(bool visible) |
|
190 | void QChartAxis::setGridLineVisible(bool visible) | |
191 | { |
|
191 | { | |
192 | if (m_gridLineVisible!=visible) { |
|
192 | if (m_gridLineVisible!=visible) { | |
193 | m_gridLineVisible=visible; |
|
193 | m_gridLineVisible=visible; | |
194 | emit updated(); |
|
194 | emit updated(); | |
195 | } |
|
195 | } | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | Sets \a pen used to draw grid line. |
|
199 | Sets \a pen used to draw grid line. | |
200 | */ |
|
200 | */ | |
201 | void QChartAxis::setGridLinePen(const QPen& pen) |
|
201 | void QChartAxis::setGridLinePen(const QPen& pen) | |
202 | { |
|
202 | { | |
203 | if (m_gridLinePen!=pen) { |
|
203 | if (m_gridLinePen!=pen) { | |
204 | m_gridLinePen=pen; |
|
204 | m_gridLinePen=pen; | |
205 | emit updated(); |
|
205 | emit updated(); | |
206 | } |
|
206 | } | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | Sets if axis' labels are \a visible. |
|
210 | Sets if axis' labels are \a visible. | |
211 | */ |
|
211 | */ | |
212 | void QChartAxis::setLabelsVisible(bool visible) |
|
212 | void QChartAxis::setLabelsVisible(bool visible) | |
213 | { |
|
213 | { | |
214 | if(m_labelsVisible!=visible) { |
|
214 | if(m_labelsVisible!=visible) { | |
215 | m_labelsVisible=visible; |
|
215 | m_labelsVisible=visible; | |
216 | emit updated(); |
|
216 | emit updated(); | |
217 | } |
|
217 | } | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | /*! |
|
220 | /*! | |
221 | Sets \a pen used to draw labels. |
|
221 | Sets \a pen used to draw labels. | |
222 | */ |
|
222 | */ | |
223 | void QChartAxis::setLabelsPen(const QPen& pen) |
|
223 | void QChartAxis::setLabelsPen(const QPen& pen) | |
224 | { |
|
224 | { | |
225 | if(m_labelsPen!=pen) { |
|
225 | if(m_labelsPen!=pen) { | |
226 | m_labelsPen=pen; |
|
226 | m_labelsPen=pen; | |
227 | emit updated(); |
|
227 | emit updated(); | |
228 | } |
|
228 | } | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | Sets \a brush used to draw labels. |
|
232 | Sets \a brush used to draw labels. | |
233 | */ |
|
233 | */ | |
234 | void QChartAxis::setLabelsBrush(const QBrush& brush) |
|
234 | void QChartAxis::setLabelsBrush(const QBrush& brush) | |
235 | { |
|
235 | { | |
236 | if(m_labelsBrush!=brush) { |
|
236 | if(m_labelsBrush!=brush) { | |
237 | m_labelsBrush=brush; |
|
237 | m_labelsBrush=brush; | |
238 | emit updated(); |
|
238 | emit updated(); | |
239 | } |
|
239 | } | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | /*! |
|
242 | /*! | |
243 | Sets \a font used to draw labels. |
|
243 | Sets \a font used to draw labels. | |
244 | */ |
|
244 | */ | |
245 | void QChartAxis::setLabelsFont(const QFont& font) |
|
245 | void QChartAxis::setLabelsFont(const QFont& font) | |
246 | { |
|
246 | { | |
247 | if(m_labelsFont!=font) { |
|
247 | if(m_labelsFont!=font) { | |
248 | m_labelsFont=font; |
|
248 | m_labelsFont=font; | |
249 | emit updated(); |
|
249 | emit updated(); | |
250 | } |
|
250 | } | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | Sets \a angle for all the labels on given axis. |
|
254 | Sets \a angle for all the labels on given axis. | |
255 | */ |
|
255 | */ | |
256 | void QChartAxis::setLabelsAngle(int angle) |
|
256 | void QChartAxis::setLabelsAngle(int angle) | |
257 | { |
|
257 | { | |
258 | if(m_labelsAngle!=angle) { |
|
258 | if(m_labelsAngle!=angle) { | |
259 | m_labelsAngle=angle; |
|
259 | m_labelsAngle=angle; | |
260 | emit updated(); |
|
260 | emit updated(); | |
261 | } |
|
261 | } | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | /*! |
|
264 | /*! | |
265 | Sets if shades are \a visible. |
|
265 | Sets if shades are \a visible. | |
266 | */ |
|
266 | */ | |
267 | void QChartAxis::setShadesVisible(bool visible) |
|
267 | void QChartAxis::setShadesVisible(bool visible) | |
268 | { |
|
268 | { | |
269 | if(m_shadesVisible!=visible) { |
|
269 | if(m_shadesVisible!=visible) { | |
270 | m_shadesVisible=visible; |
|
270 | m_shadesVisible=visible; | |
271 | emit updated(); |
|
271 | emit updated(); | |
272 | } |
|
272 | } | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Sets \a pen used to draw shades. |
|
276 | Sets \a pen used to draw shades. | |
277 | */ |
|
277 | */ | |
278 | void QChartAxis::setShadesPen(const QPen& pen) |
|
278 | void QChartAxis::setShadesPen(const QPen& pen) | |
279 | { |
|
279 | { | |
280 | if(m_shadesPen!=pen) { |
|
280 | if(m_shadesPen!=pen) { | |
281 | m_shadesPen=pen; |
|
281 | m_shadesPen=pen; | |
282 | emit updated(); |
|
282 | emit updated(); | |
283 | } |
|
283 | } | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | /*! |
|
286 | /*! | |
287 | Sets \a brush used to draw shades. |
|
287 | Sets \a brush used to draw shades. | |
288 | */ |
|
288 | */ | |
289 | void QChartAxis::setShadesBrush(const QBrush& brush) |
|
289 | void QChartAxis::setShadesBrush(const QBrush& brush) | |
290 | { |
|
290 | { | |
291 | if(m_shadesBrush!=brush) { |
|
291 | if(m_shadesBrush!=brush) { | |
292 | m_shadesBrush=brush; |
|
292 | m_shadesBrush=brush; | |
293 | emit updated(); |
|
293 | emit updated(); | |
294 | } |
|
294 | } | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | /*! |
|
297 | /*! | |
298 | Sets \a opacity of the shades. |
|
298 | Sets \a opacity of the shades. | |
299 | */ |
|
299 | */ | |
300 | void QChartAxis::setShadesOpacity(qreal opacity) |
|
300 | void QChartAxis::setShadesOpacity(qreal opacity) | |
301 | { |
|
301 | { | |
302 | if(m_shadesOpacity!=opacity) { |
|
302 | if(m_shadesOpacity!=opacity) { | |
303 | m_shadesOpacity=opacity; |
|
303 | m_shadesOpacity=opacity; | |
304 | emit updated(); |
|
304 | emit updated(); | |
305 | } |
|
305 | } | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | /*! |
|
308 | /*! | |
309 | Sets \a min value on the axis. |
|
309 | Sets \a min value on the axis. | |
310 | */ |
|
310 | */ | |
311 | void QChartAxis::setMin(qreal min) |
|
311 | void QChartAxis::setMin(qreal min) | |
312 | { |
|
312 | { | |
313 | setRange(min,m_max); |
|
313 | setRange(min,m_max); | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | /*! |
|
316 | /*! | |
317 | Sets \a max value on the axis. |
|
317 | Sets \a max value on the axis. | |
318 | */ |
|
318 | */ | |
319 | void QChartAxis::setMax(qreal max) |
|
319 | void QChartAxis::setMax(qreal max) | |
320 | { |
|
320 | { | |
321 | setRange(m_min,max); |
|
321 | setRange(m_min,max); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | /*! |
|
324 | /*! | |
325 | Sets range from \a min to \a max on the axis. |
|
325 | Sets range from \a min to \a max on the axis. | |
326 | */ |
|
326 | */ | |
327 | void QChartAxis::setRange(qreal min, qreal max) |
|
327 | void QChartAxis::setRange(qreal min, qreal max) | |
328 | { |
|
328 | { | |
329 |
|
329 | |||
330 |
|
330 | |||
331 | bool changed = false; |
|
331 | bool changed = false; | |
332 | if(m_min!=min) { |
|
332 | if(m_min!=min) { | |
333 | m_min=min; |
|
333 | m_min=min; | |
334 | changed=true; |
|
334 | changed=true; | |
335 | emit minChanged(min); |
|
335 | emit minChanged(min); | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | if(m_max!=max) { |
|
338 | if(m_max!=max) { | |
339 | m_max=max; |
|
339 | m_max=max; | |
340 | changed=true; |
|
340 | changed=true; | |
341 | emit maxChanged(max); |
|
341 | emit maxChanged(max); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | if(changed) { |
|
344 | if(changed) { | |
345 | emit rangeChanged(m_min,m_max); |
|
345 | emit rangeChanged(m_min,m_max); | |
346 | } |
|
346 | } | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | /*! |
|
349 | /*! | |
350 | Sets \a count for ticks on the axis. |
|
350 | Sets \a count for ticks on the axis. | |
351 | */ |
|
351 | */ | |
352 | void QChartAxis::setTicksCount(int count) |
|
352 | void QChartAxis::setTicksCount(int count) | |
353 | { |
|
353 | { | |
354 | if(m_ticksCount!=count) { |
|
354 | if(m_ticksCount!=count) { | |
355 | m_ticksCount=count; |
|
355 | m_ticksCount=count; | |
356 | emit ticksCountChanged(count); |
|
356 | emit ticksCountChanged(count); | |
357 | } |
|
357 | } | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | /*! |
|
360 | /*! | |
361 | Sets axis, shades, labels and grid lines to be visible. |
|
361 | Sets axis, shades, labels and grid lines to be visible. | |
362 | */ |
|
362 | */ | |
363 | void QChartAxis::show() |
|
363 | void QChartAxis::show() | |
364 | { |
|
364 | { | |
365 | m_axisVisible=true; |
|
365 | m_axisVisible=true; | |
366 | m_gridLineVisible=true; |
|
366 | m_gridLineVisible=true; | |
367 | m_labelsVisible=true; |
|
367 | m_labelsVisible=true; | |
368 | m_shadesVisible=true; |
|
368 | m_shadesVisible=true; | |
369 | emit updated(); |
|
369 | emit updated(); | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | /*! |
|
372 | /*! | |
373 | Sets axis, shades, labels and grid lines to not be visible. |
|
373 | Sets axis, shades, labels and grid lines to not be visible. | |
374 | */ |
|
374 | */ | |
375 | void QChartAxis::hide() |
|
375 | void QChartAxis::hide() | |
376 | { |
|
376 | { | |
377 | m_axisVisible=false; |
|
377 | m_axisVisible=false; | |
378 | m_gridLineVisible=false; |
|
378 | m_gridLineVisible=false; | |
379 | m_labelsVisible=false; |
|
379 | m_labelsVisible=false; | |
380 | m_shadesVisible=false; |
|
380 | m_shadesVisible=false; | |
381 | emit updated(); |
|
381 | emit updated(); | |
382 | } |
|
382 | } | |
383 |
|
383 | |||
384 | void QChartAxis::handleAxisRangeChanged(qreal min, qreal max) |
|
384 | void QChartAxis::handleAxisRangeChanged(qreal min, qreal max) | |
385 | { |
|
385 | { | |
386 | qDebug()<<__FUNCTION__<<min<<max; |
|
|||
387 | setRange(min,max); |
|
386 | setRange(min,max); | |
388 | } |
|
387 | } | |
389 |
|
388 | |||
390 | void QChartAxis::handleAxisTicksChanged(int count) |
|
389 | void QChartAxis::handleAxisTicksChanged(int count) | |
391 | { |
|
390 | { | |
392 | setTicksCount(count); |
|
391 | setTicksCount(count); | |
393 | } |
|
392 | } | |
394 |
|
393 | |||
395 | #include "moc_qchartaxis.cpp" |
|
394 | #include "moc_qchartaxis.cpp" | |
396 |
|
395 | |||
397 | QTCOMMERCIALCHART_END_NAMESPACE |
|
396 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now