##// END OF EJS Templates
removed barlabel. label visibility control is now per series instead of per set
sauimone -
r1246:5512aa7e284d
parent child
Show More
@@ -12,7 +12,6 SOURCES += \
12 12 $$PWD/qstackedbarseries.cpp \
13 13 $$PWD/qgroupedbarseries.cpp \
14 14 $$PWD/stackedbarchartitem.cpp \
15 $$PWD/barlabel.cpp \
16 15 $$PWD/qbarmodelmapper.cpp
17 16
18 17 PRIVATE_HEADERS += \
@@ -21,7 +20,6 PRIVATE_HEADERS += \
21 20 $$PWD/percentbarchartitem_p.h \
22 21 $$PWD/stackedbarchartitem_p.h \
23 22 $$PWD/groupedbarchartitem_p.h \
24 $$PWD/barlabel_p.h \
25 23 $$PWD/qbarset_p.h \
26 24 $$PWD/qbarseries_p.h \
27 25 $$PWD/qstackedbarseries_p.h\
@@ -20,7 +20,6
20 20
21 21 #include "barchartitem_p.h"
22 22 #include "bar_p.h"
23 #include "barlabel_p.h"
24 23 #include "qbarset.h"
25 24 #include "qbarset_p.h"
26 25 #include "qbarseries.h"
@@ -41,6 +40,7 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
41 40 setFlag(ItemClipsChildrenToShape);
42 41 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
43 42 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged()));
43 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(labelsVisibleChanged(bool)));
44 44 setZValue(ChartPresenter::BarSeriesZValue);
45 45 dataChanged();
46 46 }
@@ -71,11 +71,15 void BarChartItem::dataChanged()
71 71 m_labels.clear();
72 72 m_layout.clear();
73 73
74 bool labelsVisible = m_series->isLabelsVisible();
75
74 76 // Create new graphic items for bars
75 77 for (int c = 0; c < m_series->categoryCount(); c++) {
76 78 QString category = m_series->d_func()->categoryName(c);
77 79 for (int s = 0; s < m_series->barsetCount(); s++) {
78 80 QBarSet *set = m_series->d_func()->barsetAt(s);
81
82 // Bars
79 83 Bar *bar = new Bar(set,category,this);
80 84 m_bars.append(bar);
81 85 connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString)));
@@ -83,18 +87,13 void BarChartItem::dataChanged()
83 87 connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool)));
84 88 connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool)));
85 89 m_layout.append(QRectF(0, 0, 0, 0));
86 }
87 }
88 90
89 // Create labels
90 for (int category = 0; category < m_series->categoryCount(); category++) {
91 for (int s = 0; s < m_series->barsetCount(); s++) {
92 QBarSet *set = m_series->d_func()->barsetAt(s);
93 BarLabel *value = new BarLabel(*set, this);
94 m_labels.append(value);
95 connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool)));
91 // Labels
92 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
93 label->setVisible(labelsVisible);
94 m_labels.append(label);
96 95 }
97 }
96 }
98 97
99 98 // TODO: Is this the right place to call it?
100 99 // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
@@ -133,7 +132,7 QVector<QRectF> BarChartItem::calculateLayout()
133 132 bar->setPen(barSet->pen());
134 133 bar->setBrush(barSet->brush());
135 134
136 BarLabel* label = m_labels.at(itemIndex);
135 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
137 136
138 137 if (!qFuzzyIsNull(barSet->at(category).y())) {
139 138 label->setText(QString::number(barSet->at(category).y()));
@@ -205,6 +204,14 void BarChartItem::handleLayoutChanged()
205 204 update();
206 205 }
207 206
207 void BarChartItem::labelsVisibleChanged(bool visible)
208 {
209 foreach (QGraphicsSimpleTextItem* label, m_labels) {
210 label->setVisible(visible);
211 }
212 update();
213 }
214
208 215 #include "moc_barchartitem_p.cpp"
209 216
210 217 QTCOMMERCIALCHART_END_NAMESPACE
@@ -29,7 +29,6
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class Bar;
32 class BarLabel;
33 32 class QAxisCategories;
34 33 class QChart;
35 34
@@ -61,6 +60,7 public Q_SLOTS:
61 60 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
62 61 void handleGeometryChanged(const QRectF &size);
63 62 void handleLayoutChanged();
63 void labelsVisibleChanged(bool visible);
64 64
65 65 protected:
66 66
@@ -76,7 +76,7 protected:
76 76 // Not owned.
77 77 QBarSeries *m_series;
78 78 QList<Bar *> m_bars;
79 QList<BarLabel *> m_labels;
79 QList<QGraphicsSimpleTextItem *> m_labels;
80 80 };
81 81
82 82 QTCOMMERCIALCHART_END_NAMESPACE
@@ -20,7 +20,6
20 20
21 21 #include "groupedbarchartitem_p.h"
22 22 #include "bar_p.h"
23 #include "barlabel_p.h"
24 23 #include "qbarset_p.h"
25 24 #include "qbarseries_p.h"
26 25 #include "qbarset.h"
@@ -67,7 +66,7 QVector<QRectF> GroupedBarChartItem::calculateLayout()
67 66 bar->setPen(barSet->pen());
68 67 bar->setBrush(barSet->brush());
69 68
70 BarLabel* label = m_labels.at(itemIndex);
69 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
71 70
72 71 if (!qFuzzyIsNull(barSet->at(category).y())) {
73 72 label->setText(QString::number(barSet->at(category).y()));
@@ -20,7 +20,6
20 20
21 21 #include "percentbarchartitem_p.h"
22 22 #include "bar_p.h"
23 #include "barlabel_p.h"
24 23 #include "qbarseries_p.h"
25 24 #include "qbarset.h"
26 25 #include <QDebug>
@@ -67,7 +66,7 QVector<QRectF> PercentBarChartItem::calculateLayout()
67 66 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
68 67 layout.append(rect);
69 68
70 BarLabel* label = m_labels.at(itemIndex);
69 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
71 70
72 71 if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) {
73 72 int p = m_series->d_func()->percentageAt(set,category) * 100;
@@ -230,16 +230,25 QBarCategories QBarSeries::categories() const
230 230 */
231 231 void QBarSeries::setLabelsVisible(bool visible)
232 232 {
233 foreach (QBarSet* s, barSets()) {
234 s->setLabelsVisible(visible);
233 Q_D(QBarSeries);
234 if (d->m_labelsVisible != visible) {
235 d->m_labelsVisible = visible;
236 emit d->updatedBars();
235 237 }
236 238 }
237 239
240 bool QBarSeries::isLabelsVisible() const
241 {
242 Q_D(const QBarSeries);
243 return d->m_labelsVisible;
244 }
245
238 246 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
239 247
240 248 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
241 249 QAbstractSeriesPrivate(q),
242 m_barMargin(0.05) // Default value is 5% of category width
250 m_barMargin(0.05), // Default value is 5% of category width
251 m_labelsVisible(false)
243 252 {
244 253 }
245 254
@@ -53,6 +53,7 public:
53 53 QBarCategories categories() const;
54 54
55 55 void setLabelsVisible(bool visible = true);
56 bool isLabelsVisible() const;
56 57
57 58 protected:
58 59 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
@@ -44,6 +44,7 Q_SIGNALS:
44 44 void updatedBars();
45 45 void restructuredBars();
46 46 void categoriesUpdated();
47 void labelsVisibleChanged(bool visible);
47 48
48 49 private Q_SLOTS:
49 50 void barsetChanged();
@@ -52,6 +53,8 protected:
52 53 QList<QBarSet *> m_barSets;
53 54 QBarCategories m_categories;
54 55 qreal m_barMargin;
56 bool m_labelsVisible;
57
55 58 private:
56 59 Q_DECLARE_PUBLIC(QBarSeries)
57 60 };
@@ -324,32 +324,11 QFont QBarSet::labelFont() const
324 324 return d_ptr->m_labelFont;
325 325 }
326 326
327 /*!
328 Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets.
329 */
330
331 void QBarSet::setLabelsVisible(bool visible)
332 {
333 if(d_ptr->m_labelsVisible!=visible) {
334 d_ptr->m_labelsVisible = visible;
335 emit d_ptr->labelsVisibleChanged(visible);
336 }
337 }
338
339 /*!
340 Returns the visibility of values
341 */
342 bool QBarSet::labelsVisible() const
343 {
344 return d_ptr->m_labelsVisible;
345 }
346
347 327 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
348 328
349 329 QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent),
350 330 q_ptr(parent),
351 m_name(name),
352 m_labelsVisible(false)
331 m_name(name)
353 332 {
354 333 }
355 334
@@ -41,16 +41,16 public:
41 41 void setName(const QString name);
42 42 QString name() const;
43 43
44 void append(const QPointF value); // Appends bar with x-value
45 void append(const QList<QPointF> values); // Same with list
46 void append(const qreal value); // TODO: change so, that count becomes x-value
47 void append(const QList<qreal> values); // Append list of values. Using index as x-value
44 void append(const QPointF value);
45 void append(const QList<QPointF> values);
46 void append(const qreal value);
47 void append(const QList<qreal> values);
48 48
49 QBarSet& operator << (const qreal &value); // TODO: change implementations so, that count becomes x-value
50 QBarSet& operator << (const QPointF &value); // Appends bar with x-value
49 QBarSet& operator << (const qreal &value);
50 QBarSet& operator << (const QPointF &value);
51 51
52 void insert(const int index, const qreal value); // TODO: internal reindexing (what happens, if there are points with real x values?)
53 void remove(const int index); // TODO: internal reindexing (what happens, if there are points with real x values?)
52 void insert(const int index, const qreal value);
53 void remove(const int index);
54 54 void replace(const int index, const qreal value);
55 55 QPointF at(const int index) const;
56 56 QPointF operator [] (const int index) const;
@@ -72,9 +72,6 public:
72 72 void setLabelFont(const QFont &font);
73 73 QFont labelFont() const;
74 74
75 void setLabelsVisible(bool visible = true);
76 bool labelsVisible() const;
77
78 75 Q_SIGNALS:
79 76 void clicked(QString category);
80 77 void hovered(bool status);
@@ -3,6 +3,9
3 3
4 4 #include "qbarset.h"
5 5 #include <QMap>
6 #include <QPen>
7 #include <QBrush>
8 #include <QFont>
6 9
7 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 11
@@ -18,7 +21,6 Q_SIGNALS:
18 21 void clicked(QString category);
19 22 void restructuredBars();
20 23 void updatedBars();
21 void labelsVisibleChanged(bool visible);
22 24
23 25 public:
24 26 QBarSet * const q_ptr;
@@ -29,7 +31,6 public:
29 31 QPen m_labelPen;
30 32 QBrush m_labelBrush;
31 33 QFont m_labelFont;
32 bool m_labelsVisible;
33 34
34 35 friend class QBarSet;
35 36 };
@@ -20,7 +20,6
20 20
21 21 #include "stackedbarchartitem_p.h"
22 22 #include "bar_p.h"
23 #include "barlabel_p.h"
24 23 #include "qbarset_p.h"
25 24 #include "qbarseries_p.h"
26 25 #include "qbarset.h"
@@ -64,7 +63,7 QVector<QRectF> StackedBarChartItem::calculateLayout()
64 63 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
65 64 layout.append(rect);
66 65
67 BarLabel* label = m_labels.at(itemIndex);
66 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
68 67
69 68 if (!qFuzzyIsNull(barSet->at(category).y())) {
70 69 label->setText(QString::number(barSet->at(category).y()));
@@ -403,27 +403,23 void tst_QBarSeries::setLabelsVisible_data()
403 403 void tst_QBarSeries::setLabelsVisible()
404 404 {
405 405 // labels should be invisible by default
406 foreach (QBarSet* s, m_testSets) {
407 QVERIFY(s->labelsVisible() == false);
408 }
406 QVERIFY(m_barseries->isLabelsVisible() == false);
407 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
409 408
410 409 // turn labels to visible
411 410 m_barseries_with_sets->setLabelsVisible(true);
412 foreach (QBarSet* s, m_testSets) {
413 QVERIFY(s->labelsVisible() == true);
414 }
411 // TODO: test the signal
412 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
415 413
416 414 // turn labels to invisible
417 415 m_barseries_with_sets->setLabelsVisible(false);
418 foreach (QBarSet* s, m_testSets) {
419 QVERIFY(s->labelsVisible() == false);
420 }
416 // TODO: test the signal
417 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
421 418
422 419 // without parameter, should turn labels to visible
423 420 m_barseries_with_sets->setLabelsVisible();
424 foreach (QBarSet* s, m_testSets) {
425 QVERIFY(s->labelsVisible() == true);
426 }
421 // TODO: test the signal
422 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
427 423 }
428 424
429 425 void tst_QBarSeries::mouseclicked_data()
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now