@@ -0,0 +1,74 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | import QtQuick 1.0 | |
|
22 | import QtCommercial.Chart 1.0 | |
|
23 | ||
|
24 | Rectangle { | |
|
25 | width: parent.width | |
|
26 | height: parent.height | |
|
27 | ||
|
28 | // Another option for QML data api: | |
|
29 | // ListModel { | |
|
30 | // id: listModelForPie | |
|
31 | // // PieDataElement | |
|
32 | // ListElement { | |
|
33 | // label: "Apple" | |
|
34 | // value: 4.3 | |
|
35 | // } | |
|
36 | // ListElement { | |
|
37 | // label: "Blackberry" | |
|
38 | // value: 15.1 | |
|
39 | // } | |
|
40 | // } | |
|
41 | ||
|
42 | Component.onCompleted: { | |
|
43 | // console.log("model:" + myModel.item(0)); | |
|
44 | // myModel.insert(1, {"time":1.4; "speed":41.1 }); | |
|
45 | // scatter.appendData(); | |
|
46 | // chart1.theme = Chart.ThemeHighContrast; | |
|
47 | // chart2.theme = Chart.ThemeHighContrast; | |
|
48 | } | |
|
49 | ||
|
50 | Chart { | |
|
51 | id: chart1 | |
|
52 | anchors.fill: parent | |
|
53 | theme: Chart.ChartThemeDark | |
|
54 | ||
|
55 | BarSeries { | |
|
56 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] | |
|
57 | // TBD: data | |
|
58 | } | |
|
59 | ||
|
60 | PieSeries { | |
|
61 | horizontalPosition: 0.2 | |
|
62 | verticalPosition: 0.3 | |
|
63 | size: 0.4 | |
|
64 | endAngle: 0.52 * 360 // The share of "others" is 52% | |
|
65 | slices: [ | |
|
66 | PieSlice { label: "Volkswagen"; value: 13.5 }, | |
|
67 | PieSlice { label: "Toyota"; value: 10.9 }, | |
|
68 | PieSlice { label: "Ford"; value: 8.6 }, | |
|
69 | PieSlice { label: "Skoda"; value: 8.2 }, | |
|
70 | PieSlice { label: "Volvo"; value: 6.8 } | |
|
71 | ] | |
|
72 | } | |
|
73 | } | |
|
74 | } |
@@ -0,0 +1,51 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | import QtQuick 1.0 | |
|
22 | import QtCommercial.Chart 1.0 | |
|
23 | ||
|
24 | Rectangle { | |
|
25 | anchors.fill: parent | |
|
26 | ||
|
27 | Chart { | |
|
28 | anchors.fill: parent | |
|
29 | theme: Chart.ChartThemeBrownSand | |
|
30 | ||
|
31 | LineSeries { | |
|
32 | name: "Line" | |
|
33 | points: [ | |
|
34 | XyPoint { x: 0.0; y: 0.0 }, | |
|
35 | XyPoint { x: 1.1; y: 2.1 }, | |
|
36 | XyPoint { x: 2.9; y: 4.9 }, | |
|
37 | XyPoint { x: 3.2; y: 3.0 } | |
|
38 | ] | |
|
39 | } | |
|
40 | ||
|
41 | SplineSeries { | |
|
42 | name: "Spline" | |
|
43 | points: [ | |
|
44 | XyPoint { x: 0.0; y: 0.3 }, | |
|
45 | XyPoint { x: 1.1; y: 3.2 }, | |
|
46 | XyPoint { x: 2.17; y: 2.15 }, | |
|
47 | XyPoint { x: 4.17; y: 3.15 } | |
|
48 | ] | |
|
49 | } | |
|
50 | } | |
|
51 | } |
@@ -0,0 +1,70 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | import QtQuick 1.0 | |
|
22 | import QtCommercial.Chart 1.0 | |
|
23 | ||
|
24 | Rectangle { | |
|
25 | anchors.fill: parent | |
|
26 | ||
|
27 | Chart { | |
|
28 | anchors.fill: parent | |
|
29 | theme: Chart.ChartThemeHighContrast | |
|
30 | ||
|
31 | AreaSeries { | |
|
32 | name: "Area" | |
|
33 | points: [ | |
|
34 | XyPoint { x: 0.0; y: 1.1 }, | |
|
35 | XyPoint { x: 2.5; y: 3.6 }, | |
|
36 | XyPoint { x: 3.57; y: 2.55 } | |
|
37 | ] | |
|
38 | lowerPoints: [ | |
|
39 | XyPoint { x: 0.0; y: 0.0 }, | |
|
40 | XyPoint { x: 2.5; y: 0.0 }, | |
|
41 | XyPoint { x: 3.57; y: 0.0 } | |
|
42 | ] | |
|
43 | } | |
|
44 | ||
|
45 | ScatterSeries { | |
|
46 | name: "Scatter1" | |
|
47 | points: [ | |
|
48 | XyPoint { x: 1.5; y: 1.5 }, | |
|
49 | XyPoint { x: 1.5; y: 1.6 }, | |
|
50 | XyPoint { x: 1.57; y: 1.55 } | |
|
51 | ] | |
|
52 | } | |
|
53 | ScatterSeries { | |
|
54 | name: "Scatter2" | |
|
55 | points: [ | |
|
56 | XyPoint { x: 2.0; y: 2.0 }, | |
|
57 | XyPoint { x: 2.0; y: 2.1 }, | |
|
58 | XyPoint { x: 2.07; y: 2.05 } | |
|
59 | ] | |
|
60 | } | |
|
61 | ScatterSeries { | |
|
62 | name: "Scatter3" | |
|
63 | points: [ | |
|
64 | XyPoint { x: 2.6; y: 2.6 }, | |
|
65 | XyPoint { x: 2.6; y: 2.7 }, | |
|
66 | XyPoint { x: 2.67; y: 2.65 } | |
|
67 | ] | |
|
68 | } | |
|
69 | } | |
|
70 | } |
@@ -1,333 +1,336 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "tablewidget.h" |
|
22 | 22 | #include <QGridLayout> |
|
23 | 23 | #include <QTableView> |
|
24 | 24 | #include <QStyledItemDelegate> |
|
25 | 25 | #include <QLineSeries> |
|
26 | 26 | #include <QSplineSeries> |
|
27 | 27 | #include <QScatterSeries> |
|
28 | 28 | #include "customtablemodel.h" |
|
29 | 29 | #include <QPieSeries> |
|
30 | 30 | #include <QPieSlice> |
|
31 | 31 | #include <QAreaSeries> |
|
32 | 32 | #include <QBarSeries> |
|
33 | 33 | #include <QBarSet> |
|
34 | 34 | #include <QPushButton> |
|
35 | 35 | #include <QRadioButton> |
|
36 | 36 | #include <QLabel> |
|
37 | 37 | #include <QSpinBox> |
|
38 | 38 | #include <QTime> |
|
39 | 39 | |
|
40 | 40 | TableWidget::TableWidget(QWidget *parent) |
|
41 | 41 | : QWidget(parent) |
|
42 | 42 | { |
|
43 | 43 | setGeometry(100, 100, 1000, 600); |
|
44 | 44 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
45 | 45 | // create simple model for storing data |
|
46 | 46 | // user's table data model |
|
47 | 47 | m_model = new CustomTableModel; |
|
48 | 48 | m_tableView = new QTableView; |
|
49 | 49 | m_tableView->setModel(m_model); |
|
50 | 50 | m_tableView->setMinimumHeight(300); |
|
51 | 51 | // tableView->setMinimumSize(340, 480); |
|
52 | 52 | // tableView->setItemDelegate(new QStyledItemDelegate); |
|
53 | 53 | m_chart = new QChart; |
|
54 | 54 | m_chartView = new QChartView(m_chart); |
|
55 | 55 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
56 | 56 | m_chartView->setMinimumSize(640, 480); |
|
57 | 57 | |
|
58 | 58 | // add, remove data buttons |
|
59 | 59 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
60 | 60 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
61 | 61 | |
|
62 | 62 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
63 | 63 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
64 | 64 | |
|
65 | 65 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
66 | 66 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
67 | 67 | |
|
68 | 68 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
69 | 69 | |
|
70 | 70 | // spin box for setting number of affected items (add, remove) |
|
71 | 71 | m_linesCountSpinBox = new QSpinBox; |
|
72 | 72 | m_linesCountSpinBox->setRange(1, 10); |
|
73 | 73 | m_linesCountSpinBox->setValue(1); |
|
74 | 74 | |
|
75 | 75 | // buttons layout |
|
76 | 76 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
77 | 77 | buttonsLayout->addWidget(spinBoxLabel); |
|
78 | 78 | buttonsLayout->addWidget(m_linesCountSpinBox); |
|
79 | 79 | buttonsLayout->addWidget(addRowAboveButton); |
|
80 | 80 | buttonsLayout->addWidget(addRowBelowButton); |
|
81 | 81 | buttonsLayout->addWidget(removeRowButton); |
|
82 | 82 | buttonsLayout->addStretch(); |
|
83 | 83 | |
|
84 | 84 | // chart type radio buttons |
|
85 | 85 | m_lineRadioButton = new QRadioButton("Line"); |
|
86 | 86 | m_splineRadioButton = new QRadioButton("Spline"); |
|
87 | 87 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
88 | 88 | m_pieRadioButton = new QRadioButton("Pie"); |
|
89 | 89 | m_areaRadioButton = new QRadioButton("Area"); |
|
90 | 90 | m_barRadioButton = new QRadioButton("Bar"); |
|
91 | 91 | |
|
92 | 92 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
93 | 93 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
94 | 94 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
95 | 95 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
96 | 96 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
97 | 97 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
98 | 98 | m_lineRadioButton->setChecked(true); |
|
99 | 99 | |
|
100 | 100 | // radio buttons layout |
|
101 | 101 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
102 | 102 | radioLayout->addWidget(m_lineRadioButton); |
|
103 | 103 | radioLayout->addWidget(m_splineRadioButton); |
|
104 | 104 | radioLayout->addWidget(m_scatterRadioButton); |
|
105 | 105 | radioLayout->addWidget(m_pieRadioButton); |
|
106 | 106 | radioLayout->addWidget(m_areaRadioButton); |
|
107 | 107 | radioLayout->addWidget(m_barRadioButton); |
|
108 | 108 | radioLayout->addStretch(); |
|
109 | 109 | |
|
110 | 110 | // create main layout |
|
111 | 111 | QGridLayout* mainLayout = new QGridLayout; |
|
112 | 112 | mainLayout->addLayout(buttonsLayout, 1, 1); |
|
113 | 113 | mainLayout->addLayout(radioLayout, 2, 1); |
|
114 | 114 | mainLayout->addWidget(m_tableView, 1, 0); |
|
115 | 115 | mainLayout->addWidget(m_chartView, 2, 0); |
|
116 | 116 | setLayout(mainLayout); |
|
117 | 117 | m_lineRadioButton->setFocus(); |
|
118 | 118 | } |
|
119 | 119 | |
|
120 | 120 | void TableWidget::addRowAbove() |
|
121 | 121 | { |
|
122 | 122 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
123 | 123 | |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void TableWidget::addRowBelow() |
|
127 | 127 | { |
|
128 | 128 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
129 | 129 | |
|
130 | 130 | } |
|
131 | 131 | |
|
132 | 132 | void TableWidget::removeRow() |
|
133 | 133 | { |
|
134 | 134 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | void TableWidget::updateChartType(bool toggle) |
|
138 | 138 | { |
|
139 | 139 | // this if is needed, so that the function is only called once. |
|
140 | 140 | // For the radioButton that was enabled. |
|
141 | 141 | if (toggle) { |
|
142 | 142 | m_chart->removeAllSeries(); |
|
143 | 143 | |
|
144 | 144 | // renable axes of the chart (pie hides them) |
|
145 | 145 | // x axis |
|
146 | 146 | QChartAxis *axis = m_chart->axisX(); |
|
147 | 147 | axis->setAxisVisible(true); |
|
148 | 148 | axis->setGridLineVisible(true); |
|
149 | 149 | axis->setLabelsVisible(true); |
|
150 | 150 | |
|
151 | 151 | // y axis |
|
152 | 152 | axis = m_chart->axisY(); |
|
153 | 153 | axis->setAxisVisible(true); |
|
154 | 154 | axis->setGridLineVisible(true); |
|
155 | 155 | axis->setLabelsVisible(true); |
|
156 | 156 | |
|
157 | 157 | m_model->clearMapping(); |
|
158 | 158 | |
|
159 | 159 | QString seriesColorHex = "#000000"; |
|
160 | 160 | QPen pen; |
|
161 | 161 | pen.setWidth(2); |
|
162 | 162 | |
|
163 | 163 | if (m_lineRadioButton->isChecked()) |
|
164 | 164 | { |
|
165 | 165 | // series 1 |
|
166 | 166 | m_series = new QLineSeries; |
|
167 | 167 | m_series->setModel(m_model); |
|
168 | 168 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
169 | 169 | m_series->setModelMappingRange(1, 4); |
|
170 | 170 | m_chart->addSeries(m_series); |
|
171 | 171 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
172 | 172 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); |
|
173 | 173 | |
|
174 | 174 | // series 2 |
|
175 | 175 | m_series = new QLineSeries; |
|
176 | 176 | m_series->setModel(m_model); |
|
177 | 177 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
178 | 178 | m_chart->addSeries(m_series); |
|
179 | 179 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
180 | 180 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
181 | 181 | |
|
182 | 182 | // series 3 |
|
183 | 183 | m_series = new QLineSeries; |
|
184 | 184 | m_series->setModel(m_model); |
|
185 | 185 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
186 | 186 | m_series->setModelMappingRange(2, 0); |
|
187 | 187 | m_chart->addSeries(m_series); |
|
188 | 188 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
189 | 189 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
190 | 190 | } |
|
191 | 191 | else if (m_splineRadioButton->isChecked()) |
|
192 | 192 | { |
|
193 | 193 | // series 1 |
|
194 | 194 | m_series = new QSplineSeries; |
|
195 | 195 | m_series->setModel(m_model); |
|
196 | 196 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
197 | 197 | m_series->setModelMappingRange(1, 4); |
|
198 | 198 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
199 | 199 | m_chart->addSeries(m_series); |
|
200 | 200 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
201 | 201 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); |
|
202 | 202 | |
|
203 | 203 | // series 2 |
|
204 | 204 | m_series = new QSplineSeries; |
|
205 | 205 | m_series->setModel(m_model); |
|
206 | 206 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
207 | 207 | m_series->setModelMappingRange(0, 0); |
|
208 | 208 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
209 | 209 | m_chart->addSeries(m_series); |
|
210 | 210 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
211 | 211 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
212 | 212 | |
|
213 | 213 | // series 3 |
|
214 | 214 | m_series = new QSplineSeries; |
|
215 | 215 | m_series->setModel(m_model); |
|
216 | 216 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
217 | 217 | m_series->setModelMappingRange(2, 0); |
|
218 | 218 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
219 | 219 | m_chart->addSeries(m_series); |
|
220 | 220 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
221 | 221 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
222 | 222 | } |
|
223 | 223 | else if (m_scatterRadioButton->isChecked()) |
|
224 | 224 | { |
|
225 | 225 | // series 1 |
|
226 | 226 | m_series = new QScatterSeries; |
|
227 | 227 | m_series->setModel(m_model); |
|
228 | 228 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
229 | 229 | m_series->setModelMappingRange(2, 0); |
|
230 | 230 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
231 | 231 | m_chart->addSeries(m_series); |
|
232 | 232 | |
|
233 | 233 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
234 | 234 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
235 | 235 | |
|
236 | 236 | // series 2 |
|
237 | 237 | m_series = new QScatterSeries; |
|
238 | 238 | m_series->setModel(m_model); |
|
239 | 239 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
240 | 240 | m_series->setModelMappingRange(1, 6); |
|
241 | 241 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
242 | 242 | m_chart->addSeries(m_series); |
|
243 | 243 | |
|
244 | 244 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
245 | 245 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
246 | 246 | |
|
247 | 247 | // series 3 |
|
248 | 248 | m_series = new QScatterSeries; |
|
249 | 249 | m_series->setModel(m_model); |
|
250 | 250 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
251 | 251 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
252 | 252 | m_chart->addSeries(m_series); |
|
253 | 253 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
254 | 254 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
255 | 255 | } |
|
256 | 256 | else if (m_pieRadioButton->isChecked()) |
|
257 | 257 | { |
|
258 | 258 | // pie 1 |
|
259 | 259 | QPieSeries* pieSeries = new QPieSeries; |
|
260 | 260 | pieSeries->setModel(m_model); |
|
261 | 261 | pieSeries->setModelMapping(0,0, Qt::Vertical); |
|
262 | 262 | pieSeries->setLabelsVisible(true); |
|
263 | 263 | pieSeries->setPieSize(0.4); |
|
264 |
pieSeries->set |
|
|
264 | pieSeries->setHorizontalPosition(0.2); | |
|
265 | pieSeries->setVerticalPosition(0.35); | |
|
265 | 266 | |
|
266 | 267 | m_chart->addSeries(pieSeries); |
|
267 | 268 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
268 | 269 | m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000)); |
|
269 | 270 | |
|
270 | 271 | // pie 2 |
|
271 | 272 | pieSeries = new QPieSeries; |
|
272 | 273 | pieSeries->setModel(m_model); |
|
273 | 274 | pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
274 | 275 | pieSeries->setLabelsVisible(true); |
|
275 | 276 | pieSeries->setPieSize(0.4); |
|
276 |
pieSeries->set |
|
|
277 | pieSeries->setHorizontalPosition(0.8); | |
|
278 | pieSeries->setVerticalPosition(0.35); | |
|
277 | 279 | m_chart->addSeries(pieSeries); |
|
278 | 280 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
279 | 281 | m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000)); |
|
280 | 282 | |
|
281 | 283 | // pie 3 |
|
282 | 284 | pieSeries = new QPieSeries; |
|
283 | 285 | pieSeries->setModel(m_model); |
|
284 | 286 | pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
285 | 287 | pieSeries->setLabelsVisible(true); |
|
286 | 288 | pieSeries->setPieSize(0.4); |
|
287 |
pieSeries->set |
|
|
289 | pieSeries->setHorizontalPosition(0.5); | |
|
290 | pieSeries->setVerticalPosition(0.65); | |
|
288 | 291 | m_chart->addSeries(pieSeries); |
|
289 | 292 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
290 | 293 | m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
291 | 294 | } |
|
292 | 295 | else if (m_areaRadioButton->isChecked()) |
|
293 | 296 | { |
|
294 | 297 | QLineSeries* upperLineSeries = new QLineSeries; |
|
295 | 298 | upperLineSeries->setModel(m_model); |
|
296 | 299 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
297 | 300 | upperLineSeries->setModelMappingRange(1, 5); |
|
298 | 301 | QLineSeries* lowerLineSeries = new QLineSeries; |
|
299 | 302 | lowerLineSeries->setModel(m_model); |
|
300 | 303 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
301 | 304 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
302 | 305 | m_chart->addSeries(areaSeries); |
|
303 | 306 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
304 | 307 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
305 | 308 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
306 | 309 | } |
|
307 | 310 | else if (m_barRadioButton->isChecked()) |
|
308 | 311 | { |
|
309 | 312 | QBarSeries* barSeries = new QBarSeries(QStringList()); |
|
310 | 313 | barSeries->setModel(m_model); |
|
311 | 314 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
312 | 315 | barSeries->setToolTipEnabled(true); |
|
313 | 316 | m_chart->addSeries(barSeries); |
|
314 | 317 | for (int i = 0; i < barSeries->barsetCount(); i++) { |
|
315 | 318 | seriesColorHex = "#" + QString::number(barSeries->barsetAt(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
316 | 319 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
317 | 320 | } |
|
318 | 321 | } |
|
319 | 322 | |
|
320 | 323 | |
|
321 | 324 | m_chart->axisX()->setRange(0, 500); |
|
322 | 325 | m_chart->axisY()->setRange(0, 120); |
|
323 | 326 | |
|
324 | 327 | // repaint table view colors |
|
325 | 328 | m_tableView->repaint(); |
|
326 | 329 | m_tableView->setFocus(); |
|
327 | 330 | } |
|
328 | 331 | } |
|
329 | 332 | |
|
330 | 333 | TableWidget::~TableWidget() |
|
331 | 334 | { |
|
332 | 335 | |
|
333 | 336 | } |
@@ -1,37 +1,37 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | |
|
23 | 23 | Item { |
|
24 | 24 | id: container |
|
25 | 25 | width: 400 |
|
26 |
height: |
|
|
26 | height: 300 | |
|
27 | 27 | Component.onCompleted: { |
|
28 | 28 | var co = Qt.createComponent("main.qml") |
|
29 | 29 | if (co.status == Component.Ready) { |
|
30 | 30 | var o = co.createObject(container) |
|
31 | 31 | } else { |
|
32 | 32 | console.log(co.errorString()) |
|
33 | 33 | console.log("QtCommercial.Chart 1.1 not available") |
|
34 | 34 | console.log("Please use correct QML_IMPORT_PATH export") |
|
35 | 35 | } |
|
36 | 36 | } |
|
37 | 37 | } |
@@ -1,147 +1,54 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | |
|
24 | 24 | Rectangle { |
|
25 | 25 | width: parent.width |
|
26 | 26 | height: parent.height |
|
27 | ||
|
28 | // Another option for QML data api: | |
|
29 | // ListModel { | |
|
30 |
|
|
|
31 | // // PieDataElement | |
|
32 | // ListElement { | |
|
33 | // label: "Apple" | |
|
34 | // value: 4.3 | |
|
35 | // } | |
|
36 | // ListElement { | |
|
37 | // label: "Blackberry" | |
|
38 | // value: 15.1 | |
|
39 | // } | |
|
40 | // } | |
|
41 | ||
|
42 | Component.onCompleted: { | |
|
43 | // console.log("model:" + myModel.item(0)); | |
|
44 | // myModel.insert(1, {"time":1.4; "speed":41.1 }); | |
|
45 | // scatter.appendData(); | |
|
46 | // chart1.theme = Chart.ThemeHighContrast; | |
|
47 | // chart2.theme = Chart.ThemeHighContrast; | |
|
48 | } | |
|
49 | ||
|
50 | ||
|
51 | Chart { | |
|
52 | id: chart1 | |
|
53 | anchors.top: parent.top | |
|
54 | anchors.left: parent.left | |
|
55 | anchors.right: parent.right | |
|
56 | height: parent.height / 2 | |
|
57 | theme: Chart.ChartThemeDark | |
|
58 | ||
|
59 | BarSeries { | |
|
60 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] | |
|
61 | // TBD: data | |
|
62 | } | |
|
63 | ||
|
64 | PieSeries { | |
|
65 | horizontalPosition: 0.2 | |
|
66 | verticalPosition: 0.3 | |
|
67 | size: 0.4 | |
|
68 | endAngle: 0.52 * 360 // The share of "others" is 52% | |
|
69 | slices: [ | |
|
70 | PieSlice { label: "Volkswagen"; value: 13.5 }, | |
|
71 | PieSlice { label: "Toyota"; value: 10.9 }, | |
|
72 | PieSlice { label: "Ford"; value: 8.6 }, | |
|
73 | PieSlice { label: "Skoda"; value: 8.2 }, | |
|
74 | PieSlice { label: "Volvo"; value: 6.8 } | |
|
75 | ] | |
|
27 | property int __viewNumber: 0 | |
|
28 | ||
|
29 | Timer { | |
|
30 | id: timer | |
|
31 | running: true | |
|
32 | repeat: true | |
|
33 | interval: 5000 | |
|
34 | triggeredOnStart: true | |
|
35 | onTriggered: { | |
|
36 | loader.source = "View" + (__viewNumber % 3 + 1) + ".qml"; | |
|
37 | __viewNumber++; | |
|
76 | 38 | } |
|
77 | 39 | } |
|
78 | 40 | |
|
41 | Loader { | |
|
42 | id: loader | |
|
43 | anchors.fill: parent | |
|
44 | } | |
|
79 | 45 | |
|
80 | Chart { | |
|
81 |
|
|
|
82 | anchors.top: chart1.bottom | |
|
83 | anchors.bottom: parent.bottom | |
|
84 | anchors.left: parent.left | |
|
85 | anchors.right: parent.right | |
|
86 | theme: Chart.ChartThemeBrownSand | |
|
87 | ||
|
88 | LineSeries { | |
|
89 | name: "Line" | |
|
90 | points: [ | |
|
91 | XyPoint { x: 0.0; y: 0.0 }, | |
|
92 | XyPoint { x: 1.1; y: 2.1 }, | |
|
93 | XyPoint { x: 2.9; y: 4.9 }, | |
|
94 | XyPoint { x: 3.2; y: 3.0 } | |
|
95 | ] | |
|
96 | } | |
|
97 | ||
|
98 | SplineSeries { | |
|
99 | name: "Spline" | |
|
100 | points: [ | |
|
101 | XyPoint { x: 0.0; y: 0.3 }, | |
|
102 | XyPoint { x: 1.1; y: 3.2 }, | |
|
103 | XyPoint { x: 2.17; y: 2.15 }, | |
|
104 | XyPoint { x: 4.17; y: 3.15 } | |
|
105 | ] | |
|
106 | } | |
|
107 | ||
|
108 | AreaSeries { | |
|
109 | name: "Area" | |
|
110 | points: [ | |
|
111 | XyPoint { x: 0.0; y: 1.1 }, | |
|
112 | XyPoint { x: 2.5; y: 3.6 }, | |
|
113 | XyPoint { x: 3.57; y: 2.55 } | |
|
114 | ] | |
|
115 | lowerPoints: [ | |
|
116 | XyPoint { x: 0.0; y: 0.0 }, | |
|
117 | XyPoint { x: 2.5; y: 0.0 }, | |
|
118 | XyPoint { x: 3.57; y: 0.0 } | |
|
119 | ] | |
|
120 | } | |
|
121 | ||
|
122 | ScatterSeries { | |
|
123 | name: "Scatter1" | |
|
124 | points: [ | |
|
125 | XyPoint { x: 1.5; y: 1.5 }, | |
|
126 | XyPoint { x: 1.5; y: 1.6 }, | |
|
127 | XyPoint { x: 1.57; y: 1.55 } | |
|
128 | ] | |
|
129 | } | |
|
130 | ScatterSeries { | |
|
131 | name: "Scatter2" | |
|
132 | points: [ | |
|
133 | XyPoint { x: 2.0; y: 2.0 }, | |
|
134 | XyPoint { x: 2.0; y: 2.1 }, | |
|
135 | XyPoint { x: 2.07; y: 2.05 } | |
|
136 | ] | |
|
137 | } | |
|
138 | ScatterSeries { | |
|
139 | name: "Scatter3" | |
|
140 | points: [ | |
|
141 | XyPoint { x: 2.6; y: 2.6 }, | |
|
142 | XyPoint { x: 2.6; y: 2.7 }, | |
|
143 | XyPoint { x: 2.67; y: 2.65 } | |
|
144 | ] | |
|
46 | MouseArea { | |
|
47 | anchors.fill: parent | |
|
48 | onClicked: { | |
|
49 | timer.restart(); | |
|
50 | loader.source = "View" + (__viewNumber % 3 + 1) + ".qml"; | |
|
51 | __viewNumber++; | |
|
145 | 52 | } |
|
146 | 53 | } |
|
147 | 54 | } |
General Comments 0
You need to be logged in to leave comments.
Login now