@@ -0,0 +1,8 | |||
|
1 | #include "custombarset.h" | |
|
2 | ||
|
3 | CustomBarSet::CustomBarSet(QObject *parent) : | |
|
4 | QBarSet(parent) | |
|
5 | { | |
|
6 | // Using signal to signal connection here. | |
|
7 | connect(this,SIGNAL(clicked()),this,SIGNAL(toggleFloatingValues())); | |
|
8 | } |
@@ -0,0 +1,20 | |||
|
1 | #ifndef CUSTOMBARSET_H | |
|
2 | #define CUSTOMBARSET_H | |
|
3 | ||
|
4 | #include <qbarset.h> | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
7 | ||
|
8 | class CustomBarSet : public QBarSet | |
|
9 | { | |
|
10 | Q_OBJECT | |
|
11 | public: | |
|
12 | explicit CustomBarSet(QObject *parent = 0); | |
|
13 | ||
|
14 | signals: | |
|
15 | ||
|
16 | public slots: | |
|
17 | ||
|
18 | }; | |
|
19 | ||
|
20 | #endif // CUSTOMBARSET_H |
@@ -0,0 +1,8 | |||
|
1 | #include "custombarset.h" | |
|
2 | ||
|
3 | CustomBarSet::CustomBarSet(QObject *parent) : | |
|
4 | QBarSet(parent) | |
|
5 | { | |
|
6 | // Using signal to signal connection here. | |
|
7 | connect(this,SIGNAL(clicked()),this,SIGNAL(toggleFloatingValues())); | |
|
8 | } |
@@ -0,0 +1,20 | |||
|
1 | #ifndef CUSTOMBARSET_H | |
|
2 | #define CUSTOMBARSET_H | |
|
3 | ||
|
4 | #include <qbarset.h> | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
7 | ||
|
8 | class CustomBarSet : public QBarSet | |
|
9 | { | |
|
10 | Q_OBJECT | |
|
11 | public: | |
|
12 | explicit CustomBarSet(QObject *parent = 0); | |
|
13 | ||
|
14 | signals: | |
|
15 | ||
|
16 | public slots: | |
|
17 | ||
|
18 | }; | |
|
19 | ||
|
20 | #endif // CUSTOMBARSET_H |
@@ -0,0 +1,8 | |||
|
1 | #include "custombarset.h" | |
|
2 | ||
|
3 | CustomBarSet::CustomBarSet(QObject *parent) : | |
|
4 | QBarSet(parent) | |
|
5 | { | |
|
6 | // Using signal to signal connection here. | |
|
7 | connect(this,SIGNAL(clicked()),this,SIGNAL(toggleFloatingValues())); | |
|
8 | } |
@@ -0,0 +1,20 | |||
|
1 | #ifndef CUSTOMBARSET_H | |
|
2 | #define CUSTOMBARSET_H | |
|
3 | ||
|
4 | #include <qbarset.h> | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
7 | ||
|
8 | class CustomBarSet : public QBarSet | |
|
9 | { | |
|
10 | Q_OBJECT | |
|
11 | public: | |
|
12 | explicit CustomBarSet(QObject *parent = 0); | |
|
13 | ||
|
14 | signals: | |
|
15 | ||
|
16 | public slots: | |
|
17 | ||
|
18 | }; | |
|
19 | ||
|
20 | #endif // CUSTOMBARSET_H |
@@ -4,7 +4,9 | |||
|
4 | 4 | |
|
5 | 5 | TARGET = barchart |
|
6 | 6 | SOURCES += main.cpp \ |
|
7 | chartwidget.cpp | |
|
7 | chartwidget.cpp \ | |
|
8 | custombarset.cpp | |
|
8 | 9 | HEADERS += \ |
|
9 | chartwidget.h | |
|
10 | chartwidget.h \ | |
|
11 | custombarset.h | |
|
10 | 12 |
@@ -1,10 +1,11 | |||
|
1 | 1 | #include <QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | #include <QStandardItemModel> | |
|
3 | #include <qchartview.h> | |
|
4 | 4 | #include <qbarchartseries.h> |
|
5 | #include <qbarcategory.h> | |
|
6 | 5 | #include <qbarset.h> |
|
7 |
#include |
|
|
6 | #include <qbarcategory.h> | |
|
7 | ||
|
8 | #include "custombarset.h" | |
|
8 | 9 | |
|
9 | 10 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
10 | 11 | |
@@ -16,13 +17,14 int main(int argc, char *argv[]) | |||
|
16 | 17 | QBarCategory *category = new QBarCategory; |
|
17 | 18 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
18 | 19 | |
|
19 |
QBarChartSeries* series |
|
|
20 | QBarChartSeries* series= new QBarChartSeries(category); | |
|
20 | 21 | |
|
21 | QBarSet *set0 = new QBarSet; | |
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
22 | // We use custom set, which connects some signals. Could use QBarSet here if we don't need signals | |
|
23 | CustomBarSet *set0 = new CustomBarSet; | |
|
24 | CustomBarSet *set1 = new CustomBarSet; | |
|
25 | CustomBarSet *set2 = new CustomBarSet; | |
|
26 | CustomBarSet *set3 = new CustomBarSet; | |
|
27 | CustomBarSet *set4 = new CustomBarSet; | |
|
26 | 28 | |
|
27 | 29 | // Create some test data to chart |
|
28 | 30 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; |
@@ -31,16 +33,18 int main(int argc, char *argv[]) | |||
|
31 | 33 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; |
|
32 | 34 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; |
|
33 | 35 | |
|
34 |
series |
|
|
35 |
series |
|
|
36 |
series |
|
|
37 |
series |
|
|
38 |
series |
|
|
36 | series->addBarSet(set0); | |
|
37 | series->addBarSet(set1); | |
|
38 | series->addBarSet(set2); | |
|
39 | series->addBarSet(set3); | |
|
40 | series->addBarSet(set4); | |
|
39 | 41 | |
|
40 |
|
|
|
41 |
chart |
|
|
42 | QChartView* chartView = new QChartView(&window); | |
|
43 | chartView->addSeries(series); | |
|
44 | chartView->setChartTitle("simple stacked barchart"); | |
|
45 | chartView->setChartTheme(QChart::ChartThemeIcy); | |
|
42 | 46 | |
|
43 |
window.setCentralWidget(chart |
|
|
47 | window.setCentralWidget(chartView); | |
|
44 | 48 | window.resize(400, 300); |
|
45 | 49 | window.show(); |
|
46 | 50 |
@@ -2,9 +2,11 | |||
|
2 | 2 | #include <QMainWindow> |
|
3 | 3 | #include <QStandardItemModel> |
|
4 | 4 | #include <qpercentbarchartseries.h> |
|
5 | #include "chartwidget.h" | |
|
6 | 5 | #include <qbarcategory.h> |
|
7 |
#include <q |
|
|
6 | #include <qchartview.h> | |
|
7 | ||
|
8 | //#include <qbarset.h> | |
|
9 | #include "custombarset.h" | |
|
8 | 10 | |
|
9 | 11 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
10 | 12 | |
@@ -16,13 +18,14 int main(int argc, char *argv[]) | |||
|
16 | 18 | QBarCategory *category = new QBarCategory; |
|
17 | 19 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
18 | 20 | |
|
19 |
QPercentBarChartSeries* series |
|
|
21 | QPercentBarChartSeries* series = new QPercentBarChartSeries(category); | |
|
20 | 22 | |
|
21 | QBarSet *set0 = new QBarSet; | |
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
23 | // We use custom set, which connects some signals. Could use QBarSet here if we don't need signals | |
|
24 | CustomBarSet *set0 = new CustomBarSet; | |
|
25 | CustomBarSet *set1 = new CustomBarSet; | |
|
26 | CustomBarSet *set2 = new CustomBarSet; | |
|
27 | CustomBarSet *set3 = new CustomBarSet; | |
|
28 | CustomBarSet *set4 = new CustomBarSet; | |
|
26 | 29 | |
|
27 | 30 | // Create some test data to chart |
|
28 | 31 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; |
@@ -31,16 +34,18 int main(int argc, char *argv[]) | |||
|
31 | 34 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; |
|
32 | 35 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; |
|
33 | 36 | |
|
34 |
series |
|
|
35 |
series |
|
|
36 |
series |
|
|
37 |
series |
|
|
38 |
series |
|
|
37 | series->addBarSet(set0); | |
|
38 | series->addBarSet(set1); | |
|
39 | series->addBarSet(set2); | |
|
40 | series->addBarSet(set3); | |
|
41 | series->addBarSet(set4); | |
|
39 | 42 | |
|
40 |
|
|
|
41 |
chart |
|
|
43 | QChartView* chartView = new QChartView(&window); | |
|
44 | chartView->addSeries(series); | |
|
45 | chartView->setChartTitle("simple percent barchart"); | |
|
46 | chartView->setChartTheme(QChart::ChartThemeIcy); | |
|
42 | 47 | |
|
43 |
window.setCentralWidget(chart |
|
|
48 | window.setCentralWidget(chartView); | |
|
44 | 49 | window.resize(400, 300); |
|
45 | 50 | window.show(); |
|
46 | 51 |
@@ -4,7 +4,9 | |||
|
4 | 4 | |
|
5 | 5 | TARGET = percentbarchart |
|
6 | 6 | SOURCES += main.cpp \ |
|
7 | chartwidget.cpp | |
|
7 | chartwidget.cpp \ | |
|
8 | custombarset.cpp | |
|
8 | 9 | HEADERS += \ |
|
9 | chartwidget.h | |
|
10 | chartwidget.h \ | |
|
11 | custombarset.h | |
|
10 | 12 |
@@ -1,11 +1,12 | |||
|
1 | 1 | #include <QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | #include <QStandardItemModel> | |
|
3 | #include <qchartview.h> | |
|
4 | 4 | #include <qstackedbarchartseries.h> |
|
5 | #include "chartwidget.h" | |
|
6 | 5 | #include <qbarset.h> |
|
7 | 6 | #include <qbarcategory.h> |
|
8 | 7 | |
|
8 | #include "custombarset.h" | |
|
9 | ||
|
9 | 10 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
10 | 11 | |
|
11 | 12 | int main(int argc, char *argv[]) |
@@ -16,31 +17,34 int main(int argc, char *argv[]) | |||
|
16 | 17 | QBarCategory *category = new QBarCategory; |
|
17 | 18 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
18 | 19 | |
|
19 |
QStackedBarChartSeries* series |
|
|
20 | QStackedBarChartSeries* series = new QStackedBarChartSeries(category); | |
|
20 | 21 | |
|
21 | QBarSet *set0 = new QBarSet; | |
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
22 | // We use custom set, which connects some signals. Could use QBarSet here if we don't need signals | |
|
23 | CustomBarSet *set0 = new CustomBarSet; | |
|
24 | CustomBarSet *set1 = new CustomBarSet; | |
|
25 | CustomBarSet *set2 = new CustomBarSet; | |
|
26 | CustomBarSet *set3 = new CustomBarSet; | |
|
27 | CustomBarSet *set4 = new CustomBarSet; | |
|
26 | 28 | |
|
27 | 29 | // Create some test data to chart |
|
28 | 30 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; |
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
31 | *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; | |
|
32 | *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; | |
|
33 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; | |
|
32 | 34 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; |
|
33 | 35 | |
|
34 |
series |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
series |
|
|
36 | series->addBarSet(set0); | |
|
37 | series->addBarSet(set1); | |
|
38 | series->addBarSet(set2); | |
|
39 | series->addBarSet(set3); | |
|
40 | series->addBarSet(set4); | |
|
39 | 41 | |
|
40 |
|
|
|
41 |
chart |
|
|
42 | QChartView* chartView = new QChartView(&window); | |
|
43 | chartView->addSeries(series); | |
|
44 | chartView->setChartTitle("simple stacked barchart"); | |
|
45 | chartView->setChartTheme(QChart::ChartThemeIcy); | |
|
42 | 46 | |
|
43 |
window.setCentralWidget(chart |
|
|
47 | window.setCentralWidget(chartView); | |
|
44 | 48 | window.resize(400, 300); |
|
45 | 49 | window.show(); |
|
46 | 50 |
@@ -3,7 +3,9 | |||
|
3 | 3 | } |
|
4 | 4 | TARGET = stackedbarchart |
|
5 | 5 | SOURCES += main.cpp \ |
|
6 | chartwidget.cpp | |
|
6 | chartwidget.cpp \ | |
|
7 | custombarset.cpp | |
|
7 | 8 | HEADERS += \ |
|
8 | chartwidget.h | |
|
9 | chartwidget.h \ | |
|
10 | custombarset.h | |
|
9 | 11 |
@@ -72,6 +72,16 void Bar::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/) | |||
|
72 | 72 | emit clicked(); |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) | |
|
76 | { | |
|
77 | emit hoverEntered(); | |
|
78 | } | |
|
79 | ||
|
80 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) | |
|
81 | { | |
|
82 | emit hoverLeaved(); | |
|
83 | } | |
|
84 | ||
|
75 | 85 | #include "moc_bar_p.cpp" |
|
76 | 86 | |
|
77 | 87 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -27,13 +27,16 public: // from ChartItem | |||
|
27 | 27 | |
|
28 | 28 | public: |
|
29 | 29 | // From QGraphicsItem |
|
30 | ||
|
31 | 30 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
32 | 31 | QRectF boundingRect() const; |
|
33 | 32 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
33 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
|
34 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); | |
|
34 | 35 | |
|
35 | 36 | Q_SIGNALS: |
|
36 | 37 | void clicked(); |
|
38 | void hoverEntered(); | |
|
39 | void hoverLeaved(); | |
|
37 | 40 | |
|
38 | 41 | private: |
|
39 | 42 |
@@ -76,11 +76,14 void BarPresenter::layoutChanged() | |||
|
76 | 76 | |
|
77 | 77 | // TODO: remove hard coding, apply layout |
|
78 | 78 | value->resize(100,50); |
|
79 |
value->setPos(xPos |
|
|
79 | value->setPos(xPos, yPos-barHeight/2); | |
|
80 | 80 | value->setPen(QPen(QColor(255,255,255,255))); |
|
81 | 81 | |
|
82 |
|
|
|
83 |
value->setValueString( |
|
|
82 | if (mModel.valueAt(set,category) != 0) { | |
|
83 | value->setValueString(QString::number(mModel.valueAt(set,category))); | |
|
84 | } else { | |
|
85 | value->setValueString(QString("")); | |
|
86 | } | |
|
84 | 87 | |
|
85 | 88 | itemIndex++; |
|
86 | 89 | xPos += mBarDefaultWidth; |
@@ -70,6 +70,8 void BarPresenterBase::dataChanged() | |||
|
70 | 70 | childItems().append(bar); |
|
71 | 71 | mBars.append(bar); |
|
72 | 72 | connect(bar,SIGNAL(clicked()),set,SLOT(barClicked())); |
|
73 | connect(bar,SIGNAL(hoverEntered()),set,SLOT(barHoverEntered())); | |
|
74 | connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaved())); | |
|
73 | 75 | } |
|
74 | 76 | } |
|
75 | 77 | |
@@ -98,7 +100,7 void BarPresenterBase::dataChanged() | |||
|
98 | 100 | BarValue *value = new BarValue(*set, this); |
|
99 | 101 | childItems().append(value); |
|
100 | 102 | mFloatingValues.append(value); |
|
101 |
connect(set,SIGNAL( |
|
|
103 | connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible())); | |
|
102 | 104 | } |
|
103 | 105 | } |
|
104 | 106 |
@@ -84,12 +84,16 void PercentBarPresenter::layoutChanged() | |||
|
84 | 84 | BarValue* value = mFloatingValues.at(itemIndex); |
|
85 | 85 | |
|
86 | 86 | // TODO: remove hard coding, apply layout |
|
87 |
value->setPos(xPos |
|
|
87 | value->setPos(xPos, yPos-barHeight/2); | |
|
88 | 88 | value->setPen(QPen(QColor(255,255,255,255))); |
|
89 | 89 | |
|
90 |
|
|
|
91 | vString.append("%"); | |
|
92 | value->setValueString(vString); | |
|
90 | if (mModel.valueAt(set,category) != 0) { | |
|
91 | QString vString(QString::number(mModel.percentageAt(set,category) * 100)); | |
|
92 | vString.append("%"); | |
|
93 | value->setValueString(vString); | |
|
94 | } else { | |
|
95 | value->setValueString(QString("")); | |
|
96 | } | |
|
93 | 97 | |
|
94 | 98 | itemIndex++; |
|
95 | 99 | yPos -= barHeight; |
@@ -3,7 +3,8 | |||
|
3 | 3 | |
|
4 | 4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | 5 | |
|
6 | QBarSet::QBarSet() | |
|
6 | QBarSet::QBarSet(QObject *parent) | |
|
7 | : QObject(parent) | |
|
7 | 8 | { |
|
8 | 9 | mFloatingValuesVisible = false; |
|
9 | 10 | } |
@@ -71,5 +72,17 void QBarSet::barClicked() | |||
|
71 | 72 | emit clicked(); // Notify that set has been clicked |
|
72 | 73 | } |
|
73 | 74 | |
|
75 | void QBarSet::barHoverEntered() | |
|
76 | { | |
|
77 | qDebug() << "QBarset::barHoverEntered" << this; | |
|
78 | emit hoverEnter(); | |
|
79 | } | |
|
80 | ||
|
81 | void QBarSet::barHoverLeaved() | |
|
82 | { | |
|
83 | qDebug() << "QBarset::barHoverLeaved" << this; | |
|
84 | emit hoverLeave(); | |
|
85 | } | |
|
86 | ||
|
74 | 87 | #include "moc_qbarset.cpp" |
|
75 | 88 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,7 +1,7 | |||
|
1 | 1 | #ifndef QBARSET_H |
|
2 | 2 | #define QBARSET_H |
|
3 | 3 | |
|
4 |
#include |
|
|
4 | #include <qchartglobal.h> | |
|
5 | 5 | #include <QPen> |
|
6 | 6 | #include <QBrush> |
|
7 | 7 | |
@@ -11,7 +11,7 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |||
|
11 | 11 | { |
|
12 | 12 | Q_OBJECT |
|
13 | 13 | public: |
|
14 | QBarSet(); | |
|
14 | QBarSet(QObject *parent = 0); | |
|
15 | 15 | |
|
16 | 16 | void setName(QString name); |
|
17 | 17 | QString name(); |
@@ -31,13 +31,14 public: | |||
|
31 | 31 | |
|
32 | 32 | Q_SIGNALS: |
|
33 | 33 | void clicked(); |
|
34 | /* | |
|
35 | 34 | void hoverEnter(); |
|
36 | 35 | void hoverLeave(); |
|
37 | */ | |
|
36 | void toggleFloatingValues(); | |
|
38 | 37 | |
|
39 | 38 | public Q_SLOTS: |
|
40 | 39 | void barClicked(); |
|
40 | void barHoverEntered(); | |
|
41 | void barHoverLeaved(); | |
|
41 | 42 | |
|
42 | 43 | private: |
|
43 | 44 |
@@ -20,12 +20,12 public: | |||
|
20 | 20 | // from QChartSeries |
|
21 | 21 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; } |
|
22 | 22 | |
|
23 | // Set handling | |
|
23 | 24 | void addBarSet(QBarSet *set); // Takes ownership |
|
24 | 25 | void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned. |
|
25 | 26 | int countSets(); |
|
26 | 27 | QBarSet* nextSet(bool first=false); // Returns first set, if called with true |
|
27 | 28 | |
|
28 | //TODO: | |
|
29 | 29 | //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) |
|
30 | 30 | |
|
31 | 31 | // TODO: Functions below this are not part of api and will be moved |
@@ -88,11 +88,14 void StackedBarPresenter::layoutChanged() | |||
|
88 | 88 | |
|
89 | 89 | // TODO: remove hard coding, apply layout |
|
90 | 90 | value->resize(100,50); |
|
91 |
value->setPos(xPos |
|
|
91 | value->setPos(xPos, yPos-barHeight/2); | |
|
92 | 92 | value->setPen(QPen(QColor(255,255,255,255))); |
|
93 | 93 | |
|
94 |
|
|
|
95 |
value->setValueString( |
|
|
94 | if (mModel.valueAt(set,category) != 0) { | |
|
95 | value->setValueString(QString::number(mModel.valueAt(set,category))); | |
|
96 | } else { | |
|
97 | value->setValueString(QString("")); | |
|
98 | } | |
|
96 | 99 | |
|
97 | 100 | itemIndex++; |
|
98 | 101 | yPos -= barHeight; |
General Comments 0
You need to be logged in to leave comments.
Login now