@@ -44,8 +44,8 | |||||
44 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
44 | ThemeWidget::ThemeWidget(QWidget* parent) : | |
45 | QWidget(parent), |
|
45 | QWidget(parent), | |
46 | m_listCount(3), |
|
46 | m_listCount(3), | |
47 |
m_valueMax(10 |
|
47 | m_valueMax(10), | |
48 |
m_valueCount( |
|
48 | m_valueCount(7), | |
49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), | |
50 | m_themeComboBox(createThemeBox()), |
|
50 | m_themeComboBox(createThemeBox()), | |
51 | m_antialiasCheckBox(new QCheckBox("Anti aliasing")), |
|
51 | m_antialiasCheckBox(new QCheckBox("Anti aliasing")), | |
@@ -53,7 +53,6 ThemeWidget::ThemeWidget(QWidget* parent) : | |||||
53 | m_legendComboBox(createLegendBox()) |
|
53 | m_legendComboBox(createLegendBox()) | |
54 |
|
54 | |||
55 | { |
|
55 | { | |
56 |
|
||||
57 | connectSignals(); |
|
56 | connectSignals(); | |
58 | // create layout |
|
57 | // create layout | |
59 | QGridLayout* baseLayout = new QGridLayout(); |
|
58 | QGridLayout* baseLayout = new QGridLayout(); | |
@@ -97,6 +96,9 ThemeWidget::ThemeWidget(QWidget* parent) : | |||||
97 | m_charts << chartView; |
|
96 | m_charts << chartView; | |
98 |
|
97 | |||
99 | setLayout(baseLayout); |
|
98 | setLayout(baseLayout); | |
|
99 | ||||
|
100 | // Set defaults | |||
|
101 | m_antialiasCheckBox->setChecked(true); | |||
100 | } |
|
102 | } | |
101 |
|
103 | |||
102 | ThemeWidget::~ThemeWidget() |
|
104 | ThemeWidget::~ThemeWidget() | |
@@ -121,8 +123,11 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCo | |||||
121 | // generate random data |
|
123 | // generate random data | |
122 | for (int i(0); i < listCount; i++) { |
|
124 | for (int i(0); i < listCount; i++) { | |
123 | DataList dataList; |
|
125 | DataList dataList; | |
|
126 | qreal yValue(0); | |||
124 | for (int j(0); j < valueCount; j++) { |
|
127 | for (int j(0); j < valueCount; j++) { | |
125 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); |
|
128 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; | |
|
129 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), | |||
|
130 | yValue); | |||
126 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); |
|
131 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); | |
127 | dataList << Data(value, label); |
|
132 | dataList << Data(value, label); | |
128 | } |
|
133 | } | |
@@ -172,22 +177,30 QChart* ThemeWidget::createAreaChart() const | |||||
172 | { |
|
177 | { | |
173 | // area chart |
|
178 | // area chart | |
174 | QChart *chart = new QChart(); |
|
179 | QChart *chart = new QChart(); | |
|
180 | chart->axisX()->setNiceNumbers(true); | |||
|
181 | chart->axisY()->setNiceNumbers(true); | |||
175 | chart->setTitle("Area chart"); |
|
182 | chart->setTitle("Area chart"); | |
|
183 | QString name("Series "); | |||
|
184 | int nameIndex = 0; | |||
|
185 | ||||
|
186 | // The lower series initialized to zero values | |||
|
187 | QLineSeries *lowerSeries = new QLineSeries(chart); | |||
176 | { |
|
188 | { | |
177 | QString name("Series "); |
|
189 | for (int i(0); i < m_valueCount; i++) | |
178 | int nameIndex = 0; |
|
190 | lowerSeries->append(QPointF(i, 0.0)); | |
179 | for (int i(0); i < m_dataTable.count(); i++) { |
|
191 | } | |
180 | QLineSeries *series1 = new QLineSeries(chart); |
|
192 | ||
181 | QLineSeries *series2 = new QLineSeries(chart); |
|
193 | for (int i(0); i < m_dataTable.count(); i++) { | |
182 | foreach (Data data, m_dataTable[i]) { |
|
194 | QLineSeries *upperSeries = new QLineSeries(chart); | |
183 | series1->append(data.first); |
|
195 | for (int j(0); j < m_dataTable[i].count(); j++) { | |
184 | series2->append(QPointF(data.first.x(), 0.0)); |
|
196 | Data data = m_dataTable[i].at(j); | |
185 | } |
|
197 | upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y())); | |
186 | QAreaSeries *area = new QAreaSeries(series1, series2); |
|
|||
187 | area->setName(name + QString::number(nameIndex)); |
|
|||
188 | nameIndex++; |
|
|||
189 | chart->addSeries(area); |
|
|||
190 | } |
|
198 | } | |
|
199 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |||
|
200 | area->setName(name + QString::number(nameIndex)); | |||
|
201 | nameIndex++; | |||
|
202 | chart->addSeries(area); | |||
|
203 | lowerSeries = upperSeries; | |||
191 | } |
|
204 | } | |
192 | return chart; |
|
205 | return chart; | |
193 | } |
|
206 | } | |
@@ -196,23 +209,23 QChart* ThemeWidget::createBarChart(int valueCount) const | |||||
196 | { |
|
209 | { | |
197 | // bar chart |
|
210 | // bar chart | |
198 | QChart* chart = new QChart(); |
|
211 | QChart* chart = new QChart(); | |
|
212 | chart->axisX()->setNiceNumbers(true); | |||
|
213 | chart->axisY()->setNiceNumbers(true); | |||
199 | chart->setTitle("Bar chart"); |
|
214 | chart->setTitle("Bar chart"); | |
200 | { |
|
215 | QBarCategories categories; | |
201 | QBarCategories categories; |
|
216 | // TODO: categories | |
202 | // TODO: categories |
|
217 | for (int i(0); i < valueCount; i++) | |
203 | for (int i(0); i < valueCount; i++) |
|
218 | categories << QString::number(i); | |
204 | categories << QString::number(i); |
|
|||
205 | // QBarSeries* series = new QBarSeries(categories, chart); |
|
219 | // QBarSeries* series = new QBarSeries(categories, chart); | |
206 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); |
|
220 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |
207 |
|
|
221 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); | |
208 |
|
|
222 | for (int i(0); i < m_dataTable.count(); i++) { | |
209 |
|
|
223 | QBarSet *set = new QBarSet("Set" + QString::number(i)); | |
210 |
|
|
224 | foreach (Data data, m_dataTable[i]) | |
211 |
|
|
225 | *set << data.first.y(); | |
212 |
|
|
226 | series->appendBarSet(set); | |
213 | } |
|
|||
214 | chart->addSeries(series); |
|
|||
215 | } |
|
227 | } | |
|
228 | chart->addSeries(series); | |||
216 | return chart; |
|
229 | return chart; | |
217 | } |
|
230 | } | |
218 |
|
231 | |||
@@ -220,6 +233,8 QChart* ThemeWidget::createLineChart() const | |||||
220 | { |
|
233 | { | |
221 | // line chart |
|
234 | // line chart | |
222 | QChart* chart = new QChart(); |
|
235 | QChart* chart = new QChart(); | |
|
236 | chart->axisX()->setNiceNumbers(true); | |||
|
237 | chart->axisY()->setNiceNumbers(true); | |||
223 | chart->setTitle("Line chart"); |
|
238 | chart->setTitle("Line chart"); | |
224 | QString name("Series "); |
|
239 | QString name("Series "); | |
225 | int nameIndex = 0; |
|
240 | int nameIndex = 0; | |
@@ -261,6 +276,8 QChart* ThemeWidget::createPieChart() const | |||||
261 | QChart* ThemeWidget::createSplineChart() const |
|
276 | QChart* ThemeWidget::createSplineChart() const | |
262 | { // spine chart |
|
277 | { // spine chart | |
263 | QChart* chart = new QChart(); |
|
278 | QChart* chart = new QChart(); | |
|
279 | chart->axisX()->setNiceNumbers(true); | |||
|
280 | chart->axisY()->setNiceNumbers(true); | |||
264 | chart->setTitle("Spline chart"); |
|
281 | chart->setTitle("Spline chart"); | |
265 | QString name("Series "); |
|
282 | QString name("Series "); | |
266 | int nameIndex = 0; |
|
283 | int nameIndex = 0; | |
@@ -278,6 +295,8 QChart* ThemeWidget::createSplineChart() const | |||||
278 | QChart* ThemeWidget::createScatterChart() const |
|
295 | QChart* ThemeWidget::createScatterChart() const | |
279 | { // scatter chart |
|
296 | { // scatter chart | |
280 | QChart* chart = new QChart(); |
|
297 | QChart* chart = new QChart(); | |
|
298 | chart->axisX()->setNiceNumbers(true); | |||
|
299 | chart->axisY()->setNiceNumbers(true); | |||
281 | chart->setTitle("Scatter chart"); |
|
300 | chart->setTitle("Scatter chart"); | |
282 | QString name("Series "); |
|
301 | QString name("Series "); | |
283 | int nameIndex = 0; |
|
302 | int nameIndex = 0; |
General Comments 0
You need to be logged in to leave comments.
Login now