##// 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
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
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 CURRENTLY_BUILDING_COMPONENTS = "demos"
1 CURRENTLY_BUILDING_COMPONENTS = "demos"
2 !include( ../config.pri ) {
2 !include( ../config.pri ) {
3 error( "Couldn't find the config.pri file!" )
3 error( "Couldn't find the config.pri file!" )
4 }
4 }
5
5
6 TEMPLATE = subdirs
6 TEMPLATE = subdirs
7 SUBDIRS += chartthemes \
7 SUBDIRS += chartthemes \
8 piechartcustomization \
8 piechartcustomization \
9 dynamicspline \
9 qmlchart \
10 qmlchart \
10 dynamicspline
11 qmlweather
@@ -1,58 +1,34
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVE_AXIS_H
21 #include <QApplication>
22 #define DECLARATIVE_AXIS_H
22 #include "qmlapplicationviewer.h"
23
23
24 #include "qchartglobal.h"
24 Q_DECL_EXPORT int main(int argc, char *argv[])
25 #include <QAxis>
26 #include <QDeclarativeParserStatus>
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 class DeclarativeAxis: public QAxis, public QDeclarativeParserStatus
31 {
25 {
32 Q_INTERFACES(QDeclarativeParserStatus)
26 QScopedPointer<QApplication> app(createApplication(argc, argv));
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 };
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 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativechart.h"
21 #include "declarativechart.h"
22 #include "declarativepieseries.h"
23 #include <QPainter>
22 #include <QPainter>
24
23
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
25
27 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
28 : QDeclarativeItem(parent),
27 : QDeclarativeItem(parent),
29 m_chart(new QChart(this)),
28 m_chart(new QChart(this)),
30 m_legend(LegendDisabled)
29 m_legend(LegendDisabled)
31 {
30 {
32 setFlag(QGraphicsItem::ItemHasNoContents, false);
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
32 m_chart->axisX()->setNiceNumbersEnabled(false);
33 }
33 }
34
34
35 DeclarativeChart::~DeclarativeChart()
35 DeclarativeChart::~DeclarativeChart()
36 {
36 {
37 delete m_chart;
37 delete m_chart;
38 }
38 }
39
39
40 void DeclarativeChart::childEvent(QChildEvent *event)
40 void DeclarativeChart::childEvent(QChildEvent *event)
41 {
41 {
42 if (event->type() == QEvent::ChildAdded) {
42 if (event->type() == QEvent::ChildAdded) {
43 if (qobject_cast<QAbstractSeries *>(event->child())) {
43 if (qobject_cast<QAbstractSeries *>(event->child())) {
44 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
44 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
45 }
45 }
46 }
46 }
47 }
47 }
48
48
49 void DeclarativeChart::componentComplete()
49 void DeclarativeChart::componentComplete()
50 {
50 {
51 // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max();
51 foreach(QObject *child, children()) {
52 foreach(QObject *child, children()) {
52 if (qobject_cast<QAbstractSeries *>(child)) {
53 if (qobject_cast<QAbstractSeries *>(child)) {
53 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
54 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
54 }
55 }
55 }
56 }
57 // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max();
56
58
57 QDeclarativeItem::componentComplete();
59 QDeclarativeItem::componentComplete();
58 }
60 }
59
61
60 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
62 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
61 {
63 {
64 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
62 Q_UNUSED(oldGeometry)
65 Q_UNUSED(oldGeometry)
63
66
64 if (newGeometry.isValid()) {
67 if (newGeometry.isValid()) {
65 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
68 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
66 m_chart->resize(newGeometry.width(), newGeometry.height());
69 m_chart->resize(newGeometry.width(), newGeometry.height());
67 }
70 }
68 }
71 }
69 }
72 }
70
73
71 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
74 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
72 {
75 {
73 Q_UNUSED(option)
76 Q_UNUSED(option)
74 Q_UNUSED(widget)
77 Q_UNUSED(widget)
75
78
76 // TODO: optimized?
79 // TODO: optimized?
77 painter->setRenderHint(QPainter::Antialiasing, true);
80 painter->setRenderHint(QPainter::Antialiasing, true);
78 }
81 }
79
82
80 void DeclarativeChart::setAnimationOptions(QChart::AnimationOption animations)
83 void DeclarativeChart::setAnimationOptions(QChart::AnimationOption animations)
81 {
84 {
82 m_chart->setAnimationOptions(animations);
85 m_chart->setAnimationOptions(animations);
83 }
86 }
84
87
85 QChart::AnimationOption DeclarativeChart::animationOptions()
88 QChart::AnimationOption DeclarativeChart::animationOptions()
86 {
89 {
87 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
90 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
88 return QChart::AllAnimations;
91 return QChart::AllAnimations;
89 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
92 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
90 return QChart::GridAxisAnimations;
93 return QChart::GridAxisAnimations;
91 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
94 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
92 return QChart::SeriesAnimations;
95 return QChart::SeriesAnimations;
93 else
96 else
94 return QChart::NoAnimation;
97 return QChart::NoAnimation;
95 }
98 }
96
99
97 void DeclarativeChart::setLegend(ChartLegend legend)
100 void DeclarativeChart::setLegend(ChartLegend legend)
98 {
101 {
99 if (legend != m_legend) {
102 if (legend != m_legend) {
100 m_legend = legend;
103 m_legend = legend;
101 switch (m_legend) {
104 switch (m_legend) {
102 case LegendDisabled:
105 case LegendDisabled:
103 m_chart->legend()->setVisible(false);
106 m_chart->legend()->setVisible(false);
104 break;
107 break;
105 case LegendTop:
108 case LegendTop:
106 m_chart->legend()->setVisible(true);
109 m_chart->legend()->setVisible(true);
107 m_chart->legend()->setAlignment(QLegend::AlignmentTop);
110 m_chart->legend()->setAlignment(QLegend::AlignmentTop);
108 break;
111 break;
109 case LegendBottom:
112 case LegendBottom:
110 m_chart->legend()->setVisible(true);
113 m_chart->legend()->setVisible(true);
111 m_chart->legend()->setAlignment(QLegend::AlignmentBottom);
114 m_chart->legend()->setAlignment(QLegend::AlignmentBottom);
112 break;
115 break;
113 case LegendLeft:
116 case LegendLeft:
114 m_chart->legend()->setVisible(true);
117 m_chart->legend()->setVisible(true);
115 m_chart->legend()->setAlignment(QLegend::AlignmentLeft);
118 m_chart->legend()->setAlignment(QLegend::AlignmentLeft);
116 break;
119 break;
117 case LegendRight:
120 case LegendRight:
118 m_chart->legend()->setVisible(true);
121 m_chart->legend()->setVisible(true);
119 m_chart->legend()->setAlignment(QLegend::AlignmentRight);
122 m_chart->legend()->setAlignment(QLegend::AlignmentRight);
120 break;
123 break;
121 default:
124 default:
122 m_chart->legend()->setVisible(false);
125 m_chart->legend()->setVisible(false);
123 break;
126 break;
124 }
127 }
125 }
128 }
126 }
129 }
127
130
128 DeclarativeChart::ChartLegend DeclarativeChart::legend()
131 DeclarativeChart::ChartLegend DeclarativeChart::legend()
129 {
132 {
130 return m_legend;
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 #include "moc_declarativechart.cpp"
146 #include "moc_declarativechart.cpp"
134
147
135 QTCOMMERCIALCHART_END_NAMESPACE
148 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,80 +1,85
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVECHART_H
21 #ifndef DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
23
23
24 #include <QtCore/QtGlobal>
24 #include <QtCore/QtGlobal>
25 #include <QDeclarativeItem>
25 #include <QDeclarativeItem>
26 #include <qchart.h>
26 #include <qchart.h>
27 #include <QAxis>
27
28
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30
30 // TODO: Derive from QChart for easier definition of properties?
31 // TODO: Derive from QChart for easier definition of properties?
31 class DeclarativeChart : public QDeclarativeItem
32 class DeclarativeChart : public QDeclarativeItem
32 // TODO: for QTQUICK2: extend QQuickPainterItem instead
33 // TODO: for QTQUICK2: extend QQuickPainterItem instead
33 //class DeclarativeChart : public QQuickPaintedItem, public Chart
34 //class DeclarativeChart : public QQuickPaintedItem, public Chart
34 {
35 {
35 Q_OBJECT
36 Q_OBJECT
36 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
37 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
37 Q_PROPERTY(QChart::AnimationOption animationOptions READ animationOptions WRITE setAnimationOptions)
38 Q_PROPERTY(QChart::AnimationOption animationOptions READ animationOptions WRITE setAnimationOptions)
38 Q_PROPERTY(QString title READ title WRITE setTitle)
39 Q_PROPERTY(QString title READ title WRITE setTitle)
39 Q_PROPERTY(ChartLegend legend READ legend WRITE setLegend)
40 Q_PROPERTY(ChartLegend legend READ legend WRITE setLegend)
41 Q_PROPERTY(QAxis *axisX READ axisX)
42 Q_PROPERTY(QAxis *axisY READ axisY)
40 Q_ENUMS(ChartLegend)
43 Q_ENUMS(ChartLegend)
41
44
42 public:
45 public:
43 enum ChartLegend {
46 enum ChartLegend {
44 LegendDisabled = 0,
47 LegendDisabled = 0,
45 LegendTop,
48 LegendTop,
46 LegendBottom,
49 LegendBottom,
47 LegendLeft,
50 LegendLeft,
48 LegendRight
51 LegendRight
49 };
52 };
50
53
51 public:
54 public:
52 DeclarativeChart(QDeclarativeItem *parent = 0);
55 DeclarativeChart(QDeclarativeItem *parent = 0);
53 ~DeclarativeChart();
56 ~DeclarativeChart();
54
57
55 public: // From QDeclarativeItem/QGraphicsItem
58 public: // From QDeclarativeItem/QGraphicsItem
56 void childEvent(QChildEvent *event);
59 void childEvent(QChildEvent *event);
57 void componentComplete();
60 void componentComplete();
58 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
61 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
59 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
62 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
60
63
61 public:
64 public:
62 void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);}
65 void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);}
63 QChart::ChartTheme theme() {return m_chart->theme();}
66 QChart::ChartTheme theme() {return m_chart->theme();}
64 void setAnimationOptions(QChart::AnimationOption animations);
67 void setAnimationOptions(QChart::AnimationOption animations);
65 QChart::AnimationOption animationOptions();
68 QChart::AnimationOption animationOptions();
66 void setTitle(QString title) {m_chart->setTitle(title);}
69 void setTitle(QString title) {m_chart->setTitle(title);}
67 QString title() { return m_chart->title();}
70 QString title() { return m_chart->title();}
68 void setLegend(ChartLegend legend);
71 void setLegend(ChartLegend legend);
69 ChartLegend legend();
72 ChartLegend legend();
73 QAxis *axisX();
74 QAxis *axisY();
70
75
71 public:
76 public:
72 // Extending QChart with DeclarativeChart is not possible because QObject does not support
77 // Extending QChart with DeclarativeChart is not possible because QObject does not support
73 // multi inheritance, so we now have a QChart as a member instead
78 // multi inheritance, so we now have a QChart as a member instead
74 QChart *m_chart;
79 QChart *m_chart;
75 ChartLegend m_legend;
80 ChartLegend m_legend;
76 };
81 };
77
82
78 QTCOMMERCIALCHART_END_NAMESPACE
83 QTCOMMERCIALCHART_END_NAMESPACE
79
84
80 #endif // DECLARATIVECHART_H
85 #endif // DECLARATIVECHART_H
@@ -1,40 +1,35
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativelineseries.h"
21 #include "declarativelineseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qlineseries.h"
24 #include "qlineseries.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
28 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
29 QLineSeries(parent)
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 #include "moc_declarativelineseries.cpp"
33 #include "moc_declarativelineseries.cpp"
39
34
40 QTCOMMERCIALCHART_END_NAMESPACE
35 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,45 +1,42
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVELINESERIES_H
21 #ifndef DECLARATIVELINESERIES_H
22 #define DECLARATIVELINESERIES_H
22 #define DECLARATIVELINESERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qlineseries.h"
25 #include "qlineseries.h"
26 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
27 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
31 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(DeclarativeXyModel *model READ declarativeModel WRITE setDeclarativeModel)
35
35
36 public:
36 public:
37 explicit DeclarativeLineSeries(QObject *parent = 0);
37 explicit DeclarativeLineSeries(QObject *parent = 0);
38
39 public:
40 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 };
38 };
42
39
43 QTCOMMERCIALCHART_END_NAMESPACE
40 QTCOMMERCIALCHART_END_NAMESPACE
44
41
45 #endif // DECLARATIVELINESERIES_H
42 #endif // DECLARATIVELINESERIES_H
@@ -1,89 +1,141
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativepiemodel.h"
21 #include "declarativemodel.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
24 #include <qdeclarativelist.h>
22 #include <qdeclarativelist.h>
23 #include <QDebug>
25
24
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
26
28 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
27 ////////////// XY model ///////////////////////
28
29 DeclarativeXyModel::DeclarativeXyModel(QObject *parent) :
29 ChartTableModel(parent)
30 ChartTableModel(parent)
30 {
31 {
31 }
32 }
32
33
33 //void DeclarativePieModel::classBegin()
34 void DeclarativeXyModel::append(DeclarativeXyPoint* point)
34 //{
35 {
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()
45 void DeclarativeXyModel::append(QVariantList points)
38 //{
46 {
39 //}
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 void DeclarativePieModel::append(QPieSlice* slice)
92 void DeclarativePieModel::append(QPieSlice* slice)
42 {
93 {
43 // TODO: label not working...
44 qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value();
94 qDebug() << "DeclarativePieModel::append:" << slice->label() << " " << slice->value();
45 qDebug() << "rowCount:" << rowCount();
95 qDebug() << "rowCount:" << rowCount();
46 qDebug() << "coolCount:" << columnCount();
96 qDebug() << "coolCount:" << columnCount();
47 insertRow(rowCount());
97 insertRow(rowCount());
48 qDebug() << "new rowCount:" << rowCount();
98 qDebug() << "new rowCount:" << rowCount();
49
99
50 qDebug() << setData(createIndex(rowCount() - 1, 0), slice->value());
100 qDebug() << setData(createIndex(rowCount() - 1, 0), slice->value());
51 qDebug() << setData(createIndex(rowCount() - 1, 1), slice->label());
101 qDebug() << setData(createIndex(rowCount() - 1, 1), slice->label());
52 }
102 }
53
103
54 void DeclarativePieModel::append(QVariantList slices)
104 void DeclarativePieModel::append(QVariantList slices)
55 {
105 {
56 qDebug() << "append:" << slices;
106 qDebug() << "append:" << slices;
57 QString label = "";
107 QString label = "";
58 for (int i(0); i < slices.count(); i++) {
108 for (int i(0); i < slices.count(); i++) {
59 if (i % 2) {
109 if (i % 2) {
60 bool ok(false);
110 bool ok(false);
61 qreal value = slices.at(i).toReal(&ok);
111 qreal value = slices.at(i).toReal(&ok);
62 if (ok) {
112 if (ok) {
63 QPieSlice *slice = new QPieSlice(value, label);
113 QPieSlice *slice = new QPieSlice(value, label);
64 append(slice);
114 append(slice);
115 } else {
116 qWarning() << "Illegal slice item";
65 }
117 }
66 } else {
118 } else {
67 label = slices.at(i).toString();
119 label = slices.at(i).toString();
68 }
120 }
69 }
121 }
70 }
122 }
71
123
72 QDeclarativeListProperty<QPieSlice> DeclarativePieModel::slices()
124 QDeclarativeListProperty<QPieSlice> DeclarativePieModel::slices()
73 {
125 {
74 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieModel::appendSlice);
126 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieModel::appendSlice);
75 }
127 }
76
128
77 void DeclarativePieModel::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
129 void DeclarativePieModel::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
78 QPieSlice *slice)
130 QPieSlice *slice)
79 {
131 {
80 DeclarativePieModel *pieModel = qobject_cast<DeclarativePieModel *>(list->object);
132 DeclarativePieModel *pieModel = qobject_cast<DeclarativePieModel *>(list->object);
81 if (pieModel)
133 if (pieModel)
82 pieModel->append(slice);
134 pieModel->append(slice);
83 else
135 else
84 qWarning() << "Illegal slice item";
136 qWarning() << "Illegal slice item";
85 }
137 }
86
138
87 #include "moc_declarativepiemodel.cpp"
139 #include "moc_declarativemodel.cpp"
88
140
89 QTCOMMERCIALCHART_END_NAMESPACE
141 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,61 +1,70
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVEPIEMODEL_H
21 #ifndef DECLARATIVEMODEL_H
22 #define DECLARATIVEPIEMODEL_H
22 #define DECLARATIVEMODEL_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "declarativexypoint.h"
25 #include "qpieslice.h"
26 #include "qpieslice.h"
26 #include "qpieseries.h"
27 #include "../src/charttablemodel.h" // TODO
27 #include "../src/charttablemodel.h"
28 #include <QDeclarativeParserStatus>
29 #include <QDeclarativeListProperty>
28 #include <QDeclarativeListProperty>
30 #include <QAbstractItemModel>
31 #include <QVariant>
29 #include <QVariant>
32
30
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
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 Q_OBJECT
53 Q_OBJECT
39 Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices)
54 Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices)
40 Q_CLASSINFO("DefaultProperty", "slices")
55 Q_CLASSINFO("DefaultProperty", "slices")
41
56
42 public:
57 public:
43 explicit DeclarativePieModel(QObject *parent = 0);
58 explicit DeclarativePieModel(QObject *parent = 0);
44 QDeclarativeListProperty<QPieSlice> slices();
59 QDeclarativeListProperty<QPieSlice> slices();
45
60
46 //public: // from QDeclarativeParserStatus
47 // virtual void classBegin();
48 // virtual void componentComplete();
49
50 public Q_SLOTS:
61 public Q_SLOTS:
51 void append(QPieSlice* slice);
62 void append(QPieSlice* slice);
52 void append(QVariantList slices);
63 void append(QVariantList slices);
53 static void appendSlice(QDeclarativeListProperty<QPieSlice> *list,
64 static void appendSlice(QDeclarativeListProperty<QPieSlice> *list,
54 QPieSlice *element);
65 QPieSlice *element);
55
56 public:
57 };
66 };
58
67
59 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
60
69
61 #endif // DECLARATIVEPIEMODEL_H
70 #endif // DECLARATIVEMODEL_H
@@ -1,51 +1,53
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativepieseries.h"
21 #include "declarativepieseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include <qdeclarativelist.h>
24 #include <qdeclarativelist.h>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
28 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
29 QPieSeries(parent)
29 QPieSeries(parent)
30 {
30 {
31 }
31 }
32
32
33 bool DeclarativePieSeries::setPieModel(DeclarativePieModel *model)
33 bool DeclarativePieSeries::setPieModel(DeclarativePieModel *model)
34 {
34 {
35 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
35 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
36 bool value(false);
36 bool value(false);
37 if (m) {
37 if (m) {
38 value = QPieSeries::setModel(m);
38 value = QPieSeries::setModel(m);
39 setModelMapping(0, 1, Qt::Vertical);
39 setModelMapping(0, 1, Qt::Vertical);
40 } else {
41 qWarning("DeclarativePieSeries: Illegal model");
40 }
42 }
41 return value;
43 return value;
42 }
44 }
43
45
44 DeclarativePieModel *DeclarativePieSeries::pieModel()
46 DeclarativePieModel *DeclarativePieSeries::pieModel()
45 {
47 {
46 return qobject_cast<DeclarativePieModel *>(model());
48 return qobject_cast<DeclarativePieModel *>(model());
47 }
49 }
48
50
49 #include "moc_declarativepieseries.cpp"
51 #include "moc_declarativepieseries.cpp"
50
52
51 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,53 +1,53
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVEPIESERIES_H
21 #ifndef DECLARATIVEPIESERIES_H
22 #define DECLARATIVEPIESERIES_H
22 #define DECLARATIVEPIESERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qpieslice.h"
25 #include "qpieslice.h"
26 #include "qpieseries.h"
26 #include "qpieseries.h"
27 #include <QDeclarativeListProperty>
27 #include <QDeclarativeListProperty>
28 #include <QAbstractItemModel>
28 #include <QAbstractItemModel>
29 #include <QVariant>
29 #include <QVariant>
30 #include "declarativepiemodel.h"
30 #include "declarativemodel.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 class QChart;
34 class QChart;
35
35
36 class DeclarativePieSeries : public QPieSeries
36 class DeclarativePieSeries : public QPieSeries
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39 Q_PROPERTY(DeclarativePieModel *model READ pieModel WRITE setPieModel)
39 Q_PROPERTY(DeclarativePieModel *model READ pieModel WRITE setPieModel)
40
40
41 public:
41 public:
42 explicit DeclarativePieSeries(QObject *parent = 0);
42 explicit DeclarativePieSeries(QObject *parent = 0);
43
43
44 public Q_SLOTS:
44 public Q_SLOTS:
45
45
46 public:
46 public:
47 bool setPieModel(DeclarativePieModel *model);
47 bool setPieModel(DeclarativePieModel *model);
48 DeclarativePieModel *pieModel();
48 DeclarativePieModel *pieModel();
49 };
49 };
50
50
51 QTCOMMERCIALCHART_END_NAMESPACE
51 QTCOMMERCIALCHART_END_NAMESPACE
52
52
53 #endif // DECLARATIVEPIESERIES_H
53 #endif // DECLARATIVEPIESERIES_H
@@ -1,40 +1,35
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativescatterseries.h"
21 #include "declarativescatterseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qscatterseries.h"
24 #include "qscatterseries.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
28 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
29 QScatterSeries(parent)
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 #include "moc_declarativescatterseries.cpp"
33 #include "moc_declarativescatterseries.cpp"
39
34
40 QTCOMMERCIALCHART_END_NAMESPACE
35 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,45 +1,42
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVESCATTERSERIES_H
21 #ifndef DECLARATIVESCATTERSERIES_H
22 #define DECLARATIVESCATTERSERIES_H
22 #define DECLARATIVESCATTERSERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qscatterseries.h"
25 #include "qscatterseries.h"
26 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
27 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
31 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(DeclarativeXyModel *model READ declarativeModel WRITE setDeclarativeModel)
35
35
36 public:
36 public:
37 explicit DeclarativeScatterSeries(QObject *parent = 0);
37 explicit DeclarativeScatterSeries(QObject *parent = 0);
38
39 public:
40 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 };
38 };
42
39
43 QTCOMMERCIALCHART_END_NAMESPACE
40 QTCOMMERCIALCHART_END_NAMESPACE
44
41
45 #endif // DECLARATIVESCATTERSERIES_H
42 #endif // DECLARATIVESCATTERSERIES_H
@@ -1,39 +1,34
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativesplineseries.h"
21 #include "declarativesplineseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
27 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
28 QSplineSeries(parent)
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 #include "moc_declarativesplineseries.cpp"
32 #include "moc_declarativesplineseries.cpp"
38
33
39 QTCOMMERCIALCHART_END_NAMESPACE
34 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,45 +1,42
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVESPLINESERIES_H
21 #ifndef DECLARATIVESPLINESERIES_H
22 #define DECLARATIVESPLINESERIES_H
22 #define DECLARATIVESPLINESERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qsplineseries.h"
25 #include "qsplineseries.h"
26 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
27 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
31 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(DeclarativeXyModel *model READ declarativeModel WRITE setDeclarativeModel)
35
35
36 public:
36 public:
37 explicit DeclarativeSplineSeries(QObject *parent = 0);
37 explicit DeclarativeSplineSeries(QObject *parent = 0);
38
39 public:
40 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 };
38 };
42
39
43 QTCOMMERCIALCHART_END_NAMESPACE
40 QTCOMMERCIALCHART_END_NAMESPACE
44
41
45 #endif // DECLARATIVESPLINESERIES_H
42 #endif // DECLARATIVESPLINESERIES_H
@@ -1,44 +1,59
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 //#include "DeclarativeXySeries.h"
21 //#include "DeclarativeXySeries.h"
22 #include "declarativexyseries.h"
22 #include "declarativexyseries.h"
23 #include "qxyseries.h"
23 #include "qxyseries.h"
24 #include "declarativechart.h"
24 #include "declarativechart.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 DeclarativeXySeries::DeclarativeXySeries()
28 DeclarativeXySeries::DeclarativeXySeries()
29 {
29 {
30 }
30 }
31
31
32 DeclarativeXySeries::~DeclarativeXySeries()
32 DeclarativeXySeries::~DeclarativeXySeries()
33 {
33 {
34 }
34 }
35
35
36 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
36 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeXyModel *model)
37 DeclarativeXyPoint *element)
38 {
37 {
39 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
38 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
40 if (series)
39 bool value(false);
41 series->append(element->x(), element->y());
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 QTCOMMERCIALCHART_END_NAMESPACE
59 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,51 +1,48
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVE_XY_SERIES_H
21 #ifndef DECLARATIVE_XY_SERIES_H
22 #define DECLARATIVE_XY_SERIES_H
22 #define DECLARATIVE_XY_SERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "declarativexypoint.h"
25 #include "declarativexypoint.h"
26 #include <QDeclarativeListProperty>
26 #include "declarativemodel.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 class QChart;
30 class QChart;
31 class QAbstractSeries;
31 class QAbstractSeries;
32
32
33 class DeclarativeXySeries
33 class DeclarativeXySeries
34 {
34 {
35 Q_INTERFACES(QDeclarativeParserStatus)
35 Q_INTERFACES(QDeclarativeParserStatus)
36
36
37 public:
37 public:
38 explicit DeclarativeXySeries();
38 explicit DeclarativeXySeries();
39 ~DeclarativeXySeries();
39 ~DeclarativeXySeries();
40
40
41 public:
41 public:
42 virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0;
42 bool setDeclarativeModel(DeclarativeXyModel *model);
43
43 DeclarativeXyModel *declarativeModel();
44 public Q_SLOTS:
45 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
46 DeclarativeXyPoint *element);
47 };
44 };
48
45
49 QTCOMMERCIALCHART_END_NAMESPACE
46 QTCOMMERCIALCHART_END_NAMESPACE
50
47
51 #endif // DECLARATIVE_XY_SERIES_H
48 #endif // DECLARATIVE_XY_SERIES_H
@@ -1,66 +1,69
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 #include <QtDeclarative/qdeclarative.h>
22 #include <QtDeclarative/qdeclarative.h>
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qaxiscategories.h"
24 #include "declarativechart.h"
25 #include "declarativechart.h"
25 #include "declarativeaxis.h"
26 #include "declarativexypoint.h"
26 #include "declarativexypoint.h"
27 #include "declarativelineseries.h"
27 #include "declarativelineseries.h"
28 #include "declarativesplineseries.h"
28 #include "declarativesplineseries.h"
29 #include "declarativeareaseries.h"
29 #include "declarativeareaseries.h"
30 #include "declarativescatterseries.h"
30 #include "declarativescatterseries.h"
31 #include "declarativebarseries.h"
31 #include "declarativebarseries.h"
32 #include "declarativepieseries.h"
32 #include "declarativepieseries.h"
33 #include "declarativepiemodel.h"
33 //#include "declarativepiemodel.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
37 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
38 {
38 {
39 Q_OBJECT
39 Q_OBJECT
40 public:
40 public:
41 virtual void registerTypes(const char *uri)
41 virtual void registerTypes(const char *uri)
42 {
42 {
43 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
43 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
44
44
45 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
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 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
49 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
48 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
50 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
49 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
51 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
50 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
52 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
51 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
53 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
52 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
54 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
53 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
55 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
54 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
56 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
55 // TODO: a declarative model for each type
57 // TODO: a declarative model for each type
56 qmlRegisterType<DeclarativePieModel>(uri, 1, 0, "PieModel");
58 qmlRegisterType<DeclarativePieModel>(uri, 1, 0, "PieModel");
59 qmlRegisterType<DeclarativeXyModel>(uri, 1, 0, "XYModel");
57 }
60 }
58 };
61 };
59
62
60 #include "plugin.moc"
63 #include "plugin.moc"
61
64
62 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
63
66
64 QTCOMMERCIALCHART_USE_NAMESPACE
67 QTCOMMERCIALCHART_USE_NAMESPACE
65
68
66 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
69 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,56 +1,54
1 TEMPLATE = lib
1 TEMPLATE = lib
2 TARGET = qtcommercialchartqml
2 TARGET = qtcommercialchartqml
3 CONFIG += qt plugin
3 CONFIG += qt plugin
4 QT += declarative
4 QT += declarative
5
5
6 !include( ../config.pri ) {
6 !include( ../config.pri ) {
7 error( "Couldn't find the config.pri file!" )
7 error( "Couldn't find the config.pri file!" )
8 }
8 }
9
9
10 DESTDIR = $$CHART_BUILD_PLUGIN_DIR
10 DESTDIR = $$CHART_BUILD_PLUGIN_DIR
11 contains(QT_MAJOR_VERSION, 5) {
11 contains(QT_MAJOR_VERSION, 5) {
12 # TODO: QtQuick2 not supported by the implementation currently
12 # TODO: QtQuick2 not supported by the implementation currently
13 DEFINES += QTQUICK2
13 DEFINES += QTQUICK2
14 }
14 }
15
15
16 OBJECTS_DIR = $$CHART_BUILD_DIR/plugin
16 OBJECTS_DIR = $$CHART_BUILD_DIR/plugin
17 MOC_DIR = $$CHART_BUILD_DIR/plugin
17 MOC_DIR = $$CHART_BUILD_DIR/plugin
18 UI_DIR = $$CHART_BUILD_DIR/plugin
18 UI_DIR = $$CHART_BUILD_DIR/plugin
19 RCC_DIR = $$CHART_BUILD_DIR/plugin
19 RCC_DIR = $$CHART_BUILD_DIR/plugin
20
20
21 SOURCES += \
21 SOURCES += \
22 plugin.cpp \
22 plugin.cpp \
23 declarativechart.cpp \
23 declarativechart.cpp \
24 declarativeaxis.cpp \
25 declarativexypoint.cpp \
24 declarativexypoint.cpp \
26 declarativexyseries.cpp \
25 declarativexyseries.cpp \
27 declarativelineseries.cpp \
26 declarativelineseries.cpp \
28 declarativesplineseries.cpp \
27 declarativesplineseries.cpp \
29 declarativeareaseries.cpp \
28 declarativeareaseries.cpp \
30 declarativescatterseries.cpp \
29 declarativescatterseries.cpp \
31 declarativepieseries.cpp \
30 declarativepieseries.cpp \
32 declarativebarseries.cpp \
31 declarativebarseries.cpp \
33 declarativepiemodel.cpp
32 declarativemodel.cpp
34 HEADERS += \
33 HEADERS += \
35 declarativechart.h \
34 declarativechart.h \
36 declarativeaxis.h \
37 declarativexypoint.h \
35 declarativexypoint.h \
38 declarativexyseries.h \
36 declarativexyseries.h \
39 declarativelineseries.h \
37 declarativelineseries.h \
40 declarativesplineseries.h \
38 declarativesplineseries.h \
41 declarativeareaseries.h \
39 declarativeareaseries.h \
42 declarativescatterseries.h \
40 declarativescatterseries.h \
43 declarativepieseries.h \
41 declarativepieseries.h \
44 declarativebarseries.h \
42 declarativebarseries.h \
45 declarativepiemodel.h
43 declarativemodel.h
46
44
47 TARGETPATH = QtCommercial/Chart
45 TARGETPATH = QtCommercial/Chart
48 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
46 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
49 qmldir.files += $$PWD/qmldir
47 qmldir.files += $$PWD/qmldir
50 qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
48 qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
51 INSTALLS += target qmldir
49 INSTALLS += target qmldir
52
50
53 FILE = $$PWD/qmldir
51 FILE = $$PWD/qmldir
54 win32:{FILE = $$replace(FILE, "/","\\")}
52 win32:{FILE = $$replace(FILE, "/","\\")}
55 QMAKE_POST_LINK += $$QMAKE_COPY $$FILE $$CHART_BUILD_PLUGIN_DIR
53 QMAKE_POST_LINK += $$QMAKE_COPY $$FILE $$CHART_BUILD_PLUGIN_DIR
56 !system_build:mac: QMAKE_POST_LINK += " & $$MAC_POST_LINK_PREFIX $$MAC_PLUGINS_BIN_DIR"
54 !system_build:mac: QMAKE_POST_LINK += " & $$MAC_POST_LINK_PREFIX $$MAC_PLUGINS_BIN_DIR"
@@ -1,110 +1,112
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QAXIS_H
21 #ifndef QAXIS_H
22 #define QAXIS_H
22 #define QAXIS_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <qaxiscategories.h>
25 #include <qaxiscategories.h>
26 #include <QPen>
26 #include <QPen>
27 #include <QFont>
27 #include <QFont>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QAxisPrivate;
31 class QAxisPrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QAxis : public QObject
33 class QTCOMMERCIALCHART_EXPORT QAxis : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible)
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 public:
40 public:
39
41
40 QAxis(QObject *parent =0);
42 QAxis(QObject *parent =0);
41 ~QAxis();
43 ~QAxis();
42
44
43 //axis handling
45 //axis handling
44 bool isAxisVisible() const;
46 bool isAxisVisible() const;
45 void setAxisVisible(bool visible = true);
47 void setAxisVisible(bool visible = true);
46 void setAxisPen(const QPen &pen);
48 void setAxisPen(const QPen &pen);
47 QPen axisPen() const;
49 QPen axisPen() const;
48
50
49 //grid handling
51 //grid handling
50 bool isGridLineVisible() const;
52 bool isGridLineVisible() const;
51 void setGridLineVisible(bool visible = true);
53 void setGridLineVisible(bool visible = true);
52 void setGridLinePen(const QPen &pen);
54 void setGridLinePen(const QPen &pen);
53 QPen gridLinePen() const;
55 QPen gridLinePen() const;
54
56
55 //labels handling
57 //labels handling
56 bool labelsVisible() const;
58 bool labelsVisible() const;
57 void setLabelsVisible(bool visible = true);
59 void setLabelsVisible(bool visible = true);
58 void setLabelsPen(const QPen &pen);
60 void setLabelsPen(const QPen &pen);
59 QPen labelsPen() const;
61 QPen labelsPen() const;
60 void setLabelsBrush(const QBrush &brush);
62 void setLabelsBrush(const QBrush &brush);
61 QBrush labelsBrush() const;
63 QBrush labelsBrush() const;
62 void setLabelsFont(const QFont &font);
64 void setLabelsFont(const QFont &font);
63 QFont labelsFont() const;
65 QFont labelsFont() const;
64 void setLabelsAngle(int angle);
66 void setLabelsAngle(int angle);
65 int labelsAngle() const;
67 int labelsAngle() const;
66
68
67 //shades handling
69 //shades handling
68 bool shadesVisible() const;
70 bool shadesVisible() const;
69 void setShadesVisible(bool visible = true);
71 void setShadesVisible(bool visible = true);
70 void setShadesPen(const QPen &pen);
72 void setShadesPen(const QPen &pen);
71 QPen shadesPen() const;
73 QPen shadesPen() const;
72 void setShadesBrush(const QBrush &brush);
74 void setShadesBrush(const QBrush &brush);
73 QBrush shadesBrush() const;
75 QBrush shadesBrush() const;
74 void setShadesOpacity(qreal opacity);
76 void setShadesOpacity(qreal opacity);
75 qreal shadesOpacity() const;
77 qreal shadesOpacity() const;
76
78
77 //range handling
79 //range handling
78 void setMin(qreal min);
80 void setMin(qreal min);
79 qreal min() const;
81 qreal min() const;
80 void setMax(qreal max);
82 void setMax(qreal max);
81 qreal max() const;
83 qreal max() const;
82 void setRange(qreal min, qreal max);
84 void setRange(qreal min, qreal max);
83
85
84 //ticks handling
86 //ticks handling
85 void setTicksCount(int count);
87 void setTicksCount(int count);
86 int ticksCount() const;
88 int ticksCount() const;
87
89
88 void setNiceNumbersEnabled(bool enable = true);
90 void setNiceNumbersEnabled(bool enable = true);
89 bool niceNumbersEnabled() const;
91 bool niceNumbersEnabled() const;
90
92
91 QAxisCategories* categories();
93 QAxisCategories* categories();
92
94
93 void show();
95 void show();
94 void hide();
96 void hide();
95
97
96 Q_SIGNALS:
98 Q_SIGNALS:
97 void minChanged(qreal min);
99 void minChanged(qreal min);
98 void maxChanged(qreal max);
100 void maxChanged(qreal max);
99 void rangeChanged(qreal min, qreal max);
101 void rangeChanged(qreal min, qreal max);
100 void ticksCountChanged(int count);
102 void ticksCountChanged(int count);
101
103
102 private:
104 private:
103 QScopedPointer<QAxisPrivate> d_ptr;
105 QScopedPointer<QAxisPrivate> d_ptr;
104 Q_DISABLE_COPY(QAxis);
106 Q_DISABLE_COPY(QAxis);
105 friend class ChartDataSet;
107 friend class ChartDataSet;
106 friend class ChartAxis;
108 friend class ChartAxis;
107 };
109 };
108
110
109 QTCOMMERCIALCHART_END_NAMESPACE
111 QTCOMMERCIALCHART_END_NAMESPACE
110 #endif /* QCHARTAXIS_H_ */
112 #endif /* QCHARTAXIS_H_ */
@@ -1,302 +1,302
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "domain_p.h"
21 #include "domain_p.h"
22 #include <cmath>
22 #include <cmath>
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 Domain::Domain(QObject* parent):QObject(parent),
26 Domain::Domain(QObject* parent):QObject(parent),
27 m_minX(0),
27 m_minX(0),
28 m_maxX(0),
28 m_maxX(1),
29 m_minY(0),
29 m_minY(0),
30 m_maxY(0),
30 m_maxY(1),
31 m_tickXCount(5),
31 m_tickXCount(5),
32 m_tickYCount(5),
32 m_tickYCount(5),
33 m_niceXNumbers(false),
33 m_niceXNumbers(false),
34 m_niceYNumbers(false)
34 m_niceYNumbers(false)
35 {
35 {
36 }
36 }
37
37
38 Domain::~Domain()
38 Domain::~Domain()
39 {
39 {
40 }
40 }
41
41
42 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
42 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
43 {
43 {
44 setRange(minX, maxX, minY, maxY,m_tickXCount,m_tickYCount);
44 setRange(minX, maxX, minY, maxY,m_tickXCount,m_tickYCount);
45 }
45 }
46
46
47 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCount,int tickYCount)
47 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCount,int tickYCount)
48 {
48 {
49 bool axisXChanged = false;
49 bool axisXChanged = false;
50 bool axisYChanged = false;
50 bool axisYChanged = false;
51
51
52 if(m_tickXCount!=tickXCount) {
52 if(m_tickXCount!=tickXCount) {
53 m_tickXCount=tickXCount;
53 m_tickXCount=tickXCount;
54 axisXChanged=true;
54 axisXChanged=true;
55 }
55 }
56
56
57 if(m_tickYCount!=tickYCount) {
57 if(m_tickYCount!=tickYCount) {
58 m_tickYCount=tickYCount;
58 m_tickYCount=tickYCount;
59 axisYChanged=true;
59 axisYChanged=true;
60 }
60 }
61
61
62 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
62 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
63 if(m_niceXNumbers) looseNiceNumbers(minX, maxX, m_tickXCount);
63 if(m_niceXNumbers) looseNiceNumbers(minX, maxX, m_tickXCount);
64 m_minX=minX;
64 m_minX=minX;
65 m_maxX=maxX;
65 m_maxX=maxX;
66 axisXChanged=true;
66 axisXChanged=true;
67 }
67 }
68
68
69 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
69 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
70 if(m_niceYNumbers) looseNiceNumbers(minY, maxY, m_tickYCount);
70 if(m_niceYNumbers) looseNiceNumbers(minY, maxY, m_tickYCount);
71 m_minY=minY;
71 m_minY=minY;
72 m_maxY=maxY;
72 m_maxY=maxY;
73 axisYChanged=true;
73 axisYChanged=true;
74 }
74 }
75
75
76 if(axisXChanged || axisYChanged) {
76 if(axisXChanged || axisYChanged) {
77 emit this->domainChanged(m_minX, m_maxX, m_minY, m_maxY);
77 emit this->domainChanged(m_minX, m_maxX, m_minY, m_maxY);
78 }
78 }
79
79
80 if(axisXChanged) {
80 if(axisXChanged) {
81 emit rangeXChanged(minX,maxX, m_tickXCount);
81 emit rangeXChanged(minX,maxX, m_tickXCount);
82 }
82 }
83
83
84 if(axisYChanged) {
84 if(axisYChanged) {
85 emit rangeYChanged(minY,maxY, m_tickYCount);
85 emit rangeYChanged(minY,maxY, m_tickYCount);
86 }
86 }
87 }
87 }
88
88
89 void Domain::setRangeX(qreal min, qreal max)
89 void Domain::setRangeX(qreal min, qreal max)
90 {
90 {
91 setRange(min,max,m_minY, m_maxY);
91 setRange(min,max,m_minY, m_maxY);
92 }
92 }
93
93
94 void Domain::setRangeX(qreal min, qreal max, int tickCount)
94 void Domain::setRangeX(qreal min, qreal max, int tickCount)
95 {
95 {
96 setRange(min,max,m_minY, m_maxY,tickCount,m_tickYCount);
96 setRange(min,max,m_minY, m_maxY,tickCount,m_tickYCount);
97 }
97 }
98
98
99 void Domain::setRangeY(qreal min, qreal max)
99 void Domain::setRangeY(qreal min, qreal max)
100 {
100 {
101 setRange(m_minX, m_maxX, min, max);
101 setRange(m_minX, m_maxX, min, max);
102 }
102 }
103
103
104 void Domain::setRangeY(qreal min, qreal max,int tickCount)
104 void Domain::setRangeY(qreal min, qreal max,int tickCount)
105 {
105 {
106 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickCount);
106 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickCount);
107 }
107 }
108
108
109 void Domain::setMinX(qreal min)
109 void Domain::setMinX(qreal min)
110 {
110 {
111 setRange(min, m_maxX, m_minY, m_maxY);
111 setRange(min, m_maxX, m_minY, m_maxY);
112 }
112 }
113
113
114 void Domain::setMaxX(qreal max)
114 void Domain::setMaxX(qreal max)
115 {
115 {
116 setRange(m_minX, max, m_minY, m_maxY);
116 setRange(m_minX, max, m_minY, m_maxY);
117 }
117 }
118
118
119 void Domain::setMinY(qreal min)
119 void Domain::setMinY(qreal min)
120 {
120 {
121 setRange(m_minX, m_maxX, min, m_maxY);
121 setRange(m_minX, m_maxX, min, m_maxY);
122 }
122 }
123
123
124 void Domain::setMaxY(qreal max)
124 void Domain::setMaxY(qreal max)
125 {
125 {
126 setRange(m_minX, m_maxX, m_minY, max);
126 setRange(m_minX, m_maxX, m_minY, max);
127 }
127 }
128
128
129 qreal Domain::spanX() const
129 qreal Domain::spanX() const
130 {
130 {
131 Q_ASSERT(m_maxX >= m_minX);
131 Q_ASSERT(m_maxX >= m_minX);
132 return m_maxX - m_minX;
132 return m_maxX - m_minX;
133 }
133 }
134
134
135 qreal Domain::spanY() const
135 qreal Domain::spanY() const
136 {
136 {
137 Q_ASSERT(m_maxY >= m_minY);
137 Q_ASSERT(m_maxY >= m_minY);
138 return m_maxY - m_minY;
138 return m_maxY - m_minY;
139 }
139 }
140
140
141 bool Domain::isEmpty() const
141 bool Domain::isEmpty() const
142 {
142 {
143 return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY());
143 return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY());
144 }
144 }
145
145
146 void Domain::zoomIn(const QRectF& rect, const QSizeF& size)
146 void Domain::zoomIn(const QRectF& rect, const QSizeF& size)
147 {
147 {
148 qreal dx = spanX() / size.width();
148 qreal dx = spanX() / size.width();
149 qreal dy = spanY() / size.height();
149 qreal dy = spanY() / size.height();
150
150
151 qreal maxX = m_maxX;
151 qreal maxX = m_maxX;
152 qreal minX = m_minX;
152 qreal minX = m_minX;
153 qreal minY = m_minY;
153 qreal minY = m_minY;
154 qreal maxY = m_maxY;
154 qreal maxY = m_maxY;
155
155
156 maxX = minX + dx * rect.right();
156 maxX = minX + dx * rect.right();
157 minX = minX + dx * rect.left();
157 minX = minX + dx * rect.left();
158 minY = maxY - dy * rect.bottom();
158 minY = maxY - dy * rect.bottom();
159 maxY = maxY - dy * rect.top();
159 maxY = maxY - dy * rect.top();
160
160
161 int tickXCount = m_tickXCount;
161 int tickXCount = m_tickXCount;
162 int tickYCount = m_tickYCount;
162 int tickYCount = m_tickYCount;
163
163
164 if(m_niceXNumbers) {
164 if(m_niceXNumbers) {
165 looseNiceNumbers(minX, maxX, tickXCount);
165 looseNiceNumbers(minX, maxX, tickXCount);
166 }
166 }
167 if(m_niceYNumbers) {
167 if(m_niceYNumbers) {
168 looseNiceNumbers(minY, maxY, tickYCount);
168 looseNiceNumbers(minY, maxY, tickYCount);
169 }
169 }
170 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
170 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
171 }
171 }
172
172
173 void Domain::zoomOut(const QRectF& rect, const QSizeF& size)
173 void Domain::zoomOut(const QRectF& rect, const QSizeF& size)
174 {
174 {
175 qreal dx = spanX() / rect.width();
175 qreal dx = spanX() / rect.width();
176 qreal dy = spanY() / rect.height();
176 qreal dy = spanY() / rect.height();
177
177
178 qreal maxX = m_maxX;
178 qreal maxX = m_maxX;
179 qreal minX = m_minX;
179 qreal minX = m_minX;
180 qreal minY = m_minY;
180 qreal minY = m_minY;
181 qreal maxY = m_maxY;
181 qreal maxY = m_maxY;
182
182
183 minX = maxX - dx * rect.right();
183 minX = maxX - dx * rect.right();
184 maxX = minX + dx * size.width();
184 maxX = minX + dx * size.width();
185 maxY = minY + dy * rect.bottom();
185 maxY = minY + dy * rect.bottom();
186 minY = maxY - dy * size.height();
186 minY = maxY - dy * size.height();
187
187
188 int tickXCount = m_tickXCount;
188 int tickXCount = m_tickXCount;
189 int tickYCount = m_tickYCount;
189 int tickYCount = m_tickYCount;
190
190
191 if(m_niceXNumbers) {
191 if(m_niceXNumbers) {
192 looseNiceNumbers(minX, maxX, tickXCount);
192 looseNiceNumbers(minX, maxX, tickXCount);
193 }
193 }
194 if(m_niceYNumbers) {
194 if(m_niceYNumbers) {
195 looseNiceNumbers(minY, maxY, tickYCount);
195 looseNiceNumbers(minY, maxY, tickYCount);
196 }
196 }
197 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
197 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
198 }
198 }
199
199
200 void Domain::move(int dx,int dy,const QSizeF& size)
200 void Domain::move(int dx,int dy,const QSizeF& size)
201 {
201 {
202 qreal x = spanX() / size.width();
202 qreal x = spanX() / size.width();
203 qreal y = spanY() / size.height();
203 qreal y = spanY() / size.height();
204
204
205 qreal maxX = m_maxX;
205 qreal maxX = m_maxX;
206 qreal minX = m_minX;
206 qreal minX = m_minX;
207 qreal minY = m_minY;
207 qreal minY = m_minY;
208 qreal maxY = m_maxY;
208 qreal maxY = m_maxY;
209
209
210 if(dx!=0) {
210 if(dx!=0) {
211 minX = minX + x * dx;
211 minX = minX + x * dx;
212 maxX = maxX + x * dx;
212 maxX = maxX + x * dx;
213 }
213 }
214 if(dy!=0) {
214 if(dy!=0) {
215 minY = minY + y * dy;
215 minY = minY + y * dy;
216 maxY = maxY + y * dy;
216 maxY = maxY + y * dy;
217 }
217 }
218 setRange(minX,maxX,minY,maxY);
218 setRange(minX,maxX,minY,maxY);
219 }
219 }
220
220
221 void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount,bool niceNumbers)
221 void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount,bool niceNumbers)
222 {
222 {
223 if (m_niceXNumbers != niceNumbers) {
223 if (m_niceXNumbers != niceNumbers) {
224 m_niceXNumbers = niceNumbers;
224 m_niceXNumbers = niceNumbers;
225 //force recalculation
225 //force recalculation
226 m_minX = 0;
226 m_minX = 0;
227 m_maxX = 0;
227 m_maxX = 0;
228 }
228 }
229 setRange(min,max,m_minY, m_maxY,tickXCount,m_tickYCount);
229 setRange(min,max,m_minY, m_maxY,tickXCount,m_tickYCount);
230 }
230 }
231
231
232 void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount,bool niceNumbers)
232 void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount,bool niceNumbers)
233 {
233 {
234 if (m_niceYNumbers != niceNumbers) {
234 if (m_niceYNumbers != niceNumbers) {
235 m_niceYNumbers = niceNumbers;
235 m_niceYNumbers = niceNumbers;
236 //force recalculation
236 //force recalculation
237 m_minY = 0;
237 m_minY = 0;
238 m_maxY = 0;
238 m_maxY = 0;
239 }
239 }
240 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickYCount);
240 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickYCount);
241 }
241 }
242
242
243 //algorithm defined by Paul S.Heckbert GraphicalGems I
243 //algorithm defined by Paul S.Heckbert GraphicalGems I
244
244
245 void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
245 void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
246 {
246 {
247 qreal range = niceNumber(max-min,true); //range with ceiling
247 qreal range = niceNumber(max-min,true); //range with ceiling
248 qreal step = niceNumber(range/(ticksCount-1),false);
248 qreal step = niceNumber(range/(ticksCount-1),false);
249 min = floor(min/step);
249 min = floor(min/step);
250 max = ceil(max/step);
250 max = ceil(max/step);
251 ticksCount = int(max-min) +1;
251 ticksCount = int(max-min) +1;
252 min*=step;
252 min*=step;
253 max*=step;
253 max*=step;
254 }
254 }
255
255
256 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
256 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
257
257
258 qreal Domain::niceNumber(qreal x,bool ceiling) const
258 qreal Domain::niceNumber(qreal x,bool ceiling) const
259 {
259 {
260 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
260 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
261 qreal q = x/z;//q<10 && q>=1;
261 qreal q = x/z;//q<10 && q>=1;
262
262
263 if(ceiling) {
263 if(ceiling) {
264 if(q <= 1.0) q=1;
264 if(q <= 1.0) q=1;
265 else if(q <= 2.0) q=2;
265 else if(q <= 2.0) q=2;
266 else if(q <= 5.0) q=5;
266 else if(q <= 5.0) q=5;
267 else q=10;
267 else q=10;
268 }
268 }
269 else {
269 else {
270 if(q < 1.5) q=1;
270 if(q < 1.5) q=1;
271 else if(q < 3.0) q=2;
271 else if(q < 3.0) q=2;
272 else if(q < 7.0) q=5;
272 else if(q < 7.0) q=5;
273 else q=10;
273 else q=10;
274 }
274 }
275 return q*z;
275 return q*z;
276 }
276 }
277
277
278
278
279 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2)
279 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2)
280 {
280 {
281 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
281 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
282 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
282 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
283 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
283 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
284 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
284 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
285 }
285 }
286
286
287
287
288 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2)
288 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2)
289 {
289 {
290 return !(domain1 == domain2);
290 return !(domain1 == domain2);
291 }
291 }
292
292
293
293
294 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain)
294 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain)
295 {
295 {
296 dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')' << domain.m_tickXCount << "," << domain.m_tickYCount ;
296 dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')' << domain.m_tickXCount << "," << domain.m_tickYCount ;
297 return dbg.maybeSpace();
297 return dbg.maybeSpace();
298 }
298 }
299
299
300 #include "moc_domain_p.cpp"
300 #include "moc_domain_p.cpp"
301
301
302 QTCOMMERCIALCHART_END_NAMESPACE
302 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,508 +1,520
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qxyseries.h"
21 #include "qxyseries.h"
22 #include "qxyseries_p.h"
22 #include "qxyseries_p.h"
23 #include "domain_p.h"
23 #include "domain_p.h"
24 #include "legendmarker_p.h"
24 #include "legendmarker_p.h"
25 #include <QAbstractItemModel>
25 #include <QAbstractItemModel>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
29 /*!
30 \class QXYSeries
30 \class QXYSeries
31 \brief The QXYSeries class is a base class for line, spline and scatter series.
31 \brief The QXYSeries class is a base class for line, spline and scatter series.
32 */
32 */
33
33
34 /*!
34 /*!
35 \fn QPen QXYSeries::pen() const
35 \fn QPen QXYSeries::pen() const
36 \brief Returns pen used to draw points for series.
36 \brief Returns pen used to draw points for series.
37 \sa setPen()
37 \sa setPen()
38 */
38 */
39
39
40 /*!
40 /*!
41 \fn QBrush QXYSeries::brush() const
41 \fn QBrush QXYSeries::brush() const
42 \brief Returns brush used to draw points for series.
42 \brief Returns brush used to draw points for series.
43 \sa setBrush()
43 \sa setBrush()
44 */
44 */
45
45
46 /*!
46 /*!
47 \fn void QXYSeries::clicked(const QPointF& point)
47 \fn void QXYSeries::clicked(const QPointF& point)
48 \brief Signal is emitted when user clicks the \a point on chart.
48 \brief Signal is emitted when user clicks the \a point on chart.
49 */
49 */
50
50
51
51
52 /*!
52 /*!
53 \fn void QXYSeriesPrivate::pointReplaced(int index)
53 \fn void QXYSeriesPrivate::pointReplaced(int index)
54 \brief \internal \a index
54 \brief \internal \a index
55 */
55 */
56
56
57 /*!
57 /*!
58 \fn void QXYSeriesPrivate::pointAdded(int index)
58 \fn void QXYSeriesPrivate::pointAdded(int index)
59 \brief \internal \a index
59 \brief \internal \a index
60 */
60 */
61
61
62 /*!
62 /*!
63 \fn void QXYSeriesPrivate::pointRemoved(int index)
63 \fn void QXYSeriesPrivate::pointRemoved(int index)
64 \brief \internal \a index
64 \brief \internal \a index
65 */
65 */
66
66
67 /*!
67 /*!
68 \fn void QXYSeriesPrivate::updated()
68 \fn void QXYSeriesPrivate::updated()
69 \brief \internal
69 \brief \internal
70 */
70 */
71
71
72 /*!
72 /*!
73 \internal
73 \internal
74
74
75 Constructs empty series object which is a child of \a parent.
75 Constructs empty series object which is a child of \a parent.
76 When series object is added to QChartView or QChart instance ownerships is transferred.
76 When series object is added to QChartView or QChart instance ownerships is transferred.
77 */
77 */
78 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
78 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
79 {
79 {
80
80
81 }
81 }
82 /*!
82 /*!
83 Destroys the object. Series added to QChartView or QChart instances are owned by those,
83 Destroys the object. Series added to QChartView or QChart instances are owned by those,
84 and are deleted when mentioned object are destroyed.
84 and are deleted when mentioned object are destroyed.
85 */
85 */
86 QXYSeries::~QXYSeries()
86 QXYSeries::~QXYSeries()
87 {
87 {
88 }
88 }
89
89
90 /*!
90 /*!
91 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
91 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
92 */
92 */
93 void QXYSeries::append(qreal x,qreal y)
93 void QXYSeries::append(qreal x,qreal y)
94 {
94 {
95 append(QPointF(x,y));
95 append(QPointF(x,y));
96 }
96 }
97
97
98 /*!
98 /*!
99 This is an overloaded function.
99 This is an overloaded function.
100 Adds data \a point to the series. Points are connected with lines on the chart.
100 Adds data \a point to the series. Points are connected with lines on the chart.
101 */
101 */
102 void QXYSeries::append(const QPointF &point)
102 void QXYSeries::append(const QPointF &point)
103 {
103 {
104 Q_D(QXYSeries);
104 Q_D(QXYSeries);
105 d->m_points<<point;
105 d->m_points<<point;
106 emit d->pointAdded(d->m_points.count()-1);
106 emit d->pointAdded(d->m_points.count()-1);
107 }
107 }
108
108
109 /*!
109 /*!
110 This is an overloaded function.
110 This is an overloaded function.
111 Adds list of data \a points to the series. Points are connected with lines on the chart.
111 Adds list of data \a points to the series. Points are connected with lines on the chart.
112 */
112 */
113 void QXYSeries::append(const QList<QPointF> &points)
113 void QXYSeries::append(const QList<QPointF> &points)
114 {
114 {
115 foreach(const QPointF& point , points) {
115 foreach(const QPointF& point , points) {
116 append(point);
116 append(point);
117 }
117 }
118 }
118 }
119
119
120
120
121 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
121 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
122 {
122 {
123 replace(QPointF(oldX,oldY),QPointF(newX,newY));
123 replace(QPointF(oldX,oldY),QPointF(newX,newY));
124 }
124 }
125
125
126 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
126 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
127 {
127 {
128 Q_D(QXYSeries);
128 Q_D(QXYSeries);
129 int index = d->m_points.indexOf(oldPoint);
129 int index = d->m_points.indexOf(oldPoint);
130 if(index==-1) return;
130 if(index==-1) return;
131 d->m_points[index] = newPoint;
131 d->m_points[index] = newPoint;
132 emit d->pointReplaced(index);
132 emit d->pointReplaced(index);
133 }
133 }
134
134
135 /*!
135 /*!
136 Removes current \a x and \a y value.
136 Removes current \a x and \a y value.
137 */
137 */
138 void QXYSeries::remove(qreal x,qreal y)
138 void QXYSeries::remove(qreal x,qreal y)
139 {
139 {
140 remove(QPointF(x,y));
140 remove(QPointF(x,y));
141 }
141 }
142
142
143 /*!
143 /*!
144 Removes current \a point x value. Note \a point y value is ignored.
144 Removes current \a point x value. Note \a point y value is ignored.
145 */
145 */
146 void QXYSeries::remove(const QPointF &point)
146 void QXYSeries::remove(const QPointF &point)
147 {
147 {
148 Q_D(QXYSeries);
148 Q_D(QXYSeries);
149 int index = d->m_points.indexOf(point);
149 int index = d->m_points.indexOf(point);
150 if(index==-1) return;
150 if(index==-1) return;
151 d->m_points.remove(index);
151 d->m_points.remove(index);
152 emit d->pointRemoved(index);
152 emit d->pointRemoved(index);
153 }
153 }
154
154
155 /*!
155 /*!
156 Removes all data points from the series.
156 Removes all data points from the series.
157 */
157 */
158 void QXYSeries::removeAll()
158 void QXYSeries::removeAll()
159 {
159 {
160 Q_D(QXYSeries);
160 Q_D(QXYSeries);
161 foreach(const QPointF& point, d->m_points) {
161 foreach(const QPointF& point, d->m_points) {
162 remove(point);
162 remove(point);
163 }
163 }
164 }
164 }
165
165
166 /*!
166 /*!
167 \internal \a pos
167 \internal \a pos
168 */
168 */
169 QList<QPointF> QXYSeries::points() const
169 QList<QPointF> QXYSeries::points() const
170 {
170 {
171 // Q_ASSERT(false);
171 // Q_ASSERT(false);
172 Q_D(const QXYSeries);
172 Q_D(const QXYSeries);
173 if (d->m_model) {
173 if (d->m_model) {
174 QList<QPointF> result;
174 QList<QPointF> result;
175 if (d->m_mapOrientation == Qt::Vertical){
175 if (d->m_mapOrientation == Qt::Vertical){
176 // consecutive data is read from model's column
176 // consecutive data is read from model's column
177 if (d->m_mapX >= d->m_model->columnCount() || d->m_mapY >= d->m_model->columnCount())
177 if (d->m_mapX >= d->m_model->columnCount() || d->m_mapY >= d->m_model->columnCount())
178 return result; // mapped columns are not existing
178 return result; // mapped columns are not existing
179
179
180 for(int i = d->m_mapFirst; i< d->m_mapFirst + count(); ++i) {
180 for(int i = d->m_mapFirst; i< d->m_mapFirst + count(); ++i) {
181 qreal x = d->m_model->data(d->m_model->index(i, d->m_mapX), Qt::DisplayRole).toReal();
181 qreal x = d->m_model->data(d->m_model->index(i, d->m_mapX), Qt::DisplayRole).toReal();
182 qreal y = d->m_model->data(d->m_model->index(i, d->m_mapY), Qt::DisplayRole).toReal();
182 qreal y = d->m_model->data(d->m_model->index(i, d->m_mapY), Qt::DisplayRole).toReal();
183 result << QPointF(x,y);
183 result << QPointF(x,y);
184 }
184 }
185 return result;
185 return result;
186 }
186 }
187 else{
187 else{
188 // consecutive data is read from model's row
188 // consecutive data is read from model's row
189 if (d->m_mapX >= d->m_model->rowCount() || d->m_mapY >= d->m_model->rowCount())
189 if (d->m_mapX >= d->m_model->rowCount() || d->m_mapY >= d->m_model->rowCount())
190 return result; // mapped rows are not existing
190 return result; // mapped rows are not existing
191
191
192 for(int i = d->m_mapFirst; i< d->m_mapFirst + count(); ++i) {
192 for(int i = d->m_mapFirst; i< d->m_mapFirst + count(); ++i) {
193 qreal x = d->m_model->data(d->m_model->index(d->m_mapX, i), Qt::DisplayRole).toReal();
193 qreal x = d->m_model->data(d->m_model->index(d->m_mapX, i), Qt::DisplayRole).toReal();
194 qreal y = d->m_model->data(d->m_model->index(d->m_mapY, i), Qt::DisplayRole).toReal();
194 qreal y = d->m_model->data(d->m_model->index(d->m_mapY, i), Qt::DisplayRole).toReal();
195 result << QPointF(x,y);
195 result << QPointF(x,y);
196 }
196 }
197 return result;
197 return result;
198 }
198 }
199 } else {
199 } else {
200 // model is not specified, return the data from series' internal data store
200 // model is not specified, return the data from series' internal data store
201 return d->m_points.toList();
201 return d->m_points.toList();
202 }
202 }
203 }
203 }
204
204
205 /*!
205 /*!
206 Returns number of data points within series.
206 Returns number of data points within series.
207 */
207 */
208 int QXYSeries::count() const
208 int QXYSeries::count() const
209 {
209 {
210 Q_D(const QXYSeries);
210 Q_D(const QXYSeries);
211
211
212 if (d->m_model) {
212 if (d->m_model) {
213 if (d->m_mapOrientation == Qt::Vertical) {
213 if (d->m_mapOrientation == Qt::Vertical) {
214 // data is in a column. Return the number of mapped items if the model's column have enough items
214 // data is in a column. Return the number of mapped items if the model's column have enough items
215 // or the number of items that can be mapped
215 // or the number of items that can be mapped
216 if (d->m_mapX >= d->m_model->columnCount() || d->m_mapY >= d->m_model->columnCount())
216 if (d->m_mapX >= d->m_model->columnCount() || d->m_mapY >= d->m_model->columnCount())
217 return 0; // mapped columns are not existing
217 return 0; // mapped columns are not existing
218 else if (d->m_mapCount != -1)
218 else if (d->m_mapCount != -1)
219 return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0));
219 return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0));
220 else
220 else
221 return qMax(d->m_model->rowCount() - d->m_mapFirst, 0);
221 return qMax(d->m_model->rowCount() - d->m_mapFirst, 0);
222 } else {
222 } else {
223 // data is in a row. Return the number of mapped items if the model's row have enough items
223 // data is in a row. Return the number of mapped items if the model's row have enough items
224 // or the number of items that can be mapped
224 // or the number of items that can be mapped
225 if (d->m_mapX >= d->m_model->rowCount() || d->m_mapY >= d->m_model->rowCount())
225 if (d->m_mapX >= d->m_model->rowCount() || d->m_mapY >= d->m_model->rowCount())
226 return 0; // mapped rows are not existing
226 return 0; // mapped rows are not existing
227 else if (d->m_mapCount != -1)
227 else if (d->m_mapCount != -1)
228 return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0));
228 return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0));
229 else
229 else
230 return qMax(d->m_model->columnCount() - d->m_mapFirst, 0);
230 return qMax(d->m_model->columnCount() - d->m_mapFirst, 0);
231 }
231 }
232 }
232 }
233
233
234 // model is not specified, return the number of points in the series internal data store
234 // model is not specified, return the number of points in the series internal data store
235 return d->m_points.count();
235 return d->m_points.count();
236 }
236 }
237
237
238
238
239 /*!
239 /*!
240 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
240 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
241 pen from chart theme is used.
241 pen from chart theme is used.
242 \sa QChart::setTheme()
242 \sa QChart::setTheme()
243 */
243 */
244 void QXYSeries::setPen(const QPen &pen)
244 void QXYSeries::setPen(const QPen &pen)
245 {
245 {
246 Q_D(QXYSeries);
246 Q_D(QXYSeries);
247 if (d->m_pen!=pen) {
247 if (d->m_pen!=pen) {
248 d->m_pen = pen;
248 d->m_pen = pen;
249 emit d->updated();
249 emit d->updated();
250 }
250 }
251 }
251 }
252
252
253 QPen QXYSeries::pen() const
253 QPen QXYSeries::pen() const
254 {
254 {
255 Q_D(const QXYSeries);
255 Q_D(const QXYSeries);
256 return d->m_pen;
256 return d->m_pen;
257 }
257 }
258
258
259 /*!
259 /*!
260 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
260 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
261 from chart theme setting is used.
261 from chart theme setting is used.
262 \sa QChart::setTheme()
262 \sa QChart::setTheme()
263 */
263 */
264 void QXYSeries::setBrush(const QBrush &brush)
264 void QXYSeries::setBrush(const QBrush &brush)
265 {
265 {
266 Q_D(QXYSeries);
266 Q_D(QXYSeries);
267 if (d->m_brush!=brush) {
267 if (d->m_brush!=brush) {
268 d->m_brush = brush;
268 d->m_brush = brush;
269 emit d->updated();
269 emit d->updated();
270 }
270 }
271 }
271 }
272
272
273 QBrush QXYSeries::brush() const
273 QBrush QXYSeries::brush() const
274 {
274 {
275 Q_D(const QXYSeries);
275 Q_D(const QXYSeries);
276 return d->m_brush;
276 return d->m_brush;
277 }
277 }
278
278
279
279
280 /*!
280 /*!
281 Sets if data points are \a visible and should be drawn on line.
281 Sets if data points are \a visible and should be drawn on line.
282 */
282 */
283 void QXYSeries::setPointsVisible(bool visible)
283 void QXYSeries::setPointsVisible(bool visible)
284 {
284 {
285 Q_D(QXYSeries);
285 Q_D(QXYSeries);
286 if (d->m_pointsVisible != visible){
286 if (d->m_pointsVisible != visible){
287 d->m_pointsVisible = visible;
287 d->m_pointsVisible = visible;
288 emit d->updated();
288 emit d->updated();
289 }
289 }
290 }
290 }
291
291
292 /*!
292 /*!
293 Returns true if drawing the data points of the series is enabled.
293 Returns true if drawing the data points of the series is enabled.
294 */
294 */
295 bool QXYSeries::pointsVisible() const
295 bool QXYSeries::pointsVisible() const
296 {
296 {
297 Q_D(const QXYSeries);
297 Q_D(const QXYSeries);
298 return d->m_pointsVisible;
298 return d->m_pointsVisible;
299 }
299 }
300
300
301
301
302 /*!
302 /*!
303 Stream operator for adding a data \a point to the series.
303 Stream operator for adding a data \a point to the series.
304 \sa append()
304 \sa append()
305 */
305 */
306 QXYSeries& QXYSeries::operator<< (const QPointF &point)
306 QXYSeries& QXYSeries::operator<< (const QPointF &point)
307 {
307 {
308 append(point);
308 append(point);
309 return *this;
309 return *this;
310 }
310 }
311
311
312
312
313 /*!
313 /*!
314 Stream operator for adding a list of \a points to the series.
314 Stream operator for adding a list of \a points to the series.
315 \sa append()
315 \sa append()
316 */
316 */
317
317
318 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
318 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
319 {
319 {
320 append(points);
320 append(points);
321 return *this;
321 return *this;
322 }
322 }
323
323
324 /*!
324 /*!
325 \fn bool QXYSeries::setModel(QAbstractItemModel *model)
325 \fn bool QXYSeries::setModel(QAbstractItemModel *model)
326 Sets the \a model to be used as a data source
326 Sets the \a model to be used as a data source
327 \sa setModelMapping()
327 \sa setModelMapping()
328 */
328 */
329 bool QXYSeries::setModel(QAbstractItemModel *model)
329 bool QXYSeries::setModel(QAbstractItemModel *model)
330 {
330 {
331 Q_D(QXYSeries);
331 Q_D(QXYSeries);
332 // disconnect signals from old model
332 // disconnect signals from old model
333 if (d->m_model) {
333 if (d->m_model) {
334 QObject::disconnect(d->m_model, 0, this, 0);
334 QObject::disconnect(d->m_model, 0, this, 0);
335 d->m_mapX = -1;
335 d->m_mapX = -1;
336 d->m_mapY = -1;
336 d->m_mapY = -1;
337 d->m_mapFirst = 0;
337 d->m_mapFirst = 0;
338 d->m_mapCount = -1;
338 d->m_mapCount = -1;
339 d->m_mapOrientation = Qt::Vertical;
339 d->m_mapOrientation = Qt::Vertical;
340 }
340 }
341
341
342 // set new model
342 // set new model
343 if (model) {
343 if (model) {
344 d->m_model = model;
344 d->m_model = model;
345 return true;
345 return true;
346 } else {
346 } else {
347 d->m_model = 0;
347 d->m_model = 0;
348 return false;
348 return false;
349 }
349 }
350 }
350 }
351
351
352 /*!
352 /*!
353 Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used
353 Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used
354 as a data source for y coordinate. The \a orientation parameter specifies whether the data
354 as a data source for y coordinate. The \a orientation parameter specifies whether the data
355 is in columns or in rows.
355 is in columns or in rows.
356 \sa setModel()
356 \sa setModel()
357 */
357 */
358 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
358 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
359 {
359 {
360 Q_D(QXYSeries);
360 Q_D(QXYSeries);
361 if (d->m_model == 0)
361 if (d->m_model == 0)
362 return;
362 return;
363 d->m_mapX = modelX;
363 d->m_mapX = modelX;
364 d->m_mapY = modelY;
364 d->m_mapY = modelY;
365 d->m_mapOrientation = orientation;
365 d->m_mapOrientation = orientation;
366
366
367 // connect the signals from the model
367 // connect the signals from the model
368 connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
368 connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
369 // if (d->m_mapOrientation == Qt::Vertical) {
369 // if (d->m_mapOrientation == Qt::Vertical) {
370 connect(d->m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
370 connect(d->m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
371 connect(d->m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
371 connect(d->m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
372 // } else {
372 // } else {
373 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
373 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
374 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
374 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
375 // }
375 // }
376 }
376 }
377
377
378 void QXYSeries::setModelMappingRange(int first, int count)
378 void QXYSeries::setModelMappingRange(int first, int count)
379 {
379 {
380 Q_D(QXYSeries);
380 Q_D(QXYSeries);
381 d->m_mapFirst = qMax(first, 0);
381 d->m_mapFirst = qMax(first, 0);
382 d->m_mapCount = qMax(count, -1);
382 d->m_mapCount = qMax(count, -1);
383 emit d->reinitialized();
383 emit d->reinitialized();
384 }
384 }
385
385
386 int QXYSeries::mapX() const
386 int QXYSeries::mapX() const
387 {
387 {
388 Q_D(const QXYSeries);
388 Q_D(const QXYSeries);
389 return d->m_mapX;
389 return d->m_mapX;
390 }
390 }
391
391
392 int QXYSeries::mapY() const
392 int QXYSeries::mapY() const
393 {
393 {
394 Q_D(const QXYSeries);
394 Q_D(const QXYSeries);
395 return d->m_mapY;
395 return d->m_mapY;
396
396
397 }
397 }
398
398
399 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
399 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
400
400
401
401
402 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q),
402 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q),
403 m_mapX(-1),
403 m_mapX(-1),
404 m_mapY(-1),
404 m_mapY(-1),
405 m_pointsVisible(false)
405 m_pointsVisible(false)
406 {
406 {
407 }
407 }
408
408
409 void QXYSeriesPrivate::scaleDomain(Domain& domain)
409 void QXYSeriesPrivate::scaleDomain(Domain& domain)
410 {
410 {
411 qreal minX(domain.minX());
411 qreal minX(domain.minX());
412 qreal minY(domain.minY());
412 qreal minY(domain.minY());
413 qreal maxX(domain.maxX());
413 qreal maxX(domain.maxX());
414 qreal maxY(domain.maxY());
414 qreal maxY(domain.maxY());
415 int tickXCount(domain.tickXCount());
415 int tickXCount(domain.tickXCount());
416 int tickYCount(domain.tickYCount());
416 int tickYCount(domain.tickYCount());
417
417
418 Q_Q(QXYSeries);
418 Q_Q(QXYSeries);
419
419
420 const QList<QPointF>& points = q->points();
420 const QList<QPointF>& points = q->points();
421
421
422 if(points.isEmpty()){
422 // if(points.isEmpty()){
423 minX=0.0;
423 // minX=0.0;
424 minY=0.0;
424 // minY=0.0;
425 maxX=1.0;
425 // maxX=1.0;
426 maxY=1.0;
426 // maxY=1.0;
427 }
427 // }
428
428
429 for (int i = 0; i < points.count(); i++)
429 // for (int i = 0; i < points.count(); i++)
430 {
430 // {
431 qreal x = points[i].x();
431 // qreal x = points[i].x();
432 qreal y = points[i].y();
432 // qreal y = points[i].y();
433 minX = qMin(minX, x);
433 // minX = qMin(minX, x);
434 minY = qMin(minY, y);
434 // minY = qMin(minY, y);
435 maxX = qMax(maxX, x);
435 // maxX = qMax(maxX, x);
436 maxY = qMax(maxY, y);
436 // maxY = qMax(maxY, y);
437 }
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 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
454 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
443 {
455 {
444 Q_Q(QXYSeries);
456 Q_Q(QXYSeries);
445 QList<LegendMarker*> list;
457 QList<LegendMarker*> list;
446 return list << new XYLegendMarker(q,legend);
458 return list << new XYLegendMarker(q,legend);
447 }
459 }
448
460
449 void QXYSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
461 void QXYSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
450 {
462 {
451 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
463 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
452 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
464 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
453 if (m_mapOrientation == Qt::Vertical) {
465 if (m_mapOrientation == Qt::Vertical) {
454 if ((column == m_mapX || column == m_mapY) // modified item is in a mapped column
466 if ((column == m_mapX || column == m_mapY) // modified item is in a mapped column
455 && row >= m_mapFirst // modfied item in not before first item
467 && row >= m_mapFirst // modfied item in not before first item
456 && (m_mapCount == -1 || row < m_mapFirst + m_mapCount)) // map is not limited or item lays before the end of map
468 && (m_mapCount == -1 || row < m_mapFirst + m_mapCount)) // map is not limited or item lays before the end of map
457 emit pointReplaced(row - m_mapFirst);
469 emit pointReplaced(row - m_mapFirst);
458 } else {
470 } else {
459 if ((row == m_mapX || row == m_mapY) // modified item is in a mapped row
471 if ((row == m_mapX || row == m_mapY) // modified item is in a mapped row
460 && column >= m_mapFirst // modfied item in not before first item
472 && column >= m_mapFirst // modfied item in not before first item
461 && (m_mapCount == -1 || column < m_mapFirst + m_mapCount)) // map is not limited or item lays before the end of map
473 && (m_mapCount == -1 || column < m_mapFirst + m_mapCount)) // map is not limited or item lays before the end of map
462 emit pointReplaced(column - m_mapFirst);
474 emit pointReplaced(column - m_mapFirst);
463 }
475 }
464 }
476 }
465 }
477 }
466 }
478 }
467
479
468
480
469 void QXYSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
481 void QXYSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
470 {
482 {
471 Q_UNUSED(parent);
483 Q_UNUSED(parent);
472 if (m_mapOrientation == Qt::Vertical)
484 if (m_mapOrientation == Qt::Vertical)
473 emit pointsAdded(start, end);
485 emit pointsAdded(start, end);
474 else if (start <= m_mapX || start <= m_mapY)
486 else if (start <= m_mapX || start <= m_mapY)
475 emit reinitialized();
487 emit reinitialized();
476 }
488 }
477
489
478 void QXYSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
490 void QXYSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
479 {
491 {
480 Q_UNUSED(parent);
492 Q_UNUSED(parent);
481 if (m_mapOrientation == Qt::Vertical)
493 if (m_mapOrientation == Qt::Vertical)
482 emit pointsRemoved(start, end);
494 emit pointsRemoved(start, end);
483 else if (start <= m_mapX || start <= m_mapY)
495 else if (start <= m_mapX || start <= m_mapY)
484 emit reinitialized();
496 emit reinitialized();
485 }
497 }
486
498
487 void QXYSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
499 void QXYSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
488 {
500 {
489 Q_UNUSED(parent);
501 Q_UNUSED(parent);
490 if (m_mapOrientation == Qt::Horizontal)
502 if (m_mapOrientation == Qt::Horizontal)
491 emit pointsAdded(start, end);
503 emit pointsAdded(start, end);
492 else if (start <= m_mapX || start <= m_mapY)
504 else if (start <= m_mapX || start <= m_mapY)
493 emit reinitialized();
505 emit reinitialized();
494 }
506 }
495
507
496 void QXYSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
508 void QXYSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
497 {
509 {
498 Q_UNUSED(parent);
510 Q_UNUSED(parent);
499 if (m_mapOrientation == Qt::Horizontal)
511 if (m_mapOrientation == Qt::Horizontal)
500 emit pointsRemoved(start, end);
512 emit pointsRemoved(start, end);
501 else if (start <= m_mapX || start <= m_mapY)
513 else if (start <= m_mapX || start <= m_mapY)
502 emit reinitialized();
514 emit reinitialized();
503 }
515 }
504
516
505 #include "moc_qxyseries.cpp"
517 #include "moc_qxyseries.cpp"
506 #include "moc_qxyseries_p.cpp"
518 #include "moc_qxyseries_p.cpp"
507
519
508 QTCOMMERCIALCHART_END_NAMESPACE
520 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now