##// END OF EJS Templates
make QGraphicsItemGroup a pointer in axis
Jani Honkonen -
r784:5e82808a7b5e
parent child
Show More
@@ -14,20 +14,20 Axis::Axis(QChartAxis *axis,ChartPresenter *presenter,AxisType type) : Chart(pre
14 m_chartAxis(axis),
14 m_chartAxis(axis),
15 m_type(type),
15 m_type(type),
16 m_labelsAngle(0),
16 m_labelsAngle(0),
17 m_grid(presenter->rootItem()),
17 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
18 m_shades(presenter->rootItem()),
18 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
19 m_labels(presenter->rootItem()),
19 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
20 m_axis(presenter->rootItem()),
20 m_axis(new QGraphicsItemGroup(presenter->rootItem())),
21 m_min(0),
21 m_min(0),
22 m_max(0),
22 m_max(0),
23 m_ticksCount(0)
23 m_ticksCount(0)
24 {
24 {
25 //initial initialization
25 //initial initialization
26 m_axis.setZValue(ChartPresenter::AxisZValue);
26 m_axis->setZValue(ChartPresenter::AxisZValue);
27 m_axis.setHandlesChildEvents(false);
27 m_axis->setHandlesChildEvents(false);
28
28
29 m_shades.setZValue(ChartPresenter::ShadesZValue);
29 m_shades->setZValue(ChartPresenter::ShadesZValue);
30 m_grid.setZValue(ChartPresenter::GridZValue);
30 m_grid->setZValue(ChartPresenter::GridZValue);
31
31
32 connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
32 connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
33 connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
33 connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
@@ -42,22 +42,22 Axis::~Axis()
42 void Axis::createItems(int count)
42 void Axis::createItems(int count)
43 {
43 {
44
44
45 if (m_axis.children().size() == 0)
45 if (m_axis->children().size() == 0)
46 m_axis.addToGroup(new AxisItem(this));
46 m_axis->addToGroup(new AxisItem(this));
47 for (int i = 0; i < count; ++i) {
47 for (int i = 0; i < count; ++i) {
48 m_grid.addToGroup(new QGraphicsLineItem());
48 m_grid->addToGroup(new QGraphicsLineItem());
49 m_labels.addToGroup(new QGraphicsSimpleTextItem());
49 m_labels->addToGroup(new QGraphicsSimpleTextItem());
50 m_axis.addToGroup(new QGraphicsLineItem());
50 m_axis->addToGroup(new QGraphicsLineItem());
51 if ((m_grid.childItems().size())%2 && m_grid.childItems().size()>2) m_shades.addToGroup(new QGraphicsRectItem());
51 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem());
52 }
52 }
53 }
53 }
54
54
55 void Axis::deleteItems(int count)
55 void Axis::deleteItems(int count)
56 {
56 {
57 QList<QGraphicsItem *> lines = m_grid.childItems();
57 QList<QGraphicsItem *> lines = m_grid->childItems();
58 QList<QGraphicsItem *> labels = m_labels.childItems();
58 QList<QGraphicsItem *> labels = m_labels->childItems();
59 QList<QGraphicsItem *> shades = m_shades.childItems();
59 QList<QGraphicsItem *> shades = m_shades->childItems();
60 QList<QGraphicsItem *> axis = m_axis.childItems();
60 QList<QGraphicsItem *> axis = m_axis->childItems();
61
61
62 for (int i = 0; i < count; ++i) {
62 for (int i = 0; i < count; ++i) {
63 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
63 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
@@ -111,47 +111,47 bool Axis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) cons
111
111
112 void Axis::setAxisOpacity(qreal opacity)
112 void Axis::setAxisOpacity(qreal opacity)
113 {
113 {
114 m_axis.setOpacity(opacity);
114 m_axis->setOpacity(opacity);
115 }
115 }
116
116
117 qreal Axis::axisOpacity() const
117 qreal Axis::axisOpacity() const
118 {
118 {
119 return m_axis.opacity();
119 return m_axis->opacity();
120 }
120 }
121
121
122 void Axis::setGridOpacity(qreal opacity)
122 void Axis::setGridOpacity(qreal opacity)
123 {
123 {
124 m_grid.setOpacity(opacity);
124 m_grid->setOpacity(opacity);
125 }
125 }
126
126
127 qreal Axis::gridOpacity() const
127 qreal Axis::gridOpacity() const
128 {
128 {
129 return m_grid.opacity();
129 return m_grid->opacity();
130 }
130 }
131
131
132 void Axis::setLabelsOpacity(qreal opacity)
132 void Axis::setLabelsOpacity(qreal opacity)
133 {
133 {
134 m_labels.setOpacity(opacity);
134 m_labels->setOpacity(opacity);
135 }
135 }
136
136
137 qreal Axis::labelsOpacity() const
137 qreal Axis::labelsOpacity() const
138 {
138 {
139 return m_labels.opacity();
139 return m_labels->opacity();
140 }
140 }
141
141
142 void Axis::setShadesOpacity(qreal opacity)
142 void Axis::setShadesOpacity(qreal opacity)
143 {
143 {
144 m_shades.setOpacity(opacity);
144 m_shades->setOpacity(opacity);
145 }
145 }
146
146
147 qreal Axis::shadesOpacity() const
147 qreal Axis::shadesOpacity() const
148 {
148 {
149 return m_shades.opacity();
149 return m_shades->opacity();
150 }
150 }
151
151
152 void Axis::setLabelsAngle(int angle)
152 void Axis::setLabelsAngle(int angle)
153 {
153 {
154 foreach(QGraphicsItem* item , m_labels.childItems()) {
154 foreach(QGraphicsItem* item , m_labels->childItems()) {
155 item->setRotation(angle);
155 item->setRotation(angle);
156 }
156 }
157
157
@@ -160,49 +160,49 void Axis::setLabelsAngle(int angle)
160
160
161 void Axis::setLabelsPen(const QPen &pen)
161 void Axis::setLabelsPen(const QPen &pen)
162 {
162 {
163 foreach(QGraphicsItem* item , m_labels.childItems()) {
163 foreach(QGraphicsItem* item , m_labels->childItems()) {
164 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
164 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
165 }
165 }
166 }
166 }
167
167
168 void Axis::setLabelsBrush(const QBrush &brush)
168 void Axis::setLabelsBrush(const QBrush &brush)
169 {
169 {
170 foreach(QGraphicsItem* item , m_labels.childItems()) {
170 foreach(QGraphicsItem* item , m_labels->childItems()) {
171 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
171 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
172 }
172 }
173 }
173 }
174
174
175 void Axis::setLabelsFont(const QFont &font)
175 void Axis::setLabelsFont(const QFont &font)
176 {
176 {
177 foreach(QGraphicsItem* item , m_labels.childItems()) {
177 foreach(QGraphicsItem* item , m_labels->childItems()) {
178 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
178 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
179 }
179 }
180 }
180 }
181
181
182 void Axis::setShadesBrush(const QBrush &brush)
182 void Axis::setShadesBrush(const QBrush &brush)
183 {
183 {
184 foreach(QGraphicsItem* item , m_shades.childItems()) {
184 foreach(QGraphicsItem* item , m_shades->childItems()) {
185 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
185 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
186 }
186 }
187 }
187 }
188
188
189 void Axis::setShadesPen(const QPen &pen)
189 void Axis::setShadesPen(const QPen &pen)
190 {
190 {
191 foreach(QGraphicsItem* item , m_shades.childItems()) {
191 foreach(QGraphicsItem* item , m_shades->childItems()) {
192 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
192 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
193 }
193 }
194 }
194 }
195
195
196 void Axis::setAxisPen(const QPen &pen)
196 void Axis::setAxisPen(const QPen &pen)
197 {
197 {
198 foreach(QGraphicsItem* item , m_axis.childItems()) {
198 foreach(QGraphicsItem* item , m_axis->childItems()) {
199 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
199 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
200 }
200 }
201 }
201 }
202
202
203 void Axis::setGridPen(const QPen &pen)
203 void Axis::setGridPen(const QPen &pen)
204 {
204 {
205 foreach(QGraphicsItem* item , m_grid.childItems()) {
205 foreach(QGraphicsItem* item , m_grid->childItems()) {
206 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
206 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
207 }
207 }
208 }
208 }
@@ -254,10 +254,10 void Axis::setLayout(QVector<qreal> &layout)
254
254
255 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
255 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
256
256
257 QList<QGraphicsItem *> lines = m_grid.childItems();
257 QList<QGraphicsItem *> lines = m_grid->childItems();
258 QList<QGraphicsItem *> labels = m_labels.childItems();
258 QList<QGraphicsItem *> labels = m_labels->childItems();
259 QList<QGraphicsItem *> shades = m_shades.childItems();
259 QList<QGraphicsItem *> shades = m_shades->childItems();
260 QList<QGraphicsItem *> axis = m_axis.childItems();
260 QList<QGraphicsItem *> axis = m_axis->childItems();
261
261
262 Q_ASSERT(labels.size() == ticksList.size());
262 Q_ASSERT(labels.size() == ticksList.size());
263 Q_ASSERT(layout.size() == ticksList.size());
263 Q_ASSERT(layout.size() == ticksList.size());
@@ -72,10 +72,10 private:
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 QGraphicsItemGroup *m_grid;
76 QGraphicsItemGroup m_shades;
76 QGraphicsItemGroup *m_shades;
77 QGraphicsItemGroup m_labels;
77 QGraphicsItemGroup *m_labels;
78 QGraphicsItemGroup m_axis;
78 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;
General Comments 0
You need to be logged in to leave comments. Login now