##// END OF EJS Templates
Adds ScopedPointer for axis title element
Michal Klocek -
r2141:f4b9e33f4ebb
parent child
Show More
@@ -1,201 +1,201
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTAXIS_H
30 #ifndef CHARTAXIS_H
31 #define CHARTAXIS_H
31 #define CHARTAXIS_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "chartelement_p.h"
34 #include "chartelement_p.h"
35 #include "axisanimation_p.h"
35 #include "axisanimation_p.h"
36 #include <QGraphicsItem>
36 #include <QGraphicsItem>
37 #include <QGraphicsLayoutItem>
37 #include <QGraphicsLayoutItem>
38 #include <QFont>
38 #include <QFont>
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 class QAbstractAxis;
42 class QAbstractAxis;
43 class ChartPresenter;
43 class ChartPresenter;
44
44
45 class ChartAxis : public ChartElement, public QGraphicsLayoutItem
45 class ChartAxis : public ChartElement, public QGraphicsLayoutItem
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 Q_INTERFACES(QGraphicsLayoutItem)
48 Q_INTERFACES(QGraphicsLayoutItem)
49 public:
49 public:
50
50
51 ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false);
51 ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false);
52 ~ChartAxis();
52 ~ChartAxis();
53
53
54 QAbstractAxis* axis() const { return m_chartAxis; }
54 QAbstractAxis* axis() const { return m_chartAxis; }
55
55
56 void setArrowOpacity(qreal opacity);
56 void setArrowOpacity(qreal opacity);
57 qreal arrowOpacity() const;
57 qreal arrowOpacity() const;
58 void setArrowVisibility(bool visible);
58 void setArrowVisibility(bool visible);
59
59
60 void setGridOpacity(qreal opacity);
60 void setGridOpacity(qreal opacity);
61 qreal gridOpacity() const;
61 qreal gridOpacity() const;
62 void setGridVisibility(bool visible);
62 void setGridVisibility(bool visible);
63
63
64 void setLabelsOpacity(qreal opacity);
64 void setLabelsOpacity(qreal opacity);
65 qreal labelsOpacity() const;
65 qreal labelsOpacity() const;
66 void setLabelsVisibility(bool visible);
66 void setLabelsVisibility(bool visible);
67
67
68 void setShadesOpacity(qreal opacity);
68 void setShadesOpacity(qreal opacity);
69 qreal shadesOpacity() const;
69 qreal shadesOpacity() const;
70 void setShadesVisibility(bool visible);
70 void setShadesVisibility(bool visible);
71
71
72 void setLabelsAngle(int angle);
72 void setLabelsAngle(int angle);
73 int labelsAngle()const { return m_labelsAngle; }
73 int labelsAngle()const { return m_labelsAngle; }
74
74
75 void setShadesBrush(const QBrush &brush);
75 void setShadesBrush(const QBrush &brush);
76 void setShadesPen(const QPen &pen);
76 void setShadesPen(const QPen &pen);
77
77
78 void setArrowPen(const QPen &pen);
78 void setArrowPen(const QPen &pen);
79 void setGridPen(const QPen &pen);
79 void setGridPen(const QPen &pen);
80
80
81 void setLabelsPen(const QPen &pen);
81 void setLabelsPen(const QPen &pen);
82 void setLabelsBrush(const QBrush &brush);
82 void setLabelsBrush(const QBrush &brush);
83 void setLabelsFont(const QFont &font);
83 void setLabelsFont(const QFont &font);
84 void setLabelPadding(int padding);
84 void setLabelPadding(int padding);
85 int labelPadding() const { return m_labelPadding;};
85 int labelPadding() const { return m_labelPadding;};
86
86
87 void setTitlePen(const QPen &pen);
87 void setTitlePen(const QPen &pen);
88 void setTitleBrush(const QBrush &brush);
88 void setTitleBrush(const QBrush &brush);
89 void setTitleFont(const QFont &font);
89 void setTitleFont(const QFont &font);
90 QFont titleFont() const { return m_titleFont; };
90 QFont titleFont() const { return m_titleFont; };
91 void setTitleText(const QString &title);
91 void setTitleText(const QString &title);
92 QString titleText() const {return m_titleText; };
92 QString titleText() const {return m_titleText; };
93
93
94 void setLayout(QVector<qreal> &layout);
94 void setLayout(QVector<qreal> &layout);
95 QVector<qreal> layout() const { return m_layoutVector; }
95 QVector<qreal> layout() const { return m_layoutVector; }
96
96
97 void setAnimation(AxisAnimation *animation);
97 void setAnimation(AxisAnimation *animation);
98 ChartAnimation *animation() const { return m_animation; };
98 ChartAnimation *animation() const { return m_animation; };
99
99
100 Qt::Orientation orientation() const;
100 Qt::Orientation orientation() const;
101 Qt::Alignment alignment() const;
101 Qt::Alignment alignment() const;
102
102
103 bool isVisible();
103 bool isVisible();
104 void hide();
104 void hide();
105
105
106 void setGeometry(const QRectF &axis, const QRectF &grid);
106 void setGeometry(const QRectF &axis, const QRectF &grid);
107 QRectF axisGeometry() const { return m_axisRect; }
107 QRectF axisGeometry() const { return m_axisRect; }
108 QRectF gridGeometry() const { return m_gridRect; }
108 QRectF gridGeometry() const { return m_gridRect; }
109
109
110 void setLabels(const QStringList &labels);
110 void setLabels(const QStringList &labels);
111 QStringList labels() const { return m_labelsList; }
111 QStringList labels() const { return m_labelsList; }
112
112
113 //this flag indicates that axis is used to show intervals it means labels are in between ticks
113 //this flag indicates that axis is used to show intervals it means labels are in between ticks
114 bool intervalAxis() const { return m_intervalAxis; }
114 bool intervalAxis() const { return m_intervalAxis; }
115
115
116 virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
116 virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
117
117
118 protected:
118 protected:
119 void setGeometry(const QRectF &size) { Q_UNUSED(size);};
119 void setGeometry(const QRectF &size) { Q_UNUSED(size);};
120 virtual void updateGeometry() = 0;
120 virtual void updateGeometry() = 0;
121 virtual QVector<qreal> calculateLayout() const = 0;
121 virtual QVector<qreal> calculateLayout() const = 0;
122
122
123 QList<QGraphicsItem *> lineItems() { return m_grid->childItems(); };
123 QList<QGraphicsItem *> lineItems() { return m_grid->childItems(); };
124 QList<QGraphicsItem *> labelItems() { return m_labels->childItems();};
124 QList<QGraphicsItem *> labelItems() { return m_labels->childItems();};
125 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();};
125 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();};
126 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();};
126 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();};
127 QGraphicsSimpleTextItem* titleItem() const { return m_title;}
127 QGraphicsSimpleTextItem* titleItem() const { return m_title.data();}
128
128
129 QFont font() const { return m_font; }
129 QFont font() const { return m_font; }
130 qreal min() const {return m_min; }
130 qreal min() const {return m_min; }
131 qreal max() const {return m_max; }
131 qreal max() const {return m_max; }
132 QStringList createValueLabels(int ticks) const;
132 QStringList createValueLabels(int ticks) const;
133 QStringList createDateTimeLabels(const QString &format, int ticks) const;
133 QStringList createDateTimeLabels(const QString &format, int ticks) const;
134
134
135 public Q_SLOTS:
135 public Q_SLOTS:
136 virtual void handleAxisUpdated();
136 virtual void handleAxisUpdated();
137 virtual void handleDomainUpdated();
137 virtual void handleDomainUpdated();
138
138
139 private:
139 private:
140 inline bool isEmpty();
140 inline bool isEmpty();
141 void createItems(int count);
141 void createItems(int count);
142 void deleteItems(int count);
142 void deleteItems(int count);
143 void updateLayout(QVector<qreal> &layout);
143 void updateLayout(QVector<qreal> &layout);
144 void axisSelected();
144 void axisSelected();
145
145
146 private:
146 private:
147 QAbstractAxis *m_chartAxis;
147 QAbstractAxis *m_chartAxis;
148 int m_labelsAngle;
148 int m_labelsAngle;
149 QRectF m_axisRect;
149 QRectF m_axisRect;
150 QRectF m_gridRect;
150 QRectF m_gridRect;
151 QScopedPointer<QGraphicsItemGroup> m_grid;
151 QScopedPointer<QGraphicsItemGroup> m_grid;
152 QScopedPointer<QGraphicsItemGroup> m_shades;
152 QScopedPointer<QGraphicsItemGroup> m_shades;
153 QScopedPointer<QGraphicsItemGroup> m_labels;
153 QScopedPointer<QGraphicsItemGroup> m_labels;
154 QScopedPointer<QGraphicsItemGroup> m_arrow;
154 QScopedPointer<QGraphicsItemGroup> m_arrow;
155 QGraphicsSimpleTextItem *m_title;
155 QScopedPointer<QGraphicsSimpleTextItem> m_title;
156 QVector<qreal> m_layoutVector;
156 QVector<qreal> m_layoutVector;
157 qreal m_min;
157 qreal m_min;
158 qreal m_max;
158 qreal m_max;
159 AxisAnimation *m_animation;
159 AxisAnimation *m_animation;
160 QFont m_font;
160 QFont m_font;
161 QFont m_titleFont;
161 QFont m_titleFont;
162 QString m_titleText;
162 QString m_titleText;
163 int m_labelPadding;
163 int m_labelPadding;
164 QStringList m_labelsList;
164 QStringList m_labelsList;
165 bool m_intervalAxis;
165 bool m_intervalAxis;
166
166
167 friend class AxisAnimation;
167 friend class AxisAnimation;
168 friend class AxisItem;
168 friend class AxisItem;
169
169
170 };
170 };
171
171
172 class AxisItem: public QGraphicsLineItem
172 class AxisItem: public QGraphicsLineItem
173 {
173 {
174
174
175 public:
175 public:
176 explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {}
176 explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {}
177
177
178 protected:
178 protected:
179 void mousePressEvent(QGraphicsSceneMouseEvent *event) {
179 void mousePressEvent(QGraphicsSceneMouseEvent *event) {
180 Q_UNUSED(event)
180 Q_UNUSED(event)
181 m_axis->axisSelected();
181 m_axis->axisSelected();
182 }
182 }
183
183
184 QRectF boundingRect() const {
184 QRectF boundingRect() const {
185 return shape().boundingRect();
185 return shape().boundingRect();
186 }
186 }
187
187
188 QPainterPath shape() const {
188 QPainterPath shape() const {
189 QPainterPath path = QGraphicsLineItem::shape();
189 QPainterPath path = QGraphicsLineItem::shape();
190 QRectF rect = path.boundingRect();
190 QRectF rect = path.boundingRect();
191 path.addRect(rect.adjusted(0, 0, m_axis->orientation() != Qt::Horizontal ? 8 : 0, m_axis->orientation() != Qt::Vertical ? 8 : 0));
191 path.addRect(rect.adjusted(0, 0, m_axis->orientation() != Qt::Horizontal ? 8 : 0, m_axis->orientation() != Qt::Vertical ? 8 : 0));
192 return path;
192 return path;
193 }
193 }
194
194
195 private:
195 private:
196 ChartAxis *m_axis;
196 ChartAxis *m_axis;
197 };
197 };
198
198
199 QTCOMMERCIALCHART_END_NAMESPACE
199 QTCOMMERCIALCHART_END_NAMESPACE
200
200
201 #endif /* CHARTAXI_H */
201 #endif /* CHARTAXI_H */
General Comments 0
You need to be logged in to leave comments. Login now