##// END OF EJS Templates
barseries fix: series visibility now affects also label visibility
sauimone -
r1464:e8fbee1fef55
parent child
Show More
@@ -40,7 +40,7 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
40 40 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
41 41 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
42 42 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
43 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleLayoutChanged()));
43 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
44 44 setZValue(ChartPresenter::BarSeriesZValue);
45 45 handleDataStructureChanged();
46 46 }
@@ -61,42 +61,6 QRectF BarChartItem::boundingRect() const
61 61 return m_rect;
62 62 }
63 63
64 void BarChartItem::handleDataStructureChanged()
65 {
66 foreach(QGraphicsItem *item, childItems()) {
67 delete item;
68 }
69
70 m_bars.clear();
71 m_labels.clear();
72 m_layout.clear();
73
74 bool labelsVisible = m_series->isLabelsVisible();
75
76 // Create new graphic items for bars
77 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
78 for (int s = 0; s < m_series->count(); s++) {
79 QBarSet *set = m_series->d_func()->barsetAt(s);
80
81 // Bars
82 Bar *bar = new Bar(set,c,this);
83 m_bars.append(bar);
84 connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int)));
85 connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool)));
86 m_layout.append(QRectF(0, 0, 0, 0));
87
88 // Labels
89 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
90 label->setVisible(labelsVisible);
91 m_labels.append(label);
92 }
93 }
94
95 // TODO: Is this the right place to call it?
96 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
97 handleLayoutChanged();
98 }
99
100 64 QVector<QRectF> BarChartItem::calculateLayout()
101 65 {
102 66 QVector<QRectF> layout;
@@ -200,6 +164,8 void BarChartItem::handleLayoutChanged()
200 164 applyLayout(layout);
201 165 }
202 166
167
168
203 169 void BarChartItem::handleLabelsVisibleChanged(bool visible)
204 170 {
205 171 foreach (QGraphicsSimpleTextItem* label, m_labels) {
@@ -208,6 +174,51 void BarChartItem::handleLabelsVisibleChanged(bool visible)
208 174 update();
209 175 }
210 176
177 void BarChartItem::handleDataStructureChanged()
178 {
179 foreach(QGraphicsItem *item, childItems()) {
180 delete item;
181 }
182
183 m_bars.clear();
184 m_labels.clear();
185 m_layout.clear();
186
187 bool labelsVisible = m_series->isLabelsVisible();
188
189 // Create new graphic items for bars
190 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
191 for (int s = 0; s < m_series->count(); s++) {
192 QBarSet *set = m_series->d_func()->barsetAt(s);
193
194 // Bars
195 Bar *bar = new Bar(set,c,this);
196 m_bars.append(bar);
197 connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int)));
198 connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool)));
199 m_layout.append(QRectF(0, 0, 0, 0));
200
201 // Labels
202 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
203 label->setVisible(labelsVisible);
204 m_labels.append(label);
205 }
206 }
207
208 // TODO: Is this the right place to call it?
209 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
210 handleLayoutChanged();
211 }
212
213 void BarChartItem::handleVisibleChanged()
214 {
215 bool visible = m_series->isVisible();
216 handleLabelsVisibleChanged(visible);
217 foreach(QGraphicsItem *item, childItems()) {
218 item->setVisible(visible);
219 }
220 }
221
211 222 #include "moc_barchartitem_p.cpp"
212 223
213 224 QTCOMMERCIALCHART_END_NAMESPACE
@@ -66,6 +66,7 public Q_SLOTS:
66 66 void handleLayoutChanged();
67 67 void handleLabelsVisibleChanged(bool visible);
68 68 void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items
69 void handleVisibleChanged();
69 70
70 71 protected:
71 72
General Comments 0
You need to be logged in to leave comments. Login now