@@ -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 <qbarchartseries.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 = new QBarCategory; |
|
16 | QBarCategory *category = new QBarCategory; | |
17 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "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 | QBarChartSeries* series0 = new QBarChartSeries(category); | |
20 |
|
20 | |||
21 | QBarSet *set0 = new QBarSet; |
|
21 | QBarSet *set0 = new QBarSet; | |
22 | QBarSet *set1 = new QBarSet; |
|
22 | QBarSet *set1 = new QBarSet; | |
23 | QBarSet *set2 = new QBarSet; |
|
23 | QBarSet *set2 = new QBarSet; | |
24 | QBarSet *set3 = new QBarSet; |
|
24 | QBarSet *set3 = new QBarSet; | |
25 | QBarSet *set4 = new QBarSet; |
|
25 | QBarSet *set4 = new QBarSet; | |
26 |
|
26 | |||
27 | // Create some test data to chart |
|
27 | // Create some test data to chart | |
28 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; |
|
28 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; | |
29 | *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; |
|
29 | *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; | |
30 | *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; |
|
30 | *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; | |
31 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; |
|
31 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; | |
32 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; |
|
32 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; | |
33 |
|
33 | |||
34 | series0->addBarSet(set0); |
|
34 | series0->addBarSet(set0); | |
35 | series0->addBarSet(set1); |
|
35 | series0->addBarSet(set1); | |
36 | series0->addBarSet(set2); |
|
36 | series0->addBarSet(set2); | |
37 | series0->addBarSet(set3); |
|
37 | series0->addBarSet(set3); | |
38 | series0->addBarSet(set4); |
|
38 | series0->addBarSet(set4); | |
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,147 +1,147 | |||||
1 | #include "widget.h" |
|
1 | #include "widget.h" | |
2 | #include <QGridLayout> |
|
2 | #include <QGridLayout> | |
3 | #include <QPushButton> |
|
3 | #include <QPushButton> | |
4 | #include <QLabel> |
|
4 | #include <QLabel> | |
5 |
|
5 | |||
6 | #include <QSqlQuery> |
|
6 | #include <QSqlQuery> | |
7 | #include <qscatterseries.h> |
|
7 | #include <qscatterseries.h> | |
8 | #include <qchartview.h> |
|
8 | #include <qchartview.h> | |
9 | #include <qchartaxis.h> |
|
9 | #include <qchartaxis.h> | |
10 | #include <barchartseries.h> |
|
10 | #include <qbarchartseries.h> | |
11 | #include <qbarcategory.h> |
|
11 | #include <qbarcategory.h> | |
12 | #include <qbarset.h> |
|
12 | #include <qbarset.h> | |
13 | #include <QListWidget> |
|
13 | #include <QListWidget> | |
14 |
|
14 | |||
15 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
15 | QTCOMMERCIALCHART_USE_NAMESPACE | |
16 |
|
16 | |||
17 | Widget::Widget(QWidget *parent) |
|
17 | Widget::Widget(QWidget *parent) | |
18 | : QWidget(parent) |
|
18 | : QWidget(parent) | |
19 | { |
|
19 | { | |
20 | setGeometry(100, 100, 800, 600); |
|
20 | setGeometry(100, 100, 800, 600); | |
21 |
|
21 | |||
22 | // right panel layout |
|
22 | // right panel layout | |
23 | countrieslist = new QListWidget; |
|
23 | countrieslist = new QListWidget; | |
24 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); |
|
24 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); | |
25 |
|
25 | |||
26 | yearslist = new QListWidget; |
|
26 | yearslist = new QListWidget; | |
27 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
27 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
28 | for (int i = 1990; i < 2011; i++) |
|
28 | for (int i = 1990; i < 2011; i++) | |
29 | yearslist->addItem(QString("%1").arg(i)); |
|
29 | yearslist->addItem(QString("%1").arg(i)); | |
30 |
|
30 | |||
31 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); |
|
31 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); | |
32 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); |
|
32 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); | |
33 |
|
33 | |||
34 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; |
|
34 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; | |
35 | rightPanelLayout->addWidget(countrieslist); |
|
35 | rightPanelLayout->addWidget(countrieslist); | |
36 | rightPanelLayout->addWidget(yearslist); |
|
36 | rightPanelLayout->addWidget(yearslist); | |
37 | rightPanelLayout->addWidget(refreshButton); |
|
37 | rightPanelLayout->addWidget(refreshButton); | |
38 | rightPanelLayout->setStretch(0, 1); |
|
38 | rightPanelLayout->setStretch(0, 1); | |
39 | rightPanelLayout->setStretch(1, 0); |
|
39 | rightPanelLayout->setStretch(1, 0); | |
40 |
|
40 | |||
41 | // main layout |
|
41 | // main layout | |
42 | chartArea = new QChartView(this); |
|
42 | chartArea = new QChartView(this); | |
43 | chartArea->setChartTitle("GDP by country"); |
|
43 | chartArea->setChartTitle("GDP by country"); | |
44 | QGridLayout* mainLayout = new QGridLayout; |
|
44 | QGridLayout* mainLayout = new QGridLayout; | |
45 | mainLayout->addWidget(chartArea, 0, 0); |
|
45 | mainLayout->addWidget(chartArea, 0, 0); | |
46 | mainLayout->addLayout(rightPanelLayout, 0, 1); |
|
46 | mainLayout->addLayout(rightPanelLayout, 0, 1); | |
47 | mainLayout->setColumnStretch(0,1); |
|
47 | mainLayout->setColumnStretch(0,1); | |
48 | setLayout(mainLayout); |
|
48 | setLayout(mainLayout); | |
49 |
|
49 | |||
50 | // connect to the database |
|
50 | // connect to the database | |
51 | db = QSqlDatabase::addDatabase("QSQLITE"); |
|
51 | db = QSqlDatabase::addDatabase("QSQLITE"); | |
52 | db.setDatabaseName("gdpData"); |
|
52 | db.setDatabaseName("gdpData"); | |
53 | if(!db.open()) |
|
53 | if(!db.open()) | |
54 | { |
|
54 | { | |
55 | qDebug() << "could not open database. SQLite db file missing (?)"; |
|
55 | qDebug() << "could not open database. SQLite db file missing (?)"; | |
56 | return; |
|
56 | return; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | // get the list of all countires and regions. |
|
59 | // get the list of all countires and regions. | |
60 | QSqlQuery query; |
|
60 | QSqlQuery query; | |
61 | query.exec("SELECT DISTINCT country FROM gdp2"); |
|
61 | query.exec("SELECT DISTINCT country FROM gdp2"); | |
62 |
|
62 | |||
63 | // add the countries to the country filter |
|
63 | // add the countries to the country filter | |
64 | while (query.next()) { |
|
64 | while (query.next()) { | |
65 | countrieslist->addItem(query.value(0).toString()); |
|
65 | countrieslist->addItem(query.value(0).toString()); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | // hide axis X labels |
|
68 | // hide axis X labels | |
69 | QChartAxis newAxis = chartArea->defaultAxisX(); |
|
69 | QChartAxis newAxis = chartArea->defaultAxisX(); | |
70 | newAxis.setLabelsVisible(false); |
|
70 | newAxis.setLabelsVisible(false); | |
71 | // newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); |
|
71 | // newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); | |
72 | chartArea->setDefaultAxisX(newAxis); |
|
72 | chartArea->setDefaultAxisX(newAxis); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | Widget::~Widget() |
|
75 | Widget::~Widget() | |
76 | { |
|
76 | { | |
77 | // |
|
77 | // | |
78 | db.close(); |
|
78 | db.close(); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void Widget::refreshChart() |
|
81 | void Widget::refreshChart() | |
82 | { |
|
82 | { | |
83 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. |
|
83 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. | |
84 | QStringList selectedCountriesStrings; |
|
84 | QStringList selectedCountriesStrings; | |
85 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); |
|
85 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); | |
86 | for (int i = 0; i < selectedCountriesItems.size(); i++) |
|
86 | for (int i = 0; i < selectedCountriesItems.size(); i++) | |
87 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); |
|
87 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); | |
88 | selectedCountriesStrings.sort(); |
|
88 | selectedCountriesStrings.sort(); | |
89 |
|
89 | |||
90 | // use the sorted selected coutries list to initialize BarCategory |
|
90 | // use the sorted selected coutries list to initialize BarCategory | |
91 | QBarCategory* category = new QBarCategory; |
|
91 | QBarCategory* category = new QBarCategory; | |
92 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
92 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
93 | *category << selectedCountriesStrings[i]; |
|
93 | *category << selectedCountriesStrings[i]; | |
94 | BarChartSeries* series0 = new BarChartSeries(category); |
|
94 | QBarChartSeries* series0 = new QBarChartSeries(category); | |
95 |
|
95 | |||
96 | // prepare the selected counries SQL query |
|
96 | // prepare the selected counries SQL query | |
97 | QString countriesQuery = "country IN ("; |
|
97 | QString countriesQuery = "country IN ("; | |
98 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
98 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
99 | { |
|
99 | { | |
100 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); |
|
100 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); | |
101 | if ( i < selectedCountriesStrings.size() - 1) |
|
101 | if ( i < selectedCountriesStrings.size() - 1) | |
102 | countriesQuery.append(","); |
|
102 | countriesQuery.append(","); | |
103 | else |
|
103 | else | |
104 | countriesQuery.append(")"); |
|
104 | countriesQuery.append(")"); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | QSqlQuery query; |
|
107 | QSqlQuery query; | |
108 | // selected years items list is not sorted. copy the values to QList<Integer> and sort them. |
|
108 | // selected years items list is not sorted. copy the values to QList<Integer> and sort them. | |
109 | QList<int> selectedYearsInts; |
|
109 | QList<int> selectedYearsInts; | |
110 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); |
|
110 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); | |
111 | for (int i = 0; i < selectedYearsItems.size(); i++) |
|
111 | for (int i = 0; i < selectedYearsItems.size(); i++) | |
112 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); |
|
112 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); | |
113 | qSort(selectedYearsInts); |
|
113 | qSort(selectedYearsInts); | |
114 |
|
114 | |||
115 | // perform a query for each selected year |
|
115 | // perform a query for each selected year | |
116 | for (int i = 0; i < selectedYearsInts.size(); i++) |
|
116 | for (int i = 0; i < selectedYearsInts.size(); i++) | |
117 | { |
|
117 | { | |
118 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); |
|
118 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); | |
119 | QBarSet* barSet = new QBarSet; |
|
119 | QBarSet* barSet = new QBarSet; | |
120 | // while (query.next()) { |
|
120 | // while (query.next()) { | |
121 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); |
|
121 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); | |
122 | // } |
|
122 | // } | |
123 | query.first(); |
|
123 | query.first(); | |
124 |
|
124 | |||
125 | // the data for some of the coutries for some years might be missing. |
|
125 | // the data for some of the coutries for some years might be missing. | |
126 | // QBarChart needs bars to have same size |
|
126 | // QBarChart needs bars to have same size | |
127 | for (int k = 0; k < selectedCountriesStrings.size(); k++) |
|
127 | for (int k = 0; k < selectedCountriesStrings.size(); k++) | |
128 | { |
|
128 | { | |
129 | if (selectedCountriesStrings[k] == query.value(0).toString()) |
|
129 | if (selectedCountriesStrings[k] == query.value(0).toString()) | |
130 | { |
|
130 | { | |
131 | *barSet << query.value(1).toReal(); |
|
131 | *barSet << query.value(1).toReal(); | |
132 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
132 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); | |
133 | query.next(); |
|
133 | query.next(); | |
134 | } |
|
134 | } | |
135 | else |
|
135 | else | |
136 | { |
|
136 | { | |
137 | // data missing, put 0 |
|
137 | // data missing, put 0 | |
138 | *barSet << 0.0f; |
|
138 | *barSet << 0.0f; | |
139 | qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
139 | qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 | series0->addBarSet(barSet); |
|
142 | series0->addBarSet(barSet); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | // add the serie to the chart |
|
145 | // add the serie to the chart | |
146 | chartArea->addSeries(series0); |
|
146 | chartArea->addSeries(series0); | |
147 | } |
|
147 | } |
@@ -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 <qpercentbarchartseries.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 = new QBarCategory; |
|
16 | QBarCategory *category = new QBarCategory; | |
17 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "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 | QPercentBarChartSeries* series0 = new QPercentBarChartSeries(category); | |
20 |
|
20 | |||
21 | QBarSet *set0 = new QBarSet; |
|
21 | QBarSet *set0 = new QBarSet; | |
22 | QBarSet *set1 = new QBarSet; |
|
22 | QBarSet *set1 = new QBarSet; | |
23 | QBarSet *set2 = new QBarSet; |
|
23 | QBarSet *set2 = new QBarSet; | |
24 | QBarSet *set3 = new QBarSet; |
|
24 | QBarSet *set3 = new QBarSet; | |
25 | QBarSet *set4 = new QBarSet; |
|
25 | QBarSet *set4 = new QBarSet; | |
26 |
|
26 | |||
27 | // Create some test data to chart |
|
27 | // Create some test data to chart | |
28 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; |
|
28 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; | |
29 | *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; |
|
29 | *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; | |
30 | *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; |
|
30 | *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; | |
31 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; |
|
31 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; | |
32 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; |
|
32 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; | |
33 |
|
33 | |||
34 | series0->addBarSet(set0); |
|
34 | series0->addBarSet(set0); | |
35 | series0->addBarSet(set1); |
|
35 | series0->addBarSet(set1); | |
36 | series0->addBarSet(set2); |
|
36 | series0->addBarSet(set2); | |
37 | series0->addBarSet(set3); |
|
37 | series0->addBarSet(set3); | |
38 | series0->addBarSet(set4); |
|
38 | series0->addBarSet(set4); | |
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 <qstackedbarchartseries.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 = new QBarCategory; |
|
16 | QBarCategory *category = new QBarCategory; | |
17 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "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 | QStackedBarChartSeries* series0 = new QStackedBarChartSeries(category); | |
20 |
|
20 | |||
21 | QBarSet *set0 = new QBarSet; |
|
21 | QBarSet *set0 = new QBarSet; | |
22 | QBarSet *set1 = new QBarSet; |
|
22 | QBarSet *set1 = new QBarSet; | |
23 | QBarSet *set2 = new QBarSet; |
|
23 | QBarSet *set2 = new QBarSet; | |
24 | QBarSet *set3 = new QBarSet; |
|
24 | QBarSet *set3 = new QBarSet; | |
25 | QBarSet *set4 = new QBarSet; |
|
25 | QBarSet *set4 = new QBarSet; | |
26 |
|
26 | |||
27 | // Create some test data to chart |
|
27 | // Create some test data to chart | |
28 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; |
|
28 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; | |
29 | *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; |
|
29 | *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; | |
30 | *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; |
|
30 | *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; | |
31 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; |
|
31 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; | |
32 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; |
|
32 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; | |
33 |
|
33 | |||
34 | series0->addBarSet(set0); |
|
34 | series0->addBarSet(set0); | |
35 | series0->addBarSet(set1); |
|
35 | series0->addBarSet(set1); | |
36 | series0->addBarSet(set2); |
|
36 | series0->addBarSet(set2); | |
37 | series0->addBarSet(set3); |
|
37 | series0->addBarSet(set3); | |
38 | series0->addBarSet(set4); |
|
38 | series0->addBarSet(set4); | |
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,71 +1,71 | |||||
1 |
#include "bar |
|
1 | #include "barpresenter.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include <QDebug> |
|
5 | #include <QDebug> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 |
Bar |
|
9 | BarPresenter::BarPresenter(BarChartModel& model, QGraphicsItem *parent) : | |
10 |
Bar |
|
10 | BarPresenterBase(model,parent) | |
11 | { |
|
11 | { | |
12 | mBarDefaultWidth = 5; |
|
12 | mBarDefaultWidth = 5; | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 |
void Bar |
|
15 | void BarPresenter::layoutChanged() | |
16 | { |
|
16 | { | |
17 | // qDebug() << "BarGroup::layoutChanged"; |
|
17 | // qDebug() << "BarGroup::layoutChanged"; | |
18 | // Scale bars to new layout |
|
18 | // Scale bars to new layout | |
19 | // Layout for bars: |
|
19 | // Layout for bars: | |
20 | if (mModel.countSets() <= 0) { |
|
20 | if (mModel.countSets() <= 0) { | |
21 | qDebug() << "No sets in model!"; |
|
21 | qDebug() << "No sets in model!"; | |
22 | return; |
|
22 | return; | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | if (childItems().count() == 0) { |
|
25 | if (childItems().count() == 0) { | |
26 | qDebug() << "WARNING: BarGroup::layoutChanged called before graphics items are created!"; |
|
26 | qDebug() << "WARNING: BarGroup::layoutChanged called before graphics items are created!"; | |
27 | return; |
|
27 | return; | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | // TODO: better way to auto-layout? |
|
30 | // TODO: better way to auto-layout? | |
31 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
31 | // Use reals for accurancy (we might get some compiler warnings... :) | |
32 | int itemCount = mModel.countCategories(); |
|
32 | int itemCount = mModel.countCategories(); | |
33 | int setCount = mModel.countSets(); |
|
33 | int setCount = mModel.countSets(); | |
34 |
|
34 | |||
35 | qreal tW = mWidth; |
|
35 | qreal tW = mWidth; | |
36 | qreal tH = mHeight; |
|
36 | qreal tH = mHeight; | |
37 | qreal tM = mModel.max(); |
|
37 | qreal tM = mModel.max(); | |
38 | qreal scale = (tH/tM); |
|
38 | qreal scale = (tH/tM); | |
39 | qreal tC = itemCount+1; |
|
39 | qreal tC = itemCount+1; | |
40 | qreal xStepPerSet = (tW/tC); |
|
40 | qreal xStepPerSet = (tW/tC); | |
41 |
|
41 | |||
42 | // Scaling. |
|
42 | // Scaling. | |
43 | int itemIndex(0); |
|
43 | int itemIndex(0); | |
44 | int labelIndex = itemCount * setCount; |
|
44 | int labelIndex = itemCount * setCount; | |
45 |
|
45 | |||
46 | for (int item=0; item < itemCount; item++) { |
|
46 | for (int item=0; item < itemCount; item++) { | |
47 | qreal xPos = xStepPerSet * item + ((tW + mBarDefaultWidth*setCount)/(itemCount*2)); |
|
47 | qreal xPos = xStepPerSet * item + ((tW + mBarDefaultWidth*setCount)/(itemCount*2)); | |
48 | qreal yPos = mHeight; |
|
48 | qreal yPos = mHeight; | |
49 | for (int set = 0; set < setCount; set++) { |
|
49 | for (int set = 0; set < setCount; set++) { | |
50 | qreal barHeight = mModel.valueAt(set, item) * scale; |
|
50 | qreal barHeight = mModel.valueAt(set, item) * scale; | |
51 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
51 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
52 |
|
52 | |||
53 | // TODO: width settable per bar? |
|
53 | // TODO: width settable per bar? | |
54 | bar->resize(mBarDefaultWidth, barHeight); |
|
54 | bar->resize(mBarDefaultWidth, barHeight); | |
55 | bar->setBrush(mModel.setAt(set).brush()); |
|
55 | bar->setBrush(mModel.setAt(set).brush()); | |
56 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + set * mBarDefaultWidth, mHeight); |
|
56 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + set * mBarDefaultWidth, mHeight); | |
57 | itemIndex++; |
|
57 | itemIndex++; | |
58 | xPos += mBarDefaultWidth; |
|
58 | xPos += mBarDefaultWidth; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | // TODO: Layout for labels, remove magic number |
|
61 | // TODO: Layout for labels, remove magic number | |
62 | xPos = xStepPerSet * item + ((tW + mBarDefaultWidth*setCount)/(itemCount*2)); |
|
62 | xPos = xStepPerSet * item + ((tW + mBarDefaultWidth*setCount)/(itemCount*2)); | |
63 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
63 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
64 | label->setPos(xPos, mHeight + 20); |
|
64 | label->setPos(xPos, mHeight + 20); | |
65 | labelIndex++; |
|
65 | labelIndex++; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | mLayoutDirty = true; |
|
68 | mLayoutDirty = true; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,28 +1,28 | |||||
1 | #ifndef QBARGROUP_H |
|
1 | #ifndef QBARGROUP_H | |
2 | #define QBARGROUP_H |
|
2 | #define QBARGROUP_H | |
3 |
|
3 | |||
4 |
#include "bar |
|
4 | #include "barpresenterbase.h" | |
5 | #include "barchartseries.h" |
|
5 | #include "qbarchartseries.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | // Base class for bar groups |
|
10 | // Base class for bar groups | |
11 |
|
11 | |||
12 |
class Bar |
|
12 | class BarPresenter : public BarPresenterBase | |
13 | { |
|
13 | { | |
14 | public: |
|
14 | public: | |
15 |
explicit Bar |
|
15 | explicit BarPresenter(BarChartModel& model, QGraphicsItem *parent = 0); | |
16 |
|
16 | |||
17 | private: |
|
17 | private: | |
18 |
|
18 | |||
19 | // From BarGroupBase |
|
19 | // From BarGroupBase | |
20 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
20 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
21 |
|
21 | |||
22 | private: |
|
22 | private: | |
23 | // Data |
|
23 | // Data | |
24 | }; |
|
24 | }; | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_END_NAMESPACE |
|
26 | QTCOMMERCIALCHART_END_NAMESPACE | |
27 |
|
27 | |||
28 | #endif // QBARGROUP_H |
|
28 | #endif // QBARGROUP_H |
@@ -1,121 +1,121 | |||||
1 |
#include "bar |
|
1 | #include "barpresenterbase.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 |
Bar |
|
9 | BarPresenterBase::BarPresenterBase(BarChartModel& model, QGraphicsItem *parent) | |
10 | : ChartItem(parent) |
|
10 | : ChartItem(parent) | |
11 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready |
|
11 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
12 | ,mLayoutSet(false) |
|
12 | ,mLayoutSet(false) | |
13 | ,mLayoutDirty(true) |
|
13 | ,mLayoutDirty(true) | |
14 | ,mSeparatorsVisible(true) |
|
14 | ,mSeparatorsVisible(true) | |
15 | ,mModel(model) |
|
15 | ,mModel(model) | |
16 | { |
|
16 | { | |
17 | dataChanged(); |
|
17 | dataChanged(); | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 |
void Bar |
|
20 | void BarPresenterBase::setSeparatorsVisible(bool visible) | |
21 | { |
|
21 | { | |
22 | mSeparatorsVisible = visible; |
|
22 | mSeparatorsVisible = visible; | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 |
void Bar |
|
25 | void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
26 | { |
|
26 | { | |
27 | // qDebug() << "BarGroupBase::paint" << childItems().count(); |
|
27 | // qDebug() << "BarGroupBase::paint" << childItems().count(); | |
28 | if (!mLayoutSet) { |
|
28 | if (!mLayoutSet) { | |
29 | qDebug() << "BarGroupBase::paint called without layout set. Aborting."; |
|
29 | qDebug() << "BarGroupBase::paint called without layout set. Aborting."; | |
30 | return; |
|
30 | return; | |
31 | } |
|
31 | } | |
32 | // if (mLayoutDirty) { |
|
32 | // if (mLayoutDirty) { | |
33 | // Layout or data has changed. Need to redraw. |
|
33 | // Layout or data has changed. Need to redraw. | |
34 | foreach(QGraphicsItem* i, childItems()) { |
|
34 | foreach(QGraphicsItem* i, childItems()) { | |
35 | i->paint(painter,option,widget); |
|
35 | i->paint(painter,option,widget); | |
36 | } |
|
36 | } | |
37 | // } |
|
37 | // } | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 |
QRectF Bar |
|
40 | QRectF BarPresenterBase::boundingRect() const | |
41 | { |
|
41 | { | |
42 | return QRectF(0,0,mWidth,mHeight); |
|
42 | return QRectF(0,0,mWidth,mHeight); | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 |
void Bar |
|
45 | void BarPresenterBase::setBarWidth( int w ) | |
46 | { |
|
46 | { | |
47 | mBarDefaultWidth = w; |
|
47 | mBarDefaultWidth = w; | |
48 | } |
|
48 | } | |
49 | /* |
|
49 | /* | |
50 | void BarGroupBase::resetBrushes() |
|
50 | void BarGroupBase::resetBrushes() | |
51 | { |
|
51 | { | |
52 | mBrushes.clear(); |
|
52 | mBrushes.clear(); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void BarGroupBase::addBrush(QBrush brush) |
|
55 | void BarGroupBase::addBrush(QBrush brush) | |
56 | { |
|
56 | { | |
57 | mBrushes.append(brush); |
|
57 | mBrushes.append(brush); | |
58 | } |
|
58 | } | |
59 | */ |
|
59 | */ | |
60 |
void Bar |
|
60 | void BarPresenterBase::dataChanged() | |
61 | { |
|
61 | { | |
62 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
62 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
63 |
|
63 | |||
64 | // Delete old bars |
|
64 | // Delete old bars | |
65 | foreach (QGraphicsItem* item, childItems()) { |
|
65 | foreach (QGraphicsItem* item, childItems()) { | |
66 | delete item; |
|
66 | delete item; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | // Create new graphic items for bars |
|
69 | // Create new graphic items for bars | |
70 | int totalItems = mModel.countTotalItems(); |
|
70 | int totalItems = mModel.countTotalItems(); | |
71 | for (int i=0; i<totalItems; i++) { |
|
71 | for (int i=0; i<totalItems; i++) { | |
72 | Bar *bar = new Bar(this); |
|
72 | Bar *bar = new Bar(this); | |
73 | childItems().append(bar); |
|
73 | childItems().append(bar); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | int count = mModel.countCategories(); |
|
76 | int count = mModel.countCategories(); | |
77 | for (int i=0; i<count; i++) { |
|
77 | for (int i=0; i<count; i++) { | |
78 | BarLabel* label = new BarLabel(this); |
|
78 | BarLabel* label = new BarLabel(this); | |
79 | label->set(mModel.label(i)); |
|
79 | label->set(mModel.label(i)); | |
80 | childItems().append(label); |
|
80 | childItems().append(label); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | count = mModel.countCategories() - 1; // There is one less separator than columns |
|
83 | count = mModel.countCategories() - 1; // There is one less separator than columns | |
84 | for (int i=0; i<count; i++) { |
|
84 | for (int i=0; i<count; i++) { | |
85 | Separator* sep = new Separator(this); |
|
85 | Separator* sep = new Separator(this); | |
86 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme |
|
86 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme | |
87 | childItems().append(sep); |
|
87 | childItems().append(sep); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | // TODO: if (autolayout) { layoutChanged() } or something |
|
90 | // TODO: if (autolayout) { layoutChanged() } or something | |
91 | mLayoutDirty = true; |
|
91 | mLayoutDirty = true; | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | //handlers |
|
94 | //handlers | |
95 |
|
95 | |||
96 |
void Bar |
|
96 | void BarPresenterBase::handleModelChanged(int index) | |
97 | { |
|
97 | { | |
98 | // qDebug() << "BarGroupBase::handleModelChanged" << index; |
|
98 | // qDebug() << "BarGroupBase::handleModelChanged" << index; | |
99 | dataChanged(); |
|
99 | dataChanged(); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 |
void Bar |
|
102 | void BarPresenterBase::handleDomainChanged(const Domain& domain) | |
103 | { |
|
103 | { | |
104 | // qDebug() << "BarGroupBase::handleDomainChanged"; |
|
104 | // qDebug() << "BarGroupBase::handleDomainChanged"; | |
105 | // TODO: Figure out the use case for this. |
|
105 | // TODO: Figure out the use case for this. | |
106 | // Affects the size of visible item, so layout is changed. |
|
106 | // Affects the size of visible item, so layout is changed. | |
107 | // layoutChanged(); |
|
107 | // layoutChanged(); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 |
void Bar |
|
110 | void BarPresenterBase::handleGeometryChanged(const QRectF& rect) | |
111 | { |
|
111 | { | |
112 | mWidth = rect.width(); |
|
112 | mWidth = rect.width(); | |
113 | mHeight = rect.height(); |
|
113 | mHeight = rect.height(); | |
114 | layoutChanged(); |
|
114 | layoutChanged(); | |
115 | mLayoutSet = true; |
|
115 | mLayoutSet = true; | |
116 | setPos(rect.topLeft()); |
|
116 | setPos(rect.topLeft()); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 |
#include "moc_bar |
|
119 | #include "moc_barpresenterbase.cpp" | |
120 |
|
120 | |||
121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
121 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,68 +1,68 | |||||
1 | #ifndef BARGROUPBASE_H |
|
1 | #ifndef BARGROUPBASE_H | |
2 | #define BARGROUPBASE_H |
|
2 | #define BARGROUPBASE_H | |
3 |
|
3 | |||
4 | #include "chartitem_p.h" |
|
4 | #include "chartitem_p.h" | |
5 | #include "barchartmodel_p.h" |
|
5 | #include "barchartmodel_p.h" | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 | #include <QBrush> |
|
7 | #include <QBrush> | |
8 | #include <QGraphicsItem> |
|
8 | #include <QGraphicsItem> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | // Base Class for bar groups. Common implemantation of different groups. Not to be instantiated. |
|
12 | // Base Class for bar groups. Common implemantation of different groups. Not to be instantiated. | |
13 |
class Bar |
|
13 | class BarPresenterBase : public QObject, public ChartItem | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 | public: |
|
16 | public: | |
17 |
Bar |
|
17 | BarPresenterBase(BarChartModel& model, QGraphicsItem *parent = 0); | |
18 | void setSeparatorsVisible(bool visible = true); |
|
18 | void setSeparatorsVisible(bool visible = true); | |
19 |
|
19 | |||
20 | public: |
|
20 | public: | |
21 |
|
21 | |||
22 | // From QGraphicsItem |
|
22 | // From QGraphicsItem | |
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
24 | QRectF boundingRect() const; |
|
24 | QRectF boundingRect() const; | |
25 |
|
25 | |||
26 | // TODO: these may change with layout awarness. |
|
26 | // TODO: these may change with layout awarness. | |
27 | void setBarWidth( int w ); |
|
27 | void setBarWidth( int w ); | |
28 |
|
28 | |||
29 | // void resetBrushes(); |
|
29 | // void resetBrushes(); | |
30 | // void addBrush(QBrush brush); |
|
30 | // void addBrush(QBrush brush); | |
31 |
|
31 | |||
32 | void setPen(QPen pen); |
|
32 | void setPen(QPen pen); | |
33 | QPen pen(); |
|
33 | QPen pen(); | |
34 |
|
34 | |||
35 | void setBrush(QBrush brush); |
|
35 | void setBrush(QBrush brush); | |
36 | QBrush brush(); |
|
36 | QBrush brush(); | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it |
|
39 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it | |
40 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
40 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
41 | virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes |
|
41 | virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes | |
42 |
|
42 | |||
43 | protected slots: |
|
43 | protected slots: | |
44 | void handleModelChanged(int index); |
|
44 | void handleModelChanged(int index); | |
45 | void handleDomainChanged(const Domain& domain); |
|
45 | void handleDomainChanged(const Domain& domain); | |
46 | void handleGeometryChanged(const QRectF& size); |
|
46 | void handleGeometryChanged(const QRectF& size); | |
47 |
|
47 | |||
48 | protected: |
|
48 | protected: | |
49 |
|
49 | |||
50 | // TODO: consider these. |
|
50 | // TODO: consider these. | |
51 | int mHeight; // Layout spesific |
|
51 | int mHeight; // Layout spesific | |
52 | int mWidth; |
|
52 | int mWidth; | |
53 | int mBarDefaultWidth; |
|
53 | int mBarDefaultWidth; | |
54 |
|
54 | |||
55 | bool mLayoutSet; // True, if component has been laid out. |
|
55 | bool mLayoutSet; // True, if component has been laid out. | |
56 | bool mLayoutDirty; |
|
56 | bool mLayoutDirty; | |
57 |
|
57 | |||
58 | QList<QColor> mColors; // List of colors for series for now |
|
58 | QList<QColor> mColors; // List of colors for series for now | |
59 | bool mSeparatorsVisible; |
|
59 | bool mSeparatorsVisible; | |
60 | BarChartModel& mModel; |
|
60 | BarChartModel& mModel; | |
61 |
|
61 | |||
62 | QPen mPen; |
|
62 | QPen mPen; | |
63 | // QList<QBrush> mBrushes; |
|
63 | // QList<QBrush> mBrushes; | |
64 | }; |
|
64 | }; | |
65 |
|
65 | |||
66 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | QTCOMMERCIALCHART_END_NAMESPACE | |
67 |
|
67 | |||
68 | #endif // BARGROUPBASE_H |
|
68 | #endif // BARGROUPBASE_H |
@@ -1,80 +1,80 | |||||
1 |
#include "percentbar |
|
1 | #include "percentbarpresenter.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 "qbarset.h" |
|
5 | #include "qbarset.h" | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
|
10 | |||
11 |
PercentBar |
|
11 | PercentBarPresenter::PercentBarPresenter(BarChartModel& model, QGraphicsItem *parent) : | |
12 |
Bar |
|
12 | BarPresenterBase(model, parent) | |
13 | { |
|
13 | { | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 |
void PercentBar |
|
16 | void PercentBarPresenter::layoutChanged() | |
17 | { |
|
17 | { | |
18 | // qDebug() << "PercentBarGroup::layoutChanged"; |
|
18 | // qDebug() << "PercentBarGroup::layoutChanged"; | |
19 | // Scale bars to new layout |
|
19 | // Scale bars to new layout | |
20 | // Layout for bars: |
|
20 | // Layout for bars: | |
21 | if (mModel.countSets() <= 0) { |
|
21 | if (mModel.countSets() <= 0) { | |
22 | qDebug() << "No sets in model!"; |
|
22 | qDebug() << "No sets in model!"; | |
23 | // Nothing to do. |
|
23 | // Nothing to do. | |
24 | return; |
|
24 | return; | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | if (childItems().count() == 0) { |
|
27 | if (childItems().count() == 0) { | |
28 | qDebug() << "WARNING: PercentBarGroup::layoutChanged called before graphics items are created!"; |
|
28 | qDebug() << "WARNING: PercentBarGroup::layoutChanged called before graphics items are created!"; | |
29 | return; |
|
29 | return; | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | // TODO: better way to auto-layout |
|
32 | // TODO: better way to auto-layout | |
33 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
33 | // Use reals for accurancy (we might get some compiler warnings... :) | |
34 | int count = mModel.countCategories(); |
|
34 | int count = mModel.countCategories(); | |
35 | int itemIndex(0); |
|
35 | int itemIndex(0); | |
36 | qreal tW = mWidth; |
|
36 | qreal tW = mWidth; | |
37 | qreal tC = count+1; |
|
37 | qreal tC = count+1; | |
38 | qreal xStep = (tW/tC); |
|
38 | qreal xStep = (tW/tC); | |
39 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
39 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
40 | int labelIndex = mModel.countCategories() * mModel.countSets(); |
|
40 | int labelIndex = mModel.countCategories() * mModel.countSets(); | |
41 |
|
41 | |||
42 | for (int category = 0; category < mModel.countCategories(); category++) { |
|
42 | for (int category = 0; category < mModel.countCategories(); category++) { | |
43 | qreal colSum = mModel.categorySum(category); |
|
43 | qreal colSum = mModel.categorySum(category); | |
44 | qreal h = mHeight; |
|
44 | qreal h = mHeight; | |
45 | qreal scale = (h / colSum); |
|
45 | qreal scale = (h / colSum); | |
46 | qreal yPos = h; |
|
46 | qreal yPos = h; | |
47 | for (int set=0; set < mModel.countSets(); set++) { |
|
47 | for (int set=0; set < mModel.countSets(); set++) { | |
48 | qreal barHeight = mModel.valueAt(set, category) * scale; |
|
48 | qreal barHeight = mModel.valueAt(set, category) * 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->setBrush(mModel.setAt(set).brush()); |
|
53 | bar->setBrush(mModel.setAt(set).brush()); | |
54 | bar->setPos(xPos, yPos-barHeight); |
|
54 | bar->setPos(xPos, yPos-barHeight); | |
55 | itemIndex++; |
|
55 | itemIndex++; | |
56 | yPos -= barHeight; |
|
56 | yPos -= barHeight; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | // TODO: Layout for labels, remove magic number |
|
59 | // TODO: Layout for labels, remove magic number | |
60 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
60 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
61 | label->setPos(xPos, mHeight + 20); |
|
61 | label->setPos(xPos, mHeight + 20); | |
62 | labelIndex++; |
|
62 | labelIndex++; | |
63 | xPos += xStep; |
|
63 | xPos += xStep; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | // Position separators |
|
66 | // Position separators | |
67 | int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? |
|
67 | int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? | |
68 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. |
|
68 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. | |
69 | for (int s=0; s < mModel.countCategories() - 1; s++) { |
|
69 | for (int s=0; s < mModel.countCategories() - 1; s++) { | |
70 | Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex)); |
|
70 | Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex)); | |
71 | sep->setPos(xPos,0); |
|
71 | sep->setPos(xPos,0); | |
72 | sep->setSize(QSizeF(1,mHeight)); |
|
72 | sep->setSize(QSizeF(1,mHeight)); | |
73 | xPos += xStep; |
|
73 | xPos += xStep; | |
74 | separatorIndex++; |
|
74 | separatorIndex++; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | mLayoutDirty = true; |
|
77 | mLayoutDirty = true; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | QTCOMMERCIALCHART_END_NAMESPACE |
|
80 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,28 +1,28 | |||||
1 | #ifndef PERCENTBARGROUP_H |
|
1 | #ifndef PERCENTBARGROUP_H | |
2 | #define PERCENTBARGROUP_H |
|
2 | #define PERCENTBARGROUP_H | |
3 |
|
3 | |||
4 | #include "chartitem_p.h" |
|
4 | #include "chartitem_p.h" | |
5 | #include "bar_p.h" |
|
5 | #include "bar_p.h" | |
6 | #include "percentbarchartseries.h" |
|
6 | #include "qpercentbarchartseries.h" | |
7 |
#include "bar |
|
7 | #include "barpresenterbase.h" | |
8 | #include <QGraphicsItem> |
|
8 | #include <QGraphicsItem> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 |
class PercentBar |
|
12 | class PercentBarPresenter : public BarPresenterBase | |
13 | { |
|
13 | { | |
14 | public: |
|
14 | public: | |
15 |
PercentBar |
|
15 | PercentBarPresenter(BarChartModel& model, QGraphicsItem *parent = 0); | |
16 |
|
16 | |||
17 | private: |
|
17 | private: | |
18 |
|
18 | |||
19 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
19 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
20 |
|
20 | |||
21 | private: |
|
21 | private: | |
22 |
|
22 | |||
23 | // Data |
|
23 | // Data | |
24 | }; |
|
24 | }; | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_END_NAMESPACE |
|
26 | QTCOMMERCIALCHART_END_NAMESPACE | |
27 |
|
27 | |||
28 | #endif // PERCENTBARGROUP_H |
|
28 | #endif // PERCENTBARGROUP_H |
@@ -1,69 +1,69 | |||||
1 | #include <QDebug> |
|
1 | #include <QDebug> | |
2 | #include "barchartseries.h" |
|
2 | #include "qbarchartseries.h" | |
3 | #include "qbarcategory.h" |
|
3 | #include "qbarcategory.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include "barchartmodel_p.h" |
|
5 | #include "barchartmodel_p.h" | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | BarChartSeries::BarChartSeries(QBarCategory *category, QObject *parent) |
|
10 | QBarChartSeries::QBarChartSeries(QBarCategory *category, QObject *parent) | |
11 | : QChartSeries(parent) |
|
11 | : QChartSeries(parent) | |
12 | ,mModel(new BarChartModel(category, this)) |
|
12 | ,mModel(new BarChartModel(category, this)) | |
13 | { |
|
13 | { | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | void BarChartSeries::addBarSet(QBarSet *set) |
|
16 | void QBarChartSeries::addBarSet(QBarSet *set) | |
17 | { |
|
17 | { | |
18 | mModel->addBarSet(set); |
|
18 | mModel->addBarSet(set); | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void BarChartSeries::removeBarSet(QBarSet *set) |
|
21 | void QBarChartSeries::removeBarSet(QBarSet *set) | |
22 | { |
|
22 | { | |
23 | mModel->removeBarSet(set); |
|
23 | mModel->removeBarSet(set); | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | int BarChartSeries::countSets() |
|
26 | int QBarChartSeries::countSets() | |
27 | { |
|
27 | { | |
28 | return mModel->countSets(); |
|
28 | return mModel->countSets(); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | QBarSet* BarChartSeries::nextSet(bool getFirst) |
|
31 | QBarSet* QBarChartSeries::nextSet(bool getFirst) | |
32 | { |
|
32 | { | |
33 | return mModel->nextSet(getFirst); |
|
33 | return mModel->nextSet(getFirst); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | int BarChartSeries::countCategories() |
|
36 | int QBarChartSeries::countCategories() | |
37 | { |
|
37 | { | |
38 | return mModel->countCategories(); |
|
38 | return mModel->countCategories(); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | qreal BarChartSeries::min() |
|
41 | qreal QBarChartSeries::min() | |
42 | { |
|
42 | { | |
43 | return mModel->min(); |
|
43 | return mModel->min(); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | qreal BarChartSeries::max() |
|
46 | qreal QBarChartSeries::max() | |
47 | { |
|
47 | { | |
48 | return mModel->max(); |
|
48 | return mModel->max(); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | qreal BarChartSeries::valueAt(int set, int category) |
|
51 | qreal QBarChartSeries::valueAt(int set, int category) | |
52 | { |
|
52 | { | |
53 | return mModel->valueAt(set,category); |
|
53 | return mModel->valueAt(set,category); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | qreal BarChartSeries::maxCategorySum() |
|
56 | qreal QBarChartSeries::maxCategorySum() | |
57 | { |
|
57 | { | |
58 | return mModel->maxCategorySum(); |
|
58 | return mModel->maxCategorySum(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | BarChartModel& BarChartSeries::model() |
|
61 | BarChartModel& QBarChartSeries::model() | |
62 | { |
|
62 | { | |
63 | return *mModel; |
|
63 | return *mModel; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 |
|
66 | |||
67 | #include "moc_barchartseries.cpp" |
|
67 | #include "moc_qbarchartseries.cpp" | |
68 |
|
68 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,56 +1,56 | |||||
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 "qchartseries.h" |
|
6 | #include "qchartseries.h" | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QBarCategory; |
|
10 | class QBarCategory; | |
11 | class QBarSet; |
|
11 | class QBarSet; | |
12 |
class Bar |
|
12 | class BarPresenter; | |
13 | class BarChartModel; |
|
13 | class BarChartModel; | |
14 |
|
14 | |||
15 | // Container for series |
|
15 | // Container for series | |
16 | class QTCOMMERCIALCHART_EXPORT BarChartSeries : public QChartSeries |
|
16 | class QTCOMMERCIALCHART_EXPORT QBarChartSeries : public QChartSeries | |
17 | { |
|
17 | { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 | public: |
|
19 | public: | |
20 | BarChartSeries(QBarCategory *category, QObject* parent=0); |
|
20 | QBarChartSeries(QBarCategory *category, QObject* parent=0); | |
21 |
|
21 | |||
22 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; } |
|
22 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; } | |
23 |
|
23 | |||
24 | void addBarSet(QBarSet *set); // Takes ownership of set |
|
24 | void addBarSet(QBarSet *set); // Takes ownership of set | |
25 | void removeBarSet(QBarSet *set); // Removes set, releases ownership. |
|
25 | void removeBarSet(QBarSet *set); // Removes set, releases ownership. | |
26 | int countSets(); |
|
26 | int countSets(); | |
27 | QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true |
|
27 | QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true | |
28 |
|
28 | |||
29 | //TODO: |
|
29 | //TODO: | |
30 | //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) |
|
30 | //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) | |
31 |
|
31 | |||
32 | // TODO: Functions below this are not part of api and will be moved |
|
32 | // TODO: Functions below this are not part of api and will be moved | |
33 | // to private implementation, when we start using it (not part of api) |
|
33 | // to private implementation, when we start using it (not part of api) | |
34 | int countCategories(); |
|
34 | int countCategories(); | |
35 | qreal min(); |
|
35 | qreal min(); | |
36 | qreal max(); |
|
36 | qreal max(); | |
37 | qreal valueAt(int set, int category); |
|
37 | qreal valueAt(int set, int category); | |
38 | qreal maxCategorySum(); |
|
38 | qreal maxCategorySum(); | |
39 |
|
39 | |||
40 | BarChartModel& model(); |
|
40 | BarChartModel& model(); | |
41 |
|
41 | |||
42 | signals: |
|
42 | signals: | |
43 | void changed(int index); |
|
43 | void changed(int index); | |
44 |
|
44 | |||
45 | public Q_SLOTS: |
|
45 | public Q_SLOTS: | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 |
|
48 | |||
49 |
Bar |
|
49 | BarPresenter* mBarGroup; | |
50 | BarChartModel* mModel; |
|
50 | BarChartModel* mModel; | |
51 |
|
51 | |||
52 | }; |
|
52 | }; | |
53 |
|
53 | |||
54 | QTCOMMERCIALCHART_END_NAMESPACE |
|
54 | QTCOMMERCIALCHART_END_NAMESPACE | |
55 |
|
55 | |||
56 | #endif // BARCHARTSERIES_H |
|
56 | #endif // BARCHARTSERIES_H |
@@ -1,70 +1,70 | |||||
1 | #include <limits.h> |
|
1 | #include <limits.h> | |
2 | #include <QDebug> |
|
2 | #include <QDebug> | |
3 |
#include " |
|
3 | #include "qpercentbarchartseries.h" | |
4 | #include "qbarcategory.h" |
|
|||
5 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
|
5 | #include "qbarcategory.h" | |||
6 | #include "barchartmodel_p.h" |
|
6 | #include "barchartmodel_p.h" | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
|
|
10 | QPercentBarChartSeries::QPercentBarChartSeries(QBarCategory *category, QObject *parent) | |
11 | : QChartSeries(parent) |
|
11 | : QChartSeries(parent) | |
12 | ,mModel(new BarChartModel(category, this)) |
|
12 | ,mModel(new BarChartModel(category, this)) | |
13 | { |
|
13 | { | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 |
void |
|
16 | void QPercentBarChartSeries::addBarSet(QBarSet *set) | |
17 | { |
|
17 | { | |
18 | mModel->addBarSet(set); |
|
18 | mModel->addBarSet(set); | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 |
void |
|
21 | void QPercentBarChartSeries::removeBarSet(QBarSet *set) | |
22 | { |
|
22 | { | |
23 | mModel->removeBarSet(set); |
|
23 | mModel->removeBarSet(set); | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 |
int |
|
26 | int QPercentBarChartSeries::countSets() | |
27 | { |
|
27 | { | |
28 | return mModel->countSets(); |
|
28 | return mModel->countSets(); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 |
QBarSet* |
|
31 | QBarSet* QPercentBarChartSeries::nextSet(bool getFirst) | |
32 | { |
|
32 | { | |
33 | return mModel->nextSet(getFirst); |
|
33 | return mModel->nextSet(getFirst); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 |
int |
|
36 | int QPercentBarChartSeries::countCategories() | |
37 | { |
|
37 | { | |
38 | return mModel->countCategories(); |
|
38 | return mModel->countCategories(); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 |
qreal |
|
41 | qreal QPercentBarChartSeries::min() | |
42 | { |
|
42 | { | |
43 | return mModel->min(); |
|
43 | return mModel->min(); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 |
qreal |
|
46 | qreal QPercentBarChartSeries::max() | |
47 | { |
|
47 | { | |
48 | return mModel->max(); |
|
48 | return mModel->max(); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 |
qreal |
|
51 | qreal QPercentBarChartSeries::valueAt(int set, int category) | |
52 | { |
|
52 | { | |
53 | return mModel->valueAt(set,category); |
|
53 | return mModel->valueAt(set,category); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 |
qreal |
|
56 | qreal QPercentBarChartSeries::maxCategorySum() | |
57 | { |
|
57 | { | |
58 | return mModel->maxCategorySum(); |
|
58 | return mModel->maxCategorySum(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 |
BarChartModel& |
|
61 | BarChartModel& QPercentBarChartSeries::model() | |
62 | { |
|
62 | { | |
63 | return *mModel; |
|
63 | return *mModel; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 |
|
66 | |||
67 |
#include "moc_ |
|
67 | #include "moc_qpercentbarchartseries.cpp" | |
68 |
|
68 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
70 |
@@ -1,58 +1,58 | |||||
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 "qchartseries.h" |
|
6 | #include "qchartseries.h" | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
class PercentBar |
|
10 | class PercentBarPresenter; | |
11 | class QBarCategory; |
|
11 | class QBarCategory; | |
12 | class QBarSet; |
|
12 | class QBarSet; | |
13 | class BarChartModel; |
|
13 | class BarChartModel; | |
14 |
|
14 | |||
15 | class QTCOMMERCIALCHART_EXPORT PercentBarChartSeries : public QChartSeries |
|
15 | class QTCOMMERCIALCHART_EXPORT QPercentBarChartSeries : public QChartSeries | |
16 | { |
|
16 | { | |
17 | Q_OBJECT |
|
17 | Q_OBJECT | |
18 | public: |
|
18 | public: | |
19 | PercentBarChartSeries(QBarCategory *category, QObject* parent=0); |
|
19 | QPercentBarChartSeries(QBarCategory *category, QObject* parent=0); | |
20 |
|
20 | |||
21 | // from BarChartSeriesBase |
|
21 | // from BarChartSeriesBase | |
22 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; } |
|
22 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; } | |
23 |
|
23 | |||
24 | void addBarSet(QBarSet *set); // Takes ownership |
|
24 | void addBarSet(QBarSet *set); // Takes ownership | |
25 | void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned. |
|
25 | void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned. | |
26 | int countSets(); |
|
26 | int countSets(); | |
27 | QBarSet* nextSet(bool first=false); // Returns first set, if called with true |
|
27 | QBarSet* nextSet(bool first=false); // Returns first set, if called with true | |
28 |
|
28 | |||
29 | //TODO: |
|
29 | //TODO: | |
30 | //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) |
|
30 | //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) | |
31 |
|
31 | |||
32 | // TODO: Functions below this are not part of api and will be moved |
|
32 | // TODO: Functions below this are not part of api and will be moved | |
33 | // to private implementation, when we start using it (not part of api) |
|
33 | // to private implementation, when we start using it (not part of api) | |
34 | int countCategories(); |
|
34 | int countCategories(); | |
35 | qreal min(); |
|
35 | qreal min(); | |
36 | qreal max(); |
|
36 | qreal max(); | |
37 | qreal valueAt(int set, int category); |
|
37 | qreal valueAt(int set, int category); | |
38 | qreal maxCategorySum(); |
|
38 | qreal maxCategorySum(); | |
39 |
|
39 | |||
40 | BarChartModel& model(); |
|
40 | BarChartModel& model(); | |
41 |
|
41 | |||
42 | signals: |
|
42 | signals: | |
43 | void changed(int index); |
|
43 | void changed(int index); | |
44 |
|
44 | |||
45 | public Q_SLOTS: |
|
45 | public Q_SLOTS: | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | private: |
|
48 | private: | |
49 |
|
49 | |||
50 |
PercentBar |
|
50 | PercentBarPresenter* mPercentBarGroup; | |
51 | BarChartModel* mModel; |
|
51 | BarChartModel* mModel; | |
52 |
|
52 | |||
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | #endif // PERCENTBARCHARTSERIES_H |
|
58 | #endif // PERCENTBARCHARTSERIES_H |
@@ -1,72 +1,70 | |||||
1 | #include "percentbarchartseries.h" |
|
|||
2 |
|
||||
3 |
|
|
1 | #include <limits.h> | |
4 | #include <QDebug> |
|
2 | #include <QDebug> | |
5 |
#include " |
|
3 | #include "qstackedbarchartseries.h" | |
6 | #include "qbarset.h" |
|
|||
7 | #include "qbarcategory.h" |
|
4 | #include "qbarcategory.h" | |
|
5 | #include "qbarset.h" | |||
8 | #include "barchartmodel_p.h" |
|
6 | #include "barchartmodel_p.h" | |
9 |
|
7 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
9 | |||
12 |
|
|
10 | QStackedBarChartSeries::QStackedBarChartSeries(QBarCategory *category, QObject *parent) | |
13 | : QChartSeries(parent) |
|
11 | : QChartSeries(parent) | |
14 | ,mModel(new BarChartModel(category, this)) |
|
12 | ,mModel(new BarChartModel(category, this)) | |
15 | { |
|
13 | { | |
16 | } |
|
14 | } | |
17 |
|
15 | |||
18 |
void |
|
16 | void QStackedBarChartSeries::addBarSet(QBarSet *set) | |
19 | { |
|
17 | { | |
20 | mModel->addBarSet(set); |
|
18 | mModel->addBarSet(set); | |
21 | } |
|
19 | } | |
22 |
|
20 | |||
23 |
void |
|
21 | void QStackedBarChartSeries::removeBarSet(QBarSet *set) | |
24 | { |
|
22 | { | |
25 | mModel->removeBarSet(set); |
|
23 | mModel->removeBarSet(set); | |
26 | } |
|
24 | } | |
27 |
|
25 | |||
28 |
int |
|
26 | int QStackedBarChartSeries::countSets() | |
29 | { |
|
27 | { | |
30 | return mModel->countSets(); |
|
28 | return mModel->countSets(); | |
31 | } |
|
29 | } | |
32 |
|
30 | |||
33 |
QBarSet* |
|
31 | QBarSet* QStackedBarChartSeries::nextSet(bool getFirst) | |
34 | { |
|
32 | { | |
35 | return mModel->nextSet(getFirst); |
|
33 | return mModel->nextSet(getFirst); | |
36 | } |
|
34 | } | |
37 |
|
35 | |||
38 |
int |
|
36 | int QStackedBarChartSeries::countCategories() | |
39 | { |
|
37 | { | |
40 | return mModel->countCategories(); |
|
38 | return mModel->countCategories(); | |
41 | } |
|
39 | } | |
42 |
|
40 | |||
43 |
qreal |
|
41 | qreal QStackedBarChartSeries::min() | |
44 | { |
|
42 | { | |
45 | return mModel->min(); |
|
43 | return mModel->min(); | |
46 | } |
|
44 | } | |
47 |
|
45 | |||
48 |
qreal |
|
46 | qreal QStackedBarChartSeries::max() | |
49 | { |
|
47 | { | |
50 | return mModel->max(); |
|
48 | return mModel->max(); | |
51 | } |
|
49 | } | |
52 |
|
50 | |||
53 |
qreal |
|
51 | qreal QStackedBarChartSeries::valueAt(int set, int category) | |
54 | { |
|
52 | { | |
55 | return mModel->valueAt(set,category); |
|
53 | return mModel->valueAt(set,category); | |
56 | } |
|
54 | } | |
57 |
|
55 | |||
58 |
qreal |
|
56 | qreal QStackedBarChartSeries::maxCategorySum() | |
59 | { |
|
57 | { | |
60 | return mModel->maxCategorySum(); |
|
58 | return mModel->maxCategorySum(); | |
61 | } |
|
59 | } | |
62 |
|
60 | |||
63 |
BarChartModel& |
|
61 | BarChartModel& QStackedBarChartSeries::model() | |
64 | { |
|
62 | { | |
65 | return *mModel; |
|
63 | return *mModel; | |
66 | } |
|
64 | } | |
67 |
|
65 | |||
68 |
|
66 | |||
69 |
#include "moc_ |
|
67 | #include "moc_qstackedbarchartseries.cpp" | |
70 |
|
68 | |||
71 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE | |
72 |
|
70 |
@@ -1,55 +1,55 | |||||
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 "qchartseries.h" |
|
6 | #include "qchartseries.h" | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
class StackedBar |
|
10 | class StackedBarPresenter; | |
11 | class QBarCategory; |
|
11 | class QBarCategory; | |
12 | class QBarSet; |
|
12 | class QBarSet; | |
13 | class BarChartModel; |
|
13 | class BarChartModel; | |
14 |
|
14 | |||
15 | class QTCOMMERCIALCHART_EXPORT StackedBarChartSeries : public QChartSeries |
|
15 | class QTCOMMERCIALCHART_EXPORT QStackedBarChartSeries : public QChartSeries | |
16 | { |
|
16 | { | |
17 | Q_OBJECT |
|
17 | Q_OBJECT | |
18 | public: |
|
18 | public: | |
19 | StackedBarChartSeries(QBarCategory *category, QObject* parent=0); |
|
19 | QStackedBarChartSeries(QBarCategory *category, QObject* parent=0); | |
20 |
|
20 | |||
21 | // from QChartSeries |
|
21 | // from QChartSeries | |
22 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; } |
|
22 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; } | |
23 |
|
23 | |||
24 | void addBarSet(QBarSet *set); // Takes ownership |
|
24 | void addBarSet(QBarSet *set); // Takes ownership | |
25 | void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned. |
|
25 | void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned. | |
26 | int countSets(); |
|
26 | int countSets(); | |
27 | QBarSet* nextSet(bool first=false); // Returns first set, if called with true |
|
27 | QBarSet* nextSet(bool first=false); // Returns first set, if called with true | |
28 |
|
28 | |||
29 | //TODO: |
|
29 | //TODO: | |
30 | //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) |
|
30 | //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) | |
31 |
|
31 | |||
32 | // TODO: Functions below this are not part of api and will be moved |
|
32 | // TODO: Functions below this are not part of api and will be moved | |
33 | // to private implementation, when we start using it (not part of api) |
|
33 | // to private implementation, when we start using it (not part of api) | |
34 | int countCategories(); |
|
34 | int countCategories(); | |
35 | qreal min(); |
|
35 | qreal min(); | |
36 | qreal max(); |
|
36 | qreal max(); | |
37 | qreal valueAt(int set, int category); |
|
37 | qreal valueAt(int set, int category); | |
38 | qreal maxCategorySum(); |
|
38 | qreal maxCategorySum(); | |
39 |
|
39 | |||
40 | BarChartModel& model(); |
|
40 | BarChartModel& model(); | |
41 |
|
41 | |||
42 | signals: |
|
42 | signals: | |
43 | void changed(int index); |
|
43 | void changed(int index); | |
44 |
|
44 | |||
45 | public Q_SLOTS: |
|
45 | public Q_SLOTS: | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 |
|
48 | |||
49 |
StackedBar |
|
49 | StackedBarPresenter* mStackedBarGroup; | |
50 | BarChartModel* mModel; |
|
50 | BarChartModel* mModel; | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
53 | QTCOMMERCIALCHART_END_NAMESPACE | |
54 |
|
54 | |||
55 | #endif // STACKEDBARCHARTSERIES_H |
|
55 | #endif // STACKEDBARCHARTSERIES_H |
@@ -1,85 +1,85 | |||||
1 |
#include "stackedbar |
|
1 | #include "stackedbarpresenter.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 "qbarset.h" |
|
5 | #include "qbarset.h" | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
StackedBar |
|
10 | StackedBarPresenter::StackedBarPresenter(BarChartModel& model, QGraphicsItem *parent) : | |
11 |
Bar |
|
11 | BarPresenterBase(model,parent) | |
12 | { |
|
12 | { | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 |
void StackedBar |
|
15 | void StackedBarPresenter::layoutChanged() | |
16 | { |
|
16 | { | |
17 | // qDebug() << "StackedBarGroup::layoutChanged"; |
|
17 | // qDebug() << "StackedBarGroup::layoutChanged"; | |
18 | // Scale bars to new layout |
|
18 | // Scale bars to new layout | |
19 | // Layout for bars: |
|
19 | // Layout for bars: | |
20 | if (mModel.countSets() <= 0) { |
|
20 | if (mModel.countSets() <= 0) { | |
21 | qDebug() << "No sets in model!"; |
|
21 | qDebug() << "No sets in model!"; | |
22 | // Nothing to do. |
|
22 | // Nothing to do. | |
23 | return; |
|
23 | return; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | if (mModel.countCategories() == 0) { |
|
26 | if (mModel.countCategories() == 0) { | |
27 | qDebug() << "No categories in model!"; |
|
27 | qDebug() << "No categories in model!"; | |
28 | // Nothing to do |
|
28 | // Nothing to do | |
29 | return; |
|
29 | return; | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | if (childItems().count() == 0) { |
|
32 | if (childItems().count() == 0) { | |
33 | qDebug() << "WARNING: StackedBarGroup::layoutChanged called before graphics items are created!"; |
|
33 | qDebug() << "WARNING: StackedBarGroup::layoutChanged called before graphics items are created!"; | |
34 | return; |
|
34 | return; | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | // TODO: better way to auto-layout |
|
37 | // TODO: better way to auto-layout | |
38 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
38 | // Use reals for accurancy (we might get some compiler warnings... :) | |
39 | // TODO: use temp variable for category count... |
|
39 | // TODO: use temp variable for category count... | |
40 | qreal maxSum = mModel.maxCategorySum(); |
|
40 | qreal maxSum = mModel.maxCategorySum(); | |
41 | qreal h = mHeight; |
|
41 | qreal h = mHeight; | |
42 | qreal scale = (h / maxSum); |
|
42 | qreal scale = (h / maxSum); | |
43 |
|
43 | |||
44 | int itemIndex(0); |
|
44 | int itemIndex(0); | |
45 | qreal tW = mWidth; |
|
45 | qreal tW = mWidth; | |
46 | qreal tC = mModel.countCategories() + 1; |
|
46 | qreal tC = mModel.countCategories() + 1; | |
47 | qreal xStep = (tW/tC); |
|
47 | qreal xStep = (tW/tC); | |
48 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
48 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
49 | int labelIndex = mModel.countSets() * mModel.countCategories(); |
|
49 | int labelIndex = mModel.countSets() * mModel.countCategories(); | |
50 |
|
50 | |||
51 | for (int category = 0; category < mModel.countCategories(); category++) { |
|
51 | for (int category = 0; category < mModel.countCategories(); category++) { | |
52 | qreal yPos = h; |
|
52 | qreal yPos = h; | |
53 | for (int set=0; set < mModel.countSets(); set++) { |
|
53 | for (int set=0; set < mModel.countSets(); set++) { | |
54 | qreal barHeight = mModel.valueAt(set, category) * scale; |
|
54 | qreal barHeight = mModel.valueAt(set, category) * scale; | |
55 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
55 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
56 |
|
56 | |||
57 | bar->resize(mBarDefaultWidth, barHeight); |
|
57 | bar->resize(mBarDefaultWidth, barHeight); | |
58 | bar->setBrush(mModel.setAt(set).brush()); |
|
58 | bar->setBrush(mModel.setAt(set).brush()); | |
59 | bar->setPos(xPos, yPos-barHeight); |
|
59 | bar->setPos(xPos, yPos-barHeight); | |
60 | itemIndex++; |
|
60 | itemIndex++; | |
61 | yPos -= barHeight; |
|
61 | yPos -= barHeight; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | // TODO: Layout for labels, remove magic number |
|
64 | // TODO: Layout for labels, remove magic number | |
65 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
65 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
66 | label->setPos(xPos, mHeight + 20); |
|
66 | label->setPos(xPos, mHeight + 20); | |
67 | labelIndex++; |
|
67 | labelIndex++; | |
68 | xPos += xStep; |
|
68 | xPos += xStep; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | // Position separators |
|
71 | // Position separators | |
72 | int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? |
|
72 | int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? | |
73 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. |
|
73 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. | |
74 | for (int s=0; s < mModel.countCategories() - 1; s++) { |
|
74 | for (int s=0; s < mModel.countCategories() - 1; s++) { | |
75 | Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex)); |
|
75 | Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex)); | |
76 | sep->setPos(xPos,0); |
|
76 | sep->setPos(xPos,0); | |
77 | sep->setSize(QSizeF(1,mHeight)); |
|
77 | sep->setSize(QSizeF(1,mHeight)); | |
78 | xPos += xStep; |
|
78 | xPos += xStep; | |
79 | separatorIndex++; |
|
79 | separatorIndex++; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | mLayoutDirty = true; |
|
82 | mLayoutDirty = true; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
85 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,26 +1,26 | |||||
1 | #ifndef STACKEDBARGROUP_H |
|
1 | #ifndef STACKEDBARGROUP_H | |
2 | #define STACKEDBARGROUP_H |
|
2 | #define STACKEDBARGROUP_H | |
3 |
|
3 | |||
4 |
#include "bar |
|
4 | #include "barpresenterbase.h" | |
5 | #include "stackedbarchartseries.h" |
|
5 | #include "qstackedbarchartseries.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
class StackedBar |
|
10 | class StackedBarPresenter : public BarPresenterBase | |
11 | { |
|
11 | { | |
12 | public: |
|
12 | public: | |
13 |
StackedBar |
|
13 | StackedBarPresenter(BarChartModel& model, QGraphicsItem *parent = 0); | |
14 |
|
14 | |||
15 | private: |
|
15 | private: | |
16 | // From BarGroupBase |
|
16 | // From BarGroupBase | |
17 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
17 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
18 |
|
18 | |||
19 | private: |
|
19 | private: | |
20 |
|
20 | |||
21 | // Data |
|
21 | // Data | |
22 | }; |
|
22 | }; | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_END_NAMESPACE |
|
24 | QTCOMMERCIALCHART_END_NAMESPACE | |
25 |
|
25 | |||
26 | #endif // STACKEDBARGROUP_H |
|
26 | #endif // STACKEDBARGROUP_H |
@@ -1,163 +1,163 | |||||
1 | #include "chartdataset_p.h" |
|
1 | #include "chartdataset_p.h" | |
2 | //series |
|
2 | //series | |
3 | #include "qlinechartseries.h" |
|
3 | #include "qlinechartseries.h" | |
4 | #include "barchartseries.h" |
|
4 | #include "qbarchartseries.h" | |
5 | #include "stackedbarchartseries.h" |
|
5 | #include "qstackedbarchartseries.h" | |
6 | #include "percentbarchartseries.h" |
|
6 | #include "qpercentbarchartseries.h" | |
7 | #include "qpieseries.h" |
|
7 | #include "qpieseries.h" | |
8 | #include "qscatterseries.h" |
|
8 | #include "qscatterseries.h" | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent) |
|
12 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent) | |
13 | { |
|
13 | { | |
14 | Domain domain; |
|
14 | Domain domain; | |
15 | m_domains<<domain; |
|
15 | m_domains<<domain; | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | ChartDataSet::~ChartDataSet() |
|
18 | ChartDataSet::~ChartDataSet() | |
19 | { |
|
19 | { | |
20 | // TODO Auto-generated destructor stub |
|
20 | // TODO Auto-generated destructor stub | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | const Domain& ChartDataSet::domain() const |
|
23 | const Domain& ChartDataSet::domain() const | |
24 | { |
|
24 | { | |
25 | return m_domains[m_domainIndex]; |
|
25 | return m_domains[m_domainIndex]; | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | void ChartDataSet::addSeries(QChartSeries* series) |
|
28 | void ChartDataSet::addSeries(QChartSeries* series) | |
29 | { |
|
29 | { | |
30 | // TODO: we should check the series not already added |
|
30 | // TODO: we should check the series not already added | |
31 | m_chartSeries << series; |
|
31 | m_chartSeries << series; | |
32 | series->setParent(this); // take ownership |
|
32 | series->setParent(this); // take ownership | |
33 | m_domainIndex = 0; |
|
33 | m_domainIndex = 0; | |
34 | m_domains.resize(1); |
|
34 | m_domains.resize(1); | |
35 |
|
35 | |||
36 | Domain& domain = m_domains[m_domainIndex]; |
|
36 | Domain& domain = m_domains[m_domainIndex]; | |
37 |
|
37 | |||
38 | switch(series->type()) |
|
38 | switch(series->type()) | |
39 | { |
|
39 | { | |
40 | case QChartSeries::SeriesTypeLine: { |
|
40 | case QChartSeries::SeriesTypeLine: { | |
41 |
|
41 | |||
42 | QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series); |
|
42 | QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series); | |
43 |
|
43 | |||
44 | for (int i = 0; i < xyseries->count(); i++) |
|
44 | for (int i = 0; i < xyseries->count(); i++) | |
45 | { |
|
45 | { | |
46 | qreal x = xyseries->x(i); |
|
46 | qreal x = xyseries->x(i); | |
47 | qreal y = xyseries->y(i); |
|
47 | qreal y = xyseries->y(i); | |
48 | domain.m_minX = qMin(domain.m_minX,x); |
|
48 | domain.m_minX = qMin(domain.m_minX,x); | |
49 | domain.m_minY = qMin(domain.m_minY,y); |
|
49 | domain.m_minY = qMin(domain.m_minY,y); | |
50 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
50 | domain.m_maxX = qMax(domain.m_maxX,x); | |
51 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
51 | domain.m_maxY = qMax(domain.m_maxY,y); | |
52 | } |
|
52 | } | |
53 | break; |
|
53 | break; | |
54 | } |
|
54 | } | |
55 | case QChartSeries::SeriesTypeBar: { |
|
55 | case QChartSeries::SeriesTypeBar: { | |
56 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
56 | qDebug() << "QChartSeries::SeriesTypeBar"; | |
57 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
57 | QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series); | |
58 | qreal x = barSeries->countCategories(); |
|
58 | qreal x = barSeries->countCategories(); | |
59 | qreal y = barSeries->max(); |
|
59 | qreal y = barSeries->max(); | |
60 | domain.m_minX = qMin(domain.m_minX,x); |
|
60 | domain.m_minX = qMin(domain.m_minX,x); | |
61 | domain.m_minY = qMin(domain.m_minY,y); |
|
61 | domain.m_minY = qMin(domain.m_minY,y); | |
62 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
62 | domain.m_maxX = qMax(domain.m_maxX,x); | |
63 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
63 | domain.m_maxY = qMax(domain.m_maxY,y); | |
64 | break; |
|
64 | break; | |
65 | } |
|
65 | } | |
66 | case QChartSeries::SeriesTypeStackedBar: { |
|
66 | case QChartSeries::SeriesTypeStackedBar: { | |
67 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
67 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; | |
68 |
|
68 | |||
69 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
69 | QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series); | |
70 | qreal x = stackedBarSeries->countCategories(); |
|
70 | qreal x = stackedBarSeries->countCategories(); | |
71 | qreal y = stackedBarSeries->maxCategorySum(); |
|
71 | qreal y = stackedBarSeries->maxCategorySum(); | |
72 | domain.m_minX = qMin(domain.m_minX,x); |
|
72 | domain.m_minX = qMin(domain.m_minX,x); | |
73 | domain.m_minY = qMin(domain.m_minY,y); |
|
73 | domain.m_minY = qMin(domain.m_minY,y); | |
74 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
74 | domain.m_maxX = qMax(domain.m_maxX,x); | |
75 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
75 | domain.m_maxY = qMax(domain.m_maxY,y); | |
76 | break; |
|
76 | break; | |
77 | } |
|
77 | } | |
78 | case QChartSeries::SeriesTypePercentBar: { |
|
78 | case QChartSeries::SeriesTypePercentBar: { | |
79 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
79 | qDebug() << "QChartSeries::SeriesTypePercentBar"; | |
80 |
|
80 | |||
81 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
81 | QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series); | |
82 | qreal x = percentBarSeries->countCategories(); |
|
82 | qreal x = percentBarSeries->countCategories(); | |
83 | domain.m_minX = qMin(domain.m_minX,x); |
|
83 | domain.m_minX = qMin(domain.m_minX,x); | |
84 | domain.m_minY = 0; |
|
84 | domain.m_minY = 0; | |
85 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
85 | domain.m_maxX = qMax(domain.m_maxX,x); | |
86 | domain.m_maxY = 100; |
|
86 | domain.m_maxY = 100; | |
87 | break; |
|
87 | break; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | case QChartSeries::SeriesTypePie: { |
|
90 | case QChartSeries::SeriesTypePie: { | |
91 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
91 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
92 | // TODO: domain stuff |
|
92 | // TODO: domain stuff | |
93 | break; |
|
93 | break; | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | case QChartSeries::SeriesTypeScatter: { |
|
96 | case QChartSeries::SeriesTypeScatter: { | |
97 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
97 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
98 | Q_ASSERT(scatterSeries); |
|
98 | Q_ASSERT(scatterSeries); | |
99 | foreach (QPointF point, scatterSeries->data()) { |
|
99 | foreach (QPointF point, scatterSeries->data()) { | |
100 | domain.m_minX = qMin(domain.m_minX, point.x()); |
|
100 | domain.m_minX = qMin(domain.m_minX, point.x()); | |
101 | domain.m_maxX = qMax(domain.m_maxX, point.x()); |
|
101 | domain.m_maxX = qMax(domain.m_maxX, point.x()); | |
102 | domain.m_minY = qMin(domain.m_minY, point.y()); |
|
102 | domain.m_minY = qMin(domain.m_minY, point.y()); | |
103 | domain.m_maxY = qMax(domain.m_maxY, point.y()); |
|
103 | domain.m_maxY = qMax(domain.m_maxY, point.y()); | |
104 | } |
|
104 | } | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | default: { |
|
108 | default: { | |
109 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
109 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
110 | return; |
|
110 | return; | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | emit seriesAdded(series); |
|
116 | emit seriesAdded(series); | |
117 | emit domainChanged(domain); |
|
117 | emit domainChanged(domain); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | bool ChartDataSet::nextDomain() |
|
120 | bool ChartDataSet::nextDomain() | |
121 | { |
|
121 | { | |
122 | if (m_domainIndex < m_domains.count() - 1) { |
|
122 | if (m_domainIndex < m_domains.count() - 1) { | |
123 | m_domainIndex++; |
|
123 | m_domainIndex++; | |
124 | emit domainChanged(m_domains[m_domainIndex]); |
|
124 | emit domainChanged(m_domains[m_domainIndex]); | |
125 | return true; |
|
125 | return true; | |
126 | } |
|
126 | } | |
127 | else { |
|
127 | else { | |
128 | return false; |
|
128 | return false; | |
129 | } |
|
129 | } | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | bool ChartDataSet::previousDomain() |
|
132 | bool ChartDataSet::previousDomain() | |
133 | { |
|
133 | { | |
134 | if (m_domainIndex > 0) { |
|
134 | if (m_domainIndex > 0) { | |
135 | m_domainIndex--; |
|
135 | m_domainIndex--; | |
136 | emit domainChanged(m_domains[m_domainIndex]); |
|
136 | emit domainChanged(m_domains[m_domainIndex]); | |
137 | return true; |
|
137 | return true; | |
138 | } |
|
138 | } | |
139 | else { |
|
139 | else { | |
140 | return false; |
|
140 | return false; | |
141 | } |
|
141 | } | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void ChartDataSet::clearDomains() |
|
144 | void ChartDataSet::clearDomains() | |
145 | { |
|
145 | { | |
146 | if (m_domainIndex > 0) { |
|
146 | if (m_domainIndex > 0) { | |
147 | m_domainIndex = 0; |
|
147 | m_domainIndex = 0; | |
148 | emit domainChanged(m_domains[m_domainIndex]); |
|
148 | emit domainChanged(m_domains[m_domainIndex]); | |
149 | } |
|
149 | } | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void ChartDataSet::addDomain(const Domain& domain) |
|
152 | void ChartDataSet::addDomain(const Domain& domain) | |
153 | { |
|
153 | { | |
154 | m_domains.resize(m_domainIndex + 1); |
|
154 | m_domains.resize(m_domainIndex + 1); | |
155 | m_domains << domain; |
|
155 | m_domains << domain; | |
156 | m_domainIndex++; |
|
156 | m_domainIndex++; | |
157 |
|
157 | |||
158 | emit domainChanged(domain); |
|
158 | emit domainChanged(domain); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | #include "moc_chartdataset_p.cpp" |
|
161 | #include "moc_chartdataset_p.cpp" | |
162 |
|
162 | |||
163 | QTCOMMERCIALCHART_END_NAMESPACE |
|
163 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,269 +1,269 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | //series |
|
6 | //series | |
7 | #include "barchartseries.h" |
|
7 | #include "qbarchartseries.h" | |
8 | #include "stackedbarchartseries.h" |
|
8 | #include "qstackedbarchartseries.h" | |
9 | #include "percentbarchartseries.h" |
|
9 | #include "qpercentbarchartseries.h" | |
10 | #include "qlinechartseries.h" |
|
10 | #include "qlinechartseries.h" | |
11 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
12 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | //items |
|
13 | //items | |
14 | #include "axisitem_p.h" |
|
14 | #include "axisitem_p.h" | |
15 |
#include "bar |
|
15 | #include "barpresenter.h" | |
16 |
#include "stackedbar |
|
16 | #include "stackedbarpresenter.h" | |
17 | #include "linechartitem_p.h" |
|
17 | #include "linechartitem_p.h" | |
18 |
#include "percentbar |
|
18 | #include "percentbarpresenter.h" | |
19 | #include "linechartanimationitem_p.h" |
|
19 | #include "linechartanimationitem_p.h" | |
20 | #include "piepresenter.h" |
|
20 | #include "piepresenter.h" | |
21 | #include "scatterpresenter_p.h" |
|
21 | #include "scatterpresenter_p.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
26 | m_chart(chart), |
|
26 | m_chart(chart), | |
27 | m_dataset(dataset), |
|
27 | m_dataset(dataset), | |
28 | m_chartTheme(0), |
|
28 | m_chartTheme(0), | |
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)), |
|
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)), | |
30 | m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)), |
|
30 | m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)), | |
31 | m_domainIndex(0), |
|
31 | m_domainIndex(0), | |
32 | m_marginSize(0), |
|
32 | m_marginSize(0), | |
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
34 | { |
|
34 | { | |
35 | setChartTheme(QChart::ChartThemeDefault); |
|
35 | setChartTheme(QChart::ChartThemeDefault); | |
36 | createConnections(); |
|
36 | createConnections(); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void ChartPresenter::createConnections() |
|
43 | void ChartPresenter::createConnections() | |
44 | { |
|
44 | { | |
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
47 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&))); |
|
47 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&))); | |
48 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&))); |
|
48 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&))); | |
49 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&))); |
|
49 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&))); | |
50 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&))); |
|
50 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&))); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void ChartPresenter::handleGeometryChanged() |
|
53 | void ChartPresenter::handleGeometryChanged() | |
54 | { |
|
54 | { | |
55 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
55 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
56 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
56 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
57 | Q_ASSERT(m_rect.isValid()); |
|
57 | Q_ASSERT(m_rect.isValid()); | |
58 | emit geometryChanged(m_rect); |
|
58 | emit geometryChanged(m_rect); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | int ChartPresenter::margin() const |
|
61 | int ChartPresenter::margin() const | |
62 | { |
|
62 | { | |
63 | return m_marginSize; |
|
63 | return m_marginSize; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void ChartPresenter::setMargin(int margin) |
|
66 | void ChartPresenter::setMargin(int margin) | |
67 | { |
|
67 | { | |
68 | m_marginSize = margin; |
|
68 | m_marginSize = margin; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
71 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
72 | { |
|
72 | { | |
73 | qDebug() << " ChartPresenter::handleSeriesAdded"; |
|
73 | qDebug() << " ChartPresenter::handleSeriesAdded"; | |
74 | switch(series->type()) |
|
74 | switch(series->type()) | |
75 | { |
|
75 | { | |
76 | case QChartSeries::SeriesTypeLine: { |
|
76 | case QChartSeries::SeriesTypeLine: { | |
77 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); |
|
77 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); | |
78 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
78 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
79 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
79 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
80 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
80 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
81 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
81 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
82 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
82 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
83 | m_chartItems.insert(series,item); |
|
83 | m_chartItems.insert(series,item); | |
84 | break; |
|
84 | break; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | case QChartSeries::SeriesTypeBar: { |
|
87 | case QChartSeries::SeriesTypeBar: { | |
88 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
88 | QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series); | |
89 |
Bar |
|
89 | BarPresenter* item = new BarPresenter(barSeries->model(),m_chart); | |
90 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
90 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
91 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
91 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
92 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
92 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
93 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
93 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
94 | m_chartItems.insert(series,item); |
|
94 | m_chartItems.insert(series,item); | |
95 | // m_axisXItem->setVisible(false); |
|
95 | // m_axisXItem->setVisible(false); | |
96 | break; |
|
96 | break; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | case QChartSeries::SeriesTypeStackedBar: { |
|
99 | case QChartSeries::SeriesTypeStackedBar: { | |
100 |
|
100 | |||
101 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
101 | QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series); | |
102 |
StackedBar |
|
102 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries->model(),m_chart); | |
103 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
103 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
104 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
104 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
106 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
106 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
107 | m_chartItems.insert(series,item); |
|
107 | m_chartItems.insert(series,item); | |
108 | break; |
|
108 | break; | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | case QChartSeries::SeriesTypePercentBar: { |
|
111 | case QChartSeries::SeriesTypePercentBar: { | |
112 |
|
112 | |||
113 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
113 | QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series); | |
114 |
PercentBar |
|
114 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries->model(),m_chart); | |
115 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
115 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
116 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
116 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
117 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
117 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
118 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
118 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
119 | m_chartItems.insert(series,item); |
|
119 | m_chartItems.insert(series,item); | |
120 | break; |
|
120 | break; | |
121 | } |
|
121 | } | |
122 | case QChartSeries::SeriesTypeScatter: { |
|
122 | case QChartSeries::SeriesTypeScatter: { | |
123 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
123 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
124 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
124 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); | |
125 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
125 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
126 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
126 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
127 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), |
|
127 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), | |
128 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); |
|
128 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); | |
129 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
129 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); | |
130 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
130 | m_chartItems.insert(scatterSeries, scatterPresenter); | |
131 | break; |
|
131 | break; | |
132 | } |
|
132 | } | |
133 | case QChartSeries::SeriesTypePie: { |
|
133 | case QChartSeries::SeriesTypePie: { | |
134 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
134 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
135 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
135 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
136 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
136 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
137 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
137 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
138 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); |
|
138 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); | |
139 | m_chartItems.insert(series, pie); |
|
139 | m_chartItems.insert(series, pie); | |
140 | break; |
|
140 | break; | |
141 | } |
|
141 | } | |
142 | default: { |
|
142 | default: { | |
143 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
143 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
144 | break; |
|
144 | break; | |
145 | } |
|
145 | } | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
148 | if(m_rect.isValid()) emit geometryChanged(m_rect); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
151 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
152 | { |
|
152 | { | |
153 | //TODO: |
|
153 | //TODO: | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
|
156 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |
157 | { |
|
157 | { | |
158 | if(!rect.isValid()) return; |
|
158 | if(!rect.isValid()) return; | |
159 | QRectF r = rect.normalized(); |
|
159 | QRectF r = rect.normalized(); | |
160 | r.translate(-m_marginSize, -m_marginSize); |
|
160 | r.translate(-m_marginSize, -m_marginSize); | |
161 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); |
|
161 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); | |
162 | m_dataset->addDomain(domain); |
|
162 | m_dataset->addDomain(domain); | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | void ChartPresenter::zoomIn() |
|
165 | void ChartPresenter::zoomIn() | |
166 | { |
|
166 | { | |
167 | if (!m_dataset->nextDomain()) { |
|
167 | if (!m_dataset->nextDomain()) { | |
168 | QRectF rect = m_rect; |
|
168 | QRectF rect = m_rect; | |
169 | rect.setWidth(rect.width()/2); |
|
169 | rect.setWidth(rect.width()/2); | |
170 | rect.setHeight(rect.height()/2); |
|
170 | rect.setHeight(rect.height()/2); | |
171 | rect.moveCenter(m_rect.center()); |
|
171 | rect.moveCenter(m_rect.center()); | |
172 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
172 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
173 | m_dataset->addDomain(domain); |
|
173 | m_dataset->addDomain(domain); | |
174 | } |
|
174 | } | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | void ChartPresenter::zoomOut() |
|
177 | void ChartPresenter::zoomOut() | |
178 | { |
|
178 | { | |
179 | m_dataset->previousDomain(); |
|
179 | m_dataset->previousDomain(); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | void ChartPresenter::zoomReset() |
|
182 | void ChartPresenter::zoomReset() | |
183 | { |
|
183 | { | |
184 | m_dataset->clearDomains(); |
|
184 | m_dataset->clearDomains(); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
187 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
188 | { |
|
188 | { | |
189 | delete m_chartTheme; |
|
189 | delete m_chartTheme; | |
190 |
|
190 | |||
191 | m_chartTheme = ChartTheme::createTheme(theme); |
|
191 | m_chartTheme = ChartTheme::createTheme(theme); | |
192 |
|
192 | |||
193 | m_chartTheme->decorate(m_chart); |
|
193 | m_chartTheme->decorate(m_chart); | |
194 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); |
|
194 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); | |
195 |
|
195 | |||
196 | int index=0; |
|
196 | int index=0; | |
197 | while (i.hasNext()) { |
|
197 | while (i.hasNext()) { | |
198 | i.next(); |
|
198 | i.next(); | |
199 | index++; |
|
199 | index++; | |
200 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
200 | m_chartTheme->decorate(i.value(),i.key(),index); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | m_chartTheme->decorate(m_axisX, m_axisXItem); |
|
203 | m_chartTheme->decorate(m_axisX, m_axisXItem); | |
204 | m_chartTheme->decorate(m_axisY, m_axisYItem); |
|
204 | m_chartTheme->decorate(m_axisY, m_axisYItem); | |
205 |
|
205 | |||
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 |
|
208 | |||
209 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
209 | QChart::ChartTheme ChartPresenter::chartTheme() | |
210 | { |
|
210 | { | |
211 | return m_chartTheme->id(); |
|
211 | return m_chartTheme->id(); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) |
|
214 | void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) | |
215 | { |
|
215 | { | |
216 | //if(m_axisX != axis) { |
|
216 | //if(m_axisX != axis) { | |
217 | m_axisX = axis; |
|
217 | m_axisX = axis; | |
218 | m_axisXItem->handleAxisChanged(m_axisX); |
|
218 | m_axisXItem->handleAxisChanged(m_axisX); | |
219 | //} |
|
219 | //} | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) |
|
222 | void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) | |
223 | { |
|
223 | { | |
224 | // if(m_axisY != axis) { |
|
224 | // if(m_axisY != axis) { | |
225 | m_axisY = axis; |
|
225 | m_axisY = axis; | |
226 | m_axisYItem->handleAxisChanged(m_axisY); |
|
226 | m_axisYItem->handleAxisChanged(m_axisY); | |
227 | //} |
|
227 | //} | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | QChartAxis ChartPresenter::defaultAxisX() const |
|
230 | QChartAxis ChartPresenter::defaultAxisX() const | |
231 | { |
|
231 | { | |
232 | return m_axisX; |
|
232 | return m_axisX; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | QChartAxis ChartPresenter::defaultAxisY() const |
|
235 | QChartAxis ChartPresenter::defaultAxisY() const | |
236 | { |
|
236 | { | |
237 | return m_axisY; |
|
237 | return m_axisY; | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | QChartAxis ChartPresenter::axisY(int id) const |
|
240 | QChartAxis ChartPresenter::axisY(int id) const | |
241 | { |
|
241 | { | |
242 | return m_axis.value(id); |
|
242 | return m_axis.value(id); | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | int ChartPresenter::addAxisY(const QChartAxis& axis) |
|
245 | int ChartPresenter::addAxisY(const QChartAxis& axis) | |
246 | { |
|
246 | { | |
247 | int key =0 ; |
|
247 | int key =0 ; | |
248 |
|
248 | |||
249 | while(m_axis.contains(key)){ |
|
249 | while(m_axis.contains(key)){ | |
250 | key++; |
|
250 | key++; | |
251 | //TODO overflow |
|
251 | //TODO overflow | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | m_axis.insert(key,axis); |
|
254 | m_axis.insert(key,axis); | |
255 | m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); |
|
255 | m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); | |
256 |
|
256 | |||
257 | return key; |
|
257 | return key; | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 |
|
260 | |||
261 | void ChartPresenter::removeAxisY(int id) |
|
261 | void ChartPresenter::removeAxisY(int id) | |
262 | { |
|
262 | { | |
263 | m_axis.remove(id); |
|
263 | m_axis.remove(id); | |
264 | delete m_axisItems.take(id); |
|
264 | delete m_axisItems.take(id); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | #include "moc_chartpresenter_p.cpp" |
|
267 | #include "moc_chartpresenter_p.cpp" | |
268 |
|
268 | |||
269 | QTCOMMERCIALCHART_END_NAMESPACE |
|
269 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,231 +1,231 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
4 |
|
4 | |||
5 |
|
5 | |||
6 | //series |
|
6 | //series | |
7 | #include "qbarset.h" |
|
7 | #include "qbarset.h" | |
8 | #include "barchartseries.h" |
|
8 | #include "qbarchartseries.h" | |
9 | #include "stackedbarchartseries.h" |
|
9 | #include "qstackedbarchartseries.h" | |
10 | #include "percentbarchartseries.h" |
|
10 | #include "qpercentbarchartseries.h" | |
11 | #include "qlinechartseries.h" |
|
11 | #include "qlinechartseries.h" | |
12 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | #include "qpieseries.h" |
|
13 | #include "qpieseries.h" | |
14 | #include "qpieslice.h" |
|
14 | #include "qpieslice.h" | |
15 |
|
15 | |||
16 | //items |
|
16 | //items | |
17 | #include "axisitem_p.h" |
|
17 | #include "axisitem_p.h" | |
18 |
#include "bar |
|
18 | #include "barpresenter.h" | |
19 |
#include "stackedbar |
|
19 | #include "stackedbarpresenter.h" | |
20 | #include "linechartitem_p.h" |
|
20 | #include "linechartitem_p.h" | |
21 |
#include "percentbar |
|
21 | #include "percentbarpresenter.h" | |
22 | #include "scatterpresenter_p.h" |
|
22 | #include "scatterpresenter_p.h" | |
23 | #include "piepresenter.h" |
|
23 | #include "piepresenter.h" | |
24 |
|
24 | |||
25 | //themes |
|
25 | //themes | |
26 | #include "chartthemevanilla_p.h" |
|
26 | #include "chartthemevanilla_p.h" | |
27 | #include "chartthemeicy_p.h" |
|
27 | #include "chartthemeicy_p.h" | |
28 | #include "chartthemegrayscale_p.h" |
|
28 | #include "chartthemegrayscale_p.h" | |
29 | #include "chartthemescientific_p.h" |
|
29 | #include "chartthemescientific_p.h" | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /* TODO |
|
34 | /* TODO | |
35 | case QChart::ChartThemeUnnamed1: |
|
35 | case QChart::ChartThemeUnnamed1: | |
36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); | |
37 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
|
37 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); | |
38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); |
|
38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); | |
39 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); |
|
39 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); | |
40 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); |
|
40 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); | |
41 |
|
41 | |||
42 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
42 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); | |
43 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
43 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
46 | ChartTheme::ChartTheme(QChart::ChartTheme id) | |
47 | { |
|
47 | { | |
48 | m_id = id; |
|
48 | m_id = id; | |
49 | m_seriesColor.append(QRgb(0xff000000)); |
|
49 | m_seriesColor.append(QRgb(0xff000000)); | |
50 | m_seriesColor.append(QRgb(0xff707070)); |
|
50 | m_seriesColor.append(QRgb(0xff707070)); | |
51 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
51 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
52 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
52 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
56 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
57 | { |
|
57 | { | |
58 | switch(theme) { |
|
58 | switch(theme) { | |
59 | case QChart::ChartThemeDefault: |
|
59 | case QChart::ChartThemeDefault: | |
60 | return new ChartTheme(); |
|
60 | return new ChartTheme(); | |
61 | case QChart::ChartThemeVanilla: |
|
61 | case QChart::ChartThemeVanilla: | |
62 | return new ChartThemeVanilla(); |
|
62 | return new ChartThemeVanilla(); | |
63 | case QChart::ChartThemeIcy: |
|
63 | case QChart::ChartThemeIcy: | |
64 | return new ChartThemeIcy(); |
|
64 | return new ChartThemeIcy(); | |
65 | case QChart::ChartThemeGrayscale: |
|
65 | case QChart::ChartThemeGrayscale: | |
66 | return new ChartThemeGrayscale(); |
|
66 | return new ChartThemeGrayscale(); | |
67 | case QChart::ChartThemeScientific: |
|
67 | case QChart::ChartThemeScientific: | |
68 | return new ChartThemeScientific(); |
|
68 | return new ChartThemeScientific(); | |
69 | } |
|
69 | } | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void ChartTheme::decorate(QChart* chart) |
|
72 | void ChartTheme::decorate(QChart* chart) | |
73 | { |
|
73 | { | |
74 | QLinearGradient backgroundGradient; |
|
74 | QLinearGradient backgroundGradient; | |
75 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); |
|
75 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); | |
76 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); |
|
76 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); | |
77 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
77 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
78 | chart->setChartBackgroundBrush(backgroundGradient); |
|
78 | chart->setChartBackgroundBrush(backgroundGradient); | |
79 | } |
|
79 | } | |
80 | //TODO helper to by removed later |
|
80 | //TODO helper to by removed later | |
81 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) |
|
81 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) | |
82 | { |
|
82 | { | |
83 | switch(series->type()) |
|
83 | switch(series->type()) | |
84 | { |
|
84 | { | |
85 | case QChartSeries::SeriesTypeLine: { |
|
85 | case QChartSeries::SeriesTypeLine: { | |
86 | QLineChartSeries* s = static_cast<QLineChartSeries*>(series); |
|
86 | QLineChartSeries* s = static_cast<QLineChartSeries*>(series); | |
87 | LineChartItem* i = static_cast<LineChartItem*>(item); |
|
87 | LineChartItem* i = static_cast<LineChartItem*>(item); | |
88 | decorate(i,s,count); |
|
88 | decorate(i,s,count); | |
89 | break; |
|
89 | break; | |
90 | } |
|
90 | } | |
91 | case QChartSeries::SeriesTypeBar: { |
|
91 | case QChartSeries::SeriesTypeBar: { | |
92 | BarChartSeries* b = static_cast<BarChartSeries*>(series); |
|
92 | QBarChartSeries* b = static_cast<QBarChartSeries*>(series); | |
93 |
Bar |
|
93 | BarPresenter* i = static_cast<BarPresenter*>(item); | |
94 | decorate(i,b,count); |
|
94 | decorate(i,b,count); | |
95 | break; |
|
95 | break; | |
96 | } |
|
96 | } | |
97 | case QChartSeries::SeriesTypeStackedBar: { |
|
97 | case QChartSeries::SeriesTypeStackedBar: { | |
98 | StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series); |
|
98 | QStackedBarChartSeries* s = static_cast<QStackedBarChartSeries*>(series); | |
99 |
StackedBar |
|
99 | StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item); | |
100 | decorate(i,s,count); |
|
100 | decorate(i,s,count); | |
101 | break; |
|
101 | break; | |
102 | } |
|
102 | } | |
103 | case QChartSeries::SeriesTypePercentBar: { |
|
103 | case QChartSeries::SeriesTypePercentBar: { | |
104 | PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series); |
|
104 | QPercentBarChartSeries* s = static_cast<QPercentBarChartSeries*>(series); | |
105 |
PercentBar |
|
105 | PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item); | |
106 | decorate(i,s,count); |
|
106 | decorate(i,s,count); | |
107 | break; |
|
107 | break; | |
108 | } |
|
108 | } | |
109 | case QChartSeries::SeriesTypeScatter: { |
|
109 | case QChartSeries::SeriesTypeScatter: { | |
110 | QScatterSeries* s = qobject_cast<QScatterSeries*>(series); |
|
110 | QScatterSeries* s = qobject_cast<QScatterSeries*>(series); | |
111 | Q_ASSERT(s); |
|
111 | Q_ASSERT(s); | |
112 | ScatterPresenter* i = static_cast<ScatterPresenter*>(item); |
|
112 | ScatterPresenter* i = static_cast<ScatterPresenter*>(item); | |
113 | Q_ASSERT(i); |
|
113 | Q_ASSERT(i); | |
114 | decorate(i, s, count); |
|
114 | decorate(i, s, count); | |
115 | break; |
|
115 | break; | |
116 | } |
|
116 | } | |
117 | case QChartSeries::SeriesTypePie: { |
|
117 | case QChartSeries::SeriesTypePie: { | |
118 | QPieSeries* s = static_cast<QPieSeries*>(series); |
|
118 | QPieSeries* s = static_cast<QPieSeries*>(series); | |
119 | PiePresenter* i = static_cast<PiePresenter*>(item); |
|
119 | PiePresenter* i = static_cast<PiePresenter*>(item); | |
120 | decorate(i,s,count); |
|
120 | decorate(i,s,count); | |
121 | break; |
|
121 | break; | |
122 | } |
|
122 | } | |
123 | default: |
|
123 | default: | |
124 | qDebug()<<"Wrong item to be decorated by theme"; |
|
124 | qDebug()<<"Wrong item to be decorated by theme"; | |
125 | break; |
|
125 | break; | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count) |
|
130 | void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count) | |
131 | { |
|
131 | { | |
132 | QPen pen; |
|
132 | QPen pen; | |
133 | if(pen != series->pen()){ |
|
133 | if(pen != series->pen()){ | |
134 | item->setPen(series->pen()); |
|
134 | item->setPen(series->pen()); | |
135 | return; |
|
135 | return; | |
136 | } |
|
136 | } | |
137 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
137 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
138 | pen.setWidthF(2); |
|
138 | pen.setWidthF(2); | |
139 | item->setPen(pen); |
|
139 | item->setPen(pen); | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 |
void ChartTheme::decorate(Bar |
|
142 | void ChartTheme::decorate(BarPresenter* item, QBarChartSeries* series,int count) | |
143 | { |
|
143 | { | |
144 | for (int i=0; i<series->countSets(); i++) { |
|
144 | for (int i=0; i<series->countSets(); i++) { | |
145 | series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
145 | series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 |
void ChartTheme::decorate(StackedBar |
|
149 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarChartSeries* series,int count) | |
150 | { |
|
150 | { | |
151 | for (int i=0; i<series->countSets(); i++) { |
|
151 | for (int i=0; i<series->countSets(); i++) { | |
152 | series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
152 | series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 |
void ChartTheme::decorate(PercentBar |
|
156 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarChartSeries* series,int count) | |
157 | { |
|
157 | { | |
158 | for (int i=0; i<series->countSets(); i++) { |
|
158 | for (int i=0; i<series->countSets(); i++) { | |
159 | series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
159 | series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
160 | } |
|
160 | } | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) |
|
163 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) | |
164 | { |
|
164 | { | |
165 | Q_ASSERT(presenter); |
|
165 | Q_ASSERT(presenter); | |
166 | Q_ASSERT(series); |
|
166 | Q_ASSERT(series); | |
167 |
|
167 | |||
168 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); |
|
168 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); | |
169 | // TODO: define alpha in the theme? or in the series? |
|
169 | // TODO: define alpha in the theme? or in the series? | |
170 | color.setAlpha(120); |
|
170 | color.setAlpha(120); | |
171 |
|
171 | |||
172 | QBrush brush(color, Qt::SolidPattern); |
|
172 | QBrush brush(color, Qt::SolidPattern); | |
173 | presenter->m_markerBrush = brush; |
|
173 | presenter->m_markerBrush = brush; | |
174 |
|
174 | |||
175 | QPen pen(brush, 1); |
|
175 | QPen pen(brush, 1); | |
176 | pen.setColor(color); |
|
176 | pen.setColor(color); | |
177 | presenter->m_markerPen = pen; |
|
177 | presenter->m_markerPen = pen; | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) |
|
180 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) | |
181 | { |
|
181 | { | |
182 | // create a list of slice colors based on current theme |
|
182 | // create a list of slice colors based on current theme | |
183 | int i = 0; |
|
183 | int i = 0; | |
184 | QList<QColor> colors; |
|
184 | QList<QColor> colors; | |
185 | while (colors.count() < series->count()) { |
|
185 | while (colors.count() < series->count()) { | |
186 |
|
186 | |||
187 | // get base color |
|
187 | // get base color | |
188 | QColor c = m_seriesColor[i++]; |
|
188 | QColor c = m_seriesColor[i++]; | |
189 | i = i % m_seriesColor.count(); |
|
189 | i = i % m_seriesColor.count(); | |
190 |
|
190 | |||
191 | // -1 means achromatic color -> cannot manipulate lightness |
|
191 | // -1 means achromatic color -> cannot manipulate lightness | |
192 | // TODO: find a better way to randomize lightness |
|
192 | // TODO: find a better way to randomize lightness | |
193 | if (c.toHsv().hue() == -1) |
|
193 | if (c.toHsv().hue() == -1) | |
194 | qWarning() << "ChartTheme::decorate() warning: achromatic theme color"; |
|
194 | qWarning() << "ChartTheme::decorate() warning: achromatic theme color"; | |
195 |
|
195 | |||
196 | // randomize lightness |
|
196 | // randomize lightness | |
197 | qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter |
|
197 | qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter | |
198 | c = c.lighter(f); |
|
198 | c = c.lighter(f); | |
199 |
|
199 | |||
200 | // find duplicates |
|
200 | // find duplicates | |
201 | bool isUnique = true; |
|
201 | bool isUnique = true; | |
202 | foreach (QColor color, colors) { |
|
202 | foreach (QColor color, colors) { | |
203 | if (c == color) |
|
203 | if (c == color) | |
204 | isUnique = false; |
|
204 | isUnique = false; | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | // add to array if unique |
|
207 | // add to array if unique | |
208 | //if (isUnique) |
|
208 | //if (isUnique) | |
209 | colors << c; |
|
209 | colors << c; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | // finally update colors |
|
212 | // finally update colors | |
213 | foreach (QPieSlice* s, series->slices()) { |
|
213 | foreach (QPieSlice* s, series->slices()) { | |
214 | s->setPen(QPen(Qt::black)); // TODO: get from theme |
|
214 | s->setPen(QPen(Qt::black)); // TODO: get from theme | |
215 | s->setBrush(colors.takeFirst()); |
|
215 | s->setBrush(colors.takeFirst()); | |
216 | } |
|
216 | } | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 |
|
219 | |||
220 | void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) |
|
220 | void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) | |
221 | { |
|
221 | { | |
222 | //TODO: dummy defults for now |
|
222 | //TODO: dummy defults for now | |
223 |
|
223 | |||
224 | axis.setLabelsBrush(Qt::black); |
|
224 | axis.setLabelsBrush(Qt::black); | |
225 | axis.setLabelsPen(Qt::NoPen); |
|
225 | axis.setLabelsPen(Qt::NoPen); | |
226 | axis.setShadesPen(Qt::NoPen); |
|
226 | axis.setShadesPen(Qt::NoPen); | |
227 | axis.setShadesOpacity(0.5); |
|
227 | axis.setShadesOpacity(0.5); | |
228 | item->handleAxisChanged(axis); |
|
228 | item->handleAxisChanged(axis); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | QTCOMMERCIALCHART_END_NAMESPACE |
|
231 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,52 +1,52 | |||||
1 | #ifndef CHARTTHEME_H |
|
1 | #ifndef CHARTTHEME_H | |
2 | #define CHARTTHEME_H |
|
2 | #define CHARTTHEME_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" |
|
5 | #include "qchart.h" | |
6 | #include <QColor> |
|
6 | #include <QColor> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class ChartItem; |
|
10 | class ChartItem; | |
11 | class QChartSeries; |
|
11 | class QChartSeries; | |
12 | class LineChartItem; |
|
12 | class LineChartItem; | |
13 | class QLineChartSeries; |
|
13 | class QLineChartSeries; | |
14 |
class Bar |
|
14 | class BarPresenter; | |
15 | class BarChartSeries; |
|
15 | class QBarChartSeries; | |
16 |
class StackedBar |
|
16 | class StackedBarPresenter; | |
17 | class StackedBarChartSeries; |
|
17 | class QStackedBarChartSeries; | |
18 | class PercentBarChartSeries; |
|
18 | class QPercentBarChartSeries; | |
19 |
class PercentBar |
|
19 | class PercentBarPresenter; | |
20 | class QScatterSeries; |
|
20 | class QScatterSeries; | |
21 | class ScatterPresenter; |
|
21 | class ScatterPresenter; | |
22 | class PiePresenter; |
|
22 | class PiePresenter; | |
23 | class QPieSeries; |
|
23 | class QPieSeries; | |
24 |
|
24 | |||
25 | class ChartTheme |
|
25 | class ChartTheme | |
26 | { |
|
26 | { | |
27 | protected: |
|
27 | protected: | |
28 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); |
|
28 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); | |
29 | public: |
|
29 | public: | |
30 | static ChartTheme* createTheme(QChart::ChartTheme theme); |
|
30 | static ChartTheme* createTheme(QChart::ChartTheme theme); | |
31 | QChart::ChartTheme id() const {return m_id;} |
|
31 | QChart::ChartTheme id() const {return m_id;} | |
32 | void decorate(QChart* chart); |
|
32 | void decorate(QChart* chart); | |
33 | void decorate(ChartItem* item, QChartSeries* series,int count); |
|
33 | void decorate(ChartItem* item, QChartSeries* series,int count); | |
34 | void decorate(LineChartItem* item, QLineChartSeries*, int count); |
|
34 | void decorate(LineChartItem* item, QLineChartSeries*, int count); | |
35 |
void decorate(Bar |
|
35 | void decorate(BarPresenter* item, QBarChartSeries* series,int count); | |
36 |
void decorate(StackedBar |
|
36 | void decorate(StackedBarPresenter* item, QStackedBarChartSeries* series,int count); | |
37 |
void decorate(PercentBar |
|
37 | void decorate(PercentBarPresenter* item, QPercentBarChartSeries* series,int count); | |
38 | void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); |
|
38 | void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); | |
39 | void decorate(PiePresenter* item, QPieSeries* series, int count); |
|
39 | void decorate(PiePresenter* item, QPieSeries* series, int count); | |
40 | void decorate(QChartAxis& axis,AxisItem* item); |
|
40 | void decorate(QChartAxis& axis,AxisItem* item); | |
41 |
|
41 | |||
42 | protected: |
|
42 | protected: | |
43 | QChart::ChartTheme m_id; |
|
43 | QChart::ChartTheme m_id; | |
44 | QColor m_gradientStartColor; |
|
44 | QColor m_gradientStartColor; | |
45 | QColor m_gradientEndColor; |
|
45 | QColor m_gradientEndColor; | |
46 | QList<QColor> m_seriesColor; |
|
46 | QList<QColor> m_seriesColor; | |
47 |
|
47 | |||
48 | }; |
|
48 | }; | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
51 | |||
52 | #endif // CHARTTHEME_H |
|
52 | #endif // CHARTTHEME_H |
@@ -1,209 +1,209 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 |
|
5 | |||
6 | //series |
|
6 | //series | |
7 | #include "barchartseries.h" |
|
7 | #include "qbarchartseries.h" | |
8 | #include "stackedbarchartseries.h" |
|
8 | #include "qstackedbarchartseries.h" | |
9 | #include "percentbarchartseries.h" |
|
9 | #include "qpercentbarchartseries.h" | |
10 | #include "qlinechartseries.h" |
|
10 | #include "qlinechartseries.h" | |
11 | #include "qscatterseries.h" |
|
11 | #include "qscatterseries.h" | |
12 | //#include "scatterseries_p.h" |
|
12 | //#include "scatterseries_p.h" | |
13 | #include "qpieseries.h" |
|
13 | #include "qpieseries.h" | |
14 |
|
14 | |||
15 | #include <QGraphicsScene> |
|
15 | #include <QGraphicsScene> | |
16 | #include <QGraphicsSceneResizeEvent> |
|
16 | #include <QGraphicsSceneResizeEvent> | |
17 | #include <QDebug> |
|
17 | #include <QDebug> | |
18 |
|
18 | |||
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
20 |
|
20 | |||
21 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
21 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
22 | m_backgroundItem(0), |
|
22 | m_backgroundItem(0), | |
23 | m_titleItem(0), |
|
23 | m_titleItem(0), | |
24 | m_dataset(new ChartDataSet(this)), |
|
24 | m_dataset(new ChartDataSet(this)), | |
25 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
25 | m_presenter(new ChartPresenter(this,m_dataset)) | |
26 | { |
|
26 | { | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | QChart::~QChart() {} |
|
29 | QChart::~QChart() {} | |
30 |
|
30 | |||
31 | void QChart::addSeries(QChartSeries* series) |
|
31 | void QChart::addSeries(QChartSeries* series) | |
32 | { |
|
32 | { | |
33 | m_dataset->addSeries(series); |
|
33 | m_dataset->addSeries(series); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | //TODO on review, is it really needed ?? |
|
36 | //TODO on review, is it really needed ?? | |
37 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
37 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
38 | { |
|
38 | { | |
39 | QChartSeries *series(0); |
|
39 | QChartSeries *series(0); | |
40 |
|
40 | |||
41 | switch (type) { |
|
41 | switch (type) { | |
42 | case QChartSeries::SeriesTypeLine: { |
|
42 | case QChartSeries::SeriesTypeLine: { | |
43 | series = new QLineChartSeries(this); |
|
43 | series = new QLineChartSeries(this); | |
44 | break; |
|
44 | break; | |
45 | } |
|
45 | } | |
46 | case QChartSeries::SeriesTypeBar: { |
|
46 | case QChartSeries::SeriesTypeBar: { | |
47 | //series = new BarChartSeries(this); |
|
47 | //series = new BarChartSeries(this); | |
48 | break; |
|
48 | break; | |
49 | } |
|
49 | } | |
50 | case QChartSeries::SeriesTypeStackedBar: { |
|
50 | case QChartSeries::SeriesTypeStackedBar: { | |
51 | //series = new StackedBarChartSeries(this); |
|
51 | //series = new StackedBarChartSeries(this); | |
52 | break; |
|
52 | break; | |
53 | } |
|
53 | } | |
54 | case QChartSeries::SeriesTypePercentBar: { |
|
54 | case QChartSeries::SeriesTypePercentBar: { | |
55 | //series = new PercentBarChartSeries(this); |
|
55 | //series = new PercentBarChartSeries(this); | |
56 | break; |
|
56 | break; | |
57 | } |
|
57 | } | |
58 | case QChartSeries::SeriesTypeScatter: { |
|
58 | case QChartSeries::SeriesTypeScatter: { | |
59 | series = new QScatterSeries(this); |
|
59 | series = new QScatterSeries(this); | |
60 | break; |
|
60 | break; | |
61 | } |
|
61 | } | |
62 | case QChartSeries::SeriesTypePie: { |
|
62 | case QChartSeries::SeriesTypePie: { | |
63 | series = new QPieSeries(this); |
|
63 | series = new QPieSeries(this); | |
64 | break; |
|
64 | break; | |
65 | } |
|
65 | } | |
66 | default: |
|
66 | default: | |
67 | Q_ASSERT(false); |
|
67 | Q_ASSERT(false); | |
68 | break; |
|
68 | break; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | addSeries(series); |
|
71 | addSeries(series); | |
72 | return series; |
|
72 | return series; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
75 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
76 | { |
|
76 | { | |
77 |
|
77 | |||
78 | if(!m_backgroundItem) { |
|
78 | if(!m_backgroundItem) { | |
79 | m_backgroundItem = new QGraphicsRectItem(this); |
|
79 | m_backgroundItem = new QGraphicsRectItem(this); | |
80 | m_backgroundItem->setZValue(-1); |
|
80 | m_backgroundItem->setZValue(-1); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | m_backgroundItem->setBrush(brush); |
|
83 | m_backgroundItem->setBrush(brush); | |
84 | m_backgroundItem->update(); |
|
84 | m_backgroundItem->update(); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
87 | void QChart::setChartBackgroundPen(const QPen& pen) | |
88 | { |
|
88 | { | |
89 |
|
89 | |||
90 | if(!m_backgroundItem) { |
|
90 | if(!m_backgroundItem) { | |
91 | m_backgroundItem = new QGraphicsRectItem(this); |
|
91 | m_backgroundItem = new QGraphicsRectItem(this); | |
92 | m_backgroundItem->setZValue(-1); |
|
92 | m_backgroundItem->setZValue(-1); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | m_backgroundItem->setPen(pen); |
|
95 | m_backgroundItem->setPen(pen); | |
96 | m_backgroundItem->update(); |
|
96 | m_backgroundItem->update(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void QChart::setChartTitle(const QString& title) |
|
99 | void QChart::setChartTitle(const QString& title) | |
100 | { |
|
100 | { | |
101 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
101 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
102 | m_titleItem->setPlainText(title); |
|
102 | m_titleItem->setPlainText(title); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void QChart::setChartTitleFont(const QFont& font) |
|
105 | void QChart::setChartTitleFont(const QFont& font) | |
106 | { |
|
106 | { | |
107 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
107 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
108 | m_titleItem->setFont(font); |
|
108 | m_titleItem->setFont(font); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | int QChart::margin() const |
|
111 | int QChart::margin() const | |
112 | { |
|
112 | { | |
113 | return m_presenter->margin(); |
|
113 | return m_presenter->margin(); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void QChart::setMargin(int margin) |
|
116 | void QChart::setMargin(int margin) | |
117 | { |
|
117 | { | |
118 | m_presenter->setMargin(margin); |
|
118 | m_presenter->setMargin(margin); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
121 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
122 | { |
|
122 | { | |
123 | m_presenter->setChartTheme(theme); |
|
123 | m_presenter->setChartTheme(theme); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | QChart::ChartTheme QChart::chartTheme() const |
|
126 | QChart::ChartTheme QChart::chartTheme() const | |
127 | { |
|
127 | { | |
128 | return m_presenter->chartTheme(); |
|
128 | return m_presenter->chartTheme(); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
131 | void QChart::zoomInToRect(const QRectF& rectangle) | |
132 | { |
|
132 | { | |
133 | m_presenter->zoomInToRect(rectangle); |
|
133 | m_presenter->zoomInToRect(rectangle); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void QChart::zoomIn() |
|
136 | void QChart::zoomIn() | |
137 | { |
|
137 | { | |
138 | m_presenter->zoomIn(); |
|
138 | m_presenter->zoomIn(); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void QChart::zoomOut() |
|
141 | void QChart::zoomOut() | |
142 | { |
|
142 | { | |
143 | m_presenter->zoomOut(); |
|
143 | m_presenter->zoomOut(); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | void QChart::zoomReset() |
|
146 | void QChart::zoomReset() | |
147 | { |
|
147 | { | |
148 | m_presenter->zoomReset(); |
|
148 | m_presenter->zoomReset(); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void QChart::setDefaultAxisX(const QChartAxis& axis) |
|
151 | void QChart::setDefaultAxisX(const QChartAxis& axis) | |
152 | { |
|
152 | { | |
153 | m_presenter->setDefaultAxisX(axis); |
|
153 | m_presenter->setDefaultAxisX(axis); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void QChart::setDefaultAxisY(const QChartAxis& axis) |
|
156 | void QChart::setDefaultAxisY(const QChartAxis& axis) | |
157 | { |
|
157 | { | |
158 | m_presenter->setDefaultAxisY(axis); |
|
158 | m_presenter->setDefaultAxisY(axis); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | QChartAxis QChart::defaultAxisX() const |
|
161 | QChartAxis QChart::defaultAxisX() const | |
162 | { |
|
162 | { | |
163 | return m_presenter->defaultAxisX(); |
|
163 | return m_presenter->defaultAxisX(); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | QChartAxis QChart::defaultAxisY() const |
|
166 | QChartAxis QChart::defaultAxisY() const | |
167 | { |
|
167 | { | |
168 | return m_presenter->defaultAxisY(); |
|
168 | return m_presenter->defaultAxisY(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | int QChart::addAxisY(const QChartAxis& axis) |
|
171 | int QChart::addAxisY(const QChartAxis& axis) | |
172 | { |
|
172 | { | |
173 | return m_presenter->addAxisY(axis); |
|
173 | return m_presenter->addAxisY(axis); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | QChartAxis QChart::axisY(int id) const |
|
176 | QChartAxis QChart::axisY(int id) const | |
177 | { |
|
177 | { | |
178 | return m_presenter->axisY(id); |
|
178 | return m_presenter->axisY(id); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | void QChart::removeAxisY(int id) |
|
181 | void QChart::removeAxisY(int id) | |
182 | { |
|
182 | { | |
183 | m_presenter->removeAxisY(id); |
|
183 | m_presenter->removeAxisY(id); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
186 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
187 | { |
|
187 | { | |
188 |
|
188 | |||
189 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
189 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
190 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
190 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
191 |
|
191 | |||
192 | // recalculate title position |
|
192 | // recalculate title position | |
193 | if (m_titleItem) { |
|
193 | if (m_titleItem) { | |
194 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
194 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
195 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
195 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | //recalculate background gradient |
|
198 | //recalculate background gradient | |
199 | if (m_backgroundItem) { |
|
199 | if (m_backgroundItem) { | |
200 | m_backgroundItem->setRect(rect); |
|
200 | m_backgroundItem->setRect(rect); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | QGraphicsWidget::resizeEvent(event); |
|
203 | QGraphicsWidget::resizeEvent(event); | |
204 | update(); |
|
204 | update(); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | #include "moc_qchart.cpp" |
|
207 | #include "moc_qchart.cpp" | |
208 |
|
208 | |||
209 | QTCOMMERCIALCHART_END_NAMESPACE |
|
209 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,93 +1,93 | |||||
1 | #ifndef CHART_H |
|
1 | #ifndef CHART_H | |
2 | #define CHART_H |
|
2 | #define CHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QChartSeries; |
|
15 | class QChartSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 |
class Bar |
|
17 | class BarPresenter; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 |
|
23 | |||
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: |
|
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
25 | //class QTCOMMERCIALCHART_EXPORT QChart |
|
25 | //class QTCOMMERCIALCHART_EXPORT QChart | |
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { |
|
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
27 | // public: QChartGraphicsItem(QChart &chart); |
|
27 | // public: QChartGraphicsItem(QChart &chart); | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | * TODO: define the responsibilities |
|
30 | * TODO: define the responsibilities | |
31 | */ |
|
31 | */ | |
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | enum ChartTheme { |
|
36 | enum ChartTheme { | |
37 | /*! The default theme follows the GUI style of the Operating System */ |
|
37 | /*! The default theme follows the GUI style of the Operating System */ | |
38 | ChartThemeDefault, |
|
38 | ChartThemeDefault, | |
39 | ChartThemeVanilla, |
|
39 | ChartThemeVanilla, | |
40 | ChartThemeIcy, |
|
40 | ChartThemeIcy, | |
41 | ChartThemeGrayscale, |
|
41 | ChartThemeGrayscale, | |
42 | ChartThemeScientific, |
|
42 | ChartThemeScientific, | |
43 | //ChartThemeUnnamed1 |
|
43 | //ChartThemeUnnamed1 | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
48 | ~QChart(); |
|
48 | ~QChart(); | |
49 |
|
49 | |||
50 | void addSeries(QChartSeries* series); |
|
50 | void addSeries(QChartSeries* series); | |
51 |
|
51 | |||
52 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); |
|
52 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
53 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... |
|
53 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
54 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
54 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
55 |
|
55 | |||
56 | void setMargin(int margin); |
|
56 | void setMargin(int margin); | |
57 | int margin() const; |
|
57 | int margin() const; | |
58 | void setChartTheme(QChart::ChartTheme theme); |
|
58 | void setChartTheme(QChart::ChartTheme theme); | |
59 | QChart::ChartTheme chartTheme() const; |
|
59 | QChart::ChartTheme chartTheme() const; | |
60 |
|
60 | |||
61 | void setChartTitle(const QString& title); |
|
61 | void setChartTitle(const QString& title); | |
62 | void setChartTitleFont(const QFont& font); |
|
62 | void setChartTitleFont(const QFont& font); | |
63 | void setChartBackgroundBrush(const QBrush& brush); |
|
63 | void setChartBackgroundBrush(const QBrush& brush); | |
64 | void setChartBackgroundPen(const QPen& pen); |
|
64 | void setChartBackgroundPen(const QPen& pen); | |
65 |
|
65 | |||
66 | void zoomInToRect(const QRectF& rectangle); |
|
66 | void zoomInToRect(const QRectF& rectangle); | |
67 | void zoomIn(); |
|
67 | void zoomIn(); | |
68 | void zoomOut(); |
|
68 | void zoomOut(); | |
69 | void zoomReset(); |
|
69 | void zoomReset(); | |
70 |
|
70 | |||
71 | void setDefaultAxisX(const QChartAxis& axis); |
|
71 | void setDefaultAxisX(const QChartAxis& axis); | |
72 | void setDefaultAxisY(const QChartAxis& axis); |
|
72 | void setDefaultAxisY(const QChartAxis& axis); | |
73 | QChartAxis defaultAxisX() const; |
|
73 | QChartAxis defaultAxisX() const; | |
74 | QChartAxis defaultAxisY() const; |
|
74 | QChartAxis defaultAxisY() const; | |
75 | QChartAxis axisY(int id) const; |
|
75 | QChartAxis axisY(int id) const; | |
76 | int addAxisY(const QChartAxis& axis); |
|
76 | int addAxisY(const QChartAxis& axis); | |
77 | void removeAxisY(int id); |
|
77 | void removeAxisY(int id); | |
78 |
|
78 | |||
79 | protected: |
|
79 | protected: | |
80 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
80 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
81 |
|
81 | |||
82 | private: |
|
82 | private: | |
83 | Q_DISABLE_COPY(QChart) |
|
83 | Q_DISABLE_COPY(QChart) | |
84 | QGraphicsRectItem* m_backgroundItem; |
|
84 | QGraphicsRectItem* m_backgroundItem; | |
85 | QGraphicsTextItem* m_titleItem; |
|
85 | QGraphicsTextItem* m_titleItem; | |
86 | QRectF m_rect; |
|
86 | QRectF m_rect; | |
87 | ChartDataSet *m_dataset; |
|
87 | ChartDataSet *m_dataset; | |
88 | ChartPresenter *m_presenter; |
|
88 | ChartPresenter *m_presenter; | |
89 | }; |
|
89 | }; | |
90 |
|
90 | |||
91 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE | |
92 |
|
92 | |||
93 | #endif |
|
93 | #endif |
@@ -1,119 +1,120 | |||||
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) | |
2 | TARGET = QtCommercialChart |
|
2 | TARGET = QtCommercialChart | |
3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
3 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
4 | TEMPLATE = lib |
|
4 | TEMPLATE = lib | |
5 | QT += core \ |
|
5 | QT += core \ | |
6 | gui |
|
6 | gui | |
7 | CONFIG += debug_and_release |
|
7 | CONFIG += debug_and_release | |
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
9 | SOURCES += barchart/barchartseries.cpp \ |
|
9 | SOURCES += \ | |
10 | barchart/bargroup.cpp \ |
|
|||
11 | barchart/bar.cpp \ |
|
10 | barchart/bar.cpp \ | |
12 | barchart/stackedbarchartseries.cpp \ |
|
|||
13 | barchart/stackedbargroup.cpp \ |
|
|||
14 | barchart/percentbarchartseries.cpp \ |
|
|||
15 | barchart/percentbargroup.cpp \ |
|
|||
16 | barchart/barlabel.cpp \ |
|
11 | barchart/barlabel.cpp \ | |
17 | barchart/barchartmodel.cpp \ |
|
12 | barchart/barchartmodel.cpp \ | |
18 | barchart/separator.cpp \ |
|
13 | barchart/separator.cpp \ | |
19 | barchart/bargroupbase.cpp \ |
|
|||
20 | barchart/qbarset.cpp \ |
|
14 | barchart/qbarset.cpp \ | |
21 | barchart/qbarcategory.cpp \ |
|
15 | barchart/qbarcategory.cpp \ | |
|
16 | barchart/qbarchartseries.cpp \ | |||
|
17 | barchart/qpercentbarchartseries.cpp \ | |||
|
18 | barchart/qstackedbarchartseries.cpp \ | |||
|
19 | barchart/barpresenterbase.cpp \ | |||
|
20 | barchart/barpresenter.cpp \ | |||
|
21 | barchart/stackedbarpresenter.cpp \ | |||
|
22 | barchart/percentbarpresenter.cpp \ | |||
22 | linechart/linechartanimationitem.cpp \ |
|
23 | linechart/linechartanimationitem.cpp \ | |
23 | linechart/linechartitem.cpp \ |
|
24 | linechart/linechartitem.cpp \ | |
24 | linechart/qlinechartseries.cpp \ |
|
25 | linechart/qlinechartseries.cpp \ | |
25 | qchart.cpp \ |
|
26 | qchart.cpp \ | |
26 | axisitem.cpp \ |
|
27 | axisitem.cpp \ | |
27 | qchartview.cpp \ |
|
28 | qchartview.cpp \ | |
28 | qchartseries.cpp \ |
|
29 | qchartseries.cpp \ | |
29 | qchartaxis.cpp \ |
|
30 | qchartaxis.cpp \ | |
30 | charttheme.cpp \ |
|
31 | charttheme.cpp \ | |
31 | chartdataset.cpp \ |
|
32 | chartdataset.cpp \ | |
32 | chartpresenter.cpp \ |
|
33 | chartpresenter.cpp \ | |
33 | domain.cpp |
|
34 | domain.cpp | |
34 | PRIVATE_HEADERS += linechart/linechartitem_p.h \ |
|
35 | PRIVATE_HEADERS += linechart/linechartitem_p.h \ | |
35 | linechart/linechartanimationitem_p.h \ |
|
36 | linechart/linechartanimationitem_p.h \ | |
36 | barchart/barlabel_p.h \ |
|
37 | barchart/barlabel_p.h \ | |
37 | barchart/bar_p.h \ |
|
38 | barchart/bar_p.h \ | |
38 | barchart/separator_p.h \ |
|
39 | barchart/separator_p.h \ | |
39 | barchart/barchartmodel_p.h \ |
|
40 | barchart/barchartmodel_p.h \ | |
40 | axisitem_p.h \ |
|
41 | axisitem_p.h \ | |
41 | chartitem_p.h \ |
|
42 | chartitem_p.h \ | |
42 | charttheme_p.h \ |
|
43 | charttheme_p.h \ | |
43 | chartdataset_p.h \ |
|
44 | chartdataset_p.h \ | |
44 | chartpresenter_p.h \ |
|
45 | chartpresenter_p.h \ | |
45 | domain_p.h |
|
46 | domain_p.h | |
46 | PUBLIC_HEADERS += linechart/qlinechartseries.h \ |
|
47 | PUBLIC_HEADERS += linechart/qlinechartseries.h \ | |
47 | barchart/barchartseries.h \ |
|
48 | barchart/qbarchartseries.h \ | |
48 |
barchart/bar |
|
49 | barchart/barpresenter.h \ | |
49 | barchart/stackedbarchartseries.h \ |
|
50 | barchart/qstackedbarchartseries.h \ | |
50 |
barchart/stackedbar |
|
51 | barchart/stackedbarpresenter.h \ | |
51 | barchart/percentbarchartseries.h \ |
|
52 | barchart/qpercentbarchartseries.h \ | |
52 |
barchart/percentbar |
|
53 | barchart/percentbarpresenter.h \ | |
53 |
barchart/bar |
|
54 | barchart/barpresenterbase.h \ | |
54 | barchart/qbarset.h \ |
|
55 | barchart/qbarset.h \ | |
55 | barchart/qbarcategory.h \ |
|
56 | barchart/qbarcategory.h \ | |
56 | qchartseries.h \ |
|
57 | qchartseries.h \ | |
57 | qchart.h \ |
|
58 | qchart.h \ | |
58 | qchartglobal.h \ |
|
59 | qchartglobal.h \ | |
59 | qchartview.h \ |
|
60 | qchartview.h \ | |
60 | qchartaxis.h |
|
61 | qchartaxis.h | |
61 |
|
62 | |||
62 | include(piechart/piechart.pri) |
|
63 | include(piechart/piechart.pri) | |
63 | include(scatterseries/scatter.pri) |
|
64 | include(scatterseries/scatter.pri) | |
64 |
|
65 | |||
65 | THEMES += themes/chartthemeicy_p.h \ |
|
66 | THEMES += themes/chartthemeicy_p.h \ | |
66 | themes/chartthemegrayscale_p.h \ |
|
67 | themes/chartthemegrayscale_p.h \ | |
67 | themes/chartthemescientific_p.h \ |
|
68 | themes/chartthemescientific_p.h \ | |
68 | themes/chartthemevanilla_p.h |
|
69 | themes/chartthemevanilla_p.h | |
69 | HEADERS += $$PUBLIC_HEADERS |
|
70 | HEADERS += $$PUBLIC_HEADERS | |
70 | HEADERS += $$PRIVATE_HEADERS |
|
71 | HEADERS += $$PRIVATE_HEADERS | |
71 | HEADERS += $$THEMES |
|
72 | HEADERS += $$THEMES | |
72 | INCLUDEPATH += linechart \ |
|
73 | INCLUDEPATH += linechart \ | |
73 | barchart \ |
|
74 | barchart \ | |
74 | themes \ |
|
75 | themes \ | |
75 | . |
|
76 | . | |
76 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
77 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
77 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
78 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
78 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
79 | UI_DIR = $$CHART_BUILD_DIR/lib | |
79 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
80 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
80 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
81 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
81 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
82 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
82 | public_headers.files = $$PUBLIC_HEADERS |
|
83 | public_headers.files = $$PUBLIC_HEADERS | |
83 | target.path = $$[QT_INSTALL_LIBS] |
|
84 | target.path = $$[QT_INSTALL_LIBS] | |
84 | INSTALLS += target \ |
|
85 | INSTALLS += target \ | |
85 | public_headers |
|
86 | public_headers | |
86 | install_build_public_headers.name = bild_public_headers |
|
87 | install_build_public_headers.name = bild_public_headers | |
87 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
88 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
88 | install_build_public_headers.input = PUBLIC_HEADERS |
|
89 | install_build_public_headers.input = PUBLIC_HEADERS | |
89 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
90 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
90 | ${QMAKE_FILE_NAME} \ |
|
91 | ${QMAKE_FILE_NAME} \ | |
91 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
92 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
92 | install_build_public_headers.CONFIG += target_predeps \ |
|
93 | install_build_public_headers.CONFIG += target_predeps \ | |
93 | no_link |
|
94 | no_link | |
94 | install_build_private_headers.name = bild_private_headers |
|
95 | install_build_private_headers.name = bild_private_headers | |
95 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
96 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
96 | install_build_private_headers.input = PRIVATE_HEADERS |
|
97 | install_build_private_headers.input = PRIVATE_HEADERS | |
97 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
98 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
98 | ${QMAKE_FILE_NAME} \ |
|
99 | ${QMAKE_FILE_NAME} \ | |
99 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
100 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
100 | install_build_private_headers.CONFIG += target_predeps \ |
|
101 | install_build_private_headers.CONFIG += target_predeps \ | |
101 | no_link |
|
102 | no_link | |
102 | QMAKE_EXTRA_COMPILERS += install_build_public_headers install_build_private_headers |
|
103 | QMAKE_EXTRA_COMPILERS += install_build_public_headers install_build_private_headers | |
103 | chartversion.target = qchartversion_p.h |
|
104 | chartversion.target = qchartversion_p.h | |
104 | chartversion.commands = @echo \ |
|
105 | chartversion.commands = @echo \ | |
105 | "build_time" \ |
|
106 | "build_time" \ | |
106 | > \ |
|
107 | > \ | |
107 | $$chartversion.target; |
|
108 | $$chartversion.target; | |
108 | chartversion.depends = $$HEADERS \ |
|
109 | chartversion.depends = $$HEADERS \ | |
109 | $$SOURCES |
|
110 | $$SOURCES | |
110 | PRE_TARGETDEPS += qchartversion_p.h |
|
111 | PRE_TARGETDEPS += qchartversion_p.h | |
111 | QMAKE_CLEAN += qchartversion_p.h |
|
112 | QMAKE_CLEAN += qchartversion_p.h | |
112 | QMAKE_EXTRA_TARGETS += chartversion |
|
113 | QMAKE_EXTRA_TARGETS += chartversion | |
113 | unix:QMAKE_DISTCLEAN += -r \ |
|
114 | unix:QMAKE_DISTCLEAN += -r \ | |
114 | $$CHART_BUILD_HEADER_DIR \ |
|
115 | $$CHART_BUILD_HEADER_DIR \ | |
115 | $$CHART_BUILD_LIB_DIR |
|
116 | $$CHART_BUILD_LIB_DIR | |
116 | win32:QMAKE_DISTCLEAN += /Q \ |
|
117 | win32:QMAKE_DISTCLEAN += /Q \ | |
117 | $$CHART_BUILD_HEADER_DIR \ |
|
118 | $$CHART_BUILD_HEADER_DIR \ | |
118 | $$CHART_BUILD_LIB_DIR |
|
119 | $$CHART_BUILD_LIB_DIR | |
119 |
|
120 |
@@ -1,430 +1,430 | |||||
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 "qscatterseries.h" |
|
5 | #include "qscatterseries.h" | |
6 | #include <qlinechartseries.h> |
|
6 | #include <qlinechartseries.h> | |
7 | #include <qbarset.h> |
|
7 | #include <qbarset.h> | |
8 | #include <qbarcategory.h> |
|
8 | #include <qbarcategory.h> | |
9 | #include <barchartseries.h> |
|
9 | #include <qbarchartseries.h> | |
10 | #include <stackedbarchartseries.h> |
|
10 | #include <qstackedbarchartseries.h> | |
11 | #include <percentbarchartseries.h> |
|
11 | #include <qpercentbarchartseries.h> | |
12 | #include <QPushButton> |
|
12 | #include <QPushButton> | |
13 | #include <QComboBox> |
|
13 | #include <QComboBox> | |
14 | #include <QSpinBox> |
|
14 | #include <QSpinBox> | |
15 | #include <QCheckBox> |
|
15 | #include <QCheckBox> | |
16 | #include <QGridLayout> |
|
16 | #include <QGridLayout> | |
17 | #include <QHBoxLayout> |
|
17 | #include <QHBoxLayout> | |
18 | #include <QLabel> |
|
18 | #include <QLabel> | |
19 | #include <QSpacerItem> |
|
19 | #include <QSpacerItem> | |
20 | #include <QMessageBox> |
|
20 | #include <QMessageBox> | |
21 | #include <cmath> |
|
21 | #include <cmath> | |
22 | #include <QDebug> |
|
22 | #include <QDebug> | |
23 | #include <QStandardItemModel> |
|
23 | #include <QStandardItemModel> | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
27 | |||
28 | MainWidget::MainWidget(QWidget *parent) : |
|
28 | MainWidget::MainWidget(QWidget *parent) : | |
29 | QWidget(parent) |
|
29 | QWidget(parent) | |
30 | { |
|
30 | { | |
31 | m_chartWidget = new QChartView(this); |
|
31 | m_chartWidget = new QChartView(this); | |
32 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); |
|
32 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); | |
33 |
|
33 | |||
34 | // Grid layout for the controls for configuring the chart widget |
|
34 | // Grid layout for the controls for configuring the chart widget | |
35 | QGridLayout *grid = new QGridLayout(); |
|
35 | QGridLayout *grid = new QGridLayout(); | |
36 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
36 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
37 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
37 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
38 | grid->addWidget(addSeriesButton, 0, 1); |
|
38 | grid->addWidget(addSeriesButton, 0, 1); | |
39 | initBackroundCombo(grid); |
|
39 | initBackroundCombo(grid); | |
40 | initScaleControls(grid); |
|
40 | initScaleControls(grid); | |
41 | initThemeCombo(grid); |
|
41 | initThemeCombo(grid); | |
42 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
42 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
43 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); |
|
43 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); | |
44 | zoomCheckBox->setChecked(true); |
|
44 | zoomCheckBox->setChecked(true); | |
45 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
45 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
46 | // add row with empty label to make all the other rows static |
|
46 | // add row with empty label to make all the other rows static | |
47 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
47 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
48 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
48 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
49 |
|
49 | |||
50 | // Another grid layout as a main layout |
|
50 | // Another grid layout as a main layout | |
51 | QGridLayout *mainLayout = new QGridLayout(); |
|
51 | QGridLayout *mainLayout = new QGridLayout(); | |
52 | mainLayout->addLayout(grid, 0, 0); |
|
52 | mainLayout->addLayout(grid, 0, 0); | |
53 |
|
53 | |||
54 | // Init series type specific controls |
|
54 | // Init series type specific controls | |
55 | initPieControls(); |
|
55 | initPieControls(); | |
56 | mainLayout->addLayout(m_pieLayout, 2, 0); |
|
56 | mainLayout->addLayout(m_pieLayout, 2, 0); | |
57 | // Scatter series specific settings |
|
57 | // Scatter series specific settings | |
58 | // m_scatterLayout = new QGridLayout(); |
|
58 | // m_scatterLayout = new QGridLayout(); | |
59 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); |
|
59 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); | |
60 | // m_scatterLayout->setEnabled(false); |
|
60 | // m_scatterLayout->setEnabled(false); | |
61 | // mainLayout->addLayout(m_scatterLayout, 1, 0); |
|
61 | // mainLayout->addLayout(m_scatterLayout, 1, 0); | |
62 |
|
62 | |||
63 | // Add layouts and the chart widget to the main layout |
|
63 | // Add layouts and the chart widget to the main layout | |
64 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); |
|
64 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); | |
65 | setLayout(mainLayout); |
|
65 | setLayout(mainLayout); | |
66 |
|
66 | |||
67 | // force an update to test data |
|
67 | // force an update to test data | |
68 | testDataChanged(0); |
|
68 | testDataChanged(0); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | // Combo box for selecting the chart's background |
|
71 | // Combo box for selecting the chart's background | |
72 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
72 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
73 | { |
|
73 | { | |
74 | QComboBox *backgroundCombo = new QComboBox(this); |
|
74 | QComboBox *backgroundCombo = new QComboBox(this); | |
75 | backgroundCombo->addItem("Color"); |
|
75 | backgroundCombo->addItem("Color"); | |
76 | backgroundCombo->addItem("Gradient"); |
|
76 | backgroundCombo->addItem("Gradient"); | |
77 | backgroundCombo->addItem("Image"); |
|
77 | backgroundCombo->addItem("Image"); | |
78 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
78 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
79 | this, SLOT(backgroundChanged(int))); |
|
79 | this, SLOT(backgroundChanged(int))); | |
80 |
|
80 | |||
81 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
81 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
82 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
82 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | // Scale related controls (auto-scale vs. manual min-max values) |
|
85 | // Scale related controls (auto-scale vs. manual min-max values) | |
86 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
86 | void MainWidget::initScaleControls(QGridLayout *grid) | |
87 | { |
|
87 | { | |
88 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
88 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
89 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
89 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
90 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
90 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
91 | m_xMinSpin = new QSpinBox(); |
|
91 | m_xMinSpin = new QSpinBox(); | |
92 | m_xMinSpin->setMinimum(INT_MIN); |
|
92 | m_xMinSpin->setMinimum(INT_MIN); | |
93 | m_xMinSpin->setMaximum(INT_MAX); |
|
93 | m_xMinSpin->setMaximum(INT_MAX); | |
94 | m_xMinSpin->setValue(0); |
|
94 | m_xMinSpin->setValue(0); | |
95 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
95 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
96 | m_xMaxSpin = new QSpinBox(); |
|
96 | m_xMaxSpin = new QSpinBox(); | |
97 | m_xMaxSpin->setMinimum(INT_MIN); |
|
97 | m_xMaxSpin->setMinimum(INT_MIN); | |
98 | m_xMaxSpin->setMaximum(INT_MAX); |
|
98 | m_xMaxSpin->setMaximum(INT_MAX); | |
99 | m_xMaxSpin->setValue(10); |
|
99 | m_xMaxSpin->setValue(10); | |
100 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
100 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
101 | m_yMinSpin = new QSpinBox(); |
|
101 | m_yMinSpin = new QSpinBox(); | |
102 | m_yMinSpin->setMinimum(INT_MIN); |
|
102 | m_yMinSpin->setMinimum(INT_MIN); | |
103 | m_yMinSpin->setMaximum(INT_MAX); |
|
103 | m_yMinSpin->setMaximum(INT_MAX); | |
104 | m_yMinSpin->setValue(0); |
|
104 | m_yMinSpin->setValue(0); | |
105 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
105 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
106 | m_yMaxSpin = new QSpinBox(); |
|
106 | m_yMaxSpin = new QSpinBox(); | |
107 | m_yMaxSpin->setMinimum(INT_MIN); |
|
107 | m_yMaxSpin->setMinimum(INT_MIN); | |
108 | m_yMaxSpin->setMaximum(INT_MAX); |
|
108 | m_yMaxSpin->setMaximum(INT_MAX); | |
109 | m_yMaxSpin->setValue(10); |
|
109 | m_yMaxSpin->setValue(10); | |
110 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
110 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
111 |
|
111 | |||
112 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
112 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
113 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
113 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
114 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
114 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
115 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
115 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
116 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
116 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
117 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
117 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
118 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
118 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
119 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
119 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
120 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
120 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
121 |
|
121 | |||
122 | m_autoScaleCheck->setChecked(true); |
|
122 | m_autoScaleCheck->setChecked(true); | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | // Combo box for selecting theme |
|
125 | // Combo box for selecting theme | |
126 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
126 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
127 | { |
|
127 | { | |
128 | QComboBox *chartTheme = new QComboBox(); |
|
128 | QComboBox *chartTheme = new QComboBox(); | |
129 | chartTheme->addItem("Default"); |
|
129 | chartTheme->addItem("Default"); | |
130 | chartTheme->addItem("Vanilla"); |
|
130 | chartTheme->addItem("Vanilla"); | |
131 | chartTheme->addItem("Icy"); |
|
131 | chartTheme->addItem("Icy"); | |
132 | chartTheme->addItem("Grayscale"); |
|
132 | chartTheme->addItem("Grayscale"); | |
133 | chartTheme->addItem("Scientific"); |
|
133 | chartTheme->addItem("Scientific"); | |
134 | chartTheme->addItem("Unnamed1"); |
|
134 | chartTheme->addItem("Unnamed1"); | |
135 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
135 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
136 | this, SLOT(changeChartTheme(int))); |
|
136 | this, SLOT(changeChartTheme(int))); | |
137 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
137 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
138 | grid->addWidget(chartTheme, 8, 1); |
|
138 | grid->addWidget(chartTheme, 8, 1); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void MainWidget::initPieControls() |
|
141 | void MainWidget::initPieControls() | |
142 | { |
|
142 | { | |
143 | // Pie series specific settings |
|
143 | // Pie series specific settings | |
144 | // Pie size factory |
|
144 | // Pie size factory | |
145 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); |
|
145 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); | |
146 | pieSizeSpin->setMinimum(LONG_MIN); |
|
146 | pieSizeSpin->setMinimum(LONG_MIN); | |
147 | pieSizeSpin->setMaximum(LONG_MAX); |
|
147 | pieSizeSpin->setMaximum(LONG_MAX); | |
148 | pieSizeSpin->setValue(1.0); |
|
148 | pieSizeSpin->setValue(1.0); | |
149 | pieSizeSpin->setSingleStep(0.1); |
|
149 | pieSizeSpin->setSingleStep(0.1); | |
150 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); |
|
150 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); | |
151 | // Pie position |
|
151 | // Pie position | |
152 | QComboBox *piePosCombo = new QComboBox(this); |
|
152 | QComboBox *piePosCombo = new QComboBox(this); | |
153 | piePosCombo->addItem("Maximized"); |
|
153 | piePosCombo->addItem("Maximized"); | |
154 | piePosCombo->addItem("Top left"); |
|
154 | piePosCombo->addItem("Top left"); | |
155 | piePosCombo->addItem("Top right"); |
|
155 | piePosCombo->addItem("Top right"); | |
156 | piePosCombo->addItem("Bottom left"); |
|
156 | piePosCombo->addItem("Bottom left"); | |
157 | piePosCombo->addItem("Bottom right"); |
|
157 | piePosCombo->addItem("Bottom right"); | |
158 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), |
|
158 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), | |
159 | this, SLOT(setPiePosition(int))); |
|
159 | this, SLOT(setPiePosition(int))); | |
160 | m_pieLayout = new QGridLayout(); |
|
160 | m_pieLayout = new QGridLayout(); | |
161 | m_pieLayout->setEnabled(false); |
|
161 | m_pieLayout->setEnabled(false); | |
162 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); |
|
162 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); | |
163 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); |
|
163 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); | |
164 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); |
|
164 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); | |
165 | m_pieLayout->addWidget(piePosCombo, 1, 1); |
|
165 | m_pieLayout->addWidget(piePosCombo, 1, 1); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void MainWidget::addSeries() |
|
168 | void MainWidget::addSeries() | |
169 | { |
|
169 | { | |
170 | DataSerieDialog dialog(m_defaultSeriesName, this); |
|
170 | DataSerieDialog dialog(m_defaultSeriesName, this); | |
171 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
171 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
172 | dialog.exec(); |
|
172 | dialog.exec(); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void MainWidget::addSeries(QString series, QString data) |
|
175 | void MainWidget::addSeries(QString series, QString data) | |
176 | { |
|
176 | { | |
177 | qDebug() << "addSeries: " << series << " data: " << data; |
|
177 | qDebug() << "addSeries: " << series << " data: " << data; | |
178 | m_defaultSeriesName = series; |
|
178 | m_defaultSeriesName = series; | |
179 |
|
179 | |||
180 | // TODO: a dedicated data class for storing x and y values |
|
180 | // TODO: a dedicated data class for storing x and y values | |
181 | QList<qreal> x; |
|
181 | QList<qreal> x; | |
182 | QList<qreal> y; |
|
182 | QList<qreal> y; | |
183 |
|
183 | |||
184 | QBarSet *set0 = new QBarSet; |
|
184 | QBarSet *set0 = new QBarSet; | |
185 | QBarSet *set1 = new QBarSet; |
|
185 | QBarSet *set1 = new QBarSet; | |
186 | QBarSet *set2 = new QBarSet; |
|
186 | QBarSet *set2 = new QBarSet; | |
187 | QBarSet *set3 = new QBarSet; |
|
187 | QBarSet *set3 = new QBarSet; | |
188 | QBarSet *set4 = new QBarSet; |
|
188 | QBarSet *set4 = new QBarSet; | |
189 |
|
189 | |||
190 | if (data == "linear") { |
|
190 | if (data == "linear") { | |
191 | for (int i = 0; i < 20; i++) { |
|
191 | for (int i = 0; i < 20; i++) { | |
192 | x.append(i); |
|
192 | x.append(i); | |
193 | y.append(i); |
|
193 | y.append(i); | |
194 | } |
|
194 | } | |
195 | } else if (data == "linear, 1M") { |
|
195 | } else if (data == "linear, 1M") { | |
196 | // 1 million data points from 0.0001 to 100 |
|
196 | // 1 million data points from 0.0001 to 100 | |
197 | // TODO: What is the requirement? Should we be able to show this kind of data with |
|
197 | // TODO: What is the requirement? Should we be able to show this kind of data with | |
198 | // reasonable performance, or can we expect the application developer to do "data mining" |
|
198 | // reasonable performance, or can we expect the application developer to do "data mining" | |
199 | // for us, so that the count of data points given to QtCommercial Chart is always |
|
199 | // for us, so that the count of data points given to QtCommercial Chart is always | |
200 | // reasonable? |
|
200 | // reasonable? | |
201 | for (qreal i = 0; i < 100; i += 0.0001) { |
|
201 | for (qreal i = 0; i < 100; i += 0.0001) { | |
202 | x.append(i); |
|
202 | x.append(i); | |
203 | y.append(20); |
|
203 | y.append(20); | |
204 | } |
|
204 | } | |
205 | } else if (data == "SIN") { |
|
205 | } else if (data == "SIN") { | |
206 | for (int i = 0; i < 100; i++) { |
|
206 | for (int i = 0; i < 100; i++) { | |
207 | x.append(i); |
|
207 | x.append(i); | |
208 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
208 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
209 | } |
|
209 | } | |
210 | } else if (data == "SIN + random") { |
|
210 | } else if (data == "SIN + random") { | |
211 | for (qreal i = 0; i < 100; i += 0.1) { |
|
211 | for (qreal i = 0; i < 100; i += 0.1) { | |
212 | x.append(i + (rand() % 5)); |
|
212 | x.append(i + (rand() % 5)); | |
213 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
213 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
214 | } |
|
214 | } | |
215 | } else if (data == "Table, 5 series"){ |
|
215 | } else if (data == "Table, 5 series"){ | |
216 | // Create some test data to chart |
|
216 | // Create some test data to chart | |
217 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; |
|
217 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; | |
218 | *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; |
|
218 | *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; | |
219 | *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; |
|
219 | *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; | |
220 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; |
|
220 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; | |
221 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; |
|
221 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; | |
222 | } else { |
|
222 | } else { | |
223 | // TODO: check if data has a valid file name |
|
223 | // TODO: check if data has a valid file name | |
224 | Q_ASSERT(false); |
|
224 | Q_ASSERT(false); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | // TODO: color of the series |
|
227 | // TODO: color of the series | |
228 | QChartSeries *newSeries = 0; |
|
228 | QChartSeries *newSeries = 0; | |
229 | if (series == "Scatter") { |
|
229 | if (series == "Scatter") { | |
230 | QScatterSeries *scatter = new QScatterSeries(); |
|
230 | QScatterSeries *scatter = new QScatterSeries(); | |
231 | for (int i(0); i < x.count() && i < y.count(); i++) |
|
231 | for (int i(0); i < x.count() && i < y.count(); i++) | |
232 | (*scatter) << QPointF(x.at(i), y.at(i)); |
|
232 | (*scatter) << QPointF(x.at(i), y.at(i)); | |
233 | m_chartWidget->addSeries(scatter); |
|
233 | m_chartWidget->addSeries(scatter); | |
234 | } else if (series == "Pie") { |
|
234 | } else if (series == "Pie") { | |
235 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); |
|
235 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); | |
236 | Q_ASSERT(newSeries->setData(y)); |
|
236 | Q_ASSERT(newSeries->setData(y)); | |
237 | } else if (series == "Line") { |
|
237 | } else if (series == "Line") { | |
238 | // TODO: adding data to an existing line series does not give any visuals for some reason |
|
238 | // TODO: adding data to an existing line series does not give any visuals for some reason | |
239 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); |
|
239 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); | |
240 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); |
|
240 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); | |
241 | // lineSeries->setColor(Qt::blue); |
|
241 | // lineSeries->setColor(Qt::blue); | |
242 | // for (int i(0); i < x.count() && i < y.count(); i++) { |
|
242 | // for (int i(0); i < x.count() && i < y.count(); i++) { | |
243 | // lineSeries->add(x.at(i), y.at(i)); |
|
243 | // lineSeries->add(x.at(i), y.at(i)); | |
244 | // } |
|
244 | // } | |
245 | //Q_ASSERT(newSeries->setData(x, y)); |
|
245 | //Q_ASSERT(newSeries->setData(x, y)); | |
246 | QLineChartSeries* series0 = new QLineChartSeries(); |
|
246 | QLineChartSeries* series0 = new QLineChartSeries(); | |
247 | for (int i(0); i < x.count() && i < y.count(); i++) |
|
247 | for (int i(0); i < x.count() && i < y.count(); i++) | |
248 | series0->add(x.at(i), y.at(i)); |
|
248 | series0->add(x.at(i), y.at(i)); | |
249 | m_chartWidget->addSeries(series0); |
|
249 | m_chartWidget->addSeries(series0); | |
250 | newSeries = series0; |
|
250 | newSeries = series0; | |
251 | } else if (series == "Bar") { |
|
251 | } else if (series == "Bar") { | |
252 | qDebug() << "Bar chart series"; |
|
252 | qDebug() << "Bar chart series"; | |
253 |
|
253 | |||
254 | QBarCategory *category = new QBarCategory; |
|
254 | QBarCategory *category = new QBarCategory; | |
255 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
255 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
256 |
|
256 | |||
257 | BarChartSeries* series0 = new BarChartSeries(category, this); |
|
257 | BarChartSeries* series0 = new BarChartSeries(category, this); | |
258 |
|
258 | |||
259 | series0->addBarSet(set0); |
|
259 | series0->addBarSet(set0); | |
260 | series0->addBarSet(set1); |
|
260 | series0->addBarSet(set1); | |
261 | series0->addBarSet(set2); |
|
261 | series0->addBarSet(set2); | |
262 | series0->addBarSet(set3); |
|
262 | series0->addBarSet(set3); | |
263 | series0->addBarSet(set4); |
|
263 | series0->addBarSet(set4); | |
264 |
|
264 | |||
265 | m_chartWidget->addSeries(series0); |
|
265 | m_chartWidget->addSeries(series0); | |
266 | newSeries = series0; |
|
266 | newSeries = series0; | |
267 | } else if (series == "StackedBar") { |
|
267 | } else if (series == "StackedBar") { | |
268 | qDebug() << "Stacked bar chart series"; |
|
268 | qDebug() << "Stacked bar chart series"; | |
269 |
|
269 | |||
270 | QBarCategory *category = new QBarCategory; |
|
270 | QBarCategory *category = new QBarCategory; | |
271 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
271 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
272 |
|
272 | |||
273 | StackedBarChartSeries* series0 = new StackedBarChartSeries(category, this); |
|
273 | StackedBarChartSeries* series0 = new StackedBarChartSeries(category, this); | |
274 |
|
274 | |||
275 | series0->addBarSet(set0); |
|
275 | series0->addBarSet(set0); | |
276 | series0->addBarSet(set1); |
|
276 | series0->addBarSet(set1); | |
277 | series0->addBarSet(set2); |
|
277 | series0->addBarSet(set2); | |
278 | series0->addBarSet(set3); |
|
278 | series0->addBarSet(set3); | |
279 | series0->addBarSet(set4); |
|
279 | series0->addBarSet(set4); | |
280 |
|
280 | |||
281 | m_chartWidget->addSeries(series0); |
|
281 | m_chartWidget->addSeries(series0); | |
282 | newSeries = series0; |
|
282 | newSeries = series0; | |
283 | } else if (series == "PercentBar") { |
|
283 | } else if (series == "PercentBar") { | |
284 | qDebug() << "Percent bar chart series"; |
|
284 | qDebug() << "Percent bar chart series"; | |
285 |
|
285 | |||
286 | QBarCategory *category = new QBarCategory; |
|
286 | QBarCategory *category = new QBarCategory; | |
287 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
287 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
288 |
|
288 | |||
289 | PercentBarChartSeries* series0 = new PercentBarChartSeries(category, this); |
|
289 | PercentBarChartSeries* series0 = new PercentBarChartSeries(category, this); | |
290 |
|
290 | |||
291 | series0->addBarSet(set0); |
|
291 | series0->addBarSet(set0); | |
292 | series0->addBarSet(set1); |
|
292 | series0->addBarSet(set1); | |
293 | series0->addBarSet(set2); |
|
293 | series0->addBarSet(set2); | |
294 | series0->addBarSet(set3); |
|
294 | series0->addBarSet(set3); | |
295 | series0->addBarSet(set4); |
|
295 | series0->addBarSet(set4); | |
296 |
|
296 | |||
297 | m_chartWidget->addSeries(series0); |
|
297 | m_chartWidget->addSeries(series0); | |
298 | newSeries = series0; |
|
298 | newSeries = series0; | |
299 | } else { |
|
299 | } else { | |
300 | qDebug() << "Something weird going on in MainWidget::addSeries"; |
|
300 | qDebug() << "Something weird going on in MainWidget::addSeries"; | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | setCurrentSeries(newSeries); |
|
303 | setCurrentSeries(newSeries); | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | void MainWidget::setCurrentSeries(QChartSeries *series) |
|
306 | void MainWidget::setCurrentSeries(QChartSeries *series) | |
307 | { |
|
307 | { | |
308 | if (series) { |
|
308 | if (series) { | |
309 | m_currentSeries = series; |
|
309 | m_currentSeries = series; | |
310 | switch (m_currentSeries->type()) { |
|
310 | switch (m_currentSeries->type()) { | |
311 | case QChartSeries::SeriesTypeLine: |
|
311 | case QChartSeries::SeriesTypeLine: | |
312 | break; |
|
312 | break; | |
313 | case QChartSeries::SeriesTypeScatter: |
|
313 | case QChartSeries::SeriesTypeScatter: | |
314 | break; |
|
314 | break; | |
315 | case QChartSeries::SeriesTypePie: |
|
315 | case QChartSeries::SeriesTypePie: | |
316 | break; |
|
316 | break; | |
317 | case QChartSeries::SeriesTypeBar: |
|
317 | case QChartSeries::SeriesTypeBar: | |
318 | qDebug() << "setCurrentSeries (bar)"; |
|
318 | qDebug() << "setCurrentSeries (bar)"; | |
319 | break; |
|
319 | break; | |
320 | case QChartSeries::SeriesTypeStackedBar: |
|
320 | case QChartSeries::SeriesTypeStackedBar: | |
321 | qDebug() << "setCurrentSeries (Stackedbar)"; |
|
321 | qDebug() << "setCurrentSeries (Stackedbar)"; | |
322 | break; |
|
322 | break; | |
323 | case QChartSeries::SeriesTypePercentBar: |
|
323 | case QChartSeries::SeriesTypePercentBar: | |
324 | qDebug() << "setCurrentSeries (Percentbar)"; |
|
324 | qDebug() << "setCurrentSeries (Percentbar)"; | |
325 | break; |
|
325 | break; | |
326 | default: |
|
326 | default: | |
327 | Q_ASSERT(false); |
|
327 | Q_ASSERT(false); | |
328 | break; |
|
328 | break; | |
329 | } |
|
329 | } | |
330 | } |
|
330 | } | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | void MainWidget::testDataChanged(int itemIndex) |
|
333 | void MainWidget::testDataChanged(int itemIndex) | |
334 | { |
|
334 | { | |
335 | qDebug() << "testDataChanged: " << itemIndex; |
|
335 | qDebug() << "testDataChanged: " << itemIndex; | |
336 |
|
336 | |||
337 | // switch (itemIndex) { |
|
337 | // switch (itemIndex) { | |
338 | // case 0: { |
|
338 | // case 0: { | |
339 | // QList<QChartDataPoint> data; |
|
339 | // QList<QChartDataPoint> data; | |
340 | // for (int x = 0; x < 20; x++) { |
|
340 | // for (int x = 0; x < 20; x++) { | |
341 | // data.append(QChartDataPoint() << x << x / 2); |
|
341 | // data.append(QChartDataPoint() << x << x / 2); | |
342 | // } |
|
342 | // } | |
343 | // m_chartWidget->setData(data); |
|
343 | // m_chartWidget->setData(data); | |
344 | // break; |
|
344 | // break; | |
345 | // } |
|
345 | // } | |
346 | // case 1: { |
|
346 | // case 1: { | |
347 | // QList<QChartDataPoint> data; |
|
347 | // QList<QChartDataPoint> data; | |
348 | // for (int x = 0; x < 100; x++) { |
|
348 | // for (int x = 0; x < 100; x++) { | |
349 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
349 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
350 | // } |
|
350 | // } | |
351 | // m_chartWidget->setData(data); |
|
351 | // m_chartWidget->setData(data); | |
352 | // break; |
|
352 | // break; | |
353 | // } |
|
353 | // } | |
354 | // case 2: { |
|
354 | // case 2: { | |
355 | // QList<QChartDataPoint> data; |
|
355 | // QList<QChartDataPoint> data; | |
356 | // for (int x = 0; x < 1000; x++) { |
|
356 | // for (int x = 0; x < 1000; x++) { | |
357 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
357 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
358 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
358 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
359 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
359 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
360 | // } |
|
360 | // } | |
361 | // m_chartWidget->setData(data); |
|
361 | // m_chartWidget->setData(data); | |
362 | // break; |
|
362 | // break; | |
363 | // } |
|
363 | // } | |
364 | // default: |
|
364 | // default: | |
365 | // break; |
|
365 | // break; | |
366 | // } |
|
366 | // } | |
367 | } |
|
367 | } | |
368 |
|
368 | |||
369 | void MainWidget::backgroundChanged(int itemIndex) |
|
369 | void MainWidget::backgroundChanged(int itemIndex) | |
370 | { |
|
370 | { | |
371 | qDebug() << "backgroundChanged: " << itemIndex; |
|
371 | qDebug() << "backgroundChanged: " << itemIndex; | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | void MainWidget::autoScaleChanged(int value) |
|
374 | void MainWidget::autoScaleChanged(int value) | |
375 | { |
|
375 | { | |
376 | if (value) { |
|
376 | if (value) { | |
377 | // TODO: enable auto scaling |
|
377 | // TODO: enable auto scaling | |
378 | } else { |
|
378 | } else { | |
379 | // TODO: set scaling manually (and disable auto scaling) |
|
379 | // TODO: set scaling manually (and disable auto scaling) | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | m_xMinSpin->setEnabled(!value); |
|
382 | m_xMinSpin->setEnabled(!value); | |
383 | m_xMaxSpin->setEnabled(!value); |
|
383 | m_xMaxSpin->setEnabled(!value); | |
384 | m_yMinSpin->setEnabled(!value); |
|
384 | m_yMinSpin->setEnabled(!value); | |
385 | m_yMaxSpin->setEnabled(!value); |
|
385 | m_yMaxSpin->setEnabled(!value); | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | void MainWidget::xMinChanged(int value) |
|
388 | void MainWidget::xMinChanged(int value) | |
389 | { |
|
389 | { | |
390 | qDebug() << "xMinChanged: " << value; |
|
390 | qDebug() << "xMinChanged: " << value; | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | void MainWidget::xMaxChanged(int value) |
|
393 | void MainWidget::xMaxChanged(int value) | |
394 | { |
|
394 | { | |
395 | qDebug() << "xMaxChanged: " << value; |
|
395 | qDebug() << "xMaxChanged: " << value; | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 | void MainWidget::yMinChanged(int value) |
|
398 | void MainWidget::yMinChanged(int value) | |
399 | { |
|
399 | { | |
400 | qDebug() << "yMinChanged: " << value; |
|
400 | qDebug() << "yMinChanged: " << value; | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | void MainWidget::yMaxChanged(int value) |
|
403 | void MainWidget::yMaxChanged(int value) | |
404 | { |
|
404 | { | |
405 | qDebug() << "yMaxChanged: " << value; |
|
405 | qDebug() << "yMaxChanged: " << value; | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | void MainWidget::changeChartTheme(int themeIndex) |
|
408 | void MainWidget::changeChartTheme(int themeIndex) | |
409 | { |
|
409 | { | |
410 | qDebug() << "changeChartTheme: " << themeIndex; |
|
410 | qDebug() << "changeChartTheme: " << themeIndex; | |
411 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); |
|
411 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); | |
412 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. |
|
412 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. | |
413 | QSize s = size(); |
|
413 | QSize s = size(); | |
414 | s.setWidth(s.width()+1); |
|
414 | s.setWidth(s.width()+1); | |
415 | resize(s); |
|
415 | resize(s); | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | void MainWidget::setPieSizeFactor(double size) |
|
418 | void MainWidget::setPieSizeFactor(double size) | |
419 | { |
|
419 | { | |
420 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
420 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
421 | if (pie) |
|
421 | if (pie) | |
422 | pie->setSizeFactor(qreal(size)); |
|
422 | pie->setSizeFactor(qreal(size)); | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | void MainWidget::setPiePosition(int position) |
|
425 | void MainWidget::setPiePosition(int position) | |
426 | { |
|
426 | { | |
427 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
427 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
428 | if (pie) |
|
428 | if (pie) | |
429 | pie->setPosition((QPieSeries::PiePosition) position); |
|
429 | pie->setPosition((QPieSeries::PiePosition) position); | |
430 | } |
|
430 | } |
General Comments 0
You need to be logged in to leave comments.
Login now