##// END OF EJS Templates
barcharts: added legend to model. added signals for hover events (for tooltip). updated examples
sauimone -
r280:9b4c1980ee18
parent child
Show More
@@ -1,7 +1,7
1 #include "custombarset.h"
1 #include "custombarset.h"
2
2
3 CustomBarSet::CustomBarSet(QObject *parent) :
3 CustomBarSet::CustomBarSet(QString name, QObject *parent) :
4 QBarSet(parent)
4 QBarSet(name, parent)
5 {
5 {
6 // Using signal to signal connection here.
6 // Using signal to signal connection here.
7 connect(this,SIGNAL(clicked()),this,SIGNAL(toggleFloatingValues()));
7 connect(this,SIGNAL(clicked()),this,SIGNAL(toggleFloatingValues()));
@@ -9,7 +9,7 class CustomBarSet : public QBarSet
9 {
9 {
10 Q_OBJECT
10 Q_OBJECT
11 public:
11 public:
12 explicit CustomBarSet(QObject *parent = 0);
12 explicit CustomBarSet(QString name, QObject *parent = 0);
13
13
14 signals:
14 signals:
15
15
@@ -20,11 +20,11 int main(int argc, char *argv[])
20 QBarChartSeries* series= new QBarChartSeries(category);
20 QBarChartSeries* series= new QBarChartSeries(category);
21
21
22 // We use custom set, which connects some signals. Could use QBarSet here if we don't need signals
22 // We use custom set, which connects some signals. Could use QBarSet here if we don't need signals
23 CustomBarSet *set0 = new CustomBarSet;
23 CustomBarSet *set0 = new CustomBarSet("Bub");
24 CustomBarSet *set1 = new CustomBarSet;
24 CustomBarSet *set1 = new CustomBarSet("Bob");
25 CustomBarSet *set2 = new CustomBarSet;
25 CustomBarSet *set2 = new CustomBarSet("Guybrush");
26 CustomBarSet *set3 = new CustomBarSet;
26 CustomBarSet *set3 = new CustomBarSet("Larry");
27 CustomBarSet *set4 = new CustomBarSet;
27 CustomBarSet *set4 = new CustomBarSet("Zak");
28
28
29 // Create some test data to chart
29 // Create some test data to chart
30 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
30 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
@@ -1,7 +1,7
1 #include "custombarset.h"
1 #include "custombarset.h"
2
2
3 CustomBarSet::CustomBarSet(QObject *parent) :
3 CustomBarSet::CustomBarSet(QString name, QObject *parent) :
4 QBarSet(parent)
4 QBarSet(name, parent)
5 {
5 {
6 // Using signal to signal connection here.
6 // Using signal to signal connection here.
7 connect(this,SIGNAL(clicked()),this,SIGNAL(toggleFloatingValues()));
7 connect(this,SIGNAL(clicked()),this,SIGNAL(toggleFloatingValues()));
@@ -9,7 +9,7 class CustomBarSet : public QBarSet
9 {
9 {
10 Q_OBJECT
10 Q_OBJECT
11 public:
11 public:
12 explicit CustomBarSet(QObject *parent = 0);
12 explicit CustomBarSet(QString name, QObject *parent = 0);
13
13
14 signals:
14 signals:
15
15
@@ -5,7 +5,6
5 #include <qbarcategory.h>
5 #include <qbarcategory.h>
6 #include <qchartview.h>
6 #include <qchartview.h>
7
7
8 //#include <qbarset.h>
9 #include "custombarset.h"
8 #include "custombarset.h"
10
9
11 QTCOMMERCIALCHART_USE_NAMESPACE
10 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -21,11 +20,11 int main(int argc, char *argv[])
21 QPercentBarChartSeries* series = new QPercentBarChartSeries(category);
20 QPercentBarChartSeries* series = new QPercentBarChartSeries(category);
22
21
23 // We use custom set, which connects some signals. Could use QBarSet here if we don't need signals
22 // We use custom set, which connects some signals. Could use QBarSet here if we don't need signals
24 CustomBarSet *set0 = new CustomBarSet;
23 CustomBarSet *set0 = new CustomBarSet("Bub");
25 CustomBarSet *set1 = new CustomBarSet;
24 CustomBarSet *set1 = new CustomBarSet("Bob");
26 CustomBarSet *set2 = new CustomBarSet;
25 CustomBarSet *set2 = new CustomBarSet("Guybrush");
27 CustomBarSet *set3 = new CustomBarSet;
26 CustomBarSet *set3 = new CustomBarSet("Larry");
28 CustomBarSet *set4 = new CustomBarSet;
27 CustomBarSet *set4 = new CustomBarSet("Zak");
29
28
30 // Create some test data to chart
29 // Create some test data to chart
31 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
30 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
@@ -1,7 +1,7
1 #include "custombarset.h"
1 #include "custombarset.h"
2
2
3 CustomBarSet::CustomBarSet(QObject *parent) :
3 CustomBarSet::CustomBarSet(QString name, QObject *parent) :
4 QBarSet(parent)
4 QBarSet(name, parent)
5 {
5 {
6 // Using signal to signal connection here.
6 // Using signal to signal connection here.
7 connect(this,SIGNAL(clicked()),this,SIGNAL(toggleFloatingValues()));
7 connect(this,SIGNAL(clicked()),this,SIGNAL(toggleFloatingValues()));
@@ -9,7 +9,7 class CustomBarSet : public QBarSet
9 {
9 {
10 Q_OBJECT
10 Q_OBJECT
11 public:
11 public:
12 explicit CustomBarSet(QObject *parent = 0);
12 explicit CustomBarSet(QString name, QObject *parent = 0);
13
13
14 signals:
14 signals:
15
15
@@ -20,11 +20,11 int main(int argc, char *argv[])
20 QStackedBarChartSeries* series = new QStackedBarChartSeries(category);
20 QStackedBarChartSeries* series = new QStackedBarChartSeries(category);
21
21
22 // We use custom set, which connects some signals. Could use QBarSet here if we don't need signals
22 // We use custom set, which connects some signals. Could use QBarSet here if we don't need signals
23 CustomBarSet *set0 = new CustomBarSet;
23 CustomBarSet *set0 = new CustomBarSet("Bub");
24 CustomBarSet *set1 = new CustomBarSet;
24 CustomBarSet *set1 = new CustomBarSet("Bob");
25 CustomBarSet *set2 = new CustomBarSet;
25 CustomBarSet *set2 = new CustomBarSet("Guybrush");
26 CustomBarSet *set3 = new CustomBarSet;
26 CustomBarSet *set3 = new CustomBarSet("Larry");
27 CustomBarSet *set4 = new CustomBarSet;
27 CustomBarSet *set4 = new CustomBarSet("Zak");
28
28
29 // Create some test data to chart
29 // Create some test data to chart
30 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
30 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
@@ -8,6 +8,7 Bar::Bar(QGraphicsItem *parent)
8 : QGraphicsObject(parent)
8 : QGraphicsObject(parent)
9 {
9 {
10 setAcceptedMouseButtons(Qt::LeftButton);
10 setAcceptedMouseButtons(Qt::LeftButton);
11 setAcceptHoverEvents(true);
11 }
12 }
12
13
13 void Bar::setSize(const QSizeF& size)
14 void Bar::setSize(const QSizeF& size)
@@ -23,11 +24,6 void Bar::resize( qreal w, qreal h )
23 mHeight = h;
24 mHeight = h;
24 }
25 }
25
26
26 void Bar::setColor( QColor col )
27 {
28 mColor = col;
29 }
30
31 void Bar::setPos(qreal x, qreal y)
27 void Bar::setPos(qreal x, qreal y)
32 {
28 {
33 mXpos = x;
29 mXpos = x;
@@ -72,14 +68,14 void Bar::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/)
72 emit clicked();
68 emit clicked();
73 }
69 }
74
70
75 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
71 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
76 {
72 {
77 emit hoverEntered();
73 emit hoverEntered(event);
78 }
74 }
79
75
80 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
76 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
81 {
77 {
82 emit hoverLeaved();
78 emit hoverLeaved(event);
83 }
79 }
84
80
85 #include "moc_bar_p.cpp"
81 #include "moc_bar_p.cpp"
@@ -8,7 +8,7
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 // Single bar item of chart
11 // Single visual bar item of chart
12 class Bar : public QGraphicsObject
12 class Bar : public QGraphicsObject
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
@@ -19,11 +19,10 public: // from ChartItem
19 void setSize(const QSizeF &size);
19 void setSize(const QSizeF &size);
20
20
21 // Layout Stuff
21 // Layout Stuff
22 void resize(qreal w, qreal h); // Size of bar.
22 void resize(qreal w, qreal h);
23 void setPos(qreal x, qreal y);
23 void setPos(qreal x, qreal y);
24 void setPen(QPen pen);
24 void setPen(QPen pen);
25 void setBrush(QBrush brush);
25 void setBrush(QBrush brush);
26 void setColor( QColor col); // deprecated
27
26
28 public:
27 public:
29 // From QGraphicsItem
28 // From QGraphicsItem
@@ -35,8 +34,8 public:
35
34
36 Q_SIGNALS:
35 Q_SIGNALS:
37 void clicked();
36 void clicked();
38 void hoverEntered();
37 void hoverEntered(QGraphicsSceneHoverEvent *event);
39 void hoverLeaved();
38 void hoverLeaved(QGraphicsSceneHoverEvent *event);
40
39
41 private:
40 private:
42
41
@@ -56,6 +56,16 QBarSet* BarChartModel::setAt(int index)
56 return mDataModel.at(index);
56 return mDataModel.at(index);
57 }
57 }
58
58
59 QList<QString> BarChartModel::legend()
60 {
61 QList<QString> legend;
62
63 for (int i=0; i<mDataModel.count(); i++) {
64 legend.append(mDataModel.at(i)->name());
65 }
66 return legend;
67 }
68
59 int BarChartModel::countSets()
69 int BarChartModel::countSets()
60 {
70 {
61 return mDataModel.count();
71 return mDataModel.count();
@@ -24,6 +24,7 public:
24 void removeBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
25 QBarSet* nextSet(bool getFirst);
25 QBarSet* nextSet(bool getFirst);
26 QBarSet *setAt(int index);
26 QBarSet *setAt(int index);
27 QList<QString> legend();
27
28
28 int countSets(); // Number of sets in model
29 int countSets(); // Number of sets in model
29 int countCategories(); // Number of categories
30 int countCategories(); // Number of categories
@@ -70,8 +70,9 void BarPresenterBase::dataChanged()
70 childItems().append(bar);
70 childItems().append(bar);
71 mBars.append(bar);
71 mBars.append(bar);
72 connect(bar,SIGNAL(clicked()),set,SLOT(barClicked()));
72 connect(bar,SIGNAL(clicked()),set,SLOT(barClicked()));
73 connect(bar,SIGNAL(hoverEntered()),set,SLOT(barHoverEntered()));
73 // TODO: should the event be passed to set or not?
74 connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaved()));
74 //connect(bar,SIGNAL(hoverEntered(QGraphicsSceneHoverEvent* event)),set,SLOT(barHoverEntered(QGraphicsSceneHoverEvent* event)));
75 //connect(bar,SIGNAL(hoverLeaved(QGraphicsSceneHoverEvent* event)),set,SLOT(barHoverLeaved(QGraphicsSceneHoverEvent *event)));
75 }
76 }
76 }
77 }
77
78
@@ -133,6 +134,17 void BarPresenterBase::handleGeometryChanged(const QRectF& rect)
133 setPos(rect.topLeft());
134 setPos(rect.topLeft());
134 }
135 }
135
136
137
138 void BarPresenterBase::barHoverEntered(QGraphicsSceneHoverEvent *event)
139 {
140 //TODO: show tooltip (name of series, where bar belongs...)
141 }
142
143 void BarPresenterBase::barHoverLeaved(QGraphicsSceneHoverEvent *event)
144 {
145 //TODO: hide tooltip (name of series, where bar belongs...)
146 }
147
136 #include "moc_barpresenterbase.cpp"
148 #include "moc_barpresenterbase.cpp"
137
149
138 QTCOMMERCIALCHART_END_NAMESPACE
150 QTCOMMERCIALCHART_END_NAMESPACE
@@ -46,6 +46,9 protected slots:
46 void handleDomainChanged(const Domain& domain);
46 void handleDomainChanged(const Domain& domain);
47 void handleGeometryChanged(const QRectF& size);
47 void handleGeometryChanged(const QRectF& size);
48
48
49 void barHoverEntered(QGraphicsSceneHoverEvent *event); // Internal.
50 void barHoverLeaved(QGraphicsSceneHoverEvent *event);
51
49 protected:
52 protected:
50
53
51 // TODO: consider these.
54 // TODO: consider these.
@@ -43,10 +43,12 void BarValue::setPos(qreal x, qreal y)
43 mYpos = y;
43 mYpos = y;
44 }
44 }
45
45
46 /*
46 bool BarValue::belongsToSet(QBarSet *set)
47 bool BarValue::belongsToSet(QBarSet *set)
47 {
48 {
48 return (&mBarSet == set);
49 return (&mBarSet == set);
49 }
50 }
51 */
50
52
51 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
53 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
52 {
54 {
@@ -27,7 +27,8 public:
27 void resize(qreal w, qreal h);
27 void resize(qreal w, qreal h);
28 void setPos(qreal x, qreal y);
28 void setPos(qreal x, qreal y);
29
29
30 bool belongsToSet(QBarSet *set);
30 // Propably not needed.
31 // bool belongsToSet(QBarSet *set);
31
32
32 // From QGraphicsItem
33 // From QGraphicsItem
33 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
34 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@@ -84,11 +84,14 void PercentBarPresenter::layoutChanged()
84 BarValue* value = mFloatingValues.at(itemIndex);
84 BarValue* value = mFloatingValues.at(itemIndex);
85
85
86 // TODO: remove hard coding, apply layout
86 // TODO: remove hard coding, apply layout
87 value->resize(100,50);
87 value->setPos(xPos, yPos-barHeight/2);
88 value->setPos(xPos, yPos-barHeight/2);
88 value->setPen(QPen(QColor(255,255,255,255)));
89 value->setPen(QPen(QColor(255,255,255,255)));
89
90
90 if (mModel.valueAt(set,category) != 0) {
91 if (mModel.valueAt(set,category) != 0) {
91 QString vString(QString::number(mModel.percentageAt(set,category) * 100));
92 int p = mModel.percentageAt(set,category) * 100;
93 QString vString(QString::number(p));
94 vString.truncate(3);
92 vString.append("%");
95 vString.append("%");
93 value->setValueString(vString);
96 value->setValueString(vString);
94 } else {
97 } else {
@@ -15,11 +15,15 QBarChartSeries::QBarChartSeries(QBarCategory *category, QObject *parent)
15
15
16 void QBarChartSeries::addBarSet(QBarSet *set)
16 void QBarChartSeries::addBarSet(QBarSet *set)
17 {
17 {
18 // connect(this,SIGNAL(floatingValuesEnabled(bool)),set,SLOT(enableFloatingValues(bool)));
19 // connect(this,SIGNAL(hoverNamesEnabled(bool)),set,SLOT(enableHoverNames(bool)));
18 mModel->addBarSet(set);
20 mModel->addBarSet(set);
19 }
21 }
20
22
21 void QBarChartSeries::removeBarSet(QBarSet *set)
23 void QBarChartSeries::removeBarSet(QBarSet *set)
22 {
24 {
25 // disconnect(set,SLOT(enableFloatingValues(bool)));
26 // disconnect(set,SLOT(enableHoverNames(bool)));
23 mModel->removeBarSet(set);
27 mModel->removeBarSet(set);
24 }
28 }
25
29
@@ -33,6 +37,21 QBarSet* QBarChartSeries::nextSet(bool getFirst)
33 return mModel->nextSet(getFirst);
37 return mModel->nextSet(getFirst);
34 }
38 }
35
39
40 QList<QString> QBarChartSeries::legend()
41 {
42 return mModel->legend();
43 }
44
45 void QBarChartSeries::enableFloatingValues(bool enabled)
46 {
47 emit floatingValuesEnabled(enabled);
48 }
49
50 void QBarChartSeries::enableHoverNames(bool enabled)
51 {
52 emit hoverNamesEnabled(enabled);
53 }
54
36 int QBarChartSeries::countCategories()
55 int QBarChartSeries::countCategories()
37 {
56 {
38 return mModel->countCategories();
57 return mModel->countCategories();
@@ -12,6 +12,7 class QBarSet;
12 class BarChartModel;
12 class BarChartModel;
13
13
14 // Container for series
14 // Container for series
15 // TODO: derive Stacked and percent bar charts from this?
15 class QTCOMMERCIALCHART_EXPORT QBarChartSeries : public QChartSeries
16 class QTCOMMERCIALCHART_EXPORT QBarChartSeries : public QChartSeries
16 {
17 {
17 Q_OBJECT
18 Q_OBJECT
@@ -21,12 +22,15 public:
21 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
22
23
23 void addBarSet(QBarSet *set); // Takes ownership of set
24 void addBarSet(QBarSet *set); // Takes ownership of set
24 void removeBarSet(QBarSet *set); // Removes set, releases ownership.
25 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
25 int countSets();
26 int countSets();
26 QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true
27 QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true
27
28
28 //TODO:
29 QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
29 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
30
31 // Disabled by default. Call these to change behavior.
32 void enableFloatingValues(bool enabled=true);
33 void enableHoverNames(bool enabled=true);
30
34
31 // TODO: Functions below this are not part of api and will be moved
35 // TODO: Functions below this are not part of api and will be moved
32 // to private implementation, when we start using it (not part of api)
36 // to private implementation, when we start using it (not part of api)
@@ -41,10 +45,16 public:
41 signals:
45 signals:
42 void changed(int index);
46 void changed(int index);
43
47
44 public Q_SLOTS:
48 // TODO: these to private implementation.
49 void floatingValuesEnabled(bool enabled);
50 void hoverNamesEnabled(bool enabled);
51
52
53 //public Q_SLOTS:
45
54
46 private:
55 private:
47 BarChartModel* mModel;
56 BarChartModel* mModel;
57
48 };
58 };
49
59
50 QTCOMMERCIALCHART_END_NAMESPACE
60 QTCOMMERCIALCHART_END_NAMESPACE
@@ -3,10 +3,12
3
3
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
5
6 QBarSet::QBarSet(QObject *parent)
6 QBarSet::QBarSet(QString name, QObject *parent)
7 : QObject(parent)
7 : QObject(parent)
8 ,mName(name)
9 ,mHoverNamesEnabled(true) // TODO: these 2 as false by default, when implementation is ready
10 ,mFloatingValuesEnabled(true)
8 {
11 {
9 mFloatingValuesVisible = false;
10 }
12 }
11
13
12 void QBarSet::setName(QString name)
14 void QBarSet::setName(QString name)
@@ -59,9 +61,16 const QBrush& QBarSet::brush() const
59 return mBrush;
61 return mBrush;
60 }
62 }
61
63
62 bool QBarSet::isFloatingValuesVisible()
64 void QBarSet::enableFloatingValues(bool enabled)
63 {
65 {
64 return mFloatingValuesVisible;
66 qDebug() << "QBarSet::enableFloatingValues" << enabled;
67 mFloatingValuesEnabled = enabled;
68 }
69
70 void QBarSet::enableHoverNames(bool enabled)
71 {
72 qDebug() << "QBarSet::enableHoverNames" << enabled;
73 mHoverNamesEnabled = enabled;
65 }
74 }
66
75
67 void QBarSet::barClicked()
76 void QBarSet::barClicked()
@@ -75,14 +84,18 void QBarSet::barClicked()
75 void QBarSet::barHoverEntered()
84 void QBarSet::barHoverEntered()
76 {
85 {
77 qDebug() << "QBarset::barHoverEntered" << this;
86 qDebug() << "QBarset::barHoverEntered" << this;
87 if (mHoverNamesEnabled) {
78 emit hoverEnter();
88 emit hoverEnter();
79 }
89 }
90 }
80
91
81 void QBarSet::barHoverLeaved()
92 void QBarSet::barHoverLeaved()
82 {
93 {
83 qDebug() << "QBarset::barHoverLeaved" << this;
94 qDebug() << "QBarset::barHoverLeaved" << this;
95 if (mHoverNamesEnabled) {
84 emit hoverLeave();
96 emit hoverLeave();
85 }
97 }
98 }
86
99
87 #include "moc_qbarset.cpp"
100 #include "moc_qbarset.cpp"
88 QTCOMMERCIALCHART_END_NAMESPACE
101 QTCOMMERCIALCHART_END_NAMESPACE
@@ -11,7 +11,7 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13 public:
13 public:
14 QBarSet(QObject *parent = 0);
14 QBarSet(QString name, QObject *parent = 0);
15
15
16 void setName(QString name);
16 void setName(QString name);
17 QString name();
17 QString name();
@@ -19,7 +19,7 public:
19
19
20 int count(); // count of values in set
20 int count(); // count of values in set
21 qreal valueAt(int index); // for modifying individual values
21 qreal valueAt(int index); // for modifying individual values
22 void setValue(int index, qreal value); //
22 void setValue(int index, qreal value); // setter for individual value
23
23
24 void setPen(const QPen& pen);
24 void setPen(const QPen& pen);
25 const QPen& pen() const;
25 const QPen& pen() const;
@@ -27,15 +27,18 public:
27 void setBrush(const QBrush& brush);
27 void setBrush(const QBrush& brush);
28 const QBrush& brush() const;
28 const QBrush& brush() const;
29
29
30 bool isFloatingValuesVisible();
31
32 Q_SIGNALS:
30 Q_SIGNALS:
33 void clicked();
31 void clicked(); // Clicked and hover signals exposed to user
34 void hoverEnter();
32 void hoverEnter();
35 void hoverLeave();
33 void hoverLeave();
36 void toggleFloatingValues();
34 void toggleFloatingValues(); // Private signal, TODO: move to private impl
37
35
38 public Q_SLOTS:
36 public Q_SLOTS:
37 void enableFloatingValues(bool enabled); // enables floating values on top of bars
38 void enableHoverNames(bool enabled); // enableHoverEvents would be better name?
39
40 // TODO: these slots belong to private implementation.
41 // These are for single bars to notify set about internal events
39 void barClicked();
42 void barClicked();
40 void barHoverEntered();
43 void barHoverEntered();
41 void barHoverLeaved();
44 void barHoverLeaved();
@@ -47,7 +50,9 private:
47 QPen mPen;
50 QPen mPen;
48 QBrush mBrush;
51 QBrush mBrush;
49
52
50 bool mFloatingValuesVisible;
53 // TODO: to pimpl
54 bool mFloatingValuesEnabled;
55 bool mHoverNamesEnabled;
51 };
56 };
52
57
53 QTCOMMERCIALCHART_END_NAMESPACE
58 QTCOMMERCIALCHART_END_NAMESPACE
@@ -15,11 +15,15 QPercentBarChartSeries::QPercentBarChartSeries(QBarCategory *category, QObject *
15
15
16 void QPercentBarChartSeries::addBarSet(QBarSet *set)
16 void QPercentBarChartSeries::addBarSet(QBarSet *set)
17 {
17 {
18 connect(this,SIGNAL(floatingValuesEnabled(bool)),set,SLOT(enableFloatingValues(bool)));
19 connect(this,SIGNAL(hoverNamesEnabled(bool)),set,SLOT(enableHoverNames(bool)));
18 mModel->addBarSet(set);
20 mModel->addBarSet(set);
19 }
21 }
20
22
21 void QPercentBarChartSeries::removeBarSet(QBarSet *set)
23 void QPercentBarChartSeries::removeBarSet(QBarSet *set)
22 {
24 {
25 disconnect(set,SLOT(enableFloatingValues(bool)));
26 disconnect(set,SLOT(enableHoverNames(bool)));
23 mModel->removeBarSet(set);
27 mModel->removeBarSet(set);
24 }
28 }
25
29
@@ -33,6 +37,11 QBarSet* QPercentBarChartSeries::nextSet(bool getFirst)
33 return mModel->nextSet(getFirst);
37 return mModel->nextSet(getFirst);
34 }
38 }
35
39
40 QList<QString> QPercentBarChartSeries::legend()
41 {
42 return mModel->legend();
43 }
44
36 int QPercentBarChartSeries::countCategories()
45 int QPercentBarChartSeries::countCategories()
37 {
46 {
38 return mModel->countCategories();
47 return mModel->countCategories();
@@ -21,12 +21,15 public:
21 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; }
21 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; }
22
22
23 void addBarSet(QBarSet *set); // Takes ownership
23 void addBarSet(QBarSet *set); // Takes ownership
24 void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned.
24 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
25 int countSets();
25 int countSets();
26 QBarSet* nextSet(bool first=false); // Returns first set, if called with true
26 QBarSet* nextSet(bool first=false); // Returns first set, if called with true
27
27
28 //TODO:
28 QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
29 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
29
30 // Disabled by default. Call these to change behavior.
31 void enableFloatingValues(bool enabled=true);
32 void enableHoverNames(bool enabled=true);
30
33
31 // TODO: Functions below this are not part of api and will be moved
34 // TODO: Functions below this are not part of api and will be moved
32 // to private implementation, when we start using it (not part of api)
35 // to private implementation, when we start using it (not part of api)
@@ -15,11 +15,15 QStackedBarChartSeries::QStackedBarChartSeries(QBarCategory *category, QObject *
15
15
16 void QStackedBarChartSeries::addBarSet(QBarSet *set)
16 void QStackedBarChartSeries::addBarSet(QBarSet *set)
17 {
17 {
18 connect(this,SIGNAL(floatingValuesEnabled(bool)),set,SLOT(enableFloatingValues(bool)));
19 connect(this,SIGNAL(hoverNamesEnabled(bool)),set,SLOT(enableHoverNames(bool)));
18 mModel->addBarSet(set);
20 mModel->addBarSet(set);
19 }
21 }
20
22
21 void QStackedBarChartSeries::removeBarSet(QBarSet *set)
23 void QStackedBarChartSeries::removeBarSet(QBarSet *set)
22 {
24 {
25 disconnect(set,SLOT(enableFloatingValues(bool)));
26 disconnect(set,SLOT(enableHoverNames(bool)));
23 mModel->removeBarSet(set);
27 mModel->removeBarSet(set);
24 }
28 }
25
29
@@ -33,6 +37,11 QBarSet* QStackedBarChartSeries::nextSet(bool getFirst)
33 return mModel->nextSet(getFirst);
37 return mModel->nextSet(getFirst);
34 }
38 }
35
39
40 QList<QString> QStackedBarChartSeries::legend()
41 {
42 return mModel->legend();
43 }
44
36 int QStackedBarChartSeries::countCategories()
45 int QStackedBarChartSeries::countCategories()
37 {
46 {
38 return mModel->countCategories();
47 return mModel->countCategories();
@@ -22,11 +22,15 public:
22
22
23 // Set handling
23 // Set handling
24 void addBarSet(QBarSet *set); // Takes ownership
24 void addBarSet(QBarSet *set); // Takes ownership
25 void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned.
25 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
26 int countSets();
26 int countSets();
27 QBarSet* nextSet(bool first=false); // Returns first set, if called with true
27 QBarSet* nextSet(bool first=false); // Returns first set, if called with true
28
28
29 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
29 QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
30
31 // Disabled by default. Call these to change behavior.
32 void enableFloatingValues(bool enabled=true);
33 void enableHoverNames(bool enabled=true);
30
34
31 // TODO: Functions below this are not part of api and will be moved
35 // TODO: Functions below this are not part of api and will be moved
32 // to private implementation, when we start using it (not part of api)
36 // to private implementation, when we start using it (not part of api)
General Comments 0
You need to be logged in to leave comments. Login now