##// END OF EJS Templates
Refactor Visibly methods of axis...
Michal Klocek -
r1729:7809dd5f66eb
parent child
Show More
@@ -100,7 +100,7 void ChartCategoriesAxisX::updateGeometry()
100 QList<QGraphicsItem *> lines = m_grid->childItems();
100 QList<QGraphicsItem *> lines = m_grid->childItems();
101 QList<QGraphicsItem *> labels = m_labels->childItems();
101 QList<QGraphicsItem *> labels = m_labels->childItems();
102 QList<QGraphicsItem *> shades = m_shades->childItems();
102 QList<QGraphicsItem *> shades = m_shades->childItems();
103 QList<QGraphicsItem *> axis = m_axis->childItems();
103 QList<QGraphicsItem *> axis = m_arrow->childItems();
104
104
105 Q_ASSERT(labels.size() == ticksList.size());
105 Q_ASSERT(labels.size() == ticksList.size());
106 Q_ASSERT(layout.size() == ticksList.size());
106 Q_ASSERT(layout.size() == ticksList.size());
@@ -97,7 +97,7 void ChartCategoriesAxisY::updateGeometry()
97 QList<QGraphicsItem *> lines = m_grid->childItems();
97 QList<QGraphicsItem *> lines = m_grid->childItems();
98 QList<QGraphicsItem *> labels = m_labels->childItems();
98 QList<QGraphicsItem *> labels = m_labels->childItems();
99 QList<QGraphicsItem *> shades = m_shades->childItems();
99 QList<QGraphicsItem *> shades = m_shades->childItems();
100 QList<QGraphicsItem *> axis = m_axis->childItems();
100 QList<QGraphicsItem *> axis = m_arrow->childItems();
101
101
102 Q_ASSERT(labels.size() == ticksList.size());
102 Q_ASSERT(labels.size() == ticksList.size());
103 Q_ASSERT(layout.size() == ticksList.size());
103 Q_ASSERT(layout.size() == ticksList.size());
@@ -35,7 +35,7 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(pres
35 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
35 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
36 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
36 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
37 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
37 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
38 m_axis(new QGraphicsItemGroup(presenter->rootItem())),
38 m_arrow(new QGraphicsItemGroup(presenter->rootItem())),
39 m_min(0),
39 m_min(0),
40 m_max(0),
40 m_max(0),
41 m_animation(0),
41 m_animation(0),
@@ -43,8 +43,8 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(pres
43 m_minHeight(0)
43 m_minHeight(0)
44 {
44 {
45 //initial initialization
45 //initial initialization
46 m_axis->setZValue(ChartPresenter::AxisZValue);
46 m_arrow->setZValue(ChartPresenter::AxisZValue);
47 m_axis->setHandlesChildEvents(false);
47 m_arrow->setHandlesChildEvents(false);
48
48
49 m_shades->setZValue(ChartPresenter::ShadesZValue);
49 m_shades->setZValue(ChartPresenter::ShadesZValue);
50 m_grid->setZValue(ChartPresenter::GridZValue);
50 m_grid->setZValue(ChartPresenter::GridZValue);
@@ -71,12 +71,12 void ChartAxis::setLayout(QVector<qreal> &layout)
71
71
72 void ChartAxis::createItems(int count)
72 void ChartAxis::createItems(int count)
73 {
73 {
74 if (m_axis->children().size() == 0)
74 if (m_arrow->children().size() == 0)
75 m_axis->addToGroup(new AxisItem(this));
75 m_arrow->addToGroup(new AxisItem(this));
76 for (int i = 0; i < count; ++i) {
76 for (int i = 0; i < count; ++i) {
77 m_grid->addToGroup(new QGraphicsLineItem());
77 m_grid->addToGroup(new QGraphicsLineItem());
78 m_labels->addToGroup(new QGraphicsSimpleTextItem());
78 m_labels->addToGroup(new QGraphicsSimpleTextItem());
79 m_axis->addToGroup(new QGraphicsLineItem());
79 m_arrow->addToGroup(new QGraphicsLineItem());
80 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem());
80 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem());
81 }
81 }
82 }
82 }
@@ -86,7 +86,7 void ChartAxis::deleteItems(int count)
86 QList<QGraphicsItem *> lines = m_grid->childItems();
86 QList<QGraphicsItem *> lines = m_grid->childItems();
87 QList<QGraphicsItem *> labels = m_labels->childItems();
87 QList<QGraphicsItem *> labels = m_labels->childItems();
88 QList<QGraphicsItem *> shades = m_shades->childItems();
88 QList<QGraphicsItem *> shades = m_shades->childItems();
89 QList<QGraphicsItem *> axis = m_axis->childItems();
89 QList<QGraphicsItem *> axis = m_arrow->childItems();
90
90
91 for (int i = 0; i < count; ++i) {
91 for (int i = 0; i < count; ++i) {
92 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
92 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
@@ -140,14 +140,19 void ChartAxis::updateLayout(QVector<qreal> &layout)
140 }
140 }
141 }
141 }
142
142
143 void ChartAxis::setAxisOpacity(qreal opacity)
143 void ChartAxis::setArrowOpacity(qreal opacity)
144 {
144 {
145 m_axis->setOpacity(opacity);
145 m_arrow->setOpacity(opacity);
146 }
146 }
147
147
148 qreal ChartAxis::axisOpacity() const
148 qreal ChartAxis::arrowOpacity() const
149 {
149 {
150 return m_axis->opacity();
150 return m_arrow->opacity();
151 }
152
153 void ChartAxis::setArrowVisibility(bool visible)
154 {
155 m_arrow->setOpacity(visible);
151 }
156 }
152
157
153 void ChartAxis::setGridOpacity(qreal opacity)
158 void ChartAxis::setGridOpacity(qreal opacity)
@@ -160,6 +165,11 qreal ChartAxis::gridOpacity() const
160 return m_grid->opacity();
165 return m_grid->opacity();
161 }
166 }
162
167
168 void ChartAxis::setGridVisibility(bool visible)
169 {
170 m_grid->setOpacity(visible);
171 }
172
163 void ChartAxis::setLabelsOpacity(qreal opacity)
173 void ChartAxis::setLabelsOpacity(qreal opacity)
164 {
174 {
165 m_labels->setOpacity(opacity);
175 m_labels->setOpacity(opacity);
@@ -170,6 +180,11 qreal ChartAxis::labelsOpacity() const
170 return m_labels->opacity();
180 return m_labels->opacity();
171 }
181 }
172
182
183 void ChartAxis::setLabelsVisibility(bool visible)
184 {
185 m_labels->setOpacity(visible);
186 }
187
173 void ChartAxis::setShadesOpacity(qreal opacity)
188 void ChartAxis::setShadesOpacity(qreal opacity)
174 {
189 {
175 m_shades->setOpacity(opacity);
190 m_shades->setOpacity(opacity);
@@ -180,6 +195,11 qreal ChartAxis::shadesOpacity() const
180 return m_shades->opacity();
195 return m_shades->opacity();
181 }
196 }
182
197
198 void ChartAxis::setShadesVisibility(bool visible)
199 {
200 m_shades->setVisible(visible);
201 }
202
183 void ChartAxis::setLabelsAngle(int angle)
203 void ChartAxis::setLabelsAngle(int angle)
184 {
204 {
185 foreach(QGraphicsItem* item , m_labels->childItems()) {
205 foreach(QGraphicsItem* item , m_labels->childItems()) {
@@ -225,9 +245,9 void ChartAxis::setShadesPen(const QPen &pen)
225 }
245 }
226 }
246 }
227
247
228 void ChartAxis::setAxisPen(const QPen &pen)
248 void ChartAxis::setArrowPen(const QPen &pen)
229 {
249 {
230 foreach(QGraphicsItem* item , m_axis->childItems()) {
250 foreach(QGraphicsItem* item , m_arrow->childItems()) {
231 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
251 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
232 }
252 }
233 }
253 }
@@ -276,45 +296,16 void ChartAxis::handleAxisUpdated()
276 {
296 {
277 if(isEmpty()) return;
297 if(isEmpty()) return;
278
298
279 if (!m_chartAxis->isVisible()) {
280 setAxisOpacity(0);
281 setGridOpacity(0);
282 setLabelsOpacity(0);
283 setShadesOpacity(0);
284 }
285 else {
286
287 if (m_chartAxis->isArrowVisible()) {
288 setAxisOpacity(100);
289 }
290 else {
291 setAxisOpacity(0);
292 }
293
299
294 if (m_chartAxis->isGridLineVisible()) {
300 bool visible = m_chartAxis->isVisible();
295 setGridOpacity(100);
296 }
297 else {
298 setGridOpacity(0);
299 }
300
301 if (m_chartAxis->labelsVisible()) {
302 setLabelsOpacity(100);
303 }
304 else {
305 setLabelsOpacity(0);
306 }
307
301
308 if (m_chartAxis->shadesVisible()) {
302 setArrowVisibility(visible && m_chartAxis->isArrowVisible());
309 setShadesOpacity(100);
303 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
310 }
304 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
311 else {
305 setShadesVisibility(visible && m_chartAxis->shadesVisible());
312 setShadesOpacity(0);
313 }
314 }
315
306
316 setLabelsAngle(m_chartAxis->labelsAngle());
307 setLabelsAngle(m_chartAxis->labelsAngle());
317 setAxisPen(m_chartAxis->axisPen());
308 setArrowPen(m_chartAxis->axisPen());
318 setLabelsPen(m_chartAxis->labelsPen());
309 setLabelsPen(m_chartAxis->labelsPen());
319 setLabelsBrush(m_chartAxis->labelsBrush());
310 setLabelsBrush(m_chartAxis->labelsBrush());
320 setLabelsFont(m_chartAxis->labelsFont());
311 setLabelsFont(m_chartAxis->labelsFont());
@@ -324,6 +315,14 void ChartAxis::handleAxisUpdated()
324
315
325 }
316 }
326
317
318 void ChartAxis::hide()
319 {
320 setArrowVisibility(false);
321 setGridVisibility(false);
322 setLabelsVisibility(false);
323 setShadesVisibility(false);
324 }
325
327 void ChartAxis::handleGeometryChanged(const QRectF &rect)
326 void ChartAxis::handleGeometryChanged(const QRectF &rect)
328 {
327 {
329 if(m_rect != rect)
328 if(m_rect != rect)
@@ -52,17 +52,21 public:
52
52
53 virtual AxisType axisType() const = 0;
53 virtual AxisType axisType() const = 0;
54
54
55 void setAxisOpacity(qreal opacity);
55 void setArrowOpacity(qreal opacity);
56 qreal axisOpacity() const;
56 qreal arrowOpacity() const;
57 void setArrowVisibility(bool visible);
57
58
58 void setGridOpacity(qreal opacity);
59 void setGridOpacity(qreal opacity);
59 qreal gridOpacity() const;
60 qreal gridOpacity() const;
61 void setGridVisibility(bool visible);
60
62
61 void setLabelsOpacity(qreal opacity);
63 void setLabelsOpacity(qreal opacity);
62 qreal labelsOpacity() const;
64 qreal labelsOpacity() const;
65 void setLabelsVisibility(bool visible);
63
66
64 void setShadesOpacity(qreal opacity);
67 void setShadesOpacity(qreal opacity);
65 qreal shadesOpacity() const;
68 qreal shadesOpacity() const;
69 void setShadesVisibility(bool visible);
66
70
67 void setLabelsAngle(int angle);
71 void setLabelsAngle(int angle);
68 int labelsAngle()const { return m_labelsAngle; }
72 int labelsAngle()const { return m_labelsAngle; }
@@ -70,7 +74,7 public:
70 void setShadesBrush(const QBrush &brush);
74 void setShadesBrush(const QBrush &brush);
71 void setShadesPen(const QPen &pen);
75 void setShadesPen(const QPen &pen);
72
76
73 void setAxisPen(const QPen &pen);
77 void setArrowPen(const QPen &pen);
74 void setGridPen(const QPen &pen);
78 void setGridPen(const QPen &pen);
75
79
76 void setLabelsPen(const QPen &pen);
80 void setLabelsPen(const QPen &pen);
@@ -88,6 +92,8 public:
88 qreal minimumWidth();
92 qreal minimumWidth();
89 qreal minimumHeight();
93 qreal minimumHeight();
90
94
95 void hide();
96
91 protected:
97 protected:
92 virtual void updateGeometry() = 0;
98 virtual void updateGeometry() = 0;
93 virtual QVector<qreal> calculateLayout() const = 0;
99 virtual QVector<qreal> calculateLayout() const = 0;
@@ -112,7 +118,7 protected:
112 QScopedPointer<QGraphicsItemGroup> m_grid;
118 QScopedPointer<QGraphicsItemGroup> m_grid;
113 QScopedPointer<QGraphicsItemGroup> m_shades;
119 QScopedPointer<QGraphicsItemGroup> m_shades;
114 QScopedPointer<QGraphicsItemGroup> m_labels;
120 QScopedPointer<QGraphicsItemGroup> m_labels;
115 QScopedPointer<QGraphicsItemGroup> m_axis;
121 QScopedPointer<QGraphicsItemGroup> m_arrow;
116 QVector<qreal> m_layoutVector;
122 QVector<qreal> m_layoutVector;
117 qreal m_min;
123 qreal m_min;
118 qreal m_max;
124 qreal m_max;
@@ -88,7 +88,7 void ChartDateTimeAxisX::updateGeometry()
88 QList<QGraphicsItem *> lines = m_grid->childItems();
88 QList<QGraphicsItem *> lines = m_grid->childItems();
89 QList<QGraphicsItem *> labels = m_labels->childItems();
89 QList<QGraphicsItem *> labels = m_labels->childItems();
90 QList<QGraphicsItem *> shades = m_shades->childItems();
90 QList<QGraphicsItem *> shades = m_shades->childItems();
91 QList<QGraphicsItem *> axis = m_axis->childItems();
91 QList<QGraphicsItem *> axis = m_arrow->childItems();
92
92
93 Q_ASSERT(labels.size() == ticksList.size());
93 Q_ASSERT(labels.size() == ticksList.size());
94 Q_ASSERT(layout.size() == ticksList.size());
94 Q_ASSERT(layout.size() == ticksList.size());
@@ -88,7 +88,7 void ChartDateTimeAxisY::updateGeometry()
88 QList<QGraphicsItem *> lines = m_grid->childItems();
88 QList<QGraphicsItem *> lines = m_grid->childItems();
89 QList<QGraphicsItem *> labels = m_labels->childItems();
89 QList<QGraphicsItem *> labels = m_labels->childItems();
90 QList<QGraphicsItem *> shades = m_shades->childItems();
90 QList<QGraphicsItem *> shades = m_shades->childItems();
91 QList<QGraphicsItem *> axis = m_axis->childItems();
91 QList<QGraphicsItem *> axis = m_arrow->childItems();
92
92
93 Q_ASSERT(labels.size() == ticksList.size());
93 Q_ASSERT(labels.size() == ticksList.size());
94 Q_ASSERT(layout.size() == ticksList.size());
94 Q_ASSERT(layout.size() == ticksList.size());
@@ -82,7 +82,7 void ChartIntervalAxisX::updateGeometry()
82 QList<QGraphicsItem *> lines = m_grid->childItems();
82 QList<QGraphicsItem *> lines = m_grid->childItems();
83 QList<QGraphicsItem *> labels = m_labels->childItems();
83 QList<QGraphicsItem *> labels = m_labels->childItems();
84 QList<QGraphicsItem *> shades = m_shades->childItems();
84 QList<QGraphicsItem *> shades = m_shades->childItems();
85 QList<QGraphicsItem *> axis = m_axis->childItems();
85 QList<QGraphicsItem *> axis = m_arrow->childItems();
86
86
87 // Q_ASSERT(labels.size() == ticksList.size());
87 // Q_ASSERT(labels.size() == ticksList.size());
88 // Q_ASSERT(layout.size() == ticksList.size());
88 // Q_ASSERT(layout.size() == ticksList.size());
@@ -79,7 +79,7 void ChartIntervalAxisY::updateGeometry()
79 QList<QGraphicsItem *> lines = m_grid->childItems();
79 QList<QGraphicsItem *> lines = m_grid->childItems();
80 QList<QGraphicsItem *> labels = m_labels->childItems();
80 QList<QGraphicsItem *> labels = m_labels->childItems();
81 QList<QGraphicsItem *> shades = m_shades->childItems();
81 QList<QGraphicsItem *> shades = m_shades->childItems();
82 QList<QGraphicsItem *> axis = m_axis->childItems();
82 QList<QGraphicsItem *> axis = m_arrow->childItems();
83
83
84 // Q_ASSERT(labels.size() == ticksList.size());
84 // Q_ASSERT(labels.size() == ticksList.size());
85 // Q_ASSERT(layout.size() == ticksList.size());
85 // Q_ASSERT(layout.size() == ticksList.size());
@@ -72,7 +72,7 void ChartValuesAxisX::updateGeometry()
72 QList<QGraphicsItem *> lines = m_grid->childItems();
72 QList<QGraphicsItem *> lines = m_grid->childItems();
73 QList<QGraphicsItem *> labels = m_labels->childItems();
73 QList<QGraphicsItem *> labels = m_labels->childItems();
74 QList<QGraphicsItem *> shades = m_shades->childItems();
74 QList<QGraphicsItem *> shades = m_shades->childItems();
75 QList<QGraphicsItem *> axis = m_axis->childItems();
75 QList<QGraphicsItem *> axis = m_arrow->childItems();
76
76
77 Q_ASSERT(labels.size() == ticksList.size());
77 Q_ASSERT(labels.size() == ticksList.size());
78 Q_ASSERT(layout.size() == ticksList.size());
78 Q_ASSERT(layout.size() == ticksList.size());
@@ -72,7 +72,7 void ChartValuesAxisY::updateGeometry()
72 QList<QGraphicsItem *> lines = m_grid->childItems();
72 QList<QGraphicsItem *> lines = m_grid->childItems();
73 QList<QGraphicsItem *> labels = m_labels->childItems();
73 QList<QGraphicsItem *> labels = m_labels->childItems();
74 QList<QGraphicsItem *> shades = m_shades->childItems();
74 QList<QGraphicsItem *> shades = m_shades->childItems();
75 QList<QGraphicsItem *> axis = m_axis->childItems();
75 QList<QGraphicsItem *> axis = m_arrow->childItems();
76
76
77 Q_ASSERT(labels.size() == ticksList.size());
77 Q_ASSERT(labels.size() == ticksList.size());
78 Q_ASSERT(layout.size() == ticksList.size());
78 Q_ASSERT(layout.size() == ticksList.size());
@@ -423,10 +423,11 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Ori
423
423
424 QAbstractAxis *oldAxis = seriesAxisMap->take(series);
424 QAbstractAxis *oldAxis = seriesAxisMap->take(series);
425 QList<QAbstractAxis*> axes = seriesAxisMap->values();
425 QList<QAbstractAxis*> axes = seriesAxisMap->values();
426
427 if(oldAxis) {
426 if(oldAxis) {
428 if(axes.indexOf(oldAxis)==-1) {
427 if(axes.indexOf(oldAxis)==-1) {
429 emit axisRemoved(oldAxis);
428 emit axisRemoved(oldAxis);
429 oldAxis->disconnect();
430 QObject::disconnect(domain,0,oldAxis,0);
430 oldAxis->d_ptr->m_dataset=0;
431 oldAxis->d_ptr->m_dataset=0;
431 oldAxis->deleteLater();
432 oldAxis->deleteLater();
432 }
433 }
@@ -99,6 +99,9 void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis)
99 Q_ASSERT(item);
99 Q_ASSERT(item);
100 selectVisibleAxis();
100 selectVisibleAxis();
101 if(m_animator) m_animator->removeAnimation(item);
101 if(m_animator) m_animator->removeAnimation(item);
102 item->hide();
103 item->disconnect();
104 QObject::disconnect(this,0,item,0);
102 item->deleteLater();
105 item->deleteLater();
103 }
106 }
104
107
General Comments 0
You need to be logged in to leave comments. Login now