@@ -1,49 +1,49 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <QStandardItemModel> |
|
3 | #include <QStandardItemModel> | |
4 | #include <barchartseries.h> |
|
4 | #include <barchartseries.h> | |
5 | #include <qbarcategory.h> |
|
5 | #include <qbarcategory.h> | |
6 | #include <qbarset.h> |
|
6 | #include <qbarset.h> | |
7 | #include "chartwidget.h" |
|
7 | #include "chartwidget.h" | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | QTCOMMERCIALCHART_USE_NAMESPACE | |
10 |
|
10 | |||
11 | int main(int argc, char *argv[]) |
|
11 | int main(int argc, char *argv[]) | |
12 | { |
|
12 | { | |
13 | QApplication a(argc, argv); |
|
13 | QApplication a(argc, argv); | |
14 | QMainWindow window; |
|
14 | QMainWindow window; | |
15 |
|
15 | |||
16 | QBarCategory category; |
|
16 | QBarCategory category; | |
17 | category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; |
|
17 | category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
18 |
|
18 | |||
19 | BarChartSeries* series0 = new BarChartSeries(category); |
|
19 | BarChartSeries* series0 = new BarChartSeries(category); | |
20 |
|
20 | |||
21 | QBarSet barSet0; |
|
21 | QBarSet barSet0; | |
22 | QBarSet barSet1; |
|
22 | QBarSet barSet1; | |
23 | QBarSet barSet2; |
|
23 | QBarSet barSet2; | |
24 | QBarSet barSet3; |
|
24 | QBarSet barSet3; | |
25 | QBarSet barSet4; |
|
25 | QBarSet barSet4; | |
26 |
|
26 | |||
27 | // Create some test data to chart |
|
27 | // Create some test data to chart | |
28 | barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10; |
|
28 | barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10; | |
29 | barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0; |
|
29 | barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0; | |
30 | barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1; |
|
30 | barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1; | |
31 | barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5; |
|
31 | barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5; | |
32 | barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10; |
|
32 | barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10; | |
33 |
|
33 | |||
34 | series0->addBarSet(barSet0); |
|
34 | series0->addBarSet(barSet0); | |
35 | series0->addBarSet(barSet1); |
|
35 | series0->addBarSet(barSet1); | |
36 | series0->addBarSet(barSet2); |
|
36 | series0->addBarSet(barSet2); | |
37 | series0->addBarSet(barSet3); |
|
37 | series0->addBarSet(barSet3); | |
38 | series0->addBarSet(barSet4); |
|
38 | series0->addBarSet(barSet4); | |
39 |
|
39 | |||
40 | ChartWidget* chartWidget = new ChartWidget(&window); |
|
40 | ChartWidget* chartWidget = new ChartWidget(&window); | |
41 | chartWidget->addSeries(series0); |
|
41 | chartWidget->addSeries(series0); | |
42 |
|
42 | |||
43 | window.setCentralWidget(chartWidget); |
|
43 | window.setCentralWidget(chartWidget); | |
44 | window.resize(400, 300); |
|
44 | window.resize(400, 300); | |
45 | window.show(); |
|
45 | window.show(); | |
46 |
|
46 | |||
47 | return a.exec(); |
|
47 | return a.exec(); | |
48 | } |
|
48 | } | |
49 |
|
49 |
@@ -1,49 +1,49 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <QStandardItemModel> |
|
3 | #include <QStandardItemModel> | |
4 | #include <percentbarchartseries.h> |
|
4 | #include <percentbarchartseries.h> | |
5 | #include "chartwidget.h" |
|
5 | #include "chartwidget.h" | |
6 | #include <qbarcategory.h> |
|
6 | #include <qbarcategory.h> | |
7 | #include <qbarset.h> |
|
7 | #include <qbarset.h> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | QTCOMMERCIALCHART_USE_NAMESPACE | |
10 |
|
10 | |||
11 | int main(int argc, char *argv[]) |
|
11 | int main(int argc, char *argv[]) | |
12 | { |
|
12 | { | |
13 | QApplication a(argc, argv); |
|
13 | QApplication a(argc, argv); | |
14 | QMainWindow window; |
|
14 | QMainWindow window; | |
15 |
|
15 | |||
16 | QBarCategory category; |
|
16 | QBarCategory category; | |
17 | category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; |
|
17 | category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
18 |
|
18 | |||
19 | PercentBarChartSeries* series0 = new PercentBarChartSeries(category); |
|
19 | PercentBarChartSeries* series0 = new PercentBarChartSeries(category); | |
20 |
|
20 | |||
21 | QBarSet barSet0; |
|
21 | QBarSet barSet0; | |
22 | QBarSet barSet1; |
|
22 | QBarSet barSet1; | |
23 | QBarSet barSet2; |
|
23 | QBarSet barSet2; | |
24 | QBarSet barSet3; |
|
24 | QBarSet barSet3; | |
25 | QBarSet barSet4; |
|
25 | QBarSet barSet4; | |
26 |
|
26 | |||
27 | // Create some test data to chart |
|
27 | // Create some test data to chart | |
28 | barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10; |
|
28 | barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10; | |
29 | barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0; |
|
29 | barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0; | |
30 | barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1; |
|
30 | barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1; | |
31 | barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5; |
|
31 | barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5; | |
32 | barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10; |
|
32 | barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10; | |
33 |
|
33 | |||
34 | series0->addBarSet(barSet0); |
|
34 | series0->addBarSet(barSet0); | |
35 | series0->addBarSet(barSet1); |
|
35 | series0->addBarSet(barSet1); | |
36 | series0->addBarSet(barSet2); |
|
36 | series0->addBarSet(barSet2); | |
37 | series0->addBarSet(barSet3); |
|
37 | series0->addBarSet(barSet3); | |
38 | series0->addBarSet(barSet4); |
|
38 | series0->addBarSet(barSet4); | |
39 |
|
39 | |||
40 | ChartWidget* chartWidget = new ChartWidget(&window); |
|
40 | ChartWidget* chartWidget = new ChartWidget(&window); | |
41 | chartWidget->addSeries(series0); |
|
41 | chartWidget->addSeries(series0); | |
42 |
|
42 | |||
43 | window.setCentralWidget(chartWidget); |
|
43 | window.setCentralWidget(chartWidget); | |
44 | window.resize(400, 300); |
|
44 | window.resize(400, 300); | |
45 | window.show(); |
|
45 | window.show(); | |
46 |
|
46 | |||
47 | return a.exec(); |
|
47 | return a.exec(); | |
48 | } |
|
48 | } | |
49 |
|
49 |
@@ -1,49 +1,49 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <QStandardItemModel> |
|
3 | #include <QStandardItemModel> | |
4 | #include <stackedbarchartseries.h> |
|
4 | #include <stackedbarchartseries.h> | |
5 | #include "chartwidget.h" |
|
5 | #include "chartwidget.h" | |
6 | #include <qbarset.h> |
|
6 | #include <qbarset.h> | |
7 | #include <qbarcategory.h> |
|
7 | #include <qbarcategory.h> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | QTCOMMERCIALCHART_USE_NAMESPACE | |
10 |
|
10 | |||
11 | int main(int argc, char *argv[]) |
|
11 | int main(int argc, char *argv[]) | |
12 | { |
|
12 | { | |
13 | QApplication a(argc, argv); |
|
13 | QApplication a(argc, argv); | |
14 | QMainWindow window; |
|
14 | QMainWindow window; | |
15 |
|
15 | |||
16 | QBarCategory category; |
|
16 | QBarCategory category; | |
17 | category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; |
|
17 | category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
18 |
|
18 | |||
19 | StackedBarChartSeries* series0 = new StackedBarChartSeries(category); |
|
19 | StackedBarChartSeries* series0 = new StackedBarChartSeries(category); | |
20 |
|
20 | |||
21 | QBarSet barSet0; |
|
21 | QBarSet barSet0; | |
22 | QBarSet barSet1; |
|
22 | QBarSet barSet1; | |
23 | QBarSet barSet2; |
|
23 | QBarSet barSet2; | |
24 | QBarSet barSet3; |
|
24 | QBarSet barSet3; | |
25 | QBarSet barSet4; |
|
25 | QBarSet barSet4; | |
26 |
|
26 | |||
27 | // Create some test data to chart |
|
27 | // Create some test data to chart | |
28 | barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10; |
|
28 | barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10; | |
29 | barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0; |
|
29 | barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0; | |
30 | barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1; |
|
30 | barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1; | |
31 | barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5; |
|
31 | barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5; | |
32 | barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10; |
|
32 | barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10; | |
33 |
|
33 | |||
34 | series0->addBarSet(barSet0); |
|
34 | series0->addBarSet(barSet0); | |
35 | series0->addBarSet(barSet1); |
|
35 | series0->addBarSet(barSet1); | |
36 | series0->addBarSet(barSet2); |
|
36 | series0->addBarSet(barSet2); | |
37 | series0->addBarSet(barSet3); |
|
37 | series0->addBarSet(barSet3); | |
38 | series0->addBarSet(barSet4); |
|
38 | series0->addBarSet(barSet4); | |
39 |
|
39 | |||
40 | ChartWidget* chartWidget = new ChartWidget(&window); |
|
40 | ChartWidget* chartWidget = new ChartWidget(&window); | |
41 | chartWidget->addSeries(series0); |
|
41 | chartWidget->addSeries(series0); | |
42 |
|
42 | |||
43 | window.setCentralWidget(chartWidget); |
|
43 | window.setCentralWidget(chartWidget); | |
44 | window.resize(400, 300); |
|
44 | window.resize(400, 300); | |
45 | window.show(); |
|
45 | window.show(); | |
46 |
|
46 | |||
47 | return a.exec(); |
|
47 | return a.exec(); | |
48 | } |
|
48 | } | |
49 |
|
49 |
@@ -1,175 +1,138 | |||||
1 | #include <limits.h> |
|
1 | #include <limits.h> | |
2 | #include <QVector> |
|
2 | #include <QVector> | |
3 | #include <QDebug> |
|
3 | #include <QDebug> | |
4 | #include "barchartmodel_p.h" |
|
4 | #include "barchartmodel_p.h" | |
5 | #include "qbarcategory.h" |
|
5 | #include "qbarcategory.h" | |
6 | #include "qbarset.h" |
|
6 | #include "qbarset.h" | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | BarChartModel::BarChartModel(QBarCategory &category, QObject *parent) : |
|
10 | BarChartModel::BarChartModel(QBarCategory &category, QObject *parent) : | |
11 | QObject(parent) |
|
11 | QObject(parent) | |
12 | ,mRunningId(1) |
|
|||
13 | ,mCategory(category) |
|
12 | ,mCategory(category) | |
14 | { |
|
13 | { | |
15 | } |
|
14 | } | |
16 |
|
15 | |||
17 | BarChartModel::~BarChartModel() |
|
16 | QBarCategory& BarChartModel::category() | |
18 | { |
|
17 | { | |
19 | // qDebug() << "BarChartModel::~BarChartModel"; |
|
18 | return mCategory; | |
20 | foreach (DataContainer* c, mDataModel) { |
|
|||
21 | delete c; |
|
|||
22 | } |
|
|||
23 | } |
|
|||
24 |
|
||||
25 | int BarChartModel::addData(QList<qreal> data) |
|
|||
26 | { |
|
|||
27 | // qDebug() << "BarChartModel::addData" << data.count(); |
|
|||
28 | DataContainer* c = new DataContainer(data,mRunningId); |
|
|||
29 | mDataModel.append(c); |
|
|||
30 | mRunningId++; |
|
|||
31 | emit modelUpdated(); |
|
|||
32 | return mRunningId-1; |
|
|||
33 | } |
|
|||
34 |
|
||||
35 | void BarChartModel::removeData(int id) |
|
|||
36 | { |
|
|||
37 | // qDebug() << "BarChartModel::removeData"; |
|
|||
38 | foreach(DataContainer* c, mDataModel) { |
|
|||
39 | if (c->mId == id) { |
|
|||
40 | mDataModel.removeOne(c); |
|
|||
41 | delete c; |
|
|||
42 | } |
|
|||
43 | } |
|
|||
44 | emit modelUpdated(); |
|
|||
45 | } |
|
19 | } | |
46 |
|
20 | |||
47 | void BarChartModel::addBarSet(QBarSet &set) |
|
21 | void BarChartModel::addBarSet(QBarSet &set) | |
48 | { |
|
22 | { | |
49 | DataContainer* c = new DataContainer(set.mValues,mRunningId); |
|
23 | mDataModel.append(&set); | |
50 | mDataModel.append(c); |
|
|||
51 | mRunningId++; |
|
|||
52 | } |
|
24 | } | |
53 |
|
25 | |||
54 | void BarChartModel::removeBarSet(QBarSet &set) |
|
26 | void BarChartModel::removeBarSet(QBarSet &set) | |
55 | { |
|
27 | { | |
56 | // TODO: |
|
28 | mDataModel.removeOne(&set); | |
57 | } |
|
29 | } | |
58 |
|
30 | |||
59 |
|
31 | |||
60 |
int BarChartModel::count |
|
32 | int BarChartModel::countSets() | |
61 | { |
|
33 | { | |
62 | // qDebug() << "BarChartModel::countRows"; |
|
|||
63 | return mDataModel.count(); |
|
34 | return mDataModel.count(); | |
64 | } |
|
35 | } | |
65 |
|
36 | |||
66 |
int BarChartModel::countC |
|
37 | int BarChartModel::countCategories() | |
67 | { |
|
38 | { | |
68 | // qDebug() << "BarChartModel::countColumns"; |
|
|||
69 | int count(0); |
|
39 | int count(0); | |
70 | for (int i=0; i<mDataModel.count(); i++){ |
|
40 | for (int i=0; i<mDataModel.count(); i++){ | |
71 | // TODO: can we assume that all series have same number of values? If not. then which values are empty? |
|
41 | // TODO: can we assume that all series have same number of values? If not. then which values are empty? | |
72 |
int temp = mDataModel.at(i)->count |
|
42 | int temp = mDataModel.at(i)->count(); | |
73 | if (temp > count) { |
|
43 | if (temp > count) { | |
74 | count = temp; |
|
44 | count = temp; | |
75 | } |
|
45 | } | |
76 | } |
|
46 | } | |
77 | return count; |
|
47 | return count; | |
78 | } |
|
48 | } | |
79 |
|
49 | |||
80 | int BarChartModel::countTotalItems() |
|
50 | int BarChartModel::countTotalItems() | |
81 | { |
|
51 | { | |
82 | // qDebug() << "BarChartModel::countTotalItems"; |
|
52 | int total = mDataModel.count() * countCategories(); | |
83 | int total = mDataModel.count() * countColumns(); |
|
|||
84 | return total; |
|
53 | return total; | |
85 | } |
|
54 | } | |
86 |
|
55 | |||
87 | qreal BarChartModel::min() |
|
56 | qreal BarChartModel::min() | |
88 | { |
|
57 | { | |
89 | // qDebug() << "BarChartModel::min"; |
|
|||
90 | Q_ASSERT(mDataModel.count() > 0); |
|
58 | Q_ASSERT(mDataModel.count() > 0); | |
91 | // TODO: make min and max members and update them when data changes. |
|
59 | // TODO: make min and max members and update them when data changes. | |
92 | // This is slower since they are checked every time, even if data is same since previous call. |
|
60 | // This is slower since they are checked every time, even if data is same since previous call. | |
93 | qreal min = INT_MAX; |
|
61 | qreal min = INT_MAX; | |
94 |
|
62 | |||
95 | for (int i=0; i <mDataModel.count(); i++) { |
|
63 | for (int i=0; i <mDataModel.count(); i++) { | |
96 |
int itemCount = mDataModel.at(i)->count |
|
64 | int itemCount = mDataModel.at(i)->count(); | |
97 | for (int j=0; j<itemCount; j++) { |
|
65 | for (int j=0; j<itemCount; j++) { | |
98 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
66 | qreal temp = mDataModel.at(i)->valueAt(j); | |
99 | if (temp < min) { |
|
67 | if (temp < min) { | |
100 | min = temp; |
|
68 | min = temp; | |
101 | } |
|
69 | } | |
102 | } |
|
70 | } | |
103 | } |
|
71 | } | |
104 | return min; |
|
72 | return min; | |
105 | } |
|
73 | } | |
106 |
|
74 | |||
107 | qreal BarChartModel::max() |
|
75 | qreal BarChartModel::max() | |
108 | { |
|
76 | { | |
109 | // qDebug() << "BarChartModel::max"; |
|
|||
110 | Q_ASSERT(mDataModel.count() > 0); |
|
77 | Q_ASSERT(mDataModel.count() > 0); | |
111 |
|
78 | |||
112 | // TODO: make min and max members and update them when data changes. |
|
79 | // TODO: make min and max members and update them when data changes. | |
113 | // This is slower since they are checked every time, even if data is same since previous call. |
|
80 | // This is slower since they are checked every time, even if data is same since previous call. | |
114 | qreal max = INT_MIN; |
|
81 | qreal max = INT_MIN; | |
115 |
|
82 | |||
116 | for (int i=0; i <mDataModel.count(); i++) { |
|
83 | for (int i=0; i <mDataModel.count(); i++) { | |
117 |
int itemCount = mDataModel.at(i)->count |
|
84 | int itemCount = mDataModel.at(i)->count(); | |
118 | for (int j=0; j<itemCount; j++) { |
|
85 | for (int j=0; j<itemCount; j++) { | |
119 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
86 | qreal temp = mDataModel.at(i)->valueAt(j); | |
120 | if (temp > max) { |
|
87 | if (temp > max) { | |
121 | max = temp; |
|
88 | max = temp; | |
122 | } |
|
89 | } | |
123 | } |
|
90 | } | |
124 | } |
|
91 | } | |
125 |
|
92 | |||
126 | return max; |
|
93 | return max; | |
127 | } |
|
94 | } | |
128 |
|
95 | |||
129 |
qreal BarChartModel::valueAt(int se |
|
96 | qreal BarChartModel::valueAt(int set, int category) | |
130 | { |
|
97 | { | |
131 | // qDebug() << "BarChartModel::valueAt" << series << item; |
|
98 | if ((set < 0) || (set >= mDataModel.count())) { | |
132 | if ((series < 0) || (series >= mDataModel.count())) { |
|
99 | // No set, no value. | |
133 | // No series, no value. |
|
|||
134 | return 0; |
|
100 | return 0; | |
135 |
} else if (( |
|
101 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { | |
136 |
// No |
|
102 | // No category, no value. | |
137 | return 0; |
|
103 | return 0; | |
138 | } |
|
104 | } | |
139 |
|
105 | |||
140 | // qDebug() << "ValueAt" << series << item << "=" << mDataModel.at(series)->valueAt(item); |
|
106 | return mDataModel.at(set)->valueAt(category); | |
141 | return mDataModel.at(series)->valueAt(item); |
|
|||
142 | } |
|
107 | } | |
143 |
|
108 | |||
144 |
qreal BarChartModel::c |
|
109 | qreal BarChartModel::categorySum(int column) | |
145 | { |
|
110 | { | |
146 | // qDebug() << "BarChartModel::columnSum"; |
|
111 | qreal sum(0); | |
147 | int sum(0); |
|
|||
148 | int count = mDataModel.count(); // Count rows |
|
112 | int count = mDataModel.count(); // Count rows | |
149 |
|
113 | |||
150 | for (int row = 0; row < count; row++) { |
|
114 | for (int row = 0; row < count; row++) { | |
151 |
if (column < mDataModel.at(row)->count |
|
115 | if (column < mDataModel.at(row)->count()) { | |
152 | sum += mDataModel.at(row)->valueAt(column); |
|
116 | sum += mDataModel.at(row)->valueAt(column); | |
153 | } |
|
117 | } | |
154 | } |
|
118 | } | |
155 | return sum; |
|
119 | return sum; | |
156 | } |
|
120 | } | |
157 |
|
121 | |||
158 |
qreal BarChartModel::maxC |
|
122 | qreal BarChartModel::maxCategorySum() | |
159 | { |
|
123 | { | |
160 | // qDebug() << "BarChartModel::maxColumnSum"; |
|
124 | qreal max = INT_MIN; | |
161 | int max = INT_MIN; |
|
125 | int count = countCategories(); | |
162 | int count = countColumns(); |
|
|||
163 |
|
126 | |||
164 | for (int col=0; col<count; col++) { |
|
127 | for (int col=0; col<count; col++) { | |
165 |
|
|
128 | qreal sum = categorySum(col); | |
166 | if (sum > max) { |
|
129 | if (sum > max) { | |
167 | max = sum; |
|
130 | max = sum; | |
168 | } |
|
131 | } | |
169 | } |
|
132 | } | |
170 | return max; |
|
133 | return max; | |
171 | } |
|
134 | } | |
172 |
|
135 | |||
173 | #include "moc_barchartmodel_p.cpp" |
|
136 | #include "moc_barchartmodel_p.cpp" | |
174 |
|
137 | |||
175 | QTCOMMERCIALCHART_END_NAMESPACE |
|
138 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,69 +1,50 | |||||
1 | #ifndef BARCHARTMODEL_H |
|
1 | #ifndef BARCHARTMODEL_H | |
2 | #define BARCHARTMODEL_H |
|
2 | #define BARCHARTMODEL_H | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include "qchartglobal.h" |
|
5 | #include "qchartglobal.h" | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | // Model for bar chart. Internal class. |
|
9 | // Model for bar chart. Internal class. | |
10 | // TODO: Implement as QAbstractItemModel? |
|
10 | // TODO: Implement as QAbstractItemModel? | |
11 |
|
11 | |||
12 | class QBarSet; |
|
12 | class QBarSet; | |
13 | class QBarCategory; |
|
13 | class QBarCategory; | |
14 |
|
14 | |||
15 | class BarChartModel : public QObject //, public QAbstractItemModel |
|
15 | class BarChartModel : public QObject //, public QAbstractItemModel | |
16 | { |
|
16 | { | |
17 | Q_OBJECT |
|
17 | Q_OBJECT | |
18 | public: |
|
18 | public: | |
19 | explicit BarChartModel(QBarCategory &category, QObject *parent = 0); |
|
19 | explicit BarChartModel(QBarCategory &category, QObject *parent = 0); | |
20 | ~BarChartModel(); |
|
|||
21 |
|
||||
22 | // TODO: remove these after add and remove QBarSet works. |
|
|||
23 | int addData(QList<qreal> data); |
|
|||
24 | void removeData(int id); |
|
|||
25 |
|
20 | |||
|
21 | QBarCategory& category(); | |||
26 | void addBarSet(QBarSet &set); |
|
22 | void addBarSet(QBarSet &set); | |
27 | void removeBarSet(QBarSet &set); |
|
23 | void removeBarSet(QBarSet &set); | |
28 |
|
24 | |||
29 |
int count |
|
25 | int countSets(); // Number of sets in model | |
30 |
int countC |
|
26 | int countCategories(); // Number of categories | |
31 |
int countTotalItems(); // Total items in all se |
|
27 | int countTotalItems(); // Total items in all sets. Includes empty items. | |
32 |
|
28 | |||
33 |
qreal max(); // Maximum value of all se |
|
29 | qreal max(); // Maximum value of all sets | |
34 |
qreal min(); // Minimum value of all se |
|
30 | qreal min(); // Minimum value of all sets | |
35 |
qreal valueAt(int se |
|
31 | qreal valueAt(int set, int category); | |
36 |
|
32 | |||
37 |
qreal c |
|
33 | qreal categorySum(int column); | |
38 |
qreal maxC |
|
34 | qreal maxCategorySum(); // returns maximum sum of sets in all categories. | |
39 |
|
35 | |||
40 | signals: |
|
36 | signals: | |
41 | void modelUpdated(); |
|
37 | void modelUpdated(); | |
42 |
|
38 | |||
43 | public slots: |
|
39 | public slots: | |
44 |
|
40 | |||
45 | private: |
|
41 | private: | |
46 |
|
42 | |||
47 | // Little helper class. |
|
43 | QList<QBarSet*> mDataModel; | |
48 | class DataContainer { |
|
|||
49 | public: |
|
|||
50 | DataContainer(QList<qreal> data, int id) : mId(id), mData(data) {} |
|
|||
51 | int countColumns() { return mData.count(); } |
|
|||
52 | qreal valueAt(int item) { return mData.at(item); } |
|
|||
53 |
|
||||
54 | int mId; // TODO: Is this needed? |
|
|||
55 | private: |
|
|||
56 | QList<qreal> mData; |
|
|||
57 | }; |
|
|||
58 |
|
||||
59 | // Owned. N series. each has a list of values. |
|
|||
60 | QList<DataContainer*> mDataModel; |
|
|||
61 | int mRunningId; |
|
|||
62 | int mMaxColumns; // longest series in datamodel |
|
|||
63 | QBarCategory& mCategory; |
|
44 | QBarCategory& mCategory; | |
64 |
|
45 | |||
65 | }; |
|
46 | }; | |
66 |
|
47 | |||
67 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | QTCOMMERCIALCHART_END_NAMESPACE | |
68 |
|
49 | |||
69 | #endif // BARCHARTMODEL_H |
|
50 | #endif // BARCHARTMODEL_H |
@@ -1,13 +1,23 | |||||
1 | #include <QDebug> |
|
1 | #include <QDebug> | |
2 | #include "barchartseries.h" |
|
2 | #include "barchartseries.h" | |
3 |
|
3 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
5 | |||
6 | BarChartSeries::BarChartSeries(QBarCategory &category, QObject *parent) |
|
6 | BarChartSeries::BarChartSeries(QBarCategory &category, QObject *parent) | |
7 | : BarChartSeriesBase(category, parent) |
|
7 | : BarChartSeriesBase(category, parent) | |
8 | { |
|
8 | { | |
9 | } |
|
9 | } | |
10 |
|
10 | |||
|
11 | void BarChartSeries::addBarSet(QBarSet &set) | |||
|
12 | { | |||
|
13 | BarChartSeriesBase::addBarSet(set); | |||
|
14 | } | |||
|
15 | ||||
|
16 | void BarChartSeries::removeBarSet(QBarSet &set) | |||
|
17 | { | |||
|
18 | BarChartSeriesBase::removeBarSet(set); | |||
|
19 | } | |||
|
20 | ||||
11 | #include "moc_barchartseries.cpp" |
|
21 | #include "moc_barchartseries.cpp" | |
12 |
|
22 | |||
13 | QTCOMMERCIALCHART_END_NAMESPACE |
|
23 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,29 +1,34 | |||||
1 | #ifndef BARCHARTSERIES_H |
|
1 | #ifndef BARCHARTSERIES_H | |
2 | #define BARCHARTSERIES_H |
|
2 | #define BARCHARTSERIES_H | |
3 |
|
3 | |||
4 | #include <QList> |
|
4 | #include <QList> | |
5 | #include <QAbstractItemModel> |
|
5 | #include <QAbstractItemModel> | |
6 | #include "barchartseriesbase.h" |
|
6 | #include "barchartseriesbase.h" | |
7 |
|
7 | |||
8 | class BarGroup; |
|
8 | class BarGroup; | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | // Container for series |
|
12 | // Container for series | |
13 | class QTCOMMERCIALCHART_EXPORT BarChartSeries : public BarChartSeriesBase |
|
13 | class QTCOMMERCIALCHART_EXPORT BarChartSeries : public BarChartSeriesBase | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 | public: |
|
16 | public: | |
17 | BarChartSeries(QBarCategory &category, QObject* parent=0); |
|
17 | BarChartSeries(QBarCategory &category, QObject* parent=0); | |
18 |
|
18 | |||
19 | // from BarChartSeriesBase |
|
19 | // from BarChartSeriesBase | |
20 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; } |
|
20 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; } | |
21 |
|
21 | |||
|
22 | void addBarSet(QBarSet &set); | |||
|
23 | void removeBarSet(QBarSet &set); | |||
|
24 | ||||
|
25 | public Q_SLOTS: | |||
|
26 | ||||
22 | private: |
|
27 | private: | |
23 |
|
28 | |||
24 | BarGroup* mBarGroup; |
|
29 | BarGroup* mBarGroup; | |
25 | }; |
|
30 | }; | |
26 |
|
31 | |||
27 | QTCOMMERCIALCHART_END_NAMESPACE |
|
32 | QTCOMMERCIALCHART_END_NAMESPACE | |
28 |
|
33 | |||
29 | #endif // BARCHARTSERIES_H |
|
34 | #endif // BARCHARTSERIES_H |
@@ -1,84 +1,71 | |||||
1 | #include <limits.h> |
|
1 | #include <limits.h> | |
2 | #include <QDebug> |
|
2 | #include <QDebug> | |
3 | #include "barchartseriesbase.h" |
|
3 | #include "barchartseriesbase.h" | |
4 | #include "bargroup.h" |
|
4 | #include "bargroup.h" | |
5 | #include "barchartmodel_p.h" |
|
5 | #include "barchartmodel_p.h" | |
6 | #include "qbarset.h" |
|
6 | #include "qbarset.h" | |
|
7 | #include "qbarcategory.h" | |||
7 |
|
8 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
10 | |||
10 | BarChartSeriesBase::BarChartSeriesBase(QBarCategory &category, QObject *parent) |
|
11 | BarChartSeriesBase::BarChartSeriesBase(QBarCategory &category, QObject *parent) | |
11 | : QChartSeries(parent) |
|
12 | : QChartSeries(parent) | |
12 | ,mModel(new BarChartModel(category, this)) |
|
13 | ,mModel(new BarChartModel(category, this)) | |
13 | { |
|
14 | { | |
14 | } |
|
15 | mLabels.append(category.items()); | |
15 |
|
||||
16 | int BarChartSeriesBase::addData(QList<qreal> data) |
|
|||
17 | { |
|
|||
18 | return mModel->addData(data); |
|
|||
19 | } |
|
|||
20 |
|
||||
21 | void BarChartSeriesBase::removeData(int id) |
|
|||
22 | { |
|
|||
23 | mModel->removeData(id); |
|
|||
24 | } |
|
|||
25 |
|
||||
26 | void BarChartSeriesBase::setLabels(QList<QString> labels) |
|
|||
27 | { |
|
|||
28 | mLabels = labels; |
|
|||
29 | } |
|
16 | } | |
30 |
|
17 | |||
31 | void BarChartSeriesBase::addBarSet(QBarSet &set) |
|
18 | void BarChartSeriesBase::addBarSet(QBarSet &set) | |
32 | { |
|
19 | { | |
33 | mModel->addBarSet(set); |
|
20 | mModel->addBarSet(set); | |
34 | } |
|
21 | } | |
35 |
|
22 | |||
36 | void BarChartSeriesBase::removeBarSet(QBarSet &set) |
|
23 | void BarChartSeriesBase::removeBarSet(QBarSet &set) | |
37 | { |
|
24 | { | |
38 | mModel->removeBarSet(set); |
|
25 | mModel->removeBarSet(set); | |
39 | } |
|
26 | } | |
40 |
|
27 | |||
41 | qreal BarChartSeriesBase::min() |
|
28 | qreal BarChartSeriesBase::min() | |
42 | { |
|
29 | { | |
43 | return mModel->min(); |
|
30 | return mModel->min(); | |
44 | } |
|
31 | } | |
45 |
|
32 | |||
46 | qreal BarChartSeriesBase::max() |
|
33 | qreal BarChartSeriesBase::max() | |
47 | { |
|
34 | { | |
48 | return mModel->max(); |
|
35 | return mModel->max(); | |
49 | } |
|
36 | } | |
50 |
|
37 | |||
51 | int BarChartSeriesBase::countColumns() |
|
38 | int BarChartSeriesBase::countColumns() | |
52 | { |
|
39 | { | |
53 |
return mModel->countC |
|
40 | return mModel->countCategories(); | |
54 | } |
|
41 | } | |
55 |
|
42 | |||
56 | qreal BarChartSeriesBase::valueAt(int series, int item) |
|
43 | qreal BarChartSeriesBase::valueAt(int series, int item) | |
57 | { |
|
44 | { | |
58 | // qDebug() << "BarChartSeriesBase::valueAt" << series << item; |
|
45 | // qDebug() << "BarChartSeriesBase::valueAt" << series << item; | |
59 | return mModel->valueAt(series,item); |
|
46 | return mModel->valueAt(series,item); | |
60 | } |
|
47 | } | |
61 |
|
48 | |||
62 | qreal BarChartSeriesBase::maxColumnSum() |
|
49 | qreal BarChartSeriesBase::maxColumnSum() | |
63 | { |
|
50 | { | |
64 | // qDebug() << "BarChartSeriesBase::maxColumnSum" << mModel->maxColumnSum(); |
|
51 | // qDebug() << "BarChartSeriesBase::maxColumnSum" << mModel->maxColumnSum(); | |
65 |
return mModel->maxC |
|
52 | return mModel->maxCategorySum(); | |
66 | } |
|
53 | } | |
67 |
|
54 | |||
68 | BarChartModel& BarChartSeriesBase::model() |
|
55 | BarChartModel& BarChartSeriesBase::model() | |
69 | { |
|
56 | { | |
70 | return *mModel; |
|
57 | return *mModel; | |
71 | } |
|
58 | } | |
72 |
|
59 | |||
73 | QString BarChartSeriesBase::label(int item) |
|
60 | QString BarChartSeriesBase::label(int item) | |
74 | { |
|
61 | { | |
75 | if ((item>=0) && (item < mLabels.count())) { |
|
62 | if ((item>=0) && (item < mLabels.count())) { | |
76 | return mLabels.at(item); |
|
63 | return mLabels.at(item); | |
77 | } |
|
64 | } | |
78 |
|
65 | |||
79 | return QString(""); |
|
66 | return QString(""); | |
80 | } |
|
67 | } | |
81 |
|
68 | |||
82 | #include "moc_barchartseriesbase.cpp" |
|
69 | #include "moc_barchartseriesbase.cpp" | |
83 |
|
70 | |||
84 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,60 +1,57 | |||||
1 | #ifndef BARCHARTSERIESBASE_H |
|
1 | #ifndef BARCHARTSERIESBASE_H | |
2 | #define BARCHARTSERIESBASE_H |
|
2 | #define BARCHARTSERIESBASE_H | |
3 |
|
3 | |||
4 | #include <QList> |
|
4 | #include <QList> | |
5 | #include <QAbstractItemModel> |
|
5 | #include <QAbstractItemModel> | |
6 | #include "qchartseries.h" |
|
6 | #include "qchartseries.h" | |
7 | #include "qchartglobal.h" |
|
7 | #include "qchartglobal.h" | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class BarGroupBase; |
|
11 | class BarGroupBase; | |
12 | class BarChartModel; |
|
12 | class BarChartModel; | |
13 | class QBarSet; |
|
13 | class QBarSet; | |
14 | class QBarCategory; |
|
14 | class QBarCategory; | |
15 |
|
15 | |||
16 | // Container for series |
|
16 | // Container for series | |
17 | class QTCOMMERCIALCHART_EXPORT BarChartSeriesBase : public QChartSeries |
|
17 | class QTCOMMERCIALCHART_EXPORT BarChartSeriesBase : public QChartSeries | |
18 | { |
|
18 | { | |
19 | Q_OBJECT |
|
19 | Q_OBJECT | |
20 | protected: |
|
20 | protected: | |
21 | // BarChartSeriesBase(QObject* parent=0); |
|
21 | // BarChartSeriesBase(QObject* parent=0); | |
22 | BarChartSeriesBase(QBarCategory &category, QObject* parent=0); |
|
22 | BarChartSeriesBase(QBarCategory &category, QObject* parent=0); | |
23 |
|
23 | |||
24 | public: |
|
24 | public: | |
25 | // from QChartSeries |
|
25 | // from QChartSeries | |
26 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeInvalid; } |
|
26 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeInvalid; } | |
27 |
|
27 | |||
28 | // TODO: These 3 will be removed. |
|
28 | protected: | |
29 | int addData(QList<qreal> data); |
|
29 | // Used by derived series | |
30 | void removeData(int id); |
|
30 | void addBarSet(QBarSet &set); | |
31 | void setLabels(QList<QString> labels); |
|
31 | void removeBarSet(QBarSet &set); | |
32 |
|
||||
33 | // TODO: Expose these to user in derived class instead of here? Common implementation for all bar charts, but not visible to user |
|
|||
34 | void addBarSet(QBarSet &set); // Bob[1,5,6,2,15,4] first value goes to category 1 etc.. |
|
|||
35 | void removeBarSet(QBarSet &set); // |
|
|||
36 |
|
32 | |||
|
33 | public: | |||
37 | // These shouldn't be visible to chart series user. However, ChartDataSet needs to access them, and friends are evil. |
|
34 | // These shouldn't be visible to chart series user. However, ChartDataSet needs to access them, and friends are evil. | |
38 | qreal min(); |
|
35 | qreal min(); | |
39 | qreal max(); |
|
36 | qreal max(); | |
40 | int countColumns(); // Count items in one series. |
|
37 | int countColumns(); // Count items in one series. | |
41 | qreal valueAt(int series, int item); |
|
38 | qreal valueAt(int series, int item); | |
42 | qreal maxColumnSum(); |
|
39 | qreal maxColumnSum(); | |
43 |
|
40 | |||
44 | BarChartModel& model(); |
|
41 | BarChartModel& model(); | |
45 | QString label(int item); |
|
42 | QString label(int item); | |
46 |
|
43 | |||
47 | signals: |
|
44 | signals: | |
48 | void changed(int index); |
|
45 | void changed(int index); | |
49 |
|
46 | |||
50 | public Q_SLOTS: |
|
47 | public Q_SLOTS: | |
51 |
|
48 | |||
52 | private: |
|
49 | private: | |
53 |
|
50 | |||
54 | BarChartModel* mModel; |
|
51 | BarChartModel* mModel; | |
55 | QList<QString> mLabels; |
|
52 | QList<QString> mLabels; | |
56 | }; |
|
53 | }; | |
57 |
|
54 | |||
58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
59 |
|
56 | |||
60 | #endif // BARCHARTSERIESBASE_H |
|
57 | #endif // BARCHARTSERIESBASE_H |
@@ -1,69 +1,69 | |||||
1 | #include "bargroup.h" |
|
1 | #include "bargroup.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : |
|
8 | BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : | |
9 | BarGroupBase(series,parent) |
|
9 | BarGroupBase(series,parent) | |
10 | { |
|
10 | { | |
11 | mBarDefaultWidth = 10; |
|
11 | mBarDefaultWidth = 10; | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | void BarGroup::layoutChanged() |
|
14 | void BarGroup::layoutChanged() | |
15 | { |
|
15 | { | |
16 | // qDebug() << "BarGroup::layoutChanged"; |
|
16 | // qDebug() << "BarGroup::layoutChanged"; | |
17 | // Scale bars to new layout |
|
17 | // Scale bars to new layout | |
18 | // Layout for bars: |
|
18 | // Layout for bars: | |
19 |
if (mModel.count |
|
19 | if (mModel.countSets() <= 0) { | |
20 | return; |
|
20 | return; | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | if (childItems().count() == 0) { |
|
23 | if (childItems().count() == 0) { | |
24 | qDebug() << "WARNING: BarGroup::layoutChanged called before graphics items are created!"; |
|
24 | qDebug() << "WARNING: BarGroup::layoutChanged called before graphics items are created!"; | |
25 | return; |
|
25 | return; | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | // TODO: better way to auto-layout? |
|
28 | // TODO: better way to auto-layout? | |
29 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
29 | // Use reals for accurancy (we might get some compiler warnings... :) | |
30 |
int itemCount = mModel.countC |
|
30 | int itemCount = mModel.countCategories(); | |
31 |
int seriesCount = mModel.count |
|
31 | int seriesCount = mModel.countSets(); | |
32 |
|
32 | |||
33 | qreal tW = mWidth; |
|
33 | qreal tW = mWidth; | |
34 | qreal tH = mHeight; |
|
34 | qreal tH = mHeight; | |
35 | qreal tM = mModel.max(); |
|
35 | qreal tM = mModel.max(); | |
36 | qreal scale = (tH/tM); |
|
36 | qreal scale = (tH/tM); | |
37 | qreal tC = itemCount+1; |
|
37 | qreal tC = itemCount+1; | |
38 | qreal xStepPerSeries = (tW/tC); |
|
38 | qreal xStepPerSeries = (tW/tC); | |
39 |
|
39 | |||
40 | // Scaling. |
|
40 | // Scaling. | |
41 | int itemIndex(0); |
|
41 | int itemIndex(0); | |
42 | int labelIndex = itemCount * seriesCount; |
|
42 | int labelIndex = itemCount * seriesCount; | |
43 |
|
43 | |||
44 | for (int item=0; item < itemCount; item++) { |
|
44 | for (int item=0; item < itemCount; item++) { | |
45 | qreal xPos = xStepPerSeries * item + ((tW + mBarDefaultWidth*seriesCount)/(itemCount*2)); |
|
45 | qreal xPos = xStepPerSeries * item + ((tW + mBarDefaultWidth*seriesCount)/(itemCount*2)); | |
46 | qreal yPos = mHeight; |
|
46 | qreal yPos = mHeight; | |
47 | for (int series = 0; series < seriesCount; series++) { |
|
47 | for (int series = 0; series < seriesCount; series++) { | |
48 | qreal barHeight = mModel.valueAt(series, item) * scale; |
|
48 | qreal barHeight = mModel.valueAt(series, item) * scale; | |
49 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
49 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
50 |
|
50 | |||
51 | // TODO: width settable per bar? |
|
51 | // TODO: width settable per bar? | |
52 | bar->resize(mBarDefaultWidth, barHeight); |
|
52 | bar->resize(mBarDefaultWidth, barHeight); | |
53 | bar->setColor(mColors.at(series)); |
|
53 | bar->setColor(mColors.at(series)); | |
54 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); |
|
54 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); | |
55 | itemIndex++; |
|
55 | itemIndex++; | |
56 | xPos += mBarDefaultWidth; |
|
56 | xPos += mBarDefaultWidth; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | // TODO: Layout for labels, remove magic number |
|
59 | // TODO: Layout for labels, remove magic number | |
60 | xPos = xStepPerSeries * item + ((tW + mBarDefaultWidth*seriesCount)/(itemCount*2)); |
|
60 | xPos = xStepPerSeries * item + ((tW + mBarDefaultWidth*seriesCount)/(itemCount*2)); | |
61 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
61 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
62 | label->setPos(xPos, mHeight + 20); |
|
62 | label->setPos(xPos, mHeight + 20); | |
63 | labelIndex++; |
|
63 | labelIndex++; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | mLayoutDirty = true; |
|
66 | mLayoutDirty = true; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,131 +1,131 | |||||
1 | #include "bargroupbase.h" |
|
1 | #include "bargroupbase.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include "separator_p.h" |
|
4 | #include "separator_p.h" | |
5 | #include "barchartseriesbase.h" |
|
5 | #include "barchartseriesbase.h" | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | BarGroupBase::BarGroupBase(BarChartSeriesBase& series, QGraphicsItem *parent) |
|
10 | BarGroupBase::BarGroupBase(BarChartSeriesBase& series, QGraphicsItem *parent) | |
11 | : ChartItem(parent) |
|
11 | : ChartItem(parent) | |
12 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready |
|
12 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
13 | ,mLayoutSet(false) |
|
13 | ,mLayoutSet(false) | |
14 | ,mLayoutDirty(true) |
|
14 | ,mLayoutDirty(true) | |
15 | ,mSeparatorsVisible(true) |
|
15 | ,mSeparatorsVisible(true) | |
16 | ,mModel(series.model()) |
|
16 | ,mModel(series.model()) | |
17 | ,mSeries(series) |
|
17 | ,mSeries(series) | |
18 | { |
|
18 | { | |
19 | dataChanged(); |
|
19 | dataChanged(); | |
20 | } |
|
20 | } | |
21 |
|
21 | |||
22 | void BarGroupBase::setSeparatorsVisible(bool visible) |
|
22 | void BarGroupBase::setSeparatorsVisible(bool visible) | |
23 | { |
|
23 | { | |
24 | mSeparatorsVisible = visible; |
|
24 | mSeparatorsVisible = visible; | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | void BarGroupBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
27 | void BarGroupBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
28 | { |
|
28 | { | |
29 | // qDebug() << "BarGroupBase::paint" << childItems().count(); |
|
29 | // qDebug() << "BarGroupBase::paint" << childItems().count(); | |
30 | if (!mLayoutSet) { |
|
30 | if (!mLayoutSet) { | |
31 | qDebug() << "BarGroupBase::paint called without layout set. Aborting."; |
|
31 | qDebug() << "BarGroupBase::paint called without layout set. Aborting."; | |
32 | return; |
|
32 | return; | |
33 | } |
|
33 | } | |
34 | // if (mLayoutDirty) { |
|
34 | // if (mLayoutDirty) { | |
35 | // Layout or data has changed. Need to redraw. |
|
35 | // Layout or data has changed. Need to redraw. | |
36 | foreach(QGraphicsItem* i, childItems()) { |
|
36 | foreach(QGraphicsItem* i, childItems()) { | |
37 | i->paint(painter,option,widget); |
|
37 | i->paint(painter,option,widget); | |
38 | } |
|
38 | } | |
39 | // } |
|
39 | // } | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QRectF BarGroupBase::boundingRect() const |
|
42 | QRectF BarGroupBase::boundingRect() const | |
43 | { |
|
43 | { | |
44 | return QRectF(0,0,mWidth,mHeight); |
|
44 | return QRectF(0,0,mWidth,mHeight); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void BarGroupBase::setBarWidth( int w ) |
|
47 | void BarGroupBase::setBarWidth( int w ) | |
48 | { |
|
48 | { | |
49 | mBarDefaultWidth = w; |
|
49 | mBarDefaultWidth = w; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | int BarGroupBase::addColor( QColor color ) |
|
52 | int BarGroupBase::addColor( QColor color ) | |
53 | { |
|
53 | { | |
54 | // qDebug() << "BarGroupBase::addColor"; |
|
54 | // qDebug() << "BarGroupBase::addColor"; | |
55 | int colorIndex = mColors.count(); |
|
55 | int colorIndex = mColors.count(); | |
56 | mColors.append(color); |
|
56 | mColors.append(color); | |
57 | return colorIndex; |
|
57 | return colorIndex; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void BarGroupBase::resetColors() |
|
60 | void BarGroupBase::resetColors() | |
61 | { |
|
61 | { | |
62 | // qDebug() << "BarGroupBase::resetColors"; |
|
62 | // qDebug() << "BarGroupBase::resetColors"; | |
63 | mColors.clear(); |
|
63 | mColors.clear(); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void BarGroupBase::dataChanged() |
|
66 | void BarGroupBase::dataChanged() | |
67 | { |
|
67 | { | |
68 | // qDebug() << "BarGroupBase::dataChanged"; |
|
68 | // qDebug() << "BarGroupBase::dataChanged"; | |
69 |
|
69 | |||
70 | // Delete old bars |
|
70 | // Delete old bars | |
71 | foreach (QGraphicsItem* item, childItems()) { |
|
71 | foreach (QGraphicsItem* item, childItems()) { | |
72 | delete item; |
|
72 | delete item; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | // Create new graphic items for bars |
|
75 | // Create new graphic items for bars | |
76 | int totalItems = mModel.countTotalItems(); // mSeries.countTotalItems(); |
|
76 | int totalItems = mModel.countTotalItems(); // mSeries.countTotalItems(); | |
77 | for (int i=0; i<totalItems; i++) { |
|
77 | for (int i=0; i<totalItems; i++) { | |
78 | Bar *bar = new Bar(this); |
|
78 | Bar *bar = new Bar(this); | |
79 | childItems().append(bar); |
|
79 | childItems().append(bar); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | // TODO: labels from series. This creates just some example labels |
|
82 | // TODO: labels from series. This creates just some example labels | |
83 |
int count = mModel.countC |
|
83 | int count = mModel.countCategories(); // mSeries.countColumns(); | |
84 | for (int i=0; i<count; i++) { |
|
84 | for (int i=0; i<count; i++) { | |
85 | BarLabel* label = new BarLabel(this); |
|
85 | BarLabel* label = new BarLabel(this); | |
86 | // QString text("Label " + QString::number(i)); |
|
86 | // QString text("Label " + QString::number(i)); | |
87 | label->set(mSeries.label(i)); |
|
87 | label->set(mSeries.label(i)); | |
88 | childItems().append(label); |
|
88 | childItems().append(label); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 |
count = mModel.countC |
|
91 | count = mModel.countCategories() - 1; // mSeries.countColumns() - 1; // There is one less separator than columns | |
92 | for (int i=0; i<count; i++) { |
|
92 | for (int i=0; i<count; i++) { | |
93 | Separator* sep = new Separator(this); |
|
93 | Separator* sep = new Separator(this); | |
94 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme |
|
94 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme | |
95 | childItems().append(sep); |
|
95 | childItems().append(sep); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | // TODO: if (autolayout) { layoutChanged() } or something |
|
98 | // TODO: if (autolayout) { layoutChanged() } or something | |
99 | mLayoutDirty = true; |
|
99 | mLayoutDirty = true; | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | //handlers |
|
102 | //handlers | |
103 |
|
103 | |||
104 | void BarGroupBase::handleModelChanged(int index) |
|
104 | void BarGroupBase::handleModelChanged(int index) | |
105 | { |
|
105 | { | |
106 | qDebug() << "BarGroupBase::handleModelChanged" << index; |
|
106 | qDebug() << "BarGroupBase::handleModelChanged" << index; | |
107 | dataChanged(); |
|
107 | dataChanged(); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void BarGroupBase::handleDomainChanged(const Domain& domain) |
|
110 | void BarGroupBase::handleDomainChanged(const Domain& domain) | |
111 | { |
|
111 | { | |
112 | // qDebug() << "BarGroupBase::handleDomainChanged"; |
|
112 | // qDebug() << "BarGroupBase::handleDomainChanged"; | |
113 |
|
113 | |||
114 | // TODO: Figure out the use case for this. |
|
114 | // TODO: Figure out the use case for this. | |
115 | // Affects the size of visible item, so layout is changed. |
|
115 | // Affects the size of visible item, so layout is changed. | |
116 | // layoutChanged(); |
|
116 | // layoutChanged(); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | void BarGroupBase::handleGeometryChanged(const QRectF& rect) |
|
119 | void BarGroupBase::handleGeometryChanged(const QRectF& rect) | |
120 | { |
|
120 | { | |
121 | // qDebug() << "BarGroupBase::handleGeometryChanged"; |
|
121 | // qDebug() << "BarGroupBase::handleGeometryChanged"; | |
122 | mWidth = rect.width(); |
|
122 | mWidth = rect.width(); | |
123 | mHeight = rect.height(); |
|
123 | mHeight = rect.height(); | |
124 | layoutChanged(); |
|
124 | layoutChanged(); | |
125 | mLayoutSet = true; |
|
125 | mLayoutSet = true; | |
126 | setPos(rect.topLeft()); |
|
126 | setPos(rect.topLeft()); | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | #include "moc_bargroupbase.cpp" |
|
129 | #include "moc_bargroupbase.cpp" | |
130 |
|
130 | |||
131 | QTCOMMERCIALCHART_END_NAMESPACE |
|
131 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,17 +1,27 | |||||
1 | #include "percentbarchartseries.h" |
|
1 | #include "percentbarchartseries.h" | |
2 |
|
2 | |||
3 | #include <limits.h> |
|
3 | #include <limits.h> | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 | #include "percentbarchartseries.h" |
|
5 | #include "percentbarchartseries.h" | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | PercentBarChartSeries::PercentBarChartSeries(QBarCategory &category, QObject *parent) : |
|
9 | PercentBarChartSeries::PercentBarChartSeries(QBarCategory &category, QObject *parent) : | |
10 | BarChartSeriesBase(category, parent) |
|
10 | BarChartSeriesBase(category, parent) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
|
14 | void PercentBarChartSeries::addBarSet(QBarSet &set) | |||
|
15 | { | |||
|
16 | BarChartSeriesBase::addBarSet(set); | |||
|
17 | } | |||
|
18 | ||||
|
19 | void PercentBarChartSeries::removeBarSet(QBarSet &set) | |||
|
20 | { | |||
|
21 | BarChartSeriesBase::removeBarSet(set); | |||
|
22 | } | |||
|
23 | ||||
14 | #include "moc_percentbarchartseries.cpp" |
|
24 | #include "moc_percentbarchartseries.cpp" | |
15 |
|
25 | |||
16 | QTCOMMERCIALCHART_END_NAMESPACE |
|
26 | QTCOMMERCIALCHART_END_NAMESPACE | |
17 |
|
27 |
@@ -1,31 +1,34 | |||||
1 | #ifndef PERCENTBARCHARTSERIES_H |
|
1 | #ifndef PERCENTBARCHARTSERIES_H | |
2 | #define PERCENTBARCHARTSERIES_H |
|
2 | #define PERCENTBARCHARTSERIES_H | |
3 |
|
3 | |||
4 | #include <QList> |
|
4 | #include <QList> | |
5 | #include <QAbstractItemModel> |
|
5 | #include <QAbstractItemModel> | |
6 | #include "barchartseriesbase.h" |
|
6 | #include "barchartseriesbase.h" | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class PercentBarGroup; |
|
10 | class PercentBarGroup; | |
11 |
|
11 | |||
12 | class QTCOMMERCIALCHART_EXPORT PercentBarChartSeries : public BarChartSeriesBase |
|
12 | class QTCOMMERCIALCHART_EXPORT PercentBarChartSeries : public BarChartSeriesBase | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | PercentBarChartSeries(QBarCategory &category, QObject* parent=0); |
|
16 | PercentBarChartSeries(QBarCategory &category, QObject* parent=0); | |
17 |
|
17 | |||
18 | // from BarChartSeriesBase |
|
18 | // from BarChartSeriesBase | |
19 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; } |
|
19 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; } | |
20 |
|
20 | |||
|
21 | void addBarSet(QBarSet &set); | |||
|
22 | void removeBarSet(QBarSet &set); | |||
|
23 | ||||
21 | public Q_SLOTS: |
|
24 | public Q_SLOTS: | |
22 |
|
25 | |||
23 | private: |
|
26 | private: | |
24 |
|
27 | |||
25 | PercentBarGroup* mPercentBarGroup; |
|
28 | PercentBarGroup* mPercentBarGroup; | |
26 | }; |
|
29 | }; | |
27 |
|
30 | |||
28 | QTCOMMERCIALCHART_END_NAMESPACE |
|
31 | QTCOMMERCIALCHART_END_NAMESPACE | |
29 |
|
32 | |||
30 |
|
33 | |||
31 | #endif // PERCENTBARCHARTSERIES_H |
|
34 | #endif // PERCENTBARCHARTSERIES_H |
@@ -1,77 +1,77 | |||||
1 | #include "percentbargroup.h" |
|
1 | #include "percentbargroup.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include "separator_p.h" |
|
4 | #include "separator_p.h" | |
5 | #include <QDebug> |
|
5 | #include <QDebug> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : |
|
10 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : | |
11 | BarGroupBase(series, parent) |
|
11 | BarGroupBase(series, parent) | |
12 | { |
|
12 | { | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | void PercentBarGroup::layoutChanged() |
|
15 | void PercentBarGroup::layoutChanged() | |
16 | { |
|
16 | { | |
17 | // Scale bars to new layout |
|
17 | // Scale bars to new layout | |
18 | // Layout for bars: |
|
18 | // Layout for bars: | |
19 |
if (mModel.count |
|
19 | if (mModel.countSets() <= 0) { | |
20 | // Nothing to do. |
|
20 | // Nothing to do. | |
21 | return; |
|
21 | return; | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | if (childItems().count() == 0) { |
|
24 | if (childItems().count() == 0) { | |
25 | qDebug() << "WARNING: PercentBarGroup::layoutChanged called before graphics items are created!"; |
|
25 | qDebug() << "WARNING: PercentBarGroup::layoutChanged called before graphics items are created!"; | |
26 | return; |
|
26 | return; | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | // TODO: better way to auto-layout |
|
29 | // TODO: better way to auto-layout | |
30 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
30 | // Use reals for accurancy (we might get some compiler warnings... :) | |
31 |
int count = mModel.countC |
|
31 | int count = mModel.countCategories(); | |
32 | int itemIndex(0); |
|
32 | int itemIndex(0); | |
33 | qreal tW = mWidth; |
|
33 | qreal tW = mWidth; | |
34 | qreal tC = count+1; |
|
34 | qreal tC = count+1; | |
35 | qreal xStep = (tW/tC); |
|
35 | qreal xStep = (tW/tC); | |
36 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
36 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
37 |
int labelIndex = mModel.countC |
|
37 | int labelIndex = mModel.countCategories() * mModel.countSets(); | |
38 |
|
38 | |||
39 |
for (int column = 0; column < mModel.countC |
|
39 | for (int column = 0; column < mModel.countCategories(); column++) { | |
40 |
qreal colSum = mModel.c |
|
40 | qreal colSum = mModel.categorySum(column); | |
41 | qreal h = mHeight; |
|
41 | qreal h = mHeight; | |
42 | qreal scale = (h / colSum); |
|
42 | qreal scale = (h / colSum); | |
43 | qreal yPos = h; |
|
43 | qreal yPos = h; | |
44 |
for (int row=0; row < mModel.count |
|
44 | for (int row=0; row < mModel.countSets(); row++) { | |
45 | qreal barHeight = mModel.valueAt(row, column) * scale; |
|
45 | qreal barHeight = mModel.valueAt(row, column) * scale; | |
46 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
46 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
47 |
|
47 | |||
48 | // TODO: width settable per bar? |
|
48 | // TODO: width settable per bar? | |
49 | bar->resize(mBarDefaultWidth, barHeight); |
|
49 | bar->resize(mBarDefaultWidth, barHeight); | |
50 | bar->setColor(mColors.at(row)); |
|
50 | bar->setColor(mColors.at(row)); | |
51 | bar->setPos(xPos, yPos-barHeight); |
|
51 | bar->setPos(xPos, yPos-barHeight); | |
52 | itemIndex++; |
|
52 | itemIndex++; | |
53 | yPos -= barHeight; |
|
53 | yPos -= barHeight; | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | // TODO: Layout for labels, remove magic number |
|
56 | // TODO: Layout for labels, remove magic number | |
57 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
57 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
58 | label->setPos(xPos, mHeight + 20); |
|
58 | label->setPos(xPos, mHeight + 20); | |
59 | labelIndex++; |
|
59 | labelIndex++; | |
60 | xPos += xStep; |
|
60 | xPos += xStep; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | // Position separators |
|
63 | // Position separators | |
64 | int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? |
|
64 | int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? | |
65 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. |
|
65 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. | |
66 |
for (int s=0; s < mModel.countC |
|
66 | for (int s=0; s < mModel.countCategories() - 1; s++) { | |
67 | Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex)); |
|
67 | Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex)); | |
68 | sep->setPos(xPos,0); |
|
68 | sep->setPos(xPos,0); | |
69 | sep->setSize(QSizeF(1,mHeight)); |
|
69 | sep->setSize(QSizeF(1,mHeight)); | |
70 | xPos += xStep; |
|
70 | xPos += xStep; | |
71 | separatorIndex++; |
|
71 | separatorIndex++; | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | mLayoutDirty = true; |
|
74 | mLayoutDirty = true; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,20 +1,35 | |||||
1 | #include "qbarset.h" |
|
1 | #include "qbarset.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | QBarSet::QBarSet() |
|
5 | QBarSet::QBarSet() | |
6 | { |
|
6 | { | |
7 | } |
|
7 | } | |
8 |
|
8 | |||
9 | void QBarSet::setName(QString name) |
|
9 | void QBarSet::setName(QString name) | |
10 | { |
|
10 | { | |
11 | mName = name; |
|
11 | mName = name; | |
12 | } |
|
12 | } | |
|
13 | QString QBarSet::name() | |||
|
14 | { | |||
|
15 | return mName; | |||
|
16 | } | |||
13 |
|
17 | |||
14 | QBarSet& QBarSet::operator << (const qreal &value) |
|
18 | QBarSet& QBarSet::operator << (const qreal &value) | |
15 | { |
|
19 | { | |
16 | mValues.append(value); |
|
20 | mValues.append(value); | |
17 | return *this; |
|
21 | return *this; | |
18 | } |
|
22 | } | |
19 |
|
23 | |||
|
24 | int QBarSet::count() | |||
|
25 | { | |||
|
26 | return mValues.count(); | |||
|
27 | } | |||
|
28 | ||||
|
29 | qreal QBarSet::valueAt(int index) | |||
|
30 | { | |||
|
31 | return mValues.at(index); | |||
|
32 | } | |||
|
33 | ||||
|
34 | ||||
20 | QTCOMMERCIALCHART_END_NAMESPACE |
|
35 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,29 +1,31 | |||||
1 | #ifndef QBARSET_H |
|
1 | #ifndef QBARSET_H | |
2 | #define QBARSET_H |
|
2 | #define QBARSET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | class QTCOMMERCIALCHART_EXPORT QBarSet // : pubclic QObject // TODO: Need for this? |
|
8 | class QTCOMMERCIALCHART_EXPORT QBarSet // : pubclic QObject // TODO: Need for this? | |
9 | { |
|
9 | { | |
10 | public: |
|
10 | public: | |
11 | QBarSet(); |
|
11 | QBarSet(); | |
12 |
|
12 | |||
13 | void setName(QString name); |
|
13 | void setName(QString name); | |
14 | // void setValues(QList<qreal> &values); |
|
14 | QString name(); | |
15 |
|
||||
16 | // TODO: |
|
|||
17 | QBarSet& operator << (const qreal &value); |
|
15 | QBarSet& operator << (const qreal &value); | |
18 |
|
16 | |||
19 | // TODO: Hide these from user of QBarSet. (but data model needs access to these) |
|
17 | //TODO: What is the way to set a single value to n:th item? Is there need for such functionality? | |
20 | public: |
|
18 | ||
|
19 | int count(); | |||
|
20 | qreal valueAt(int index); | |||
|
21 | ||||
|
22 | private: | |||
21 |
|
23 | |||
22 | QString mName; |
|
24 | QString mName; | |
23 | QList<qreal> mValues; |
|
25 | QList<qreal> mValues; | |
24 |
|
26 | |||
25 | }; |
|
27 | }; | |
26 |
|
28 | |||
27 | QTCOMMERCIALCHART_END_NAMESPACE |
|
29 | QTCOMMERCIALCHART_END_NAMESPACE | |
28 |
|
30 | |||
29 | #endif // QBARSET_H |
|
31 | #endif // QBARSET_H |
@@ -1,15 +1,25 | |||||
1 | #include <limits.h> |
|
1 | #include <limits.h> | |
2 | #include <QDebug> |
|
2 | #include <QDebug> | |
3 | #include "stackedbarchartseries.h" |
|
3 | #include "stackedbarchartseries.h" | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | StackedBarChartSeries::StackedBarChartSeries(QBarCategory &category, QObject *parent) : |
|
7 | StackedBarChartSeries::StackedBarChartSeries(QBarCategory &category, QObject *parent) : | |
8 | BarChartSeriesBase(category, parent) |
|
8 | BarChartSeriesBase(category, parent) | |
9 | { |
|
9 | { | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
|
12 | void StackedBarChartSeries::addBarSet(QBarSet &set) | |||
|
13 | { | |||
|
14 | BarChartSeriesBase::addBarSet(set); | |||
|
15 | } | |||
|
16 | ||||
|
17 | void StackedBarChartSeries::removeBarSet(QBarSet &set) | |||
|
18 | { | |||
|
19 | BarChartSeriesBase::removeBarSet(set); | |||
|
20 | } | |||
|
21 | ||||
12 | #include "moc_stackedbarchartseries.cpp" |
|
22 | #include "moc_stackedbarchartseries.cpp" | |
13 |
|
23 | |||
14 | QTCOMMERCIALCHART_END_NAMESPACE |
|
24 | QTCOMMERCIALCHART_END_NAMESPACE | |
15 |
|
25 |
@@ -1,30 +1,33 | |||||
1 | #ifndef STACKEDBARCHARTSERIES_H |
|
1 | #ifndef STACKEDBARCHARTSERIES_H | |
2 | #define STACKEDBARCHARTSERIES_H |
|
2 | #define STACKEDBARCHARTSERIES_H | |
3 |
|
3 | |||
4 | #include <QList> |
|
4 | #include <QList> | |
5 | #include <QAbstractItemModel> |
|
5 | #include <QAbstractItemModel> | |
6 | #include "barchartseriesbase.h" |
|
6 | #include "barchartseriesbase.h" | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class StackedBarGroup; |
|
10 | class StackedBarGroup; | |
11 |
|
11 | |||
12 | class QTCOMMERCIALCHART_EXPORT StackedBarChartSeries : public BarChartSeriesBase |
|
12 | class QTCOMMERCIALCHART_EXPORT StackedBarChartSeries : public BarChartSeriesBase | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | StackedBarChartSeries(QBarCategory &category, QObject* parent=0); |
|
16 | StackedBarChartSeries(QBarCategory &category, QObject* parent=0); | |
17 |
|
17 | |||
18 | // from QChartSeries |
|
18 | // from QChartSeries | |
19 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; } |
|
19 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; } | |
20 |
|
20 | |||
|
21 | void addBarSet(QBarSet &set); | |||
|
22 | void removeBarSet(QBarSet &set); | |||
|
23 | ||||
21 | public Q_SLOTS: |
|
24 | public Q_SLOTS: | |
22 |
|
25 | |||
23 | private: |
|
26 | private: | |
24 |
|
27 | |||
25 | StackedBarGroup* mStackedBarGroup; |
|
28 | StackedBarGroup* mStackedBarGroup; | |
26 | }; |
|
29 | }; | |
27 |
|
30 | |||
28 | QTCOMMERCIALCHART_END_NAMESPACE |
|
31 | QTCOMMERCIALCHART_END_NAMESPACE | |
29 |
|
32 | |||
30 | #endif // STACKEDBARCHARTSERIES_H |
|
33 | #endif // STACKEDBARCHARTSERIES_H |
@@ -1,83 +1,83 | |||||
1 | #include "stackedbargroup.h" |
|
1 | #include "stackedbargroup.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include "separator_p.h" |
|
4 | #include "separator_p.h" | |
5 | #include <QDebug> |
|
5 | #include <QDebug> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : |
|
9 | StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : | |
10 | BarGroupBase(series,parent) |
|
10 | BarGroupBase(series,parent) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | void StackedBarGroup::layoutChanged() |
|
14 | void StackedBarGroup::layoutChanged() | |
15 | { |
|
15 | { | |
16 | // qDebug() << "StackedBarGroup::layoutChanged"; |
|
16 | // qDebug() << "StackedBarGroup::layoutChanged"; | |
17 | // Scale bars to new layout |
|
17 | // Scale bars to new layout | |
18 | // Layout for bars: |
|
18 | // Layout for bars: | |
19 |
if (mModel.count |
|
19 | if (mModel.countSets() <= 0) { | |
20 | // Nothing to do. |
|
20 | // Nothing to do. | |
21 | return; |
|
21 | return; | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 |
if (mModel.countC |
|
24 | if (mModel.countCategories() == 0) { | |
25 | // Nothing to do |
|
25 | // Nothing to do | |
26 | return; |
|
26 | return; | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | if (childItems().count() == 0) { |
|
29 | if (childItems().count() == 0) { | |
30 | qDebug() << "WARNING: StackedBarGroup::layoutChanged called before graphics items are created!"; |
|
30 | qDebug() << "WARNING: StackedBarGroup::layoutChanged called before graphics items are created!"; | |
31 | return; |
|
31 | return; | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | // TODO: better way to auto-layout |
|
34 | // TODO: better way to auto-layout | |
35 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
35 | // Use reals for accurancy (we might get some compiler warnings... :) | |
36 | // TODO: use temp variable for column count... |
|
36 | // TODO: use temp variable for column count... | |
37 |
qreal maxSum = mModel.maxC |
|
37 | qreal maxSum = mModel.maxCategorySum(); | |
38 | qreal h = mHeight; |
|
38 | qreal h = mHeight; | |
39 | qreal scale = (h / maxSum); |
|
39 | qreal scale = (h / maxSum); | |
40 |
|
40 | |||
41 | int itemIndex(0); |
|
41 | int itemIndex(0); | |
42 | qreal tW = mWidth; |
|
42 | qreal tW = mWidth; | |
43 |
qreal tC = mModel.countC |
|
43 | qreal tC = mModel.countCategories() + 1; | |
44 | qreal xStep = (tW/tC); |
|
44 | qreal xStep = (tW/tC); | |
45 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
45 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
46 |
int labelIndex = mModel.count |
|
46 | int labelIndex = mModel.countSets() * mModel.countCategories(); | |
47 |
|
47 | |||
48 |
for (int column = 0; column < mModel.countC |
|
48 | for (int column = 0; column < mModel.countCategories(); column++) { | |
49 | qreal yPos = h; |
|
49 | qreal yPos = h; | |
50 |
for (int row=0; row < mModel.count |
|
50 | for (int row=0; row < mModel.countSets(); row++) { | |
51 | qreal barHeight = mModel.valueAt(row, column) * scale; |
|
51 | qreal barHeight = mModel.valueAt(row, column) * scale; | |
52 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
52 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
53 |
|
53 | |||
54 | bar->resize(mBarDefaultWidth, barHeight); |
|
54 | bar->resize(mBarDefaultWidth, barHeight); | |
55 | bar->setColor(mColors.at(row)); |
|
55 | bar->setColor(mColors.at(row)); | |
56 | bar->setPos(xPos, yPos-barHeight); |
|
56 | bar->setPos(xPos, yPos-barHeight); | |
57 | itemIndex++; |
|
57 | itemIndex++; | |
58 | yPos -= barHeight; |
|
58 | yPos -= barHeight; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | // TODO: Layout for labels, remove magic number |
|
61 | // TODO: Layout for labels, remove magic number | |
62 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
62 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
63 | label->setPos(xPos, mHeight + 20); |
|
63 | label->setPos(xPos, mHeight + 20); | |
64 | labelIndex++; |
|
64 | labelIndex++; | |
65 | xPos += xStep; |
|
65 | xPos += xStep; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | // Position separators |
|
69 | // Position separators | |
70 | int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? |
|
70 | int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? | |
71 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. |
|
71 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. | |
72 |
for (int s=0; s < mModel.countC |
|
72 | for (int s=0; s < mModel.countCategories() - 1; s++) { | |
73 | Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex)); |
|
73 | Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex)); | |
74 | sep->setPos(xPos,0); |
|
74 | sep->setPos(xPos,0); | |
75 | sep->setSize(QSizeF(1,mHeight)); |
|
75 | sep->setSize(QSizeF(1,mHeight)); | |
76 | xPos += xStep; |
|
76 | xPos += xStep; | |
77 | separatorIndex++; |
|
77 | separatorIndex++; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | mLayoutDirty = true; |
|
80 | mLayoutDirty = true; | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,414 +1,425 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "dataseriedialog.h" |
|
2 | #include "dataseriedialog.h" | |
3 | #include "qchartseries.h" |
|
3 | #include "qchartseries.h" | |
4 | #include "qpieseries.h" |
|
4 | #include "qpieseries.h" | |
5 | #include <qlinechartseries.h> |
|
5 | #include <qlinechartseries.h> | |
|
6 | #include <qbarset.h> | |||
|
7 | #include <qbarcategory.h> | |||
6 | #include <barchartseries.h> |
|
8 | #include <barchartseries.h> | |
7 | #include <stackedbarchartseries.h> |
|
9 | #include <stackedbarchartseries.h> | |
8 | #include <percentbarchartseries.h> |
|
10 | #include <percentbarchartseries.h> | |
9 | #include <QPushButton> |
|
11 | #include <QPushButton> | |
10 | #include <QComboBox> |
|
12 | #include <QComboBox> | |
11 | #include <QSpinBox> |
|
13 | #include <QSpinBox> | |
12 | #include <QCheckBox> |
|
14 | #include <QCheckBox> | |
13 | #include <QGridLayout> |
|
15 | #include <QGridLayout> | |
14 | #include <QHBoxLayout> |
|
16 | #include <QHBoxLayout> | |
15 | #include <QLabel> |
|
17 | #include <QLabel> | |
16 | #include <QSpacerItem> |
|
18 | #include <QSpacerItem> | |
17 | #include <QMessageBox> |
|
19 | #include <QMessageBox> | |
18 | #include <cmath> |
|
20 | #include <cmath> | |
19 | #include <QDebug> |
|
21 | #include <QDebug> | |
20 | #include <QStandardItemModel> |
|
22 | #include <QStandardItemModel> | |
21 |
|
23 | |||
22 |
|
24 | |||
23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
24 |
|
26 | |||
25 | MainWidget::MainWidget(QWidget *parent) : |
|
27 | MainWidget::MainWidget(QWidget *parent) : | |
26 | QWidget(parent) |
|
28 | QWidget(parent) | |
27 | { |
|
29 | { | |
28 | m_chartWidget = new QChartView(this); |
|
30 | m_chartWidget = new QChartView(this); | |
29 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); |
|
31 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); | |
30 |
|
32 | |||
31 | // Grid layout for the controls for configuring the chart widget |
|
33 | // Grid layout for the controls for configuring the chart widget | |
32 | QGridLayout *grid = new QGridLayout(); |
|
34 | QGridLayout *grid = new QGridLayout(); | |
33 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
35 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
34 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
36 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
35 | grid->addWidget(addSeriesButton, 0, 1); |
|
37 | grid->addWidget(addSeriesButton, 0, 1); | |
36 | initBackroundCombo(grid); |
|
38 | initBackroundCombo(grid); | |
37 | initScaleControls(grid); |
|
39 | initScaleControls(grid); | |
38 | initThemeCombo(grid); |
|
40 | initThemeCombo(grid); | |
39 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
41 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
40 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); |
|
42 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); | |
41 | zoomCheckBox->setChecked(true); |
|
43 | zoomCheckBox->setChecked(true); | |
42 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
44 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
43 | // add row with empty label to make all the other rows static |
|
45 | // add row with empty label to make all the other rows static | |
44 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
46 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
45 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
47 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
46 |
|
48 | |||
47 | // Another grid layout as a main layout |
|
49 | // Another grid layout as a main layout | |
48 | QGridLayout *mainLayout = new QGridLayout(); |
|
50 | QGridLayout *mainLayout = new QGridLayout(); | |
49 | mainLayout->addLayout(grid, 0, 0); |
|
51 | mainLayout->addLayout(grid, 0, 0); | |
50 |
|
52 | |||
51 | // Init series type specific controls |
|
53 | // Init series type specific controls | |
52 | initPieControls(); |
|
54 | initPieControls(); | |
53 | mainLayout->addLayout(m_pieLayout, 2, 0); |
|
55 | mainLayout->addLayout(m_pieLayout, 2, 0); | |
54 | // Scatter series specific settings |
|
56 | // Scatter series specific settings | |
55 | // m_scatterLayout = new QGridLayout(); |
|
57 | // m_scatterLayout = new QGridLayout(); | |
56 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); |
|
58 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); | |
57 | // m_scatterLayout->setEnabled(false); |
|
59 | // m_scatterLayout->setEnabled(false); | |
58 | // mainLayout->addLayout(m_scatterLayout, 1, 0); |
|
60 | // mainLayout->addLayout(m_scatterLayout, 1, 0); | |
59 |
|
61 | |||
60 | // Add layouts and the chart widget to the main layout |
|
62 | // Add layouts and the chart widget to the main layout | |
61 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); |
|
63 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); | |
62 | setLayout(mainLayout); |
|
64 | setLayout(mainLayout); | |
63 |
|
65 | |||
64 | // force an update to test data |
|
66 | // force an update to test data | |
65 | testDataChanged(0); |
|
67 | testDataChanged(0); | |
66 | } |
|
68 | } | |
67 |
|
69 | |||
68 | // Combo box for selecting the chart's background |
|
70 | // Combo box for selecting the chart's background | |
69 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
71 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
70 | { |
|
72 | { | |
71 | QComboBox *backgroundCombo = new QComboBox(this); |
|
73 | QComboBox *backgroundCombo = new QComboBox(this); | |
72 | backgroundCombo->addItem("Color"); |
|
74 | backgroundCombo->addItem("Color"); | |
73 | backgroundCombo->addItem("Gradient"); |
|
75 | backgroundCombo->addItem("Gradient"); | |
74 | backgroundCombo->addItem("Image"); |
|
76 | backgroundCombo->addItem("Image"); | |
75 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
77 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
76 | this, SLOT(backgroundChanged(int))); |
|
78 | this, SLOT(backgroundChanged(int))); | |
77 |
|
79 | |||
78 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
80 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
79 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
81 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
80 | } |
|
82 | } | |
81 |
|
83 | |||
82 | // Scale related controls (auto-scale vs. manual min-max values) |
|
84 | // Scale related controls (auto-scale vs. manual min-max values) | |
83 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
85 | void MainWidget::initScaleControls(QGridLayout *grid) | |
84 | { |
|
86 | { | |
85 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
87 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
86 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
88 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
87 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
89 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
88 | m_xMinSpin = new QSpinBox(); |
|
90 | m_xMinSpin = new QSpinBox(); | |
89 | m_xMinSpin->setMinimum(INT_MIN); |
|
91 | m_xMinSpin->setMinimum(INT_MIN); | |
90 | m_xMinSpin->setMaximum(INT_MAX); |
|
92 | m_xMinSpin->setMaximum(INT_MAX); | |
91 | m_xMinSpin->setValue(0); |
|
93 | m_xMinSpin->setValue(0); | |
92 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
94 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
93 | m_xMaxSpin = new QSpinBox(); |
|
95 | m_xMaxSpin = new QSpinBox(); | |
94 | m_xMaxSpin->setMinimum(INT_MIN); |
|
96 | m_xMaxSpin->setMinimum(INT_MIN); | |
95 | m_xMaxSpin->setMaximum(INT_MAX); |
|
97 | m_xMaxSpin->setMaximum(INT_MAX); | |
96 | m_xMaxSpin->setValue(10); |
|
98 | m_xMaxSpin->setValue(10); | |
97 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
99 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
98 | m_yMinSpin = new QSpinBox(); |
|
100 | m_yMinSpin = new QSpinBox(); | |
99 | m_yMinSpin->setMinimum(INT_MIN); |
|
101 | m_yMinSpin->setMinimum(INT_MIN); | |
100 | m_yMinSpin->setMaximum(INT_MAX); |
|
102 | m_yMinSpin->setMaximum(INT_MAX); | |
101 | m_yMinSpin->setValue(0); |
|
103 | m_yMinSpin->setValue(0); | |
102 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
104 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
103 | m_yMaxSpin = new QSpinBox(); |
|
105 | m_yMaxSpin = new QSpinBox(); | |
104 | m_yMaxSpin->setMinimum(INT_MIN); |
|
106 | m_yMaxSpin->setMinimum(INT_MIN); | |
105 | m_yMaxSpin->setMaximum(INT_MAX); |
|
107 | m_yMaxSpin->setMaximum(INT_MAX); | |
106 | m_yMaxSpin->setValue(10); |
|
108 | m_yMaxSpin->setValue(10); | |
107 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
109 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
108 |
|
110 | |||
109 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
111 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
110 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
112 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
111 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
113 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
112 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
114 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
113 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
115 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
114 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
116 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
115 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
117 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
116 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
118 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
117 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
119 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
118 |
|
120 | |||
119 | m_autoScaleCheck->setChecked(true); |
|
121 | m_autoScaleCheck->setChecked(true); | |
120 | } |
|
122 | } | |
121 |
|
123 | |||
122 | // Combo box for selecting theme |
|
124 | // Combo box for selecting theme | |
123 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
125 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
124 | { |
|
126 | { | |
125 | QComboBox *chartTheme = new QComboBox(); |
|
127 | QComboBox *chartTheme = new QComboBox(); | |
126 | chartTheme->addItem("Default"); |
|
128 | chartTheme->addItem("Default"); | |
127 | chartTheme->addItem("Vanilla"); |
|
129 | chartTheme->addItem("Vanilla"); | |
128 | chartTheme->addItem("Icy"); |
|
130 | chartTheme->addItem("Icy"); | |
129 | chartTheme->addItem("Grayscale"); |
|
131 | chartTheme->addItem("Grayscale"); | |
130 | chartTheme->addItem("Scientific"); |
|
132 | chartTheme->addItem("Scientific"); | |
131 | chartTheme->addItem("Unnamed1"); |
|
133 | chartTheme->addItem("Unnamed1"); | |
132 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
134 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
133 | this, SLOT(changeChartTheme(int))); |
|
135 | this, SLOT(changeChartTheme(int))); | |
134 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
136 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
135 | grid->addWidget(chartTheme, 8, 1); |
|
137 | grid->addWidget(chartTheme, 8, 1); | |
136 | } |
|
138 | } | |
137 |
|
139 | |||
138 | void MainWidget::initPieControls() |
|
140 | void MainWidget::initPieControls() | |
139 | { |
|
141 | { | |
140 | // Pie series specific settings |
|
142 | // Pie series specific settings | |
141 | // Pie size factory |
|
143 | // Pie size factory | |
142 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); |
|
144 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); | |
143 | pieSizeSpin->setMinimum(LONG_MIN); |
|
145 | pieSizeSpin->setMinimum(LONG_MIN); | |
144 | pieSizeSpin->setMaximum(LONG_MAX); |
|
146 | pieSizeSpin->setMaximum(LONG_MAX); | |
145 | pieSizeSpin->setValue(1.0); |
|
147 | pieSizeSpin->setValue(1.0); | |
146 | pieSizeSpin->setSingleStep(0.1); |
|
148 | pieSizeSpin->setSingleStep(0.1); | |
147 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); |
|
149 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); | |
148 | // Pie position |
|
150 | // Pie position | |
149 | QComboBox *piePosCombo = new QComboBox(this); |
|
151 | QComboBox *piePosCombo = new QComboBox(this); | |
150 | piePosCombo->addItem("Maximized"); |
|
152 | piePosCombo->addItem("Maximized"); | |
151 | piePosCombo->addItem("Top left"); |
|
153 | piePosCombo->addItem("Top left"); | |
152 | piePosCombo->addItem("Top right"); |
|
154 | piePosCombo->addItem("Top right"); | |
153 | piePosCombo->addItem("Bottom left"); |
|
155 | piePosCombo->addItem("Bottom left"); | |
154 | piePosCombo->addItem("Bottom right"); |
|
156 | piePosCombo->addItem("Bottom right"); | |
155 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), |
|
157 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), | |
156 | this, SLOT(setPiePosition(int))); |
|
158 | this, SLOT(setPiePosition(int))); | |
157 | m_pieLayout = new QGridLayout(); |
|
159 | m_pieLayout = new QGridLayout(); | |
158 | m_pieLayout->setEnabled(false); |
|
160 | m_pieLayout->setEnabled(false); | |
159 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); |
|
161 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); | |
160 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); |
|
162 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); | |
161 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); |
|
163 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); | |
162 | m_pieLayout->addWidget(piePosCombo, 1, 1); |
|
164 | m_pieLayout->addWidget(piePosCombo, 1, 1); | |
163 | } |
|
165 | } | |
164 |
|
166 | |||
165 | void MainWidget::addSeries() |
|
167 | void MainWidget::addSeries() | |
166 | { |
|
168 | { | |
167 | DataSerieDialog dialog(m_defaultSeriesName, this); |
|
169 | DataSerieDialog dialog(m_defaultSeriesName, this); | |
168 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
170 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
169 | dialog.exec(); |
|
171 | dialog.exec(); | |
170 | } |
|
172 | } | |
171 |
|
173 | |||
172 | void MainWidget::addSeries(QString series, QString data) |
|
174 | void MainWidget::addSeries(QString series, QString data) | |
173 | { |
|
175 | { | |
174 | qDebug() << "addSeries: " << series << " data: " << data; |
|
176 | qDebug() << "addSeries: " << series << " data: " << data; | |
175 | m_defaultSeriesName = series; |
|
177 | m_defaultSeriesName = series; | |
176 |
|
178 | |||
177 | // TODO: a dedicated data class for storing x and y values |
|
179 | // TODO: a dedicated data class for storing x and y values | |
178 | QList<qreal> x; |
|
180 | QList<qreal> x; | |
179 | QList<qreal> y; |
|
181 | QList<qreal> y; | |
180 |
|
182 | |||
181 | QList<qreal> data0; |
|
183 | QBarSet set0; | |
182 | QList<qreal> data1; |
|
184 | QBarSet set1; | |
183 | QList<qreal> data2; |
|
185 | QBarSet set2; | |
184 | QList<qreal> data3; |
|
186 | QBarSet set3; | |
185 | QList<qreal> data4; |
|
187 | QBarSet set4; | |
186 |
|
188 | |||
187 | if (data == "linear") { |
|
189 | if (data == "linear") { | |
188 | for (int i = 0; i < 20; i++) { |
|
190 | for (int i = 0; i < 20; i++) { | |
189 | x.append(i); |
|
191 | x.append(i); | |
190 | y.append(i); |
|
192 | y.append(i); | |
191 | } |
|
193 | } | |
192 | } else if (data == "linear, 1M") { |
|
194 | } else if (data == "linear, 1M") { | |
193 | // 1 million data points from 0.0001 to 100 |
|
195 | // 1 million data points from 0.0001 to 100 | |
194 | // TODO: What is the requirement? Should we be able to show this kind of data with |
|
196 | // TODO: What is the requirement? Should we be able to show this kind of data with | |
195 | // reasonable performance, or can we expect the application developer to do "data mining" |
|
197 | // reasonable performance, or can we expect the application developer to do "data mining" | |
196 | // for us, so that the count of data points given to QtCommercial Chart is always |
|
198 | // for us, so that the count of data points given to QtCommercial Chart is always | |
197 | // reasonable? |
|
199 | // reasonable? | |
198 | for (qreal i = 0; i < 100; i += 0.0001) { |
|
200 | for (qreal i = 0; i < 100; i += 0.0001) { | |
199 | x.append(i); |
|
201 | x.append(i); | |
200 | y.append(20); |
|
202 | y.append(20); | |
201 | } |
|
203 | } | |
202 | } else if (data == "SIN") { |
|
204 | } else if (data == "SIN") { | |
203 | for (int i = 0; i < 100; i++) { |
|
205 | for (int i = 0; i < 100; i++) { | |
204 | x.append(i); |
|
206 | x.append(i); | |
205 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
207 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
206 | } |
|
208 | } | |
207 | } else if (data == "SIN + random") { |
|
209 | } else if (data == "SIN + random") { | |
208 | for (qreal i = 0; i < 100; i += 0.1) { |
|
210 | for (qreal i = 0; i < 100; i += 0.1) { | |
209 | x.append(i + (rand() % 5)); |
|
211 | x.append(i + (rand() % 5)); | |
210 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
212 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
211 | } |
|
213 | } | |
212 | } else if (data == "Table, 5 series"){ |
|
214 | } else if (data == "Table, 5 series"){ | |
213 | // Create some test data to chart |
|
215 | // Create some test data to chart | |
214 |
|
|
216 | set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; | |
215 |
|
|
217 | set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; | |
216 |
|
|
218 | set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; | |
217 |
|
|
219 | set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; | |
218 |
|
|
220 | set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; | |
219 | } else { |
|
221 | } else { | |
220 | // TODO: check if data has a valid file name |
|
222 | // TODO: check if data has a valid file name | |
221 | Q_ASSERT(false); |
|
223 | Q_ASSERT(false); | |
222 | } |
|
224 | } | |
223 |
|
225 | |||
224 | // TODO: color of the series |
|
226 | // TODO: color of the series | |
225 | QChartSeries *newSeries = 0; |
|
227 | QChartSeries *newSeries = 0; | |
226 | if (series == "Scatter") { |
|
228 | if (series == "Scatter") { | |
227 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); |
|
229 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); | |
228 | Q_ASSERT(newSeries->setData(x, y)); |
|
230 | Q_ASSERT(newSeries->setData(x, y)); | |
229 | } else if (series == "Pie") { |
|
231 | } else if (series == "Pie") { | |
230 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); |
|
232 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); | |
231 | Q_ASSERT(newSeries->setData(y)); |
|
233 | Q_ASSERT(newSeries->setData(y)); | |
232 | } else if (series == "Line") { |
|
234 | } else if (series == "Line") { | |
233 | // TODO: adding data to an existing line series does not give any visuals for some reason |
|
235 | // TODO: adding data to an existing line series does not give any visuals for some reason | |
234 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); |
|
236 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); | |
235 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); |
|
237 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); | |
236 | // lineSeries->setColor(Qt::blue); |
|
238 | // lineSeries->setColor(Qt::blue); | |
237 | // for (int i(0); i < x.count() && i < y.count(); i++) { |
|
239 | // for (int i(0); i < x.count() && i < y.count(); i++) { | |
238 | // lineSeries->add(x.at(i), y.at(i)); |
|
240 | // lineSeries->add(x.at(i), y.at(i)); | |
239 | // } |
|
241 | // } | |
240 | //Q_ASSERT(newSeries->setData(x, y)); |
|
242 | //Q_ASSERT(newSeries->setData(x, y)); | |
241 | QLineChartSeries* series0 = new QLineChartSeries(); |
|
243 | QLineChartSeries* series0 = new QLineChartSeries(); | |
242 | for (int i(0); i < x.count() && i < y.count(); i++) |
|
244 | for (int i(0); i < x.count() && i < y.count(); i++) | |
243 | series0->add(x.at(i), y.at(i)); |
|
245 | series0->add(x.at(i), y.at(i)); | |
244 | m_chartWidget->addSeries(series0); |
|
246 | m_chartWidget->addSeries(series0); | |
245 | newSeries = series0; |
|
247 | newSeries = series0; | |
246 | } else if (series == "Bar") { |
|
248 | } else if (series == "Bar") { | |
247 | qDebug() << "Bar chart series"; |
|
249 | qDebug() << "Bar chart series"; | |
248 | BarChartSeries* series0 = new BarChartSeries(this); |
|
250 | ||
249 | series0->addData(data0); |
|
251 | QBarCategory category; | |
250 | series0->addData(data1); |
|
252 | category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
251 | series0->addData(data2); |
|
253 | ||
252 | series0->addData(data3); |
|
254 | BarChartSeries* series0 = new BarChartSeries(category, this); | |
253 | series0->addData(data4); |
|
255 | ||
254 | QList<QString> labels; |
|
256 | series0->addBarSet(set0); | |
255 | labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; |
|
257 | series0->addBarSet(set1); | |
256 |
series0-> |
|
258 | series0->addBarSet(set2); | |
|
259 | series0->addBarSet(set3); | |||
|
260 | series0->addBarSet(set4); | |||
|
261 | ||||
257 | m_chartWidget->addSeries(series0); |
|
262 | m_chartWidget->addSeries(series0); | |
258 | newSeries = series0; |
|
263 | newSeries = series0; | |
259 | } else if (series == "StackedBar") { |
|
264 | } else if (series == "StackedBar") { | |
260 |
qDebug() << " |
|
265 | qDebug() << "Stacked bar chart series"; | |
261 | StackedBarChartSeries* series0 = new StackedBarChartSeries(this); |
|
266 | ||
262 | series0->addData(data0); |
|
267 | QBarCategory category; | |
263 | series0->addData(data1); |
|
268 | category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
264 | series0->addData(data2); |
|
269 | ||
265 | series0->addData(data3); |
|
270 | StackedBarChartSeries* series0 = new StackedBarChartSeries(category, this); | |
266 | series0->addData(data4); |
|
271 | ||
267 | QList<QString> labels; |
|
272 | series0->addBarSet(set0); | |
268 | labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; |
|
273 | series0->addBarSet(set1); | |
269 |
series0-> |
|
274 | series0->addBarSet(set2); | |
|
275 | series0->addBarSet(set3); | |||
|
276 | series0->addBarSet(set4); | |||
|
277 | ||||
270 | m_chartWidget->addSeries(series0); |
|
278 | m_chartWidget->addSeries(series0); | |
271 | newSeries = series0; |
|
279 | newSeries = series0; | |
272 | } else if (series == "PercentBar") { |
|
280 | } else if (series == "PercentBar") { | |
273 |
qDebug() << " |
|
281 | qDebug() << "Percent bar chart series"; | |
274 | PercentBarChartSeries* series0 = new PercentBarChartSeries(this); |
|
282 | ||
275 | series0->addData(data0); |
|
283 | QBarCategory category; | |
276 | series0->addData(data1); |
|
284 | category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
277 | series0->addData(data2); |
|
285 | ||
278 | series0->addData(data3); |
|
286 | PercentBarChartSeries* series0 = new PercentBarChartSeries(category, this); | |
279 | series0->addData(data4); |
|
287 | ||
280 | QList<QString> labels; |
|
288 | series0->addBarSet(set0); | |
281 | labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; |
|
289 | series0->addBarSet(set1); | |
282 |
series0-> |
|
290 | series0->addBarSet(set2); | |
|
291 | series0->addBarSet(set3); | |||
|
292 | series0->addBarSet(set4); | |||
|
293 | ||||
283 | m_chartWidget->addSeries(series0); |
|
294 | m_chartWidget->addSeries(series0); | |
284 | newSeries = series0; |
|
295 | newSeries = series0; | |
285 | } else { |
|
296 | } else { | |
286 | qDebug() << "Something weird going on in MainWidget::addSeries"; |
|
297 | qDebug() << "Something weird going on in MainWidget::addSeries"; | |
287 | } |
|
298 | } | |
288 |
|
299 | |||
289 | setCurrentSeries(newSeries); |
|
300 | setCurrentSeries(newSeries); | |
290 | } |
|
301 | } | |
291 |
|
302 | |||
292 | void MainWidget::setCurrentSeries(QChartSeries *series) |
|
303 | void MainWidget::setCurrentSeries(QChartSeries *series) | |
293 | { |
|
304 | { | |
294 | m_currentSeries = series; |
|
305 | m_currentSeries = series; | |
295 | switch (m_currentSeries->type()) { |
|
306 | switch (m_currentSeries->type()) { | |
296 | case QChartSeries::SeriesTypeLine: |
|
307 | case QChartSeries::SeriesTypeLine: | |
297 | break; |
|
308 | break; | |
298 | case QChartSeries::SeriesTypeScatter: |
|
309 | case QChartSeries::SeriesTypeScatter: | |
299 | break; |
|
310 | break; | |
300 | case QChartSeries::SeriesTypePie: |
|
311 | case QChartSeries::SeriesTypePie: | |
301 | break; |
|
312 | break; | |
302 | case QChartSeries::SeriesTypeBar: |
|
313 | case QChartSeries::SeriesTypeBar: | |
303 | qDebug() << "setCurrentSeries (bar)"; |
|
314 | qDebug() << "setCurrentSeries (bar)"; | |
304 | break; |
|
315 | break; | |
305 | case QChartSeries::SeriesTypeStackedBar: |
|
316 | case QChartSeries::SeriesTypeStackedBar: | |
306 | qDebug() << "setCurrentSeries (Stackedbar)"; |
|
317 | qDebug() << "setCurrentSeries (Stackedbar)"; | |
307 | break; |
|
318 | break; | |
308 | case QChartSeries::SeriesTypePercentBar: |
|
319 | case QChartSeries::SeriesTypePercentBar: | |
309 | qDebug() << "setCurrentSeries (Percentbar)"; |
|
320 | qDebug() << "setCurrentSeries (Percentbar)"; | |
310 | break; |
|
321 | break; | |
311 | default: |
|
322 | default: | |
312 | Q_ASSERT(false); |
|
323 | Q_ASSERT(false); | |
313 | break; |
|
324 | break; | |
314 | } |
|
325 | } | |
315 | } |
|
326 | } | |
316 |
|
327 | |||
317 | void MainWidget::testDataChanged(int itemIndex) |
|
328 | void MainWidget::testDataChanged(int itemIndex) | |
318 | { |
|
329 | { | |
319 | qDebug() << "testDataChanged: " << itemIndex; |
|
330 | qDebug() << "testDataChanged: " << itemIndex; | |
320 |
|
331 | |||
321 | // switch (itemIndex) { |
|
332 | // switch (itemIndex) { | |
322 | // case 0: { |
|
333 | // case 0: { | |
323 | // QList<QChartDataPoint> data; |
|
334 | // QList<QChartDataPoint> data; | |
324 | // for (int x = 0; x < 20; x++) { |
|
335 | // for (int x = 0; x < 20; x++) { | |
325 | // data.append(QChartDataPoint() << x << x / 2); |
|
336 | // data.append(QChartDataPoint() << x << x / 2); | |
326 | // } |
|
337 | // } | |
327 | // m_chartWidget->setData(data); |
|
338 | // m_chartWidget->setData(data); | |
328 | // break; |
|
339 | // break; | |
329 | // } |
|
340 | // } | |
330 | // case 1: { |
|
341 | // case 1: { | |
331 | // QList<QChartDataPoint> data; |
|
342 | // QList<QChartDataPoint> data; | |
332 | // for (int x = 0; x < 100; x++) { |
|
343 | // for (int x = 0; x < 100; x++) { | |
333 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
344 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
334 | // } |
|
345 | // } | |
335 | // m_chartWidget->setData(data); |
|
346 | // m_chartWidget->setData(data); | |
336 | // break; |
|
347 | // break; | |
337 | // } |
|
348 | // } | |
338 | // case 2: { |
|
349 | // case 2: { | |
339 | // QList<QChartDataPoint> data; |
|
350 | // QList<QChartDataPoint> data; | |
340 | // for (int x = 0; x < 1000; x++) { |
|
351 | // for (int x = 0; x < 1000; x++) { | |
341 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
352 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
342 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
353 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
343 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
354 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
344 | // } |
|
355 | // } | |
345 | // m_chartWidget->setData(data); |
|
356 | // m_chartWidget->setData(data); | |
346 | // break; |
|
357 | // break; | |
347 | // } |
|
358 | // } | |
348 | // default: |
|
359 | // default: | |
349 | // break; |
|
360 | // break; | |
350 | // } |
|
361 | // } | |
351 | } |
|
362 | } | |
352 |
|
363 | |||
353 | void MainWidget::backgroundChanged(int itemIndex) |
|
364 | void MainWidget::backgroundChanged(int itemIndex) | |
354 | { |
|
365 | { | |
355 | qDebug() << "backgroundChanged: " << itemIndex; |
|
366 | qDebug() << "backgroundChanged: " << itemIndex; | |
356 | } |
|
367 | } | |
357 |
|
368 | |||
358 | void MainWidget::autoScaleChanged(int value) |
|
369 | void MainWidget::autoScaleChanged(int value) | |
359 | { |
|
370 | { | |
360 | if (value) { |
|
371 | if (value) { | |
361 | // TODO: enable auto scaling |
|
372 | // TODO: enable auto scaling | |
362 | } else { |
|
373 | } else { | |
363 | // TODO: set scaling manually (and disable auto scaling) |
|
374 | // TODO: set scaling manually (and disable auto scaling) | |
364 | } |
|
375 | } | |
365 |
|
376 | |||
366 | m_xMinSpin->setEnabled(!value); |
|
377 | m_xMinSpin->setEnabled(!value); | |
367 | m_xMaxSpin->setEnabled(!value); |
|
378 | m_xMaxSpin->setEnabled(!value); | |
368 | m_yMinSpin->setEnabled(!value); |
|
379 | m_yMinSpin->setEnabled(!value); | |
369 | m_yMaxSpin->setEnabled(!value); |
|
380 | m_yMaxSpin->setEnabled(!value); | |
370 | } |
|
381 | } | |
371 |
|
382 | |||
372 | void MainWidget::xMinChanged(int value) |
|
383 | void MainWidget::xMinChanged(int value) | |
373 | { |
|
384 | { | |
374 | qDebug() << "xMinChanged: " << value; |
|
385 | qDebug() << "xMinChanged: " << value; | |
375 | } |
|
386 | } | |
376 |
|
387 | |||
377 | void MainWidget::xMaxChanged(int value) |
|
388 | void MainWidget::xMaxChanged(int value) | |
378 | { |
|
389 | { | |
379 | qDebug() << "xMaxChanged: " << value; |
|
390 | qDebug() << "xMaxChanged: " << value; | |
380 | } |
|
391 | } | |
381 |
|
392 | |||
382 | void MainWidget::yMinChanged(int value) |
|
393 | void MainWidget::yMinChanged(int value) | |
383 | { |
|
394 | { | |
384 | qDebug() << "yMinChanged: " << value; |
|
395 | qDebug() << "yMinChanged: " << value; | |
385 | } |
|
396 | } | |
386 |
|
397 | |||
387 | void MainWidget::yMaxChanged(int value) |
|
398 | void MainWidget::yMaxChanged(int value) | |
388 | { |
|
399 | { | |
389 | qDebug() << "yMaxChanged: " << value; |
|
400 | qDebug() << "yMaxChanged: " << value; | |
390 | } |
|
401 | } | |
391 |
|
402 | |||
392 | void MainWidget::changeChartTheme(int themeIndex) |
|
403 | void MainWidget::changeChartTheme(int themeIndex) | |
393 | { |
|
404 | { | |
394 | qDebug() << "changeChartTheme: " << themeIndex; |
|
405 | qDebug() << "changeChartTheme: " << themeIndex; | |
395 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); |
|
406 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); | |
396 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. |
|
407 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. | |
397 | QSize s = size(); |
|
408 | QSize s = size(); | |
398 | s.setWidth(s.width()+1); |
|
409 | s.setWidth(s.width()+1); | |
399 | resize(s); |
|
410 | resize(s); | |
400 | } |
|
411 | } | |
401 |
|
412 | |||
402 | void MainWidget::setPieSizeFactor(double size) |
|
413 | void MainWidget::setPieSizeFactor(double size) | |
403 | { |
|
414 | { | |
404 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
415 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
405 | if (pie) |
|
416 | if (pie) | |
406 | pie->setSizeFactor(qreal(size)); |
|
417 | pie->setSizeFactor(qreal(size)); | |
407 | } |
|
418 | } | |
408 |
|
419 | |||
409 | void MainWidget::setPiePosition(int position) |
|
420 | void MainWidget::setPiePosition(int position) | |
410 | { |
|
421 | { | |
411 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
422 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
412 | if (pie) |
|
423 | if (pie) | |
413 | pie->setPosition((QPieSeries::PiePosition) position); |
|
424 | pie->setPosition((QPieSeries::PiePosition) position); | |
414 | } |
|
425 | } |
General Comments 0
You need to be logged in to leave comments.
Login now