##// END OF EJS Templates
Fix labels, shades visible naming convention
Michal Klocek -
r365:884af9f4ef86
parent child
Show More
@@ -1,335 +1,335
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 <QPainter>
4 #include <QPainter>
5 #include <QDebug>
5 #include <QDebug>
6
6
7 static int label_padding = 5;
7 static int label_padding = 5;
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) :
11 AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) :
12 ChartItem(parent),
12 ChartItem(parent),
13 m_type(type),
13 m_type(type),
14 m_labelsAngle(0),
14 m_labelsAngle(0),
15 m_grid(parent),
15 m_grid(parent),
16 m_shades(parent),
16 m_shades(parent),
17 m_labels(parent),
17 m_labels(parent),
18 m_axis(parent)
18 m_axis(parent)
19 {
19 {
20 //initial initialization
20 //initial initialization
21 m_axis.setZValue(ChartPresenter::AxisZValue);
21 m_axis.setZValue(ChartPresenter::AxisZValue);
22 m_shades.setZValue(ChartPresenter::ShadesZValue);
22 m_shades.setZValue(ChartPresenter::ShadesZValue);
23 m_grid.setZValue(ChartPresenter::GridZValue);
23 m_grid.setZValue(ChartPresenter::GridZValue);
24 setFlags(QGraphicsItem::ItemHasNoContents);
24 setFlags(QGraphicsItem::ItemHasNoContents);
25 }
25 }
26
26
27 AxisItem::~AxisItem()
27 AxisItem::~AxisItem()
28 {
28 {
29 }
29 }
30
30
31 QRectF AxisItem::boundingRect() const
31 QRectF AxisItem::boundingRect() const
32 {
32 {
33 return QRectF();
33 return QRectF();
34 }
34 }
35
35
36 void AxisItem::createItems(int count)
36 void AxisItem::createItems(int count)
37 {
37 {
38 if(m_axis.children().size()==0)
38 if(m_axis.children().size()==0)
39 m_axis.addToGroup(new QGraphicsLineItem());
39 m_axis.addToGroup(new QGraphicsLineItem());
40 for (int i = 0; i < count; ++i) {
40 for (int i = 0; i < count; ++i) {
41 m_grid.addToGroup(new QGraphicsLineItem());
41 m_grid.addToGroup(new QGraphicsLineItem());
42 m_labels.addToGroup(new QGraphicsSimpleTextItem());
42 m_labels.addToGroup(new QGraphicsSimpleTextItem());
43 if(m_grid.childItems().size()%2) m_shades.addToGroup(new QGraphicsRectItem());
43 if(m_grid.childItems().size()%2) m_shades.addToGroup(new QGraphicsRectItem());
44 m_axis.addToGroup(new QGraphicsLineItem());
44 m_axis.addToGroup(new QGraphicsLineItem());
45 }
45 }
46 }
46 }
47
47
48 void AxisItem::clear(int count)
48 void AxisItem::clear(int count)
49 {
49 {
50 QList<QGraphicsItem *> lines = m_grid.childItems();
50 QList<QGraphicsItem *> lines = m_grid.childItems();
51 QList<QGraphicsItem *> labels = m_labels.childItems();
51 QList<QGraphicsItem *> labels = m_labels.childItems();
52 QList<QGraphicsItem *> shades = m_shades.childItems();
52 QList<QGraphicsItem *> shades = m_shades.childItems();
53 QList<QGraphicsItem *> axis = m_axis.childItems();
53 QList<QGraphicsItem *> axis = m_axis.childItems();
54
54
55 for (int i = 0; i < count; ++i) {
55 for (int i = 0; i < count; ++i) {
56 delete(lines.takeLast());
56 delete(lines.takeLast());
57 delete(labels.takeLast());
57 delete(labels.takeLast());
58 if(lines.size()%2) delete(shades.takeLast());
58 if(lines.size()%2) delete(shades.takeLast());
59 delete(axis.takeLast());
59 delete(axis.takeLast());
60 }
60 }
61
61
62 m_thicksList.clear();
62 m_thicksList.clear();
63
63
64 }
64 }
65
65
66 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
66 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
67 {
67 {
68 Q_UNUSED(painter);
68 Q_UNUSED(painter);
69 Q_UNUSED(option);
69 Q_UNUSED(option);
70 Q_UNUSED(widget);
70 Q_UNUSED(widget);
71 }
71 }
72
72
73 void AxisItem::updateItems(QVector<qreal>& vector)
73 void AxisItem::updateItems(QVector<qreal>& vector)
74 {
74 {
75 calculateLayout(vector);
75 calculateLayout(vector);
76 if(vector.count()==0) return;
76 if(vector.count()==0) return;
77 applyLayout(vector);
77 applyLayout(vector);
78 }
78 }
79
79
80 void AxisItem::handleAxisUpdate(QChartAxis* axis)
80 void AxisItem::handleAxisUpdate(QChartAxis* axis)
81 {
81 {
82 if(m_layoutVector.count()==0) return;
82 if(m_layoutVector.count()==0) return;
83
83
84 if(axis->isAxisVisible()) {
84 if(axis->isAxisVisible()) {
85 setAxisOpacity(100);
85 setAxisOpacity(100);
86 }
86 }
87 else {
87 else {
88 setAxisOpacity(0);
88 setAxisOpacity(0);
89 }
89 }
90
90
91 if(axis->isGridVisible()) {
91 if(axis->isGridVisible()) {
92 setGridOpacity(100);
92 setGridOpacity(100);
93 }
93 }
94 else {
94 else {
95 setGridOpacity(0);
95 setGridOpacity(0);
96 }
96 }
97
97
98 if(axis->isLabelsVisible())
98 if(axis->labelsVisible())
99 {
99 {
100 setLabelsOpacity(100);
100 setLabelsOpacity(100);
101 }
101 }
102 else {
102 else {
103 setLabelsOpacity(0);
103 setLabelsOpacity(0);
104 }
104 }
105
105
106 if(axis->isShadesVisible()) {
106 if(axis->shadesVisible()) {
107 setShadesOpacity(axis->shadesOpacity());
107 setShadesOpacity(axis->shadesOpacity());
108 }
108 }
109 else {
109 else {
110 setShadesOpacity(0);
110 setShadesOpacity(0);
111 }
111 }
112
112
113 setLabelsAngle(axis->labelsAngle());
113 setLabelsAngle(axis->labelsAngle());
114 setAxisPen(axis->axisPen());
114 setAxisPen(axis->axisPen());
115 setLabelsPen(axis->labelsPen());
115 setLabelsPen(axis->labelsPen());
116 setLabelsBrush(axis->labelsBrush());
116 setLabelsBrush(axis->labelsBrush());
117 setLabelsFont(axis->labelsFont());
117 setLabelsFont(axis->labelsFont());
118 setGridPen(axis->gridPen());
118 setGridPen(axis->gridPen());
119 setShadesPen(axis->shadesPen());
119 setShadesPen(axis->shadesPen());
120 setShadesBrush(axis->shadesBrush());
120 setShadesBrush(axis->shadesBrush());
121 }
121 }
122
122
123 void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels)
123 void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels)
124 {
124 {
125 int diff = m_thicksList.size() - labels.size();
125 int diff = m_thicksList.size() - labels.size();
126
126
127 if(diff>0){
127 if(diff>0){
128 clear(diff);
128 clear(diff);
129 }else if(diff<0){
129 }else if(diff<0){
130 createItems(-diff);
130 createItems(-diff);
131 }
131 }
132 m_thicksList=labels;
132 m_thicksList=labels;
133 m_layoutVector.resize(m_thicksList.size());
133 m_layoutVector.resize(m_thicksList.size());
134 updateItems(m_layoutVector);
134 updateItems(m_layoutVector);
135 if(diff!=0) handleAxisUpdate(axis);
135 if(diff!=0) handleAxisUpdate(axis);
136 }
136 }
137
137
138 void AxisItem::handleGeometryChanged(const QRectF& rect)
138 void AxisItem::handleGeometryChanged(const QRectF& rect)
139 {
139 {
140 m_rect = rect;
140 m_rect = rect;
141 updateItems(m_layoutVector);
141 updateItems(m_layoutVector);
142 }
142 }
143
143
144 void AxisItem::setAxisOpacity(qreal opacity)
144 void AxisItem::setAxisOpacity(qreal opacity)
145 {
145 {
146 m_axis.setOpacity(opacity);
146 m_axis.setOpacity(opacity);
147 }
147 }
148
148
149 qreal AxisItem::axisOpacity() const
149 qreal AxisItem::axisOpacity() const
150 {
150 {
151 return m_axis.opacity();
151 return m_axis.opacity();
152 }
152 }
153
153
154 void AxisItem::setGridOpacity(qreal opacity)
154 void AxisItem::setGridOpacity(qreal opacity)
155 {
155 {
156 m_grid.setOpacity(opacity);
156 m_grid.setOpacity(opacity);
157 }
157 }
158
158
159 qreal AxisItem::gridOpacity() const
159 qreal AxisItem::gridOpacity() const
160 {
160 {
161 return m_grid.opacity();
161 return m_grid.opacity();
162 }
162 }
163
163
164 void AxisItem::setLabelsOpacity(qreal opacity)
164 void AxisItem::setLabelsOpacity(qreal opacity)
165 {
165 {
166 m_labels.setOpacity(opacity);
166 m_labels.setOpacity(opacity);
167 }
167 }
168
168
169 qreal AxisItem::labelsOpacity() const
169 qreal AxisItem::labelsOpacity() const
170 {
170 {
171 return m_labels.opacity();
171 return m_labels.opacity();
172 }
172 }
173
173
174 void AxisItem::setShadesOpacity(qreal opacity)
174 void AxisItem::setShadesOpacity(qreal opacity)
175 {
175 {
176 m_shades.setOpacity(opacity);
176 m_shades.setOpacity(opacity);
177 }
177 }
178
178
179 qreal AxisItem::shadesOpacity() const
179 qreal AxisItem::shadesOpacity() const
180 {
180 {
181 return m_shades.opacity();
181 return m_shades.opacity();
182 }
182 }
183
183
184 void AxisItem::setLabelsAngle(int angle)
184 void AxisItem::setLabelsAngle(int angle)
185 {
185 {
186 foreach(QGraphicsItem* item , m_labels.childItems()) {
186 foreach(QGraphicsItem* item , m_labels.childItems()) {
187 QPointF center = item->boundingRect().center();
187 QPointF center = item->boundingRect().center();
188 item->setRotation(angle);
188 item->setRotation(angle);
189 }
189 }
190
190
191 m_labelsAngle=angle;
191 m_labelsAngle=angle;
192 }
192 }
193
193
194 void AxisItem::setLabelsPen(const QPen& pen)
194 void AxisItem::setLabelsPen(const QPen& pen)
195 {
195 {
196 foreach(QGraphicsItem* item , m_labels.childItems()) {
196 foreach(QGraphicsItem* item , m_labels.childItems()) {
197 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
197 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
198 }
198 }
199 }
199 }
200
200
201 void AxisItem::setLabelsBrush(const QBrush& brush)
201 void AxisItem::setLabelsBrush(const QBrush& brush)
202 {
202 {
203 foreach(QGraphicsItem* item , m_labels.childItems()) {
203 foreach(QGraphicsItem* item , m_labels.childItems()) {
204 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
204 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
205 }
205 }
206 }
206 }
207
207
208 void AxisItem::setLabelsFont(const QFont& font)
208 void AxisItem::setLabelsFont(const QFont& font)
209 {
209 {
210 foreach(QGraphicsItem* item , m_labels.childItems()) {
210 foreach(QGraphicsItem* item , m_labels.childItems()) {
211 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
211 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
212 }
212 }
213 }
213 }
214
214
215 void AxisItem::setShadesBrush(const QBrush& brush)
215 void AxisItem::setShadesBrush(const QBrush& brush)
216 {
216 {
217 foreach(QGraphicsItem* item , m_shades.childItems()) {
217 foreach(QGraphicsItem* item , m_shades.childItems()) {
218 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
218 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
219 }
219 }
220 }
220 }
221
221
222 void AxisItem::setShadesPen(const QPen& pen)
222 void AxisItem::setShadesPen(const QPen& pen)
223 {
223 {
224 foreach(QGraphicsItem* item , m_shades.childItems()) {
224 foreach(QGraphicsItem* item , m_shades.childItems()) {
225 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
225 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
226 }
226 }
227 }
227 }
228
228
229 void AxisItem::setAxisPen(const QPen& pen)
229 void AxisItem::setAxisPen(const QPen& pen)
230 {
230 {
231 foreach(QGraphicsItem* item , m_axis.childItems()) {
231 foreach(QGraphicsItem* item , m_axis.childItems()) {
232 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
232 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
233 }
233 }
234 }
234 }
235
235
236 void AxisItem::setGridPen(const QPen& pen)
236 void AxisItem::setGridPen(const QPen& pen)
237 {
237 {
238 foreach(QGraphicsItem* item , m_grid.childItems()) {
238 foreach(QGraphicsItem* item , m_grid.childItems()) {
239 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
239 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
240 }
240 }
241 }
241 }
242
242
243 void AxisItem::calculateLayout(QVector<qreal>& points)
243 void AxisItem::calculateLayout(QVector<qreal>& points)
244 {
244 {
245 switch (m_type)
245 switch (m_type)
246 {
246 {
247 case X_AXIS:
247 case X_AXIS:
248 {
248 {
249 const qreal deltaX = m_rect.width()/(m_thicksList.size()-1);
249 const qreal deltaX = m_rect.width()/(m_thicksList.size()-1);
250 for (int i = 0; i < m_thicksList.size(); ++i) {
250 for (int i = 0; i < m_thicksList.size(); ++i) {
251 int x = i * deltaX + m_rect.left();
251 int x = i * deltaX + m_rect.left();
252 points[i]=x;
252 points[i]=x;
253 }
253 }
254 }
254 }
255 break;
255 break;
256 case Y_AXIS:
256 case Y_AXIS:
257 {
257 {
258 const qreal deltaY = m_rect.height()/(m_thicksList.size()-1);
258 const qreal deltaY = m_rect.height()/(m_thicksList.size()-1);
259 for (int i = 0; i < m_thicksList.size(); ++i) {
259 for (int i = 0; i < m_thicksList.size(); ++i) {
260 int y = i * -deltaY + m_rect.bottom();
260 int y = i * -deltaY + m_rect.bottom();
261 points[i]=y;
261 points[i]=y;
262 }
262 }
263 }
263 }
264 break;
264 break;
265 }
265 }
266 }
266 }
267
267
268 void AxisItem::applyLayout(const QVector<qreal>& points)
268 void AxisItem::applyLayout(const QVector<qreal>& points)
269 {
269 {
270 Q_ASSERT(points.size() == m_thicksList.size());
270 Q_ASSERT(points.size() == m_thicksList.size());
271
271
272 QList<QGraphicsItem *> lines = m_grid.childItems();
272 QList<QGraphicsItem *> lines = m_grid.childItems();
273 QList<QGraphicsItem *> labels = m_labels.childItems();
273 QList<QGraphicsItem *> labels = m_labels.childItems();
274 QList<QGraphicsItem *> shades = m_shades.childItems();
274 QList<QGraphicsItem *> shades = m_shades.childItems();
275 QList<QGraphicsItem *> axis = m_axis.childItems();
275 QList<QGraphicsItem *> axis = m_axis.childItems();
276
276
277 Q_ASSERT(labels.size() == m_thicksList.size());
277 Q_ASSERT(labels.size() == m_thicksList.size());
278
278
279 switch (m_type)
279 switch (m_type)
280 {
280 {
281 case X_AXIS:
281 case X_AXIS:
282 {
282 {
283 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
283 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
284 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
284 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
285
285
286 for (int i = 0; i < points.size(); ++i) {
286 for (int i = 0; i < points.size(); ++i) {
287 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
287 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
288 lineItem->setLine(points[i], m_rect.top(), points[i], m_rect.bottom());
288 lineItem->setLine(points[i], m_rect.top(), points[i], m_rect.bottom());
289 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
289 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
290 labelItem->setText(m_thicksList.at(i));
290 labelItem->setText(m_thicksList.at(i));
291 QPointF center = labelItem->boundingRect().center();
291 QPointF center = labelItem->boundingRect().center();
292 labelItem->setTransformOriginPoint(center.x(), center.y());
292 labelItem->setTransformOriginPoint(center.x(), center.y());
293 labelItem->setPos(points[i] - center.x(), m_rect.bottom() + label_padding);
293 labelItem->setPos(points[i] - center.x(), m_rect.bottom() + label_padding);
294 if(i%2){
294 if(i%2){
295 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
295 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
296 rectItem->setRect(points[i],m_rect.top(),points[i+1]-points[i],m_rect.height());
296 rectItem->setRect(points[i],m_rect.top(),points[i+1]-points[i],m_rect.height());
297 }
297 }
298 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
298 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
299 lineItem->setLine(points[i],m_rect.bottom(),points[i],m_rect.bottom()+5);
299 lineItem->setLine(points[i],m_rect.bottom(),points[i],m_rect.bottom()+5);
300 }
300 }
301 }
301 }
302 break;
302 break;
303
303
304 case Y_AXIS:
304 case Y_AXIS:
305 {
305 {
306 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
306 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
307 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
307 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
308
308
309 for (int i = 0; i < points.size(); ++i) {
309 for (int i = 0; i < points.size(); ++i) {
310 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
310 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
311 lineItem->setLine(m_rect.left() , points[i], m_rect.right(), points[i]);
311 lineItem->setLine(m_rect.left() , points[i], m_rect.right(), points[i]);
312 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
312 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
313 labelItem->setText(m_thicksList.at(i));
313 labelItem->setText(m_thicksList.at(i));
314 QPointF center = labelItem->boundingRect().center();
314 QPointF center = labelItem->boundingRect().center();
315 labelItem->setTransformOriginPoint(center.x(), center.y());
315 labelItem->setTransformOriginPoint(center.x(), center.y());
316 labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , points[i]-center.y());
316 labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , points[i]-center.y());
317 if(i%2){
317 if(i%2){
318 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
318 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
319 rectItem->setRect(m_rect.left(),points[i],m_rect.width(),points[i]-points[i+1]);
319 rectItem->setRect(m_rect.left(),points[i],m_rect.width(),points[i]-points[i+1]);
320 }
320 }
321 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
321 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
322 lineItem->setLine(m_rect.left()-5,points[i],m_rect.left(),points[i]);
322 lineItem->setLine(m_rect.left()-5,points[i],m_rect.left(),points[i]);
323 }
323 }
324 }
324 }
325 break;
325 break;
326 default:
326 default:
327 qDebug()<<"Unknown axis type";
327 qDebug()<<"Unknown axis type";
328 break;
328 break;
329 }
329 }
330 }
330 }
331
331
332 //TODO "nice numbers algorithm"
332 //TODO "nice numbers algorithm"
333 #include "moc_axisitem_p.cpp"
333 #include "moc_axisitem_p.cpp"
334
334
335 QTCOMMERCIALCHART_END_NAMESPACE
335 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,353 +1,353
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::isGridVisible() const
31 \fn bool QChartAxis::isGridVisible() const
32 \brief Returns if grid is visible
32 \brief Returns if grid is visible
33 \sa setGridVisible()
33 \sa setGridVisible()
34 */
34 */
35
35
36 /*!
36 /*!
37 \fn QPen QChartAxis::gridPen() const
37 \fn QPen QChartAxis::gridPen() const
38 \brief Returns pen used to draw grid.
38 \brief Returns pen used to draw grid.
39 \sa setGridPen()
39 \sa setGridPen()
40 */
40 */
41
41
42 /*!
42 /*!
43 \fn bool QChartAxis::isLabelsVisible() 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::isShadesVisible() 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 \fn int QChartAxis::ticksCount() const
117 \fn int QChartAxis::ticksCount() const
118 \brief Return number of ticks on the axis
118 \brief Return number of ticks on the axis
119 \sa setTicksCount()
119 \sa setTicksCount()
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn void QChartAxis::update(QChartAxis*)
123 \fn void QChartAxis::update(QChartAxis*)
124 \brief \internal
124 \brief \internal
125 */
125 */
126
126
127 /*!
127 /*!
128 \fn void QChartAxis::ticksChanged(QChartAxis*)
128 \fn void QChartAxis::ticksChanged(QChartAxis*)
129 \brief \internal
129 \brief \internal
130 */
130 */
131
131
132 /*!
132 /*!
133 Constructs new axis object which is a child of \a parent. Ownership is taken by
133 Constructs new axis object which is a child of \a parent. Ownership is taken by
134 QChatView or QChart when axis added.
134 QChatView or QChart when axis added.
135 */
135 */
136
136
137 QChartAxis::QChartAxis(QObject* parent):QObject(parent),
137 QChartAxis::QChartAxis(QObject* parent):QObject(parent),
138 m_axisVisible(true),
138 m_axisVisible(true),
139 m_gridVisible(true),
139 m_gridVisible(true),
140 m_labelsVisible(true),
140 m_labelsVisible(true),
141 m_labelsAngle(0),
141 m_labelsAngle(0),
142 m_shadesVisible(true),
142 m_shadesVisible(true),
143 m_shadesOpacity(1.0),
143 m_shadesOpacity(1.0),
144 m_min(0),
144 m_min(0),
145 m_max(0),
145 m_max(0),
146 m_ticksCount(5)
146 m_ticksCount(5)
147 {
147 {
148
148
149 }
149 }
150
150
151 /*!
151 /*!
152 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
152 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
153 */
153 */
154
154
155 QChartAxis::~QChartAxis()
155 QChartAxis::~QChartAxis()
156 {
156 {
157 }
157 }
158
158
159 /*!
159 /*!
160 Sets \a pen used to draw axis line and ticks.
160 Sets \a pen used to draw axis line and ticks.
161 */
161 */
162 void QChartAxis::setAxisPen(const QPen& pen)
162 void QChartAxis::setAxisPen(const QPen& pen)
163 {
163 {
164 m_axisPen=pen;
164 m_axisPen=pen;
165 emit update(this);
165 emit update(this);
166 }
166 }
167
167
168 /*!
168 /*!
169 Sets if axis and ticks are \a visible.
169 Sets if axis and ticks are \a visible.
170 */
170 */
171 void QChartAxis::setAxisVisible(bool visible)
171 void QChartAxis::setAxisVisible(bool visible)
172 {
172 {
173 m_axisVisible=visible;
173 m_axisVisible=visible;
174 emit update(this);
174 emit update(this);
175 }
175 }
176
176
177 /*!
177 /*!
178 Sets if grid is \a visible.
178 Sets if grid is \a visible.
179 */
179 */
180 void QChartAxis::setGridVisible(bool visible)
180 void QChartAxis::setGridVisible(bool visible)
181 {
181 {
182 m_gridVisible=visible;
182 m_gridVisible=visible;
183 emit update(this);
183 emit update(this);
184 }
184 }
185
185
186 /*!
186 /*!
187 Sets \a pen used to draw grid.
187 Sets \a pen used to draw grid.
188 */
188 */
189 void QChartAxis::setGridPen(const QPen& pen)
189 void QChartAxis::setGridPen(const QPen& pen)
190 {
190 {
191 m_gridPen=pen;
191 m_gridPen=pen;
192 emit update(this);
192 emit update(this);
193 }
193 }
194
194
195 /*!
195 /*!
196 Sets if axis' labels are \a visible.
196 Sets if axis' labels are \a visible.
197 */
197 */
198 void QChartAxis::setLabelsVisible(bool visible)
198 void QChartAxis::setLabelsVisible(bool visible)
199 {
199 {
200 m_labelsVisible=visible;
200 m_labelsVisible=visible;
201 emit update(this);
201 emit update(this);
202 }
202 }
203
203
204 /*!
204 /*!
205 Sets \a pen used to draw labels.
205 Sets \a pen used to draw labels.
206 */
206 */
207 void QChartAxis::setLabelsPen(const QPen& pen)
207 void QChartAxis::setLabelsPen(const QPen& pen)
208 {
208 {
209 m_labelsPen=pen;
209 m_labelsPen=pen;
210 emit update(this);
210 emit update(this);
211 }
211 }
212
212
213 /*!
213 /*!
214 Sets \a brush used to draw labels.
214 Sets \a brush used to draw labels.
215 */
215 */
216 void QChartAxis::setLabelsBrush(const QBrush& brush)
216 void QChartAxis::setLabelsBrush(const QBrush& brush)
217 {
217 {
218 m_labelsBrush=brush;
218 m_labelsBrush=brush;
219 emit update(this);
219 emit update(this);
220 }
220 }
221
221
222 /*!
222 /*!
223 Sets \a font used to draw labels.
223 Sets \a font used to draw labels.
224 */
224 */
225 void QChartAxis::setLabelsFont(const QFont& font)
225 void QChartAxis::setLabelsFont(const QFont& font)
226 {
226 {
227 m_labelsFont=font;
227 m_labelsFont=font;
228 emit update(this);
228 emit update(this);
229 }
229 }
230
230
231 /*!
231 /*!
232 Sets \a angle for all the labels on given axis.
232 Sets \a angle for all the labels on given axis.
233 */
233 */
234 void QChartAxis::setLabelsAngle(int angle)
234 void QChartAxis::setLabelsAngle(int angle)
235 {
235 {
236 m_labelsAngle=angle;
236 m_labelsAngle=angle;
237 emit update(this);
237 emit update(this);
238 }
238 }
239
239
240 /*!
240 /*!
241 Sets if shades are \a visible.
241 Sets if shades are \a visible.
242 */
242 */
243 void QChartAxis::setShadesVisible(bool visible)
243 void QChartAxis::setShadesVisible(bool visible)
244 {
244 {
245 m_shadesVisible=visible;
245 m_shadesVisible=visible;
246 emit update(this);
246 emit update(this);
247 }
247 }
248
248
249 /*!
249 /*!
250 Sets \a pen used to draw shades.
250 Sets \a pen used to draw shades.
251 */
251 */
252 void QChartAxis::setShadesPen(const QPen& pen)
252 void QChartAxis::setShadesPen(const QPen& pen)
253 {
253 {
254 m_shadesPen=pen;
254 m_shadesPen=pen;
255 emit update(this);
255 emit update(this);
256 }
256 }
257
257
258 /*!
258 /*!
259 Sets \a brush used to draw shades.
259 Sets \a brush used to draw shades.
260 */
260 */
261 void QChartAxis::setShadesBrush(const QBrush& brush)
261 void QChartAxis::setShadesBrush(const QBrush& brush)
262 {
262 {
263 m_shadesBrush=brush;
263 m_shadesBrush=brush;
264 emit update(this);
264 emit update(this);
265 }
265 }
266
266
267 /*!
267 /*!
268 Sets \a opacity of the shades.
268 Sets \a opacity of the shades.
269 */
269 */
270 void QChartAxis::setShadesOpacity(qreal opacity)
270 void QChartAxis::setShadesOpacity(qreal opacity)
271 {
271 {
272 m_shadesOpacity=opacity;
272 m_shadesOpacity=opacity;
273 emit update(this);
273 emit update(this);
274 }
274 }
275
275
276 /*!
276 /*!
277 Sets \a min value on the axis.
277 Sets \a min value on the axis.
278 */
278 */
279 void QChartAxis::setMin(qreal min)
279 void QChartAxis::setMin(qreal min)
280 {
280 {
281 if(m_min!=min){
281 if(m_min!=min){
282 m_min=min;
282 m_min=min;
283 emit minChanged(m_min);
283 emit minChanged(m_min);
284 }
284 }
285 }
285 }
286
286
287 /*!
287 /*!
288 Sets \a max value on the axis.
288 Sets \a max value on the axis.
289 */
289 */
290 void QChartAxis::setMax(qreal max)
290 void QChartAxis::setMax(qreal max)
291 {
291 {
292 if(m_max!=max){
292 if(m_max!=max){
293 m_max=max;
293 m_max=max;
294 emit maxChanged(m_max);
294 emit maxChanged(m_max);
295 }
295 }
296 }
296 }
297
297
298 /*!
298 /*!
299 Sets range from \a min to \a max on the axis.
299 Sets range from \a min to \a max on the axis.
300 */
300 */
301 void QChartAxis::setRange(qreal min, qreal max)
301 void QChartAxis::setRange(qreal min, qreal max)
302 {
302 {
303 setMin(min);
303 setMin(min);
304 setMax(max);
304 setMax(max);
305 }
305 }
306
306
307 /*!
307 /*!
308 Sets \a count for ticks on the axis.
308 Sets \a count for ticks on the axis.
309 */
309 */
310 void QChartAxis::setTicksCount(int count)
310 void QChartAxis::setTicksCount(int count)
311 {
311 {
312 m_ticksCount=count;
312 m_ticksCount=count;
313 emit ticksChanged(this);
313 emit ticksChanged(this);
314 }
314 }
315
315
316 /*!
316 /*!
317 TODO: refactor me. Sets string \a label for \a value on the axis.
317 TODO: refactor me. Sets string \a label for \a value on the axis.
318 */
318 */
319 void QChartAxis::addAxisTickLabel(qreal value,const QString& label)
319 void QChartAxis::addAxisTickLabel(qreal value,const QString& label)
320 {
320 {
321 m_ticks.insert(value,label);
321 m_ticks.insert(value,label);
322 emit ticksChanged(this);
322 emit ticksChanged(this);
323 }
323 }
324
324
325 /*!
325 /*!
326 TODO: refactor me. Removes label for \a value on the axis.
326 TODO: refactor me. Removes label for \a value on the axis.
327 */
327 */
328 void QChartAxis::removeAxisTickLabel(qreal value)
328 void QChartAxis::removeAxisTickLabel(qreal value)
329 {
329 {
330 m_ticks.remove(value);
330 m_ticks.remove(value);
331 emit ticksChanged(this);
331 emit ticksChanged(this);
332 }
332 }
333
333
334 /*!
334 /*!
335 TODO: refactor me. Returns label for \a value on the axis.
335 TODO: refactor me. Returns label for \a value on the axis.
336 */
336 */
337 QString QChartAxis::axisTickLabel(qreal value) const
337 QString QChartAxis::axisTickLabel(qreal value) const
338 {
338 {
339 return m_ticks.value(value);
339 return m_ticks.value(value);
340 }
340 }
341
341
342 /*!
342 /*!
343 TODO: refactor me. Removes all the string labels for on the axis.
343 TODO: refactor me. Removes all the string labels for on the axis.
344 */
344 */
345 void QChartAxis::clearAxisTickLabels()
345 void QChartAxis::clearAxisTickLabels()
346 {
346 {
347 m_ticks.clear();
347 m_ticks.clear();
348 emit ticksChanged(this);
348 emit ticksChanged(this);
349 }
349 }
350
350
351 #include "moc_qchartaxis.cpp"
351 #include "moc_qchartaxis.cpp"
352
352
353 QTCOMMERCIALCHART_END_NAMESPACE
353 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,101 +1,101
1 #ifndef QCHARTAXIS_H_
1 #ifndef QCHARTAXIS_H_
2 #define QCHARTAXIS_H_
2 #define QCHARTAXIS_H_
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <QPen>
5 #include <QPen>
6 #include <QFont>
6 #include <QFont>
7
7
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject
11 class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject
12 {
12 {
13 Q_OBJECT
13 Q_OBJECT
14 public:
14 public:
15 QChartAxis(QObject* parent =0);
15 QChartAxis(QObject* parent =0);
16 ~QChartAxis();
16 ~QChartAxis();
17
17
18 //axis handling
18 //axis handling
19 bool isAxisVisible() const { return m_axisVisible;};
19 bool isAxisVisible() const { return m_axisVisible;};
20 void setAxisVisible(bool visible);
20 void setAxisVisible(bool visible);
21 void setAxisPen(const QPen& pen);
21 void setAxisPen(const QPen& pen);
22 QPen axisPen() const { return m_axisPen;};
22 QPen axisPen() const { return m_axisPen;};
23
23
24 //grid handling
24 //grid handling
25 bool isGridVisible() const { return m_gridVisible;};
25 bool isGridVisible() const { return m_gridVisible;};
26 void setGridVisible(bool visible);
26 void setGridVisible(bool visible);
27 void setGridPen(const QPen& pen);
27 void setGridPen(const QPen& pen);
28 QPen gridPen() const {return m_gridPen;}
28 QPen gridPen() const {return m_gridPen;}
29
29
30 //labels handling
30 //labels handling
31 bool isLabelsVisible() const { return m_labelsVisible;};
31 bool labelsVisible() const { return m_labelsVisible;};
32 void setLabelsVisible(bool visible);
32 void setLabelsVisible(bool visible);
33 void setLabelsPen(const QPen& pen);
33 void setLabelsPen(const QPen& pen);
34 QPen labelsPen() const { return m_labelsPen;}
34 QPen labelsPen() const { return m_labelsPen;}
35 void setLabelsBrush(const QBrush& brush);
35 void setLabelsBrush(const QBrush& brush);
36 QBrush labelsBrush() const { return m_labelsBrush;}
36 QBrush labelsBrush() const { return m_labelsBrush;}
37 void setLabelsFont(const QFont& font);
37 void setLabelsFont(const QFont& font);
38 QFont labelsFont() const { return m_labelsFont;}
38 QFont labelsFont() const { return m_labelsFont;}
39 void setLabelsAngle(int angle);
39 void setLabelsAngle(int angle);
40 int labelsAngle() const { return m_labelsAngle;};
40 int labelsAngle() const { return m_labelsAngle;};
41
41
42 //shades handling
42 //shades handling
43 bool isShadesVisible() const { return m_shadesVisible;};
43 bool shadesVisible() const { return m_shadesVisible;};
44 void setShadesVisible(bool visible);
44 void setShadesVisible(bool visible);
45 void setShadesPen(const QPen& pen);
45 void setShadesPen(const QPen& pen);
46 QPen shadesPen() const { return m_shadesPen;}
46 QPen shadesPen() const { return m_shadesPen;}
47 void setShadesBrush(const QBrush& brush);
47 void setShadesBrush(const QBrush& brush);
48 QBrush shadesBrush() const { return m_shadesBrush;}
48 QBrush shadesBrush() const { return m_shadesBrush;}
49 void setShadesOpacity(qreal opacity);
49 void setShadesOpacity(qreal opacity);
50 qreal shadesOpacity() const { return m_shadesOpacity;}
50 qreal shadesOpacity() const { return m_shadesOpacity;}
51
51
52 //range handling
52 //range handling
53 void setMin(qreal min);
53 void setMin(qreal min);
54 qreal min() const { return m_min;};
54 qreal min() const { return m_min;};
55 void setMax(qreal max);
55 void setMax(qreal max);
56 qreal max() const { return m_max;};
56 qreal max() const { return m_max;};
57 void setRange(qreal min, qreal max);
57 void setRange(qreal min, qreal max);
58
58
59 //ticks handling
59 //ticks handling
60 void setTicksCount(int count);
60 void setTicksCount(int count);
61 int ticksCount() const { return m_ticksCount;}
61 int ticksCount() const { return m_ticksCount;}
62 void addAxisTickLabel(qreal value,const QString& label);
62 void addAxisTickLabel(qreal value,const QString& label);
63 void removeAxisTickLabel(qreal value);
63 void removeAxisTickLabel(qreal value);
64 QString axisTickLabel(qreal value) const ;
64 QString axisTickLabel(qreal value) const ;
65 void clearAxisTickLabels();
65 void clearAxisTickLabels();
66
66
67 signals:
67 signals:
68 void minChanged(qreal min);
68 void minChanged(qreal min);
69 void maxChanged(qreal max);
69 void maxChanged(qreal max);
70 //private signal
70 //private signal
71 void update(QChartAxis*);
71 void update(QChartAxis*);
72 void ticksChanged(QChartAxis*);
72 void ticksChanged(QChartAxis*);
73
73
74 private:
74 private:
75 bool m_axisVisible;
75 bool m_axisVisible;
76 QPen m_axisPen;
76 QPen m_axisPen;
77 QBrush m_axisBrush;
77 QBrush m_axisBrush;
78
78
79 bool m_gridVisible;
79 bool m_gridVisible;
80 QPen m_gridPen;
80 QPen m_gridPen;
81
81
82 bool m_labelsVisible;
82 bool m_labelsVisible;
83 QPen m_labelsPen;
83 QPen m_labelsPen;
84 QBrush m_labelsBrush;
84 QBrush m_labelsBrush;
85 QFont m_labelsFont;
85 QFont m_labelsFont;
86 int m_labelsAngle;
86 int m_labelsAngle;
87
87
88 bool m_shadesVisible;
88 bool m_shadesVisible;
89 QPen m_shadesPen;
89 QPen m_shadesPen;
90 QBrush m_shadesBrush;
90 QBrush m_shadesBrush;
91 qreal m_shadesOpacity;
91 qreal m_shadesOpacity;
92
92
93 qreal m_min;
93 qreal m_min;
94 qreal m_max;
94 qreal m_max;
95
95
96 int m_ticksCount;
96 int m_ticksCount;
97 QMap<qreal, QString> m_ticks;
97 QMap<qreal, QString> m_ticks;
98 };
98 };
99
99
100 QTCOMMERCIALCHART_END_NAMESPACE
100 QTCOMMERCIALCHART_END_NAMESPACE
101 #endif /* QCHARTAXIS_H_ */
101 #endif /* QCHARTAXIS_H_ */
General Comments 0
You need to be logged in to leave comments. Login now