@@ -1,243 +1,247 | |||||
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 <qpercentbarseries.h> |
|
8 | #include <qpercentbarseries.h> | |
|
9 | #include <qstackedbarseries.h> | |||
8 | #include <qbarset.h> |
|
10 | #include <qbarset.h> | |
9 | #include <QGridLayout> |
|
11 | #include <QGridLayout> | |
10 | #include <QFormLayout> |
|
12 | #include <QFormLayout> | |
11 | #include <QComboBox> |
|
13 | #include <QComboBox> | |
12 | #include <QSpinBox> |
|
14 | #include <QSpinBox> | |
13 | #include <QCheckBox> |
|
15 | #include <QCheckBox> | |
14 | #include <QGroupBox> |
|
16 | #include <QGroupBox> | |
15 | #include <QLabel> |
|
17 | #include <QLabel> | |
16 | #include <QTime> |
|
18 | #include <QTime> | |
17 | #include <qlineseries.h> |
|
19 | #include <qlineseries.h> | |
18 | #include <qsplineseries.h> |
|
20 | #include <qsplineseries.h> | |
19 | #include <qscatterseries.h> |
|
21 | #include <qscatterseries.h> | |
20 | #include <qareaseries.h> |
|
22 | #include <qareaseries.h> | |
21 |
|
23 | |||
22 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
24 | QTCOMMERCIALCHART_USE_NAMESPACE | |
23 |
|
25 | |||
24 | typedef QPair<QPointF, QString> Data; |
|
26 | typedef QPair<QPointF, QString> Data; | |
25 | typedef QList<Data> DataList; |
|
27 | typedef QList<Data> DataList; | |
26 | typedef QList<DataList> DataTable; |
|
28 | typedef QList<DataList> DataTable; | |
27 |
|
29 | |||
28 |
|
30 | |||
29 | class MainWidget : public QWidget |
|
31 | class MainWidget : public QWidget | |
30 | { |
|
32 | { | |
31 | Q_OBJECT |
|
33 | Q_OBJECT | |
32 |
|
34 | |||
33 | public: |
|
35 | public: | |
34 | explicit MainWidget(QWidget* parent = 0) |
|
36 | explicit MainWidget(QWidget* parent = 0) | |
35 | :QWidget(parent) |
|
37 | :QWidget(parent) | |
36 | { |
|
38 | { | |
37 | // set seed for random stuff |
|
39 | // set seed for random stuff | |
38 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
40 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
39 |
|
41 | |||
40 | // generate random data |
|
42 | // generate random data | |
41 | int listCount = 3; |
|
43 | int listCount = 3; | |
42 | int valueMax = 100; |
|
44 | int valueMax = 100; | |
43 | int valueCount = 11; |
|
45 | int valueCount = 11; | |
44 | for (int i(0); i < listCount; i++) { |
|
46 | for (int i(0); i < listCount; i++) { | |
45 | DataList dataList; |
|
47 | DataList dataList; | |
46 | for (int j(0); j < valueCount; j++) { |
|
48 | for (int j(0); j < valueCount; j++) { | |
47 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); |
|
49 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); | |
48 | QString label = QString::number(i) + ":" + QString::number(j); |
|
50 | QString label = QString::number(i) + ":" + QString::number(j); | |
49 | dataList << Data(value, label); |
|
51 | dataList << Data(value, label); | |
50 | } |
|
52 | } | |
51 | m_dataTable << dataList; |
|
53 | m_dataTable << dataList; | |
52 | } |
|
54 | } | |
53 |
|
55 | |||
54 | // create layout |
|
56 | // create layout | |
55 | QGridLayout* baseLayout = new QGridLayout(); |
|
57 | QGridLayout* baseLayout = new QGridLayout(); | |
56 |
|
58 | |||
57 | // settings layout |
|
59 | // settings layout | |
58 | m_themeComboBox = new QComboBox(); |
|
60 | m_themeComboBox = new QComboBox(); | |
59 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
61 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); | |
60 | m_themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
62 | m_themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
61 | m_themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
63 | m_themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
62 | m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
64 | m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
63 | m_themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
65 | m_themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
64 | m_themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
66 | m_themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
65 | m_themeComboBox->addItem("Vanilla", QChart::ChartThemeVanilla); |
|
67 | m_themeComboBox->addItem("Vanilla", QChart::ChartThemeVanilla); | |
66 | m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); |
|
68 | m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); | |
67 | m_themeComboBox->addItem("Grayscale", QChart::ChartThemeGrayscale); |
|
69 | m_themeComboBox->addItem("Grayscale", QChart::ChartThemeGrayscale); | |
68 | m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); |
|
70 | m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); | |
69 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateTheme())); |
|
71 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateTheme())); | |
70 | QCheckBox *antialiasCheckBox = new QCheckBox("Anti aliasing"); |
|
72 | QCheckBox *antialiasCheckBox = new QCheckBox("Anti aliasing"); | |
71 | connect(antialiasCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateAntialiasing(bool))); |
|
73 | connect(antialiasCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateAntialiasing(bool))); | |
72 | QCheckBox *animatedCheckBox = new QCheckBox("Animated"); |
|
74 | QCheckBox *animatedCheckBox = new QCheckBox("Animated"); | |
73 | connect(animatedCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateAnimations(bool))); |
|
75 | connect(animatedCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateAnimations(bool))); | |
74 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
76 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
75 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
77 | settingsLayout->addWidget(new QLabel("Theme:")); | |
76 | settingsLayout->addWidget(m_themeComboBox); |
|
78 | settingsLayout->addWidget(m_themeComboBox); | |
77 | settingsLayout->addWidget(antialiasCheckBox); |
|
79 | settingsLayout->addWidget(antialiasCheckBox); | |
78 | settingsLayout->addWidget(animatedCheckBox); |
|
80 | settingsLayout->addWidget(animatedCheckBox); | |
79 | settingsLayout->addStretch(); |
|
81 | settingsLayout->addStretch(); | |
80 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
82 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
81 |
|
83 | |||
82 | // area chart |
|
84 | // area chart | |
83 | QChartView *chart = new QChartView(); |
|
85 | QChartView *chart = new QChartView(); | |
84 | chart->setChartTitle("Area chart"); |
|
86 | chart->setChartTitle("Area chart"); | |
85 | baseLayout->addWidget(chart, 1, 0); |
|
87 | baseLayout->addWidget(chart, 1, 0); | |
86 | { |
|
88 | { | |
87 | for (int i(0); i < m_dataTable.count(); i++) { |
|
89 | for (int i(0); i < m_dataTable.count(); i++) { | |
88 | QLineSeries *series1 = new QLineSeries(chart); |
|
90 | QLineSeries *series1 = new QLineSeries(chart); | |
89 | QLineSeries *series2 = new QLineSeries(chart); |
|
91 | QLineSeries *series2 = new QLineSeries(chart); | |
90 | foreach (Data data, m_dataTable[i]) { |
|
92 | foreach (Data data, m_dataTable[i]) { | |
91 | series1->add(data.first); |
|
93 | series1->add(data.first); | |
92 | series2->add(QPointF(data.first.x(), 0.0)); |
|
94 | series2->add(QPointF(data.first.x(), 0.0)); | |
93 | } |
|
95 | } | |
94 | QAreaSeries *area = new QAreaSeries(series1, series2); |
|
96 | QAreaSeries *area = new QAreaSeries(series1, series2); | |
95 | chart->addSeries(area); |
|
97 | chart->addSeries(area); | |
96 | } |
|
98 | } | |
97 | } |
|
99 | } | |
98 | m_charts << chart; |
|
100 | m_charts << chart; | |
99 |
|
101 | |||
100 | // bar chart |
|
102 | // bar chart | |
101 | chart = new QChartView(); |
|
103 | chart = new QChartView(); | |
102 | chart->setChartTitle("bar chart"); |
|
104 | chart->setChartTitle("bar chart"); | |
103 | baseLayout->addWidget(chart, 1, 1); |
|
105 | baseLayout->addWidget(chart, 1, 1); | |
104 | { |
|
106 | { | |
105 | QStringList categories; |
|
107 | QStringList categories; | |
106 | // TODO: categories |
|
108 | // TODO: categories | |
107 | for (int i(0); i < valueCount; i++) |
|
109 | for (int i(0); i < valueCount; i++) | |
108 | categories << QString::number(i); |
|
110 | categories << QString::number(i); | |
109 |
Q |
|
111 | // QBarSeries* series = new QBarSeries(categories, chart); | |
|
112 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |||
|
113 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); | |||
110 | for (int i(0); i < m_dataTable.count(); i++) { |
|
114 | for (int i(0); i < m_dataTable.count(); i++) { | |
111 | QBarSet *set = new QBarSet("Set" + QString::number(i)); |
|
115 | QBarSet *set = new QBarSet("Set" + QString::number(i)); | |
112 | foreach (Data data, m_dataTable[i]) |
|
116 | foreach (Data data, m_dataTable[i]) | |
113 | *set << data.first.y(); |
|
117 | *set << data.first.y(); | |
114 | series->addBarSet(set); |
|
118 | series->addBarSet(set); | |
115 | } |
|
119 | } | |
116 | chart->addSeries(series); |
|
120 | chart->addSeries(series); | |
117 | } |
|
121 | } | |
118 | m_charts << chart; |
|
122 | m_charts << chart; | |
119 |
|
123 | |||
120 | // line chart |
|
124 | // line chart | |
121 | chart = new QChartView(); |
|
125 | chart = new QChartView(); | |
122 | chart->setChartTitle("line chart"); |
|
126 | chart->setChartTitle("line chart"); | |
123 | baseLayout->addWidget(chart, 1, 2); |
|
127 | baseLayout->addWidget(chart, 1, 2); | |
124 | foreach (DataList list, m_dataTable) { |
|
128 | foreach (DataList list, m_dataTable) { | |
125 | QLineSeries *series = new QLineSeries(chart); |
|
129 | QLineSeries *series = new QLineSeries(chart); | |
126 | foreach (Data data, list) |
|
130 | foreach (Data data, list) | |
127 | series->add(data.first); |
|
131 | series->add(data.first); | |
128 | chart->addSeries(series); |
|
132 | chart->addSeries(series); | |
129 | } |
|
133 | } | |
130 | m_charts << chart; |
|
134 | m_charts << chart; | |
131 |
|
135 | |||
132 | // pie chart |
|
136 | // pie chart | |
133 | chart = new QChartView(); |
|
137 | chart = new QChartView(); | |
134 | chart->setChartTitle("pie chart"); |
|
138 | chart->setChartTitle("pie chart"); | |
135 | baseLayout->addWidget(chart, 2, 0); |
|
139 | baseLayout->addWidget(chart, 2, 0); | |
136 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
140 | qreal pieSize = 1.0 / m_dataTable.count(); | |
137 | for (int i=0; i<m_dataTable.count(); i++) { |
|
141 | for (int i=0; i<m_dataTable.count(); i++) { | |
138 | QPieSeries *series = new QPieSeries(chart); |
|
142 | QPieSeries *series = new QPieSeries(chart); | |
139 | foreach (Data data, m_dataTable[i]) |
|
143 | foreach (Data data, m_dataTable[i]) | |
140 | series->add(data.first.y(), data.second); |
|
144 | series->add(data.first.y(), data.second); | |
141 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
145 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
142 | series->setPieSize(pieSize); |
|
146 | series->setPieSize(pieSize); | |
143 | series->setPiePosition(hPos, 0.5); |
|
147 | series->setPiePosition(hPos, 0.5); | |
144 | chart->addSeries(series); |
|
148 | chart->addSeries(series); | |
145 | } |
|
149 | } | |
146 | m_charts << chart; |
|
150 | m_charts << chart; | |
147 |
|
151 | |||
148 | // spine chart |
|
152 | // spine chart | |
149 | chart = new QChartView(); |
|
153 | chart = new QChartView(); | |
150 | chart->setChartTitle("spline chart"); |
|
154 | chart->setChartTitle("spline chart"); | |
151 | baseLayout->addWidget(chart, 2, 1); |
|
155 | baseLayout->addWidget(chart, 2, 1); | |
152 | foreach (DataList list, m_dataTable) { |
|
156 | foreach (DataList list, m_dataTable) { | |
153 | QSplineSeries *series = new QSplineSeries(chart); |
|
157 | QSplineSeries *series = new QSplineSeries(chart); | |
154 | foreach (Data data, list) |
|
158 | foreach (Data data, list) | |
155 | series->add(data.first); |
|
159 | series->add(data.first); | |
156 | chart->addSeries(series); |
|
160 | chart->addSeries(series); | |
157 | } |
|
161 | } | |
158 | m_charts << chart; |
|
162 | m_charts << chart; | |
159 |
|
163 | |||
160 | // scatter chart |
|
164 | // scatter chart | |
161 | chart = new QChartView(); |
|
165 | chart = new QChartView(); | |
162 | chart->setChartTitle("scatter chart"); |
|
166 | chart->setChartTitle("scatter chart"); | |
163 | baseLayout->addWidget(chart, 2, 2); |
|
167 | baseLayout->addWidget(chart, 2, 2); | |
164 | foreach (DataList list, m_dataTable) { |
|
168 | foreach (DataList list, m_dataTable) { | |
165 | QScatterSeries *series = new QScatterSeries(chart); |
|
169 | QScatterSeries *series = new QScatterSeries(chart); | |
166 | foreach (Data data, list) |
|
170 | foreach (Data data, list) | |
167 | series->add(data.first); |
|
171 | series->add(data.first); | |
168 | chart->addSeries(series); |
|
172 | chart->addSeries(series); | |
169 | } |
|
173 | } | |
170 | m_charts << chart; |
|
174 | m_charts << chart; | |
171 |
|
175 | |||
172 | setLayout(baseLayout); |
|
176 | setLayout(baseLayout); | |
173 | } |
|
177 | } | |
174 |
|
178 | |||
175 | public Q_SLOTS: |
|
179 | public Q_SLOTS: | |
176 |
|
180 | |||
177 | void updateTheme() |
|
181 | void updateTheme() | |
178 | { |
|
182 | { | |
179 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
183 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
180 | foreach (QChartView *chart, m_charts) |
|
184 | foreach (QChartView *chart, m_charts) | |
181 | chart->setChartTheme(theme); |
|
185 | chart->setChartTheme(theme); | |
182 |
|
186 | |||
183 | QPalette pal = window()->palette(); |
|
187 | QPalette pal = window()->palette(); | |
184 | if (theme == QChart::ChartThemeLight) { |
|
188 | if (theme == QChart::ChartThemeLight) { | |
185 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
189 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
186 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
190 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
187 | } else if (theme == QChart::ChartThemeDark) { |
|
191 | } else if (theme == QChart::ChartThemeDark) { | |
188 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
192 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
189 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
193 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
190 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
194 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
191 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
195 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
192 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
196 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
193 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
197 | } else if (theme == QChart::ChartThemeBrownSand) { | |
194 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
198 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
195 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
199 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
196 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
200 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
197 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
201 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
198 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
202 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
199 | } else { |
|
203 | } else { | |
200 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
204 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
201 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
205 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
202 | } |
|
206 | } | |
203 | window()->setPalette(pal); |
|
207 | window()->setPalette(pal); | |
204 | } |
|
208 | } | |
205 |
|
209 | |||
206 | void updateAntialiasing(bool enabled) |
|
210 | void updateAntialiasing(bool enabled) | |
207 | { |
|
211 | { | |
208 | foreach (QChartView *chart, m_charts) |
|
212 | foreach (QChartView *chart, m_charts) | |
209 | chart->setRenderHint(QPainter::Antialiasing, enabled); |
|
213 | chart->setRenderHint(QPainter::Antialiasing, enabled); | |
210 | } |
|
214 | } | |
211 |
|
215 | |||
212 | void updateAnimations(bool animated) |
|
216 | void updateAnimations(bool animated) | |
213 | { |
|
217 | { | |
214 | QChart::AnimationOptions options = QChart::NoAnimation; |
|
218 | QChart::AnimationOptions options = QChart::NoAnimation; | |
215 | if (animated) |
|
219 | if (animated) | |
216 | options = QChart::AllAnimations; |
|
220 | options = QChart::AllAnimations; | |
217 |
|
221 | |||
218 | foreach (QChartView *chart, m_charts) |
|
222 | foreach (QChartView *chart, m_charts) | |
219 | chart->setAnimationOptions(options); |
|
223 | chart->setAnimationOptions(options); | |
220 | } |
|
224 | } | |
221 |
|
225 | |||
222 | private: |
|
226 | private: | |
223 | QList<QChartView*> m_charts; |
|
227 | QList<QChartView*> m_charts; | |
224 | QComboBox *m_themeComboBox; |
|
228 | QComboBox *m_themeComboBox; | |
225 | DataTable m_dataTable; |
|
229 | DataTable m_dataTable; | |
226 | }; |
|
230 | }; | |
227 |
|
231 | |||
228 | int main(int argc, char *argv[]) |
|
232 | int main(int argc, char *argv[]) | |
229 | { |
|
233 | { | |
230 | QApplication a(argc, argv); |
|
234 | QApplication a(argc, argv); | |
231 |
|
235 | |||
232 | QMainWindow window; |
|
236 | QMainWindow window; | |
233 |
|
237 | |||
234 | MainWidget* widget = new MainWidget(); |
|
238 | MainWidget* widget = new MainWidget(); | |
235 |
|
239 | |||
236 | window.setCentralWidget(widget); |
|
240 | window.setCentralWidget(widget); | |
237 | window.resize(900, 600); |
|
241 | window.resize(900, 600); | |
238 | window.show(); |
|
242 | window.show(); | |
239 |
|
243 | |||
240 | return a.exec(); |
|
244 | return a.exec(); | |
241 | } |
|
245 | } | |
242 |
|
246 | |||
243 | #include "main.moc" |
|
247 | #include "main.moc" |
@@ -1,87 +1,88 | |||||
1 | #include "barpresenter_p.h" |
|
1 | #include "barpresenter_p.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barvalue_p.h" |
|
3 | #include "barvalue_p.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include <QDebug> |
|
5 | #include <QDebug> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | BarPresenter::BarPresenter(QBarSeries *series, QChart *parent) : |
|
9 | BarPresenter::BarPresenter(QBarSeries *series, QChart *parent) : | |
10 | BarPresenterBase(series, parent) |
|
10 | BarPresenterBase(series, parent) | |
11 | { |
|
11 | { | |
12 | connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged())); |
|
12 | connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged())); | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | void BarPresenter::layoutChanged() |
|
15 | void BarPresenter::layoutChanged() | |
16 | { |
|
16 | { | |
17 | // Scale bars to new layout |
|
17 | // Scale bars to new layout | |
18 | // Layout for bars: |
|
18 | // Layout for bars: | |
19 | if (mSeries->barsetCount() <= 0) { |
|
19 | if (mSeries->barsetCount() <= 0) { | |
20 | qDebug() << "No sets in model!"; |
|
20 | qDebug() << "No sets in model!"; | |
21 | return; |
|
21 | return; | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | if (childItems().count() == 0) { |
|
24 | if (childItems().count() == 0) { | |
25 | qDebug() << "WARNING: BarPresenter::layoutChanged called before graphics items are created!"; |
|
25 | qDebug() << "WARNING: BarPresenter::layoutChanged called before graphics items are created!"; | |
26 | return; |
|
26 | return; | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
29 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
30 | int categoryCount = mSeries->categoryCount(); |
|
30 | int categoryCount = mSeries->categoryCount(); | |
31 | int setCount = mSeries->barsetCount(); |
|
31 | int setCount = mSeries->barsetCount(); | |
32 |
|
32 | |||
33 | qreal tW = mWidth; |
|
33 | qreal tW = mWidth; | |
34 | qreal tH = mHeight; |
|
34 | qreal tH = mHeight; | |
35 | qreal tM = mSeries->max(); |
|
35 | qreal tM = mSeries->max(); | |
36 | qreal scale = (tH/tM); |
|
36 | qreal scale = (tH/tM); | |
37 | qreal tC = categoryCount + 1; |
|
37 | qreal tC = categoryCount + 1; | |
38 | qreal categoryWidth = tW/tC; |
|
38 | qreal categoryWidth = tW/tC; | |
39 | mBarWidth = categoryWidth / (setCount+1); |
|
39 | mBarWidth = categoryWidth / (setCount+1); | |
40 |
|
40 | |||
41 | int itemIndex(0); |
|
41 | int itemIndex(0); | |
42 | for (int category=0; category < categoryCount; category++) { |
|
42 | for (int category=0; category < categoryCount; category++) { | |
43 | qreal xPos = categoryWidth * category + categoryWidth /2 + mBarWidth/2; |
|
43 | qreal xPos = categoryWidth * category + categoryWidth /2 + mBarWidth/2; | |
44 | qreal yPos = mHeight; |
|
44 | qreal yPos = mHeight; | |
45 | for (int set = 0; set < setCount; set++) { |
|
45 | for (int set = 0; set < setCount; set++) { | |
46 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
46 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
47 | Bar* bar = mBars.at(itemIndex); |
|
47 | Bar* bar = mBars.at(itemIndex); | |
48 |
|
48 | |||
49 | // TODO: width settable per bar? |
|
49 | // TODO: width settable per bar? | |
50 | bar->resize(mBarWidth, barHeight); |
|
50 | bar->resize(mBarWidth, barHeight); | |
|
51 | bar->setPen(mSeries->barsetAt(set)->pen()); | |||
51 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
52 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
52 | bar->setPos(xPos, yPos-barHeight); |
|
53 | bar->setPos(xPos, yPos-barHeight); | |
53 | itemIndex++; |
|
54 | itemIndex++; | |
54 | xPos += mBarWidth; |
|
55 | xPos += mBarWidth; | |
55 | } |
|
56 | } | |
56 | } |
|
57 | } | |
57 |
|
58 | |||
58 | // Position floating values |
|
59 | // Position floating values | |
59 | itemIndex = 0; |
|
60 | itemIndex = 0; | |
60 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
61 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
61 | qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth; |
|
62 | qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth; | |
62 | qreal yPos = mHeight; |
|
63 | qreal yPos = mHeight; | |
63 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
64 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
64 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
65 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
65 | BarValue* value = mFloatingValues.at(itemIndex); |
|
66 | BarValue* value = mFloatingValues.at(itemIndex); | |
66 |
|
67 | |||
67 | QBarSet* barSet = mSeries->barsetAt(set); |
|
68 | QBarSet* barSet = mSeries->barsetAt(set); | |
68 | value->resize(100,50); // TODO: proper layout for this. |
|
69 | value->resize(100,50); // TODO: proper layout for this. | |
69 | value->setPos(xPos, yPos-barHeight/2); |
|
70 | value->setPos(xPos, yPos-barHeight/2); | |
70 | value->setPen(barSet->floatingValuePen()); |
|
71 | value->setPen(barSet->floatingValuePen()); | |
71 |
|
72 | |||
72 | if (mSeries->valueAt(set,category) != 0) { |
|
73 | if (mSeries->valueAt(set,category) != 0) { | |
73 | value->setValueString(QString::number(mSeries->valueAt(set,category))); |
|
74 | value->setValueString(QString::number(mSeries->valueAt(set,category))); | |
74 | } else { |
|
75 | } else { | |
75 | value->setValueString(QString("")); |
|
76 | value->setValueString(QString("")); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | itemIndex++; |
|
79 | itemIndex++; | |
79 | xPos += mBarWidth; |
|
80 | xPos += mBarWidth; | |
80 | } |
|
81 | } | |
81 | } |
|
82 | } | |
82 | update(); |
|
83 | update(); | |
83 | } |
|
84 | } | |
84 |
|
85 | |||
85 | #include "moc_barpresenter_p.cpp" |
|
86 | #include "moc_barpresenter_p.cpp" | |
86 |
|
87 | |||
87 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,96 +1,97 | |||||
1 | #include "stackedbarpresenter_p.h" |
|
1 | #include "stackedbarpresenter_p.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barvalue_p.h" |
|
3 | #include "barvalue_p.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include <QDebug> |
|
5 | #include <QDebug> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | StackedBarPresenter::StackedBarPresenter(QBarSeries *series, QChart *parent) : |
|
9 | StackedBarPresenter::StackedBarPresenter(QBarSeries *series, QChart *parent) : | |
10 | BarPresenterBase(series,parent) |
|
10 | BarPresenterBase(series,parent) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | StackedBarPresenter::~StackedBarPresenter() |
|
14 | StackedBarPresenter::~StackedBarPresenter() | |
15 | { |
|
15 | { | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | void StackedBarPresenter::layoutChanged() |
|
19 | void StackedBarPresenter::layoutChanged() | |
20 | { |
|
20 | { | |
21 | // Scale bars to new layout |
|
21 | // Scale bars to new layout | |
22 | // Layout for bars: |
|
22 | // Layout for bars: | |
23 | if (mSeries->barsetCount() <= 0) { |
|
23 | if (mSeries->barsetCount() <= 0) { | |
24 | qDebug() << "No sets in model!"; |
|
24 | qDebug() << "No sets in model!"; | |
25 | // Nothing to do. |
|
25 | // Nothing to do. | |
26 | return; |
|
26 | return; | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | if (mSeries->categoryCount() == 0) { |
|
29 | if (mSeries->categoryCount() == 0) { | |
30 | qDebug() << "No categories in model!"; |
|
30 | qDebug() << "No categories in model!"; | |
31 | // Nothing to do |
|
31 | // Nothing to do | |
32 | return; |
|
32 | return; | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | if (childItems().count() == 0) { |
|
35 | if (childItems().count() == 0) { | |
36 | qDebug() << "WARNING: StackedBarPresenter::layoutChanged called before graphics items are created!"; |
|
36 | qDebug() << "WARNING: StackedBarPresenter::layoutChanged called before graphics items are created!"; | |
37 | return; |
|
37 | return; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
40 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
41 | qreal maxSum = mSeries->maxCategorySum(); |
|
41 | qreal maxSum = mSeries->maxCategorySum(); | |
42 | qreal h = mHeight; |
|
42 | qreal h = mHeight; | |
43 | qreal scale = (h / maxSum); |
|
43 | qreal scale = (h / maxSum); | |
44 | qreal tW = mWidth; |
|
44 | qreal tW = mWidth; | |
45 | qreal tC = mSeries->categoryCount() + 1; |
|
45 | qreal tC = mSeries->categoryCount() + 1; | |
46 | qreal cC = mSeries->categoryCount() * 2 + 1; |
|
46 | qreal cC = mSeries->categoryCount() * 2 + 1; | |
47 | mBarWidth = tW / cC; |
|
47 | mBarWidth = tW / cC; | |
48 | qreal xStep = (tW/tC); |
|
48 | qreal xStep = (tW/tC); | |
49 | qreal xPos = ((tW/tC) - mBarWidth / 2); |
|
49 | qreal xPos = ((tW/tC) - mBarWidth / 2); | |
50 |
|
50 | |||
51 | int itemIndex(0); |
|
51 | int itemIndex(0); | |
52 | for (int category = 0; category < mSeries->categoryCount(); category++) { |
|
52 | for (int category = 0; category < mSeries->categoryCount(); category++) { | |
53 | qreal yPos = h; |
|
53 | qreal yPos = h; | |
54 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
54 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
55 | qreal barHeight = mSeries->valueAt(set, category) * scale; |
|
55 | qreal barHeight = mSeries->valueAt(set, category) * scale; | |
56 | Bar* bar = mBars.at(itemIndex); |
|
56 | Bar* bar = mBars.at(itemIndex); | |
57 |
|
57 | |||
58 | bar->resize(mBarWidth, barHeight); |
|
58 | bar->resize(mBarWidth, barHeight); | |
|
59 | bar->setPen(mSeries->barsetAt(set)->pen()); | |||
59 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
60 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
60 | bar->setPos(xPos, yPos-barHeight); |
|
61 | bar->setPos(xPos, yPos-barHeight); | |
61 | itemIndex++; |
|
62 | itemIndex++; | |
62 | yPos -= barHeight; |
|
63 | yPos -= barHeight; | |
63 | } |
|
64 | } | |
64 | xPos += xStep; |
|
65 | xPos += xStep; | |
65 | } |
|
66 | } | |
66 |
|
67 | |||
67 | // Position floating values |
|
68 | // Position floating values | |
68 | itemIndex = 0; |
|
69 | itemIndex = 0; | |
69 | xPos = (tW/tC); |
|
70 | xPos = (tW/tC); | |
70 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
71 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
71 | qreal yPos = h; |
|
72 | qreal yPos = h; | |
72 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
73 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
73 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
74 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
74 | BarValue* value = mFloatingValues.at(itemIndex); |
|
75 | BarValue* value = mFloatingValues.at(itemIndex); | |
75 |
|
76 | |||
76 | QBarSet* barSet = mSeries->barsetAt(set); |
|
77 | QBarSet* barSet = mSeries->barsetAt(set); | |
77 | value->resize(100,50); // TODO: proper layout for this. |
|
78 | value->resize(100,50); // TODO: proper layout for this. | |
78 | value->setPos(xPos, yPos-barHeight/2); |
|
79 | value->setPos(xPos, yPos-barHeight/2); | |
79 | value->setPen(barSet->floatingValuePen()); |
|
80 | value->setPen(barSet->floatingValuePen()); | |
80 |
|
81 | |||
81 | if (mSeries->valueAt(set,category) != 0) { |
|
82 | if (mSeries->valueAt(set,category) != 0) { | |
82 | value->setValueString(QString::number(mSeries->valueAt(set,category))); |
|
83 | value->setValueString(QString::number(mSeries->valueAt(set,category))); | |
83 | } else { |
|
84 | } else { | |
84 | value->setValueString(QString("")); |
|
85 | value->setValueString(QString("")); | |
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 | itemIndex++; |
|
88 | itemIndex++; | |
88 | yPos -= barHeight; |
|
89 | yPos -= barHeight; | |
89 | } |
|
90 | } | |
90 | xPos += xStep; |
|
91 | xPos += xStep; | |
91 | } |
|
92 | } | |
92 | } |
|
93 | } | |
93 |
|
94 | |||
94 | #include "moc_stackedbarpresenter_p.cpp" |
|
95 | #include "moc_stackedbarpresenter_p.cpp" | |
95 |
|
96 | |||
96 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,352 +1,365 | |||||
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 "barpresenter_p.h" |
|
22 | #include "barpresenter_p.h" | |
23 | #include "stackedbarpresenter_p.h" |
|
23 | #include "stackedbarpresenter_p.h" | |
24 | #include "percentbarpresenter_p.h" |
|
24 | #include "percentbarpresenter_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" |
|
38 | #include "chartthemevanilla_p.h" | |
39 | #include "chartthemeicy_p.h" |
|
39 | #include "chartthemeicy_p.h" | |
40 | #include "chartthemegrayscale_p.h" |
|
40 | #include "chartthemegrayscale_p.h" | |
41 | #include "chartthemescientific_p.h" |
|
41 | #include "chartthemescientific_p.h" | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
44 |
|
44 | |||
45 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
45 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
46 | m_masterFont(QFont()), |
|
46 | m_masterFont(QFont()), | |
47 | m_titleBrush(QColor(QRgb(0x000000))), |
|
47 | m_titleBrush(QColor(QRgb(0x000000))), | |
48 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
48 | m_axisLinePen(QPen(QRgb(0x000000))), | |
49 | m_axisLabelBrush(QColor(QRgb(0x000000))), |
|
49 | m_axisLabelBrush(QColor(QRgb(0x000000))), | |
50 | m_backgroundShadesPen(Qt::NoPen), |
|
50 | m_backgroundShadesPen(Qt::NoPen), | |
51 | m_backgroundShadesBrush(Qt::NoBrush), |
|
51 | m_backgroundShadesBrush(Qt::NoBrush), | |
52 | m_backgroundShades(BackgroundShadesNone), |
|
52 | m_backgroundShades(BackgroundShadesNone), | |
53 | m_gridLinePen(QPen(QRgb(0x000000))) |
|
53 | m_gridLinePen(QPen(QRgb(0x000000))) | |
54 | { |
|
54 | { | |
55 | m_id = id; |
|
55 | m_id = id; | |
56 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
56 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
60 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
61 | { |
|
61 | { | |
62 | switch(theme) { |
|
62 | switch(theme) { | |
63 | case QChart::ChartThemeLight: |
|
63 | case QChart::ChartThemeLight: | |
64 | return new ChartThemeLight(); |
|
64 | return new ChartThemeLight(); | |
65 | case QChart::ChartThemeBlueCerulean: |
|
65 | case QChart::ChartThemeBlueCerulean: | |
66 | return new ChartThemeBlueCerulean(); |
|
66 | return new ChartThemeBlueCerulean(); | |
67 | case QChart::ChartThemeDark: |
|
67 | case QChart::ChartThemeDark: | |
68 | return new ChartThemeDark(); |
|
68 | return new ChartThemeDark(); | |
69 | case QChart::ChartThemeBrownSand: |
|
69 | case QChart::ChartThemeBrownSand: | |
70 | return new ChartThemeBrownSand(); |
|
70 | return new ChartThemeBrownSand(); | |
71 | case QChart::ChartThemeBlueNcs: |
|
71 | case QChart::ChartThemeBlueNcs: | |
72 | return new ChartThemeBlueNcs(); |
|
72 | return new ChartThemeBlueNcs(); | |
73 | case QChart::ChartThemeVanilla: |
|
73 | case QChart::ChartThemeVanilla: | |
74 | return new ChartThemeVanilla(); |
|
74 | return new ChartThemeVanilla(); | |
75 | case QChart::ChartThemeIcy: |
|
75 | case QChart::ChartThemeIcy: | |
76 | return new ChartThemeIcy(); |
|
76 | return new ChartThemeIcy(); | |
77 | case QChart::ChartThemeGrayscale: |
|
77 | case QChart::ChartThemeGrayscale: | |
78 | return new ChartThemeGrayscale(); |
|
78 | return new ChartThemeGrayscale(); | |
79 | case QChart::ChartThemeScientific: |
|
79 | case QChart::ChartThemeScientific: | |
80 | return new ChartThemeScientific(); |
|
80 | return new ChartThemeScientific(); | |
81 | default: |
|
81 | default: | |
82 | return new ChartThemeDefault(); |
|
82 | return new ChartThemeDefault(); | |
83 | } |
|
83 | } | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void ChartTheme::decorate(QChart* chart,bool force) |
|
86 | void ChartTheme::decorate(QChart* chart,bool force) | |
87 | { |
|
87 | { | |
88 | QPen pen; |
|
88 | QPen pen; | |
89 | QBrush brush; |
|
89 | QBrush brush; | |
90 |
|
90 | |||
91 | if(brush == chart->backgroundBrush() || force) |
|
91 | if(brush == chart->backgroundBrush() || force) | |
92 | { |
|
92 | { | |
93 | if (m_backgroundShades == BackgroundShadesNone) { |
|
93 | if (m_backgroundShades == BackgroundShadesNone) { | |
94 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
94 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
95 | } |
|
95 | } | |
96 | else { |
|
96 | else { | |
97 | chart->setBackgroundBrush(Qt::NoBrush); |
|
97 | chart->setBackgroundBrush(Qt::NoBrush); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 | chart->setTitleFont(m_masterFont); |
|
100 | chart->setTitleFont(m_masterFont); | |
101 | chart->setTitleBrush(m_titleBrush); |
|
101 | chart->setTitleBrush(m_titleBrush); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void ChartTheme::decorate(QLegend* legend,bool force) |
|
104 | void ChartTheme::decorate(QLegend* legend,bool force) | |
105 | { |
|
105 | { | |
106 | QPen pen; |
|
106 | QPen pen; | |
107 | QBrush brush; |
|
107 | QBrush brush; | |
108 |
|
108 | |||
109 | if (pen == legend->pen() || force){ |
|
109 | if (pen == legend->pen() || force){ | |
110 | //TODO:: legend->setPen(); |
|
110 | //TODO:: legend->setPen(); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 |
|
113 | |||
114 | if (brush == legend->brush() || force) { |
|
114 | if (brush == legend->brush() || force) { | |
115 | legend->setBrush(m_chartBackgroundGradient); |
|
115 | legend->setBrush(m_chartBackgroundGradient); | |
116 | } |
|
116 | } | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) |
|
119 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) | |
120 | { |
|
120 | { | |
121 | QPen pen; |
|
121 | QPen pen; | |
122 | QBrush brush; |
|
122 | QBrush brush; | |
123 |
|
123 | |||
124 | if (pen == series->pen() || force){ |
|
124 | if (pen == series->pen() || force){ | |
125 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
125 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
126 | pen.setWidthF(2); |
|
126 | pen.setWidthF(2); | |
127 | series->setPen(pen); |
|
127 | series->setPen(pen); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | if (brush == series->brush() || force) { |
|
130 | if (brush == series->brush() || force) { | |
131 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
131 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
132 | series->setBrush(brush); |
|
132 | series->setBrush(brush); | |
133 | } |
|
133 | } | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 |
|
136 | |||
137 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) |
|
137 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) | |
138 | { |
|
138 | { | |
139 | QPen pen; |
|
139 | QPen pen; | |
140 | if(pen == series->pen() || force ){ |
|
140 | if(pen == series->pen() || force ){ | |
141 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
141 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
142 | pen.setWidthF(2); |
|
142 | pen.setWidthF(2); | |
143 | series->setPen(pen); |
|
143 | series->setPen(pen); | |
144 | } |
|
144 | } | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) |
|
147 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) | |
148 | { |
|
148 | { | |
149 | QBrush brush; |
|
149 | QBrush brush; | |
150 | QPen pen; |
|
150 | QPen pen; | |
151 | QList<QBarSet*> sets = series->barSets(); |
|
151 | QList<QBarSet*> sets = series->barSets(); | |
152 |
|
152 | |||
153 | for (int i(0); i < sets.count(); i++) { |
|
153 | qreal takeAtPos = 0.5; | |
154 |
|
|
154 | qreal step = 0.2; | |
155 |
|
|
155 | if (sets.count() > 1 ) { | |
156 |
|
|
156 | step = 1.0 / (qreal) sets.count(); | |
157 |
|
157 | if (sets.count() % m_seriesGradients.count()) | ||
158 | if (brush == sets.at(i)->brush() || force ) { |
|
158 | step *= m_seriesGradients.count(); | |
159 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
159 | else | |
160 | sets.at(i)->setBrush(QBrush(c)); |
|
160 | step *= (m_seriesGradients.count() - 1); | |
161 |
|
|
161 | } | |
162 |
|
162 | |||
|
163 | for (int i(0); i < sets.count(); i++) { | |||
|
164 | int colorIndex = (index + i) % m_seriesGradients.count(); | |||
|
165 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |||
|
166 | // There is no dedicated base color for each sets, generate more colors | |||
|
167 | takeAtPos += step; | |||
|
168 | if (takeAtPos == 1.0) | |||
|
169 | takeAtPos += step; | |||
|
170 | takeAtPos -= (int) takeAtPos; | |||
|
171 | } | |||
|
172 | qDebug() << "pos:" << takeAtPos; | |||
|
173 | if (brush == sets.at(i)->brush() || force ) | |||
|
174 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |||
|
175 | ||||
163 | // Pick label color from the opposite end of the gradient. |
|
176 | // Pick label color from the opposite end of the gradient. | |
164 | // 0.3 as a boundary seems to work well. |
|
177 | // 0.3 as a boundary seems to work well. | |
165 |
if ( |
|
178 | if (takeAtPos < 0.3) | |
166 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
179 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
167 | else |
|
180 | else | |
168 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
181 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
169 |
|
182 | |||
170 | if (pen == sets.at(i)->pen() || force) { |
|
183 | if (pen == sets.at(i)->pen() || force) { | |
171 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
184 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
172 | sets.at(i)->setPen(c); |
|
185 | sets.at(i)->setPen(c); | |
173 | } |
|
186 | } | |
174 | } |
|
187 | } | |
175 | } |
|
188 | } | |
176 |
|
189 | |||
177 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) |
|
190 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) | |
178 | { |
|
191 | { | |
179 | QPen pen; |
|
192 | QPen pen; | |
180 | QBrush brush; |
|
193 | QBrush brush; | |
181 |
|
194 | |||
182 | if (pen == series->pen() || force) { |
|
195 | if (pen == series->pen() || force) { | |
183 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
196 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
184 | pen.setWidthF(2); |
|
197 | pen.setWidthF(2); | |
185 | series->setPen(pen); |
|
198 | series->setPen(pen); | |
186 | } |
|
199 | } | |
187 |
|
200 | |||
188 | if (brush == series->brush() || force) { |
|
201 | if (brush == series->brush() || force) { | |
189 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
202 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
190 | series->setBrush(brush); |
|
203 | series->setBrush(brush); | |
191 | } |
|
204 | } | |
192 | } |
|
205 | } | |
193 |
|
206 | |||
194 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) |
|
207 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) | |
195 | { |
|
208 | { | |
196 | QPen pen; |
|
209 | QPen pen; | |
197 | QBrush brush; |
|
210 | QBrush brush; | |
198 |
|
211 | |||
199 | for (int i(0); i < series->slices().count(); i++) { |
|
212 | for (int i(0); i < series->slices().count(); i++) { | |
200 | if (pen == series->slices().at(i)->slicePen() || force) { |
|
213 | if (pen == series->slices().at(i)->slicePen() || force) { | |
201 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
214 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
202 | series->slices().at(i)->setSlicePen(penColor); |
|
215 | series->slices().at(i)->setSlicePen(penColor); | |
203 | } |
|
216 | } | |
204 |
|
217 | |||
205 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
218 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
206 | qreal pos = (qreal) i / (qreal) series->count(); |
|
219 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
207 | if (brush == series->slices().at(i)->sliceBrush() || force) { |
|
220 | if (brush == series->slices().at(i)->sliceBrush() || force) { | |
208 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
221 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
209 | series->slices().at(i)->setSliceBrush(brushColor); |
|
222 | series->slices().at(i)->setSliceBrush(brushColor); | |
210 | } |
|
223 | } | |
211 | } |
|
224 | } | |
212 | } |
|
225 | } | |
213 |
|
226 | |||
214 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) |
|
227 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) | |
215 | { |
|
228 | { | |
216 | QPen pen; |
|
229 | QPen pen; | |
217 | if(pen == series->pen() || force){ |
|
230 | if(pen == series->pen() || force){ | |
218 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
231 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
219 | pen.setWidthF(2); |
|
232 | pen.setWidthF(2); | |
220 | series->setPen(pen); |
|
233 | series->setPen(pen); | |
221 | } |
|
234 | } | |
222 | } |
|
235 | } | |
223 |
|
236 | |||
224 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) |
|
237 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) | |
225 | { |
|
238 | { | |
226 | QPen pen; |
|
239 | QPen pen; | |
227 | QBrush brush; |
|
240 | QBrush brush; | |
228 | QFont font; |
|
241 | QFont font; | |
229 |
|
242 | |||
230 | if (axis->isAxisVisible()) { |
|
243 | if (axis->isAxisVisible()) { | |
231 |
|
244 | |||
232 | if(brush == axis->labelsBrush() || force){ |
|
245 | if(brush == axis->labelsBrush() || force){ | |
233 | axis->setLabelsBrush(m_axisLabelBrush); |
|
246 | axis->setLabelsBrush(m_axisLabelBrush); | |
234 | } |
|
247 | } | |
235 | if(pen == axis->labelsPen() || force){ |
|
248 | if(pen == axis->labelsPen() || force){ | |
236 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
249 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
237 | } |
|
250 | } | |
238 |
|
251 | |||
239 |
|
252 | |||
240 | if (axis->shadesVisible() || force) { |
|
253 | if (axis->shadesVisible() || force) { | |
241 |
|
254 | |||
242 | if(brush == axis->shadesBrush() || force){ |
|
255 | if(brush == axis->shadesBrush() || force){ | |
243 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
256 | axis->setShadesBrush(m_backgroundShadesBrush); | |
244 | } |
|
257 | } | |
245 |
|
258 | |||
246 | if(pen == axis->shadesPen() || force){ |
|
259 | if(pen == axis->shadesPen() || force){ | |
247 | axis->setShadesPen(m_backgroundShadesPen); |
|
260 | axis->setShadesPen(m_backgroundShadesPen); | |
248 | } |
|
261 | } | |
249 |
|
262 | |||
250 | if(force && (m_backgroundShades == BackgroundShadesBoth |
|
263 | if(force && (m_backgroundShades == BackgroundShadesBoth | |
251 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
264 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
252 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
265 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
253 | axis->setShadesVisible(true); |
|
266 | axis->setShadesVisible(true); | |
254 |
|
267 | |||
255 | } |
|
268 | } | |
256 | } |
|
269 | } | |
257 |
|
270 | |||
258 | if(pen == axis->axisPen() || force){ |
|
271 | if(pen == axis->axisPen() || force){ | |
259 | axis->setAxisPen(m_axisLinePen); |
|
272 | axis->setAxisPen(m_axisLinePen); | |
260 | } |
|
273 | } | |
261 |
|
274 | |||
262 | if(pen == axis->gridLinePen() || force){ |
|
275 | if(pen == axis->gridLinePen() || force){ | |
263 | axis->setGridLinePen(m_gridLinePen); |
|
276 | axis->setGridLinePen(m_gridLinePen); | |
264 | } |
|
277 | } | |
265 |
|
278 | |||
266 | if(font == axis->labelsFont() || force){ |
|
279 | if(font == axis->labelsFont() || force){ | |
267 | axis->setLabelsFont(m_masterFont); |
|
280 | axis->setLabelsFont(m_masterFont); | |
268 | } |
|
281 | } | |
269 | } |
|
282 | } | |
270 | } |
|
283 | } | |
271 |
|
284 | |||
272 | void ChartTheme::generateSeriesGradients() |
|
285 | void ChartTheme::generateSeriesGradients() | |
273 | { |
|
286 | { | |
274 | // Generate gradients in HSV color space |
|
287 | // Generate gradients in HSV color space | |
275 | foreach (QColor color, m_seriesColors) { |
|
288 | foreach (QColor color, m_seriesColors) { | |
276 | QLinearGradient g; |
|
289 | QLinearGradient g; | |
277 | qreal h = color.hsvHueF(); |
|
290 | qreal h = color.hsvHueF(); | |
278 | qreal s = color.hsvSaturationF(); |
|
291 | qreal s = color.hsvSaturationF(); | |
279 |
|
292 | |||
280 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
293 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
281 | // most themes. The rest of the gradients we can define manually in theme specific |
|
294 | // most themes. The rest of the gradients we can define manually in theme specific | |
282 | // implementation. |
|
295 | // implementation. | |
283 | QColor start = color; |
|
296 | QColor start = color; | |
284 | start.setHsvF(h, 0.0, 1.0); |
|
297 | start.setHsvF(h, 0.0, 1.0); | |
285 | g.setColorAt(0.0, start); |
|
298 | g.setColorAt(0.0, start); | |
286 |
|
299 | |||
287 | g.setColorAt(0.5, color); |
|
300 | g.setColorAt(0.5, color); | |
288 |
|
301 | |||
289 | QColor end = color; |
|
302 | QColor end = color; | |
290 | end.setHsvF(h, s, 0.25); |
|
303 | end.setHsvF(h, s, 0.25); | |
291 | g.setColorAt(1.0, end); |
|
304 | g.setColorAt(1.0, end); | |
292 |
|
305 | |||
293 | m_seriesGradients << g; |
|
306 | m_seriesGradients << g; | |
294 | } |
|
307 | } | |
295 | } |
|
308 | } | |
296 |
|
309 | |||
297 |
|
310 | |||
298 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
311 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
299 | { |
|
312 | { | |
300 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
313 | Q_ASSERT(pos >=0.0 && pos <= 1.0); | |
301 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
314 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
302 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
315 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
303 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
316 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
304 | QColor c; |
|
317 | QColor c; | |
305 | c.setRgbF(r, g, b); |
|
318 | c.setRgbF(r, g, b); | |
306 | return c; |
|
319 | return c; | |
307 | } |
|
320 | } | |
308 |
|
321 | |||
309 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
322 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
310 | { |
|
323 | { | |
311 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
324 | Q_ASSERT(pos >=0 && pos <= 1.0); | |
312 |
|
325 | |||
313 | // another possibility: |
|
326 | // another possibility: | |
314 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
327 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
315 |
|
328 | |||
316 | QGradientStops stops = gradient.stops(); |
|
329 | QGradientStops stops = gradient.stops(); | |
317 | int count = stops.count(); |
|
330 | int count = stops.count(); | |
318 |
|
331 | |||
319 | // find previous stop relative to position |
|
332 | // find previous stop relative to position | |
320 | QGradientStop prev = stops.first(); |
|
333 | QGradientStop prev = stops.first(); | |
321 | for (int i=0; i<count; i++) { |
|
334 | for (int i=0; i<count; i++) { | |
322 | QGradientStop stop = stops.at(i); |
|
335 | QGradientStop stop = stops.at(i); | |
323 | if (pos > stop.first) |
|
336 | if (pos > stop.first) | |
324 | prev = stop; |
|
337 | prev = stop; | |
325 |
|
338 | |||
326 | // given position is actually a stop position? |
|
339 | // given position is actually a stop position? | |
327 | if (pos == stop.first) { |
|
340 | if (pos == stop.first) { | |
328 | //qDebug() << "stop color" << pos; |
|
341 | //qDebug() << "stop color" << pos; | |
329 | return stop.second; |
|
342 | return stop.second; | |
330 | } |
|
343 | } | |
331 | } |
|
344 | } | |
332 |
|
345 | |||
333 | // find next stop relative to position |
|
346 | // find next stop relative to position | |
334 | QGradientStop next = stops.last(); |
|
347 | QGradientStop next = stops.last(); | |
335 | for (int i=count-1; i>=0; i--) { |
|
348 | for (int i=count-1; i>=0; i--) { | |
336 | QGradientStop stop = stops.at(i); |
|
349 | QGradientStop stop = stops.at(i); | |
337 | if (pos < stop.first) |
|
350 | if (pos < stop.first) | |
338 | next = stop; |
|
351 | next = stop; | |
339 | } |
|
352 | } | |
340 |
|
353 | |||
341 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
354 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
342 |
|
355 | |||
343 | qreal range = next.first - prev.first; |
|
356 | qreal range = next.first - prev.first; | |
344 | qreal posDelta = pos - prev.first; |
|
357 | qreal posDelta = pos - prev.first; | |
345 | qreal relativePos = posDelta / range; |
|
358 | qreal relativePos = posDelta / range; | |
346 |
|
359 | |||
347 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
360 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
348 |
|
361 | |||
349 | return colorAt(prev.second, next.second, relativePos); |
|
362 | return colorAt(prev.second, next.second, relativePos); | |
350 | } |
|
363 | } | |
351 |
|
364 | |||
352 | QTCOMMERCIALCHART_END_NAMESPACE |
|
365 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,165 +1,168 | |||||
1 | #include "dataseriedialog.h" |
|
1 | #include "dataseriedialog.h" | |
2 | #include <QDialogButtonBox> |
|
2 | #include <QDialogButtonBox> | |
3 | #include <QGridLayout> |
|
3 | #include <QGridLayout> | |
4 | #include <QCheckBox> |
|
4 | #include <QCheckBox> | |
5 | #include <QPushButton> |
|
5 | #include <QPushButton> | |
6 | #include <QGroupBox> |
|
6 | #include <QGroupBox> | |
7 | #include <QRadioButton> |
|
7 | #include <QRadioButton> | |
8 | #include <QLabel> |
|
8 | #include <QLabel> | |
9 | #include <QDebug> |
|
9 | #include <QDebug> | |
10 |
|
10 | |||
11 | DataSerieDialog::DataSerieDialog(QWidget *parent) : |
|
11 | DataSerieDialog::DataSerieDialog(QWidget *parent) : | |
12 | QDialog(parent) |
|
12 | QDialog(parent) | |
13 | { |
|
13 | { | |
14 | QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); |
|
14 | QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); | |
15 | QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok); |
|
15 | QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok); | |
16 | connect(b, SIGNAL(clicked()), this, SLOT(accept())); |
|
16 | connect(b, SIGNAL(clicked()), this, SLOT(accept())); | |
17 | b = addSeriesBox->addButton(QDialogButtonBox::Cancel); |
|
17 | b = addSeriesBox->addButton(QDialogButtonBox::Cancel); | |
18 | connect(b, SIGNAL(clicked()), this, SLOT(reject())); |
|
18 | connect(b, SIGNAL(clicked()), this, SLOT(reject())); | |
19 |
|
19 | |||
20 | QGridLayout *grid = new QGridLayout(); |
|
20 | QGridLayout *grid = new QGridLayout(); | |
21 |
|
21 | |||
22 | m_seriesTypeSelector = seriesTypeSelector(); |
|
22 | m_seriesTypeSelector = seriesTypeSelector(); | |
23 | m_columnCountSelector = columnCountSelector(); |
|
23 | m_columnCountSelector = columnCountSelector(); | |
24 | m_rowCountSelector = rowCountSelector(); |
|
24 | m_rowCountSelector = rowCountSelector(); | |
25 | m_dataCharacteristicsSelector = dataCharacteristicsSelector(); |
|
25 | m_dataCharacteristicsSelector = dataCharacteristicsSelector(); | |
26 |
|
26 | |||
27 | grid->addWidget(m_seriesTypeSelector, 0, 0); |
|
27 | grid->addWidget(m_seriesTypeSelector, 0, 0); | |
28 | grid->addWidget(m_columnCountSelector, 0, 1); |
|
28 | grid->addWidget(m_columnCountSelector, 0, 1); | |
29 | grid->addWidget(m_rowCountSelector, 1, 1); |
|
29 | grid->addWidget(m_rowCountSelector, 1, 1); | |
30 | grid->addWidget(m_dataCharacteristicsSelector, 1, 0); |
|
30 | grid->addWidget(m_dataCharacteristicsSelector, 1, 0); | |
31 | m_labelsSelector = new QCheckBox("Labels defined"); |
|
31 | m_labelsSelector = new QCheckBox("Labels defined"); | |
32 | m_labelsSelector->setChecked(true); |
|
32 | m_labelsSelector->setChecked(true); | |
33 | grid->addWidget(m_labelsSelector, 2, 0); |
|
33 | grid->addWidget(m_labelsSelector, 2, 0); | |
34 | grid->addWidget(addSeriesBox, 3, 1); |
|
34 | grid->addWidget(addSeriesBox, 3, 1); | |
35 |
|
35 | |||
36 | setLayout(grid); |
|
36 | setLayout(grid); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | QGroupBox *DataSerieDialog::seriesTypeSelector() |
|
39 | QGroupBox *DataSerieDialog::seriesTypeSelector() | |
40 | { |
|
40 | { | |
41 | QVBoxLayout *layout = new QVBoxLayout(); |
|
41 | QVBoxLayout *layout = new QVBoxLayout(); | |
42 |
|
42 | |||
43 | QRadioButton *line = new QRadioButton("Line"); |
|
43 | QRadioButton *line = new QRadioButton("Line"); | |
44 | line->setChecked(true); |
|
44 | line->setChecked(true); | |
45 | layout->addWidget(line); |
|
45 | layout->addWidget(line); | |
46 | layout->addWidget(new QRadioButton("Area")); |
|
46 | layout->addWidget(new QRadioButton("Area")); | |
47 | layout->addWidget(new QRadioButton("Pie")); |
|
47 | layout->addWidget(new QRadioButton("Pie")); | |
48 | layout->addWidget(new QRadioButton("Bar")); |
|
48 | layout->addWidget(new QRadioButton("Bar")); | |
49 | layout->addWidget(new QRadioButton("Stacked bar")); |
|
49 | layout->addWidget(new QRadioButton("Stacked bar")); | |
50 | layout->addWidget(new QRadioButton("Percent bar")); |
|
50 | layout->addWidget(new QRadioButton("Percent bar")); | |
51 | layout->addWidget(new QRadioButton("Scatter")); |
|
51 | layout->addWidget(new QRadioButton("Scatter")); | |
52 | layout->addWidget(new QRadioButton("Spline")); |
|
52 | layout->addWidget(new QRadioButton("Spline")); | |
53 |
|
53 | |||
54 | QGroupBox *groupBox = new QGroupBox("Series type"); |
|
54 | QGroupBox *groupBox = new QGroupBox("Series type"); | |
55 | groupBox->setLayout(layout); |
|
55 | groupBox->setLayout(layout); | |
56 | selectRadio(groupBox, 0); |
|
56 | selectRadio(groupBox, 0); | |
57 |
|
57 | |||
58 | return groupBox; |
|
58 | return groupBox; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | QGroupBox *DataSerieDialog::columnCountSelector() |
|
61 | QGroupBox *DataSerieDialog::columnCountSelector() | |
62 | { |
|
62 | { | |
63 | QVBoxLayout *layout = new QVBoxLayout(); |
|
63 | QVBoxLayout *layout = new QVBoxLayout(); | |
64 |
|
64 | |||
65 | QRadioButton *radio = new QRadioButton("1"); |
|
65 | QRadioButton *radio = new QRadioButton("1"); | |
66 | radio->setChecked(true); |
|
66 | radio->setChecked(true); | |
67 | layout->addWidget(radio); |
|
67 | layout->addWidget(radio); | |
68 | layout->addWidget(new QRadioButton("2")); |
|
68 | layout->addWidget(new QRadioButton("2")); | |
69 | layout->addWidget(new QRadioButton("3")); |
|
69 | layout->addWidget(new QRadioButton("3")); | |
|
70 | layout->addWidget(new QRadioButton("4")); | |||
70 | layout->addWidget(new QRadioButton("5")); |
|
71 | layout->addWidget(new QRadioButton("5")); | |
|
72 | layout->addWidget(new QRadioButton("8")); | |||
71 | layout->addWidget(new QRadioButton("10")); |
|
73 | layout->addWidget(new QRadioButton("10")); | |
72 | layout->addWidget(new QRadioButton("100")); |
|
74 | layout->addWidget(new QRadioButton("100")); | |
73 |
|
75 | |||
74 | QGroupBox *groupBox = new QGroupBox("Column count"); |
|
76 | QGroupBox *groupBox = new QGroupBox("Column count"); | |
75 | groupBox->setLayout(layout); |
|
77 | groupBox->setLayout(layout); | |
76 | selectRadio(groupBox, 0); |
|
78 | selectRadio(groupBox, 0); | |
77 |
|
79 | |||
78 | return groupBox; |
|
80 | return groupBox; | |
79 | } |
|
81 | } | |
80 |
|
82 | |||
81 | QGroupBox *DataSerieDialog::rowCountSelector() |
|
83 | QGroupBox *DataSerieDialog::rowCountSelector() | |
82 | { |
|
84 | { | |
83 | QVBoxLayout *layout = new QVBoxLayout(); |
|
85 | QVBoxLayout *layout = new QVBoxLayout(); | |
84 |
|
86 | |||
85 | layout->addWidget(new QRadioButton("1")); |
|
87 | layout->addWidget(new QRadioButton("1")); | |
86 | QRadioButton *radio = new QRadioButton("10"); |
|
88 | QRadioButton *radio = new QRadioButton("10"); | |
87 | radio->setChecked(true); |
|
89 | radio->setChecked(true); | |
88 | layout->addWidget(radio); |
|
90 | layout->addWidget(radio); | |
89 | layout->addWidget(new QRadioButton("50")); |
|
91 | layout->addWidget(new QRadioButton("50")); | |
90 | layout->addWidget(new QRadioButton("100")); |
|
92 | layout->addWidget(new QRadioButton("100")); | |
91 | layout->addWidget(new QRadioButton("10000")); |
|
93 | layout->addWidget(new QRadioButton("10000")); | |
|
94 | layout->addWidget(new QRadioButton("100000")); | |||
92 | layout->addWidget(new QRadioButton("1000000")); |
|
95 | layout->addWidget(new QRadioButton("1000000")); | |
93 |
|
96 | |||
94 | QGroupBox *groupBox = new QGroupBox("Row count"); |
|
97 | QGroupBox *groupBox = new QGroupBox("Row count"); | |
95 | groupBox->setLayout(layout); |
|
98 | groupBox->setLayout(layout); | |
96 | selectRadio(groupBox, 0); |
|
99 | selectRadio(groupBox, 0); | |
97 |
|
100 | |||
98 | return groupBox; |
|
101 | return groupBox; | |
99 | } |
|
102 | } | |
100 |
|
103 | |||
101 | QGroupBox *DataSerieDialog::dataCharacteristicsSelector() |
|
104 | QGroupBox *DataSerieDialog::dataCharacteristicsSelector() | |
102 | { |
|
105 | { | |
103 | QVBoxLayout *layout = new QVBoxLayout(); |
|
106 | QVBoxLayout *layout = new QVBoxLayout(); | |
104 |
|
107 | |||
105 | layout->addWidget(new QRadioButton("Linear")); |
|
108 | layout->addWidget(new QRadioButton("Linear")); | |
106 | layout->addWidget(new QRadioButton("Constant")); |
|
109 | layout->addWidget(new QRadioButton("Constant")); | |
107 | layout->addWidget(new QRadioButton("Random")); |
|
110 | layout->addWidget(new QRadioButton("Random")); | |
108 | layout->addWidget(new QRadioButton("Sin")); |
|
111 | layout->addWidget(new QRadioButton("Sin")); | |
109 | layout->addWidget(new QRadioButton("Sin + random")); |
|
112 | layout->addWidget(new QRadioButton("Sin + random")); | |
110 |
|
113 | |||
111 | QGroupBox *groupBox = new QGroupBox("Data Characteristics"); |
|
114 | QGroupBox *groupBox = new QGroupBox("Data Characteristics"); | |
112 | groupBox->setLayout(layout); |
|
115 | groupBox->setLayout(layout); | |
113 | selectRadio(groupBox, 0); |
|
116 | selectRadio(groupBox, 0); | |
114 |
|
117 | |||
115 | return groupBox; |
|
118 | return groupBox; | |
116 | } |
|
119 | } | |
117 |
|
120 | |||
118 | void DataSerieDialog::accept() |
|
121 | void DataSerieDialog::accept() | |
119 | { |
|
122 | { | |
120 | accepted(radioSelection(m_seriesTypeSelector), |
|
123 | accepted(radioSelection(m_seriesTypeSelector), | |
121 | radioSelection(m_columnCountSelector).toInt(), |
|
124 | radioSelection(m_columnCountSelector).toInt(), | |
122 | radioSelection(m_rowCountSelector).toInt(), |
|
125 | radioSelection(m_rowCountSelector).toInt(), | |
123 | radioSelection(m_dataCharacteristicsSelector), |
|
126 | radioSelection(m_dataCharacteristicsSelector), | |
124 | m_labelsSelector->isChecked()); |
|
127 | m_labelsSelector->isChecked()); | |
125 | QDialog::accept(); |
|
128 | QDialog::accept(); | |
126 | } |
|
129 | } | |
127 |
|
130 | |||
128 | void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection) |
|
131 | void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection) | |
129 | { |
|
132 | { | |
130 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); |
|
133 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); | |
131 | Q_ASSERT(layout); |
|
134 | Q_ASSERT(layout); | |
132 | Q_ASSERT(layout->count()); |
|
135 | Q_ASSERT(layout->count()); | |
133 |
|
136 | |||
134 | QLayoutItem *item = 0; |
|
137 | QLayoutItem *item = 0; | |
135 | if (defaultSelection == -1) { |
|
138 | if (defaultSelection == -1) { | |
136 | item = layout->itemAt(0); |
|
139 | item = layout->itemAt(0); | |
137 | } else if (layout->count() > defaultSelection) { |
|
140 | } else if (layout->count() > defaultSelection) { | |
138 | item = layout->itemAt(defaultSelection); |
|
141 | item = layout->itemAt(defaultSelection); | |
139 | } |
|
142 | } | |
140 | Q_ASSERT(item); |
|
143 | Q_ASSERT(item); | |
141 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); |
|
144 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); | |
142 | Q_ASSERT(radio); |
|
145 | Q_ASSERT(radio); | |
143 | radio->setChecked(true); |
|
146 | radio->setChecked(true); | |
144 | } |
|
147 | } | |
145 |
|
148 | |||
146 | QString DataSerieDialog::radioSelection(QGroupBox *groupBox) |
|
149 | QString DataSerieDialog::radioSelection(QGroupBox *groupBox) | |
147 | { |
|
150 | { | |
148 | QString selection; |
|
151 | QString selection; | |
149 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); |
|
152 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); | |
150 | Q_ASSERT(layout); |
|
153 | Q_ASSERT(layout); | |
151 |
|
154 | |||
152 | for (int i(0); i < layout->count(); i++) { |
|
155 | for (int i(0); i < layout->count(); i++) { | |
153 | QLayoutItem *item = layout->itemAt(i); |
|
156 | QLayoutItem *item = layout->itemAt(i); | |
154 | Q_ASSERT(item); |
|
157 | Q_ASSERT(item); | |
155 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); |
|
158 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); | |
156 | Q_ASSERT(radio); |
|
159 | Q_ASSERT(radio); | |
157 | if (radio->isChecked()) { |
|
160 | if (radio->isChecked()) { | |
158 | selection = radio->text(); |
|
161 | selection = radio->text(); | |
159 | break; |
|
162 | break; | |
160 | } |
|
163 | } | |
161 | } |
|
164 | } | |
162 |
|
165 | |||
163 | qDebug() << "radioSelection: " << selection; |
|
166 | qDebug() << "radioSelection: " << selection; | |
164 | return selection; |
|
167 | return selection; | |
165 | } |
|
168 | } |
General Comments 0
You need to be logged in to leave comments.
Login now