@@ -1,247 +1,245 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartglobal.h> |
|
3 | #include <qchartglobal.h> | |
4 | #include <qchartview.h> |
|
4 | #include <qchartview.h> | |
5 | #include <qpieseries.h> |
|
5 | #include <qpieseries.h> | |
6 | #include <qpieslice.h> |
|
6 | #include <qpieslice.h> | |
7 | #include <qbarseries.h> |
|
7 | #include <qbarseries.h> | |
8 | #include <qpercentbarseries.h> |
|
8 | #include <qpercentbarseries.h> | |
9 | #include <qstackedbarseries.h> |
|
9 | #include <qstackedbarseries.h> | |
10 | #include <qbarset.h> |
|
10 | #include <qbarset.h> | |
11 | #include <QGridLayout> |
|
11 | #include <QGridLayout> | |
12 | #include <QFormLayout> |
|
12 | #include <QFormLayout> | |
13 | #include <QComboBox> |
|
13 | #include <QComboBox> | |
14 | #include <QSpinBox> |
|
14 | #include <QSpinBox> | |
15 | #include <QCheckBox> |
|
15 | #include <QCheckBox> | |
16 | #include <QGroupBox> |
|
16 | #include <QGroupBox> | |
17 | #include <QLabel> |
|
17 | #include <QLabel> | |
18 | #include <QTime> |
|
18 | #include <QTime> | |
19 | #include <qlineseries.h> |
|
19 | #include <qlineseries.h> | |
20 | #include <qsplineseries.h> |
|
20 | #include <qsplineseries.h> | |
21 | #include <qscatterseries.h> |
|
21 | #include <qscatterseries.h> | |
22 | #include <qareaseries.h> |
|
22 | #include <qareaseries.h> | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
24 | QTCOMMERCIALCHART_USE_NAMESPACE | |
25 |
|
25 | |||
26 | typedef QPair<QPointF, QString> Data; |
|
26 | typedef QPair<QPointF, QString> Data; | |
27 | typedef QList<Data> DataList; |
|
27 | typedef QList<Data> DataList; | |
28 | typedef QList<DataList> DataTable; |
|
28 | typedef QList<DataList> DataTable; | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | class MainWidget : public QWidget |
|
31 | class MainWidget : public QWidget | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public: |
|
35 | public: | |
36 | explicit MainWidget(QWidget* parent = 0) |
|
36 | explicit MainWidget(QWidget* parent = 0) | |
37 | :QWidget(parent) |
|
37 | :QWidget(parent) | |
38 | { |
|
38 | { | |
39 | // set seed for random stuff |
|
39 | // set seed for random stuff | |
40 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
40 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
41 |
|
41 | |||
42 | // generate random data |
|
42 | // generate random data | |
43 | int listCount = 3; |
|
43 | int listCount = 3; | |
44 | int valueMax = 100; |
|
44 | int valueMax = 100; | |
45 | int valueCount = 11; |
|
45 | int valueCount = 11; | |
46 | for (int i(0); i < listCount; i++) { |
|
46 | for (int i(0); i < listCount; i++) { | |
47 | DataList dataList; |
|
47 | DataList dataList; | |
48 | for (int j(0); j < valueCount; j++) { |
|
48 | for (int j(0); j < valueCount; j++) { | |
49 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); |
|
49 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); | |
50 | QString label = QString::number(i) + ":" + QString::number(j); |
|
50 | QString label = QString::number(i) + ":" + QString::number(j); | |
51 | dataList << Data(value, label); |
|
51 | dataList << Data(value, label); | |
52 | } |
|
52 | } | |
53 | m_dataTable << dataList; |
|
53 | m_dataTable << dataList; | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | // create layout |
|
56 | // create layout | |
57 | QGridLayout* baseLayout = new QGridLayout(); |
|
57 | QGridLayout* baseLayout = new QGridLayout(); | |
58 |
|
58 | |||
59 | // settings layout |
|
59 | // settings layout | |
60 | m_themeComboBox = new QComboBox(); |
|
60 | m_themeComboBox = new QComboBox(); | |
61 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
61 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); | |
62 | m_themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
62 | m_themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
63 | m_themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
63 | m_themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
64 | m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
64 | m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
65 | m_themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
65 | m_themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
66 | m_themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
66 | m_themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
67 | m_themeComboBox->addItem("Vanilla", QChart::ChartThemeVanilla); |
|
|||
68 | m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); |
|
67 | m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); | |
69 | m_themeComboBox->addItem("Grayscale", QChart::ChartThemeGrayscale); |
|
|||
70 | m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); |
|
68 | m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); | |
71 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateTheme())); |
|
69 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateTheme())); | |
72 | QCheckBox *antialiasCheckBox = new QCheckBox("Anti aliasing"); |
|
70 | QCheckBox *antialiasCheckBox = new QCheckBox("Anti aliasing"); | |
73 | connect(antialiasCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateAntialiasing(bool))); |
|
71 | connect(antialiasCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateAntialiasing(bool))); | |
74 | QCheckBox *animatedCheckBox = new QCheckBox("Animated"); |
|
72 | QCheckBox *animatedCheckBox = new QCheckBox("Animated"); | |
75 | connect(animatedCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateAnimations(bool))); |
|
73 | connect(animatedCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateAnimations(bool))); | |
76 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
74 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
77 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
75 | settingsLayout->addWidget(new QLabel("Theme:")); | |
78 | settingsLayout->addWidget(m_themeComboBox); |
|
76 | settingsLayout->addWidget(m_themeComboBox); | |
79 | settingsLayout->addWidget(antialiasCheckBox); |
|
77 | settingsLayout->addWidget(antialiasCheckBox); | |
80 | settingsLayout->addWidget(animatedCheckBox); |
|
78 | settingsLayout->addWidget(animatedCheckBox); | |
81 | settingsLayout->addStretch(); |
|
79 | settingsLayout->addStretch(); | |
82 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
80 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
83 |
|
81 | |||
84 | // area chart |
|
82 | // area chart | |
85 | QChartView *chart = new QChartView(); |
|
83 | QChartView *chart = new QChartView(); | |
86 | chart->setChartTitle("Area chart"); |
|
84 | chart->setChartTitle("Area chart"); | |
87 | baseLayout->addWidget(chart, 1, 0); |
|
85 | baseLayout->addWidget(chart, 1, 0); | |
88 | { |
|
86 | { | |
89 | for (int i(0); i < m_dataTable.count(); i++) { |
|
87 | for (int i(0); i < m_dataTable.count(); i++) { | |
90 | QLineSeries *series1 = new QLineSeries(chart); |
|
88 | QLineSeries *series1 = new QLineSeries(chart); | |
91 | QLineSeries *series2 = new QLineSeries(chart); |
|
89 | QLineSeries *series2 = new QLineSeries(chart); | |
92 | foreach (Data data, m_dataTable[i]) { |
|
90 | foreach (Data data, m_dataTable[i]) { | |
93 | series1->add(data.first); |
|
91 | series1->add(data.first); | |
94 | series2->add(QPointF(data.first.x(), 0.0)); |
|
92 | series2->add(QPointF(data.first.x(), 0.0)); | |
95 | } |
|
93 | } | |
96 | QAreaSeries *area = new QAreaSeries(series1, series2); |
|
94 | QAreaSeries *area = new QAreaSeries(series1, series2); | |
97 | chart->addSeries(area); |
|
95 | chart->addSeries(area); | |
98 | } |
|
96 | } | |
99 | } |
|
97 | } | |
100 | m_charts << chart; |
|
98 | m_charts << chart; | |
101 |
|
99 | |||
102 | // bar chart |
|
100 | // bar chart | |
103 | chart = new QChartView(); |
|
101 | chart = new QChartView(); | |
104 | chart->setChartTitle("bar chart"); |
|
102 | chart->setChartTitle("bar chart"); | |
105 | baseLayout->addWidget(chart, 1, 1); |
|
103 | baseLayout->addWidget(chart, 1, 1); | |
106 | { |
|
104 | { | |
107 | QStringList categories; |
|
105 | QStringList categories; | |
108 | // TODO: categories |
|
106 | // TODO: categories | |
109 | for (int i(0); i < valueCount; i++) |
|
107 | for (int i(0); i < valueCount; i++) | |
110 | categories << QString::number(i); |
|
108 | categories << QString::number(i); | |
111 | // QBarSeries* series = new QBarSeries(categories, chart); |
|
109 | // QBarSeries* series = new QBarSeries(categories, chart); | |
112 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); |
|
110 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |
113 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); |
|
111 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); | |
114 | for (int i(0); i < m_dataTable.count(); i++) { |
|
112 | for (int i(0); i < m_dataTable.count(); i++) { | |
115 | QBarSet *set = new QBarSet("Set" + QString::number(i)); |
|
113 | QBarSet *set = new QBarSet("Set" + QString::number(i)); | |
116 | foreach (Data data, m_dataTable[i]) |
|
114 | foreach (Data data, m_dataTable[i]) | |
117 | *set << data.first.y(); |
|
115 | *set << data.first.y(); | |
118 | series->addBarSet(set); |
|
116 | series->addBarSet(set); | |
119 | } |
|
117 | } | |
120 | chart->addSeries(series); |
|
118 | chart->addSeries(series); | |
121 | } |
|
119 | } | |
122 | m_charts << chart; |
|
120 | m_charts << chart; | |
123 |
|
121 | |||
124 | // line chart |
|
122 | // line chart | |
125 | chart = new QChartView(); |
|
123 | chart = new QChartView(); | |
126 | chart->setChartTitle("line chart"); |
|
124 | chart->setChartTitle("line chart"); | |
127 | baseLayout->addWidget(chart, 1, 2); |
|
125 | baseLayout->addWidget(chart, 1, 2); | |
128 | foreach (DataList list, m_dataTable) { |
|
126 | foreach (DataList list, m_dataTable) { | |
129 | QLineSeries *series = new QLineSeries(chart); |
|
127 | QLineSeries *series = new QLineSeries(chart); | |
130 | foreach (Data data, list) |
|
128 | foreach (Data data, list) | |
131 | series->add(data.first); |
|
129 | series->add(data.first); | |
132 | chart->addSeries(series); |
|
130 | chart->addSeries(series); | |
133 | } |
|
131 | } | |
134 | m_charts << chart; |
|
132 | m_charts << chart; | |
135 |
|
133 | |||
136 | // pie chart |
|
134 | // pie chart | |
137 | chart = new QChartView(); |
|
135 | chart = new QChartView(); | |
138 | chart->setChartTitle("pie chart"); |
|
136 | chart->setChartTitle("pie chart"); | |
139 | baseLayout->addWidget(chart, 2, 0); |
|
137 | baseLayout->addWidget(chart, 2, 0); | |
140 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
138 | qreal pieSize = 1.0 / m_dataTable.count(); | |
141 | for (int i=0; i<m_dataTable.count(); i++) { |
|
139 | for (int i=0; i<m_dataTable.count(); i++) { | |
142 | QPieSeries *series = new QPieSeries(chart); |
|
140 | QPieSeries *series = new QPieSeries(chart); | |
143 | foreach (Data data, m_dataTable[i]) |
|
141 | foreach (Data data, m_dataTable[i]) | |
144 | series->add(data.first.y(), data.second); |
|
142 | series->add(data.first.y(), data.second); | |
145 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
143 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
146 | series->setPieSize(pieSize); |
|
144 | series->setPieSize(pieSize); | |
147 | series->setPiePosition(hPos, 0.5); |
|
145 | series->setPiePosition(hPos, 0.5); | |
148 | chart->addSeries(series); |
|
146 | chart->addSeries(series); | |
149 | } |
|
147 | } | |
150 | m_charts << chart; |
|
148 | m_charts << chart; | |
151 |
|
149 | |||
152 | // spine chart |
|
150 | // spine chart | |
153 | chart = new QChartView(); |
|
151 | chart = new QChartView(); | |
154 | chart->setChartTitle("spline chart"); |
|
152 | chart->setChartTitle("spline chart"); | |
155 | baseLayout->addWidget(chart, 2, 1); |
|
153 | baseLayout->addWidget(chart, 2, 1); | |
156 | foreach (DataList list, m_dataTable) { |
|
154 | foreach (DataList list, m_dataTable) { | |
157 | QSplineSeries *series = new QSplineSeries(chart); |
|
155 | QSplineSeries *series = new QSplineSeries(chart); | |
158 | foreach (Data data, list) |
|
156 | foreach (Data data, list) | |
159 | series->add(data.first); |
|
157 | series->add(data.first); | |
160 | chart->addSeries(series); |
|
158 | chart->addSeries(series); | |
161 | } |
|
159 | } | |
162 | m_charts << chart; |
|
160 | m_charts << chart; | |
163 |
|
161 | |||
164 | // scatter chart |
|
162 | // scatter chart | |
165 | chart = new QChartView(); |
|
163 | chart = new QChartView(); | |
166 | chart->setChartTitle("scatter chart"); |
|
164 | chart->setChartTitle("scatter chart"); | |
167 | baseLayout->addWidget(chart, 2, 2); |
|
165 | baseLayout->addWidget(chart, 2, 2); | |
168 | foreach (DataList list, m_dataTable) { |
|
166 | foreach (DataList list, m_dataTable) { | |
169 | QScatterSeries *series = new QScatterSeries(chart); |
|
167 | QScatterSeries *series = new QScatterSeries(chart); | |
170 | foreach (Data data, list) |
|
168 | foreach (Data data, list) | |
171 | series->add(data.first); |
|
169 | series->add(data.first); | |
172 | chart->addSeries(series); |
|
170 | chart->addSeries(series); | |
173 | } |
|
171 | } | |
174 | m_charts << chart; |
|
172 | m_charts << chart; | |
175 |
|
173 | |||
176 | setLayout(baseLayout); |
|
174 | setLayout(baseLayout); | |
177 | } |
|
175 | } | |
178 |
|
176 | |||
179 | public Q_SLOTS: |
|
177 | public Q_SLOTS: | |
180 |
|
178 | |||
181 | void updateTheme() |
|
179 | void updateTheme() | |
182 | { |
|
180 | { | |
183 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
181 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
184 | foreach (QChartView *chart, m_charts) |
|
182 | foreach (QChartView *chart, m_charts) | |
185 | chart->setChartTheme(theme); |
|
183 | chart->setChartTheme(theme); | |
186 |
|
184 | |||
187 | QPalette pal = window()->palette(); |
|
185 | QPalette pal = window()->palette(); | |
188 | if (theme == QChart::ChartThemeLight) { |
|
186 | if (theme == QChart::ChartThemeLight) { | |
189 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
187 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
190 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
188 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
191 | } else if (theme == QChart::ChartThemeDark) { |
|
189 | } else if (theme == QChart::ChartThemeDark) { | |
192 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
190 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
193 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
191 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
194 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
192 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
195 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
193 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
196 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
194 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
197 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
195 | } else if (theme == QChart::ChartThemeBrownSand) { | |
198 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
196 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
199 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
197 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
200 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
198 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
201 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
199 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
202 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
200 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
203 | } else { |
|
201 | } else { | |
204 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
202 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
205 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
203 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
206 | } |
|
204 | } | |
207 | window()->setPalette(pal); |
|
205 | window()->setPalette(pal); | |
208 | } |
|
206 | } | |
209 |
|
207 | |||
210 | void updateAntialiasing(bool enabled) |
|
208 | void updateAntialiasing(bool enabled) | |
211 | { |
|
209 | { | |
212 | foreach (QChartView *chart, m_charts) |
|
210 | foreach (QChartView *chart, m_charts) | |
213 | chart->setRenderHint(QPainter::Antialiasing, enabled); |
|
211 | chart->setRenderHint(QPainter::Antialiasing, enabled); | |
214 | } |
|
212 | } | |
215 |
|
213 | |||
216 | void updateAnimations(bool animated) |
|
214 | void updateAnimations(bool animated) | |
217 | { |
|
215 | { | |
218 | QChart::AnimationOptions options = QChart::NoAnimation; |
|
216 | QChart::AnimationOptions options = QChart::NoAnimation; | |
219 | if (animated) |
|
217 | if (animated) | |
220 | options = QChart::AllAnimations; |
|
218 | options = QChart::AllAnimations; | |
221 |
|
219 | |||
222 | foreach (QChartView *chart, m_charts) |
|
220 | foreach (QChartView *chart, m_charts) | |
223 | chart->setAnimationOptions(options); |
|
221 | chart->setAnimationOptions(options); | |
224 | } |
|
222 | } | |
225 |
|
223 | |||
226 | private: |
|
224 | private: | |
227 | QList<QChartView*> m_charts; |
|
225 | QList<QChartView*> m_charts; | |
228 | QComboBox *m_themeComboBox; |
|
226 | QComboBox *m_themeComboBox; | |
229 | DataTable m_dataTable; |
|
227 | DataTable m_dataTable; | |
230 | }; |
|
228 | }; | |
231 |
|
229 | |||
232 | int main(int argc, char *argv[]) |
|
230 | int main(int argc, char *argv[]) | |
233 | { |
|
231 | { | |
234 | QApplication a(argc, argv); |
|
232 | QApplication a(argc, argv); | |
235 |
|
233 | |||
236 | QMainWindow window; |
|
234 | QMainWindow window; | |
237 |
|
235 | |||
238 | MainWidget* widget = new MainWidget(); |
|
236 | MainWidget* widget = new MainWidget(); | |
239 |
|
237 | |||
240 | window.setCentralWidget(widget); |
|
238 | window.setCentralWidget(widget); | |
241 | window.resize(900, 600); |
|
239 | window.resize(900, 600); | |
242 | window.show(); |
|
240 | window.show(); | |
243 |
|
241 | |||
244 | return a.exec(); |
|
242 | return a.exec(); | |
245 | } |
|
243 | } | |
246 |
|
244 | |||
247 | #include "main.moc" |
|
245 | #include "main.moc" |
@@ -1,610 +1,608 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartglobal.h> |
|
3 | #include <qchartglobal.h> | |
4 | #include <qchartview.h> |
|
4 | #include <qchartview.h> | |
5 | #include <qpieseries.h> |
|
5 | #include <qpieseries.h> | |
6 | #include <qpieslice.h> |
|
6 | #include <qpieslice.h> | |
7 | #include <QGridLayout> |
|
7 | #include <QGridLayout> | |
8 | #include <QFormLayout> |
|
8 | #include <QFormLayout> | |
9 | #include <QComboBox> |
|
9 | #include <QComboBox> | |
10 | #include <QSpinBox> |
|
10 | #include <QSpinBox> | |
11 | #include <QCheckBox> |
|
11 | #include <QCheckBox> | |
12 | #include <QGroupBox> |
|
12 | #include <QGroupBox> | |
13 | #include <QLabel> |
|
13 | #include <QLabel> | |
14 | #include <QPushButton> |
|
14 | #include <QPushButton> | |
15 | #include <QColorDialog> |
|
15 | #include <QColorDialog> | |
16 | #include <QFontDialog> |
|
16 | #include <QFontDialog> | |
17 |
|
17 | |||
18 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
18 | QTCOMMERCIALCHART_USE_NAMESPACE | |
19 |
|
19 | |||
20 | class PenTool : public QWidget |
|
20 | class PenTool : public QWidget | |
21 | { |
|
21 | { | |
22 | Q_OBJECT |
|
22 | Q_OBJECT | |
23 |
|
23 | |||
24 | public: |
|
24 | public: | |
25 | explicit PenTool(QString title, QWidget *parent = 0) |
|
25 | explicit PenTool(QString title, QWidget *parent = 0) | |
26 | :QWidget(parent) |
|
26 | :QWidget(parent) | |
27 | { |
|
27 | { | |
28 | setWindowTitle(title); |
|
28 | setWindowTitle(title); | |
29 | setWindowFlags(Qt::Tool); |
|
29 | setWindowFlags(Qt::Tool); | |
30 |
|
30 | |||
31 | m_colorButton = new QPushButton(); |
|
31 | m_colorButton = new QPushButton(); | |
32 |
|
32 | |||
33 | m_widthSpinBox = new QDoubleSpinBox(); |
|
33 | m_widthSpinBox = new QDoubleSpinBox(); | |
34 |
|
34 | |||
35 | m_styleCombo = new QComboBox(); |
|
35 | m_styleCombo = new QComboBox(); | |
36 | m_styleCombo->addItem("NoPen"); |
|
36 | m_styleCombo->addItem("NoPen"); | |
37 | m_styleCombo->addItem("SolidLine"); |
|
37 | m_styleCombo->addItem("SolidLine"); | |
38 | m_styleCombo->addItem("DashLine"); |
|
38 | m_styleCombo->addItem("DashLine"); | |
39 | m_styleCombo->addItem("DotLine"); |
|
39 | m_styleCombo->addItem("DotLine"); | |
40 | m_styleCombo->addItem("DashDotLine"); |
|
40 | m_styleCombo->addItem("DashDotLine"); | |
41 | m_styleCombo->addItem("DashDotDotLine"); |
|
41 | m_styleCombo->addItem("DashDotDotLine"); | |
42 |
|
42 | |||
43 | m_capStyleCombo = new QComboBox(); |
|
43 | m_capStyleCombo = new QComboBox(); | |
44 | m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); |
|
44 | m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); | |
45 | m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); |
|
45 | m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); | |
46 | m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); |
|
46 | m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); | |
47 |
|
47 | |||
48 | m_joinStyleCombo = new QComboBox(); |
|
48 | m_joinStyleCombo = new QComboBox(); | |
49 | m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); |
|
49 | m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); | |
50 | m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); |
|
50 | m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); | |
51 | m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); |
|
51 | m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); | |
52 | m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); |
|
52 | m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); | |
53 |
|
53 | |||
54 | QFormLayout *layout = new QFormLayout(); |
|
54 | QFormLayout *layout = new QFormLayout(); | |
55 | layout->addRow("Color", m_colorButton); |
|
55 | layout->addRow("Color", m_colorButton); | |
56 | layout->addRow("Width", m_widthSpinBox); |
|
56 | layout->addRow("Width", m_widthSpinBox); | |
57 | layout->addRow("Style", m_styleCombo); |
|
57 | layout->addRow("Style", m_styleCombo); | |
58 | layout->addRow("Cap style", m_capStyleCombo); |
|
58 | layout->addRow("Cap style", m_capStyleCombo); | |
59 | layout->addRow("Join style", m_joinStyleCombo); |
|
59 | layout->addRow("Join style", m_joinStyleCombo); | |
60 | setLayout(layout); |
|
60 | setLayout(layout); | |
61 |
|
61 | |||
62 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); |
|
62 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); | |
63 | connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); |
|
63 | connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); | |
64 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); |
|
64 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); | |
65 | connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); |
|
65 | connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); | |
66 | connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); |
|
66 | connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void setPen(QPen pen) |
|
69 | void setPen(QPen pen) | |
70 | { |
|
70 | { | |
71 | m_pen = pen; |
|
71 | m_pen = pen; | |
72 | m_colorButton->setText(m_pen.color().name()); |
|
72 | m_colorButton->setText(m_pen.color().name()); | |
73 | m_widthSpinBox->setValue(m_pen.widthF()); |
|
73 | m_widthSpinBox->setValue(m_pen.widthF()); | |
74 | m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum |
|
74 | m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum | |
75 | m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); |
|
75 | m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); | |
76 | m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); |
|
76 | m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | QPen pen() const |
|
79 | QPen pen() const | |
80 | { |
|
80 | { | |
81 | return m_pen; |
|
81 | return m_pen; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | QString name() |
|
84 | QString name() | |
85 | { |
|
85 | { | |
86 | return name(m_pen); |
|
86 | return name(m_pen); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | static QString name(const QPen &pen) |
|
89 | static QString name(const QPen &pen) | |
90 | { |
|
90 | { | |
91 | return pen.color().name() + ":" + QString::number(pen.widthF()); |
|
91 | return pen.color().name() + ":" + QString::number(pen.widthF()); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | Q_SIGNALS: |
|
94 | Q_SIGNALS: | |
95 | void changed(); |
|
95 | void changed(); | |
96 |
|
96 | |||
97 | public Q_SLOTS: |
|
97 | public Q_SLOTS: | |
98 |
|
98 | |||
99 | void showColorDialog() |
|
99 | void showColorDialog() | |
100 | { |
|
100 | { | |
101 | QColorDialog dialog(m_pen.color()); |
|
101 | QColorDialog dialog(m_pen.color()); | |
102 | dialog.show(); |
|
102 | dialog.show(); | |
103 | dialog.exec(); |
|
103 | dialog.exec(); | |
104 | m_pen.setColor(dialog.selectedColor()); |
|
104 | m_pen.setColor(dialog.selectedColor()); | |
105 | m_colorButton->setText(m_pen.color().name()); |
|
105 | m_colorButton->setText(m_pen.color().name()); | |
106 | emit changed(); |
|
106 | emit changed(); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void updateWidth(double width) |
|
109 | void updateWidth(double width) | |
110 | { |
|
110 | { | |
111 | if (width != m_pen.widthF()) { |
|
111 | if (width != m_pen.widthF()) { | |
112 | m_pen.setWidthF(width); |
|
112 | m_pen.setWidthF(width); | |
113 | emit changed(); |
|
113 | emit changed(); | |
114 | } |
|
114 | } | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void updateStyle(int style) |
|
117 | void updateStyle(int style) | |
118 | { |
|
118 | { | |
119 | if (m_pen.style() != style) { |
|
119 | if (m_pen.style() != style) { | |
120 | m_pen.setStyle((Qt::PenStyle) style); |
|
120 | m_pen.setStyle((Qt::PenStyle) style); | |
121 | emit changed(); |
|
121 | emit changed(); | |
122 | } |
|
122 | } | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | void updateCapStyle(int index) |
|
125 | void updateCapStyle(int index) | |
126 | { |
|
126 | { | |
127 | Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); |
|
127 | Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); | |
128 | if (m_pen.capStyle() != capStyle) { |
|
128 | if (m_pen.capStyle() != capStyle) { | |
129 | m_pen.setCapStyle(capStyle); |
|
129 | m_pen.setCapStyle(capStyle); | |
130 | emit changed(); |
|
130 | emit changed(); | |
131 | } |
|
131 | } | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | void updateJoinStyle(int index) |
|
134 | void updateJoinStyle(int index) | |
135 | { |
|
135 | { | |
136 | Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); |
|
136 | Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); | |
137 | if (m_pen.joinStyle() != joinStyle) { |
|
137 | if (m_pen.joinStyle() != joinStyle) { | |
138 | m_pen.setJoinStyle(joinStyle); |
|
138 | m_pen.setJoinStyle(joinStyle); | |
139 | emit changed(); |
|
139 | emit changed(); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | private: |
|
143 | private: | |
144 | QPen m_pen; |
|
144 | QPen m_pen; | |
145 | QPushButton *m_colorButton; |
|
145 | QPushButton *m_colorButton; | |
146 | QDoubleSpinBox *m_widthSpinBox; |
|
146 | QDoubleSpinBox *m_widthSpinBox; | |
147 | QComboBox *m_styleCombo; |
|
147 | QComboBox *m_styleCombo; | |
148 | QComboBox *m_capStyleCombo; |
|
148 | QComboBox *m_capStyleCombo; | |
149 | QComboBox *m_joinStyleCombo; |
|
149 | QComboBox *m_joinStyleCombo; | |
150 | }; |
|
150 | }; | |
151 |
|
151 | |||
152 | class BrushTool : public QWidget |
|
152 | class BrushTool : public QWidget | |
153 | { |
|
153 | { | |
154 | Q_OBJECT |
|
154 | Q_OBJECT | |
155 |
|
155 | |||
156 | public: |
|
156 | public: | |
157 | explicit BrushTool(QString title, QWidget *parent = 0) |
|
157 | explicit BrushTool(QString title, QWidget *parent = 0) | |
158 | :QWidget(parent) |
|
158 | :QWidget(parent) | |
159 | { |
|
159 | { | |
160 | setWindowTitle(title); |
|
160 | setWindowTitle(title); | |
161 | setWindowFlags(Qt::Tool); |
|
161 | setWindowFlags(Qt::Tool); | |
162 |
|
162 | |||
163 | m_colorButton = new QPushButton(); |
|
163 | m_colorButton = new QPushButton(); | |
164 | m_styleCombo = new QComboBox(); |
|
164 | m_styleCombo = new QComboBox(); | |
165 | m_styleCombo->addItem("Nobrush", Qt::NoBrush); |
|
165 | m_styleCombo->addItem("Nobrush", Qt::NoBrush); | |
166 | m_styleCombo->addItem("Solidpattern", Qt::SolidPattern); |
|
166 | m_styleCombo->addItem("Solidpattern", Qt::SolidPattern); | |
167 | m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern); |
|
167 | m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern); | |
168 | m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern); |
|
168 | m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern); | |
169 | m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern); |
|
169 | m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern); | |
170 | m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern); |
|
170 | m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern); | |
171 | m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern); |
|
171 | m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern); | |
172 | m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern); |
|
172 | m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern); | |
173 | m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern); |
|
173 | m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern); | |
174 | m_styleCombo->addItem("HorPattern", Qt::HorPattern); |
|
174 | m_styleCombo->addItem("HorPattern", Qt::HorPattern); | |
175 | m_styleCombo->addItem("VerPattern", Qt::VerPattern); |
|
175 | m_styleCombo->addItem("VerPattern", Qt::VerPattern); | |
176 | m_styleCombo->addItem("CrossPattern", Qt::CrossPattern); |
|
176 | m_styleCombo->addItem("CrossPattern", Qt::CrossPattern); | |
177 | m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern); |
|
177 | m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern); | |
178 | m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern); |
|
178 | m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern); | |
179 | m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern); |
|
179 | m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern); | |
180 |
|
180 | |||
181 | QFormLayout *layout = new QFormLayout(); |
|
181 | QFormLayout *layout = new QFormLayout(); | |
182 | layout->addRow("Color", m_colorButton); |
|
182 | layout->addRow("Color", m_colorButton); | |
183 | layout->addRow("Style", m_styleCombo); |
|
183 | layout->addRow("Style", m_styleCombo); | |
184 | setLayout(layout); |
|
184 | setLayout(layout); | |
185 |
|
185 | |||
186 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); |
|
186 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); | |
187 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle())); |
|
187 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle())); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | void setBrush(QBrush brush) |
|
190 | void setBrush(QBrush brush) | |
191 | { |
|
191 | { | |
192 | m_brush = brush; |
|
192 | m_brush = brush; | |
193 | m_colorButton->setText(m_brush.color().name()); |
|
193 | m_colorButton->setText(m_brush.color().name()); | |
194 | m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum |
|
194 | m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | QBrush brush() const |
|
197 | QBrush brush() const | |
198 | { |
|
198 | { | |
199 | return m_brush; |
|
199 | return m_brush; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | QString name() |
|
202 | QString name() | |
203 | { |
|
203 | { | |
204 | return name(m_brush); |
|
204 | return name(m_brush); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | static QString name(const QBrush &brush) |
|
207 | static QString name(const QBrush &brush) | |
208 | { |
|
208 | { | |
209 | return brush.color().name(); |
|
209 | return brush.color().name(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | Q_SIGNALS: |
|
212 | Q_SIGNALS: | |
213 | void changed(); |
|
213 | void changed(); | |
214 |
|
214 | |||
215 | public Q_SLOTS: |
|
215 | public Q_SLOTS: | |
216 |
|
216 | |||
217 | void showColorDialog() |
|
217 | void showColorDialog() | |
218 | { |
|
218 | { | |
219 | QColorDialog dialog(m_brush.color()); |
|
219 | QColorDialog dialog(m_brush.color()); | |
220 | dialog.show(); |
|
220 | dialog.show(); | |
221 | dialog.exec(); |
|
221 | dialog.exec(); | |
222 | m_brush.setColor(dialog.selectedColor()); |
|
222 | m_brush.setColor(dialog.selectedColor()); | |
223 | m_colorButton->setText(m_brush.color().name()); |
|
223 | m_colorButton->setText(m_brush.color().name()); | |
224 | emit changed(); |
|
224 | emit changed(); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | void updateStyle() |
|
227 | void updateStyle() | |
228 | { |
|
228 | { | |
229 | Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt(); |
|
229 | Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt(); | |
230 | if (m_brush.style() != style) { |
|
230 | if (m_brush.style() != style) { | |
231 | m_brush.setStyle(style); |
|
231 | m_brush.setStyle(style); | |
232 | emit changed(); |
|
232 | emit changed(); | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | private: |
|
236 | private: | |
237 | QBrush m_brush; |
|
237 | QBrush m_brush; | |
238 | QPushButton *m_colorButton; |
|
238 | QPushButton *m_colorButton; | |
239 | QComboBox *m_styleCombo; |
|
239 | QComboBox *m_styleCombo; | |
240 | }; |
|
240 | }; | |
241 |
|
241 | |||
242 | class CustomSlice : public QPieSlice |
|
242 | class CustomSlice : public QPieSlice | |
243 | { |
|
243 | { | |
244 | Q_OBJECT |
|
244 | Q_OBJECT | |
245 | public: |
|
245 | public: | |
246 | CustomSlice(qreal value, QString label) |
|
246 | CustomSlice(qreal value, QString label) | |
247 | :QPieSlice(value, label) |
|
247 | :QPieSlice(value, label) | |
248 | { |
|
248 | { | |
249 | connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter())); |
|
249 | connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter())); | |
250 | connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave())); |
|
250 | connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave())); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | public: |
|
253 | public: | |
254 | QBrush originalBrush() |
|
254 | QBrush originalBrush() | |
255 | { |
|
255 | { | |
256 | return m_originalBrush; |
|
256 | return m_originalBrush; | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | public Q_SLOTS: |
|
259 | public Q_SLOTS: | |
260 |
|
260 | |||
261 | void handleHoverEnter() |
|
261 | void handleHoverEnter() | |
262 | { |
|
262 | { | |
263 | QBrush brush = this->sliceBrush(); |
|
263 | QBrush brush = this->sliceBrush(); | |
264 | m_originalBrush = brush; |
|
264 | m_originalBrush = brush; | |
265 | brush.setColor(brush.color().lighter()); |
|
265 | brush.setColor(brush.color().lighter()); | |
266 | setSliceBrush(brush); |
|
266 | setSliceBrush(brush); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | void handleHoverLeave() |
|
269 | void handleHoverLeave() | |
270 | { |
|
270 | { | |
271 | setSliceBrush(m_originalBrush); |
|
271 | setSliceBrush(m_originalBrush); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | private: |
|
274 | private: | |
275 | QBrush m_originalBrush; |
|
275 | QBrush m_originalBrush; | |
276 | }; |
|
276 | }; | |
277 |
|
277 | |||
278 | class MainWidget : public QWidget |
|
278 | class MainWidget : public QWidget | |
279 | { |
|
279 | { | |
280 | Q_OBJECT |
|
280 | Q_OBJECT | |
281 |
|
281 | |||
282 | public: |
|
282 | public: | |
283 | explicit MainWidget(QWidget* parent = 0) |
|
283 | explicit MainWidget(QWidget* parent = 0) | |
284 | :QWidget(parent), |
|
284 | :QWidget(parent), | |
285 | m_slice(0) |
|
285 | m_slice(0) | |
286 | { |
|
286 | { | |
287 | // create chart |
|
287 | // create chart | |
288 | m_chartView = new QChartView(); |
|
288 | m_chartView = new QChartView(); | |
289 | m_chartView->setChartTitle("Piechart customization"); |
|
289 | m_chartView->setChartTitle("Piechart customization"); | |
290 | m_chartView->setAnimationOptions(QChart::AllAnimations); |
|
290 | m_chartView->setAnimationOptions(QChart::AllAnimations); | |
291 |
|
291 | |||
292 | // create series |
|
292 | // create series | |
293 | m_series = new QPieSeries(); |
|
293 | m_series = new QPieSeries(); | |
294 | *m_series << new CustomSlice(10.0, "Slice 1"); |
|
294 | *m_series << new CustomSlice(10.0, "Slice 1"); | |
295 | *m_series << new CustomSlice(20.0, "Slice 2"); |
|
295 | *m_series << new CustomSlice(20.0, "Slice 2"); | |
296 | *m_series << new CustomSlice(30.0, "Slice 3"); |
|
296 | *m_series << new CustomSlice(30.0, "Slice 3"); | |
297 | *m_series << new CustomSlice(40.0, "Slice 4"); |
|
297 | *m_series << new CustomSlice(40.0, "Slice 4"); | |
298 | *m_series << new CustomSlice(50.0, "Slice 5"); |
|
298 | *m_series << new CustomSlice(50.0, "Slice 5"); | |
299 | m_chartView->addSeries(m_series); |
|
299 | m_chartView->addSeries(m_series); | |
300 |
|
300 | |||
301 | connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*))); |
|
301 | connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*))); | |
302 |
|
302 | |||
303 | // chart settings |
|
303 | // chart settings | |
304 | m_themeComboBox = new QComboBox(); |
|
304 | m_themeComboBox = new QComboBox(); | |
305 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
305 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); | |
306 | m_themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
306 | m_themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
307 | m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean); |
|
307 | m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean); | |
308 | m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
308 | m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
309 | m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand); |
|
309 | m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand); | |
310 | m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs); |
|
310 | m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs); | |
311 | m_themeComboBox->addItem("Vanilla", QChart::ChartThemeVanilla); |
|
|||
312 | m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); |
|
311 | m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); | |
313 | m_themeComboBox->addItem("Grayscale", QChart::ChartThemeGrayscale); |
|
|||
314 | m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); |
|
312 | m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); | |
315 |
|
313 | |||
316 | m_aaCheckBox = new QCheckBox(); |
|
314 | m_aaCheckBox = new QCheckBox(); | |
317 | m_animationsCheckBox = new QCheckBox(); |
|
315 | m_animationsCheckBox = new QCheckBox(); | |
318 | m_animationsCheckBox->setCheckState(Qt::Checked); |
|
316 | m_animationsCheckBox->setCheckState(Qt::Checked); | |
319 |
|
317 | |||
320 | QFormLayout* chartSettingsLayout = new QFormLayout(); |
|
318 | QFormLayout* chartSettingsLayout = new QFormLayout(); | |
321 | chartSettingsLayout->addRow("Theme", m_themeComboBox); |
|
319 | chartSettingsLayout->addRow("Theme", m_themeComboBox); | |
322 | chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); |
|
320 | chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); | |
323 | chartSettingsLayout->addRow("Animations", m_animationsCheckBox); |
|
321 | chartSettingsLayout->addRow("Animations", m_animationsCheckBox); | |
324 | QGroupBox* chartSettings = new QGroupBox("Chart"); |
|
322 | QGroupBox* chartSettings = new QGroupBox("Chart"); | |
325 | chartSettings->setLayout(chartSettingsLayout); |
|
323 | chartSettings->setLayout(chartSettingsLayout); | |
326 |
|
324 | |||
327 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings())); |
|
325 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings())); | |
328 | connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); |
|
326 | connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); | |
329 | connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); |
|
327 | connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); | |
330 |
|
328 | |||
331 | // series settings |
|
329 | // series settings | |
332 | m_hPosition = new QDoubleSpinBox(); |
|
330 | m_hPosition = new QDoubleSpinBox(); | |
333 | m_hPosition->setMinimum(0.0); |
|
331 | m_hPosition->setMinimum(0.0); | |
334 | m_hPosition->setMaximum(1.0); |
|
332 | m_hPosition->setMaximum(1.0); | |
335 | m_hPosition->setSingleStep(0.1); |
|
333 | m_hPosition->setSingleStep(0.1); | |
336 | m_hPosition->setValue(m_series->pieHorizontalPosition()); |
|
334 | m_hPosition->setValue(m_series->pieHorizontalPosition()); | |
337 |
|
335 | |||
338 | m_vPosition = new QDoubleSpinBox(); |
|
336 | m_vPosition = new QDoubleSpinBox(); | |
339 | m_vPosition->setMinimum(0.0); |
|
337 | m_vPosition->setMinimum(0.0); | |
340 | m_vPosition->setMaximum(1.0); |
|
338 | m_vPosition->setMaximum(1.0); | |
341 | m_vPosition->setSingleStep(0.1); |
|
339 | m_vPosition->setSingleStep(0.1); | |
342 | m_vPosition->setValue(m_series->pieVerticalPosition()); |
|
340 | m_vPosition->setValue(m_series->pieVerticalPosition()); | |
343 |
|
341 | |||
344 | m_sizeFactor = new QDoubleSpinBox(); |
|
342 | m_sizeFactor = new QDoubleSpinBox(); | |
345 | m_sizeFactor->setMinimum(0.0); |
|
343 | m_sizeFactor->setMinimum(0.0); | |
346 | m_sizeFactor->setMaximum(1.0); |
|
344 | m_sizeFactor->setMaximum(1.0); | |
347 | m_sizeFactor->setSingleStep(0.1); |
|
345 | m_sizeFactor->setSingleStep(0.1); | |
348 | m_sizeFactor->setValue(m_series->pieSize()); |
|
346 | m_sizeFactor->setValue(m_series->pieSize()); | |
349 |
|
347 | |||
350 | m_startAngle = new QDoubleSpinBox(); |
|
348 | m_startAngle = new QDoubleSpinBox(); | |
351 | m_startAngle->setMinimum(0.0); |
|
349 | m_startAngle->setMinimum(0.0); | |
352 | m_startAngle->setMaximum(360); |
|
350 | m_startAngle->setMaximum(360); | |
353 | m_startAngle->setValue(m_series->pieStartAngle()); |
|
351 | m_startAngle->setValue(m_series->pieStartAngle()); | |
354 | m_startAngle->setSingleStep(1); |
|
352 | m_startAngle->setSingleStep(1); | |
355 |
|
353 | |||
356 | m_endAngle = new QDoubleSpinBox(); |
|
354 | m_endAngle = new QDoubleSpinBox(); | |
357 | m_endAngle->setMinimum(0.0); |
|
355 | m_endAngle->setMinimum(0.0); | |
358 | m_endAngle->setMaximum(360); |
|
356 | m_endAngle->setMaximum(360); | |
359 | m_endAngle->setValue(m_series->pieEndAngle()); |
|
357 | m_endAngle->setValue(m_series->pieEndAngle()); | |
360 | m_endAngle->setSingleStep(1); |
|
358 | m_endAngle->setSingleStep(1); | |
361 |
|
359 | |||
362 | QPushButton *addSlice = new QPushButton("Add slice"); |
|
360 | QPushButton *addSlice = new QPushButton("Add slice"); | |
363 | QPushButton *insertSlice = new QPushButton("Insert slice"); |
|
361 | QPushButton *insertSlice = new QPushButton("Insert slice"); | |
364 |
|
362 | |||
365 | QFormLayout* seriesSettingsLayout = new QFormLayout(); |
|
363 | QFormLayout* seriesSettingsLayout = new QFormLayout(); | |
366 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); |
|
364 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); | |
367 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); |
|
365 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); | |
368 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); |
|
366 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); | |
369 | seriesSettingsLayout->addRow("Start angle", m_startAngle); |
|
367 | seriesSettingsLayout->addRow("Start angle", m_startAngle); | |
370 | seriesSettingsLayout->addRow("End angle", m_endAngle); |
|
368 | seriesSettingsLayout->addRow("End angle", m_endAngle); | |
371 | seriesSettingsLayout->addRow(addSlice); |
|
369 | seriesSettingsLayout->addRow(addSlice); | |
372 | seriesSettingsLayout->addRow(insertSlice); |
|
370 | seriesSettingsLayout->addRow(insertSlice); | |
373 | QGroupBox* seriesSettings = new QGroupBox("Series"); |
|
371 | QGroupBox* seriesSettings = new QGroupBox("Series"); | |
374 | seriesSettings->setLayout(seriesSettingsLayout); |
|
372 | seriesSettings->setLayout(seriesSettingsLayout); | |
375 |
|
373 | |||
376 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
374 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
377 | connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
375 | connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
378 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
376 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
379 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
377 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
380 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
378 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
381 | connect(addSlice, SIGNAL(clicked()), this, SLOT(addSlice())); |
|
379 | connect(addSlice, SIGNAL(clicked()), this, SLOT(addSlice())); | |
382 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); |
|
380 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); | |
383 |
|
381 | |||
384 | // slice settings |
|
382 | // slice settings | |
385 | m_sliceName = new QLabel("<click a slice>"); |
|
383 | m_sliceName = new QLabel("<click a slice>"); | |
386 | m_sliceValue = new QDoubleSpinBox(); |
|
384 | m_sliceValue = new QDoubleSpinBox(); | |
387 | m_sliceValue->setMaximum(1000); |
|
385 | m_sliceValue->setMaximum(1000); | |
388 | m_sliceLabelVisible = new QCheckBox(); |
|
386 | m_sliceLabelVisible = new QCheckBox(); | |
389 | m_sliceLabelArmFactor = new QDoubleSpinBox(); |
|
387 | m_sliceLabelArmFactor = new QDoubleSpinBox(); | |
390 | m_sliceLabelArmFactor->setSingleStep(0.01); |
|
388 | m_sliceLabelArmFactor->setSingleStep(0.01); | |
391 | m_sliceExploded = new QCheckBox(); |
|
389 | m_sliceExploded = new QCheckBox(); | |
392 | m_sliceExplodedFactor = new QDoubleSpinBox(); |
|
390 | m_sliceExplodedFactor = new QDoubleSpinBox(); | |
393 | m_sliceExplodedFactor->setSingleStep(0.01); |
|
391 | m_sliceExplodedFactor->setSingleStep(0.01); | |
394 | m_pen = new QPushButton(); |
|
392 | m_pen = new QPushButton(); | |
395 | m_penTool = new PenTool("Slice pen", this); |
|
393 | m_penTool = new PenTool("Slice pen", this); | |
396 | m_brush = new QPushButton(); |
|
394 | m_brush = new QPushButton(); | |
397 | m_brushTool = new BrushTool("Slice brush", this); |
|
395 | m_brushTool = new BrushTool("Slice brush", this); | |
398 | m_font = new QPushButton(); |
|
396 | m_font = new QPushButton(); | |
399 | m_labelArmPen = new QPushButton(); |
|
397 | m_labelArmPen = new QPushButton(); | |
400 | m_labelArmPenTool = new PenTool("Label arm pen", this); |
|
398 | m_labelArmPenTool = new PenTool("Label arm pen", this); | |
401 | QPushButton *removeSlice = new QPushButton("Remove slice"); |
|
399 | QPushButton *removeSlice = new QPushButton("Remove slice"); | |
402 |
|
400 | |||
403 | QFormLayout* sliceSettingsLayout = new QFormLayout(); |
|
401 | QFormLayout* sliceSettingsLayout = new QFormLayout(); | |
404 | sliceSettingsLayout->addRow("Selected", m_sliceName); |
|
402 | sliceSettingsLayout->addRow("Selected", m_sliceName); | |
405 | sliceSettingsLayout->addRow("Value", m_sliceValue); |
|
403 | sliceSettingsLayout->addRow("Value", m_sliceValue); | |
406 | sliceSettingsLayout->addRow("Pen", m_pen); |
|
404 | sliceSettingsLayout->addRow("Pen", m_pen); | |
407 | sliceSettingsLayout->addRow("Brush", m_brush); |
|
405 | sliceSettingsLayout->addRow("Brush", m_brush); | |
408 | sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); |
|
406 | sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); | |
409 | sliceSettingsLayout->addRow("Label font", m_font); |
|
407 | sliceSettingsLayout->addRow("Label font", m_font); | |
410 | sliceSettingsLayout->addRow("Label arm pen", m_labelArmPen); |
|
408 | sliceSettingsLayout->addRow("Label arm pen", m_labelArmPen); | |
411 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); |
|
409 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); | |
412 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); |
|
410 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); | |
413 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); |
|
411 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); | |
414 | sliceSettingsLayout->addRow(removeSlice); |
|
412 | sliceSettingsLayout->addRow(removeSlice); | |
415 | QGroupBox* sliceSettings = new QGroupBox("Slice"); |
|
413 | QGroupBox* sliceSettings = new QGroupBox("Slice"); | |
416 | sliceSettings->setLayout(sliceSettingsLayout); |
|
414 | sliceSettings->setLayout(sliceSettingsLayout); | |
417 |
|
415 | |||
418 | connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
416 | connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
419 | connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); |
|
417 | connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); | |
420 | connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
418 | connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
421 | connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); |
|
419 | connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); | |
422 | connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
420 | connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
423 | connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); |
|
421 | connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); | |
424 | connect(m_labelArmPen, SIGNAL(clicked()), m_labelArmPenTool, SLOT(show())); |
|
422 | connect(m_labelArmPen, SIGNAL(clicked()), m_labelArmPenTool, SLOT(show())); | |
425 | connect(m_labelArmPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
423 | connect(m_labelArmPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
426 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
424 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
427 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
425 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
428 | connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
426 | connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
429 | connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
427 | connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
430 | connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
428 | connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
431 | connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); |
|
429 | connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); | |
432 |
|
430 | |||
433 | // create main layout |
|
431 | // create main layout | |
434 | QVBoxLayout *settingsLayout = new QVBoxLayout(); |
|
432 | QVBoxLayout *settingsLayout = new QVBoxLayout(); | |
435 | settingsLayout->addWidget(chartSettings); |
|
433 | settingsLayout->addWidget(chartSettings); | |
436 | settingsLayout->addWidget(seriesSettings); |
|
434 | settingsLayout->addWidget(seriesSettings); | |
437 | settingsLayout->addWidget(sliceSettings); |
|
435 | settingsLayout->addWidget(sliceSettings); | |
438 | settingsLayout->addStretch(); |
|
436 | settingsLayout->addStretch(); | |
439 |
|
437 | |||
440 | QGridLayout* baseLayout = new QGridLayout(); |
|
438 | QGridLayout* baseLayout = new QGridLayout(); | |
441 | baseLayout->addLayout(settingsLayout, 0, 0); |
|
439 | baseLayout->addLayout(settingsLayout, 0, 0); | |
442 | baseLayout->addWidget(m_chartView, 0, 1); |
|
440 | baseLayout->addWidget(m_chartView, 0, 1); | |
443 | setLayout(baseLayout); |
|
441 | setLayout(baseLayout); | |
444 |
|
442 | |||
445 | updateSerieSettings(); |
|
443 | updateSerieSettings(); | |
446 | } |
|
444 | } | |
447 |
|
445 | |||
448 | public Q_SLOTS: |
|
446 | public Q_SLOTS: | |
449 |
|
447 | |||
450 | void updateChartSettings() |
|
448 | void updateChartSettings() | |
451 | { |
|
449 | { | |
452 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
450 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
453 | m_chartView->setChartTheme(theme); |
|
451 | m_chartView->setChartTheme(theme); | |
454 | m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); |
|
452 | m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); | |
455 |
|
453 | |||
456 | if (m_animationsCheckBox->checkState() == Qt::Checked) |
|
454 | if (m_animationsCheckBox->checkState() == Qt::Checked) | |
457 | m_chartView->setAnimationOptions(QChart::AllAnimations); |
|
455 | m_chartView->setAnimationOptions(QChart::AllAnimations); | |
458 | else |
|
456 | else | |
459 | m_chartView->setAnimationOptions(QChart::NoAnimation); |
|
457 | m_chartView->setAnimationOptions(QChart::NoAnimation); | |
460 | } |
|
458 | } | |
461 |
|
459 | |||
462 | void updateSerieSettings() |
|
460 | void updateSerieSettings() | |
463 | { |
|
461 | { | |
464 | m_series->setPiePosition(m_hPosition->value(), m_vPosition->value()); |
|
462 | m_series->setPiePosition(m_hPosition->value(), m_vPosition->value()); | |
465 | m_series->setPieSize(m_sizeFactor->value()); |
|
463 | m_series->setPieSize(m_sizeFactor->value()); | |
466 | m_series->setPieStartAngle(m_startAngle->value()); |
|
464 | m_series->setPieStartAngle(m_startAngle->value()); | |
467 | m_series->setPieEndAngle(m_endAngle->value()); |
|
465 | m_series->setPieEndAngle(m_endAngle->value()); | |
468 | } |
|
466 | } | |
469 |
|
467 | |||
470 | void updateSliceSettings() |
|
468 | void updateSliceSettings() | |
471 | { |
|
469 | { | |
472 | if (!m_slice) |
|
470 | if (!m_slice) | |
473 | return; |
|
471 | return; | |
474 |
|
472 | |||
475 | m_slice->setValue(m_sliceValue->value()); |
|
473 | m_slice->setValue(m_sliceValue->value()); | |
476 |
|
474 | |||
477 | m_slice->setSlicePen(m_penTool->pen()); |
|
475 | m_slice->setSlicePen(m_penTool->pen()); | |
478 | m_slice->setSliceBrush(m_brushTool->brush()); |
|
476 | m_slice->setSliceBrush(m_brushTool->brush()); | |
479 |
|
477 | |||
480 | m_slice->setLabelArmPen(m_labelArmPenTool->pen()); |
|
478 | m_slice->setLabelArmPen(m_labelArmPenTool->pen()); | |
481 | m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); |
|
479 | m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); | |
482 | m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); |
|
480 | m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); | |
483 |
|
481 | |||
484 | m_slice->setExploded(m_sliceExploded->isChecked()); |
|
482 | m_slice->setExploded(m_sliceExploded->isChecked()); | |
485 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); |
|
483 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); | |
486 | } |
|
484 | } | |
487 |
|
485 | |||
488 | void handleSliceClicked(QPieSlice* slice) |
|
486 | void handleSliceClicked(QPieSlice* slice) | |
489 | { |
|
487 | { | |
490 | m_slice = static_cast<CustomSlice*>(slice); |
|
488 | m_slice = static_cast<CustomSlice*>(slice); | |
491 |
|
489 | |||
492 | // name |
|
490 | // name | |
493 | m_sliceName->setText(slice->label()); |
|
491 | m_sliceName->setText(slice->label()); | |
494 |
|
492 | |||
495 | // value |
|
493 | // value | |
496 | m_sliceValue->blockSignals(true); |
|
494 | m_sliceValue->blockSignals(true); | |
497 | m_sliceValue->setValue(slice->value()); |
|
495 | m_sliceValue->setValue(slice->value()); | |
498 | m_sliceValue->blockSignals(false); |
|
496 | m_sliceValue->blockSignals(false); | |
499 |
|
497 | |||
500 | // pen |
|
498 | // pen | |
501 | m_pen->setText(PenTool::name(m_slice->slicePen())); |
|
499 | m_pen->setText(PenTool::name(m_slice->slicePen())); | |
502 | m_penTool->setPen(m_slice->slicePen()); |
|
500 | m_penTool->setPen(m_slice->slicePen()); | |
503 |
|
501 | |||
504 | // brush |
|
502 | // brush | |
505 | m_brush->setText(m_slice->originalBrush().color().name()); |
|
503 | m_brush->setText(m_slice->originalBrush().color().name()); | |
506 | m_brushTool->setBrush(m_slice->originalBrush()); |
|
504 | m_brushTool->setBrush(m_slice->originalBrush()); | |
507 |
|
505 | |||
508 | // label |
|
506 | // label | |
509 | m_labelArmPen->setText(PenTool::name(m_slice->labelArmPen())); |
|
507 | m_labelArmPen->setText(PenTool::name(m_slice->labelArmPen())); | |
510 | m_labelArmPenTool->setPen(m_slice->labelArmPen()); |
|
508 | m_labelArmPenTool->setPen(m_slice->labelArmPen()); | |
511 | m_font->setText(slice->labelFont().toString()); |
|
509 | m_font->setText(slice->labelFont().toString()); | |
512 | m_sliceLabelVisible->blockSignals(true); |
|
510 | m_sliceLabelVisible->blockSignals(true); | |
513 | m_sliceLabelVisible->setChecked(slice->isLabelVisible()); |
|
511 | m_sliceLabelVisible->setChecked(slice->isLabelVisible()); | |
514 | m_sliceLabelVisible->blockSignals(false); |
|
512 | m_sliceLabelVisible->blockSignals(false); | |
515 | m_sliceLabelArmFactor->blockSignals(true); |
|
513 | m_sliceLabelArmFactor->blockSignals(true); | |
516 | m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); |
|
514 | m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); | |
517 | m_sliceLabelArmFactor->blockSignals(false); |
|
515 | m_sliceLabelArmFactor->blockSignals(false); | |
518 |
|
516 | |||
519 | // exploded |
|
517 | // exploded | |
520 | m_sliceExploded->blockSignals(true); |
|
518 | m_sliceExploded->blockSignals(true); | |
521 | m_sliceExploded->setChecked(slice->isExploded()); |
|
519 | m_sliceExploded->setChecked(slice->isExploded()); | |
522 | m_sliceExploded->blockSignals(false); |
|
520 | m_sliceExploded->blockSignals(false); | |
523 | m_sliceExplodedFactor->blockSignals(true); |
|
521 | m_sliceExplodedFactor->blockSignals(true); | |
524 | m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); |
|
522 | m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); | |
525 | m_sliceExplodedFactor->blockSignals(false); |
|
523 | m_sliceExplodedFactor->blockSignals(false); | |
526 | } |
|
524 | } | |
527 |
|
525 | |||
528 | void showFontDialog() |
|
526 | void showFontDialog() | |
529 | { |
|
527 | { | |
530 | if (!m_slice) |
|
528 | if (!m_slice) | |
531 | return; |
|
529 | return; | |
532 |
|
530 | |||
533 | QFontDialog dialog(m_slice->labelFont()); |
|
531 | QFontDialog dialog(m_slice->labelFont()); | |
534 | dialog.show(); |
|
532 | dialog.show(); | |
535 | dialog.exec(); |
|
533 | dialog.exec(); | |
536 |
|
534 | |||
537 | m_slice->setLabelFont(dialog.currentFont()); |
|
535 | m_slice->setLabelFont(dialog.currentFont()); | |
538 | m_font->setText(dialog.currentFont().toString()); |
|
536 | m_font->setText(dialog.currentFont().toString()); | |
539 | } |
|
537 | } | |
540 |
|
538 | |||
541 | void addSlice() |
|
539 | void addSlice() | |
542 | { |
|
540 | { | |
543 | *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)); |
|
541 | *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)); | |
544 | } |
|
542 | } | |
545 |
|
543 | |||
546 | void insertSlice() |
|
544 | void insertSlice() | |
547 | { |
|
545 | { | |
548 | if (!m_slice) |
|
546 | if (!m_slice) | |
549 | return; |
|
547 | return; | |
550 |
|
548 | |||
551 | int i = m_series->slices().indexOf(m_slice); |
|
549 | int i = m_series->slices().indexOf(m_slice); | |
552 |
|
550 | |||
553 | m_series->insert(i, new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1))); |
|
551 | m_series->insert(i, new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1))); | |
554 | } |
|
552 | } | |
555 |
|
553 | |||
556 | void removeSlice() |
|
554 | void removeSlice() | |
557 | { |
|
555 | { | |
558 | if (!m_slice) |
|
556 | if (!m_slice) | |
559 | return; |
|
557 | return; | |
560 |
|
558 | |||
561 | m_series->remove(m_slice); |
|
559 | m_series->remove(m_slice); | |
562 | m_slice = 0; |
|
560 | m_slice = 0; | |
563 | } |
|
561 | } | |
564 |
|
562 | |||
565 | private: |
|
563 | private: | |
566 | QComboBox *m_themeComboBox; |
|
564 | QComboBox *m_themeComboBox; | |
567 | QCheckBox *m_aaCheckBox; |
|
565 | QCheckBox *m_aaCheckBox; | |
568 | QCheckBox *m_animationsCheckBox; |
|
566 | QCheckBox *m_animationsCheckBox; | |
569 |
|
567 | |||
570 | QChartView* m_chartView; |
|
568 | QChartView* m_chartView; | |
571 | QPieSeries* m_series; |
|
569 | QPieSeries* m_series; | |
572 | CustomSlice* m_slice; |
|
570 | CustomSlice* m_slice; | |
573 |
|
571 | |||
574 | QDoubleSpinBox* m_hPosition; |
|
572 | QDoubleSpinBox* m_hPosition; | |
575 | QDoubleSpinBox* m_vPosition; |
|
573 | QDoubleSpinBox* m_vPosition; | |
576 | QDoubleSpinBox* m_sizeFactor; |
|
574 | QDoubleSpinBox* m_sizeFactor; | |
577 | QDoubleSpinBox* m_startAngle; |
|
575 | QDoubleSpinBox* m_startAngle; | |
578 | QDoubleSpinBox* m_endAngle; |
|
576 | QDoubleSpinBox* m_endAngle; | |
579 |
|
577 | |||
580 | QLabel* m_sliceName; |
|
578 | QLabel* m_sliceName; | |
581 | QDoubleSpinBox* m_sliceValue; |
|
579 | QDoubleSpinBox* m_sliceValue; | |
582 | QCheckBox* m_sliceLabelVisible; |
|
580 | QCheckBox* m_sliceLabelVisible; | |
583 | QDoubleSpinBox* m_sliceLabelArmFactor; |
|
581 | QDoubleSpinBox* m_sliceLabelArmFactor; | |
584 | QCheckBox* m_sliceExploded; |
|
582 | QCheckBox* m_sliceExploded; | |
585 | QDoubleSpinBox* m_sliceExplodedFactor; |
|
583 | QDoubleSpinBox* m_sliceExplodedFactor; | |
586 | QPushButton *m_brush; |
|
584 | QPushButton *m_brush; | |
587 | BrushTool *m_brushTool; |
|
585 | BrushTool *m_brushTool; | |
588 | QPushButton *m_pen; |
|
586 | QPushButton *m_pen; | |
589 | PenTool *m_penTool; |
|
587 | PenTool *m_penTool; | |
590 | QPushButton *m_font; |
|
588 | QPushButton *m_font; | |
591 | QPushButton *m_labelArmPen; |
|
589 | QPushButton *m_labelArmPen; | |
592 | PenTool *m_labelArmPenTool; |
|
590 | PenTool *m_labelArmPenTool; | |
593 | }; |
|
591 | }; | |
594 |
|
592 | |||
595 | int main(int argc, char *argv[]) |
|
593 | int main(int argc, char *argv[]) | |
596 | { |
|
594 | { | |
597 | QApplication a(argc, argv); |
|
595 | QApplication a(argc, argv); | |
598 |
|
596 | |||
599 | QMainWindow window; |
|
597 | QMainWindow window; | |
600 |
|
598 | |||
601 | MainWidget* widget = new MainWidget(); |
|
599 | MainWidget* widget = new MainWidget(); | |
602 |
|
600 | |||
603 | window.setCentralWidget(widget); |
|
601 | window.setCentralWidget(widget); | |
604 | window.resize(900, 600); |
|
602 | window.resize(900, 600); | |
605 | window.show(); |
|
603 | window.show(); | |
606 |
|
604 | |||
607 | return a.exec(); |
|
605 | return a.exec(); | |
608 | } |
|
606 | } | |
609 |
|
607 | |||
610 | #include "main.moc" |
|
608 | #include "main.moc" |
@@ -1,114 +1,114 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartglobal.h> |
|
3 | #include <qchartglobal.h> | |
4 | #include <qchartview.h> |
|
4 | #include <qchartview.h> | |
5 | #include <qpieseries.h> |
|
5 | #include <qpieseries.h> | |
6 | #include <qpieslice.h> |
|
6 | #include <qpieslice.h> | |
7 | #include <QTime> |
|
7 | #include <QTime> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | QTCOMMERCIALCHART_USE_NAMESPACE | |
10 |
|
10 | |||
11 | class DrilldownSlice : public QPieSlice |
|
11 | class DrilldownSlice : public QPieSlice | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 |
|
14 | |||
15 | public: |
|
15 | public: | |
16 | DrilldownSlice(qreal value, QString prefix, QSeries* drilldownSeries) |
|
16 | DrilldownSlice(qreal value, QString prefix, QSeries* drilldownSeries) | |
17 | :m_drilldownSeries(drilldownSeries), |
|
17 | :m_drilldownSeries(drilldownSeries), | |
18 | m_prefix(prefix) |
|
18 | m_prefix(prefix) | |
19 | { |
|
19 | { | |
20 | setValue(value); |
|
20 | setValue(value); | |
21 | setLabelVisible(true); |
|
21 | setLabelVisible(true); | |
22 | updateLabel(); |
|
22 | updateLabel(); | |
23 | connect(this, SIGNAL(changed()), this, SLOT(updateLabel())); |
|
23 | connect(this, SIGNAL(changed()), this, SLOT(updateLabel())); | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | QSeries* drilldownSeries() const { return m_drilldownSeries; } |
|
26 | QSeries* drilldownSeries() const { return m_drilldownSeries; } | |
27 |
|
27 | |||
28 | public Q_SLOTS: |
|
28 | public Q_SLOTS: | |
29 | void updateLabel() |
|
29 | void updateLabel() | |
30 | { |
|
30 | { | |
31 | QString label = m_prefix; |
|
31 | QString label = m_prefix; | |
32 | label += " " + QString::number(this->value())+ "e ("; |
|
32 | label += " " + QString::number(this->value())+ "e ("; | |
33 | label += QString::number(this->percentage()*100, 'f', 1) + "%)"; |
|
33 | label += QString::number(this->percentage()*100, 'f', 1) + "%)"; | |
34 | setLabel(label); |
|
34 | setLabel(label); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | private: |
|
37 | private: | |
38 | QSeries* m_drilldownSeries; |
|
38 | QSeries* m_drilldownSeries; | |
39 | QString m_prefix; |
|
39 | QString m_prefix; | |
40 | }; |
|
40 | }; | |
41 |
|
41 | |||
42 | class DrilldownChart : public QChartView |
|
42 | class DrilldownChart : public QChartView | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | public: |
|
45 | public: | |
46 | explicit DrilldownChart(QWidget *parent = 0):QChartView(parent), m_currentSeries(0) {} |
|
46 | explicit DrilldownChart(QWidget *parent = 0):QChartView(parent), m_currentSeries(0) {} | |
47 |
|
47 | |||
48 | void changeSeries(QSeries* series) |
|
48 | void changeSeries(QSeries* series) | |
49 | { |
|
49 | { | |
50 | // NOTE: if the series is owned by the chart it will be deleted |
|
50 | // NOTE: if the series is owned by the chart it will be deleted | |
51 | // here the "window" owns the series... |
|
51 | // here the "window" owns the series... | |
52 | if (m_currentSeries) |
|
52 | if (m_currentSeries) | |
53 | removeSeries(m_currentSeries); |
|
53 | removeSeries(m_currentSeries); | |
54 | m_currentSeries = series; |
|
54 | m_currentSeries = series; | |
55 | addSeries(series); |
|
55 | addSeries(series); | |
56 | setChartTitle(series->title()); |
|
56 | setChartTitle(series->title()); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | public Q_SLOTS: |
|
59 | public Q_SLOTS: | |
60 | void handleSliceClicked(QPieSlice* slice) |
|
60 | void handleSliceClicked(QPieSlice* slice) | |
61 | { |
|
61 | { | |
62 | DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice); |
|
62 | DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice); | |
63 | changeSeries(drilldownSlice->drilldownSeries()); |
|
63 | changeSeries(drilldownSlice->drilldownSeries()); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | private: |
|
66 | private: | |
67 | QSeries* m_currentSeries; |
|
67 | QSeries* m_currentSeries; | |
68 | }; |
|
68 | }; | |
69 |
|
69 | |||
70 | int main(int argc, char *argv[]) |
|
70 | int main(int argc, char *argv[]) | |
71 | { |
|
71 | { | |
72 | QApplication a(argc, argv); |
|
72 | QApplication a(argc, argv); | |
73 |
|
73 | |||
74 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
74 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
75 |
|
75 | |||
76 | QMainWindow window; |
|
76 | QMainWindow window; | |
77 |
|
77 | |||
78 | DrilldownChart* drilldownChart = new DrilldownChart(&window); |
|
78 | DrilldownChart* drilldownChart = new DrilldownChart(&window); | |
79 | drilldownChart->setRenderHint(QPainter::Antialiasing); |
|
79 | drilldownChart->setRenderHint(QPainter::Antialiasing); | |
80 |
drilldownChart->setChartTheme(QChart::ChartTheme |
|
80 | drilldownChart->setChartTheme(QChart::ChartThemeLight); | |
81 | drilldownChart->setAnimationOptions(QChart::AllAnimations); |
|
81 | drilldownChart->setAnimationOptions(QChart::AllAnimations); | |
82 |
|
82 | |||
83 | QPieSeries* yearSeries = new QPieSeries(&window); |
|
83 | QPieSeries* yearSeries = new QPieSeries(&window); | |
84 | yearSeries->setTitle("Sales by year - All"); |
|
84 | yearSeries->setTitle("Sales by year - All"); | |
85 |
|
85 | |||
86 | QList<QString> months; |
|
86 | QList<QString> months; | |
87 | months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
87 | months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
88 | QList<QString> names; |
|
88 | QList<QString> names; | |
89 | names << "Jane" << "John" << "Axel" << "Mary" << "Samantha" << "Bob"; |
|
89 | names << "Jane" << "John" << "Axel" << "Mary" << "Samantha" << "Bob"; | |
90 |
|
90 | |||
91 | foreach (QString name, names) { |
|
91 | foreach (QString name, names) { | |
92 | QPieSeries* series = new QPieSeries(&window); |
|
92 | QPieSeries* series = new QPieSeries(&window); | |
93 | series->setTitle("Sales by month - " + name); |
|
93 | series->setTitle("Sales by month - " + name); | |
94 |
|
94 | |||
95 | foreach (QString month, months) |
|
95 | foreach (QString month, months) | |
96 | *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); |
|
96 | *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); | |
97 |
|
97 | |||
98 | QObject::connect(series, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*))); |
|
98 | QObject::connect(series, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*))); | |
99 |
|
99 | |||
100 | *yearSeries << new DrilldownSlice(series->total(), name, series); |
|
100 | *yearSeries << new DrilldownSlice(series->total(), name, series); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*))); |
|
103 | QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*))); | |
104 |
|
104 | |||
105 | drilldownChart->changeSeries(yearSeries); |
|
105 | drilldownChart->changeSeries(yearSeries); | |
106 |
|
106 | |||
107 | window.setCentralWidget(drilldownChart); |
|
107 | window.setCentralWidget(drilldownChart); | |
108 | window.resize(800, 600); |
|
108 | window.resize(800, 600); | |
109 | window.show(); |
|
109 | window.show(); | |
110 |
|
110 | |||
111 | return a.exec(); |
|
111 | return a.exec(); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | #include "main.moc" |
|
114 | #include "main.moc" |
@@ -1,49 +1,47 | |||||
1 | #ifndef DECLARATIVECHART_H |
|
1 | #ifndef DECLARATIVECHART_H | |
2 | #define DECLARATIVECHART_H |
|
2 | #define DECLARATIVECHART_H | |
3 |
|
3 | |||
4 | #include <QtCore/QtGlobal> |
|
4 | #include <QtCore/QtGlobal> | |
5 | #include <QDeclarativeItem> |
|
5 | #include <QDeclarativeItem> | |
6 | #include <qchart.h> |
|
6 | #include <qchart.h> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class DeclarativeChart : public QDeclarativeItem |
|
10 | class DeclarativeChart : public QDeclarativeItem | |
11 | // TODO: for QTQUICK2: extend QQuickPainterItem instead |
|
11 | // TODO: for QTQUICK2: extend QQuickPainterItem instead | |
12 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
12 | //class DeclarativeChart : public QQuickPaintedItem, public Chart | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | Q_ENUMS(ChartTheme) |
|
15 | Q_ENUMS(ChartTheme) | |
16 | Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme) |
|
16 | Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme) | |
17 |
|
17 | |||
18 | public: |
|
18 | public: | |
19 | enum ChartTheme { |
|
19 | enum ChartTheme { | |
20 | ThemeDefault, |
|
20 | ThemeDefault, | |
21 | ThemeLight, |
|
21 | ThemeLight, | |
22 | ThemeBlueCerulean, |
|
22 | ThemeBlueCerulean, | |
23 | ThemeDark, |
|
23 | ThemeDark, | |
24 | ThemeBrownSand, |
|
24 | ThemeBrownSand, | |
25 | ThemeBlueNcs, |
|
25 | ThemeBlueNcs, | |
26 | ThemeVanilla, |
|
|||
27 | ThemeIcy, |
|
26 | ThemeIcy, | |
28 | ThemeGrayscale, |
|
|||
29 | ThemeScientific |
|
27 | ThemeScientific | |
30 | }; |
|
28 | }; | |
31 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
29 | DeclarativeChart(QDeclarativeItem *parent = 0); | |
32 |
|
30 | |||
33 | public: // From QDeclarativeItem/QGraphicsItem |
|
31 | public: // From QDeclarativeItem/QGraphicsItem | |
34 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
32 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); | |
35 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
33 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
36 |
|
34 | |||
37 | public: |
|
35 | public: | |
38 | void setTheme(ChartTheme theme) {m_chart->setChartTheme((QChart::ChartTheme) theme);} |
|
36 | void setTheme(ChartTheme theme) {m_chart->setChartTheme((QChart::ChartTheme) theme);} | |
39 | ChartTheme theme(); |
|
37 | ChartTheme theme(); | |
40 |
|
38 | |||
41 | public: |
|
39 | public: | |
42 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
40 | // Extending QChart with DeclarativeChart is not possible because QObject does not support | |
43 | // multi inheritance, so we now have a QChart as a member instead |
|
41 | // multi inheritance, so we now have a QChart as a member instead | |
44 | QChart *m_chart; |
|
42 | QChart *m_chart; | |
45 | }; |
|
43 | }; | |
46 |
|
44 | |||
47 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | QTCOMMERCIALCHART_END_NAMESPACE | |
48 |
|
46 | |||
49 | #endif // DECLARATIVECHART_H |
|
47 | #endif // DECLARATIVECHART_H |
@@ -1,375 +1,369 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartview.h" |
|
3 | #include "qchartview.h" | |
4 | #include "qlegend.h" |
|
4 | #include "qlegend.h" | |
5 | #include "qchartaxis.h" |
|
5 | #include "qchartaxis.h" | |
6 | #include <QTime> |
|
6 | #include <QTime> | |
7 |
|
7 | |||
8 | //series |
|
8 | //series | |
9 | #include "qbarset.h" |
|
9 | #include "qbarset.h" | |
10 | #include "qbarseries.h" |
|
10 | #include "qbarseries.h" | |
11 | #include "qstackedbarseries.h" |
|
11 | #include "qstackedbarseries.h" | |
12 | #include "qpercentbarseries.h" |
|
12 | #include "qpercentbarseries.h" | |
13 | #include "qlineseries.h" |
|
13 | #include "qlineseries.h" | |
14 | #include "qareaseries.h" |
|
14 | #include "qareaseries.h" | |
15 | #include "qscatterseries.h" |
|
15 | #include "qscatterseries.h" | |
16 | #include "qpieseries.h" |
|
16 | #include "qpieseries.h" | |
17 | #include "qpieslice.h" |
|
17 | #include "qpieslice.h" | |
18 | #include "qsplineseries.h" |
|
18 | #include "qsplineseries.h" | |
19 |
|
19 | |||
20 | //items |
|
20 | //items | |
21 | #include "axisitem_p.h" |
|
21 | #include "axisitem_p.h" | |
22 | #include "barchartitem_p.h" |
|
22 | #include "barchartitem_p.h" | |
23 | #include "stackedbarchartitem_p.h" |
|
23 | #include "stackedbarchartitem_p.h" | |
24 | #include "percentbarchartitem_p.h" |
|
24 | #include "percentbarchartitem_p.h" | |
25 | #include "linechartitem_p.h" |
|
25 | #include "linechartitem_p.h" | |
26 | #include "areachartitem_p.h" |
|
26 | #include "areachartitem_p.h" | |
27 | #include "scatterchartitem_p.h" |
|
27 | #include "scatterchartitem_p.h" | |
28 | #include "piechartitem_p.h" |
|
28 | #include "piechartitem_p.h" | |
29 | #include "splinechartitem_p.h" |
|
29 | #include "splinechartitem_p.h" | |
30 |
|
30 | |||
31 | //themes |
|
31 | //themes | |
32 | #include "chartthemedefault_p.h" |
|
32 | #include "chartthemedefault_p.h" | |
33 | #include "chartthemelight_p.h" |
|
33 | #include "chartthemelight_p.h" | |
34 | #include "chartthemebluecerulean_p.h" |
|
34 | #include "chartthemebluecerulean_p.h" | |
35 | #include "chartthemedark_p.h" |
|
35 | #include "chartthemedark_p.h" | |
36 | #include "chartthemebrownsand_p.h" |
|
36 | #include "chartthemebrownsand_p.h" | |
37 | #include "chartthemebluencs_p.h" |
|
37 | #include "chartthemebluencs_p.h" | |
38 | #include "chartthemevanilla_p.h" |
|
|||
39 | #include "chartthemeicy_p.h" |
|
38 | #include "chartthemeicy_p.h" | |
40 | #include "chartthemegrayscale_p.h" |
|
|||
41 | #include "chartthemescientific_p.h" |
|
39 | #include "chartthemescientific_p.h" | |
42 |
|
40 | |||
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
44 |
|
42 | |||
45 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
43 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
46 | m_masterFont(QFont()), |
|
44 | m_masterFont(QFont()), | |
47 | m_titleBrush(QColor(QRgb(0x000000))), |
|
45 | m_titleBrush(QColor(QRgb(0x000000))), | |
48 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
46 | m_axisLinePen(QPen(QRgb(0x000000))), | |
49 | m_axisLabelBrush(QColor(QRgb(0x000000))), |
|
47 | m_axisLabelBrush(QColor(QRgb(0x000000))), | |
50 | m_backgroundShadesPen(Qt::NoPen), |
|
48 | m_backgroundShadesPen(Qt::NoPen), | |
51 | m_backgroundShadesBrush(Qt::NoBrush), |
|
49 | m_backgroundShadesBrush(Qt::NoBrush), | |
52 | m_backgroundShades(BackgroundShadesNone), |
|
50 | m_backgroundShades(BackgroundShadesNone), | |
53 | m_gridLinePen(QPen(QRgb(0x000000))) |
|
51 | m_gridLinePen(QPen(QRgb(0x000000))) | |
54 | { |
|
52 | { | |
55 | m_id = id; |
|
53 | m_id = id; | |
56 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
54 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
57 | } |
|
55 | } | |
58 |
|
56 | |||
59 |
|
57 | |||
60 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
58 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
61 | { |
|
59 | { | |
62 | switch(theme) { |
|
60 | switch(theme) { | |
63 | case QChart::ChartThemeLight: |
|
61 | case QChart::ChartThemeLight: | |
64 | return new ChartThemeLight(); |
|
62 | return new ChartThemeLight(); | |
65 | case QChart::ChartThemeBlueCerulean: |
|
63 | case QChart::ChartThemeBlueCerulean: | |
66 | return new ChartThemeBlueCerulean(); |
|
64 | return new ChartThemeBlueCerulean(); | |
67 | case QChart::ChartThemeDark: |
|
65 | case QChart::ChartThemeDark: | |
68 | return new ChartThemeDark(); |
|
66 | return new ChartThemeDark(); | |
69 | case QChart::ChartThemeBrownSand: |
|
67 | case QChart::ChartThemeBrownSand: | |
70 | return new ChartThemeBrownSand(); |
|
68 | return new ChartThemeBrownSand(); | |
71 | case QChart::ChartThemeBlueNcs: |
|
69 | case QChart::ChartThemeBlueNcs: | |
72 | return new ChartThemeBlueNcs(); |
|
70 | return new ChartThemeBlueNcs(); | |
73 | case QChart::ChartThemeVanilla: |
|
|||
74 | return new ChartThemeVanilla(); |
|
|||
75 | case QChart::ChartThemeIcy: |
|
71 | case QChart::ChartThemeIcy: | |
76 | return new ChartThemeIcy(); |
|
72 | return new ChartThemeIcy(); | |
77 | case QChart::ChartThemeGrayscale: |
|
|||
78 | return new ChartThemeGrayscale(); |
|
|||
79 | case QChart::ChartThemeScientific: |
|
73 | case QChart::ChartThemeScientific: | |
80 | return new ChartThemeScientific(); |
|
74 | return new ChartThemeScientific(); | |
81 | default: |
|
75 | default: | |
82 | return new ChartThemeDefault(); |
|
76 | return new ChartThemeDefault(); | |
83 | } |
|
77 | } | |
84 | } |
|
78 | } | |
85 |
|
79 | |||
86 | void ChartTheme::decorate(QChart* chart,bool force) |
|
80 | void ChartTheme::decorate(QChart* chart,bool force) | |
87 | { |
|
81 | { | |
88 | QPen pen; |
|
82 | QPen pen; | |
89 | QBrush brush; |
|
83 | QBrush brush; | |
90 |
|
84 | |||
91 | if(brush == chart->backgroundBrush() || force) |
|
85 | if(brush == chart->backgroundBrush() || force) | |
92 | { |
|
86 | { | |
93 | if (m_backgroundShades == BackgroundShadesNone) { |
|
87 | if (m_backgroundShades == BackgroundShadesNone) { | |
94 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
88 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
95 | } |
|
89 | } | |
96 | else { |
|
90 | else { | |
97 | chart->setBackgroundBrush(Qt::NoBrush); |
|
91 | chart->setBackgroundBrush(Qt::NoBrush); | |
98 | } |
|
92 | } | |
99 | } |
|
93 | } | |
100 | chart->setTitleFont(m_masterFont); |
|
94 | chart->setTitleFont(m_masterFont); | |
101 | chart->setTitleBrush(m_titleBrush); |
|
95 | chart->setTitleBrush(m_titleBrush); | |
102 | } |
|
96 | } | |
103 |
|
97 | |||
104 | void ChartTheme::decorate(QLegend* legend,bool force) |
|
98 | void ChartTheme::decorate(QLegend* legend,bool force) | |
105 | { |
|
99 | { | |
106 | QPen pen; |
|
100 | QPen pen; | |
107 | QBrush brush; |
|
101 | QBrush brush; | |
108 |
|
102 | |||
109 | if (pen == legend->pen() || force){ |
|
103 | if (pen == legend->pen() || force){ | |
110 | //TODO:: legend->setPen(); |
|
104 | //TODO:: legend->setPen(); | |
111 | } |
|
105 | } | |
112 |
|
106 | |||
113 |
|
107 | |||
114 | if (brush == legend->brush() || force) { |
|
108 | if (brush == legend->brush() || force) { | |
115 | legend->setBrush(m_chartBackgroundGradient); |
|
109 | legend->setBrush(m_chartBackgroundGradient); | |
116 | } |
|
110 | } | |
117 | } |
|
111 | } | |
118 |
|
112 | |||
119 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) |
|
113 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) | |
120 | { |
|
114 | { | |
121 | QPen pen; |
|
115 | QPen pen; | |
122 | QBrush brush; |
|
116 | QBrush brush; | |
123 |
|
117 | |||
124 | if (pen == series->pen() || force){ |
|
118 | if (pen == series->pen() || force){ | |
125 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
119 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
126 | pen.setWidthF(2); |
|
120 | pen.setWidthF(2); | |
127 | series->setPen(pen); |
|
121 | series->setPen(pen); | |
128 | } |
|
122 | } | |
129 |
|
123 | |||
130 | if (brush == series->brush() || force) { |
|
124 | if (brush == series->brush() || force) { | |
131 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
125 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
132 | series->setBrush(brush); |
|
126 | series->setBrush(brush); | |
133 | } |
|
127 | } | |
134 | } |
|
128 | } | |
135 |
|
129 | |||
136 |
|
130 | |||
137 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) |
|
131 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) | |
138 | { |
|
132 | { | |
139 | QPen pen; |
|
133 | QPen pen; | |
140 | if(pen == series->pen() || force ){ |
|
134 | if(pen == series->pen() || force ){ | |
141 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
135 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
142 | pen.setWidthF(2); |
|
136 | pen.setWidthF(2); | |
143 | series->setPen(pen); |
|
137 | series->setPen(pen); | |
144 | } |
|
138 | } | |
145 | } |
|
139 | } | |
146 |
|
140 | |||
147 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) |
|
141 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) | |
148 | { |
|
142 | { | |
149 | QBrush brush; |
|
143 | QBrush brush; | |
150 | QPen pen; |
|
144 | QPen pen; | |
151 | QList<QBarSet*> sets = series->barSets(); |
|
145 | QList<QBarSet*> sets = series->barSets(); | |
152 |
|
146 | |||
153 | qreal takeAtPos = 0.5; |
|
147 | qreal takeAtPos = 0.5; | |
154 | qreal step = 0.2; |
|
148 | qreal step = 0.2; | |
155 | if (sets.count() > 1 ) { |
|
149 | if (sets.count() > 1 ) { | |
156 | step = 1.0 / (qreal) sets.count(); |
|
150 | step = 1.0 / (qreal) sets.count(); | |
157 | if (sets.count() % m_seriesGradients.count()) |
|
151 | if (sets.count() % m_seriesGradients.count()) | |
158 | step *= m_seriesGradients.count(); |
|
152 | step *= m_seriesGradients.count(); | |
159 | else |
|
153 | else | |
160 | step *= (m_seriesGradients.count() - 1); |
|
154 | step *= (m_seriesGradients.count() - 1); | |
161 | } |
|
155 | } | |
162 |
|
156 | |||
163 | for (int i(0); i < sets.count(); i++) { |
|
157 | for (int i(0); i < sets.count(); i++) { | |
164 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
158 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
165 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
159 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
166 | // There is no dedicated base color for each sets, generate more colors |
|
160 | // There is no dedicated base color for each sets, generate more colors | |
167 | takeAtPos += step; |
|
161 | takeAtPos += step; | |
168 | if (takeAtPos == 1.0) |
|
162 | if (takeAtPos == 1.0) | |
169 | takeAtPos += step; |
|
163 | takeAtPos += step; | |
170 | takeAtPos -= (int) takeAtPos; |
|
164 | takeAtPos -= (int) takeAtPos; | |
171 | } |
|
165 | } | |
172 | qDebug() << "pos:" << takeAtPos; |
|
166 | qDebug() << "pos:" << takeAtPos; | |
173 | if (brush == sets.at(i)->brush() || force ) |
|
167 | if (brush == sets.at(i)->brush() || force ) | |
174 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
168 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
175 |
|
169 | |||
176 | // Pick label color from the opposite end of the gradient. |
|
170 | // Pick label color from the opposite end of the gradient. | |
177 | // 0.3 as a boundary seems to work well. |
|
171 | // 0.3 as a boundary seems to work well. | |
178 | if (takeAtPos < 0.3) |
|
172 | if (takeAtPos < 0.3) | |
179 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
173 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
180 | else |
|
174 | else | |
181 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
175 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
182 |
|
176 | |||
183 | if (pen == sets.at(i)->pen() || force) { |
|
177 | if (pen == sets.at(i)->pen() || force) { | |
184 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
178 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
185 | sets.at(i)->setPen(c); |
|
179 | sets.at(i)->setPen(c); | |
186 | } |
|
180 | } | |
187 | } |
|
181 | } | |
188 | } |
|
182 | } | |
189 |
|
183 | |||
190 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) |
|
184 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) | |
191 | { |
|
185 | { | |
192 | QPen pen; |
|
186 | QPen pen; | |
193 | QBrush brush; |
|
187 | QBrush brush; | |
194 |
|
188 | |||
195 | if (pen == series->pen() || force) { |
|
189 | if (pen == series->pen() || force) { | |
196 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
190 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
197 | pen.setWidthF(2); |
|
191 | pen.setWidthF(2); | |
198 | series->setPen(pen); |
|
192 | series->setPen(pen); | |
199 | } |
|
193 | } | |
200 |
|
194 | |||
201 | if (brush == series->brush() || force) { |
|
195 | if (brush == series->brush() || force) { | |
202 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
196 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
203 | series->setBrush(brush); |
|
197 | series->setBrush(brush); | |
204 | } |
|
198 | } | |
205 | } |
|
199 | } | |
206 |
|
200 | |||
207 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) |
|
201 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) | |
208 | { |
|
202 | { | |
209 | for (int i(0); i < series->slices().count(); i++) { |
|
203 | for (int i(0); i < series->slices().count(); i++) { | |
210 |
|
204 | |||
211 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
205 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
212 |
|
206 | |||
213 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
207 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
214 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
208 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
215 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
209 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
216 |
|
210 | |||
217 | QPieSlice::DataPtr s = series->slices().at(i)->data_ptr(); |
|
211 | QPieSlice::DataPtr s = series->slices().at(i)->data_ptr(); | |
218 | PieSliceData data = s->m_data; |
|
212 | PieSliceData data = s->m_data; | |
219 |
|
213 | |||
220 | if (data.m_slicePen.isThemed() || force) { |
|
214 | if (data.m_slicePen.isThemed() || force) { | |
221 | data.m_slicePen = penColor; |
|
215 | data.m_slicePen = penColor; | |
222 | data.m_slicePen.setThemed(true); |
|
216 | data.m_slicePen.setThemed(true); | |
223 | } |
|
217 | } | |
224 |
|
218 | |||
225 | if (data.m_sliceBrush.isThemed() || force) { |
|
219 | if (data.m_sliceBrush.isThemed() || force) { | |
226 | data.m_sliceBrush = brushColor; |
|
220 | data.m_sliceBrush = brushColor; | |
227 | data.m_sliceBrush.setThemed(true); |
|
221 | data.m_sliceBrush.setThemed(true); | |
228 | } |
|
222 | } | |
229 |
|
223 | |||
230 | if (s->m_data != data) { |
|
224 | if (s->m_data != data) { | |
231 | s->m_data = data; |
|
225 | s->m_data = data; | |
232 | emit s->changed(); |
|
226 | emit s->changed(); | |
233 | } |
|
227 | } | |
234 | } |
|
228 | } | |
235 | } |
|
229 | } | |
236 |
|
230 | |||
237 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) |
|
231 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) | |
238 | { |
|
232 | { | |
239 | QPen pen; |
|
233 | QPen pen; | |
240 | if(pen == series->pen() || force){ |
|
234 | if(pen == series->pen() || force){ | |
241 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
235 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
242 | pen.setWidthF(2); |
|
236 | pen.setWidthF(2); | |
243 | series->setPen(pen); |
|
237 | series->setPen(pen); | |
244 | } |
|
238 | } | |
245 | } |
|
239 | } | |
246 |
|
240 | |||
247 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) |
|
241 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) | |
248 | { |
|
242 | { | |
249 | QPen pen; |
|
243 | QPen pen; | |
250 | QBrush brush; |
|
244 | QBrush brush; | |
251 | QFont font; |
|
245 | QFont font; | |
252 |
|
246 | |||
253 | if (axis->isAxisVisible()) { |
|
247 | if (axis->isAxisVisible()) { | |
254 |
|
248 | |||
255 | if(brush == axis->labelsBrush() || force){ |
|
249 | if(brush == axis->labelsBrush() || force){ | |
256 | axis->setLabelsBrush(m_axisLabelBrush); |
|
250 | axis->setLabelsBrush(m_axisLabelBrush); | |
257 | } |
|
251 | } | |
258 | if(pen == axis->labelsPen() || force){ |
|
252 | if(pen == axis->labelsPen() || force){ | |
259 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
253 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
260 | } |
|
254 | } | |
261 |
|
255 | |||
262 |
|
256 | |||
263 | if (axis->shadesVisible() || force) { |
|
257 | if (axis->shadesVisible() || force) { | |
264 |
|
258 | |||
265 | if(brush == axis->shadesBrush() || force){ |
|
259 | if(brush == axis->shadesBrush() || force){ | |
266 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
260 | axis->setShadesBrush(m_backgroundShadesBrush); | |
267 | } |
|
261 | } | |
268 |
|
262 | |||
269 | if(pen == axis->shadesPen() || force){ |
|
263 | if(pen == axis->shadesPen() || force){ | |
270 | axis->setShadesPen(m_backgroundShadesPen); |
|
264 | axis->setShadesPen(m_backgroundShadesPen); | |
271 | } |
|
265 | } | |
272 |
|
266 | |||
273 | if(force && (m_backgroundShades == BackgroundShadesBoth |
|
267 | if(force && (m_backgroundShades == BackgroundShadesBoth | |
274 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
268 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
275 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
269 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
276 | axis->setShadesVisible(true); |
|
270 | axis->setShadesVisible(true); | |
277 |
|
271 | |||
278 | } |
|
272 | } | |
279 | } |
|
273 | } | |
280 |
|
274 | |||
281 | if(pen == axis->axisPen() || force){ |
|
275 | if(pen == axis->axisPen() || force){ | |
282 | axis->setAxisPen(m_axisLinePen); |
|
276 | axis->setAxisPen(m_axisLinePen); | |
283 | } |
|
277 | } | |
284 |
|
278 | |||
285 | if(pen == axis->gridLinePen() || force){ |
|
279 | if(pen == axis->gridLinePen() || force){ | |
286 | axis->setGridLinePen(m_gridLinePen); |
|
280 | axis->setGridLinePen(m_gridLinePen); | |
287 | } |
|
281 | } | |
288 |
|
282 | |||
289 | if(font == axis->labelsFont() || force){ |
|
283 | if(font == axis->labelsFont() || force){ | |
290 | axis->setLabelsFont(m_masterFont); |
|
284 | axis->setLabelsFont(m_masterFont); | |
291 | } |
|
285 | } | |
292 | } |
|
286 | } | |
293 | } |
|
287 | } | |
294 |
|
288 | |||
295 | void ChartTheme::generateSeriesGradients() |
|
289 | void ChartTheme::generateSeriesGradients() | |
296 | { |
|
290 | { | |
297 | // Generate gradients in HSV color space |
|
291 | // Generate gradients in HSV color space | |
298 | foreach (QColor color, m_seriesColors) { |
|
292 | foreach (QColor color, m_seriesColors) { | |
299 | QLinearGradient g; |
|
293 | QLinearGradient g; | |
300 | qreal h = color.hsvHueF(); |
|
294 | qreal h = color.hsvHueF(); | |
301 | qreal s = color.hsvSaturationF(); |
|
295 | qreal s = color.hsvSaturationF(); | |
302 |
|
296 | |||
303 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
297 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
304 | // most themes. The rest of the gradients we can define manually in theme specific |
|
298 | // most themes. The rest of the gradients we can define manually in theme specific | |
305 | // implementation. |
|
299 | // implementation. | |
306 | QColor start = color; |
|
300 | QColor start = color; | |
307 | start.setHsvF(h, 0.0, 1.0); |
|
301 | start.setHsvF(h, 0.0, 1.0); | |
308 | g.setColorAt(0.0, start); |
|
302 | g.setColorAt(0.0, start); | |
309 |
|
303 | |||
310 | g.setColorAt(0.5, color); |
|
304 | g.setColorAt(0.5, color); | |
311 |
|
305 | |||
312 | QColor end = color; |
|
306 | QColor end = color; | |
313 | end.setHsvF(h, s, 0.25); |
|
307 | end.setHsvF(h, s, 0.25); | |
314 | g.setColorAt(1.0, end); |
|
308 | g.setColorAt(1.0, end); | |
315 |
|
309 | |||
316 | m_seriesGradients << g; |
|
310 | m_seriesGradients << g; | |
317 | } |
|
311 | } | |
318 | } |
|
312 | } | |
319 |
|
313 | |||
320 |
|
314 | |||
321 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
315 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
322 | { |
|
316 | { | |
323 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
317 | Q_ASSERT(pos >=0.0 && pos <= 1.0); | |
324 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
318 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
325 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
319 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
326 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
320 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
327 | QColor c; |
|
321 | QColor c; | |
328 | c.setRgbF(r, g, b); |
|
322 | c.setRgbF(r, g, b); | |
329 | return c; |
|
323 | return c; | |
330 | } |
|
324 | } | |
331 |
|
325 | |||
332 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
326 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
333 | { |
|
327 | { | |
334 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
328 | Q_ASSERT(pos >=0 && pos <= 1.0); | |
335 |
|
329 | |||
336 | // another possibility: |
|
330 | // another possibility: | |
337 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
331 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
338 |
|
332 | |||
339 | QGradientStops stops = gradient.stops(); |
|
333 | QGradientStops stops = gradient.stops(); | |
340 | int count = stops.count(); |
|
334 | int count = stops.count(); | |
341 |
|
335 | |||
342 | // find previous stop relative to position |
|
336 | // find previous stop relative to position | |
343 | QGradientStop prev = stops.first(); |
|
337 | QGradientStop prev = stops.first(); | |
344 | for (int i=0; i<count; i++) { |
|
338 | for (int i=0; i<count; i++) { | |
345 | QGradientStop stop = stops.at(i); |
|
339 | QGradientStop stop = stops.at(i); | |
346 | if (pos > stop.first) |
|
340 | if (pos > stop.first) | |
347 | prev = stop; |
|
341 | prev = stop; | |
348 |
|
342 | |||
349 | // given position is actually a stop position? |
|
343 | // given position is actually a stop position? | |
350 | if (pos == stop.first) { |
|
344 | if (pos == stop.first) { | |
351 | //qDebug() << "stop color" << pos; |
|
345 | //qDebug() << "stop color" << pos; | |
352 | return stop.second; |
|
346 | return stop.second; | |
353 | } |
|
347 | } | |
354 | } |
|
348 | } | |
355 |
|
349 | |||
356 | // find next stop relative to position |
|
350 | // find next stop relative to position | |
357 | QGradientStop next = stops.last(); |
|
351 | QGradientStop next = stops.last(); | |
358 | for (int i=count-1; i>=0; i--) { |
|
352 | for (int i=count-1; i>=0; i--) { | |
359 | QGradientStop stop = stops.at(i); |
|
353 | QGradientStop stop = stops.at(i); | |
360 | if (pos < stop.first) |
|
354 | if (pos < stop.first) | |
361 | next = stop; |
|
355 | next = stop; | |
362 | } |
|
356 | } | |
363 |
|
357 | |||
364 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
358 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
365 |
|
359 | |||
366 | qreal range = next.first - prev.first; |
|
360 | qreal range = next.first - prev.first; | |
367 | qreal posDelta = pos - prev.first; |
|
361 | qreal posDelta = pos - prev.first; | |
368 | qreal relativePos = posDelta / range; |
|
362 | qreal relativePos = posDelta / range; | |
369 |
|
363 | |||
370 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
364 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
371 |
|
365 | |||
372 | return colorAt(prev.second, next.second, relativePos); |
|
366 | return colorAt(prev.second, next.second, relativePos); | |
373 | } |
|
367 | } | |
374 |
|
368 | |||
375 | QTCOMMERCIALCHART_END_NAMESPACE |
|
369 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,391 +1,392 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "qlegend.h" |
|
3 | #include "qlegend.h" | |
4 | #include "chartpresenter_p.h" |
|
4 | #include "chartpresenter_p.h" | |
5 | #include "chartdataset_p.h" |
|
5 | #include "chartdataset_p.h" | |
6 | #include "chartbackground_p.h" |
|
6 | #include "chartbackground_p.h" | |
7 | #include <QGraphicsScene> |
|
7 | #include <QGraphicsScene> | |
8 | #include <QGraphicsSceneResizeEvent> |
|
8 | #include <QGraphicsSceneResizeEvent> | |
9 | #include <QDebug> |
|
9 | #include <QDebug> | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | /*! |
|
13 | /*! | |
14 | \enum QChart::ChartTheme |
|
14 | \enum QChart::ChartTheme | |
15 |
|
15 | |||
16 | This enum describes the theme used by the chart. |
|
16 | This enum describes the theme used by the chart. | |
17 |
|
17 | |||
18 | \value ChartThemeDefault Follows the GUI style of the Operating System |
|
18 | \value ChartThemeDefault Follows the GUI style of the Operating System | |
19 |
\value ChartTheme |
|
19 | \value ChartThemeLight | |
|
20 | \value ChartThemeBlueCerulean | |||
|
21 | \value ChartThemeDark | |||
|
22 | \value ChartThemeBrownSand | |||
|
23 | \value ChartThemeBlueNcs | |||
20 | \value ChartThemeIcy |
|
24 | \value ChartThemeIcy | |
21 | \value ChartThemeGrayscale |
|
|||
22 | \value ChartThemeScientific |
|
25 | \value ChartThemeScientific | |
23 | \value ChartThemeBlueCerulean |
|
|||
24 | \value ChartThemeLight |
|
|||
25 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
26 | \value ChartThemeCount Not really a theme; the total count of themes. | |
26 | */ |
|
27 | */ | |
27 |
|
28 | |||
28 | /*! |
|
29 | /*! | |
29 | \enum QChart::AnimationOption |
|
30 | \enum QChart::AnimationOption | |
30 |
|
31 | |||
31 | For enabling/disabling animations. Defaults to NoAnimation. |
|
32 | For enabling/disabling animations. Defaults to NoAnimation. | |
32 |
|
33 | |||
33 | \value NoAnimation |
|
34 | \value NoAnimation | |
34 | \value GridAxisAnimations |
|
35 | \value GridAxisAnimations | |
35 | \value SeriesAnimations |
|
36 | \value SeriesAnimations | |
36 | \value AllAnimations |
|
37 | \value AllAnimations | |
37 | */ |
|
38 | */ | |
38 |
|
39 | |||
39 | /*! |
|
40 | /*! | |
40 | \class QChart |
|
41 | \class QChart | |
41 | \brief QtCommercial chart API. |
|
42 | \brief QtCommercial chart API. | |
42 |
|
43 | |||
43 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
44 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
44 | representation of different types of QChartSeries and other chart related objects like |
|
45 | representation of different types of QChartSeries and other chart related objects like | |
45 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
46 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
46 | convenience class QChartView instead of QChart. |
|
47 | convenience class QChartView instead of QChart. | |
47 | \sa QChartView |
|
48 | \sa QChartView | |
48 | */ |
|
49 | */ | |
49 |
|
50 | |||
50 | /*! |
|
51 | /*! | |
51 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
52 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
52 | */ |
|
53 | */ | |
53 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
54 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
54 | m_backgroundItem(0), |
|
55 | m_backgroundItem(0), | |
55 | m_titleItem(0), |
|
56 | m_titleItem(0), | |
56 | m_legend(new QLegend(this)), |
|
57 | m_legend(new QLegend(this)), | |
57 | m_dataset(new ChartDataSet(this)), |
|
58 | m_dataset(new ChartDataSet(this)), | |
58 | m_presenter(new ChartPresenter(this,m_dataset)), |
|
59 | m_presenter(new ChartPresenter(this,m_dataset)), | |
59 | m_padding(50), |
|
60 | m_padding(50), | |
60 | m_backgroundPadding(10) |
|
61 | m_backgroundPadding(10) | |
61 | { |
|
62 | { | |
62 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
63 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
63 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
64 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
64 | } |
|
65 | } | |
65 |
|
66 | |||
66 | /*! |
|
67 | /*! | |
67 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
68 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
68 | */ |
|
69 | */ | |
69 | QChart::~QChart() |
|
70 | QChart::~QChart() | |
70 | { |
|
71 | { | |
71 | //delete first presenter , since this is a root of all the graphical items |
|
72 | //delete first presenter , since this is a root of all the graphical items | |
72 | delete m_presenter; |
|
73 | delete m_presenter; | |
73 | m_presenter=0; |
|
74 | m_presenter=0; | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | /*! |
|
77 | /*! | |
77 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
78 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
78 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
79 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
79 | the y axis). |
|
80 | the y axis). | |
80 | */ |
|
81 | */ | |
81 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
82 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
82 | { |
|
83 | { | |
83 | m_dataset->addSeries(series, axisY); |
|
84 | m_dataset->addSeries(series, axisY); | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | /*! |
|
87 | /*! | |
87 | Removes the \a series specified in a perameter from the QChartView. |
|
88 | Removes the \a series specified in a perameter from the QChartView. | |
88 | It releses its ownership of the specified QChartSeries object. |
|
89 | It releses its ownership of the specified QChartSeries object. | |
89 | It does not delete the pointed QChartSeries data object |
|
90 | It does not delete the pointed QChartSeries data object | |
90 | \sa addSeries(), removeAllSeries() |
|
91 | \sa addSeries(), removeAllSeries() | |
91 | */ |
|
92 | */ | |
92 | void QChart::removeSeries(QSeries* series) |
|
93 | void QChart::removeSeries(QSeries* series) | |
93 | { |
|
94 | { | |
94 | m_dataset->removeSeries(series); |
|
95 | m_dataset->removeSeries(series); | |
95 | } |
|
96 | } | |
96 |
|
97 | |||
97 | /*! |
|
98 | /*! | |
98 | Removes all the QChartSeries that have been added to the QChartView |
|
99 | Removes all the QChartSeries that have been added to the QChartView | |
99 | It also deletes the pointed QChartSeries data objects |
|
100 | It also deletes the pointed QChartSeries data objects | |
100 | \sa addSeries(), removeSeries() |
|
101 | \sa addSeries(), removeSeries() | |
101 | */ |
|
102 | */ | |
102 | void QChart::removeAllSeries() |
|
103 | void QChart::removeAllSeries() | |
103 | { |
|
104 | { | |
104 | m_dataset->removeAllSeries(); |
|
105 | m_dataset->removeAllSeries(); | |
105 | } |
|
106 | } | |
106 |
|
107 | |||
107 | /*! |
|
108 | /*! | |
108 | Sets the \a brush that is used for painting the background of the chart area. |
|
109 | Sets the \a brush that is used for painting the background of the chart area. | |
109 | */ |
|
110 | */ | |
110 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
111 | void QChart::setBackgroundBrush(const QBrush& brush) | |
111 | { |
|
112 | { | |
112 | createChartBackgroundItem(); |
|
113 | createChartBackgroundItem(); | |
113 | m_backgroundItem->setBrush(brush); |
|
114 | m_backgroundItem->setBrush(brush); | |
114 | m_backgroundItem->update(); |
|
115 | m_backgroundItem->update(); | |
115 | } |
|
116 | } | |
116 |
|
117 | |||
117 | QBrush QChart::backgroundBrush() const |
|
118 | QBrush QChart::backgroundBrush() const | |
118 | { |
|
119 | { | |
119 | if(!m_backgroundItem) return QBrush(); |
|
120 | if(!m_backgroundItem) return QBrush(); | |
120 | return m_backgroundItem->brush(); |
|
121 | return m_backgroundItem->brush(); | |
121 | } |
|
122 | } | |
122 |
|
123 | |||
123 | /*! |
|
124 | /*! | |
124 | Sets the \a pen that is used for painting the background of the chart area. |
|
125 | Sets the \a pen that is used for painting the background of the chart area. | |
125 | */ |
|
126 | */ | |
126 | void QChart::setBackgroundPen(const QPen& pen) |
|
127 | void QChart::setBackgroundPen(const QPen& pen) | |
127 | { |
|
128 | { | |
128 | createChartBackgroundItem(); |
|
129 | createChartBackgroundItem(); | |
129 | m_backgroundItem->setPen(pen); |
|
130 | m_backgroundItem->setPen(pen); | |
130 | m_backgroundItem->update(); |
|
131 | m_backgroundItem->update(); | |
131 | } |
|
132 | } | |
132 |
|
133 | |||
133 | QPen QChart::backgroundPen() const |
|
134 | QPen QChart::backgroundPen() const | |
134 | { |
|
135 | { | |
135 | if(!m_backgroundItem) return QPen(); |
|
136 | if(!m_backgroundItem) return QPen(); | |
136 | return m_backgroundItem->pen(); |
|
137 | return m_backgroundItem->pen(); | |
137 | } |
|
138 | } | |
138 |
|
139 | |||
139 | /*! |
|
140 | /*! | |
140 | Sets the chart \a title. The description text that is drawn above the chart. |
|
141 | Sets the chart \a title. The description text that is drawn above the chart. | |
141 | */ |
|
142 | */ | |
142 | void QChart::setTitle(const QString& title) |
|
143 | void QChart::setTitle(const QString& title) | |
143 | { |
|
144 | { | |
144 | createChartTitleItem(); |
|
145 | createChartTitleItem(); | |
145 | m_titleItem->setText(title); |
|
146 | m_titleItem->setText(title); | |
146 | updateLayout(); |
|
147 | updateLayout(); | |
147 | } |
|
148 | } | |
148 |
|
149 | |||
149 | /*! |
|
150 | /*! | |
150 | Returns the chart title. The description text that is drawn above the chart. |
|
151 | Returns the chart title. The description text that is drawn above the chart. | |
151 | */ |
|
152 | */ | |
152 | QString QChart::title() const |
|
153 | QString QChart::title() const | |
153 | { |
|
154 | { | |
154 | if(m_titleItem) |
|
155 | if(m_titleItem) | |
155 | return m_titleItem->text(); |
|
156 | return m_titleItem->text(); | |
156 | else |
|
157 | else | |
157 | return QString(); |
|
158 | return QString(); | |
158 | } |
|
159 | } | |
159 |
|
160 | |||
160 | /*! |
|
161 | /*! | |
161 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
162 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
162 | */ |
|
163 | */ | |
163 | void QChart::setTitleFont(const QFont& font) |
|
164 | void QChart::setTitleFont(const QFont& font) | |
164 | { |
|
165 | { | |
165 | createChartTitleItem(); |
|
166 | createChartTitleItem(); | |
166 | m_titleItem->setFont(font); |
|
167 | m_titleItem->setFont(font); | |
167 | updateLayout(); |
|
168 | updateLayout(); | |
168 | } |
|
169 | } | |
169 |
|
170 | |||
170 | /*! |
|
171 | /*! | |
171 | Sets the \a brush used for rendering the title text. |
|
172 | Sets the \a brush used for rendering the title text. | |
172 | */ |
|
173 | */ | |
173 | void QChart::setTitleBrush(const QBrush &brush) |
|
174 | void QChart::setTitleBrush(const QBrush &brush) | |
174 | { |
|
175 | { | |
175 | createChartTitleItem(); |
|
176 | createChartTitleItem(); | |
176 | m_titleItem->setBrush(brush); |
|
177 | m_titleItem->setBrush(brush); | |
177 | updateLayout(); |
|
178 | updateLayout(); | |
178 | } |
|
179 | } | |
179 |
|
180 | |||
180 | /*! |
|
181 | /*! | |
181 | Returns the brush used for rendering the title text. |
|
182 | Returns the brush used for rendering the title text. | |
182 | */ |
|
183 | */ | |
183 | QBrush QChart::titleBrush() const |
|
184 | QBrush QChart::titleBrush() const | |
184 | { |
|
185 | { | |
185 | if(!m_titleItem) return QBrush(); |
|
186 | if(!m_titleItem) return QBrush(); | |
186 | return m_titleItem->brush(); |
|
187 | return m_titleItem->brush(); | |
187 | } |
|
188 | } | |
188 |
|
189 | |||
189 | void QChart::createChartBackgroundItem() |
|
190 | void QChart::createChartBackgroundItem() | |
190 | { |
|
191 | { | |
191 | if(!m_backgroundItem) { |
|
192 | if(!m_backgroundItem) { | |
192 | m_backgroundItem = new ChartBackground(this); |
|
193 | m_backgroundItem = new ChartBackground(this); | |
193 | m_backgroundItem->setPen(Qt::NoPen); |
|
194 | m_backgroundItem->setPen(Qt::NoPen); | |
194 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
195 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
195 | } |
|
196 | } | |
196 | } |
|
197 | } | |
197 |
|
198 | |||
198 | void QChart::createChartTitleItem() |
|
199 | void QChart::createChartTitleItem() | |
199 | { |
|
200 | { | |
200 | if(!m_titleItem) { |
|
201 | if(!m_titleItem) { | |
201 | m_titleItem = new QGraphicsSimpleTextItem(this); |
|
202 | m_titleItem = new QGraphicsSimpleTextItem(this); | |
202 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
203 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
203 | } |
|
204 | } | |
204 | } |
|
205 | } | |
205 |
|
206 | |||
206 | /*! |
|
207 | /*! | |
207 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
208 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
208 | \sa ChartTheme, chartTheme() |
|
209 | \sa ChartTheme, chartTheme() | |
209 | */ |
|
210 | */ | |
210 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
211 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
211 | { |
|
212 | { | |
212 | m_presenter->setChartTheme(theme); |
|
213 | m_presenter->setChartTheme(theme); | |
213 | } |
|
214 | } | |
214 |
|
215 | |||
215 | /*! |
|
216 | /*! | |
216 | Returns the theme enum used by the chart. |
|
217 | Returns the theme enum used by the chart. | |
217 | \sa ChartTheme, setChartTheme() |
|
218 | \sa ChartTheme, setChartTheme() | |
218 | */ |
|
219 | */ | |
219 | QChart::ChartTheme QChart::chartTheme() const |
|
220 | QChart::ChartTheme QChart::chartTheme() const | |
220 | { |
|
221 | { | |
221 | return m_presenter->chartTheme(); |
|
222 | return m_presenter->chartTheme(); | |
222 | } |
|
223 | } | |
223 |
|
224 | |||
224 | /*! |
|
225 | /*! | |
225 | Zooms in the view by a factor of 2 |
|
226 | Zooms in the view by a factor of 2 | |
226 | */ |
|
227 | */ | |
227 | void QChart::zoomIn() |
|
228 | void QChart::zoomIn() | |
228 | { |
|
229 | { | |
229 | m_presenter->zoomIn(); |
|
230 | m_presenter->zoomIn(); | |
230 | } |
|
231 | } | |
231 |
|
232 | |||
232 | /*! |
|
233 | /*! | |
233 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
234 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
234 | */ |
|
235 | */ | |
235 | void QChart::zoomIn(const QRectF& rect) |
|
236 | void QChart::zoomIn(const QRectF& rect) | |
236 | { |
|
237 | { | |
237 |
|
238 | |||
238 | if(!rect.isValid()) return; |
|
239 | if(!rect.isValid()) return; | |
239 | m_presenter->zoomIn(rect); |
|
240 | m_presenter->zoomIn(rect); | |
240 | } |
|
241 | } | |
241 |
|
242 | |||
242 | /*! |
|
243 | /*! | |
243 | Restores the view zoom level to the previous one. |
|
244 | Restores the view zoom level to the previous one. | |
244 | */ |
|
245 | */ | |
245 | void QChart::zoomOut() |
|
246 | void QChart::zoomOut() | |
246 | { |
|
247 | { | |
247 | m_presenter->zoomOut(); |
|
248 | m_presenter->zoomOut(); | |
248 | } |
|
249 | } | |
249 |
|
250 | |||
250 | /*! |
|
251 | /*! | |
251 | Returns the pointer to the x axis object of the chart |
|
252 | Returns the pointer to the x axis object of the chart | |
252 | */ |
|
253 | */ | |
253 | QChartAxis* QChart::axisX() const |
|
254 | QChartAxis* QChart::axisX() const | |
254 | { |
|
255 | { | |
255 | return m_dataset->axisX(); |
|
256 | return m_dataset->axisX(); | |
256 | } |
|
257 | } | |
257 |
|
258 | |||
258 | /*! |
|
259 | /*! | |
259 | Returns the pointer to the y axis object of the chart |
|
260 | Returns the pointer to the y axis object of the chart | |
260 | */ |
|
261 | */ | |
261 | QChartAxis* QChart::axisY() const |
|
262 | QChartAxis* QChart::axisY() const | |
262 | { |
|
263 | { | |
263 | return m_dataset->axisY(); |
|
264 | return m_dataset->axisY(); | |
264 | } |
|
265 | } | |
265 |
|
266 | |||
266 | /*! |
|
267 | /*! | |
267 | Returns the legend object of the chart. Ownership stays in chart. |
|
268 | Returns the legend object of the chart. Ownership stays in chart. | |
268 | */ |
|
269 | */ | |
269 | QLegend* QChart::legend() const |
|
270 | QLegend* QChart::legend() const | |
270 | { |
|
271 | { | |
271 | return m_legend; |
|
272 | return m_legend; | |
272 | } |
|
273 | } | |
273 |
|
274 | |||
274 | /*! |
|
275 | /*! | |
275 | Resizes and updates the chart area using the \a event data |
|
276 | Resizes and updates the chart area using the \a event data | |
276 | */ |
|
277 | */ | |
277 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
278 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
278 | { |
|
279 | { | |
279 |
|
280 | |||
280 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
281 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
281 | updateLayout(); |
|
282 | updateLayout(); | |
282 | QGraphicsWidget::resizeEvent(event); |
|
283 | QGraphicsWidget::resizeEvent(event); | |
283 | update(); |
|
284 | update(); | |
284 | } |
|
285 | } | |
285 |
|
286 | |||
286 | /*! |
|
287 | /*! | |
287 | Sets animation \a options for the chart |
|
288 | Sets animation \a options for the chart | |
288 | */ |
|
289 | */ | |
289 | void QChart::setAnimationOptions(AnimationOptions options) |
|
290 | void QChart::setAnimationOptions(AnimationOptions options) | |
290 | { |
|
291 | { | |
291 | m_presenter->setAnimationOptions(options); |
|
292 | m_presenter->setAnimationOptions(options); | |
292 | } |
|
293 | } | |
293 |
|
294 | |||
294 | /*! |
|
295 | /*! | |
295 | Returns animation options for the chart |
|
296 | Returns animation options for the chart | |
296 | */ |
|
297 | */ | |
297 | QChart::AnimationOptions QChart::animationOptions() const |
|
298 | QChart::AnimationOptions QChart::animationOptions() const | |
298 | { |
|
299 | { | |
299 | return m_presenter->animationOptions(); |
|
300 | return m_presenter->animationOptions(); | |
300 | } |
|
301 | } | |
301 |
|
302 | |||
302 | void QChart::scrollLeft() |
|
303 | void QChart::scrollLeft() | |
303 | { |
|
304 | { | |
304 | m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
305 | m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
305 | } |
|
306 | } | |
306 |
|
307 | |||
307 | void QChart::scrollRight() |
|
308 | void QChart::scrollRight() | |
308 | { |
|
309 | { | |
309 | m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
310 | m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
310 | } |
|
311 | } | |
311 | void QChart::scrollUp() |
|
312 | void QChart::scrollUp() | |
312 | { |
|
313 | { | |
313 | m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
314 | m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
314 | } |
|
315 | } | |
315 | void QChart::scrollDown() |
|
316 | void QChart::scrollDown() | |
316 | { |
|
317 | { | |
317 | m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
318 | m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
318 | } |
|
319 | } | |
319 |
|
320 | |||
320 | void QChart::updateLayout() |
|
321 | void QChart::updateLayout() | |
321 | { |
|
322 | { | |
322 | if(!m_rect.isValid()) return; |
|
323 | if(!m_rect.isValid()) return; | |
323 |
|
324 | |||
324 | QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding); |
|
325 | QRectF rect = m_rect.adjusted(m_padding,m_padding, -m_padding, -m_padding); | |
325 |
|
326 | |||
326 | // recalculate title position |
|
327 | // recalculate title position | |
327 | if (m_titleItem) { |
|
328 | if (m_titleItem) { | |
328 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
329 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
329 | m_titleItem->setPos(center.x(),m_rect.top()/2 + m_padding/2); |
|
330 | m_titleItem->setPos(center.x(),m_rect.top()/2 + m_padding/2); | |
330 | } |
|
331 | } | |
331 |
|
332 | |||
332 | //recalculate background gradient |
|
333 | //recalculate background gradient | |
333 | if (m_backgroundItem) { |
|
334 | if (m_backgroundItem) { | |
334 | m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding)); |
|
335 | m_backgroundItem->setRect(m_rect.adjusted(m_backgroundPadding,m_backgroundPadding, -m_backgroundPadding, -m_backgroundPadding)); | |
335 | } |
|
336 | } | |
336 |
|
337 | |||
337 | // recalculate legend position |
|
338 | // recalculate legend position | |
338 | if (m_legend) { |
|
339 | if (m_legend) { | |
339 | if (m_legend->parentObject() == this) { |
|
340 | if (m_legend->parentObject() == this) { | |
340 | m_legend->setMaximumSize(rect.size()); |
|
341 | m_legend->setMaximumSize(rect.size()); | |
341 | m_legend->setPos(rect.topLeft()); |
|
342 | m_legend->setPos(rect.topLeft()); | |
342 | } |
|
343 | } | |
343 | } |
|
344 | } | |
344 | } |
|
345 | } | |
345 |
|
346 | |||
346 |
|
347 | |||
347 | int QChart::padding() const |
|
348 | int QChart::padding() const | |
348 | { |
|
349 | { | |
349 | return m_padding; |
|
350 | return m_padding; | |
350 | } |
|
351 | } | |
351 |
|
352 | |||
352 | void QChart::setPadding(int padding) |
|
353 | void QChart::setPadding(int padding) | |
353 | { |
|
354 | { | |
354 | if(m_padding==padding){ |
|
355 | if(m_padding==padding){ | |
355 | m_padding = padding; |
|
356 | m_padding = padding; | |
356 | m_presenter->handleGeometryChanged(); |
|
357 | m_presenter->handleGeometryChanged(); | |
357 | updateLayout(); |
|
358 | updateLayout(); | |
358 | } |
|
359 | } | |
359 | } |
|
360 | } | |
360 |
|
361 | |||
361 | void QChart::setBackgroundPadding(int padding) |
|
362 | void QChart::setBackgroundPadding(int padding) | |
362 | { |
|
363 | { | |
363 | if(m_backgroundPadding!=padding){ |
|
364 | if(m_backgroundPadding!=padding){ | |
364 | m_backgroundPadding = padding; |
|
365 | m_backgroundPadding = padding; | |
365 | updateLayout(); |
|
366 | updateLayout(); | |
366 | } |
|
367 | } | |
367 | } |
|
368 | } | |
368 |
|
369 | |||
369 | void QChart::setBackgroundDiameter(int diameter) |
|
370 | void QChart::setBackgroundDiameter(int diameter) | |
370 | { |
|
371 | { | |
371 | createChartBackgroundItem(); |
|
372 | createChartBackgroundItem(); | |
372 | m_backgroundItem->setDimeter(diameter); |
|
373 | m_backgroundItem->setDimeter(diameter); | |
373 | m_backgroundItem->update(); |
|
374 | m_backgroundItem->update(); | |
374 | } |
|
375 | } | |
375 |
|
376 | |||
376 | void QChart::setBackgroundVisible(bool visible) |
|
377 | void QChart::setBackgroundVisible(bool visible) | |
377 | { |
|
378 | { | |
378 | createChartBackgroundItem(); |
|
379 | createChartBackgroundItem(); | |
379 | m_backgroundItem->setVisible(visible); |
|
380 | m_backgroundItem->setVisible(visible); | |
380 | } |
|
381 | } | |
381 |
|
382 | |||
382 | bool QChart::isBackgroundVisible() const |
|
383 | bool QChart::isBackgroundVisible() const | |
383 | { |
|
384 | { | |
384 | if(!m_backgroundItem) return false; |
|
385 | if(!m_backgroundItem) return false; | |
385 | return m_backgroundItem->isVisible(); |
|
386 | return m_backgroundItem->isVisible(); | |
386 | } |
|
387 | } | |
387 |
|
388 | |||
388 |
|
389 | |||
389 | #include "moc_qchart.cpp" |
|
390 | #include "moc_qchart.cpp" | |
390 |
|
391 | |||
391 | QTCOMMERCIALCHART_END_NAMESPACE |
|
392 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,123 +1,121 | |||||
1 | #ifndef QCHART_H |
|
1 | #ifndef QCHART_H | |
2 | #define QCHART_H |
|
2 | #define QCHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qseries.h> |
|
5 | #include <qseries.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 Axis; |
|
14 | class Axis; | |
15 | class QSeries; |
|
15 | class QSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarChartItem; |
|
17 | class BarChartItem; | |
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 | class QLegend; |
|
23 | class QLegend; | |
24 | class ChartBackground; |
|
24 | class ChartBackground; | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
27 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
28 | { |
|
28 | { | |
29 | Q_OBJECT |
|
29 | Q_OBJECT | |
30 | public: |
|
30 | public: | |
31 | enum ChartTheme { |
|
31 | enum ChartTheme { | |
32 | ChartThemeDefault, |
|
32 | ChartThemeDefault, | |
33 | ChartThemeLight, |
|
33 | ChartThemeLight, | |
34 | ChartThemeBlueCerulean, |
|
34 | ChartThemeBlueCerulean, | |
35 | ChartThemeDark, |
|
35 | ChartThemeDark, | |
36 | ChartThemeBrownSand, |
|
36 | ChartThemeBrownSand, | |
37 | ChartThemeBlueNcs, |
|
37 | ChartThemeBlueNcs, | |
38 | ChartThemeVanilla, |
|
|||
39 | ChartThemeIcy, |
|
38 | ChartThemeIcy, | |
40 | ChartThemeGrayscale, |
|
|||
41 | ChartThemeScientific, |
|
39 | ChartThemeScientific, | |
42 | ChartThemeCount |
|
40 | ChartThemeCount | |
43 | }; |
|
41 | }; | |
44 |
|
42 | |||
45 | enum AnimationOption { |
|
43 | enum AnimationOption { | |
46 | NoAnimation = 0x0, |
|
44 | NoAnimation = 0x0, | |
47 | GridAxisAnimations = 0x1, |
|
45 | GridAxisAnimations = 0x1, | |
48 | SeriesAnimations =0x2, |
|
46 | SeriesAnimations =0x2, | |
49 | AllAnimations = 0x3 |
|
47 | AllAnimations = 0x3 | |
50 | }; |
|
48 | }; | |
51 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
49 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
52 |
|
50 | |||
53 | public: |
|
51 | public: | |
54 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
52 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
55 | ~QChart(); |
|
53 | ~QChart(); | |
56 |
|
54 | |||
57 | void addSeries(QSeries* series, QChartAxis* axisY = 0); |
|
55 | void addSeries(QSeries* series, QChartAxis* axisY = 0); | |
58 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached |
|
56 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
59 | void removeAllSeries(); // deletes series and axis |
|
57 | void removeAllSeries(); // deletes series and axis | |
60 |
|
58 | |||
61 | void setChartTheme(QChart::ChartTheme theme); |
|
59 | void setChartTheme(QChart::ChartTheme theme); | |
62 | QChart::ChartTheme chartTheme() const; |
|
60 | QChart::ChartTheme chartTheme() const; | |
63 |
|
61 | |||
64 | void setTitle(const QString& title); |
|
62 | void setTitle(const QString& title); | |
65 | QString title() const; |
|
63 | QString title() const; | |
66 | void setTitleFont(const QFont& font); |
|
64 | void setTitleFont(const QFont& font); | |
67 | QFont titleFont() const; |
|
65 | QFont titleFont() const; | |
68 | void setTitleBrush(const QBrush &brush); |
|
66 | void setTitleBrush(const QBrush &brush); | |
69 | QBrush titleBrush() const; |
|
67 | QBrush titleBrush() const; | |
70 | void setBackgroundBrush(const QBrush& brush); |
|
68 | void setBackgroundBrush(const QBrush& brush); | |
71 | QBrush backgroundBrush() const; |
|
69 | QBrush backgroundBrush() const; | |
72 | void setBackgroundPen(const QPen& pen); |
|
70 | void setBackgroundPen(const QPen& pen); | |
73 | QPen backgroundPen() const; |
|
71 | QPen backgroundPen() const; | |
74 |
|
72 | |||
75 | void setBackgroundVisible(bool visible); |
|
73 | void setBackgroundVisible(bool visible); | |
76 | bool isBackgroundVisible() const; |
|
74 | bool isBackgroundVisible() const; | |
77 |
|
75 | |||
78 | void setAnimationOptions(AnimationOptions options); |
|
76 | void setAnimationOptions(AnimationOptions options); | |
79 | AnimationOptions animationOptions() const; |
|
77 | AnimationOptions animationOptions() const; | |
80 |
|
78 | |||
81 | void zoomIn(); |
|
79 | void zoomIn(); | |
82 | void zoomIn(const QRectF& rect); |
|
80 | void zoomIn(const QRectF& rect); | |
83 | void zoomOut(); |
|
81 | void zoomOut(); | |
84 | void scrollLeft(); |
|
82 | void scrollLeft(); | |
85 | void scrollRight(); |
|
83 | void scrollRight(); | |
86 | void scrollUp(); |
|
84 | void scrollUp(); | |
87 | void scrollDown(); |
|
85 | void scrollDown(); | |
88 |
|
86 | |||
89 | QChartAxis* axisX() const; |
|
87 | QChartAxis* axisX() const; | |
90 | QChartAxis* axisY() const; |
|
88 | QChartAxis* axisY() const; | |
91 |
|
89 | |||
92 | QLegend* legend() const; |
|
90 | QLegend* legend() const; | |
93 |
|
91 | |||
94 | int padding() const; |
|
92 | int padding() const; | |
95 |
|
93 | |||
96 | protected: |
|
94 | protected: | |
97 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
95 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
98 |
|
96 | |||
99 | private: |
|
97 | private: | |
100 | inline void createChartBackgroundItem(); |
|
98 | inline void createChartBackgroundItem(); | |
101 | inline void createChartTitleItem(); |
|
99 | inline void createChartTitleItem(); | |
102 | void setPadding(int padding); |
|
100 | void setPadding(int padding); | |
103 | void setBackgroundPadding(int padding); |
|
101 | void setBackgroundPadding(int padding); | |
104 | void setBackgroundDiameter(int diameter); |
|
102 | void setBackgroundDiameter(int diameter); | |
105 | void updateLayout(); |
|
103 | void updateLayout(); | |
106 |
|
104 | |||
107 | private: |
|
105 | private: | |
108 | Q_DISABLE_COPY(QChart) |
|
106 | Q_DISABLE_COPY(QChart) | |
109 | ChartBackground* m_backgroundItem; |
|
107 | ChartBackground* m_backgroundItem; | |
110 | QGraphicsSimpleTextItem* m_titleItem; |
|
108 | QGraphicsSimpleTextItem* m_titleItem; | |
111 | QRectF m_rect; |
|
109 | QRectF m_rect; | |
112 | QLegend* m_legend; |
|
110 | QLegend* m_legend; | |
113 | ChartDataSet *m_dataset; |
|
111 | ChartDataSet *m_dataset; | |
114 | ChartPresenter *m_presenter; |
|
112 | ChartPresenter *m_presenter; | |
115 | int m_padding; |
|
113 | int m_padding; | |
116 | int m_backgroundPadding; |
|
114 | int m_backgroundPadding; | |
117 | }; |
|
115 | }; | |
118 |
|
116 | |||
119 | QTCOMMERCIALCHART_END_NAMESPACE |
|
117 | QTCOMMERCIALCHART_END_NAMESPACE | |
120 |
|
118 | |||
121 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
119 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
122 |
|
120 | |||
123 | #endif |
|
121 | #endif |
@@ -1,149 +1,147 | |||||
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 | win32-msvc*: LIBS += User32.lib |
|
7 | win32-msvc*: LIBS += User32.lib | |
8 | CONFIG += debug_and_release |
|
8 | CONFIG += debug_and_release | |
9 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
9 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
10 | SOURCES += \ |
|
10 | SOURCES += \ | |
11 | chartdataset.cpp \ |
|
11 | chartdataset.cpp \ | |
12 | chartpresenter.cpp \ |
|
12 | chartpresenter.cpp \ | |
13 | charttheme.cpp \ |
|
13 | charttheme.cpp \ | |
14 | domain.cpp \ |
|
14 | domain.cpp \ | |
15 | qchart.cpp \ |
|
15 | qchart.cpp \ | |
16 | qchartview.cpp \ |
|
16 | qchartview.cpp \ | |
17 | qseries.cpp \ |
|
17 | qseries.cpp \ | |
18 | qlegend.cpp \ |
|
18 | qlegend.cpp \ | |
19 | legendmarker.cpp \ |
|
19 | legendmarker.cpp \ | |
20 | chartbackground.cpp \ |
|
20 | chartbackground.cpp \ | |
21 | chart.cpp |
|
21 | chart.cpp | |
22 | PRIVATE_HEADERS += \ |
|
22 | PRIVATE_HEADERS += \ | |
23 | chartdataset_p.h \ |
|
23 | chartdataset_p.h \ | |
24 | chartitem_p.h \ |
|
24 | chartitem_p.h \ | |
25 | chartpresenter_p.h \ |
|
25 | chartpresenter_p.h \ | |
26 | charttheme_p.h \ |
|
26 | charttheme_p.h \ | |
27 | domain_p.h \ |
|
27 | domain_p.h \ | |
28 | legendmarker_p.h \ |
|
28 | legendmarker_p.h \ | |
29 | chartbackground_p.h \ |
|
29 | chartbackground_p.h \ | |
30 | chart_p.h |
|
30 | chart_p.h | |
31 | PUBLIC_HEADERS += \ |
|
31 | PUBLIC_HEADERS += \ | |
32 | qchart.h \ |
|
32 | qchart.h \ | |
33 | qchartglobal.h \ |
|
33 | qchartglobal.h \ | |
34 | qseries.h \ |
|
34 | qseries.h \ | |
35 | qchartview.h \ |
|
35 | qchartview.h \ | |
36 | qlegend.h |
|
36 | qlegend.h | |
37 |
|
37 | |||
38 | include(animations/animations.pri) |
|
38 | include(animations/animations.pri) | |
39 | include(axis/axis.pri) |
|
39 | include(axis/axis.pri) | |
40 | include(xychart/xychart.pri) |
|
40 | include(xychart/xychart.pri) | |
41 | include(linechart/linechart.pri) |
|
41 | include(linechart/linechart.pri) | |
42 | include(areachart/areachart.pri) |
|
42 | include(areachart/areachart.pri) | |
43 | include(barchart/barchart.pri) |
|
43 | include(barchart/barchart.pri) | |
44 | include(piechart/piechart.pri) |
|
44 | include(piechart/piechart.pri) | |
45 | include(scatterseries/scatter.pri) |
|
45 | include(scatterseries/scatter.pri) | |
46 | include(splinechart/splinechart.pri) |
|
46 | include(splinechart/splinechart.pri) | |
47 |
|
47 | |||
48 | THEMES += themes/chartthemedefault_p.h \ |
|
48 | THEMES += themes/chartthemedefault_p.h \ | |
49 | themes/chartthemelight_p.h \ |
|
49 | themes/chartthemelight_p.h \ | |
50 | themes/chartthemebluecerulean_p.h \ |
|
50 | themes/chartthemebluecerulean_p.h \ | |
51 | themes/chartthemedark_p.h \ |
|
51 | themes/chartthemedark_p.h \ | |
52 | themes/chartthemebrownsand_p.h \ |
|
52 | themes/chartthemebrownsand_p.h \ | |
53 | themes/chartthemebluencs_p.h \ |
|
53 | themes/chartthemebluencs_p.h \ | |
54 | themes/chartthemeicy_p.h \ |
|
54 | themes/chartthemeicy_p.h \ | |
55 |
themes/charttheme |
|
55 | themes/chartthemescientific_p.h | |
56 | themes/chartthemescientific_p.h \ |
|
|||
57 | themes/chartthemevanilla_p.h |
|
|||
58 |
|
56 | |||
59 | HEADERS += $$PUBLIC_HEADERS |
|
57 | HEADERS += $$PUBLIC_HEADERS | |
60 | HEADERS += $$PRIVATE_HEADERS |
|
58 | HEADERS += $$PRIVATE_HEADERS | |
61 | HEADERS += $$THEMES |
|
59 | HEADERS += $$THEMES | |
62 | INCLUDEPATH += linechart \ |
|
60 | INCLUDEPATH += linechart \ | |
63 | barchart \ |
|
61 | barchart \ | |
64 | themes \ |
|
62 | themes \ | |
65 | . |
|
63 | . | |
66 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
64 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
67 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
65 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
68 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
66 | UI_DIR = $$CHART_BUILD_DIR/lib | |
69 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
67 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
70 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
68 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
71 |
|
69 | |||
72 | #qt public headers |
|
70 | #qt public headers | |
73 | #this is very primitive and lame parser , TODO: make perl script insted |
|
71 | #this is very primitive and lame parser , TODO: make perl script insted | |
74 | !exists($$CHART_BUILD_PUBLIC_HEADER_DIR) |
|
72 | !exists($$CHART_BUILD_PUBLIC_HEADER_DIR) | |
75 | { |
|
73 | { | |
76 | system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR) |
|
74 | system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR) | |
77 | } |
|
75 | } | |
78 |
|
76 | |||
79 | for(file, PUBLIC_HEADERS) { |
|
77 | for(file, PUBLIC_HEADERS) { | |
80 | name = $$split(file,'/') |
|
78 | name = $$split(file,'/') | |
81 | name = $$last(name) |
|
79 | name = $$last(name) | |
82 | class = "$$cat($$file)" |
|
80 | class = "$$cat($$file)" | |
83 | class = $$find(class,class) |
|
81 | class = $$find(class,class) | |
84 | !isEmpty(class){ |
|
82 | !isEmpty(class){ | |
85 | class = $$split(class,QTCOMMERCIALCHART_EXPORT) |
|
83 | class = $$split(class,QTCOMMERCIALCHART_EXPORT) | |
86 | class = $$member(class,1) |
|
84 | class = $$member(class,1) | |
87 | class = $$split(class,' ') |
|
85 | class = $$split(class,' ') | |
88 | class = $$replace(class,' ','') |
|
86 | class = $$replace(class,' ','') | |
89 | class = $$member(class,0) |
|
87 | class = $$member(class,0) | |
90 | win32:{ |
|
88 | win32:{ | |
91 | command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" |
|
89 | command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" | |
92 | }else{ |
|
90 | }else{ | |
93 | command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" |
|
91 | command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" | |
94 | } |
|
92 | } | |
95 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class |
|
93 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class | |
96 | system($$command) |
|
94 | system($$command) | |
97 | } |
|
95 | } | |
98 | } |
|
96 | } | |
99 |
|
97 | |||
100 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
98 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
101 | public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS |
|
99 | public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS | |
102 |
|
100 | |||
103 | target.path = $$[QT_INSTALL_LIBS] |
|
101 | target.path = $$[QT_INSTALL_LIBS] | |
104 | INSTALLS += target public_headers |
|
102 | INSTALLS += target public_headers | |
105 |
|
103 | |||
106 | install_build_public_headers.name = build_public_headers |
|
104 | install_build_public_headers.name = build_public_headers | |
107 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
105 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
108 | install_build_public_headers.input = PUBLIC_HEADERS |
|
106 | install_build_public_headers.input = PUBLIC_HEADERS | |
109 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
107 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
110 | ${QMAKE_FILE_NAME} \ |
|
108 | ${QMAKE_FILE_NAME} \ | |
111 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
109 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
112 | install_build_public_headers.CONFIG += target_predeps \ |
|
110 | install_build_public_headers.CONFIG += target_predeps \ | |
113 | no_link |
|
111 | no_link | |
114 |
|
112 | |||
115 | install_build_private_headers.name = buld_private_headers |
|
113 | install_build_private_headers.name = buld_private_headers | |
116 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
114 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
117 | install_build_private_headers.input = PRIVATE_HEADERS |
|
115 | install_build_private_headers.input = PRIVATE_HEADERS | |
118 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
116 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
119 | ${QMAKE_FILE_NAME} \ |
|
117 | ${QMAKE_FILE_NAME} \ | |
120 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
118 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
121 | install_build_private_headers.CONFIG += target_predeps \ |
|
119 | install_build_private_headers.CONFIG += target_predeps \ | |
122 | no_link |
|
120 | no_link | |
123 |
|
121 | |||
124 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
122 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
125 | install_build_private_headers \ |
|
123 | install_build_private_headers \ | |
126 |
|
124 | |||
127 | chartversion.target = qchartversion_p.h |
|
125 | chartversion.target = qchartversion_p.h | |
128 | chartversion.commands = @echo \ |
|
126 | chartversion.commands = @echo \ | |
129 | "build_time" \ |
|
127 | "build_time" \ | |
130 | > \ |
|
128 | > \ | |
131 | $$chartversion.target; |
|
129 | $$chartversion.target; | |
132 | chartversion.depends = $$HEADERS \ |
|
130 | chartversion.depends = $$HEADERS \ | |
133 | $$SOURCES |
|
131 | $$SOURCES | |
134 | PRE_TARGETDEPS += qchartversion_p.h |
|
132 | PRE_TARGETDEPS += qchartversion_p.h | |
135 | QMAKE_CLEAN += qchartversion_p.h |
|
133 | QMAKE_CLEAN += qchartversion_p.h | |
136 | QMAKE_EXTRA_TARGETS += chartversion |
|
134 | QMAKE_EXTRA_TARGETS += chartversion | |
137 | unix:QMAKE_DISTCLEAN += -r \ |
|
135 | unix:QMAKE_DISTCLEAN += -r \ | |
138 | $$CHART_BUILD_HEADER_DIR \ |
|
136 | $$CHART_BUILD_HEADER_DIR \ | |
139 | $$CHART_BUILD_LIB_DIR |
|
137 | $$CHART_BUILD_LIB_DIR | |
140 | win32:QMAKE_DISTCLEAN += /Q \ |
|
138 | win32:QMAKE_DISTCLEAN += /Q \ | |
141 | $$CHART_BUILD_HEADER_DIR \ |
|
139 | $$CHART_BUILD_HEADER_DIR \ | |
142 | $$CHART_BUILD_LIB_DIR |
|
140 | $$CHART_BUILD_LIB_DIR | |
143 |
|
141 | |||
144 | # treat warnings as errors |
|
142 | # treat warnings as errors | |
145 | win32-msvc*: { |
|
143 | win32-msvc*: { | |
146 | QMAKE_CXXFLAGS += /WX |
|
144 | QMAKE_CXXFLAGS += /WX | |
147 | } else { |
|
145 | } else { | |
148 | QMAKE_CXXFLAGS += -Werror |
|
146 | QMAKE_CXXFLAGS += -Werror | |
149 | } |
|
147 | } |
@@ -1,36 +1,37 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeBlueCerulean: public ChartTheme |
|
5 | class ChartThemeBlueCerulean: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeBlueCerulean() : ChartTheme(QChart::ChartThemeBlueCerulean) |
|
8 | ChartThemeBlueCerulean() : ChartTheme(QChart::ChartThemeBlueCerulean) | |
9 | { |
|
9 | { | |
10 | // Series colors |
|
10 | // Series colors | |
11 | m_seriesColors << QRgb(0xc7e85b); |
|
11 | m_seriesColors << QRgb(0xc7e85b); | |
12 | m_seriesColors << QRgb(0x1cb54f); |
|
12 | m_seriesColors << QRgb(0x1cb54f); | |
13 | m_seriesColors << QRgb(0x5cbf9b); |
|
13 | m_seriesColors << QRgb(0x5cbf9b); | |
14 | m_seriesColors << QRgb(0x009fbf); |
|
14 | m_seriesColors << QRgb(0x009fbf); | |
15 | m_seriesColors << QRgb(0xee7392); |
|
15 | m_seriesColors << QRgb(0xee7392); | |
16 | generateSeriesGradients(); |
|
16 | generateSeriesGradients(); | |
17 |
|
17 | |||
18 | // Background |
|
18 | // Background | |
19 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
|
19 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); | |
20 | backgroundGradient.setColorAt(0.0, QRgb(0x056189)); |
|
20 | backgroundGradient.setColorAt(0.0, QRgb(0x056189)); | |
21 | backgroundGradient.setColorAt(1.0, QRgb(0x101a31)); |
|
21 | backgroundGradient.setColorAt(1.0, QRgb(0x101a31)); | |
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
23 | m_chartBackgroundGradient = backgroundGradient; |
|
23 | m_chartBackgroundGradient = backgroundGradient; | |
24 |
|
24 | |||
25 | // Axes and other |
|
25 | // Axes and other | |
26 | m_masterFont = QFont("arial"); |
|
26 | m_masterFont = QFont("arial"); | |
27 | m_titleBrush = QBrush(QRgb(0xffffff)); |
|
27 | m_titleBrush = QBrush(QRgb(0xffffff)); | |
28 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); |
|
28 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); | |
29 | m_axisLinePen.setWidth(2); |
|
29 | m_axisLinePen.setWidth(2); | |
30 | m_axisLabelBrush = QBrush(QRgb(0xffffff)); |
|
30 | m_axisLabelBrush = QBrush(QRgb(0xffffff)); | |
31 | m_gridLinePen = QPen(QRgb(0x84a2b0)); |
|
31 | m_gridLinePen = QPen(QRgb(0x84a2b0)); | |
32 | m_gridLinePen.setWidth(1); |
|
32 | m_gridLinePen.setWidth(1); | |
|
33 | m_backgroundShades = BackgroundShadesNone; | |||
33 | } |
|
34 | } | |
34 | }; |
|
35 | }; | |
35 |
|
36 | |||
36 | QTCOMMERCIALCHART_END_NAMESPACE |
|
37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,37 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeBlueNcs: public ChartTheme |
|
5 | class ChartThemeBlueNcs: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeBlueNcs() : ChartTheme(QChart::ChartThemeBlueNcs) |
|
8 | ChartThemeBlueNcs() : ChartTheme(QChart::ChartThemeBlueNcs) | |
9 | { |
|
9 | { | |
10 | // Series colors |
|
10 | // Series colors | |
11 | m_seriesColors << QRgb(0x1db0da); |
|
11 | m_seriesColors << QRgb(0x1db0da); | |
12 | m_seriesColors << QRgb(0x1341a6); |
|
12 | m_seriesColors << QRgb(0x1341a6); | |
13 | m_seriesColors << QRgb(0x88d41e); |
|
13 | m_seriesColors << QRgb(0x88d41e); | |
14 | m_seriesColors << QRgb(0xff8e1a); |
|
14 | m_seriesColors << QRgb(0xff8e1a); | |
15 | m_seriesColors << QRgb(0x398ca3); |
|
15 | m_seriesColors << QRgb(0x398ca3); | |
16 | generateSeriesGradients(); |
|
16 | generateSeriesGradients(); | |
17 |
|
17 | |||
18 | // Background |
|
18 | // Background | |
19 | QLinearGradient backgroundGradient; |
|
19 | QLinearGradient backgroundGradient; | |
20 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
20 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
21 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
21 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
23 | m_chartBackgroundGradient = backgroundGradient; |
|
23 | m_chartBackgroundGradient = backgroundGradient; | |
24 |
|
24 | |||
25 | // Axes and other |
|
25 | // Axes and other | |
26 | m_masterFont = QFont("arial"); |
|
26 | m_masterFont = QFont("arial"); | |
27 | m_titleBrush = QBrush(QRgb(0x404044)); |
|
27 | m_titleBrush = QBrush(QRgb(0x404044)); | |
28 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); |
|
28 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); | |
29 | m_axisLinePen.setWidth(2); |
|
29 | m_axisLinePen.setWidth(2); | |
30 | m_axisLabelBrush = QBrush(QRgb(0x404044)); |
|
30 | m_axisLabelBrush = QBrush(QRgb(0x404044)); | |
31 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
31 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
32 | m_gridLinePen.setWidth(1); |
|
32 | m_gridLinePen.setWidth(1); | |
|
33 | m_backgroundShades = BackgroundShadesNone; | |||
33 | } |
|
34 | } | |
34 | }; |
|
35 | }; | |
35 |
|
36 | |||
36 | QTCOMMERCIALCHART_END_NAMESPACE |
|
37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,37 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeBrownSand: public ChartTheme |
|
5 | class ChartThemeBrownSand: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeBrownSand() : ChartTheme(QChart::ChartThemeBrownSand) |
|
8 | ChartThemeBrownSand() : ChartTheme(QChart::ChartThemeBrownSand) | |
9 | { |
|
9 | { | |
10 | // Series colors |
|
10 | // Series colors | |
11 | m_seriesColors << QRgb(0xb39b72); |
|
11 | m_seriesColors << QRgb(0xb39b72); | |
12 | m_seriesColors << QRgb(0xb3b376); |
|
12 | m_seriesColors << QRgb(0xb3b376); | |
13 | m_seriesColors << QRgb(0xc35660); |
|
13 | m_seriesColors << QRgb(0xc35660); | |
14 | m_seriesColors << QRgb(0x536780); |
|
14 | m_seriesColors << QRgb(0x536780); | |
15 | m_seriesColors << QRgb(0x494345); |
|
15 | m_seriesColors << QRgb(0x494345); | |
16 | generateSeriesGradients(); |
|
16 | generateSeriesGradients(); | |
17 |
|
17 | |||
18 | // Background |
|
18 | // Background | |
19 | QLinearGradient backgroundGradient; |
|
19 | QLinearGradient backgroundGradient; | |
20 | backgroundGradient.setColorAt(0.0, QRgb(0xf3ece0)); |
|
20 | backgroundGradient.setColorAt(0.0, QRgb(0xf3ece0)); | |
21 | backgroundGradient.setColorAt(1.0, QRgb(0xf3ece0)); |
|
21 | backgroundGradient.setColorAt(1.0, QRgb(0xf3ece0)); | |
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
23 | m_chartBackgroundGradient = backgroundGradient; |
|
23 | m_chartBackgroundGradient = backgroundGradient; | |
24 |
|
24 | |||
25 | // Axes and other |
|
25 | // Axes and other | |
26 | m_masterFont = QFont("arial"); |
|
26 | m_masterFont = QFont("arial"); | |
27 | m_titleBrush = QBrush(QRgb(0x404044)); |
|
27 | m_titleBrush = QBrush(QRgb(0x404044)); | |
28 | m_axisLinePen = QPen(QRgb(0xb5b0a7)); |
|
28 | m_axisLinePen = QPen(QRgb(0xb5b0a7)); | |
29 | m_axisLinePen.setWidth(2); |
|
29 | m_axisLinePen.setWidth(2); | |
30 | m_axisLabelBrush = QBrush(QRgb(0x404044)); |
|
30 | m_axisLabelBrush = QBrush(QRgb(0x404044)); | |
31 | m_gridLinePen = QPen(QRgb(0xd4cec3)); |
|
31 | m_gridLinePen = QPen(QRgb(0xd4cec3)); | |
32 | m_gridLinePen.setWidth(1); |
|
32 | m_gridLinePen.setWidth(1); | |
|
33 | m_backgroundShades = BackgroundShadesNone; | |||
33 | } |
|
34 | } | |
34 | }; |
|
35 | }; | |
35 |
|
36 | |||
36 | QTCOMMERCIALCHART_END_NAMESPACE |
|
37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,37 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeDark : public ChartTheme |
|
5 | class ChartThemeDark : public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeDark() : ChartTheme(QChart::ChartThemeDark) |
|
8 | ChartThemeDark() : ChartTheme(QChart::ChartThemeDark) | |
9 | { |
|
9 | { | |
10 | // Series colors |
|
10 | // Series colors | |
11 | m_seriesColors << QRgb(0x38ad6b); |
|
11 | m_seriesColors << QRgb(0x38ad6b); | |
12 | m_seriesColors << QRgb(0x3c84a7); |
|
12 | m_seriesColors << QRgb(0x3c84a7); | |
13 | m_seriesColors << QRgb(0xeb8817); |
|
13 | m_seriesColors << QRgb(0xeb8817); | |
14 | m_seriesColors << QRgb(0x7b7f8c); |
|
14 | m_seriesColors << QRgb(0x7b7f8c); | |
15 | m_seriesColors << QRgb(0xbf593e); |
|
15 | m_seriesColors << QRgb(0xbf593e); | |
16 | generateSeriesGradients(); |
|
16 | generateSeriesGradients(); | |
17 |
|
17 | |||
18 | // Background |
|
18 | // Background | |
19 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
|
19 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); | |
20 | backgroundGradient.setColorAt(0.0, QRgb(0x2e303a)); |
|
20 | backgroundGradient.setColorAt(0.0, QRgb(0x2e303a)); | |
21 | backgroundGradient.setColorAt(1.0, QRgb(0x121218)); |
|
21 | backgroundGradient.setColorAt(1.0, QRgb(0x121218)); | |
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
23 | m_chartBackgroundGradient = backgroundGradient; |
|
23 | m_chartBackgroundGradient = backgroundGradient; | |
24 |
|
24 | |||
25 | // Axes and other |
|
25 | // Axes and other | |
26 | m_masterFont = QFont("arial"); |
|
26 | m_masterFont = QFont("arial"); | |
27 | m_titleBrush = QBrush(QRgb(0xffffff)); |
|
27 | m_titleBrush = QBrush(QRgb(0xffffff)); | |
28 | m_axisLinePen = QPen(QRgb(0x86878c)); |
|
28 | m_axisLinePen = QPen(QRgb(0x86878c)); | |
29 | m_axisLinePen.setWidth(2); |
|
29 | m_axisLinePen.setWidth(2); | |
30 | m_axisLabelBrush = QBrush(QRgb(0xffffff)); |
|
30 | m_axisLabelBrush = QBrush(QRgb(0xffffff)); | |
31 | m_gridLinePen = QPen(QRgb(0x86878c)); |
|
31 | m_gridLinePen = QPen(QRgb(0x86878c)); | |
32 | m_gridLinePen.setWidth(1); |
|
32 | m_gridLinePen.setWidth(1); | |
|
33 | m_backgroundShades = BackgroundShadesNone; | |||
33 | } |
|
34 | } | |
34 | }; |
|
35 | }; | |
35 |
|
36 | |||
36 | QTCOMMERCIALCHART_END_NAMESPACE |
|
37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,126 +1,149 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #ifdef Q_OS_WIN |
|
2 | #ifdef Q_OS_WIN | |
3 | #include <windows.h> |
|
3 | #include <windows.h> | |
4 | #include <stdio.h> |
|
4 | #include <stdio.h> | |
5 | #endif |
|
5 | #endif | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class ChartThemeDefault: public ChartTheme |
|
9 | class ChartThemeDefault: public ChartTheme | |
10 | { |
|
10 | { | |
11 | public: |
|
11 | public: | |
12 | ChartThemeDefault() : ChartTheme(QChart::ChartThemeDefault) |
|
12 | ChartThemeDefault() : ChartTheme(QChart::ChartThemeDefault) | |
13 | { |
|
13 | { | |
14 | #ifdef Q_OS_WIN |
|
14 | #ifdef Q_OS_WIN | |
15 | // TODO: use theme specific window frame color as a series base color (it would give more |
|
15 | // TODO: use theme specific window frame color as a series base color (it would give more | |
16 | // variation to the base colors in addition to the blue and black used now) |
|
16 | // variation to the base colors in addition to the blue and black used now) | |
17 | // TODO: COLOR_WINDOWTEXT for text color? |
|
17 | // TODO: COLOR_WINDOWTEXT for text color? | |
18 | // TODO: COLOR_INFOTEXT for tooltip text color? |
|
18 | // TODO: COLOR_INFOTEXT for tooltip text color? | |
19 | // TODO: COLOR_INFOBK for tooltip background color? |
|
19 | // TODO: COLOR_INFOBK for tooltip background color? | |
20 |
|
20 | |||
21 | // First series base color from COLOR_HIGHLIGHT |
|
21 | // First series base color from COLOR_HIGHLIGHT | |
22 | DWORD colorHighlight; |
|
22 | DWORD colorHighlight; | |
23 | colorHighlight = GetSysColor(COLOR_HIGHLIGHT); |
|
23 | colorHighlight = GetSysColor(COLOR_HIGHLIGHT); | |
24 | m_seriesColors.append(QColor(GetRValue(colorHighlight), |
|
24 | m_seriesColors.append(QColor(GetRValue(colorHighlight), | |
25 | GetGValue(colorHighlight), |
|
25 | GetGValue(colorHighlight), | |
26 | GetBValue(colorHighlight))); |
|
26 | GetBValue(colorHighlight))); | |
27 |
|
27 | |||
28 | // Second series base color from COLOR_WINDOWFRAME |
|
28 | // Second series base color from COLOR_WINDOWFRAME | |
29 | DWORD colorWindowFrame; |
|
29 | DWORD colorWindowFrame; | |
30 | colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); |
|
30 | colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); | |
31 | m_seriesColors.append(QColor(GetRValue(colorWindowFrame), |
|
31 | m_seriesColors.append(QColor(GetRValue(colorWindowFrame), | |
32 | GetGValue(colorWindowFrame), |
|
32 | GetGValue(colorWindowFrame), | |
33 | GetBValue(colorWindowFrame))); |
|
33 | GetBValue(colorWindowFrame))); | |
34 |
|
34 | |||
35 | // Third series base color from the middle of the COLOR_ACTIVECAPTION / |
|
35 | // Third series base color from the middle of the COLOR_ACTIVECAPTION / | |
36 | // COLOR_GRADIENTACTIVECAPTION gradient |
|
36 | // COLOR_GRADIENTACTIVECAPTION gradient | |
37 | DWORD colorGradientActiveCaptionLeft; |
|
37 | DWORD colorGradientActiveCaptionLeft; | |
38 | colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); |
|
38 | colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); | |
39 | DWORD colorGradientActiveCaptionRight; |
|
39 | DWORD colorGradientActiveCaptionRight; | |
40 | colorGradientActiveCaptionRight = GetSysColor(COLOR_GRADIENTACTIVECAPTION); |
|
40 | colorGradientActiveCaptionRight = GetSysColor(COLOR_GRADIENTACTIVECAPTION); | |
41 | QLinearGradient g; |
|
41 | QLinearGradient g; | |
42 | QColor start = QColor(GetRValue(colorGradientActiveCaptionLeft), |
|
42 | QColor start = QColor(GetRValue(colorGradientActiveCaptionLeft), | |
43 | GetGValue(colorGradientActiveCaptionLeft), |
|
43 | GetGValue(colorGradientActiveCaptionLeft), | |
44 | GetBValue(colorGradientActiveCaptionLeft)); |
|
44 | GetBValue(colorGradientActiveCaptionLeft)); | |
45 | g.setColorAt(0.0, start); |
|
45 | g.setColorAt(0.0, start); | |
46 | QColor end = QColor(GetRValue(colorGradientActiveCaptionRight), |
|
46 | QColor end = QColor(GetRValue(colorGradientActiveCaptionRight), | |
47 | GetGValue(colorGradientActiveCaptionRight), |
|
47 | GetGValue(colorGradientActiveCaptionRight), | |
48 | GetBValue(colorGradientActiveCaptionRight)); |
|
48 | GetBValue(colorGradientActiveCaptionRight)); | |
49 | g.setColorAt(1.0, end); |
|
49 | g.setColorAt(1.0, end); | |
50 | m_seriesColors.append(colorAt(g, 0.5)); |
|
50 | m_seriesColors.append(colorAt(g, 0.5)); | |
51 |
|
51 | |||
52 | // Generate gradients from the base colors |
|
52 | // Generate gradients from the base colors | |
53 | generateSeriesGradients(); |
|
53 | generateSeriesGradients(); | |
54 |
|
54 | |||
55 | // Background fill color from COLOR_WINDOW |
|
55 | // Background fill color from COLOR_WINDOW | |
56 | QLinearGradient backgroundGradient; |
|
56 | QLinearGradient backgroundGradient; | |
57 | DWORD colorWindow; |
|
57 | DWORD colorWindow; | |
58 | colorWindow = GetSysColor(COLOR_WINDOW); |
|
58 | colorWindow = GetSysColor(COLOR_WINDOW); | |
59 | backgroundGradient.setColorAt(0.0, QColor(GetRValue(colorWindow), |
|
59 | backgroundGradient.setColorAt(0.0, QColor(GetRValue(colorWindow), | |
60 | GetGValue(colorWindow), |
|
60 | GetGValue(colorWindow), | |
61 | GetBValue(colorWindow))); |
|
61 | GetBValue(colorWindow))); | |
62 | backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), |
|
62 | backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), | |
63 | GetGValue(colorWindow), |
|
63 | GetGValue(colorWindow), | |
64 | GetBValue(colorWindow))); |
|
64 | GetBValue(colorWindow))); | |
65 | // Axes and other |
|
65 | // Axes and other | |
66 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
66 | m_masterFont = QFont("arial"); | |
67 | m_backgroundShades = BackgroundShadesVertical; |
|
67 | m_axisLinePen = QPen(0xd6d6d6); | |
|
68 | m_axisLinePen.setWidth(1); | |||
|
69 | m_axisLabelBrush = QBrush(QRgb(0x404044)); | |||
|
70 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |||
|
71 | m_gridLinePen.setWidth(1); | |||
|
72 | m_backgroundShades = BackgroundShadesNone; | |||
68 |
|
73 | |||
69 | #elif defined(Q_OS_LINUX) |
|
74 | #elif defined(Q_OS_LINUX) | |
70 | // TODO: replace this dummy theme with linux specific theme |
|
75 | // TODO: replace this dummy theme with linux specific theme | |
71 | m_seriesColors << QRgb(0x60a6e6); |
|
76 | m_seriesColors << QRgb(0x60a6e6); | |
72 | m_seriesColors << QRgb(0x92ca66); |
|
77 | m_seriesColors << QRgb(0x92ca66); | |
73 | m_seriesColors << QRgb(0xeba85f); |
|
78 | m_seriesColors << QRgb(0xeba85f); | |
74 | m_seriesColors << QRgb(0xfc5751); |
|
79 | m_seriesColors << QRgb(0xfc5751); | |
75 | generateSeriesGradients(); |
|
80 | generateSeriesGradients(); | |
76 |
|
81 | |||
|
82 | // Background | |||
77 | QLinearGradient backgroundGradient; |
|
83 | QLinearGradient backgroundGradient; | |
78 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
84 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
79 |
backgroundGradient.setColorAt(1.0, QRgb(0x |
|
85 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
80 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
86 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
81 | m_chartBackgroundGradient = backgroundGradient; |
|
87 | m_chartBackgroundGradient = backgroundGradient; | |
82 |
|
88 | |||
83 | // Axes and other |
|
89 | // Axes and other | |
84 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
90 | m_masterFont = QFont("arial"); | |
85 | m_backgroundShades = BackgroundShadesVertical; |
|
91 | m_axisLinePen = QPen(0xd6d6d6); | |
|
92 | m_axisLinePen.setWidth(1); | |||
|
93 | m_axisLabelBrush = QBrush(QRgb(0x404044)); | |||
|
94 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |||
|
95 | m_gridLinePen.setWidth(1); | |||
|
96 | m_backgroundShades = BackgroundShadesNone; | |||
86 |
|
97 | |||
87 | #elif defined(Q_OS_MAC) |
|
98 | #elif defined(Q_OS_MAC) | |
88 | // TODO: replace this dummy theme with OSX specific theme |
|
99 | // TODO: replace this dummy theme with OSX specific theme | |
89 | m_seriesColors << QRgb(0x60a6e6); |
|
100 | m_seriesColors << QRgb(0x60a6e6); | |
90 | m_seriesColors << QRgb(0x92ca66); |
|
101 | m_seriesColors << QRgb(0x92ca66); | |
91 | m_seriesColors << QRgb(0xeba85f); |
|
102 | m_seriesColors << QRgb(0xeba85f); | |
92 | m_seriesColors << QRgb(0xfc5751); |
|
103 | m_seriesColors << QRgb(0xfc5751); | |
93 | generateSeriesGradients(); |
|
104 | generateSeriesGradients(); | |
94 |
|
105 | |||
|
106 | // Background | |||
95 | QLinearGradient backgroundGradient; |
|
107 | QLinearGradient backgroundGradient; | |
96 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
108 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
97 |
backgroundGradient.setColorAt(1.0, QRgb(0x |
|
109 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
98 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
110 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
99 | m_chartBackgroundGradient = backgroundGradient; |
|
111 | m_chartBackgroundGradient = backgroundGradient; | |
100 |
|
112 | |||
101 | // Axes and other |
|
113 | // Axes and other | |
102 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
114 | m_masterFont = QFont("arial"); | |
103 | m_backgroundShades = BackgroundShadesVertical; |
|
115 | m_axisLinePen = QPen(0xd6d6d6); | |
|
116 | m_axisLinePen.setWidth(1); | |||
|
117 | m_axisLabelBrush = QBrush(QRgb(0x404044)); | |||
|
118 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |||
|
119 | m_gridLinePen.setWidth(1); | |||
|
120 | m_backgroundShades = BackgroundShadesNone; | |||
104 |
|
121 | |||
105 | #else |
|
122 | #else | |
106 | // TODO: replace this dummy theme with generic (not OS specific) theme |
|
123 | // TODO: replace this dummy theme with generic (not OS specific) theme | |
107 | m_seriesColors << QRgb(0x60a6e6); |
|
124 | m_seriesColors << QRgb(0x60a6e6); | |
108 | m_seriesColors << QRgb(0x92ca66); |
|
125 | m_seriesColors << QRgb(0x92ca66); | |
109 | m_seriesColors << QRgb(0xeba85f); |
|
126 | m_seriesColors << QRgb(0xeba85f); | |
110 | m_seriesColors << QRgb(0xfc5751); |
|
127 | m_seriesColors << QRgb(0xfc5751); | |
111 | generateSeriesGradients(); |
|
128 | generateSeriesGradients(); | |
112 |
|
129 | |||
|
130 | // Background | |||
113 | QLinearGradient backgroundGradient; |
|
131 | QLinearGradient backgroundGradient; | |
114 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
132 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
115 |
backgroundGradient.setColorAt(1.0, QRgb(0x |
|
133 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
116 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
134 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
117 |
m_ |
|
135 | m_chartBackgroundGradient = backgroundGradient; | |
118 |
|
136 | |||
119 | // Axes and other |
|
137 | // Axes and other | |
120 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
138 | m_masterFont = QFont("arial"); | |
121 | m_backgroundShades = BackgroundShadesVertical; |
|
139 | m_axisLinePen = QPen(0xd6d6d6); | |
|
140 | m_axisLinePen.setWidth(1); | |||
|
141 | m_axisLabelBrush = QBrush(QRgb(0x404044)); | |||
|
142 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |||
|
143 | m_gridLinePen.setWidth(1); | |||
|
144 | m_backgroundShades = BackgroundShadesNone; | |||
122 | #endif |
|
145 | #endif | |
123 | } |
|
146 | } | |
124 | }; |
|
147 | }; | |
125 |
|
148 | |||
126 | QTCOMMERCIALCHART_END_NAMESPACE |
|
149 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,33 +1,34 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeIcy: public ChartTheme |
|
5 | class ChartThemeIcy: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeIcy() : ChartTheme(QChart::ChartThemeIcy) |
|
8 | ChartThemeIcy() : ChartTheme(QChart::ChartThemeIcy) | |
9 | { |
|
9 | { | |
10 | // Series |
|
10 | // Series | |
11 | m_seriesColors << QRgb(0x0d2673); |
|
11 | m_seriesColors << QRgb(0x0d2673); | |
12 | m_seriesColors << QRgb(0x2685bf); |
|
12 | m_seriesColors << QRgb(0x2685bf); | |
13 | m_seriesColors << QRgb(0x3dadd9); |
|
13 | m_seriesColors << QRgb(0x3dadd9); | |
14 | m_seriesColors << QRgb(0x62c3d9); |
|
14 | m_seriesColors << QRgb(0x62c3d9); | |
15 | generateSeriesGradients(); |
|
15 | generateSeriesGradients(); | |
16 |
|
16 | |||
17 | // Background |
|
17 | // Background | |
18 | QLinearGradient backgroundGradient; |
|
18 | QLinearGradient backgroundGradient; | |
19 | backgroundGradient.setColorAt(0.0, QRgb(0xebebeb)); |
|
19 | backgroundGradient.setColorAt(0.0, QRgb(0xebebeb)); | |
20 | backgroundGradient.setColorAt(1.0, QRgb(0xf8f9fb)); |
|
20 | backgroundGradient.setColorAt(1.0, QRgb(0xf8f9fb)); | |
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
22 | m_chartBackgroundGradient = backgroundGradient; |
|
22 | m_chartBackgroundGradient = backgroundGradient; | |
23 |
|
23 | |||
24 | // Axes and other |
|
24 | // Axes and other | |
25 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
25 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); | |
26 | m_axisLinePen.setWidth(2); |
|
26 | m_axisLinePen.setWidth(2); | |
27 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); |
|
27 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); | |
28 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
28 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); | |
29 | m_gridLinePen.setWidth(2); |
|
29 | m_gridLinePen.setWidth(2); | |
|
30 | m_backgroundShades = BackgroundShadesNone; | |||
30 | } |
|
31 | } | |
31 | }; |
|
32 | }; | |
32 |
|
33 | |||
33 | QTCOMMERCIALCHART_END_NAMESPACE |
|
34 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,35 +1,36 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeLight: public ChartTheme |
|
5 | class ChartThemeLight: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeLight() : ChartTheme(QChart::ChartThemeLight) |
|
8 | ChartThemeLight() : ChartTheme(QChart::ChartThemeLight) | |
9 | { |
|
9 | { | |
10 | // Series colors |
|
10 | // Series colors | |
11 | m_seriesColors << QRgb(0x209fdf); |
|
11 | m_seriesColors << QRgb(0x209fdf); | |
12 | m_seriesColors << QRgb(0x99ca53); |
|
12 | m_seriesColors << QRgb(0x99ca53); | |
13 | m_seriesColors << QRgb(0xf6a625); |
|
13 | m_seriesColors << QRgb(0xf6a625); | |
14 | m_seriesColors << QRgb(0x6d5fd5); |
|
14 | m_seriesColors << QRgb(0x6d5fd5); | |
15 | m_seriesColors << QRgb(0xbf593e); |
|
15 | m_seriesColors << QRgb(0xbf593e); | |
16 | generateSeriesGradients(); |
|
16 | generateSeriesGradients(); | |
17 |
|
17 | |||
18 | // Background |
|
18 | // Background | |
19 | QLinearGradient backgroundGradient; |
|
19 | QLinearGradient backgroundGradient; | |
20 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
20 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
21 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
21 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
23 | m_chartBackgroundGradient = backgroundGradient; |
|
23 | m_chartBackgroundGradient = backgroundGradient; | |
24 |
|
24 | |||
25 | // Axes and other |
|
25 | // Axes and other | |
26 | m_masterFont = QFont("arial"); |
|
26 | m_masterFont = QFont("arial"); | |
27 | m_axisLinePen = QPen(0xd6d6d6); |
|
27 | m_axisLinePen = QPen(0xd6d6d6); | |
28 | m_axisLinePen.setWidth(1); |
|
28 | m_axisLinePen.setWidth(1); | |
29 | m_axisLabelBrush = QBrush(QRgb(0x404044)); |
|
29 | m_axisLabelBrush = QBrush(QRgb(0x404044)); | |
30 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
30 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
31 | m_gridLinePen.setWidth(1); |
|
31 | m_gridLinePen.setWidth(1); | |
|
32 | m_backgroundShades = BackgroundShadesNone; | |||
32 | } |
|
33 | } | |
33 | }; |
|
34 | }; | |
34 |
|
35 | |||
35 | QTCOMMERCIALCHART_END_NAMESPACE |
|
36 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,35 +1,35 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeScientific: public ChartTheme |
|
5 | class ChartThemeScientific: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeScientific() : ChartTheme(QChart::ChartThemeScientific) |
|
8 | ChartThemeScientific() : ChartTheme(QChart::ChartThemeScientific) | |
9 | { |
|
9 | { | |
10 | // Series |
|
10 | // Series | |
11 | m_seriesColors << QRgb(0xFFAD00); |
|
11 | m_seriesColors << QRgb(0xFFAD00); | |
12 | m_seriesColors << QRgb(0x596A75); |
|
12 | m_seriesColors << QRgb(0x596A75); | |
13 | m_seriesColors << QRgb(0x202020); |
|
13 | m_seriesColors << QRgb(0x202020); | |
14 | m_seriesColors << QRgb(0x474747); |
|
14 | m_seriesColors << QRgb(0x474747); | |
15 | generateSeriesGradients(); |
|
15 | generateSeriesGradients(); | |
16 |
|
16 | |||
17 | // Background |
|
17 | // Background | |
18 | QLinearGradient backgroundGradient; |
|
18 | QLinearGradient backgroundGradient; | |
19 | backgroundGradient.setColorAt(0.0, QRgb(0xfffefc)); |
|
19 | backgroundGradient.setColorAt(0.0, QRgb(0xfffefc)); | |
20 | backgroundGradient.setColorAt(1.0, QRgb(0xfffefc)); |
|
20 | backgroundGradient.setColorAt(1.0, QRgb(0xfffefc)); | |
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
22 | m_chartBackgroundGradient = backgroundGradient; |
|
22 | m_chartBackgroundGradient = backgroundGradient; | |
23 |
|
23 | |||
24 | // Axes and other |
|
24 | // Axes and other | |
25 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
25 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); | |
26 | m_axisLinePen.setWidth(2); |
|
26 | m_axisLinePen.setWidth(2); | |
27 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); |
|
27 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); | |
28 | m_backgroundShadesBrush = QBrush(QColor(0xff, 0xad, 0x00, 0x50)); |
|
|||
29 | m_backgroundShades = BackgroundShadesHorizontal; |
|
|||
30 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
28 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); | |
31 | m_gridLinePen.setWidth(2); |
|
29 | m_gridLinePen.setWidth(2); | |
|
30 | m_backgroundShadesBrush = QBrush(QColor(0xff, 0xad, 0x00, 0x50)); | |||
|
31 | m_backgroundShades = BackgroundShadesHorizontal; | |||
32 | } |
|
32 | } | |
33 | }; |
|
33 | }; | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_END_NAMESPACE |
|
35 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,331 +1,333 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "dataseriedialog.h" |
|
2 | #include "dataseriedialog.h" | |
3 | #include <qpieseries.h> |
|
3 | #include <qpieseries.h> | |
4 | #include <qscatterseries.h> |
|
4 | #include <qscatterseries.h> | |
5 | #include <qlineseries.h> |
|
5 | #include <qlineseries.h> | |
6 | #include <qareaseries.h> |
|
6 | #include <qareaseries.h> | |
7 | #include <qsplineseries.h> |
|
7 | #include <qsplineseries.h> | |
8 | #include <qbarset.h> |
|
8 | #include <qbarset.h> | |
9 | #include <qbarseries.h> |
|
9 | #include <qbarseries.h> | |
10 | #include <qstackedbarseries.h> |
|
10 | #include <qstackedbarseries.h> | |
11 | #include <qpercentbarseries.h> |
|
11 | #include <qpercentbarseries.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 | m_addSerieDialog(0), |
|
30 | m_addSerieDialog(0), | |
31 | m_chartView(0) |
|
31 | m_chartView(0) | |
32 | { |
|
32 | { | |
33 | m_chartView = new QChartView(this); |
|
33 | m_chartView = new QChartView(this); | |
34 | m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand); |
|
34 | m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand); | |
35 |
|
35 | |||
36 | // Grid layout for the controls for configuring the chart widget |
|
36 | // Grid layout for the controls for configuring the chart widget | |
37 | QGridLayout *grid = new QGridLayout(); |
|
37 | QGridLayout *grid = new QGridLayout(); | |
38 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
38 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
39 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
39 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
40 | grid->addWidget(addSeriesButton, 0, 1); |
|
40 | grid->addWidget(addSeriesButton, 0, 1); | |
41 | initBackroundCombo(grid); |
|
41 | initBackroundCombo(grid); | |
42 | initScaleControls(grid); |
|
42 | initScaleControls(grid); | |
43 | initThemeCombo(grid); |
|
43 | initThemeCombo(grid); | |
44 | initCheckboxes(grid); |
|
44 | initCheckboxes(grid); | |
45 |
|
45 | |||
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 | // Add layouts and the chart widget to the main layout |
|
54 | // Add layouts and the chart widget to the main layout | |
55 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
55 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
56 | setLayout(mainLayout); |
|
56 | setLayout(mainLayout); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | // Combo box for selecting the chart's background |
|
59 | // Combo box for selecting the chart's background | |
60 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
60 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
61 | { |
|
61 | { | |
62 | QComboBox *backgroundCombo = new QComboBox(this); |
|
62 | QComboBox *backgroundCombo = new QComboBox(this); | |
63 | backgroundCombo->addItem("Color"); |
|
63 | backgroundCombo->addItem("Color"); | |
64 | backgroundCombo->addItem("Gradient"); |
|
64 | backgroundCombo->addItem("Gradient"); | |
65 | backgroundCombo->addItem("Image"); |
|
65 | backgroundCombo->addItem("Image"); | |
66 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
66 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
67 | this, SLOT(backgroundChanged(int))); |
|
67 | this, SLOT(backgroundChanged(int))); | |
68 |
|
68 | |||
69 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
69 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
70 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
70 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | // Scale related controls (auto-scale vs. manual min-max values) |
|
73 | // Scale related controls (auto-scale vs. manual min-max values) | |
74 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
74 | void MainWidget::initScaleControls(QGridLayout *grid) | |
75 | { |
|
75 | { | |
76 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
76 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
77 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
77 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
78 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
78 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
79 | m_xMinSpin = new QSpinBox(); |
|
79 | m_xMinSpin = new QSpinBox(); | |
80 | m_xMinSpin->setMinimum(INT_MIN); |
|
80 | m_xMinSpin->setMinimum(INT_MIN); | |
81 | m_xMinSpin->setMaximum(INT_MAX); |
|
81 | m_xMinSpin->setMaximum(INT_MAX); | |
82 | m_xMinSpin->setValue(0); |
|
82 | m_xMinSpin->setValue(0); | |
83 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
83 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
84 | m_xMaxSpin = new QSpinBox(); |
|
84 | m_xMaxSpin = new QSpinBox(); | |
85 | m_xMaxSpin->setMinimum(INT_MIN); |
|
85 | m_xMaxSpin->setMinimum(INT_MIN); | |
86 | m_xMaxSpin->setMaximum(INT_MAX); |
|
86 | m_xMaxSpin->setMaximum(INT_MAX); | |
87 | m_xMaxSpin->setValue(10); |
|
87 | m_xMaxSpin->setValue(10); | |
88 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
88 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
89 | m_yMinSpin = new QSpinBox(); |
|
89 | m_yMinSpin = new QSpinBox(); | |
90 | m_yMinSpin->setMinimum(INT_MIN); |
|
90 | m_yMinSpin->setMinimum(INT_MIN); | |
91 | m_yMinSpin->setMaximum(INT_MAX); |
|
91 | m_yMinSpin->setMaximum(INT_MAX); | |
92 | m_yMinSpin->setValue(0); |
|
92 | m_yMinSpin->setValue(0); | |
93 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
93 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
94 | m_yMaxSpin = new QSpinBox(); |
|
94 | m_yMaxSpin = new QSpinBox(); | |
95 | m_yMaxSpin->setMinimum(INT_MIN); |
|
95 | m_yMaxSpin->setMinimum(INT_MIN); | |
96 | m_yMaxSpin->setMaximum(INT_MAX); |
|
96 | m_yMaxSpin->setMaximum(INT_MAX); | |
97 | m_yMaxSpin->setValue(10); |
|
97 | m_yMaxSpin->setValue(10); | |
98 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
98 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
99 |
|
99 | |||
100 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
100 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
101 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
101 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
102 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
102 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
103 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
103 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
104 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
104 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
105 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
105 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
106 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
106 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
107 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
107 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
108 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
108 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
109 |
|
109 | |||
110 | m_autoScaleCheck->setChecked(true); |
|
110 | m_autoScaleCheck->setChecked(true); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | // Combo box for selecting theme |
|
113 | // Combo box for selecting theme | |
114 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
114 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
115 | { |
|
115 | { | |
116 | QComboBox *chartTheme = new QComboBox(); |
|
116 | QComboBox *chartTheme = new QComboBox(); | |
117 | chartTheme->addItem("Default"); |
|
117 | chartTheme->addItem("Default"); | |
118 |
chartTheme->addItem(" |
|
118 | chartTheme->addItem("Light"); | |
|
119 | chartTheme->addItem("Blue Cerulean"); | |||
|
120 | chartTheme->addItem("Dark"); | |||
|
121 | chartTheme->addItem("Brown Sand"); | |||
|
122 | chartTheme->addItem("Blue NCS"); | |||
119 | chartTheme->addItem("Icy"); |
|
123 | chartTheme->addItem("Icy"); | |
120 | chartTheme->addItem("Grayscale"); |
|
|||
121 | chartTheme->addItem("Scientific"); |
|
124 | chartTheme->addItem("Scientific"); | |
122 | chartTheme->addItem("Unnamed1"); |
|
|||
123 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
125 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
124 | this, SLOT(changeChartTheme(int))); |
|
126 | this, SLOT(changeChartTheme(int))); | |
125 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
127 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
126 | grid->addWidget(chartTheme, 8, 1); |
|
128 | grid->addWidget(chartTheme, 8, 1); | |
127 | } |
|
129 | } | |
128 |
|
130 | |||
129 | // Different check boxes for customizing chart |
|
131 | // Different check boxes for customizing chart | |
130 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
132 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
131 | { |
|
133 | { | |
132 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
134 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off | |
133 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
135 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
134 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
136 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); | |
135 | zoomCheckBox->setChecked(true); |
|
137 | zoomCheckBox->setChecked(true); | |
136 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
138 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
137 |
|
139 | |||
138 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
140 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); | |
139 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
141 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); | |
140 | aliasCheckBox->setChecked(false); |
|
142 | aliasCheckBox->setChecked(false); | |
141 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
143 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); | |
142 | } |
|
144 | } | |
143 |
|
145 | |||
144 | void MainWidget::antiAliasToggled(bool enabled) |
|
146 | void MainWidget::antiAliasToggled(bool enabled) | |
145 | { |
|
147 | { | |
146 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
148 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
147 | } |
|
149 | } | |
148 |
|
150 | |||
149 | void MainWidget::addSeries() |
|
151 | void MainWidget::addSeries() | |
150 | { |
|
152 | { | |
151 | if (!m_addSerieDialog) { |
|
153 | if (!m_addSerieDialog) { | |
152 | m_addSerieDialog = new DataSerieDialog(this); |
|
154 | m_addSerieDialog = new DataSerieDialog(this); | |
153 | connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)), |
|
155 | connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)), | |
154 | this, SLOT(addSeries(QString, int, int, QString, bool))); |
|
156 | this, SLOT(addSeries(QString, int, int, QString, bool))); | |
155 | } |
|
157 | } | |
156 | m_addSerieDialog->exec(); |
|
158 | m_addSerieDialog->exec(); | |
157 | } |
|
159 | } | |
158 |
|
160 | |||
159 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
161 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
160 | { |
|
162 | { | |
161 | // TODO: dataCharacteristics |
|
163 | // TODO: dataCharacteristics | |
162 | QList<RealList> testData; |
|
164 | QList<RealList> testData; | |
163 | for (int j(0); j < columnCount; j++) { |
|
165 | for (int j(0); j < columnCount; j++) { | |
164 | QList <qreal> newColumn; |
|
166 | QList <qreal> newColumn; | |
165 | for (int i(0); i < rowCount; i++) { |
|
167 | for (int i(0); i < rowCount; i++) { | |
166 | if (dataCharacteristics == "Sin") { |
|
168 | if (dataCharacteristics == "Sin") { | |
167 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
169 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
168 | } else if (dataCharacteristics == "Sin + random") { |
|
170 | } else if (dataCharacteristics == "Sin + random") { | |
169 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
171 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
170 | } else if (dataCharacteristics == "Random") { |
|
172 | } else if (dataCharacteristics == "Random") { | |
171 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
173 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); | |
172 | } else if (dataCharacteristics == "Linear") { |
|
174 | } else if (dataCharacteristics == "Linear") { | |
173 | //newColumn.append(i * (j + 1.0)); |
|
175 | //newColumn.append(i * (j + 1.0)); | |
174 | // TODO: temporary hack to make pie work; prevent zero values: |
|
176 | // TODO: temporary hack to make pie work; prevent zero values: | |
175 | newColumn.append(i * (j + 1.0) + 0.1); |
|
177 | newColumn.append(i * (j + 1.0) + 0.1); | |
176 | } else { // "constant" |
|
178 | } else { // "constant" | |
177 | newColumn.append((j + 1.0)); |
|
179 | newColumn.append((j + 1.0)); | |
178 | } |
|
180 | } | |
179 | } |
|
181 | } | |
180 | testData.append(newColumn); |
|
182 | testData.append(newColumn); | |
181 | } |
|
183 | } | |
182 | return testData; |
|
184 | return testData; | |
183 | } |
|
185 | } | |
184 |
|
186 | |||
185 | QStringList MainWidget::generateLabels(int count) |
|
187 | QStringList MainWidget::generateLabels(int count) | |
186 | { |
|
188 | { | |
187 | QStringList result; |
|
189 | QStringList result; | |
188 | for (int i(0); i < count; i++) |
|
190 | for (int i(0); i < count; i++) | |
189 | result.append("label" + QString::number(i)); |
|
191 | result.append("label" + QString::number(i)); | |
190 | return result; |
|
192 | return result; | |
191 | } |
|
193 | } | |
192 |
|
194 | |||
193 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
195 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
194 | { |
|
196 | { | |
195 | qDebug() << "addSeries: " << seriesName |
|
197 | qDebug() << "addSeries: " << seriesName | |
196 | << " columnCount: " << columnCount |
|
198 | << " columnCount: " << columnCount | |
197 | << " rowCount: " << rowCount |
|
199 | << " rowCount: " << rowCount | |
198 | << " dataCharacteristics: " << dataCharacteristics |
|
200 | << " dataCharacteristics: " << dataCharacteristics | |
199 | << " labels enabled: " << labelsEnabled; |
|
201 | << " labels enabled: " << labelsEnabled; | |
200 | m_defaultSeriesName = seriesName; |
|
202 | m_defaultSeriesName = seriesName; | |
201 |
|
203 | |||
202 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
204 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
203 |
|
205 | |||
204 | // Line series and scatter series use similar data |
|
206 | // Line series and scatter series use similar data | |
205 | if (seriesName == "Line") { |
|
207 | if (seriesName == "Line") { | |
206 | for (int j(0); j < data.count(); j ++) { |
|
208 | for (int j(0); j < data.count(); j ++) { | |
207 | QList<qreal> column = data.at(j); |
|
209 | QList<qreal> column = data.at(j); | |
208 | QLineSeries *series = new QLineSeries(); |
|
210 | QLineSeries *series = new QLineSeries(); | |
209 | for (int i(0); i < column.count(); i++) { |
|
211 | for (int i(0); i < column.count(); i++) { | |
210 | series->add(i, column.at(i)); |
|
212 | series->add(i, column.at(i)); | |
211 | } |
|
213 | } | |
212 | m_chartView->addSeries(series); |
|
214 | m_chartView->addSeries(series); | |
213 | } |
|
215 | } | |
214 | } else if (seriesName == "Area") { |
|
216 | } else if (seriesName == "Area") { | |
215 | // TODO: lower series for the area? |
|
217 | // TODO: lower series for the area? | |
216 | for (int j(0); j < data.count(); j ++) { |
|
218 | for (int j(0); j < data.count(); j ++) { | |
217 | QList<qreal> column = data.at(j); |
|
219 | QList<qreal> column = data.at(j); | |
218 | QLineSeries *lineSeries = new QLineSeries(); |
|
220 | QLineSeries *lineSeries = new QLineSeries(); | |
219 | for (int i(0); i < column.count(); i++) { |
|
221 | for (int i(0); i < column.count(); i++) { | |
220 | lineSeries->add(i, column.at(i)); |
|
222 | lineSeries->add(i, column.at(i)); | |
221 | } |
|
223 | } | |
222 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
224 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); | |
223 | m_chartView->addSeries(areaSeries); |
|
225 | m_chartView->addSeries(areaSeries); | |
224 | } |
|
226 | } | |
225 | } else if (seriesName == "Scatter") { |
|
227 | } else if (seriesName == "Scatter") { | |
226 | for (int j(0); j < data.count(); j++) { |
|
228 | for (int j(0); j < data.count(); j++) { | |
227 | QList<qreal> column = data.at(j); |
|
229 | QList<qreal> column = data.at(j); | |
228 | QScatterSeries *series = new QScatterSeries(); |
|
230 | QScatterSeries *series = new QScatterSeries(); | |
229 | for (int i(0); i < column.count(); i++) { |
|
231 | for (int i(0); i < column.count(); i++) { | |
230 | (*series) << QPointF(i, column.at(i)); |
|
232 | (*series) << QPointF(i, column.at(i)); | |
231 | } |
|
233 | } | |
232 | m_chartView->addSeries(series); |
|
234 | m_chartView->addSeries(series); | |
233 | } |
|
235 | } | |
234 | } else if (seriesName == "Pie") { |
|
236 | } else if (seriesName == "Pie") { | |
235 | QStringList labels = generateLabels(rowCount); |
|
237 | QStringList labels = generateLabels(rowCount); | |
236 | for (int j(0); j < data.count(); j++) { |
|
238 | for (int j(0); j < data.count(); j++) { | |
237 | QPieSeries *series = new QPieSeries(); |
|
239 | QPieSeries *series = new QPieSeries(); | |
238 | QList<qreal> column = data.at(j); |
|
240 | QList<qreal> column = data.at(j); | |
239 | for (int i(0); i < column.count(); i++) { |
|
241 | for (int i(0); i < column.count(); i++) { | |
240 | series->add(column.at(i), labels.at(i)); |
|
242 | series->add(column.at(i), labels.at(i)); | |
241 | } |
|
243 | } | |
242 | m_chartView->addSeries(series); |
|
244 | m_chartView->addSeries(series); | |
243 | } |
|
245 | } | |
244 | } else if (seriesName == "Bar" |
|
246 | } else if (seriesName == "Bar" | |
245 | || seriesName == "Stacked bar" |
|
247 | || seriesName == "Stacked bar" | |
246 | || seriesName == "Percent bar") { |
|
248 | || seriesName == "Percent bar") { | |
247 | QStringList category; |
|
249 | QStringList category; | |
248 | QStringList labels = generateLabels(rowCount); |
|
250 | QStringList labels = generateLabels(rowCount); | |
249 | foreach(QString label, labels) |
|
251 | foreach(QString label, labels) | |
250 | category << label; |
|
252 | category << label; | |
251 | QBarSeries* series = 0; |
|
253 | QBarSeries* series = 0; | |
252 | if (seriesName == "Bar") |
|
254 | if (seriesName == "Bar") | |
253 | series = new QBarSeries(category, this); |
|
255 | series = new QBarSeries(category, this); | |
254 | else if (seriesName == "Stacked bar") |
|
256 | else if (seriesName == "Stacked bar") | |
255 | series = new QStackedBarSeries(category, this); |
|
257 | series = new QStackedBarSeries(category, this); | |
256 | else |
|
258 | else | |
257 | series = new QPercentBarSeries(category, this); |
|
259 | series = new QPercentBarSeries(category, this); | |
258 |
|
260 | |||
259 | for (int j(0); j < data.count(); j++) { |
|
261 | for (int j(0); j < data.count(); j++) { | |
260 | QList<qreal> column = data.at(j); |
|
262 | QList<qreal> column = data.at(j); | |
261 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
263 | QBarSet *set = new QBarSet("set" + QString::number(j)); | |
262 | for (int i(0); i < column.count(); i++) { |
|
264 | for (int i(0); i < column.count(); i++) { | |
263 | *set << column.at(i); |
|
265 | *set << column.at(i); | |
264 | } |
|
266 | } | |
265 | series->addBarSet(set); |
|
267 | series->addBarSet(set); | |
266 | } |
|
268 | } | |
267 |
|
269 | |||
268 | // TODO: new implementation of setFloatingValuesEnabled with signals |
|
270 | // TODO: new implementation of setFloatingValuesEnabled with signals | |
269 | //series->setFloatingValuesEnabled(true); |
|
271 | //series->setFloatingValuesEnabled(true); | |
270 | series->setToolTipEnabled(true); |
|
272 | series->setToolTipEnabled(true); | |
271 | m_chartView->addSeries(series); |
|
273 | m_chartView->addSeries(series); | |
272 | } else if (seriesName == "Spline") { |
|
274 | } else if (seriesName == "Spline") { | |
273 | for (int j(0); j < data.count(); j ++) { |
|
275 | for (int j(0); j < data.count(); j ++) { | |
274 | QList<qreal> column = data.at(j); |
|
276 | QList<qreal> column = data.at(j); | |
275 | QSplineSeries *series = new QSplineSeries(); |
|
277 | QSplineSeries *series = new QSplineSeries(); | |
276 | for (int i(0); i < column.count(); i++) { |
|
278 | for (int i(0); i < column.count(); i++) { | |
277 | series->add(i, column.at(i)); |
|
279 | series->add(i, column.at(i)); | |
278 | } |
|
280 | } | |
279 | m_chartView->addSeries(series); |
|
281 | m_chartView->addSeries(series); | |
280 | } |
|
282 | } | |
281 | } |
|
283 | } | |
282 | } |
|
284 | } | |
283 |
|
285 | |||
284 | void MainWidget::backgroundChanged(int itemIndex) |
|
286 | void MainWidget::backgroundChanged(int itemIndex) | |
285 | { |
|
287 | { | |
286 | qDebug() << "backgroundChanged: " << itemIndex; |
|
288 | qDebug() << "backgroundChanged: " << itemIndex; | |
287 | } |
|
289 | } | |
288 |
|
290 | |||
289 | void MainWidget::autoScaleChanged(int value) |
|
291 | void MainWidget::autoScaleChanged(int value) | |
290 | { |
|
292 | { | |
291 | if (value) { |
|
293 | if (value) { | |
292 | // TODO: enable auto scaling |
|
294 | // TODO: enable auto scaling | |
293 | } else { |
|
295 | } else { | |
294 | // TODO: set scaling manually (and disable auto scaling) |
|
296 | // TODO: set scaling manually (and disable auto scaling) | |
295 | } |
|
297 | } | |
296 |
|
298 | |||
297 | m_xMinSpin->setEnabled(!value); |
|
299 | m_xMinSpin->setEnabled(!value); | |
298 | m_xMaxSpin->setEnabled(!value); |
|
300 | m_xMaxSpin->setEnabled(!value); | |
299 | m_yMinSpin->setEnabled(!value); |
|
301 | m_yMinSpin->setEnabled(!value); | |
300 | m_yMaxSpin->setEnabled(!value); |
|
302 | m_yMaxSpin->setEnabled(!value); | |
301 | } |
|
303 | } | |
302 |
|
304 | |||
303 | void MainWidget::xMinChanged(int value) |
|
305 | void MainWidget::xMinChanged(int value) | |
304 | { |
|
306 | { | |
305 | qDebug() << "xMinChanged: " << value; |
|
307 | qDebug() << "xMinChanged: " << value; | |
306 | } |
|
308 | } | |
307 |
|
309 | |||
308 | void MainWidget::xMaxChanged(int value) |
|
310 | void MainWidget::xMaxChanged(int value) | |
309 | { |
|
311 | { | |
310 | qDebug() << "xMaxChanged: " << value; |
|
312 | qDebug() << "xMaxChanged: " << value; | |
311 | } |
|
313 | } | |
312 |
|
314 | |||
313 | void MainWidget::yMinChanged(int value) |
|
315 | void MainWidget::yMinChanged(int value) | |
314 | { |
|
316 | { | |
315 | qDebug() << "yMinChanged: " << value; |
|
317 | qDebug() << "yMinChanged: " << value; | |
316 | } |
|
318 | } | |
317 |
|
319 | |||
318 | void MainWidget::yMaxChanged(int value) |
|
320 | void MainWidget::yMaxChanged(int value) | |
319 | { |
|
321 | { | |
320 | qDebug() << "yMaxChanged: " << value; |
|
322 | qDebug() << "yMaxChanged: " << value; | |
321 | } |
|
323 | } | |
322 |
|
324 | |||
323 | void MainWidget::changeChartTheme(int themeIndex) |
|
325 | void MainWidget::changeChartTheme(int themeIndex) | |
324 | { |
|
326 | { | |
325 | qDebug() << "changeChartTheme: " << themeIndex; |
|
327 | qDebug() << "changeChartTheme: " << themeIndex; | |
326 | m_chartView->setChartTheme((QChart::ChartTheme) themeIndex); |
|
328 | m_chartView->setChartTheme((QChart::ChartTheme) themeIndex); | |
327 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. |
|
329 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. | |
328 | QSize s = size(); |
|
330 | QSize s = size(); | |
329 | s.setWidth(s.width()+1); |
|
331 | s.setWidth(s.width()+1); | |
330 | resize(s); |
|
332 | resize(s); | |
331 | } |
|
333 | } |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now