##// END OF EJS Templates
QML test app's scatter and area into separate views
Tero Ahola -
r918:1555e575642a
parent child
Show More
@@ -0,0 +1,57
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 title: "Scatters"
29 anchors.fill: parent
30 theme: Chart.ChartThemeBlueCerulean
31
32 ScatterSeries {
33 id: scatter1
34 name: "Scatter1"
35 points: [
36 XyPoint { x: 1.5; y: 1.5 },
37 XyPoint { x: 1.5; y: 1.6 },
38 XyPoint { x: 1.57; y: 1.55 },
39 XyPoint { x: 1.8; y: 1.8 },
40 XyPoint { x: 1.9; y: 1.6 },
41 XyPoint { x: 2.1; y: 1.3 },
42 XyPoint { x: 2.5; y: 2.1 }
43 ]
44 }
45 ScatterSeries {
46 name: "Scatter2"
47 points: [
48 XyPoint { x: 2.0; y: 2.0 },
49 XyPoint { x: 2.0; y: 2.1 },
50 XyPoint { x: 2.07; y: 2.05 },
51 XyPoint { x: 2.2; y: 2.9 },
52 XyPoint { x: 2.4; y: 2.7 },
53 XyPoint { x: 2.67; y: 2.65 }
54 ]
55 }
56 }
57 }
@@ -1,89 +1,89
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 "declarativebarseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include "qbarseries.h"
25 25 #include "qbarset.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
30 30 QDeclarativeItem(parent)
31 31 {
32 32 setFlag(QGraphicsItem::ItemHasNoContents, false);
33 33 }
34 34
35 35 void DeclarativeBarSeries::componentComplete()
36 36 {
37 37 if (!m_series) {
38 38 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
39 39
40 40 if (declarativeChart) {
41 41 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
42 42 Q_ASSERT(chart);
43 43
44 44 // QStringList categories;
45 45 // categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
46 46 // m_series = new QBarSeries(categories);
47 47 // m_series = new QBarSeries(m_categories);
48 48 m_series = new QBarSeries(m_categories);
49 49
50 50 // TODO: use data from model
51 51 QBarSet *set0 = new QBarSet("Bub");
52 52 QBarSet *set1 = new QBarSet("Bob");
53 53 QBarSet *set2 = new QBarSet("Guybrush");
54 54
55 55 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
56 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
56 *set1 << 5 << 1 << 2 << 4 << 1 << 7;
57 57 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
58 58
59 59 m_series->appendBarSet(set0);
60 60 m_series->appendBarSet(set1);
61 61 m_series->appendBarSet(set2);
62 62
63 63 chart->addSeries(m_series);
64 64 }
65 65 }
66 66 }
67 67
68 68 void DeclarativeBarSeries::setBarCategories(QStringList categories)
69 69 {
70 70 m_categories = categories;
71 71 if (m_series) {
72 72 // Replace categories of the QBarSeries with the new categories
73 73 for (int i(0); i < m_categories.count(); i++) {
74 74 if (m_series->categories().at(i) != m_categories.at(i))
75 75 m_series->insertCategory(m_series->categoryCount(), m_categories.at(i));
76 76 }
77 77 while (m_series->categoryCount() > m_categories.count())
78 78 m_series->removeCategory(m_series->categoryCount() - 1);
79 79 }
80 80 }
81 81
82 82 QStringList DeclarativeBarSeries::barCategories()
83 83 {
84 84 return m_categories;
85 85 }
86 86
87 87 #include "moc_declarativebarseries.cpp"
88 88
89 89 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,58 +1,61
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 #ifndef DECLARATIVECHART_H
22 22 #define DECLARATIVECHART_H
23 23
24 24 #include <QtCore/QtGlobal>
25 25 #include <QDeclarativeItem>
26 26 #include <qchart.h>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 // TODO: Derive from QChart for easier definition of properties?
31 31 class DeclarativeChart : public QDeclarativeItem
32 32 // TODO: for QTQUICK2: extend QQuickPainterItem instead
33 33 //class DeclarativeChart : public QQuickPaintedItem, public Chart
34 34 {
35 35 Q_OBJECT
36 36 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
37 Q_PROPERTY(QString title READ title WRITE setTitle)
37 38
38 39 public:
39 40 DeclarativeChart(QDeclarativeItem *parent = 0);
40 41 ~DeclarativeChart();
41 42
42 43 public: // From QDeclarativeItem/QGraphicsItem
43 44 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
44 45 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
45 46
46 47 public:
47 48 void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);}
48 49 QChart::ChartTheme theme();
50 void setTitle(QString title) {m_chart->setTitle(title);}
51 QString title() { return m_chart->title();}
49 52
50 53 public:
51 54 // Extending QChart with DeclarativeChart is not possible because QObject does not support
52 55 // multi inheritance, so we now have a QChart as a member instead
53 56 QChart *m_chart;
54 57 };
55 58
56 59 QTCOMMERCIALCHART_END_NAMESPACE
57 60
58 61 #endif // DECLARATIVECHART_H
@@ -1,74 +1,51
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 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 }
25 anchors.fill: parent
49 26
50 27 Chart {
51 id: chart1
28 title: "Car brand shares in Finland"
52 29 anchors.fill: parent
53 theme: Chart.ChartThemeDark
54
55 BarSeries {
56 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
57 // TBD: data
58 }
30 theme: Chart.ChartThemeLight
59 31
60 32 PieSeries {
61 33 horizontalPosition: 0.2
62 34 verticalPosition: 0.3
63 35 size: 0.4
64 endAngle: 0.52 * 360 // The share of "others" is 52%
65 36 slices: [
66 37 PieSlice { label: "Volkswagen"; value: 13.5 },
67 38 PieSlice { label: "Toyota"; value: 10.9 },
68 39 PieSlice { label: "Ford"; value: 8.6 },
69 40 PieSlice { label: "Skoda"; value: 8.2 },
70 PieSlice { label: "Volvo"; value: 6.8 }
41 PieSlice { label: "Volvo"; value: 6.8 },
42 PieSlice { label: "Others"; value: 52.0 }
71 43 ]
72 44 }
45
46 BarSeries {
47 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
48 // data implementation missing
49 }
73 50 }
74 51 }
@@ -1,51 +1,57
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 anchors.fill: parent
26 26
27 27 Chart {
28 title: "Line&Spline"
28 29 anchors.fill: parent
29 30 theme: Chart.ChartThemeBrownSand
30 31
31 32 LineSeries {
32 33 name: "Line"
33 34 points: [
34 35 XyPoint { x: 0.0; y: 0.0 },
35 36 XyPoint { x: 1.1; y: 2.1 },
37 XyPoint { x: 1.9; y: 3.3 },
36 38 XyPoint { x: 2.9; y: 4.9 },
37 XyPoint { x: 3.2; y: 3.0 }
39 XyPoint { x: 3.2; y: 3.0 },
40 XyPoint { x: 4.0; y: 3.3 }
38 41 ]
39 42 }
40 43
41 44 SplineSeries {
42 45 name: "Spline"
43 46 points: [
44 47 XyPoint { x: 0.0; y: 0.3 },
45 48 XyPoint { x: 1.1; y: 3.2 },
46 XyPoint { x: 2.17; y: 2.15 },
47 XyPoint { x: 4.17; y: 3.15 }
49 XyPoint { x: 1.7; y: 2.4 },
50 XyPoint { x: 2.1; y: 2.1 },
51 XyPoint { x: 2.9; y: 2.6 },
52 XyPoint { x: 3.4; y: 2.3 },
53 XyPoint { x: 4.1; y: 3.1 }
48 54 ]
49 55 }
50 56 }
51 57 }
@@ -1,70 +1,128
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 anchors.fill: parent
26 26
27 27 Chart {
28 title: "NHL All-Star Team Players"
28 29 anchors.fill: parent
29 30 theme: Chart.ChartThemeHighContrast
30 31
31 32 AreaSeries {
32 name: "Area"
33 name: "Finnish"
33 34 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 }
35 XyPoint { x: 0; y: 0 },
36 XyPoint { x: 1; y: 0 },
37 XyPoint { x: 2; y: 0 },
38 XyPoint { x: 3; y: 0 },
39 XyPoint { x: 4; y: 0 },
40 XyPoint { x: 5; y: 0 },
41 XyPoint { x: 6; y: 1 },
42 XyPoint { x: 7; y: 0 },
43 XyPoint { x: 8; y: 0 },
44 XyPoint { x: 9; y: 0 },
45 XyPoint { x: 10; y: 0 },
46 XyPoint { x: 11; y: 1 }
37 47 ]
38 48 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 }
49 XyPoint { x: 0; y: 0 },
50 XyPoint { x: 1; y: 0 },
51 XyPoint { x: 2; y: 0 },
52 XyPoint { x: 3; y: 0 },
53 XyPoint { x: 4; y: 0 },
54 XyPoint { x: 5; y: 0 },
55 XyPoint { x: 6; y: 0 },
56 XyPoint { x: 7; y: 0 },
57 XyPoint { x: 8; y: 0 },
58 XyPoint { x: 9; y: 0 },
59 XyPoint { x: 10; y: 0 },
60 XyPoint { x: 11; y: 0 }
42 61 ]
43 62 }
44 63
45 ScatterSeries {
46 name: "Scatter1"
64 AreaSeries {
65 name: "Russian"
47 66 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 }
67 XyPoint { x: 0; y: 1 },
68 XyPoint { x: 1; y: 1 },
69 XyPoint { x: 2; y: 1 },
70 XyPoint { x: 3; y: 1 },
71 XyPoint { x: 4; y: 1 },
72 XyPoint { x: 5; y: 0 },
73 XyPoint { x: 6; y: 1 },
74 XyPoint { x: 7; y: 1 },
75 XyPoint { x: 8; y: 4 },
76 XyPoint { x: 9; y: 3 },
77 XyPoint { x: 10; y: 2 },
78 XyPoint { x: 11; y: 1 }
51 79 ]
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 }
80 lowerPoints: [
81 XyPoint { x: 0; y: 0 },
82 XyPoint { x: 1; y: 0 },
83 XyPoint { x: 2; y: 0 },
84 XyPoint { x: 3; y: 0 },
85 XyPoint { x: 4; y: 0 },
86 XyPoint { x: 5; y: 0 },
87 XyPoint { x: 6; y: 0 },
88 XyPoint { x: 7; y: 0 },
89 XyPoint { x: 8; y: 0 },
90 XyPoint { x: 9; y: 0 },
91 XyPoint { x: 10; y: 0 },
92 XyPoint { x: 11; y: 0 }
59 93 ]
60 94 }
61 ScatterSeries {
62 name: "Scatter3"
95
96 AreaSeries {
97 name: "Swedish"
63 98 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 }
99 XyPoint { x: 0; y: 1 },
100 XyPoint { x: 1; y: 1 },
101 XyPoint { x: 2; y: 3 },
102 XyPoint { x: 3; y: 3 },
103 XyPoint { x: 4; y: 2 },
104 XyPoint { x: 5; y: 0 },
105 XyPoint { x: 6; y: 2 },
106 XyPoint { x: 7; y: 1 },
107 XyPoint { x: 8; y: 2 },
108 XyPoint { x: 9; y: 1 },
109 XyPoint { x: 10; y: 3 },
110 XyPoint { x: 11; y: 3 }
111 ]
112 lowerPoints: [
113 XyPoint { x: 0; y: 0 },
114 XyPoint { x: 1; y: 0 },
115 XyPoint { x: 2; y: 0 },
116 XyPoint { x: 3; y: 0 },
117 XyPoint { x: 4; y: 0 },
118 XyPoint { x: 5; y: 0 },
119 XyPoint { x: 6; y: 0 },
120 XyPoint { x: 7; y: 0 },
121 XyPoint { x: 8; y: 0 },
122 XyPoint { x: 9; y: 0 },
123 XyPoint { x: 10; y: 0 },
124 XyPoint { x: 11; y: 0 }
67 125 ]
68 126 }
69 127 }
70 128 }
@@ -1,54 +1,53
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 27 property int __viewNumber: 0
28 28
29 29 Timer {
30 30 id: timer
31 31 running: true
32 32 repeat: true
33 33 interval: 5000
34 triggeredOnStart: true
34 triggeredOnStart: false
35 35 onTriggered: {
36 loader.source = "View" + (__viewNumber % 3 + 1) + ".qml";
37 36 __viewNumber++;
38 37 }
39 38 }
40 39
41 40 Loader {
42 41 id: loader
43 42 anchors.fill: parent
43 source: "View" + (__viewNumber % 4 + 1) + ".qml";
44 44 }
45 45
46 46 MouseArea {
47 47 anchors.fill: parent
48 48 onClicked: {
49 49 timer.restart();
50 loader.source = "View" + (__viewNumber % 3 + 1) + ".qml";
51 50 __viewNumber++;
52 51 }
53 52 }
54 53 }
@@ -1,9 +1,10
1 1 <RCC>
2 2 <qresource prefix="/">
3 3 <file>qml/qmlchart/loader.qml</file>
4 4 <file>qml/qmlchart/main.qml</file>
5 5 <file>qml/qmlchart/View1.qml</file>
6 6 <file>qml/qmlchart/View2.qml</file>
7 7 <file>qml/qmlchart/View3.qml</file>
8 <file>qml/qmlchart/View4.qml</file>
8 9 </qresource>
9 10 </RCC>
General Comments 0
You need to be logged in to leave comments. Login now