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