##// END OF EJS Templates
Adds axis scoped pointers (to be checked on windows)
Michal Klocek -
r788:bfedfc6138fd
parent child
Show More
@@ -1,123 +1,123
1 #ifndef AXISITEM_H_
1 #ifndef AXISITEM_H_
2 #define AXISITEM_H_
2 #define AXISITEM_H_
3
3
4 #include "chart_p.h"
4 #include "chart_p.h"
5 #include <QGraphicsItem>
5 #include <QGraphicsItem>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 class QChartAxis;
9 class QChartAxis;
10 class ChartPresenter;
10 class ChartPresenter;
11
11
12 class Axis : public Chart
12 class Axis : public Chart
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 public:
15 public:
16 enum AxisType{X_AXIS,Y_AXIS};
16 enum AxisType{X_AXIS,Y_AXIS};
17
17
18 Axis(QChartAxis *axis, ChartPresenter *presenter, AxisType type = X_AXIS);
18 Axis(QChartAxis *axis, ChartPresenter *presenter, AxisType type = X_AXIS);
19 ~Axis();
19 ~Axis();
20
20
21 AxisType axisType() const { return m_type; }
21 AxisType axisType() const { return m_type; }
22
22
23 void setAxisOpacity(qreal opacity);
23 void setAxisOpacity(qreal opacity);
24 qreal axisOpacity() const;
24 qreal axisOpacity() const;
25
25
26 void setGridOpacity(qreal opacity);
26 void setGridOpacity(qreal opacity);
27 qreal gridOpacity() const;
27 qreal gridOpacity() const;
28
28
29 void setLabelsOpacity(qreal opacity);
29 void setLabelsOpacity(qreal opacity);
30 qreal labelsOpacity() const;
30 qreal labelsOpacity() const;
31
31
32 void setShadesOpacity(qreal opacity);
32 void setShadesOpacity(qreal opacity);
33 qreal shadesOpacity() const;
33 qreal shadesOpacity() const;
34
34
35 void setLabelsAngle(int angle);
35 void setLabelsAngle(int angle);
36 int labelsAngle()const { return m_labelsAngle; }
36 int labelsAngle()const { return m_labelsAngle; }
37
37
38 void setShadesBrush(const QBrush &brush);
38 void setShadesBrush(const QBrush &brush);
39 void setShadesPen(const QPen &pen);
39 void setShadesPen(const QPen &pen);
40
40
41 void setAxisPen(const QPen &pen);
41 void setAxisPen(const QPen &pen);
42 void setGridPen(const QPen &pen);
42 void setGridPen(const QPen &pen);
43
43
44 void setLabelsPen(const QPen &pen);
44 void setLabelsPen(const QPen &pen);
45 void setLabelsBrush(const QBrush &brush);
45 void setLabelsBrush(const QBrush &brush);
46 void setLabelsFont(const QFont &font);
46 void setLabelsFont(const QFont &font);
47
47
48 inline QRectF geometry() const { return m_rect; }
48 inline QRectF geometry() const { return m_rect; }
49 inline QVector<qreal> layout() { return m_layoutVector; }
49 inline QVector<qreal> layout() { return m_layoutVector; }
50
50
51 public Q_SLOTS:
51 public Q_SLOTS:
52 void handleAxisUpdated();
52 void handleAxisUpdated();
53 void handleAxisCategoriesUpdated();
53 void handleAxisCategoriesUpdated();
54 void handleRangeChanged(qreal min , qreal max,int tickCount);
54 void handleRangeChanged(qreal min , qreal max,int tickCount);
55 void handleGeometryChanged(const QRectF &size);
55 void handleGeometryChanged(const QRectF &size);
56
56
57
57
58 private:
58 private:
59 inline bool isEmpty();
59 inline bool isEmpty();
60 void createItems(int count);
60 void createItems(int count);
61 void deleteItems(int count);
61 void deleteItems(int count);
62
62
63 QVector<qreal> calculateLayout() const;
63 QVector<qreal> calculateLayout() const;
64 void updateLayout(QVector<qreal> &layout);
64 void updateLayout(QVector<qreal> &layout);
65 void setLayout(QVector<qreal> &layout);
65 void setLayout(QVector<qreal> &layout);
66
66
67 bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
67 bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const;
68 void axisSelected();
68 void axisSelected();
69
69
70 private:
70 private:
71 QChartAxis* m_chartAxis;
71 QChartAxis* m_chartAxis;
72 AxisType m_type;
72 AxisType m_type;
73 QRectF m_rect;
73 QRectF m_rect;
74 int m_labelsAngle;
74 int m_labelsAngle;
75 QGraphicsItemGroup *m_grid;
75 QScopedPointer<QGraphicsItemGroup> m_grid;
76 QGraphicsItemGroup *m_shades;
76 QScopedPointer<QGraphicsItemGroup> m_shades;
77 QGraphicsItemGroup *m_labels;
77 QScopedPointer<QGraphicsItemGroup> m_labels;
78 QGraphicsItemGroup *m_axis;
78 QScopedPointer<QGraphicsItemGroup> m_axis;
79 QVector<qreal> m_layoutVector;
79 QVector<qreal> m_layoutVector;
80 qreal m_min;
80 qreal m_min;
81 qreal m_max;
81 qreal m_max;
82 int m_ticksCount;
82 int m_ticksCount;
83 qreal m_zoomFactor;
83 qreal m_zoomFactor;
84
84
85 friend class AxisAnimation;
85 friend class AxisAnimation;
86 friend class AxisItem;
86 friend class AxisItem;
87
87
88 };
88 };
89
89
90 class AxisItem: public QGraphicsLineItem
90 class AxisItem: public QGraphicsLineItem
91 {
91 {
92 public:
92 public:
93
93
94 AxisItem(Axis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {}
94 AxisItem(Axis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {}
95
95
96 protected:
96 protected:
97 void mousePressEvent(QGraphicsSceneMouseEvent *event)
97 void mousePressEvent(QGraphicsSceneMouseEvent *event)
98 {
98 {
99 Q_UNUSED(event)
99 Q_UNUSED(event)
100 m_axis->axisSelected();
100 m_axis->axisSelected();
101 }
101 }
102
102
103 QRectF boundingRect() const
103 QRectF boundingRect() const
104 {
104 {
105 return shape().boundingRect();
105 return shape().boundingRect();
106 }
106 }
107
107
108 QPainterPath shape() const
108 QPainterPath shape() const
109 {
109 {
110 QPainterPath path = QGraphicsLineItem::shape();
110 QPainterPath path = QGraphicsLineItem::shape();
111 QRectF rect = path.boundingRect();
111 QRectF rect = path.boundingRect();
112 path.addRect(rect.adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?8:0,m_axis->axisType()!=Axis::Y_AXIS?8:0));
112 path.addRect(rect.adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?8:0,m_axis->axisType()!=Axis::Y_AXIS?8:0));
113 return path;
113 return path;
114 }
114 }
115
115
116 private:
116 private:
117 Axis* m_axis;
117 Axis* m_axis;
118
118
119 };
119 };
120
120
121 QTCOMMERCIALCHART_END_NAMESPACE
121 QTCOMMERCIALCHART_END_NAMESPACE
122
122
123 #endif /* AXISITEM_H_ */
123 #endif /* AXISITEM_H_ */
General Comments 0
You need to be logged in to leave comments. Login now