##// END OF EJS Templates
Draft for QML demo that shows weather forecasts
Tero Ahola -
r1139:d61f2486cd3e
parent child
Show More
@@ -0,0 +1,136
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.1
22 import QtCommercial.Chart 1.0
23
24 Rectangle {
25 width: 360
26 height: 360
27
28 ChartView {
29 id: chartView
30 anchors.top: parent.top
31 anchors.bottom: weatherImageRow.top
32 anchors.left: parent.left
33 anchors.right: parent.right
34 axisX.min: 0
35 axisX.max: 6
36 axisY.min: 0
37 axisY.max: 50
38
39 // TODO: implement categories
40 // AxisCategory { axis: AxisCategory.AxisX; value: 0.0; label: "" }
41 // AxisCategory { axis: AxisCategory.AxisX; value: 1.0; label: "Today" }
42 // AxisCategory { axis: AxisCategory.AxisX; value: 2.0; label: "Tomorrow" }
43 // AxisCategory { axis: AxisCategory.AxisX; value: 3.0; label: "Day after tomorrow" }
44
45 LineSeries {
46 model: maxModel
47 }
48
49 LineSeries {
50 model: minModel
51 }
52
53 // TODO: use a single base model with mappings instead of two separate xy models
54 // LineSeries {
55 // model: chartModel
56 // modelMapping: XyModelMapping {
57 // xColumn: 0
58 // yColumn: 1
59 // }
60 // }
61 // LineSeries {
62 // model: chartModel
63 // modelMapping: XyModelMapping {
64 // xColumn: 0
65 // yColumn: 2
66 // }
67 // }
68 }
69
70 // ChartModel {
71 // id: chartModel
72 // }
73
74 XYModel {
75 id: maxModel
76 }
77
78 XYModel {
79 id: minModel
80 }
81
82 Component.onCompleted: {
83 // TODO: use live data instead of hard coded example data
84 // in case an application key was defined for this demo app
85 // var xhr = new XMLHttpRequest;
86 // var appKey = "";
87 // xhr.open("GET", "http://free.worldweatheronline.com/feed/weather.ashx?q=Jyv%c3%a4skyl%c3%a4,Finland&format=json&num_of_days=5&key=" + appKey");
88 // xhr.onreadystatechange = function() {
89 // if (xhr.readyState == XMLHttpRequest.DONE) {
90 // var a = JSON.parse(xhr.responseText);
91 // console.log("a: " + a);
92 // console.log("response: " + xhr.responseText);
93 // for (var b in a) {
94 // var o = a[b];
95 // console.log("o: " + o);
96 //// model.append({id: o.id, name: o.name, duration: o.duration});
97 // }
98 // }
99 // }
100 // xhr.send();
101
102 var responseText = "{ \"data\": { \"current_condition\": [ {\"cloudcover\": \"10\", \"humidity\": \"61\", \"observation_time\": \"06:26 AM\", \"precipMM\": \"0.0\", \"pressure\": \"1022\", \"temp_C\": \"6\", \"temp_F\": \"43\", \"visibility\": \"10\", \"weatherCode\": \"113\", \"weatherDesc\": [ {\"value\": \"Sunny\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png\" } ], \"winddir16Point\": \"SE\", \"winddirDegree\": \"140\", \"windspeedKmph\": \"7\", \"windspeedMiles\": \"4\" } ], \"request\": [ {\"query\": \"Jyvaskyla, Finland\", \"type\": \"City\" } ], \"weather\": [ {\"date\": \"2012-05-09\", \"precipMM\": \"0.4\", \"tempMaxC\": \"14\", \"tempMaxF\": \"57\", \"tempMinC\": \"7\", \"tempMinF\": \"45\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"S\", \"winddirDegree\": \"179\", \"winddirection\": \"S\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-10\", \"precipMM\": \"2.4\", \"tempMaxC\": \"13\", \"tempMaxF\": \"55\", \"tempMinC\": \"8\", \"tempMinF\": \"46\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SW\", \"winddirDegree\": \"219\", \"winddirection\": \"SW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" }, {\"date\": \"2012-05-11\", \"precipMM\": \"11.1\", \"tempMaxC\": \"15\", \"tempMaxF\": \"59\", \"tempMinC\": \"7\", \"tempMinF\": \"44\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SSW\", \"winddirDegree\": \"200\", \"winddirection\": \"SSW\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-12\", \"precipMM\": \"2.8\", \"tempMaxC\": \"7\", \"tempMaxF\": \"44\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"317\", \"weatherDesc\": [ {\"value\": \"Light sleet\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0021_cloudy_with_sleet.png\" } ], \"winddir16Point\": \"NW\", \"winddirDegree\": \"311\", \"winddirection\": \"NW\", \"windspeedKmph\": \"24\", \"windspeedMiles\": \"15\" }, {\"date\": \"2012-05-13\", \"precipMM\": \"0.4\", \"tempMaxC\": \"6\", \"tempMaxF\": \"42\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"WNW\", \"winddirDegree\": \"281\", \"winddirection\": \"WNW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" } ] }}";
103 var a = JSON.parse(responseText);
104
105 for (var i in a.data.weather) {
106 var weatherObj = a.data.weather[i];
107 maxModel.append([Number(i) + 1, weatherObj.tempMaxC]);
108 minModel.append([Number(i) + 1, weatherObj.tempMinC]);
109 weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value});
110 }
111 }
112
113 ListModel {
114 id: weatherImageModel
115 }
116
117 Row {
118 id: weatherImageRow
119 anchors.bottom: parent.bottom
120 anchors.bottomMargin: 10
121 anchors.left: parent.left
122 anchors.leftMargin: 25
123 anchors.right: parent.right
124 anchors.rightMargin: 25
125 Repeater {
126 id: repeater
127 model: weatherImageModel
128 delegate: Image {
129 source: imageSource
130 width: weatherImageRow.width / weatherImageModel.count
131 height: width
132 fillMode: Image.PreserveAspectCrop
133 }
134 }
135 }
136 }
@@ -0,0 +1,174
1 // checksum 0x3fbf version 0x70013
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 <QDir>
14 #include <QFileInfo>
15 #include <QApplication>
16 #include <QDeclarativeComponent>
17 #include <QDeclarativeEngine>
18 #include <QDeclarativeContext>
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 QString mainQmlFile;
54 friend class QmlApplicationViewer;
55 static QString adjustPath(const QString &path);
56 };
57
58 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
59 {
60 #ifdef Q_OS_UNIX
61 #ifdef Q_OS_MAC
62 if (!QDir::isAbsolutePath(path))
63 return QString::fromLatin1("%1/../Resources/%2")
64 .arg(QCoreApplication::applicationDirPath(), path);
65 #else
66 const QString pathInInstallDir =
67 QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
68 if (QFileInfo(pathInInstallDir).exists())
69 return pathInInstallDir;
70 #endif
71 #endif
72 return path;
73 }
74
75 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
76 : QDeclarativeView(parent)
77 , d(new QmlApplicationViewerPrivate())
78 {
79 connect(engine(), SIGNAL(quit()), SLOT(close()));
80 setResizeMode(QDeclarativeView::SizeRootObjectToView);
81 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
82 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
83 #if !defined(NO_JSDEBUGGER)
84 new QmlJSDebugger::JSDebuggerAgent(engine());
85 #endif
86 #if !defined(NO_QMLOBSERVER)
87 new QmlJSDebugger::QDeclarativeViewObserver(this, this);
88 #endif
89 #endif
90 }
91
92 QmlApplicationViewer::~QmlApplicationViewer()
93 {
94 delete d;
95 }
96
97 QmlApplicationViewer *QmlApplicationViewer::create()
98 {
99 return new QmlApplicationViewer();
100 }
101
102 void QmlApplicationViewer::setMainQmlFile(const QString &file)
103 {
104 d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
105 setSource(QUrl::fromLocalFile(d->mainQmlFile));
106 }
107
108 void QmlApplicationViewer::addImportPath(const QString &path)
109 {
110 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
111 }
112
113 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
114 {
115 #if defined(Q_OS_SYMBIAN)
116 // If the version of Qt on the device is < 4.7.2, that attribute won't work
117 if (orientation != ScreenOrientationAuto) {
118 const QStringList v = QString::fromLatin1(qVersion()).split(QLatin1Char('.'));
119 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
120 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
121 return;
122 }
123 }
124 #endif // Q_OS_SYMBIAN
125
126 Qt::WidgetAttribute attribute;
127 switch (orientation) {
128 #if QT_VERSION < 0x040702
129 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
130 case ScreenOrientationLockPortrait:
131 attribute = static_cast<Qt::WidgetAttribute>(128);
132 break;
133 case ScreenOrientationLockLandscape:
134 attribute = static_cast<Qt::WidgetAttribute>(129);
135 break;
136 default:
137 case ScreenOrientationAuto:
138 attribute = static_cast<Qt::WidgetAttribute>(130);
139 break;
140 #else // QT_VERSION < 0x040702
141 case ScreenOrientationLockPortrait:
142 attribute = Qt::WA_LockPortraitOrientation;
143 break;
144 case ScreenOrientationLockLandscape:
145 attribute = Qt::WA_LockLandscapeOrientation;
146 break;
147 default:
148 case ScreenOrientationAuto:
149 attribute = Qt::WA_AutoOrientation;
150 break;
151 #endif // QT_VERSION < 0x040702
152 };
153 setAttribute(attribute, true);
154 }
155
156 void QmlApplicationViewer::showExpanded()
157 {
158 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
159 showFullScreen();
160 #elif defined(Q_WS_MAEMO_5)
161 showMaximized();
162 #else
163 show();
164 #endif
165 }
166
167 QApplication *createApplication(int &argc, char **argv)
168 {
169 #ifdef HARMATTAN_BOOSTER
170 return MDeclarativeCache::qApplication(argc, argv);
171 #else
172 return new QApplication(argc, argv);
173 #endif
174 }
@@ -0,0 +1,46
1 // checksum 0x734b version 0x70013
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 <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 class QmlApplicationViewerPrivate *d;
42 };
43
44 QApplication *createApplication(int &argc, char **argv);
45
46 #endif // QMLAPPLICATIONVIEWER_H
@@ -0,0 +1,148
1 # checksum 0x5b42 version 0x70013
2 # This file was generated by the Qt Quick Application wizard of Qt Creator.
3 # The code below adds the QmlApplicationViewer to the project and handles the
4 # activation of QML debugging.
5 # It is recommended not to modify this file, since newer versions of Qt Creator
6 # may offer an updated version of it.
7
8 QT += declarative
9
10 SOURCES += $$PWD/qmlapplicationviewer.cpp
11 HEADERS += $$PWD/qmlapplicationviewer.h
12 INCLUDEPATH += $$PWD
13
14 # Include JS debugger library if QMLJSDEBUGGER_PATH is set
15 !isEmpty(QMLJSDEBUGGER_PATH) {
16 include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri)
17 } else {
18 DEFINES -= QMLJSDEBUGGER
19 }
20
21 contains(CONFIG,qdeclarative-boostable):contains(MEEGO_EDITION,harmattan) {
22 DEFINES += HARMATTAN_BOOSTER
23 }
24 # This file was generated by an application wizard of Qt Creator.
25 # The code below handles deployment to Symbian and Maemo, aswell as copying
26 # of the application data to shadow build directories on desktop.
27 # It is recommended not to modify this file, since newer versions of Qt Creator
28 # may offer an updated version of it.
29
30 defineTest(qtcAddDeployment) {
31 for(deploymentfolder, DEPLOYMENTFOLDERS) {
32 item = item$${deploymentfolder}
33 itemsources = $${item}.sources
34 $$itemsources = $$eval($${deploymentfolder}.source)
35 itempath = $${item}.path
36 $$itempath= $$eval($${deploymentfolder}.target)
37 export($$itemsources)
38 export($$itempath)
39 DEPLOYMENT += $$item
40 }
41
42 MAINPROFILEPWD = $$PWD
43
44 symbian {
45 isEmpty(ICON):exists($${TARGET}.svg):ICON = $${TARGET}.svg
46 isEmpty(TARGET.EPOCHEAPSIZE):TARGET.EPOCHEAPSIZE = 0x20000 0x2000000
47 } else:win32 {
48 copyCommand =
49 for(deploymentfolder, DEPLOYMENTFOLDERS) {
50 source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source)
51 source = $$replace(source, /, \\)
52 sourcePathSegments = $$split(source, \\)
53 target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments)
54 target = $$replace(target, /, \\)
55 target ~= s,\\\\\\.?\\\\,\\,
56 !isEqual(source,$$target) {
57 !isEmpty(copyCommand):copyCommand += &&
58 isEqual(QMAKE_DIR_SEP, \\) {
59 copyCommand += $(COPY_DIR) \"$$source\" \"$$target\"
60 } else {
61 source = $$replace(source, \\\\, /)
62 target = $$OUT_PWD/$$eval($${deploymentfolder}.target)
63 target = $$replace(target, \\\\, /)
64 copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\"
65 }
66 }
67 }
68 !isEmpty(copyCommand) {
69 copyCommand = @echo Copying application data... && $$copyCommand
70 copydeploymentfolders.commands = $$copyCommand
71 first.depends = $(first) copydeploymentfolders
72 export(first.depends)
73 export(copydeploymentfolders.commands)
74 QMAKE_EXTRA_TARGETS += first copydeploymentfolders
75 }
76 } else:unix {
77 maemo5 {
78 desktopfile.files = $${TARGET}.desktop
79 desktopfile.path = /usr/share/applications/hildon
80 icon.files = $${TARGET}64.png
81 icon.path = /usr/share/icons/hicolor/64x64/apps
82 } else:!isEmpty(MEEGO_VERSION_MAJOR) {
83 desktopfile.files = $${TARGET}_harmattan.desktop
84 desktopfile.path = /usr/share/applications
85 icon.files = $${TARGET}80.png
86 icon.path = /usr/share/icons/hicolor/80x80/apps
87 } else { # Assumed to be a Desktop Unix
88 copyCommand =
89 for(deploymentfolder, DEPLOYMENTFOLDERS) {
90 source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source)
91 source = $$replace(source, \\\\, /)
92 macx {
93 target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target)
94 } else {
95 target = $$OUT_PWD/$$eval($${deploymentfolder}.target)
96 }
97 target = $$replace(target, \\\\, /)
98 sourcePathSegments = $$split(source, /)
99 targetFullPath = $$target/$$last(sourcePathSegments)
100 targetFullPath ~= s,/\\.?/,/,
101 !isEqual(source,$$targetFullPath) {
102 !isEmpty(copyCommand):copyCommand += &&
103 copyCommand += $(MKDIR) \"$$target\"
104 copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\"
105 }
106 }
107 !isEmpty(copyCommand) {
108 copyCommand = @echo Copying application data... && $$copyCommand
109 copydeploymentfolders.commands = $$copyCommand
110 first.depends = $(first) copydeploymentfolders
111 export(first.depends)
112 export(copydeploymentfolders.commands)
113 QMAKE_EXTRA_TARGETS += first copydeploymentfolders
114 }
115 }
116 installPrefix = /opt/$${TARGET}
117 for(deploymentfolder, DEPLOYMENTFOLDERS) {
118 item = item$${deploymentfolder}
119 itemfiles = $${item}.files
120 $$itemfiles = $$eval($${deploymentfolder}.source)
121 itempath = $${item}.path
122 $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target)
123 export($$itemfiles)
124 export($$itempath)
125 INSTALLS += $$item
126 }
127
128 !isEmpty(desktopfile.path) {
129 export(icon.files)
130 export(icon.path)
131 export(desktopfile.files)
132 export(desktopfile.path)
133 INSTALLS += icon desktopfile
134 }
135
136 target.path = $${installPrefix}/bin
137 export(target.path)
138 INSTALLS += target
139 }
140
141 export (ICON)
142 export (INSTALLS)
143 export (DEPLOYMENT)
144 export (TARGET.EPOCHEAPSIZE)
145 export (TARGET.CAPABILITY)
146 export (LIBS)
147 export (QMAKE_EXTRA_TARGETS)
148 }
@@ -0,0 +1,11
1 [Desktop Entry]
2 Encoding=UTF-8
3 Version=1.0
4 Type=Application
5 Terminal=false
6 Name=qmlweather
7 Exec=/opt/qmlweather/bin/qmlweather
8 Icon=qmlweather64
9 X-Window-Icon=
10 X-HildonDesk-ShowInToolbar=true
11 X-Osso-Type=application/x-executable
@@ -0,0 +1,11
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 #qtcAddDeployment()
10
11 !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_DEMOS_BIN_DIR"
@@ -0,0 +1,93
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <svg
3 xmlns:dc="http://purl.org/dc/elements/1.1/"
4 xmlns:cc="http://creativecommons.org/ns#"
5 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6 xmlns:svg="http://www.w3.org/2000/svg"
7 xmlns="http://www.w3.org/2000/svg"
8 xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
9 xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
10 height="44px"
11 version="1.1"
12 viewBox="0 0 44 44"
13 width="44px"
14 x="0px"
15 y="0px"
16 id="svg2"
17 inkscape:version="0.47 r22583"
18 sodipodi:docname="qt.svg">
19 <metadata
20 id="metadata18">
21 <rdf:RDF>
22 <cc:Work
23 rdf:about="">
24 <dc:format>image/svg+xml</dc:format>
25 <dc:type
26 rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
27 </cc:Work>
28 </rdf:RDF>
29 </metadata>
30 <defs
31 id="defs16">
32 <inkscape:perspective
33 sodipodi:type="inkscape:persp3d"
34 inkscape:vp_x="0 : 22 : 1"
35 inkscape:vp_y="0 : 1000 : 0"
36 inkscape:vp_z="44 : 22 : 1"
37 inkscape:persp3d-origin="22 : 14.666667 : 1"
38 id="perspective2836" />
39 </defs>
40 <sodipodi:namedview
41 pagecolor="#ffffff"
42 bordercolor="#666666"
43 borderopacity="1"
44 objecttolerance="10"
45 gridtolerance="10"
46 guidetolerance="10"
47 inkscape:pageopacity="0"
48 inkscape:pageshadow="2"
49 inkscape:window-width="1920"
50 inkscape:window-height="1020"
51 id="namedview14"
52 showgrid="false"
53 inkscape:zoom="21.454545"
54 inkscape:cx="49.412871"
55 inkscape:cy="21.894358"
56 inkscape:window-x="-4"
57 inkscape:window-y="-4"
58 inkscape:window-maximized="1"
59 inkscape:current-layer="g3" />
60 <g
61 transform="matrix(0.18308778,0,0,0.18308778,6.6100946,3.2385199)"
62 id="g3">
63 <path
64 d="M 43.09,0.3586 C 40.94,0.0036 38.84,-0.0824 36.81,0.0776 31.968136,0.39505671 27.122677,0.73638425 22.28,1.0696 9.62,2.0816 0,12.4996 0,26.8896 l 0,169.7 14.19,13.2 28.87,-209.42 0.03,-0.011 z"
65 style="fill:#006225"
66 id="path5"
67 sodipodi:nodetypes="cccccccc" />
68 <path
69 d="m 174.4,160 c 0,12.5 -7.75,24.07 -17.57,25.77 L 14.23,209.73 V 25.93 C 14.23,9.21 27.57,-2.27 43.12,0.3 l 131.3,21.52 v 138.2 z"
70 style="fill:#80c342"
71 id="path7" />
72 <path
73 d="m 154.9,80.96 -12.96,-0.598 0,0.278 6.945,0.32 6.016,0 z"
74 style="fill:#006225"
75 id="path11" />
76 <path
77 d="m 144.6,135.6 c 0.66,0.328 1.43,0.476 2.351,0.476 0.161,0 0.329,-0.004 0.497,-0.016 2.55,-0.148 5.32,-0.933 8.343,-2.308 h -6.015 c -1.821,0.832 -3.532,1.457 -5.176,1.848 z"
78 style="fill:#006225"
79 id="path13" />
80 <path
81 id="path17"
82 style="fill:#ffffff"
83 d="m 91.15,132.4 c 2.351,-6.051 3.511,-17.91 3.511,-35.62 0,-15.89 -1.148,-26.82 -3.484,-32.81 -2.336,-6.027 -5.832,-9.281 -10.52,-9.691 -0.359,-0.031 -0.714,-0.051 -1.058,-0.051 -4.34,0 -7.68,2.535 -10.01,7.625 -2.52,5.543 -3.793,17.04 -3.793,34.44 0,16.82 1.238,28.75 3.734,35.75 2.356,6.672 5.879,9.976 10.5,9.976 0.207,0 0.41,-0.008 0.621,-0.019 4.633,-0.293 8.121,-3.496 10.49,-9.602 m 17.98,3.75 c -4.117,9.707 -10.39,16.06 -18.99,19 0.867,4.449 2.176,7.441 3.922,9.019 1.351,1.211 3.433,1.821 6.222,1.821 0.805,0 1.668,-0.055 2.59,-0.157 v 13.12 l -5.961,0.782 c -1.758,0.23 -3.426,0.343 -5.004,0.343 -5.218,0 -9.445,-1.265 -12.62,-3.824 -4.207,-3.379 -7.308,-9.894 -9.297,-19.54 -9.136,-1.945 -16.26,-7.754 -21.19,-17.5 -5.004,-9.902 -7.551,-24.39 -7.551,-43.34 0,-20.43 3.484,-35.51 10.34,-45.07 5.789,-8.07 13.86,-12.04 24.02,-12.04 1.629,0 3.309,0.102 5.043,0.305 11.95,1.375 20.62,7.016 26.26,16.79 5.535,9.562 8.254,23.27 8.254,41.26 0,16.48 -2,29.45 -6.043,39.02 z M 130.4,45.91 l 11.52,1.238 0,20.21 12.96,0.914 0,12.68 -12.96,-0.598 0,46.33 c 0,4.032 0.445,6.625 1.34,7.789 0.8,1.067 2.046,1.594 3.71,1.594 0.161,0 0.329,-0.004 0.497,-0.016 2.55,-0.148 5.32,-0.933 8.343,-2.308 v 11.65 c -5.136,2.258 -10.18,3.598 -15.12,4.02 -0.718,0.055 -1.41,0.086 -2.078,0.086 -4.48,0 -7.906,-1.301 -10.25,-3.934 -2.73,-3.051 -4.09,-7.949 -4.09,-14.67 V 79.535 L 118.046,79.25 V 65.66 l 7.586,0.547 4.773,-20.3 z" />
84 <path
85 d="m 100.3,166 c 0.809,0 1.672,-0.055 2.59,-0.157 H 98.054 C 98.73,165.949 99.507,166 100.3,166 z"
86 style="fill:#006225"
87 id="path19" />
88 <path
89 id="path21"
90 style="fill:#006225"
91 d="m 84.85,63.98 c 2.336,5.997 3.484,16.92 3.484,32.81 0,17.7 -1.16,29.57 -3.512,35.62 -1.894,4.879 -4.527,7.902 -7.863,9.07 0.965,0.368 1.992,0.551 3.078,0.551 0.207,0 0.41,-0.008 0.621,-0.019 4.633,-0.293 8.121,-3.496 10.49,-9.602 2.351,-6.051 3.511,-17.91 3.511,-35.62 0,-15.89 -1.148,-26.82 -3.484,-32.81 -2.336,-6.027 -5.832,-9.281 -10.52,-9.691 -0.359,-0.031 -0.714,-0.051 -1.058,-0.051 -1.09,0 -2.117,0.16 -3.082,0.481 h -0.004 c 3.601,1.121 6.379,4.215 8.336,9.261 z m -2.344,114.3 c -0.113,-0.05 -0.227,-0.105 -0.336,-0.16 -0.012,-0.004 -0.023,-0.012 -0.035,-0.015 -0.102,-0.051 -0.207,-0.106 -0.309,-0.157 -0.019,-0.011 -0.039,-0.019 -0.058,-0.031 -0.09,-0.051 -0.184,-0.098 -0.278,-0.148 -0.027,-0.016 -0.054,-0.036 -0.086,-0.051 -0.082,-0.043 -0.164,-0.09 -0.242,-0.137 -0.039,-0.023 -0.078,-0.047 -0.113,-0.07 -0.07,-0.039 -0.145,-0.082 -0.215,-0.125 -0.047,-0.031 -0.094,-0.059 -0.14,-0.09 -0.059,-0.039 -0.118,-0.074 -0.176,-0.113 -0.059,-0.039 -0.114,-0.075 -0.168,-0.114 -0.051,-0.031 -0.102,-0.066 -0.149,-0.097 -0.066,-0.047 -0.132,-0.094 -0.195,-0.137 -0.039,-0.027 -0.078,-0.055 -0.113,-0.082 -0.078,-0.055 -0.153,-0.113 -0.231,-0.172 -0.023,-0.016 -0.05,-0.035 -0.078,-0.055 -0.098,-0.078 -0.199,-0.156 -0.297,-0.234 -4.207,-3.379 -7.308,-9.894 -9.297,-19.54 -9.136,-1.945 -16.26,-7.754 -21.19,-17.5 -5.004,-9.902 -7.551,-24.39 -7.551,-43.34 0,-20.43 3.484,-35.51 10.34,-45.07 5.789,-8.07 13.86,-12.04 24.02,-12.04 h -6.351 c -10.15,0.008 -18.22,3.977 -24,12.04 -6.855,9.563 -10.34,24.64 -10.34,45.07 0,18.95 2.547,33.44 7.551,43.34 4.934,9.75 12.05,15.56 21.19,17.5 1.989,9.641 5.09,16.16 9.297,19.54 3.176,2.559 7.403,3.824 12.62,3.824 0.098,0 0.199,0 0.297,-0.004 h 5.539 c -3.406,-0.05 -6.383,-0.66 -8.906,-1.828 L 82.498,178.28 z M 128.4,145.6 c -2.73,-3.051 -4.09,-7.949 -4.09,-14.67 V 79.57 l -6.226,-0.285 v -13.59 h -6.016 v 3.035 c 0.871,3.273 1.555,6.82 2.063,10.64 l 4.164,0.192 v 51.36 c 0,6.723 1.367,11.62 4.09,14.67 2.343,2.633 5.765,3.934 10.25,3.934 h 6.015 c -4.48,0 -7.906,-1.301 -10.25,-3.934 z m 2.043,-99.66 -6.016,0 -4.668,19.88 5.911,0.422 4.773,-20.3 z" />
92 </g>
93 </svg>
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,11
1 [Desktop Entry]
2 Encoding=UTF-8
3 Version=1.0
4 Type=Application
5 Terminal=false
6 Name=qmlweather
7 Exec=/usr/bin/single-instance /opt/qmlweather/bin/qmlweather
8 Icon=/usr/share/icons/hicolor/80x80/apps/qmlweather80.png
9 X-Window-Icon=
10 X-HildonDesk-ShowInToolbar=true
11 X-Osso-Type=application/x-executable
@@ -0,0 +1,5
1 <RCC>
2 <qresource prefix="/">
3 <file>qml/qmlweather/main.qml</file>
4 </qresource>
5 </RCC>
@@ -1,10 +1,11
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 dynamicspline \
9 10 qmlchart \
10 dynamicspline
11 qmlweather
@@ -1,58 +1,34
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 #ifndef DECLARATIVE_AXIS_H
22 #define DECLARATIVE_AXIS_H
21 #include <QApplication>
22 #include "qmlapplicationviewer.h"
23 23
24 #include "qchartglobal.h"
25 #include <QAxis>
26 #include <QDeclarativeParserStatus>
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 class DeclarativeAxis: public QAxis, public QDeclarativeParserStatus
24 Q_DECL_EXPORT int main(int argc, char *argv[])
31 25 {
32 Q_INTERFACES(QDeclarativeParserStatus)
33 Q_OBJECT
34 Q_PROPERTY(AxisRole role READ role WRITE setRole /*NOTIFY roleChanged*/)
35 Q_ENUMS(AxisRole)
36
37 public:
38 enum AxisRole {
39 RoleX = 0,
40 RoleY
41 };
42
43 public:
44 explicit DeclarativeAxis(QObject *parent = 0);
45
46 public: // from QDeclarativeParserStatus
47 virtual void classBegin();
48 virtual void componentComplete();
49
50 public:
51 void setRole(AxisRole role);
52 AxisRole role() { return m_role; }
53 AxisRole m_role;
54 };
26 QScopedPointer<QApplication> app(createApplication(argc, argv));
55 27
56 QTCOMMERCIALCHART_END_NAMESPACE
28 QmlApplicationViewer viewer;
29 viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
30 viewer.setSource(QUrl("qrc:/qml/qmlweather/main.qml"));
31 viewer.showExpanded();
57 32
58 #endif // DECLARATIVE_AXIS_H
33 return app->exec();
34 }
@@ -1,135 +1,148
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 #include "declarativepieseries.h"
23 22 #include <QPainter>
24 23
25 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 25
27 26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
28 27 : QDeclarativeItem(parent),
29 28 m_chart(new QChart(this)),
30 29 m_legend(LegendDisabled)
31 30 {
32 31 setFlag(QGraphicsItem::ItemHasNoContents, false);
32 m_chart->axisX()->setNiceNumbersEnabled(false);
33 33 }
34 34
35 35 DeclarativeChart::~DeclarativeChart()
36 36 {
37 37 delete m_chart;
38 38 }
39 39
40 40 void DeclarativeChart::childEvent(QChildEvent *event)
41 41 {
42 42 if (event->type() == QEvent::ChildAdded) {
43 43 if (qobject_cast<QAbstractSeries *>(event->child())) {
44 44 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
45 45 }
46 46 }
47 47 }
48 48
49 49 void DeclarativeChart::componentComplete()
50 50 {
51 // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max();
51 52 foreach(QObject *child, children()) {
52 53 if (qobject_cast<QAbstractSeries *>(child)) {
53 54 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
54 55 }
55 56 }
57 // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max();
56 58
57 59 QDeclarativeItem::componentComplete();
58 60 }
59 61
60 62 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
61 63 {
64 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
62 65 Q_UNUSED(oldGeometry)
63 66
64 67 if (newGeometry.isValid()) {
65 68 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
66 69 m_chart->resize(newGeometry.width(), newGeometry.height());
67 70 }
68 71 }
69 72 }
70 73
71 74 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
72 75 {
73 76 Q_UNUSED(option)
74 77 Q_UNUSED(widget)
75 78
76 79 // TODO: optimized?
77 80 painter->setRenderHint(QPainter::Antialiasing, true);
78 81 }
79 82
80 83 void DeclarativeChart::setAnimationOptions(QChart::AnimationOption animations)
81 84 {
82 85 m_chart->setAnimationOptions(animations);
83 86 }
84 87
85 88 QChart::AnimationOption DeclarativeChart::animationOptions()
86 89 {
87 90 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
88 91 return QChart::AllAnimations;
89 92 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
90 93 return QChart::GridAxisAnimations;
91 94 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
92 95 return QChart::SeriesAnimations;
93 96 else
94 97 return QChart::NoAnimation;
95 98 }
96 99
97 100 void DeclarativeChart::setLegend(ChartLegend legend)
98 101 {
99 102 if (legend != m_legend) {
100 103 m_legend = legend;
101 104 switch (m_legend) {
102 105 case LegendDisabled:
103 106 m_chart->legend()->setVisible(false);
104 107 break;
105 108 case LegendTop:
106 109 m_chart->legend()->setVisible(true);
107 110 m_chart->legend()->setAlignment(QLegend::AlignmentTop);
108 111 break;
109 112 case LegendBottom:
110 113 m_chart->legend()->setVisible(true);
111 114 m_chart->legend()->setAlignment(QLegend::AlignmentBottom);
112 115 break;
113 116 case LegendLeft:
114 117 m_chart->legend()->setVisible(true);
115 118 m_chart->legend()->setAlignment(QLegend::AlignmentLeft);
116 119 break;
117 120 case LegendRight:
118 121 m_chart->legend()->setVisible(true);
119 122 m_chart->legend()->setAlignment(QLegend::AlignmentRight);
120 123 break;
121 124 default:
122 125 m_chart->legend()->setVisible(false);
123 126 break;
124 127 }
125 128 }
126 129 }
127 130
128 131 DeclarativeChart::ChartLegend DeclarativeChart::legend()
129 132 {
130 133 return m_legend;
131 134 }
132 135
136 QAxis *DeclarativeChart::axisX()
137 {
138 return m_chart->axisX();
139 }
140
141 QAxis *DeclarativeChart::axisY()
142 {
143 return m_chart->axisY();
144 }
145
133 146 #include "moc_declarativechart.cpp"
134 147
135 148 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,80 +1,85
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 #include <QAxis>
27 28
28 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 30
30 31 // TODO: Derive from QChart for easier definition of properties?
31 32 class DeclarativeChart : public QDeclarativeItem
32 33 // TODO: for QTQUICK2: extend QQuickPainterItem instead
33 34 //class DeclarativeChart : public QQuickPaintedItem, public Chart
34 35 {
35 36 Q_OBJECT
36 37 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
37 38 Q_PROPERTY(QChart::AnimationOption animationOptions READ animationOptions WRITE setAnimationOptions)
38 39 Q_PROPERTY(QString title READ title WRITE setTitle)
39 40 Q_PROPERTY(ChartLegend legend READ legend WRITE setLegend)
41 Q_PROPERTY(QAxis *axisX READ axisX)
42 Q_PROPERTY(QAxis *axisY READ axisY)
40 43 Q_ENUMS(ChartLegend)
41 44
42 45 public:
43 46 enum ChartLegend {
44 47 LegendDisabled = 0,
45 48 LegendTop,
46 49 LegendBottom,
47 50 LegendLeft,
48 51 LegendRight
49 52 };
50 53
51 54 public:
52 55 DeclarativeChart(QDeclarativeItem *parent = 0);
53 56 ~DeclarativeChart();
54 57
55 58 public: // From QDeclarativeItem/QGraphicsItem
56 59 void childEvent(QChildEvent *event);
57 60 void componentComplete();
58 61 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
59 62 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
60 63
61 64 public:
62 65 void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);}
63 66 QChart::ChartTheme theme() {return m_chart->theme();}
64 67 void setAnimationOptions(QChart::AnimationOption animations);
65 68 QChart::AnimationOption animationOptions();
66 69 void setTitle(QString title) {m_chart->setTitle(title);}
67 70 QString title() { return m_chart->title();}
68 71 void setLegend(ChartLegend legend);
69 72 ChartLegend legend();
73 QAxis *axisX();
74 QAxis *axisY();
70 75
71 76 public:
72 77 // Extending QChart with DeclarativeChart is not possible because QObject does not support
73 78 // multi inheritance, so we now have a QChart as a member instead
74 79 QChart *m_chart;
75 80 ChartLegend m_legend;
76 81 };
77 82
78 83 QTCOMMERCIALCHART_END_NAMESPACE
79 84
80 85 #endif // DECLARATIVECHART_H
@@ -1,40 +1,35
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 "declarativelineseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include "qlineseries.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
29 29 QLineSeries(parent)
30 30 {
31 31 }
32 32
33 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points()
34 {
35 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
36 }
37
38 33 #include "moc_declarativelineseries.cpp"
39 34
40 35 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,45 +1,42
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
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
32 32 {
33 33 Q_OBJECT
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(DeclarativeXyModel *model READ declarativeModel WRITE setDeclarativeModel)
35 35
36 36 public:
37 37 explicit DeclarativeLineSeries(QObject *parent = 0);
38
39 public:
40 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 38 };
42 39
43 40 QTCOMMERCIALCHART_END_NAMESPACE
44 41
45 42 #endif // DECLARATIVELINESERIES_H
@@ -1,89 +1,141
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 #include "declarativepiemodel.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
21 #include "declarativemodel.h"
24 22 #include <qdeclarativelist.h>
23 #include <QDebug>
25 24
26 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 26
28 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
27 ////////////// XY model ///////////////////////
28
29 DeclarativeXyModel::DeclarativeXyModel(QObject *parent) :
29 30 ChartTableModel(parent)
30 31 {
31 32 }
32 33
33 //void DeclarativePieModel::classBegin()
34 //{
35 //}
34 void DeclarativeXyModel::append(DeclarativeXyPoint* point)
35 {
36 // qDebug() << "DeclarativeXyModel::append:" << point->x() << " " << point->y();
37 insertRow(rowCount());
38 QModelIndex xModelIndex = createIndex(rowCount() - 1, 0);
39 QModelIndex yModelIndex = createIndex(rowCount() - 1, 1);
40 setData(xModelIndex, point->x());
41 setData(yModelIndex, point->y());
42 dataChanged(xModelIndex, yModelIndex);
43 }
36 44
37 //void DeclarativePieModel::componentComplete()
38 //{
39 //}
45 void DeclarativeXyModel::append(QVariantList points)
46 {
47 qreal x = 0.0;
48 for (int i(0); i < points.count(); i++) {
49 if (i % 2) {
50 bool ok(false);
51 qreal y = points.at(i).toReal(&ok);
52 if (ok) {
53 DeclarativeXyPoint *point= new DeclarativeXyPoint();
54 point->setX(x);
55 point->setY(y);
56 append(point);
57 } else {
58 qWarning() << "Illegal y value";
59 }
60 } else {
61 bool ok(false);
62 x = points.at(i).toReal(&ok);
63 if (!ok) {
64 qWarning() << "Illegal x value";
65 }
66 }
67 }
68 }
69
70 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeXyModel::points()
71 {
72 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXyModel::appendPoint);
73 }
74
75 void DeclarativeXyModel::appendPoint(QDeclarativeListProperty<DeclarativeXyPoint> *list,
76 DeclarativeXyPoint *point)
77 {
78 DeclarativeXyModel *model = qobject_cast<DeclarativeXyModel *>(list->object);
79 if (model)
80 model->append(point);
81 else
82 qWarning() << "Illegal point item";
83 }
84
85 ////////////// Pie model ///////////////////////
86
87 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
88 ChartTableModel(parent)
89 {
90 }
40 91
41 92 void DeclarativePieModel::append(QPieSlice* slice)
42 93 {
43 // TODO: label not working...
44 94 qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value();
45 95 qDebug() << "rowCount:" << rowCount();
46 96 qDebug() << "coolCount:" << columnCount();
47 97 insertRow(rowCount());
48 98 qDebug() << "new rowCount:" << rowCount();
49 99
50 100 qDebug() << setData(createIndex(rowCount() - 1, 0), slice->value());
51 101 qDebug() << setData(createIndex(rowCount() - 1, 1), slice->label());
52 102 }
53 103
54 104 void DeclarativePieModel::append(QVariantList slices)
55 105 {
56 106 qDebug() << "append:" << slices;
57 107 QString label = "";
58 108 for (int i(0); i < slices.count(); i++) {
59 109 if (i % 2) {
60 110 bool ok(false);
61 111 qreal value = slices.at(i).toReal(&ok);
62 112 if (ok) {
63 113 QPieSlice *slice = new QPieSlice(value, label);
64 114 append(slice);
115 } else {
116 qWarning() << "Illegal slice item";
65 117 }
66 118 } else {
67 119 label = slices.at(i).toString();
68 120 }
69 121 }
70 122 }
71 123
72 124 QDeclarativeListProperty<QPieSlice> DeclarativePieModel::slices()
73 125 {
74 126 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieModel::appendSlice);
75 127 }
76 128
77 129 void DeclarativePieModel::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
78 130 QPieSlice *slice)
79 131 {
80 132 DeclarativePieModel *pieModel = qobject_cast<DeclarativePieModel *>(list->object);
81 133 if (pieModel)
82 134 pieModel->append(slice);
83 135 else
84 136 qWarning() << "Illegal slice item";
85 137 }
86 138
87 #include "moc_declarativepiemodel.cpp"
139 #include "moc_declarativemodel.cpp"
88 140
89 141 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,61 +1,70
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 #ifndef DECLARATIVEPIEMODEL_H
22 #define DECLARATIVEPIEMODEL_H
21 #ifndef DECLARATIVEMODEL_H
22 #define DECLARATIVEMODEL_H
23 23
24 24 #include "qchartglobal.h"
25 #include "declarativexypoint.h"
25 26 #include "qpieslice.h"
26 #include "qpieseries.h"
27 #include "../src/charttablemodel.h"
28 #include <QDeclarativeParserStatus>
27 #include "../src/charttablemodel.h" // TODO
29 28 #include <QDeclarativeListProperty>
30 #include <QAbstractItemModel>
31 29 #include <QVariant>
32 30
33 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 32
35 class DeclarativePieModel : public ChartTableModel/*, public QDeclarativeParserStatus*/
33 class DeclarativeXyModel : public ChartTableModel
34 {
35 Q_OBJECT
36 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
37 Q_CLASSINFO("DefaultProperty", "points")
38
39 public:
40 explicit DeclarativeXyModel(QObject *parent = 0);
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42
43 public Q_SLOTS:
44 void append(DeclarativeXyPoint* point);
45 void append(QVariantList points);
46 static void appendPoint(QDeclarativeListProperty<DeclarativeXyPoint> *list,
47 DeclarativeXyPoint *element);
48 };
49
50
51 class DeclarativePieModel : public ChartTableModel
36 52 {
37 // Q_INTERFACES(QDeclarativeParserStatus)
38 53 Q_OBJECT
39 54 Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices)
40 55 Q_CLASSINFO("DefaultProperty", "slices")
41 56
42 57 public:
43 58 explicit DeclarativePieModel(QObject *parent = 0);
44 59 QDeclarativeListProperty<QPieSlice> slices();
45 60
46 //public: // from QDeclarativeParserStatus
47 // virtual void classBegin();
48 // virtual void componentComplete();
49
50 61 public Q_SLOTS:
51 62 void append(QPieSlice* slice);
52 63 void append(QVariantList slices);
53 64 static void appendSlice(QDeclarativeListProperty<QPieSlice> *list,
54 65 QPieSlice *element);
55
56 public:
57 66 };
58 67
59 68 QTCOMMERCIALCHART_END_NAMESPACE
60 69
61 #endif // DECLARATIVEPIEMODEL_H
70 #endif // DECLARATIVEMODEL_H
@@ -1,51 +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 #include "declarativepieseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include <qdeclarativelist.h>
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
29 29 QPieSeries(parent)
30 30 {
31 31 }
32 32
33 33 bool DeclarativePieSeries::setPieModel(DeclarativePieModel *model)
34 34 {
35 35 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
36 36 bool value(false);
37 37 if (m) {
38 38 value = QPieSeries::setModel(m);
39 39 setModelMapping(0, 1, Qt::Vertical);
40 } else {
41 qWarning("DeclarativePieSeries: Illegal model");
40 42 }
41 43 return value;
42 44 }
43 45
44 46 DeclarativePieModel *DeclarativePieSeries::pieModel()
45 47 {
46 48 return qobject_cast<DeclarativePieModel *>(model());
47 49 }
48 50
49 51 #include "moc_declarativepieseries.cpp"
50 52
51 53 QTCOMMERCIALCHART_END_NAMESPACE
@@ -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 DECLARATIVEPIESERIES_H
22 22 #define DECLARATIVEPIESERIES_H
23 23
24 24 #include "qchartglobal.h"
25 25 #include "qpieslice.h"
26 26 #include "qpieseries.h"
27 27 #include <QDeclarativeListProperty>
28 28 #include <QAbstractItemModel>
29 29 #include <QVariant>
30 #include "declarativepiemodel.h"
30 #include "declarativemodel.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 class QChart;
35 35
36 36 class DeclarativePieSeries : public QPieSeries
37 37 {
38 38 Q_OBJECT
39 39 Q_PROPERTY(DeclarativePieModel *model READ pieModel WRITE setPieModel)
40 40
41 41 public:
42 42 explicit DeclarativePieSeries(QObject *parent = 0);
43 43
44 44 public Q_SLOTS:
45 45
46 46 public:
47 47 bool setPieModel(DeclarativePieModel *model);
48 48 DeclarativePieModel *pieModel();
49 49 };
50 50
51 51 QTCOMMERCIALCHART_END_NAMESPACE
52 52
53 53 #endif // DECLARATIVEPIESERIES_H
@@ -1,40 +1,35
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 "declarativescatterseries.h"
22 22 #include "declarativechart.h"
23 23 #include "qchart.h"
24 24 #include "qscatterseries.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
29 29 QScatterSeries(parent)
30 30 {
31 31 }
32 32
33 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points()
34 {
35 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
36 }
37
38 33 #include "moc_declarativescatterseries.cpp"
39 34
40 35 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,45 +1,42
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 #include <QDeclarativeParserStatus>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
32 32 {
33 33 Q_OBJECT
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(DeclarativeXyModel *model READ declarativeModel WRITE setDeclarativeModel)
35 35
36 36 public:
37 37 explicit DeclarativeScatterSeries(QObject *parent = 0);
38
39 public:
40 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 38 };
42 39
43 40 QTCOMMERCIALCHART_END_NAMESPACE
44 41
45 42 #endif // DECLARATIVESCATTERSERIES_H
@@ -1,39 +1,34
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.h"
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
28 28 QSplineSeries(parent)
29 29 {
30 30 }
31 31
32 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points()
33 {
34 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
35 }
36
37 32 #include "moc_declarativesplineseries.cpp"
38 33
39 34 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,45 +1,42
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(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(DeclarativeXyModel *model READ declarativeModel WRITE setDeclarativeModel)
35 35
36 36 public:
37 37 explicit DeclarativeSplineSeries(QObject *parent = 0);
38
39 public:
40 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 38 };
42 39
43 40 QTCOMMERCIALCHART_END_NAMESPACE
44 41
45 42 #endif // DECLARATIVESPLINESERIES_H
@@ -1,44 +1,59
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 "qxyseries.h"
24 24 #include "declarativechart.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 DeclarativeXySeries::DeclarativeXySeries()
29 29 {
30 30 }
31 31
32 32 DeclarativeXySeries::~DeclarativeXySeries()
33 33 {
34 34 }
35 35
36 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
37 DeclarativeXyPoint *element)
36 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeXyModel *model)
38 37 {
39 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
40 if (series)
41 series->append(element->x(), element->y());
38 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
39 bool value(false);
40 if (m) {
41 // All the inherited objects must be of type QXYSeries, so it is safe to cast
42 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
43 series->setModel(m);
44 series->setModelMapping(0, 1, Qt::Vertical);
45 } else {
46 qWarning("DeclarativeXySeries: Illegal model");
47 }
48 return value;
49 }
50
51 DeclarativeXyModel *DeclarativeXySeries::declarativeModel()
52 {
53 // All the inherited objects must be of type QXYSeries, so it is safe to cast
54 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
55 Q_ASSERT(series);
56 return qobject_cast<DeclarativeXyModel *>(series->model());
42 57 }
43 58
44 59 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,51 +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 #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 #include <QDeclarativeListProperty>
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 Q_INTERFACES(QDeclarativeParserStatus)
36 36
37 37 public:
38 38 explicit DeclarativeXySeries();
39 39 ~DeclarativeXySeries();
40 40
41 41 public:
42 virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0;
43
44 public Q_SLOTS:
45 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
46 DeclarativeXyPoint *element);
42 bool setDeclarativeModel(DeclarativeXyModel *model);
43 DeclarativeXyModel *declarativeModel();
47 44 };
48 45
49 46 QTCOMMERCIALCHART_END_NAMESPACE
50 47
51 48 #endif // DECLARATIVE_XY_SERIES_H
@@ -1,66 +1,69
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 #include "qaxiscategories.h"
24 25 #include "declarativechart.h"
25 #include "declarativeaxis.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 #include "declarativepiemodel.h"
33 //#include "declarativepiemodel.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
38 38 {
39 39 Q_OBJECT
40 40 public:
41 41 virtual void registerTypes(const char *uri)
42 42 {
43 43 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
44 44
45 45 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
46 qmlRegisterType<DeclarativeAxis>(uri, 1, 0, "Axis");
46 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
47 QLatin1String("Trying to create uncreatable type: Axis."));
48 //qmlRegisterType<DeclarativeAxisCategory>(uri, 1, 0, "AxisCategory");
47 49 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
48 50 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
49 51 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
50 52 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
51 53 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
52 54 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
53 55 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
54 56 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
55 57 // TODO: a declarative model for each type
56 58 qmlRegisterType<DeclarativePieModel>(uri, 1, 0, "PieModel");
59 qmlRegisterType<DeclarativeXyModel>(uri, 1, 0, "XYModel");
57 60 }
58 61 };
59 62
60 63 #include "plugin.moc"
61 64
62 65 QTCOMMERCIALCHART_END_NAMESPACE
63 66
64 67 QTCOMMERCIALCHART_USE_NAMESPACE
65 68
66 69 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,56 +1,54
1 1 TEMPLATE = lib
2 2 TARGET = qtcommercialchartqml
3 3 CONFIG += qt plugin
4 4 QT += declarative
5 5
6 6 !include( ../config.pri ) {
7 7 error( "Couldn't find the config.pri file!" )
8 8 }
9 9
10 10 DESTDIR = $$CHART_BUILD_PLUGIN_DIR
11 11 contains(QT_MAJOR_VERSION, 5) {
12 12 # TODO: QtQuick2 not supported by the implementation currently
13 13 DEFINES += QTQUICK2
14 14 }
15 15
16 16 OBJECTS_DIR = $$CHART_BUILD_DIR/plugin
17 17 MOC_DIR = $$CHART_BUILD_DIR/plugin
18 18 UI_DIR = $$CHART_BUILD_DIR/plugin
19 19 RCC_DIR = $$CHART_BUILD_DIR/plugin
20 20
21 21 SOURCES += \
22 22 plugin.cpp \
23 23 declarativechart.cpp \
24 declarativeaxis.cpp \
25 24 declarativexypoint.cpp \
26 25 declarativexyseries.cpp \
27 26 declarativelineseries.cpp \
28 27 declarativesplineseries.cpp \
29 28 declarativeareaseries.cpp \
30 29 declarativescatterseries.cpp \
31 30 declarativepieseries.cpp \
32 31 declarativebarseries.cpp \
33 declarativepiemodel.cpp
32 declarativemodel.cpp
34 33 HEADERS += \
35 34 declarativechart.h \
36 declarativeaxis.h \
37 35 declarativexypoint.h \
38 36 declarativexyseries.h \
39 37 declarativelineseries.h \
40 38 declarativesplineseries.h \
41 39 declarativeareaseries.h \
42 40 declarativescatterseries.h \
43 41 declarativepieseries.h \
44 42 declarativebarseries.h \
45 declarativepiemodel.h
43 declarativemodel.h
46 44
47 45 TARGETPATH = QtCommercial/Chart
48 46 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
49 47 qmldir.files += $$PWD/qmldir
50 48 qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
51 49 INSTALLS += target qmldir
52 50
53 51 FILE = $$PWD/qmldir
54 52 win32:{FILE = $$replace(FILE, "/","\\")}
55 53 QMAKE_POST_LINK += $$QMAKE_COPY $$FILE $$CHART_BUILD_PLUGIN_DIR
56 54 !system_build:mac: QMAKE_POST_LINK += " & $$MAC_POST_LINK_PREFIX $$MAC_PLUGINS_BIN_DIR"
@@ -1,110 +1,112
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 QAXIS_H
22 22 #define QAXIS_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <qaxiscategories.h>
26 26 #include <QPen>
27 27 #include <QFont>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class QAxisPrivate;
32 32
33 33 class QTCOMMERCIALCHART_EXPORT QAxis : public QObject
34 34 {
35 35 Q_OBJECT
36 36 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible)
37 Q_PROPERTY(qreal min READ min WRITE setMin)
38 Q_PROPERTY(qreal max READ max WRITE setMax)
37 39
38 40 public:
39 41
40 42 QAxis(QObject *parent =0);
41 43 ~QAxis();
42 44
43 45 //axis handling
44 46 bool isAxisVisible() const;
45 47 void setAxisVisible(bool visible = true);
46 48 void setAxisPen(const QPen &pen);
47 49 QPen axisPen() const;
48 50
49 51 //grid handling
50 52 bool isGridLineVisible() const;
51 53 void setGridLineVisible(bool visible = true);
52 54 void setGridLinePen(const QPen &pen);
53 55 QPen gridLinePen() const;
54 56
55 57 //labels handling
56 58 bool labelsVisible() const;
57 59 void setLabelsVisible(bool visible = true);
58 60 void setLabelsPen(const QPen &pen);
59 61 QPen labelsPen() const;
60 62 void setLabelsBrush(const QBrush &brush);
61 63 QBrush labelsBrush() const;
62 64 void setLabelsFont(const QFont &font);
63 65 QFont labelsFont() const;
64 66 void setLabelsAngle(int angle);
65 67 int labelsAngle() const;
66 68
67 69 //shades handling
68 70 bool shadesVisible() const;
69 71 void setShadesVisible(bool visible = true);
70 72 void setShadesPen(const QPen &pen);
71 73 QPen shadesPen() const;
72 74 void setShadesBrush(const QBrush &brush);
73 75 QBrush shadesBrush() const;
74 76 void setShadesOpacity(qreal opacity);
75 77 qreal shadesOpacity() const;
76 78
77 79 //range handling
78 80 void setMin(qreal min);
79 81 qreal min() const;
80 82 void setMax(qreal max);
81 83 qreal max() const;
82 84 void setRange(qreal min, qreal max);
83 85
84 86 //ticks handling
85 87 void setTicksCount(int count);
86 88 int ticksCount() const;
87 89
88 90 void setNiceNumbersEnabled(bool enable = true);
89 91 bool niceNumbersEnabled() const;
90 92
91 93 QAxisCategories* categories();
92 94
93 95 void show();
94 96 void hide();
95 97
96 98 Q_SIGNALS:
97 99 void minChanged(qreal min);
98 100 void maxChanged(qreal max);
99 101 void rangeChanged(qreal min, qreal max);
100 102 void ticksCountChanged(int count);
101 103
102 104 private:
103 105 QScopedPointer<QAxisPrivate> d_ptr;
104 106 Q_DISABLE_COPY(QAxis);
105 107 friend class ChartDataSet;
106 108 friend class ChartAxis;
107 109 };
108 110
109 111 QTCOMMERCIALCHART_END_NAMESPACE
110 112 #endif /* QCHARTAXIS_H_ */
@@ -1,302 +1,302
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 "domain_p.h"
22 22 #include <cmath>
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 Domain::Domain(QObject* parent):QObject(parent),
27 27 m_minX(0),
28 m_maxX(0),
28 m_maxX(1),
29 29 m_minY(0),
30 m_maxY(0),
30 m_maxY(1),
31 31 m_tickXCount(5),
32 32 m_tickYCount(5),
33 33 m_niceXNumbers(false),
34 34 m_niceYNumbers(false)
35 35 {
36 36 }
37 37
38 38 Domain::~Domain()
39 39 {
40 40 }
41 41
42 42 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
43 43 {
44 44 setRange(minX, maxX, minY, maxY,m_tickXCount,m_tickYCount);
45 45 }
46 46
47 47 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCount,int tickYCount)
48 48 {
49 49 bool axisXChanged = false;
50 50 bool axisYChanged = false;
51 51
52 52 if(m_tickXCount!=tickXCount) {
53 53 m_tickXCount=tickXCount;
54 54 axisXChanged=true;
55 55 }
56 56
57 57 if(m_tickYCount!=tickYCount) {
58 58 m_tickYCount=tickYCount;
59 59 axisYChanged=true;
60 60 }
61 61
62 62 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
63 63 if(m_niceXNumbers) looseNiceNumbers(minX, maxX, m_tickXCount);
64 64 m_minX=minX;
65 65 m_maxX=maxX;
66 66 axisXChanged=true;
67 67 }
68 68
69 69 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
70 70 if(m_niceYNumbers) looseNiceNumbers(minY, maxY, m_tickYCount);
71 71 m_minY=minY;
72 72 m_maxY=maxY;
73 73 axisYChanged=true;
74 74 }
75 75
76 76 if(axisXChanged || axisYChanged) {
77 77 emit this->domainChanged(m_minX, m_maxX, m_minY, m_maxY);
78 78 }
79 79
80 80 if(axisXChanged) {
81 81 emit rangeXChanged(minX,maxX, m_tickXCount);
82 82 }
83 83
84 84 if(axisYChanged) {
85 85 emit rangeYChanged(minY,maxY, m_tickYCount);
86 86 }
87 87 }
88 88
89 89 void Domain::setRangeX(qreal min, qreal max)
90 90 {
91 91 setRange(min,max,m_minY, m_maxY);
92 92 }
93 93
94 94 void Domain::setRangeX(qreal min, qreal max, int tickCount)
95 95 {
96 96 setRange(min,max,m_minY, m_maxY,tickCount,m_tickYCount);
97 97 }
98 98
99 99 void Domain::setRangeY(qreal min, qreal max)
100 100 {
101 101 setRange(m_minX, m_maxX, min, max);
102 102 }
103 103
104 104 void Domain::setRangeY(qreal min, qreal max,int tickCount)
105 105 {
106 106 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickCount);
107 107 }
108 108
109 109 void Domain::setMinX(qreal min)
110 110 {
111 111 setRange(min, m_maxX, m_minY, m_maxY);
112 112 }
113 113
114 114 void Domain::setMaxX(qreal max)
115 115 {
116 116 setRange(m_minX, max, m_minY, m_maxY);
117 117 }
118 118
119 119 void Domain::setMinY(qreal min)
120 120 {
121 121 setRange(m_minX, m_maxX, min, m_maxY);
122 122 }
123 123
124 124 void Domain::setMaxY(qreal max)
125 125 {
126 126 setRange(m_minX, m_maxX, m_minY, max);
127 127 }
128 128
129 129 qreal Domain::spanX() const
130 130 {
131 131 Q_ASSERT(m_maxX >= m_minX);
132 132 return m_maxX - m_minX;
133 133 }
134 134
135 135 qreal Domain::spanY() const
136 136 {
137 137 Q_ASSERT(m_maxY >= m_minY);
138 138 return m_maxY - m_minY;
139 139 }
140 140
141 141 bool Domain::isEmpty() const
142 142 {
143 143 return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY());
144 144 }
145 145
146 146 void Domain::zoomIn(const QRectF& rect, const QSizeF& size)
147 147 {
148 148 qreal dx = spanX() / size.width();
149 149 qreal dy = spanY() / size.height();
150 150
151 151 qreal maxX = m_maxX;
152 152 qreal minX = m_minX;
153 153 qreal minY = m_minY;
154 154 qreal maxY = m_maxY;
155 155
156 156 maxX = minX + dx * rect.right();
157 157 minX = minX + dx * rect.left();
158 158 minY = maxY - dy * rect.bottom();
159 159 maxY = maxY - dy * rect.top();
160 160
161 161 int tickXCount = m_tickXCount;
162 162 int tickYCount = m_tickYCount;
163 163
164 164 if(m_niceXNumbers) {
165 165 looseNiceNumbers(minX, maxX, tickXCount);
166 166 }
167 167 if(m_niceYNumbers) {
168 168 looseNiceNumbers(minY, maxY, tickYCount);
169 169 }
170 170 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
171 171 }
172 172
173 173 void Domain::zoomOut(const QRectF& rect, const QSizeF& size)
174 174 {
175 175 qreal dx = spanX() / rect.width();
176 176 qreal dy = spanY() / rect.height();
177 177
178 178 qreal maxX = m_maxX;
179 179 qreal minX = m_minX;
180 180 qreal minY = m_minY;
181 181 qreal maxY = m_maxY;
182 182
183 183 minX = maxX - dx * rect.right();
184 184 maxX = minX + dx * size.width();
185 185 maxY = minY + dy * rect.bottom();
186 186 minY = maxY - dy * size.height();
187 187
188 188 int tickXCount = m_tickXCount;
189 189 int tickYCount = m_tickYCount;
190 190
191 191 if(m_niceXNumbers) {
192 192 looseNiceNumbers(minX, maxX, tickXCount);
193 193 }
194 194 if(m_niceYNumbers) {
195 195 looseNiceNumbers(minY, maxY, tickYCount);
196 196 }
197 197 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
198 198 }
199 199
200 200 void Domain::move(int dx,int dy,const QSizeF& size)
201 201 {
202 202 qreal x = spanX() / size.width();
203 203 qreal y = spanY() / size.height();
204 204
205 205 qreal maxX = m_maxX;
206 206 qreal minX = m_minX;
207 207 qreal minY = m_minY;
208 208 qreal maxY = m_maxY;
209 209
210 210 if(dx!=0) {
211 211 minX = minX + x * dx;
212 212 maxX = maxX + x * dx;
213 213 }
214 214 if(dy!=0) {
215 215 minY = minY + y * dy;
216 216 maxY = maxY + y * dy;
217 217 }
218 218 setRange(minX,maxX,minY,maxY);
219 219 }
220 220
221 221 void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount,bool niceNumbers)
222 222 {
223 223 if (m_niceXNumbers != niceNumbers) {
224 224 m_niceXNumbers = niceNumbers;
225 225 //force recalculation
226 226 m_minX = 0;
227 227 m_maxX = 0;
228 228 }
229 229 setRange(min,max,m_minY, m_maxY,tickXCount,m_tickYCount);
230 230 }
231 231
232 232 void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount,bool niceNumbers)
233 233 {
234 234 if (m_niceYNumbers != niceNumbers) {
235 235 m_niceYNumbers = niceNumbers;
236 236 //force recalculation
237 237 m_minY = 0;
238 238 m_maxY = 0;
239 239 }
240 240 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickYCount);
241 241 }
242 242
243 243 //algorithm defined by Paul S.Heckbert GraphicalGems I
244 244
245 245 void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
246 246 {
247 247 qreal range = niceNumber(max-min,true); //range with ceiling
248 248 qreal step = niceNumber(range/(ticksCount-1),false);
249 249 min = floor(min/step);
250 250 max = ceil(max/step);
251 251 ticksCount = int(max-min) +1;
252 252 min*=step;
253 253 max*=step;
254 254 }
255 255
256 256 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
257 257
258 258 qreal Domain::niceNumber(qreal x,bool ceiling) const
259 259 {
260 260 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
261 261 qreal q = x/z;//q<10 && q>=1;
262 262
263 263 if(ceiling) {
264 264 if(q <= 1.0) q=1;
265 265 else if(q <= 2.0) q=2;
266 266 else if(q <= 5.0) q=5;
267 267 else q=10;
268 268 }
269 269 else {
270 270 if(q < 1.5) q=1;
271 271 else if(q < 3.0) q=2;
272 272 else if(q < 7.0) q=5;
273 273 else q=10;
274 274 }
275 275 return q*z;
276 276 }
277 277
278 278
279 279 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2)
280 280 {
281 281 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
282 282 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
283 283 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
284 284 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
285 285 }
286 286
287 287
288 288 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2)
289 289 {
290 290 return !(domain1 == domain2);
291 291 }
292 292
293 293
294 294 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain)
295 295 {
296 296 dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')' << domain.m_tickXCount << "," << domain.m_tickYCount ;
297 297 return dbg.maybeSpace();
298 298 }
299 299
300 300 #include "moc_domain_p.cpp"
301 301
302 302 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,508 +1,520
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 "qxyseries.h"
22 22 #include "qxyseries_p.h"
23 23 #include "domain_p.h"
24 24 #include "legendmarker_p.h"
25 25 #include <QAbstractItemModel>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 /*!
30 30 \class QXYSeries
31 31 \brief The QXYSeries class is a base class for line, spline and scatter series.
32 32 */
33 33
34 34 /*!
35 35 \fn QPen QXYSeries::pen() const
36 36 \brief Returns pen used to draw points for series.
37 37 \sa setPen()
38 38 */
39 39
40 40 /*!
41 41 \fn QBrush QXYSeries::brush() const
42 42 \brief Returns brush used to draw points for series.
43 43 \sa setBrush()
44 44 */
45 45
46 46 /*!
47 47 \fn void QXYSeries::clicked(const QPointF& point)
48 48 \brief Signal is emitted when user clicks the \a point on chart.
49 49 */
50 50
51 51
52 52 /*!
53 53 \fn void QXYSeriesPrivate::pointReplaced(int index)
54 54 \brief \internal \a index
55 55 */
56 56
57 57 /*!
58 58 \fn void QXYSeriesPrivate::pointAdded(int index)
59 59 \brief \internal \a index
60 60 */
61 61
62 62 /*!
63 63 \fn void QXYSeriesPrivate::pointRemoved(int index)
64 64 \brief \internal \a index
65 65 */
66 66
67 67 /*!
68 68 \fn void QXYSeriesPrivate::updated()
69 69 \brief \internal
70 70 */
71 71
72 72 /*!
73 73 \internal
74 74
75 75 Constructs empty series object which is a child of \a parent.
76 76 When series object is added to QChartView or QChart instance ownerships is transferred.
77 77 */
78 78 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
79 79 {
80 80
81 81 }
82 82 /*!
83 83 Destroys the object. Series added to QChartView or QChart instances are owned by those,
84 84 and are deleted when mentioned object are destroyed.
85 85 */
86 86 QXYSeries::~QXYSeries()
87 87 {
88 88 }
89 89
90 90 /*!
91 91 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
92 92 */
93 93 void QXYSeries::append(qreal x,qreal y)
94 94 {
95 95 append(QPointF(x,y));
96 96 }
97 97
98 98 /*!
99 99 This is an overloaded function.
100 100 Adds data \a point to the series. Points are connected with lines on the chart.
101 101 */
102 102 void QXYSeries::append(const QPointF &point)
103 103 {
104 104 Q_D(QXYSeries);
105 105 d->m_points<<point;
106 106 emit d->pointAdded(d->m_points.count()-1);
107 107 }
108 108
109 109 /*!
110 110 This is an overloaded function.
111 111 Adds list of data \a points to the series. Points are connected with lines on the chart.
112 112 */
113 113 void QXYSeries::append(const QList<QPointF> &points)
114 114 {
115 115 foreach(const QPointF& point , points) {
116 116 append(point);
117 117 }
118 118 }
119 119
120 120
121 121 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
122 122 {
123 123 replace(QPointF(oldX,oldY),QPointF(newX,newY));
124 124 }
125 125
126 126 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
127 127 {
128 128 Q_D(QXYSeries);
129 129 int index = d->m_points.indexOf(oldPoint);
130 130 if(index==-1) return;
131 131 d->m_points[index] = newPoint;
132 132 emit d->pointReplaced(index);
133 133 }
134 134
135 135 /*!
136 136 Removes current \a x and \a y value.
137 137 */
138 138 void QXYSeries::remove(qreal x,qreal y)
139 139 {
140 140 remove(QPointF(x,y));
141 141 }
142 142
143 143 /*!
144 144 Removes current \a point x value. Note \a point y value is ignored.
145 145 */
146 146 void QXYSeries::remove(const QPointF &point)
147 147 {
148 148 Q_D(QXYSeries);
149 149 int index = d->m_points.indexOf(point);
150 150 if(index==-1) return;
151 151 d->m_points.remove(index);
152 152 emit d->pointRemoved(index);
153 153 }
154 154
155 155 /*!
156 156 Removes all data points from the series.
157 157 */
158 158 void QXYSeries::removeAll()
159 159 {
160 160 Q_D(QXYSeries);
161 161 foreach(const QPointF& point, d->m_points) {
162 162 remove(point);
163 163 }
164 164 }
165 165
166 166 /*!
167 167 \internal \a pos
168 168 */
169 169 QList<QPointF> QXYSeries::points() const
170 170 {
171 171 // Q_ASSERT(false);
172 172 Q_D(const QXYSeries);
173 173 if (d->m_model) {
174 174 QList<QPointF> result;
175 175 if (d->m_mapOrientation == Qt::Vertical){
176 176 // consecutive data is read from model's column
177 177 if (d->m_mapX >= d->m_model->columnCount() || d->m_mapY >= d->m_model->columnCount())
178 178 return result; // mapped columns are not existing
179 179
180 180 for(int i = d->m_mapFirst; i< d->m_mapFirst + count(); ++i) {
181 181 qreal x = d->m_model->data(d->m_model->index(i, d->m_mapX), Qt::DisplayRole).toReal();
182 182 qreal y = d->m_model->data(d->m_model->index(i, d->m_mapY), Qt::DisplayRole).toReal();
183 183 result << QPointF(x,y);
184 184 }
185 185 return result;
186 186 }
187 187 else{
188 188 // consecutive data is read from model's row
189 189 if (d->m_mapX >= d->m_model->rowCount() || d->m_mapY >= d->m_model->rowCount())
190 190 return result; // mapped rows are not existing
191 191
192 192 for(int i = d->m_mapFirst; i< d->m_mapFirst + count(); ++i) {
193 193 qreal x = d->m_model->data(d->m_model->index(d->m_mapX, i), Qt::DisplayRole).toReal();
194 194 qreal y = d->m_model->data(d->m_model->index(d->m_mapY, i), Qt::DisplayRole).toReal();
195 195 result << QPointF(x,y);
196 196 }
197 197 return result;
198 198 }
199 199 } else {
200 200 // model is not specified, return the data from series' internal data store
201 201 return d->m_points.toList();
202 202 }
203 203 }
204 204
205 205 /*!
206 206 Returns number of data points within series.
207 207 */
208 208 int QXYSeries::count() const
209 209 {
210 210 Q_D(const QXYSeries);
211 211
212 212 if (d->m_model) {
213 213 if (d->m_mapOrientation == Qt::Vertical) {
214 214 // data is in a column. Return the number of mapped items if the model's column have enough items
215 215 // or the number of items that can be mapped
216 216 if (d->m_mapX >= d->m_model->columnCount() || d->m_mapY >= d->m_model->columnCount())
217 217 return 0; // mapped columns are not existing
218 218 else if (d->m_mapCount != -1)
219 219 return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0));
220 220 else
221 221 return qMax(d->m_model->rowCount() - d->m_mapFirst, 0);
222 222 } else {
223 223 // data is in a row. Return the number of mapped items if the model's row have enough items
224 224 // or the number of items that can be mapped
225 225 if (d->m_mapX >= d->m_model->rowCount() || d->m_mapY >= d->m_model->rowCount())
226 226 return 0; // mapped rows are not existing
227 227 else if (d->m_mapCount != -1)
228 228 return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0));
229 229 else
230 230 return qMax(d->m_model->columnCount() - d->m_mapFirst, 0);
231 231 }
232 232 }
233 233
234 234 // model is not specified, return the number of points in the series internal data store
235 235 return d->m_points.count();
236 236 }
237 237
238 238
239 239 /*!
240 240 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
241 241 pen from chart theme is used.
242 242 \sa QChart::setTheme()
243 243 */
244 244 void QXYSeries::setPen(const QPen &pen)
245 245 {
246 246 Q_D(QXYSeries);
247 247 if (d->m_pen!=pen) {
248 248 d->m_pen = pen;
249 249 emit d->updated();
250 250 }
251 251 }
252 252
253 253 QPen QXYSeries::pen() const
254 254 {
255 255 Q_D(const QXYSeries);
256 256 return d->m_pen;
257 257 }
258 258
259 259 /*!
260 260 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
261 261 from chart theme setting is used.
262 262 \sa QChart::setTheme()
263 263 */
264 264 void QXYSeries::setBrush(const QBrush &brush)
265 265 {
266 266 Q_D(QXYSeries);
267 267 if (d->m_brush!=brush) {
268 268 d->m_brush = brush;
269 269 emit d->updated();
270 270 }
271 271 }
272 272
273 273 QBrush QXYSeries::brush() const
274 274 {
275 275 Q_D(const QXYSeries);
276 276 return d->m_brush;
277 277 }
278 278
279 279
280 280 /*!
281 281 Sets if data points are \a visible and should be drawn on line.
282 282 */
283 283 void QXYSeries::setPointsVisible(bool visible)
284 284 {
285 285 Q_D(QXYSeries);
286 286 if (d->m_pointsVisible != visible){
287 287 d->m_pointsVisible = visible;
288 288 emit d->updated();
289 289 }
290 290 }
291 291
292 292 /*!
293 293 Returns true if drawing the data points of the series is enabled.
294 294 */
295 295 bool QXYSeries::pointsVisible() const
296 296 {
297 297 Q_D(const QXYSeries);
298 298 return d->m_pointsVisible;
299 299 }
300 300
301 301
302 302 /*!
303 303 Stream operator for adding a data \a point to the series.
304 304 \sa append()
305 305 */
306 306 QXYSeries& QXYSeries::operator<< (const QPointF &point)
307 307 {
308 308 append(point);
309 309 return *this;
310 310 }
311 311
312 312
313 313 /*!
314 314 Stream operator for adding a list of \a points to the series.
315 315 \sa append()
316 316 */
317 317
318 318 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
319 319 {
320 320 append(points);
321 321 return *this;
322 322 }
323 323
324 324 /*!
325 325 \fn bool QXYSeries::setModel(QAbstractItemModel *model)
326 326 Sets the \a model to be used as a data source
327 327 \sa setModelMapping()
328 328 */
329 329 bool QXYSeries::setModel(QAbstractItemModel *model)
330 330 {
331 331 Q_D(QXYSeries);
332 332 // disconnect signals from old model
333 333 if (d->m_model) {
334 334 QObject::disconnect(d->m_model, 0, this, 0);
335 335 d->m_mapX = -1;
336 336 d->m_mapY = -1;
337 337 d->m_mapFirst = 0;
338 338 d->m_mapCount = -1;
339 339 d->m_mapOrientation = Qt::Vertical;
340 340 }
341 341
342 342 // set new model
343 343 if (model) {
344 344 d->m_model = model;
345 345 return true;
346 346 } else {
347 347 d->m_model = 0;
348 348 return false;
349 349 }
350 350 }
351 351
352 352 /*!
353 353 Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used
354 354 as a data source for y coordinate. The \a orientation parameter specifies whether the data
355 355 is in columns or in rows.
356 356 \sa setModel()
357 357 */
358 358 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
359 359 {
360 360 Q_D(QXYSeries);
361 361 if (d->m_model == 0)
362 362 return;
363 363 d->m_mapX = modelX;
364 364 d->m_mapY = modelY;
365 365 d->m_mapOrientation = orientation;
366 366
367 367 // connect the signals from the model
368 368 connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
369 369 // if (d->m_mapOrientation == Qt::Vertical) {
370 370 connect(d->m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
371 371 connect(d->m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
372 372 // } else {
373 373 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
374 374 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
375 375 // }
376 376 }
377 377
378 378 void QXYSeries::setModelMappingRange(int first, int count)
379 379 {
380 380 Q_D(QXYSeries);
381 381 d->m_mapFirst = qMax(first, 0);
382 382 d->m_mapCount = qMax(count, -1);
383 383 emit d->reinitialized();
384 384 }
385 385
386 386 int QXYSeries::mapX() const
387 387 {
388 388 Q_D(const QXYSeries);
389 389 return d->m_mapX;
390 390 }
391 391
392 392 int QXYSeries::mapY() const
393 393 {
394 394 Q_D(const QXYSeries);
395 395 return d->m_mapY;
396 396
397 397 }
398 398
399 399 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
400 400
401 401
402 402 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q),
403 403 m_mapX(-1),
404 404 m_mapY(-1),
405 405 m_pointsVisible(false)
406 406 {
407 407 }
408 408
409 409 void QXYSeriesPrivate::scaleDomain(Domain& domain)
410 410 {
411 411 qreal minX(domain.minX());
412 412 qreal minY(domain.minY());
413 413 qreal maxX(domain.maxX());
414 414 qreal maxY(domain.maxY());
415 415 int tickXCount(domain.tickXCount());
416 416 int tickYCount(domain.tickYCount());
417 417
418 418 Q_Q(QXYSeries);
419 419
420 420 const QList<QPointF>& points = q->points();
421 421
422 if(points.isEmpty()){
423 minX=0.0;
424 minY=0.0;
425 maxX=1.0;
426 maxY=1.0;
427 }
422 // if(points.isEmpty()){
423 // minX=0.0;
424 // minY=0.0;
425 // maxX=1.0;
426 // maxY=1.0;
427 // }
428 428
429 for (int i = 0; i < points.count(); i++)
430 {
431 qreal x = points[i].x();
432 qreal y = points[i].y();
433 minX = qMin(minX, x);
434 minY = qMin(minY, y);
435 maxX = qMax(maxX, x);
436 maxY = qMax(maxY, y);
437 }
429 // for (int i = 0; i < points.count(); i++)
430 // {
431 // qreal x = points[i].x();
432 // qreal y = points[i].y();
433 // minX = qMin(minX, x);
434 // minY = qMin(minY, y);
435 // maxX = qMax(maxX, x);
436 // maxY = qMax(maxY, y);
437 // }
438 438
439 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
439 // domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
440
441 if (!points.isEmpty()) {
442 for (int i = 0; i < points.count(); i++) {
443 qreal x = points[i].x();
444 qreal y = points[i].y();
445 minX = qMin(minX, x);
446 minY = qMin(minY, y);
447 maxX = qMax(maxX, x);
448 maxY = qMax(maxY, y);
449 }
450 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
451 }
440 452 }
441 453
442 454 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
443 455 {
444 456 Q_Q(QXYSeries);
445 457 QList<LegendMarker*> list;
446 458 return list << new XYLegendMarker(q,legend);
447 459 }
448 460
449 461 void QXYSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
450 462 {
451 463 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
452 464 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
453 465 if (m_mapOrientation == Qt::Vertical) {
454 466 if ((column == m_mapX || column == m_mapY) // modified item is in a mapped column
455 467 && row >= m_mapFirst // modfied item in not before first item
456 468 && (m_mapCount == -1 || row < m_mapFirst + m_mapCount)) // map is not limited or item lays before the end of map
457 469 emit pointReplaced(row - m_mapFirst);
458 470 } else {
459 471 if ((row == m_mapX || row == m_mapY) // modified item is in a mapped row
460 472 && column >= m_mapFirst // modfied item in not before first item
461 473 && (m_mapCount == -1 || column < m_mapFirst + m_mapCount)) // map is not limited or item lays before the end of map
462 474 emit pointReplaced(column - m_mapFirst);
463 475 }
464 476 }
465 477 }
466 478 }
467 479
468 480
469 481 void QXYSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
470 482 {
471 483 Q_UNUSED(parent);
472 484 if (m_mapOrientation == Qt::Vertical)
473 485 emit pointsAdded(start, end);
474 486 else if (start <= m_mapX || start <= m_mapY)
475 487 emit reinitialized();
476 488 }
477 489
478 490 void QXYSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
479 491 {
480 492 Q_UNUSED(parent);
481 493 if (m_mapOrientation == Qt::Vertical)
482 494 emit pointsRemoved(start, end);
483 495 else if (start <= m_mapX || start <= m_mapY)
484 496 emit reinitialized();
485 497 }
486 498
487 499 void QXYSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
488 500 {
489 501 Q_UNUSED(parent);
490 502 if (m_mapOrientation == Qt::Horizontal)
491 503 emit pointsAdded(start, end);
492 504 else if (start <= m_mapX || start <= m_mapY)
493 505 emit reinitialized();
494 506 }
495 507
496 508 void QXYSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
497 509 {
498 510 Q_UNUSED(parent);
499 511 if (m_mapOrientation == Qt::Horizontal)
500 512 emit pointsRemoved(start, end);
501 513 else if (start <= m_mapX || start <= m_mapY)
502 514 emit reinitialized();
503 515 }
504 516
505 517 #include "moc_qxyseries.cpp"
506 518 #include "moc_qxyseries_p.cpp"
507 519
508 520 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now