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