##// END OF EJS Templates
App for demonstrating QML customization apis
Tero Ahola -
r1259:5664856ed1d4
parent child
Show More
@@ -0,0 +1,35
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 #include <QtGui/QApplication>
22 #include <QDeclarativeEngine>
23 #include "qmlapplicationviewer.h"
24
25 Q_DECL_EXPORT int main(int argc, char *argv[])
26 {
27 QScopedPointer<QApplication> app(createApplication(argc, argv));
28 QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
29
30 viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
31 viewer->setSource(QUrl("qrc:/qml/qmlcustomizations/loader.qml"));
32 viewer->showExpanded();
33
34 return app->exec();
35 }
@@ -0,0 +1,44
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 ChartView {
28 id: chart
29 title: "Top-5 car brand shares in Finland"
30 anchors.fill: parent
31 theme: ChartView.ChartThemeLight
32 legend: ChartView.LegendBottom
33 animationOptions: ChartView.SeriesAnimations
34
35 PieSeries {
36 id: pieSeries
37 PieSlice { label: "Volkswagen"; value: 13.5 }
38 PieSlice { label: "Toyota"; value: 10.9 }
39 PieSlice { label: "Ford"; value: 8.6 }
40 PieSlice { label: "Skoda"; value: 8.2 }
41 PieSlice { label: "Volvo"; value: 6.8 }
42 }
43 }
44 }
@@ -0,0 +1,37
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
23 Item {
24 id: container
25 width: 400
26 height: 300
27 Component.onCompleted: {
28 var co = Qt.createComponent("main.qml")
29 if (co.status == Component.Ready) {
30 var o = co.createObject(container)
31 } else {
32 console.log(co.errorString())
33 console.log("QtCommercial.Chart 1.1 not available")
34 console.log("Please use correct QML_IMPORT_PATH export")
35 }
36 }
37 }
@@ -0,0 +1,98
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 property int __activeIndex: 1
28 property real __intervalCoefficient: 0
29
30
31 ChartView {
32 id: chartView
33 anchors.fill: parent
34 title: "Wheel of fortune"
35 legend: ChartView.LegendDisabled
36
37 PieSeries {
38 id: wheelOfFortune
39 }
40
41 SplineSeries {
42 id: splineSeries
43 }
44
45 ScatterSeries {
46 id: scatterSeries
47 }
48 }
49
50
51 Component.onCompleted: {
52 __intervalCoefficient = Math.random() + 0.1;
53 console.log("__intervalCoefficient: " + __intervalCoefficient);
54
55 for (var i = 0; i < 20; i++)
56 wheelOfFortune.append("", 1);
57
58 var interval = 1;
59 for (var j = 0; interval < 800; j++) {
60 interval = __intervalCoefficient * j * j;
61 splineSeries.append(j, interval);
62 }
63 chartView.axisX.max = j;
64 chartView.axisY.max = 1000;
65 }
66
67 Timer {
68 triggeredOnStart: true
69 running: true
70 repeat: true
71 interval: 100
72 onTriggered: {
73 // console.log("interval: " + interval);
74 var index = __activeIndex % wheelOfFortune.count;
75 if (interval < 700) {
76 scatterSeries.clear();
77 wheelOfFortune.at(index).exploded = false;
78 __activeIndex++;
79 index = __activeIndex % wheelOfFortune.count;
80 wheelOfFortune.at(index).exploded = true;
81 interval = splineSeries.at(__activeIndex).y;
82 scatterSeries.append(__activeIndex, interval);
83 } else {
84 // Switch the colors of the slice and the border
85 wheelOfFortune.at(index).borderWidth = 2;
86 var borderColor = wheelOfFortune.at(index).borderColor;
87 wheelOfFortune.at(index).borderColor = wheelOfFortune.at(index).color;
88 wheelOfFortune.at(index).color = borderColor;
89 }
90 }
91 }
92
93 // Loader {
94 // id: loader
95 // anchors.fill: parent
96 // source: "View" + (__viewNumber % 5 + 1) + ".qml";
97 // }
98 }
@@ -0,0 +1,200
1 // checksum 0x78c version 0x60010
2 /*
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
6 handled here.
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
9 */
10
11 #include "qmlapplicationviewer.h"
12
13 #include <QtCore/QDir>
14 #include <QtCore/QFileInfo>
15 #include <QtDeclarative/QDeclarativeComponent>
16 #include <QtDeclarative/QDeclarativeEngine>
17 #include <QtDeclarative/QDeclarativeContext>
18 #include <QtGui/QApplication>
19
20 #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
21
22 #ifdef HARMATTAN_BOOSTER
23 #include <MDeclarativeCache>
24 #endif
25
26 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
27
28 #include <qt_private/qdeclarativedebughelper_p.h>
29
30 #if !defined(NO_JSDEBUGGER)
31 #include <jsdebuggeragent.h>
32 #endif
33 #if !defined(NO_QMLOBSERVER)
34 #include <qdeclarativeviewobserver.h>
35 #endif
36
37 // Enable debugging before any QDeclarativeEngine is created
38 struct QmlJsDebuggingEnabler
39 {
40 QmlJsDebuggingEnabler()
41 {
42 QDeclarativeDebugHelper::enableDebugging();
43 }
44 };
45
46 // Execute code in constructor before first QDeclarativeEngine is instantiated
47 static QmlJsDebuggingEnabler enableDebuggingHelper;
48
49 #endif // QMLJSDEBUGGER
50
51 class QmlApplicationViewerPrivate
52 {
53 QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
54
55 QString mainQmlFile;
56 QDeclarativeView *view;
57 friend class QmlApplicationViewer;
58 QString adjustPath(const QString &path);
59 };
60
61 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
62 {
63 #ifdef Q_OS_UNIX
64 #ifdef Q_OS_MAC
65 if (!QDir::isAbsolutePath(path))
66 return QCoreApplication::applicationDirPath()
67 + QLatin1String("/../Resources/") + path;
68 #else
69 QString pathInInstallDir;
70 const QString applicationDirPath = QCoreApplication::applicationDirPath();
71 pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
72
73 if (QFileInfo(pathInInstallDir).exists())
74 return pathInInstallDir;
75 #endif
76 #endif
77 return path;
78 }
79
80 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
81 : QDeclarativeView(parent)
82 , d(new QmlApplicationViewerPrivate(this))
83 {
84 connect(engine(), SIGNAL(quit()), SLOT(close()));
85 setResizeMode(QDeclarativeView::SizeRootObjectToView);
86 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
87 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
88 #if !defined(NO_JSDEBUGGER)
89 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
90 #endif
91 #if !defined(NO_QMLOBSERVER)
92 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
93 #endif
94 #endif
95 }
96
97 QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent)
98 : QDeclarativeView(parent)
99 , d(new QmlApplicationViewerPrivate(view))
100 {
101 connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
102 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
103 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
104 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
105 #if !defined(NO_JSDEBUGGER)
106 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
107 #endif
108 #if !defined(NO_QMLOBSERVER)
109 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
110 #endif
111 #endif
112 }
113
114 QmlApplicationViewer::~QmlApplicationViewer()
115 {
116 delete d;
117 }
118
119 QmlApplicationViewer *QmlApplicationViewer::create()
120 {
121 #ifdef HARMATTAN_BOOSTER
122 return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0);
123 #else
124 return new QmlApplicationViewer();
125 #endif
126 }
127
128 void QmlApplicationViewer::setMainQmlFile(const QString &file)
129 {
130 d->mainQmlFile = d->adjustPath(file);
131 d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
132 }
133
134 void QmlApplicationViewer::addImportPath(const QString &path)
135 {
136 d->view->engine()->addImportPath(d->adjustPath(path));
137 }
138
139 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
140 {
141 #if defined(Q_OS_SYMBIAN)
142 // If the version of Qt on the device is < 4.7.2, that attribute won't work
143 if (orientation != ScreenOrientationAuto) {
144 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
145 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
146 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
147 return;
148 }
149 }
150 #endif // Q_OS_SYMBIAN
151
152 Qt::WidgetAttribute attribute;
153 switch (orientation) {
154 #if QT_VERSION < 0x040702
155 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
156 case ScreenOrientationLockPortrait:
157 attribute = static_cast<Qt::WidgetAttribute>(128);
158 break;
159 case ScreenOrientationLockLandscape:
160 attribute = static_cast<Qt::WidgetAttribute>(129);
161 break;
162 default:
163 case ScreenOrientationAuto:
164 attribute = static_cast<Qt::WidgetAttribute>(130);
165 break;
166 #else // QT_VERSION < 0x040702
167 case ScreenOrientationLockPortrait:
168 attribute = Qt::WA_LockPortraitOrientation;
169 break;
170 case ScreenOrientationLockLandscape:
171 attribute = Qt::WA_LockLandscapeOrientation;
172 break;
173 default:
174 case ScreenOrientationAuto:
175 attribute = Qt::WA_AutoOrientation;
176 break;
177 #endif // QT_VERSION < 0x040702
178 };
179 setAttribute(attribute, true);
180 }
181
182 void QmlApplicationViewer::showExpanded()
183 {
184 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
185 d->view->showFullScreen();
186 #elif defined(Q_WS_MAEMO_5)
187 d->view->showMaximized();
188 #else
189 d->view->show();
190 #endif
191 }
192
193 QApplication *createApplication(int &argc, char **argv)
194 {
195 #ifdef HARMATTAN_BOOSTER
196 return MDeclarativeCache::qApplication(argc, argv);
197 #else
198 return new QApplication(argc, argv);
199 #endif
200 }
@@ -0,0 +1,47
1 // checksum 0x82ed version 0x60010
2 /*
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
6 handled here.
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
9 */
10
11 #ifndef QMLAPPLICATIONVIEWER_H
12 #define QMLAPPLICATIONVIEWER_H
13
14 #include <QtDeclarative/QDeclarativeView>
15
16 class QmlApplicationViewer : public QDeclarativeView
17 {
18 Q_OBJECT
19
20 public:
21 enum ScreenOrientation {
22 ScreenOrientationLockPortrait,
23 ScreenOrientationLockLandscape,
24 ScreenOrientationAuto
25 };
26
27 explicit QmlApplicationViewer(QWidget *parent = 0);
28 virtual ~QmlApplicationViewer();
29
30 static QmlApplicationViewer *create();
31
32 void setMainQmlFile(const QString &file);
33 void addImportPath(const QString &path);
34
35 // Note that this will only have an effect on Symbian and Fremantle.
36 void setOrientation(ScreenOrientation orientation);
37
38 void showExpanded();
39
40 private:
41 explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent);
42 class QmlApplicationViewerPrivate *d;
43 };
44
45 QApplication *createApplication(int &argc, char **argv);
46
47 #endif // QMLAPPLICATIONVIEWER_H
@@ -0,0 +1,13
1 QT += declarative
2
3 SOURCES += $$PWD/qmlapplicationviewer.cpp
4 HEADERS += $$PWD/qmlapplicationviewer.h
5 INCLUDEPATH += $$PWD
6
7 # Include JS debugger library if QMLJSDEBUGGER_PATH is set
8 !isEmpty(QMLJSDEBUGGER_PATH) {
9 include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri)
10 } else {
11 DEFINES -= QMLJSDEBUGGER
12 }
13
@@ -0,0 +1,10
1 !include( ../demos.pri ) {
2 error( "Couldn't find the demos.pri file!" )
3 }
4
5 RESOURCES += resources.qrc
6 SOURCES += main.cpp
7
8 include(qmlapplicationviewer/qmlapplicationviewer.pri)
9
10 !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_DEMOS_BIN_DIR"
@@ -0,0 +1,7
1 <RCC>
2 <qresource prefix="/">
3 <file>qml/qmlcustomizations/loader.qml</file>
4 <file>qml/qmlcustomizations/main.qml</file>
5 <file>qml/qmlcustomizations/View1.qml</file>
6 </qresource>
7 </RCC>
@@ -1,13 +1,14
1 1 CURRENTLY_BUILDING_COMPONENTS = "demos"
2 2 !include( ../config.pri ) {
3 3 error( "Couldn't find the config.pri file!" )
4 4 }
5 5
6 6 TEMPLATE = subdirs
7 7 SUBDIRS += chartthemes \
8 8 piechartcustomization \
9 9 dynamicspline \
10 10 qmlchart \
11 11 qmlweather \
12 12 qmlf1legends \
13 qmlcustomizations \
13 14 qmlcustommodel
@@ -1,157 +1,119
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 <QBarSet>
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
28 28 QBarSet("", parent)
29 29 {
30 30 }
31 31
32 32 QVariantList DeclarativeBarSet::values()
33 33 {
34 34 QVariantList values;
35 35 for (int i(0); i < count(); i++)
36 36 values.append(QVariant(at(i)));
37 37 return values;
38 38 }
39 39
40 40 void DeclarativeBarSet::setValues(QVariantList values)
41 41 {
42 42 while (count())
43 43 remove(count() - 1);
44 44
45 45 for (int i(0); i < values.count(); i++) {
46 46 if (values.at(i).canConvert(QVariant::Double))
47 47 append(values[i].toDouble());
48 48 }
49 49 }
50 50
51 51 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
52 52 QBarSeries(parent)
53 53 {
54 54 }
55 55
56 56 void DeclarativeBarSeries::classBegin()
57 57 {
58 58 }
59 59
60 60 void DeclarativeBarSeries::componentComplete()
61 61 {
62 62 foreach(QObject *child, children()) {
63 63 if (qobject_cast<QBarSet *>(child)) {
64 64 QBarSeries::append(qobject_cast<QBarSet *>(child));
65 65 }
66 66 }
67 67 }
68 68
69 69 QDeclarativeListProperty<DeclarativeBarSet> DeclarativeBarSeries::initialBarSets()
70 70 {
71 71 return QDeclarativeListProperty<DeclarativeBarSet>(this, 0, &DeclarativeBarSeries::appendInitialBarSets);
72 72 }
73 73
74 bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeTableModel *model)
75 {
76 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
77 bool value(false);
78 if (m) {
79 // setModel(m);
80 //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
81 // setModelMapping(0, 1, 1, Qt::Vertical);
82 } else {
83 qWarning("DeclarativeBarSeries: Illegal model");
84 }
85 return value;
86 }
87
88 DeclarativeTableModel *DeclarativeBarSeries::declarativeModel()
89 {
90 return 0;//qobject_cast<DeclarativeTableModel *>(model());
91 }
92
93 74 void DeclarativeBarSeries::setBarCategories(QStringList categories)
94 75 {
95 76 setCategories(categories);
96 77 }
97 78
98 79 QStringList DeclarativeBarSeries::barCategories()
99 80 {
100 81 return categories();
101 82 }
102 83
103 84 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
104 85 QGroupedBarSeries(parent)
105 86 {
106 87 }
107 88
108 89 void DeclarativeGroupedBarSeries::classBegin()
109 90 {
110 91 }
111 92
112 93 void DeclarativeGroupedBarSeries::componentComplete()
113 94 {
114 95 foreach(QObject *child, children()) {
115 96 if (qobject_cast<QBarSet *>(child)) {
116 97 QBarSeries::append(qobject_cast<QBarSet *>(child));
117 98 }
118 99 }
119 100 }
120 101
121 102 QDeclarativeListProperty<DeclarativeBarSet> DeclarativeGroupedBarSeries::initialBarSets()
122 103 {
123 104 return QDeclarativeListProperty<DeclarativeBarSet>(this, 0, &DeclarativeGroupedBarSeries::appendInitialBarSets);
124 105 }
125 106
126 bool DeclarativeGroupedBarSeries::setDeclarativeModel(DeclarativeTableModel *model)
127 {
128 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
129 bool value(false);
130 if (m) {
131 // setModel(m);
132 //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
133 // setModelMapping(0, 1, 1, Qt::Vertical);
134 } else {
135 qWarning("DeclarativeGroupedBarSeries: Illegal model");
136 }
137 return value;
138 }
139
140 DeclarativeTableModel *DeclarativeGroupedBarSeries::declarativeModel()
141 {
142 return 0; //qobject_cast<DeclarativeTableModel *>(model());
143 }
144
145 107 void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories)
146 108 {
147 109 setCategories(categories);
148 110 }
149 111
150 112 QStringList DeclarativeGroupedBarSeries::barCategories()
151 113 {
152 114 return categories();
153 115 }
154 116
155 117 #include "moc_declarativebarseries.cpp"
156 118
157 119 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,107 +1,99
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 DECLARATIVEBARSERIES_H
22 22 #define DECLARATIVEBARSERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "declarativemodel.h"
26 26 #include <QDeclarativeItem>
27 27 #include <QDeclarativeParserStatus>
28 28 #include <QGroupedBarSeries>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 class QChart;
33 33
34 34 class DeclarativeBarSet : public QBarSet
35 35 {
36 36 Q_OBJECT
37 37 Q_PROPERTY(QVariantList values READ values WRITE setValues)
38 38 Q_PROPERTY(QString name READ name WRITE setName)
39 39
40 40 public:
41 41 explicit DeclarativeBarSet(QObject *parent = 0);
42 42 QVariantList values();
43 43 void setValues(QVariantList values);
44 44
45 45 public: // From QBarSet
46 46 Q_INVOKABLE void append(qreal value) { QBarSet::append(value); }
47 47 Q_INVOKABLE void append(qreal x, qreal y) { QBarSet::append(QPointF(x, y)); }
48 48 };
49 49
50 50 class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus
51 51 {
52 52 Q_OBJECT
53 53 Q_INTERFACES(QDeclarativeParserStatus)
54 Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel)
55 54 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
56 55 Q_PROPERTY(QDeclarativeListProperty<DeclarativeBarSet> initialBarSets READ initialBarSets)
57 56 Q_CLASSINFO("DefaultProperty", "initialBarSets")
58 57
59 58 public:
60 59 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
61 60 QDeclarativeListProperty<DeclarativeBarSet> initialBarSets();
62 61
63 62 void setBarCategories(QStringList categories);
64 63 QStringList barCategories();
65 64
66 65 public: // from QDeclarativeParserStatus
67 66 void classBegin();
68 67 void componentComplete();
69 68
70 public:
71 bool setDeclarativeModel(DeclarativeTableModel *model);
72 DeclarativeTableModel *declarativeModel();
73
74 69 public Q_SLOTS:
75 70 static void appendInitialBarSets(QDeclarativeListProperty<DeclarativeBarSet> * /*list*/, DeclarativeBarSet * /*element*/) {}
76 71 };
77 72
78 73 class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus
79 74 {
80 75 Q_OBJECT
81 76 Q_INTERFACES(QDeclarativeParserStatus)
82 Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel)
83 77 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
84 78 Q_PROPERTY(QDeclarativeListProperty<DeclarativeBarSet> initialBarSets READ initialBarSets)
85 79 Q_CLASSINFO("DefaultProperty", "initialBarSets")
86 80
87 81 public:
88 82 explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0);
89 83 QDeclarativeListProperty<DeclarativeBarSet> initialBarSets();
90 84
91 85 public: // from QDeclarativeParserStatus
92 86 void classBegin();
93 87 void componentComplete();
94 88
95 89 public:
96 90 void setBarCategories(QStringList categories);
97 91 QStringList barCategories();
98 bool setDeclarativeModel(DeclarativeTableModel *model);
99 DeclarativeTableModel *declarativeModel();
100 92
101 93 public Q_SLOTS:
102 94 static void appendInitialBarSets(QDeclarativeListProperty<DeclarativeBarSet> * /*list*/, DeclarativeBarSet * /*element*/) {}
103 95 };
104 96
105 97 QTCOMMERCIALCHART_END_NAMESPACE
106 98
107 99 #endif // DECLARATIVEBARSERIES_H
@@ -1,249 +1,250
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 "declarativechart.h"
22 22 #include <QPainter>
23 23 #include "declarativelineseries.h"
24 24 #include "declarativeareaseries.h"
25 25 #include "declarativebarseries.h"
26 26 #include "declarativepieseries.h"
27 27 #include "declarativesplineseries.h"
28 28 #include "declarativescatterseries.h"
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
33 33 : QDeclarativeItem(parent),
34 34 m_chart(new QChart(this)),
35 35 m_legend(LegendTop)
36 36 {
37 37 setFlag(QGraphicsItem::ItemHasNoContents, false);
38 38 m_chart->axisX()->setNiceNumbersEnabled(false);
39 39 }
40 40
41 41 DeclarativeChart::~DeclarativeChart()
42 42 {
43 43 delete m_chart;
44 44 }
45 45
46 46 void DeclarativeChart::childEvent(QChildEvent *event)
47 47 {
48 48 if (event->type() == QEvent::ChildAdded) {
49 49 if (qobject_cast<QAbstractSeries *>(event->child())) {
50 50 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
51 51 }
52 52 }
53 53 }
54 54
55 55 void DeclarativeChart::componentComplete()
56 56 {
57 57 // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max();
58 58 foreach(QObject *child, children()) {
59 59 if (qobject_cast<QAbstractSeries *>(child)) {
60 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
60 61 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
61 62 }
62 63 }
63 64 // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max();
64 65
65 66 QDeclarativeItem::componentComplete();
66 67 }
67 68
68 69 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
69 70 {
70 71 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
71 72 Q_UNUSED(oldGeometry)
72 73
73 74 if (newGeometry.isValid()) {
74 75 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
75 76 m_chart->resize(newGeometry.width(), newGeometry.height());
76 77 }
77 78 }
78 79 }
79 80
80 81 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
81 82 {
82 83 Q_UNUSED(option)
83 84 Q_UNUSED(widget)
84 85
85 86 // TODO: optimized?
86 87 painter->setRenderHint(QPainter::Antialiasing, true);
87 88 }
88 89
89 90 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
90 91 {
91 92 m_chart->setTheme((QChart::ChartTheme) theme);
92 93 }
93 94
94 95 DeclarativeChart::Theme DeclarativeChart::theme()
95 96 {
96 97 return (DeclarativeChart::Theme) m_chart->theme();
97 98 }
98 99
99 100 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
100 101 {
101 102 m_chart->setAnimationOptions((QChart::AnimationOption) animations);
102 103 }
103 104
104 105 DeclarativeChart::Animation DeclarativeChart::animationOptions()
105 106 {
106 107 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
107 108 return DeclarativeChart::AllAnimations;
108 109 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
109 110 return DeclarativeChart::GridAxisAnimations;
110 111 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
111 112 return DeclarativeChart::SeriesAnimations;
112 113 else
113 114 return DeclarativeChart::NoAnimation;
114 115 }
115 116
116 117 void DeclarativeChart::setLegend(DeclarativeChart::Legend legend)
117 118 {
118 119 if (legend != m_legend) {
119 120 m_legend = legend;
120 121 switch (m_legend) {
121 122 case LegendDisabled:
122 123 m_chart->legend()->setVisible(false);
123 124 break;
124 125 case LegendTop:
125 126 m_chart->legend()->setVisible(true);
126 127 m_chart->legend()->setAlignment(QLegend::AlignmentTop);
127 128 break;
128 129 case LegendBottom:
129 130 m_chart->legend()->setVisible(true);
130 131 m_chart->legend()->setAlignment(QLegend::AlignmentBottom);
131 132 break;
132 133 case LegendLeft:
133 134 m_chart->legend()->setVisible(true);
134 135 m_chart->legend()->setAlignment(QLegend::AlignmentLeft);
135 136 break;
136 137 case LegendRight:
137 138 m_chart->legend()->setVisible(true);
138 139 m_chart->legend()->setAlignment(QLegend::AlignmentRight);
139 140 break;
140 141 default:
141 142 m_chart->legend()->setVisible(false);
142 143 break;
143 144 }
144 145 }
145 146 }
146 147
147 148 DeclarativeChart::Legend DeclarativeChart::legend()
148 149 {
149 150 return m_legend;
150 151 }
151 152
152 153 QAxis *DeclarativeChart::axisX()
153 154 {
154 155 return m_chart->axisX();
155 156 }
156 157
157 158 QAxis *DeclarativeChart::axisY()
158 159 {
159 160 return m_chart->axisY();
160 161 }
161 162
162 163 QVariantList DeclarativeChart::axisXLabels()
163 164 {
164 165 QVariantList labels;
165 166 foreach (qreal value, m_chart->axisX()->categories()->values()) {
166 167 labels.append(value);
167 168 labels.append(m_chart->axisX()->categories()->label(value));
168 169 }
169 170 return labels;
170 171 }
171 172
172 173 void DeclarativeChart::setAxisXLabels(QVariantList list)
173 174 {
174 175 QVariant value(QVariant::Invalid);
175 176 foreach (QVariant element, list) {
176 177 if (value.isValid() && element.type() == QVariant::String) {
177 178 m_chart->axisX()->categories()->insert(value.toDouble(), element.toString());
178 179 value = QVariant(QVariant::Invalid);
179 180 } else {
180 181 if (element.canConvert(QVariant::Double))
181 182 value = element;
182 183 }
183 184 }
184 185 }
185 186
186 187 int DeclarativeChart::count()
187 188 {
188 189 return m_chart->series().count();
189 190 }
190 191
191 192 QAbstractSeries *DeclarativeChart::series(int index)
192 193 {
193 194 if (index < m_chart->series().count()) {
194 195 return m_chart->series().at(index);
195 196 }
196 197 return 0;
197 198 }
198 199
199 200 QAbstractSeries *DeclarativeChart::series(QString seriesName)
200 201 {
201 202 foreach(QAbstractSeries *series, m_chart->series()) {
202 203 if (series->name() == seriesName)
203 204 return series;
204 205 }
205 206 return 0;
206 207 }
207 208
208 209 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
209 210 {
210 211 QAbstractSeries *series = 0;
211 212 switch (type) {
212 213 case DeclarativeChart::SeriesTypeLine:
213 214 series = new DeclarativeLineSeries();
214 215 break;
215 216 case DeclarativeChart::SeriesTypeArea:
216 217 series = new DeclarativeAreaSeries();
217 218 break;
218 219 case DeclarativeChart::SeriesTypeBar:
219 220 series = new DeclarativeBarSeries();
220 221 break;
221 222 case DeclarativeChart::SeriesTypeStackedBar:
222 223 // TODO
223 224 break;
224 225 case DeclarativeChart::SeriesTypePercentBar:
225 226 // TODO
226 227 break;
227 228 case DeclarativeChart::SeriesTypeGroupedBar:
228 229 series = new DeclarativeGroupedBarSeries();
229 230 break;
230 231 case DeclarativeChart::SeriesTypePie:
231 232 series = new DeclarativePieSeries();
232 233 break;
233 234 case DeclarativeChart::SeriesTypeScatter:
234 235 series = new DeclarativeScatterSeries();
235 236 break;
236 237 case DeclarativeChart::SeriesTypeSpline:
237 238 series = new DeclarativeSplineSeries();
238 239 break;
239 240 default:
240 241 qWarning() << "Illegal series type";
241 242 }
242 243 series->setName(name);
243 244 m_chart->addSeries(series);
244 245 return series;
245 246 }
246 247
247 248 #include "moc_declarativechart.cpp"
248 249
249 250 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,55 +1,55
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 DECLARATIVELINESERIES_H
22 22 #define DECLARATIVELINESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qlineseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28 #include <QDebug>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
33 33 {
34 34 Q_OBJECT
35 Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel)
36 35 Q_PROPERTY(QColor color READ color WRITE setColor)
37 36 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
38 37 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
39 38
40 39 public:
41 40 explicit DeclarativeLineSeries(QObject *parent = 0);
42 41 QDeclarativeListProperty<QObject> declarativeChildren();
43 42
44 43 public: // from QLineSeries
45 44 Q_INVOKABLE void append(qreal x, qreal y) { QLineSeries::append(x, y); }
46 45 Q_INVOKABLE void remove(qreal x, qreal y) { QLineSeries::remove(x, y); }
47 46 Q_INVOKABLE void clear() { QLineSeries::removeAll(); }
47 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
48 48
49 49 public Q_SLOTS:
50 50 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
51 51 };
52 52
53 53 QTCOMMERCIALCHART_END_NAMESPACE
54 54
55 55 #endif // DECLARATIVELINESERIES_H
@@ -1,107 +1,137
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 "declarativepieseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include <qdeclarativelist.h>
25 25 #include <QVPieModelMapper>
26 26 #include <QHPieModelMapper>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 DeclarativePieSlice::DeclarativePieSlice(QObject *parent) :
31 QPieSlice(parent)
32 {
33 }
34
35 QColor DeclarativePieSlice::color()
36 {
37 return brush().color();
38 }
39
40 void DeclarativePieSlice::setColor(QColor color)
41 {
42 QBrush b = brush();
43 b.setColor(color);
44 setBrush(b);
45 }
46
47 QColor DeclarativePieSlice::borderColor()
48 {
49 return pen().color();
50 }
51
52 void DeclarativePieSlice::setBorderColor(QColor color)
53 {
54 QPen p = pen();
55 p.setColor(color);
56 setPen(p);
57 }
58
59 int DeclarativePieSlice::borderWidth()
60 {
61 return pen().width();
62 }
63
64 void DeclarativePieSlice::setBorderWidth(int width)
65 {
66 QPen p = pen();
67 p.setWidth(width);
68 setPen(p);
69 }
70
30 71 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
31 72 QPieSeries(parent)
32 73 {
33 74 }
34 75
35 76 void DeclarativePieSeries::classBegin()
36 77 {
37 78 }
38 79
39 80 void DeclarativePieSeries::componentComplete()
40 81 {
41 82 foreach(QObject *child, children()) {
42 if (qobject_cast<QPieSlice *>(child)) {
43 QPieSeries::append(qobject_cast<QPieSlice *>(child));
83 if (qobject_cast<DeclarativePieSlice *>(child)) {
84 QPieSeries::append(qobject_cast<DeclarativePieSlice *>(child));
44 85 } else if(qobject_cast<QVPieModelMapper *>(child)) {
45 86 QVPieModelMapper *mapper = qobject_cast<QVPieModelMapper *>(child);
46 87 mapper->setSeries(this);
47 88 } else if(qobject_cast<QHPieModelMapper *>(child)) {
48 89 QHPieModelMapper *mapper = qobject_cast<QHPieModelMapper *>(child);
49 90 mapper->setSeries(this);
50 91 }
51 92 }
52 93 }
53 94
54 95 QDeclarativeListProperty<QObject> DeclarativePieSeries::seriesChildren()
55 96 {
56 97 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativePieSeries::appendSeriesChildren);
57 98 }
58 99
59 100 void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
60 101 {
61 102 // Empty implementation; the children are parsed in componentComplete instead
62 103 Q_UNUSED(list);
63 104 Q_UNUSED(element);
64 105 }
65 106
66 QPieSlice *DeclarativePieSeries::at(int index)
107 DeclarativePieSlice *DeclarativePieSeries::at(int index)
67 108 {
68 109 QList<QPieSlice*> sliceList = slices();
69 110 if (index < sliceList.count())
70 return sliceList[index];
111 return qobject_cast<DeclarativePieSlice *>(sliceList[index]);
71 112
72 113 return 0;
73 114 }
74 115
75 QPieSlice* DeclarativePieSeries::find(QString label)
116 DeclarativePieSlice* DeclarativePieSeries::find(QString label)
76 117 {
77 118 foreach (QPieSlice *slice, slices()) {
78 119 if (slice->label() == label)
79 return slice;
120 return qobject_cast<DeclarativePieSlice *>(slice);
80 121 }
81 122 return 0;
82 123 }
83 124
84 QPieSlice* DeclarativePieSeries::append(QString name, qreal value)
125 DeclarativePieSlice* DeclarativePieSeries::append(QString label, qreal value)
85 126 {
86 127 // TODO: parameter order is wrong, switch it:
87 return QPieSeries::append(name, value);
88 }
89
90 void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model)
91 {
92 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
93 if (m) {
94 // QPieSeries::setModel(m);
95 } else {
96 qWarning("DeclarativePieSeries: Illegal model");
97 }
98 }
99
100 DeclarativeTableModel *DeclarativePieSeries::pieModel()
101 {
102 return 0;//qobject_cast<DeclarativeTableModel *>(model());
128 DeclarativePieSlice *slice = new DeclarativePieSlice(this);
129 slice->setLabel(label);
130 slice->setValue(value);
131 QPieSeries::append(slice);
132 return slice;
103 133 }
104 134
105 135 #include "moc_declarativepieseries.cpp"
106 136
107 137 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,63 +1,77
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 DECLARATIVEPIESERIES_H
22 22 #define DECLARATIVEPIESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include <QPieSlice>
26 26 #include <QPieSeries>
27 27 #include <QDeclarativeParserStatus>
28 28 #include <QDeclarativeListProperty>
29 29 #include <QAbstractItemModel>
30 30 #include "declarativemodel.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 class QChart;
35 35
36 class DeclarativePieSlice: public QPieSlice
37 {
38 Q_OBJECT
39 Q_PROPERTY(QColor color READ color WRITE setColor)
40 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)
41 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth)
42
43 public:
44 explicit DeclarativePieSlice(QObject *parent = 0);
45 QColor color();
46 void setColor(QColor color);
47 QColor borderColor();
48 void setBorderColor(QColor color);
49 int borderWidth();
50 void setBorderWidth(int width);
51 };
52
36 53 class DeclarativePieSeries : public QPieSeries, public QDeclarativeParserStatus
37 54 {
38 55 Q_OBJECT
39 56 Q_INTERFACES(QDeclarativeParserStatus)
40 Q_PROPERTY(DeclarativeTableModel *model READ pieModel WRITE setPieModel)
41 57 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
42 58 Q_CLASSINFO("DefaultProperty", "seriesChildren")
43 59
44 60 public:
45 61 explicit DeclarativePieSeries(QObject *parent = 0);
46 62 QDeclarativeListProperty<QObject> seriesChildren();
47 DeclarativeTableModel *pieModel();
48 void setPieModel(DeclarativeTableModel *model);
49 Q_INVOKABLE QPieSlice *at(int index);
50 Q_INVOKABLE QPieSlice* find(QString label);
51 Q_INVOKABLE QPieSlice* append(QString label, qreal value);
63 Q_INVOKABLE DeclarativePieSlice *at(int index);
64 Q_INVOKABLE DeclarativePieSlice* find(QString label);
65 Q_INVOKABLE DeclarativePieSlice* append(QString label, qreal value);
52 66
53 67 public:
54 68 void classBegin();
55 69 void componentComplete();
56 70
57 71 public Q_SLOTS:
58 72 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
59 73 };
60 74
61 75 QTCOMMERCIALCHART_END_NAMESPACE
62 76
63 77 #endif // DECLARATIVEPIESERIES_H
@@ -1,53 +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 #ifndef DECLARATIVESCATTERSERIES_H
22 22 #define DECLARATIVESCATTERSERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qscatterseries.h"
26 26 #include "declarativexyseries.h"
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
31 31 {
32 32 Q_OBJECT
33 Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel)
34 33 Q_PROPERTY(QColor color READ color WRITE setColor)
35 34 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
36 35 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
37 36
38 37 public:
39 38 explicit DeclarativeScatterSeries(QObject *parent = 0);
40 39 QDeclarativeListProperty<QObject> declarativeChildren();
41 40
42 41 public: // from QScatterSeries
43 42 Q_INVOKABLE void append(qreal x, qreal y) { QScatterSeries::append(x, y); }
44 43 Q_INVOKABLE void remove(qreal x, qreal y) { QScatterSeries::remove(x, y); }
45 44 Q_INVOKABLE void clear() { QScatterSeries::removeAll(); }
45 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
46 46
47 47 public Q_SLOTS:
48 48 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
49 49 };
50 50
51 51 QTCOMMERCIALCHART_END_NAMESPACE
52 52
53 53 #endif // DECLARATIVESCATTERSERIES_H
@@ -1,47 +1,48
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 "declarativesplineseries.h"
22 22 #include "declarativechart.h"
23 23 #include <QChart>
24 #include "declarativexypoint.h"
24 25
25 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 27
27 28 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
28 29 QSplineSeries(parent)
29 30 {
30 31 }
31 32
32 33 QDeclarativeListProperty<QObject> DeclarativeSplineSeries::declarativeChildren()
33 34 {
34 35 return QDeclarativeListProperty<QObject>(this, 0, &appendDeclarativeChildren);
35 36 }
36 37
37 38 void DeclarativeSplineSeries::appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element)
38 39 {
39 40 QXYSeries *series = qobject_cast<QXYSeries*>(list->object);
40 41 DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(element);
41 42 if (series && point)
42 43 series->append(*point);
43 44 }
44 45
45 46 #include "moc_declarativesplineseries.cpp"
46 47
47 48 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,54 +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 #ifndef DECLARATIVESPLINESERIES_H
22 22 #define DECLARATIVESPLINESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qsplineseries.h"
26 26 #include "declarativexyseries.h"
27 27 #include <QDeclarativeParserStatus>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
32 32 {
33 33 Q_OBJECT
34 Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel)
35 34 Q_PROPERTY(QColor color READ color WRITE setColor)
36 35 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
37 36 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
38 37
39 38 public:
40 39 explicit DeclarativeSplineSeries(QObject *parent = 0);
41 40 QDeclarativeListProperty<QObject> declarativeChildren();
42 41
43 42 public: // from QSplineSeries
44 43 Q_INVOKABLE void append(qreal x, qreal y) { QSplineSeries::append(x, y); }
45 44 Q_INVOKABLE void remove(qreal x, qreal y) { QSplineSeries::remove(x, y); }
46 45 Q_INVOKABLE void clear() { QSplineSeries::removeAll(); }
46 Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); }
47 47
48 48 public Q_SLOTS:
49 49 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
50 50 };
51 51
52 52 QTCOMMERCIALCHART_END_NAMESPACE
53 53
54 54 #endif // DECLARATIVESPLINESERIES_H
@@ -1,43 +1,44
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 DECLARATIVE_XY_POINT_H
22 22 #define DECLARATIVE_XY_POINT_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include <QObject>
26 26 #include <QPointF>
27 27 #include <QDataStream>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class DeclarativeXyPoint : public QObject, public QPointF
32 32 {
33 33 Q_OBJECT
34 // TODO: make the setters change the value, if parented by a series
34 35 Q_PROPERTY(qreal x READ x WRITE setX /*NOTIFY dataXChanged*/)
35 36 Q_PROPERTY(qreal y READ y WRITE setY /*NOTIFY dataYChanged*/)
36 37
37 38 public:
38 39 explicit DeclarativeXyPoint(QObject *parent = 0);
39 40 };
40 41
41 42 QTCOMMERCIALCHART_END_NAMESPACE
42 43
43 44 #endif // DECLARATIVE_XY_POINT_H
@@ -1,87 +1,67
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 "DeclarativeXySeries.h"
22 22 #include "declarativexyseries.h"
23 23 #include "declarativechart.h"
24 24 #include <QXYSeries>
25 25 #include <QXYModelMapper>
26 26 #include <QDeclarativeListProperty>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 DeclarativeXySeries::DeclarativeXySeries()
31 31 {
32 // TODO: XYModelMapper implementation has changed, this code has to be updated
33
34 // All the inherited objects must be of type QXYSeries, so it is safe to cast
35 // QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
36 // // TODO: mapper should be available on the series by default
37 // QXYModelMapper *mapper = new QXYModelMapper(series);
38 // mapper->setMapX(0);
39 // mapper->setMapY(1);
40 // mapper->setFirst(0);
41 // mapper->setCount(-1);
42 // mapper->setOrientation(Qt::Vertical);
43 // series->setModelMapper(mapper);
44 32 }
45 33
46 34 DeclarativeXySeries::~DeclarativeXySeries()
47 35 {
48 36 }
49 37
50 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeTableModel *model)
51 {
52 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
53 bool value(false);
54 if (m) {
55 // All the inherited objects must be of type QXYSeries, so it is safe to cast
56 // QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
57 // series->setModel(m);
58 } else {
59 qWarning("DeclarativeXySeries: Illegal model");
60 }
61 return value;
62 }
63
64 DeclarativeTableModel *DeclarativeXySeries::declarativeModel()
65 {
66 // All the inherited objects must be of type QXYSeries, so it is safe to cast
67 // QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
68 return 0; //qobject_cast<DeclarativeTableModel *>(series->model());
69 }
70
71 38 QColor DeclarativeXySeries::color()
72 39 {
73 40 // All the inherited objects must be of type QXYSeries, so it is safe to cast
74 41 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
75 42 return series->pen().color();
76 43 }
77 44
78 45 void DeclarativeXySeries::setColor(QColor color)
79 46 {
80 47 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
81 48 QPen pen = series->pen();
82 49 pen.setColor(color);
83 50 series->setPen(pen);
84 51 }
85 52
53 DeclarativeXyPoint *DeclarativeXySeries::at(int index)
54 {
55 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
56 if (index < series->count()) {
57 QPointF point = series->points().at(index);
58 DeclarativeXyPoint *xyPoint = new DeclarativeXyPoint(series);
59 xyPoint->setX(point.x());
60 xyPoint->setY(point.y());
61 return xyPoint;
62 }
63 return 0;
64 }
65
86 66
87 67 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,48 +1,47
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 DECLARATIVE_XY_SERIES_H
22 22 #define DECLARATIVE_XY_SERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "declarativexypoint.h"
26 26 #include "declarativemodel.h"
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 class QChart;
31 31 class QAbstractSeries;
32 32
33 33 class DeclarativeXySeries
34 34 {
35 35 public:
36 36 explicit DeclarativeXySeries();
37 37 ~DeclarativeXySeries();
38 38
39 39 public:
40 bool setDeclarativeModel(DeclarativeTableModel *model);
41 DeclarativeTableModel *declarativeModel();
42 40 QColor color();
43 41 void setColor(QColor color);
42 DeclarativeXyPoint *at(int index);
44 43 };
45 44
46 45 QTCOMMERCIALCHART_END_NAMESPACE
47 46
48 47 #endif // DECLARATIVE_XY_SERIES_H
@@ -1,86 +1,86
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 <QtDeclarative/qdeclarativeextensionplugin.h>
22 22 #include <QtDeclarative/qdeclarative.h>
23 23 #include "qchart.h"
24 24 #include "qaxiscategories.h"
25 25 #include "declarativechart.h"
26 26 #include "declarativexypoint.h"
27 27 #include "declarativelineseries.h"
28 28 #include "declarativesplineseries.h"
29 29 #include "declarativeareaseries.h"
30 30 #include "declarativescatterseries.h"
31 31 #include "declarativebarseries.h"
32 32 #include "declarativepieseries.h"
33 33 #include "declarativemodel.h"
34 34 #include <QHPieModelMapper>
35 35 #include <QVPieModelMapper>
36 36 #include <QXYModelMapper>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
41 41 {
42 42 Q_OBJECT
43 43 public:
44 44 virtual void registerTypes(const char *uri)
45 45 {
46 46 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
47 47
48 48 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
49 49 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
50 50 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
51 51 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
52 52 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
53 53 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
54 54 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
55 55 qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries");
56 56 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
57 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
57 qmlRegisterType<DeclarativePieSlice>(uri, 1, 0, "PieSlice");
58 58 qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel");
59 59 qmlRegisterType<DeclarativeTableModelElement>(uri, 1, 0, "ChartModelElement");
60 60 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
61 61
62 62 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
63 63 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
64 64 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
65 65 QLatin1String("Trying to create uncreatable: PieModelMapper."));
66 66 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
67 67 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
68 68
69 69 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
70 70 QLatin1String("Trying to create uncreatable: AbstractSeries."));
71 71 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
72 72 QLatin1String("Trying to create uncreatable: Axis."));
73 73 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
74 74 QLatin1String("Trying to create uncreatable: PieModelMapper."));
75 75 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
76 76 QLatin1String("Trying to create uncreatable: XYModelMapper."));
77 77 }
78 78 };
79 79
80 80 #include "plugin.moc"
81 81
82 82 QTCOMMERCIALCHART_END_NAMESPACE
83 83
84 84 QTCOMMERCIALCHART_USE_NAMESPACE
85 85
86 86 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
General Comments 0
You need to be logged in to leave comments. Login now