From d898436e4875e009f1b67c3aa054e69b322a0931 2012-05-21 10:54:06 From: Tero Ahola Date: 2012-05-21 10:54:06 Subject: [PATCH] Separated series model stuff from data api in QML examples --- diff --git a/demos/demos.pro b/demos/demos.pro index 50f839d..371bda4 100644 --- a/demos/demos.pro +++ b/demos/demos.pro @@ -8,4 +8,5 @@ SUBDIRS += chartthemes \ piechartcustomization \ dynamicspline \ qmlchart \ - qmlweather + qmlweather \ + qmlcustommodel diff --git a/demos/qmlchart/qml/qmlchart/View1.qml b/demos/qmlchart/qml/qmlchart/View1.qml index 6d3e1bb..e7d89d4 100644 --- a/demos/qmlchart/qml/qmlchart/View1.qml +++ b/demos/qmlchart/qml/qmlchart/View1.qml @@ -45,30 +45,6 @@ Rectangle { PieSlice { label: "Skoda"; value: 8.2 } PieSlice { label: "Volvo"; value: 6.8 } } - - // TODO: move ChartModel API into a demo application instead of making it a public API -// // For dynamic data you can use the ChartModel API. -// ChartModel { -// id: chartModel -// ChartModelElement { values: ["Volkswagen", 13.5] } -// ChartModelElement { values: ["Toyota", 10.9] } -// ChartModelElement { values: ["Ford", 8.6] } -// ChartModelElement { values: ["Skoda", 8.2] } -// ChartModelElement { values: ["Volvo", 6.8] } -// } -// // In this case you need to define how the data maps to pie slices with the ModelMapper API of the pie series. -// PieSeries { -// id: pieSeries -// model: chartModel -// modelMapper.mapLabels: 0 -// modelMapper.mapValues: 1 -// modelMapper.first: 0 -// modelMapper.count: -1 // "Undefined" = -1 by default -// modelMapper.orientation: PieModelMapper.Vertical -// } - - // TODO: you could also append to your model, for example: -// pieSeries.model.append(["Others", 52.0]); } Component.onCompleted: { @@ -90,9 +66,9 @@ Rectangle { __explodedIndex = (__explodedIndex + 1) % pieSeries.count; pieSeries.at(__explodedIndex).exploded = true; + pieSeries.find("Volkswagen").exploded = true; // TODO: implement for convenience -// pieSeries.find("Ford").exploded = true; -// pieSeries.removeAll("Ford") +// pieSeries.removeAll("Ford"); } } @@ -123,20 +99,4 @@ Rectangle { } } } - - // TODO: show how to use data from a list model in a chart view - // i.e. copy the data into a chart model -// ListModel { -// id: listModel -// ListElement { -// label: "Volkswagen" -// value: 13.5 -// } -// ListElement { -// label: "Toyota" -// value: 10.9 -// } -// // and so on... -// } - } diff --git a/demos/qmlchart/qml/qmlchart/View2.qml b/demos/qmlchart/qml/qmlchart/View2.qml index 116f54a..aa3ac9b 100644 --- a/demos/qmlchart/qml/qmlchart/View2.qml +++ b/demos/qmlchart/qml/qmlchart/View2.qml @@ -32,31 +32,24 @@ Rectangle { LineSeries { name: "Line" - model: chartModel - modelMapper.mapX: 0 - modelMapper.mapY: 1 - modelMapper.first: 0 - modelMapper.count: -1 - modelMapper.orientation: XYModelMapper.Vertical + XyPoint { x: 0; y: 0 } + XyPoint { x: 1.1; y: 2.1 } + XyPoint { x: 1.9; y: 3.3 } + XyPoint { x: 2.1; y: 2.1 } + XyPoint { x: 2.9; y: 4.9 } + XyPoint { x: 3.4; y: 3.0 } + XyPoint { x: 4.1; y: 3.3 } } SplineSeries { name: "Spline" - model: chartModel - modelMapper.mapX: 0 - modelMapper.mapY: 2 + XyPoint { x: 0; y: 0.3 } + XyPoint { x: 1.1; y: 3.2 } + XyPoint { x: 1.9; y: 2.4 } + XyPoint { x: 2.1; y: 2.1 } + XyPoint { x: 2.9; y: 2.6 } + XyPoint { x: 3.4; y: 2.3 } + XyPoint { x: 4.1; y: 3.1 } } } - - ChartModel { - id: chartModel - ChartModelElement { values: [0.0, 0.0, 0.3] } - ChartModelElement { values: [1.1, 2.1, 3.2] } - ChartModelElement { values: [1.9, 3.3, 2.4] } - ChartModelElement { values: [2.1, 2.1, 2.1] } - ChartModelElement { values: [2.9, 4.9, 2.6] } - ChartModelElement { values: [3.4, 3.0, 2.3] } - ChartModelElement { values: [4.1, 3.3, 3.1] } - } - } diff --git a/demos/qmlchart/qml/qmlchart/View3.qml b/demos/qmlchart/qml/qmlchart/View3.qml index 7f42654..a223a73 100644 --- a/demos/qmlchart/qml/qmlchart/View3.qml +++ b/demos/qmlchart/qml/qmlchart/View3.qml @@ -33,46 +33,98 @@ Rectangle { AreaSeries { name: "Russian" - upperModel: chartModel - upperModelMapper.mapX: 0 - upperModelMapper.mapY: 2 - lowerModel: chartModel - lowerModelMapper.mapX: 0 - lowerModelMapper.mapY: 1 + upperSeries: LineSeries { + XyPoint { x: 0; y: 1 } + XyPoint { x: 1; y: 1 } + XyPoint { x: 2; y: 1 } + XyPoint { x: 3; y: 1 } + XyPoint { x: 4; y: 1 } + XyPoint { x: 5; y: 0 } + XyPoint { x: 6; y: 1 } + XyPoint { x: 7; y: 1 } + XyPoint { x: 8; y: 4 } + XyPoint { x: 9; y: 3 } + XyPoint { x: 10; y: 2 } + XyPoint { x: 11; y: 1 } + } + lowerSeries: LineSeries { + XyPoint { x: 0; y: 0 } + XyPoint { x: 1; y: 0 } + XyPoint { x: 2; y: 0 } + XyPoint { x: 3; y: 0 } + XyPoint { x: 4; y: 0 } + XyPoint { x: 5; y: 0 } + XyPoint { x: 6; y: 0 } + XyPoint { x: 7; y: 0 } + XyPoint { x: 8; y: 0 } + XyPoint { x: 9; y: 0 } + XyPoint { x: 10; y: 0 } + XyPoint { x: 11; y: 0 } + } } + AreaSeries { name: "Swedish" - upperModel: chartModel - upperModelMapper.mapX: 0 - upperModelMapper.mapY: 3 - lowerModel: chartModel - lowerModelMapper.mapX: 0 - lowerModelMapper.mapY: 1 + upperSeries: LineSeries { + XyPoint { x: 0; y: 1 } + XyPoint { x: 1; y: 1 } + XyPoint { x: 2; y: 3 } + XyPoint { x: 3; y: 3 } + XyPoint { x: 4; y: 2 } + XyPoint { x: 5; y: 0 } + XyPoint { x: 6; y: 2 } + XyPoint { x: 7; y: 1 } + XyPoint { x: 8; y: 2 } + XyPoint { x: 9; y: 1 } + XyPoint { x: 10; y: 3 } + XyPoint { x: 11; y: 3 } + } + lowerSeries: LineSeries { + XyPoint { x: 0; y: 0 } + XyPoint { x: 1; y: 0 } + XyPoint { x: 2; y: 0 } + XyPoint { x: 3; y: 0 } + XyPoint { x: 4; y: 0 } + XyPoint { x: 5; y: 0 } + XyPoint { x: 6; y: 0 } + XyPoint { x: 7; y: 0 } + XyPoint { x: 8; y: 0 } + XyPoint { x: 9; y: 0 } + XyPoint { x: 10; y: 0 } + XyPoint { x: 11; y: 0 } + } } + AreaSeries { - name: "Finnish" - upperModel: chartModel - upperModelMapper.mapX: 0 - upperModelMapper.mapY: 4 - lowerModel: chartModel - lowerModelMapper.mapX: 0 - lowerModelMapper.mapY: 1 + name: "Swedish" + upperSeries: LineSeries { + XyPoint { x: 0; y: 0 } + XyPoint { x: 1; y: 0 } + XyPoint { x: 2; y: 0 } + XyPoint { x: 3; y: 0 } + XyPoint { x: 4; y: 0 } + XyPoint { x: 5; y: 0 } + XyPoint { x: 6; y: 1 } + XyPoint { x: 7; y: 0 } + XyPoint { x: 8; y: 0 } + XyPoint { x: 9; y: 0 } + XyPoint { x: 10; y: 0 } + XyPoint { x: 11; y: 1 } + } + lowerSeries: LineSeries { + XyPoint { x: 0; y: 0 } + XyPoint { x: 1; y: 0 } + XyPoint { x: 2; y: 0 } + XyPoint { x: 3; y: 0 } + XyPoint { x: 4; y: 0 } + XyPoint { x: 5; y: 0 } + XyPoint { x: 6; y: 0 } + XyPoint { x: 7; y: 0 } + XyPoint { x: 8; y: 0 } + XyPoint { x: 9; y: 0 } + XyPoint { x: 10; y: 0 } + XyPoint { x: 11; y: 0 } + } } } - - ChartModel { - id: chartModel - ChartModelElement { values: [0, 0, 1, 1, 0] } - ChartModelElement { values: [1, 0, 1, 1, 0] } - ChartModelElement { values: [2, 0, 1, 3, 0] } - ChartModelElement { values: [3, 0, 1, 3, 0] } - ChartModelElement { values: [4, 0, 1, 2, 0] } - ChartModelElement { values: [5, 0, 0, 0, 0] } - ChartModelElement { values: [6, 0, 1, 2, 1] } - ChartModelElement { values: [7, 0, 1, 1, 0] } - ChartModelElement { values: [8, 0, 4, 2, 0] } - ChartModelElement { values: [9, 0, 3, 1, 0] } - ChartModelElement { values: [10, 0, 2, 3, 0] } - ChartModelElement { values: [11, 0, 1, 3, 1] } - } } diff --git a/demos/qmlchart/qml/qmlchart/View4.qml b/demos/qmlchart/qml/qmlchart/View4.qml index a2223f5..2c54a88 100644 --- a/demos/qmlchart/qml/qmlchart/View4.qml +++ b/demos/qmlchart/qml/qmlchart/View4.qml @@ -40,6 +40,7 @@ Rectangle { XyPoint { x: 2.1; y: 1.3 } XyPoint { x: 2.5; y: 2.1 } } + ScatterSeries { name: "Scatter2" XyPoint { x: 2.0; y: 2.0 } diff --git a/demos/qmlchart/qml/qmlchart/View5.qml b/demos/qmlchart/qml/qmlchart/View5.qml index a22abc7..24cc799 100644 --- a/demos/qmlchart/qml/qmlchart/View5.qml +++ b/demos/qmlchart/qml/qmlchart/View5.qml @@ -29,6 +29,7 @@ Rectangle { anchors.fill: parent theme: ChartView.ChartThemeLight legend: ChartView.LegendBottom + // TODO: labels defined by x-axis, not by bar series // axisXLabels: ["0", "2008", "1", "2009", "2", "2010", "3", "2012"] axisX.max: 10 @@ -38,21 +39,5 @@ Rectangle { BarSet { name: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { name: "James"; values: [3, 5, 8, 13, 5, 8] } } - - // TODO: optional syntax with ChartModel base model API -// BarSeries { -// model: chartModel -// modelMapping: BarSeriesMapping { -// ? -// startIndex: 0 // defaults to 0 -// count: BarSeriesMapping.Undefined // defaults to "Undefined" -// } -// } -// ChartModel { -// id: chartModel -// ChartModelElement { values: ["Bob", 2, 2, 3, 4, 5, 6] } -// ChartModelElement { values: ["Susan", 5, 1, 2, 4, 1, 7] } -// ChartModelElement { values: ["James", 3, 5, 8, 13, 5, 8] } -// } } } diff --git a/demos/qmlcustommodel/main.cpp b/demos/qmlcustommodel/main.cpp new file mode 100644 index 0000000..600b5f3 --- /dev/null +++ b/demos/qmlcustommodel/main.cpp @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "qmlapplicationviewer.h" + +Q_DECL_EXPORT int main(int argc, char *argv[]) +{ + QScopedPointer app(createApplication(argc, argv)); + QScopedPointer viewer(QmlApplicationViewer::create()); + + viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); + viewer->setSource(QUrl("qrc:/qml/qmlcustommodel/loader.qml")); + viewer->showExpanded(); + + return app->exec(); +} diff --git a/demos/qmlcustommodel/qml/qmlcustommodel/loader.qml b/demos/qmlcustommodel/qml/qmlcustommodel/loader.qml new file mode 100644 index 0000000..7668f0c --- /dev/null +++ b/demos/qmlcustommodel/qml/qmlcustommodel/loader.qml @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 + +Item { + id: container + width: 400 + height: 300 + Component.onCompleted: { + var co = Qt.createComponent("main.qml") + if (co.status == Component.Ready) { + var o = co.createObject(container) + } else { + console.log(co.errorString()) + console.log("QtCommercial.Chart 1.1 not available") + console.log("Please use correct QML_IMPORT_PATH export") + } + } +} diff --git a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml new file mode 100644 index 0000000..7772916 --- /dev/null +++ b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +Rectangle { + width: parent.width + height: parent.height + + ChartView { + id: chart + title: "Top-5 car brand shares in Finland" + anchors.fill: parent + theme: ChartView.ChartThemeLight + + // For dynamic data you can use the ChartModel API. + ChartModel { + id: chartModel + ChartModelElement { values: [0, "Volkswagen", 13.5] } + ChartModelElement { values: [0, "Toyota", 10.9] } + ChartModelElement { values: [0, "Ford", 8.6] } + ChartModelElement { values: [0, "Skoda", 8.2] } + ChartModelElement { values: [0, "Volvo", 6.8] } + } + + LineSeries { + name: "line" + model: chartModel + modelMapper.mapX: 2 + modelMapper.mapY: 2 + } + + PieSeries { + id: pieSeries + model: chartModel + size: 0.4 + horizontalPosition: 0.2 + verticalPosition: 0.3 + // Define how your data maps to pie slices with the ModelMapper API of the pie series + modelMapper.mapLabels: 1 + modelMapper.mapValues: 2 + modelMapper.first: 0 + modelMapper.count: -1 // "Undefined" = -1 by default + modelMapper.orientation: PieModelMapper.Vertical + } + + AreaSeries { + name: "area" + upperSeries: LineSeries { + model: chartModel + modelMapper.mapX: 2 + modelMapper.mapY: 2 + } + lowerSeries: LineSeries { + model: chartModel + modelMapper.mapX: 2 + modelMapper.mapY: 0 + } + } + + // TODO: BarSeries with ChartModel base model API +// BarSeries { +// model: chartModel +// modelMapper.first: 0 +// } + } + + + // TODO: you could also implement appending to your model, for example: +// pieSeries.model.append(["Others", 52.0]); + + // TODO: show how to use data from a list model in a chart view + // i.e. copy the data into a chart model +// ListModel { +// id: listModel +// ListElement { +// label: "Volkswagen" +// value: 13.5 +// } +// ListElement { +// label: "Toyota" +// value: 10.9 +// } +// // and so on... +// } + +} diff --git a/demos/qmlcustommodel/qmlapplicationviewer/qmlapplicationviewer.cpp b/demos/qmlcustommodel/qmlapplicationviewer/qmlapplicationviewer.cpp new file mode 100644 index 0000000..8ba6e88 --- /dev/null +++ b/demos/qmlcustommodel/qmlapplicationviewer/qmlapplicationviewer.cpp @@ -0,0 +1,200 @@ +// checksum 0x78c version 0x60010 +/* + This file was generated by the Qt Quick Application wizard of Qt Creator. + QmlApplicationViewer is a convenience class containing mobile device specific + code such as screen orientation handling. Also QML paths and debugging are + handled here. + It is recommended not to modify this file, since newer versions of Qt Creator + may offer an updated version of it. +*/ + +#include "qmlapplicationviewer.h" + +#include +#include +#include +#include +#include +#include + +#include // MEEGO_EDITION_HARMATTAN + +#ifdef HARMATTAN_BOOSTER +#include +#endif + +#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 + +#include + +#if !defined(NO_JSDEBUGGER) +#include +#endif +#if !defined(NO_QMLOBSERVER) +#include +#endif + +// Enable debugging before any QDeclarativeEngine is created +struct QmlJsDebuggingEnabler +{ + QmlJsDebuggingEnabler() + { + QDeclarativeDebugHelper::enableDebugging(); + } +}; + +// Execute code in constructor before first QDeclarativeEngine is instantiated +static QmlJsDebuggingEnabler enableDebuggingHelper; + +#endif // QMLJSDEBUGGER + +class QmlApplicationViewerPrivate +{ + QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {} + + QString mainQmlFile; + QDeclarativeView *view; + friend class QmlApplicationViewer; + QString adjustPath(const QString &path); +}; + +QString QmlApplicationViewerPrivate::adjustPath(const QString &path) +{ +#ifdef Q_OS_UNIX +#ifdef Q_OS_MAC + if (!QDir::isAbsolutePath(path)) + return QCoreApplication::applicationDirPath() + + QLatin1String("/../Resources/") + path; +#else + QString pathInInstallDir; + const QString applicationDirPath = QCoreApplication::applicationDirPath(); + pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path); + + if (QFileInfo(pathInInstallDir).exists()) + return pathInInstallDir; +#endif +#endif + return path; +} + +QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) + : QDeclarativeView(parent) + , d(new QmlApplicationViewerPrivate(this)) +{ + connect(engine(), SIGNAL(quit()), SLOT(close())); + setResizeMode(QDeclarativeView::SizeRootObjectToView); + // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in +#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 +#if !defined(NO_JSDEBUGGER) + new QmlJSDebugger::JSDebuggerAgent(d->view->engine()); +#endif +#if !defined(NO_QMLOBSERVER) + new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view); +#endif +#endif +} + +QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent) + : QDeclarativeView(parent) + , d(new QmlApplicationViewerPrivate(view)) +{ + connect(view->engine(), SIGNAL(quit()), view, SLOT(close())); + view->setResizeMode(QDeclarativeView::SizeRootObjectToView); + // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in +#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 +#if !defined(NO_JSDEBUGGER) + new QmlJSDebugger::JSDebuggerAgent(d->view->engine()); +#endif +#if !defined(NO_QMLOBSERVER) + new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view); +#endif +#endif +} + +QmlApplicationViewer::~QmlApplicationViewer() +{ + delete d; +} + +QmlApplicationViewer *QmlApplicationViewer::create() +{ +#ifdef HARMATTAN_BOOSTER + return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0); +#else + return new QmlApplicationViewer(); +#endif +} + +void QmlApplicationViewer::setMainQmlFile(const QString &file) +{ + d->mainQmlFile = d->adjustPath(file); + d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile)); +} + +void QmlApplicationViewer::addImportPath(const QString &path) +{ + d->view->engine()->addImportPath(d->adjustPath(path)); +} + +void QmlApplicationViewer::setOrientation(ScreenOrientation orientation) +{ +#if defined(Q_OS_SYMBIAN) + // If the version of Qt on the device is < 4.7.2, that attribute won't work + if (orientation != ScreenOrientationAuto) { + const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.')); + if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) { + qWarning("Screen orientation locking only supported with Qt 4.7.2 and above"); + return; + } + } +#endif // Q_OS_SYMBIAN + + Qt::WidgetAttribute attribute; + switch (orientation) { +#if QT_VERSION < 0x040702 + // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes + case ScreenOrientationLockPortrait: + attribute = static_cast(128); + break; + case ScreenOrientationLockLandscape: + attribute = static_cast(129); + break; + default: + case ScreenOrientationAuto: + attribute = static_cast(130); + break; +#else // QT_VERSION < 0x040702 + case ScreenOrientationLockPortrait: + attribute = Qt::WA_LockPortraitOrientation; + break; + case ScreenOrientationLockLandscape: + attribute = Qt::WA_LockLandscapeOrientation; + break; + default: + case ScreenOrientationAuto: + attribute = Qt::WA_AutoOrientation; + break; +#endif // QT_VERSION < 0x040702 + }; + setAttribute(attribute, true); +} + +void QmlApplicationViewer::showExpanded() +{ +#if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR) + d->view->showFullScreen(); +#elif defined(Q_WS_MAEMO_5) + d->view->showMaximized(); +#else + d->view->show(); +#endif +} + +QApplication *createApplication(int &argc, char **argv) +{ +#ifdef HARMATTAN_BOOSTER + return MDeclarativeCache::qApplication(argc, argv); +#else + return new QApplication(argc, argv); +#endif +} diff --git a/demos/qmlcustommodel/qmlapplicationviewer/qmlapplicationviewer.h b/demos/qmlcustommodel/qmlapplicationviewer/qmlapplicationviewer.h new file mode 100644 index 0000000..f8008f5 --- /dev/null +++ b/demos/qmlcustommodel/qmlapplicationviewer/qmlapplicationviewer.h @@ -0,0 +1,47 @@ +// checksum 0x82ed version 0x60010 +/* + This file was generated by the Qt Quick Application wizard of Qt Creator. + QmlApplicationViewer is a convenience class containing mobile device specific + code such as screen orientation handling. Also QML paths and debugging are + handled here. + It is recommended not to modify this file, since newer versions of Qt Creator + may offer an updated version of it. +*/ + +#ifndef QMLAPPLICATIONVIEWER_H +#define QMLAPPLICATIONVIEWER_H + +#include + +class QmlApplicationViewer : public QDeclarativeView +{ + Q_OBJECT + +public: + enum ScreenOrientation { + ScreenOrientationLockPortrait, + ScreenOrientationLockLandscape, + ScreenOrientationAuto + }; + + explicit QmlApplicationViewer(QWidget *parent = 0); + virtual ~QmlApplicationViewer(); + + static QmlApplicationViewer *create(); + + void setMainQmlFile(const QString &file); + void addImportPath(const QString &path); + + // Note that this will only have an effect on Symbian and Fremantle. + void setOrientation(ScreenOrientation orientation); + + void showExpanded(); + +private: + explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent); + class QmlApplicationViewerPrivate *d; +}; + +QApplication *createApplication(int &argc, char **argv); + +#endif // QMLAPPLICATIONVIEWER_H diff --git a/demos/qmlcustommodel/qmlapplicationviewer/qmlapplicationviewer.pri b/demos/qmlcustommodel/qmlapplicationviewer/qmlapplicationviewer.pri new file mode 100644 index 0000000..567c6dc --- /dev/null +++ b/demos/qmlcustommodel/qmlapplicationviewer/qmlapplicationviewer.pri @@ -0,0 +1,13 @@ +QT += declarative + +SOURCES += $$PWD/qmlapplicationviewer.cpp +HEADERS += $$PWD/qmlapplicationviewer.h +INCLUDEPATH += $$PWD + +# Include JS debugger library if QMLJSDEBUGGER_PATH is set +!isEmpty(QMLJSDEBUGGER_PATH) { + include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri) +} else { + DEFINES -= QMLJSDEBUGGER +} + diff --git a/demos/qmlcustommodel/qmlchart.svg b/demos/qmlcustommodel/qmlchart.svg new file mode 100644 index 0000000..566acfa --- /dev/null +++ b/demos/qmlcustommodel/qmlchart.svg @@ -0,0 +1,93 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/demos/qmlcustommodel/qmlcustommodel.pro b/demos/qmlcustommodel/qmlcustommodel.pro new file mode 100644 index 0000000..394db8f --- /dev/null +++ b/demos/qmlcustommodel/qmlcustommodel.pro @@ -0,0 +1,10 @@ +!include( ../demos.pri ) { + error( "Couldn't find the demos.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp + +include(qmlapplicationviewer/qmlapplicationviewer.pri) + +!system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_DEMOS_BIN_DIR" diff --git a/demos/qmlcustommodel/resources.qrc b/demos/qmlcustommodel/resources.qrc new file mode 100644 index 0000000..7effbf4 --- /dev/null +++ b/demos/qmlcustommodel/resources.qrc @@ -0,0 +1,6 @@ + + + qml/qmlcustommodel/loader.qml + qml/qmlcustommodel/main.qml + + diff --git a/plugins/declarative/declarativeareaseries.cpp b/plugins/declarative/declarativeareaseries.cpp index 939858b..62adf04 100644 --- a/plugins/declarative/declarativeareaseries.cpp +++ b/plugins/declarative/declarativeareaseries.cpp @@ -26,67 +26,28 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : - QAreaSeries(new QLineSeries(parent), new QLineSeries(parent)) + QAreaSeries(parent) { - QXYModelMapper *upperMapper = new QXYModelMapper(upperSeries()); - upperMapper->setMapX(0); - upperMapper->setMapY(1); - upperMapper->setFirst(0); - upperMapper->setCount(-1); - upperMapper->setOrientation(Qt::Vertical); - upperSeries()->setModelMapper(upperMapper); - - QXYModelMapper *lowerMapper = new QXYModelMapper(lowerSeries()); - lowerMapper->setMapX(2); - lowerMapper->setMapY(3); - lowerMapper->setFirst(0); - lowerMapper->setCount(-1); - lowerMapper->setOrientation(Qt::Vertical); - lowerSeries()->setModelMapper(lowerMapper); -} - -bool DeclarativeAreaSeries::setDeclarativeUpperModel(DeclarativeTableModel *model) -{ - QAbstractItemModel *m = qobject_cast(model); - bool value(false); - if (m) { - upperSeries()->setModel(m); - } else { - qWarning("DeclarativeAreaSeries: Illegal model"); - } - return value; -} - -DeclarativeTableModel *DeclarativeAreaSeries::declarativeUpperModel() -{ - return qobject_cast(upperSeries()->model()); } -bool DeclarativeAreaSeries::setDeclarativeLowerModel(DeclarativeTableModel *model) +void DeclarativeAreaSeries::setUpperSeries(DeclarativeLineSeries* series) { - QAbstractItemModel *m = qobject_cast(model); - bool value(false); - if (m) { - lowerSeries()->setModel(m); - } else { - qWarning("DeclarativeAreaSeries: Illegal model"); - } - return value; + QAreaSeries::setUpperSeries(series); } -DeclarativeTableModel *DeclarativeAreaSeries::declarativeLowerModel() +DeclarativeLineSeries* DeclarativeAreaSeries::upperSeries() const { - return qobject_cast(lowerSeries()->model()); + return qobject_cast(QAreaSeries::upperSeries()); } -QXYModelMapper* DeclarativeAreaSeries::upperModelMapper() const +void DeclarativeAreaSeries::setLowerSeries(DeclarativeLineSeries* series) { - return upperSeries()->modelMapper(); + QAreaSeries::setLowerSeries(series); } -QXYModelMapper* DeclarativeAreaSeries::lowerModelMapper() const +DeclarativeLineSeries* DeclarativeAreaSeries::lowerSeries() const { - return lowerSeries()->modelMapper(); + return qobject_cast(QAreaSeries::lowerSeries()); } #include "moc_declarativeareaseries.cpp" diff --git a/plugins/declarative/declarativeareaseries.h b/plugins/declarative/declarativeareaseries.h index 2773ece..2f78381 100644 --- a/plugins/declarative/declarativeareaseries.h +++ b/plugins/declarative/declarativeareaseries.h @@ -30,10 +30,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class DeclarativeAreaSeries : public QAreaSeries { Q_OBJECT - Q_PROPERTY(DeclarativeTableModel *upperModel READ declarativeUpperModel WRITE setDeclarativeUpperModel) - Q_PROPERTY(DeclarativeTableModel *lowerModel READ declarativeLowerModel WRITE setDeclarativeLowerModel) - Q_PROPERTY(QXYModelMapper *upperModelMapper READ upperModelMapper) - Q_PROPERTY(QXYModelMapper *lowerModelMapper READ lowerModelMapper) + Q_PROPERTY(DeclarativeLineSeries *upperSeries READ upperSeries WRITE setUpperSeries) + Q_PROPERTY(DeclarativeLineSeries *lowerSeries READ lowerSeries WRITE setLowerSeries) public: explicit DeclarativeAreaSeries(QObject *parent = 0); @@ -45,6 +43,11 @@ public: DeclarativeTableModel *declarativeLowerModel(); QXYModelMapper* upperModelMapper() const; QXYModelMapper* lowerModelMapper() const; +public: + void setUpperSeries(DeclarativeLineSeries* series); + DeclarativeLineSeries* upperSeries() const; + void setLowerSeries(DeclarativeLineSeries* series); + DeclarativeLineSeries* lowerSeries() const; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index b471cf3..d9f29d6 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -61,7 +61,6 @@ void DeclarativeBarSeries::componentComplete() { foreach(QObject *child, children()) { if (qobject_cast(child)) { - qDebug() << "append bar set:" << child; QBarSeries::append(qobject_cast(child)); } } diff --git a/plugins/declarative/declarativelineseries.cpp b/plugins/declarative/declarativelineseries.cpp index 9b371e0..82a2378 100644 --- a/plugins/declarative/declarativelineseries.cpp +++ b/plugins/declarative/declarativelineseries.cpp @@ -30,6 +30,21 @@ DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : { } +QDeclarativeListProperty DeclarativeLineSeries::declarativeChildren() +{ + return QDeclarativeListProperty(this, 0, &appendDeclarativeChildren); +} + +void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element) +{ + QXYSeries *series = qobject_cast(list->object); + DeclarativeXyPoint *point = qobject_cast(element); + if (series && point) { + qDebug() << "DeclarativeScatterSeries::appendDeclarativeChildren:" << *point; + series->append(*point); + } +} + #include "moc_declarativelineseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativelineseries.h b/plugins/declarative/declarativelineseries.h index 3e5cc23..1cabcbd 100644 --- a/plugins/declarative/declarativelineseries.h +++ b/plugins/declarative/declarativelineseries.h @@ -32,9 +32,15 @@ class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries { Q_OBJECT Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) + Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) + Q_CLASSINFO("DefaultProperty", "declarativeChildren") public: explicit DeclarativeLineSeries(QObject *parent = 0); + QDeclarativeListProperty declarativeChildren(); + +public Q_SLOTS: + static void appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativepieseries.cpp b/plugins/declarative/declarativepieseries.cpp index e3a87f7..ee98e13 100644 --- a/plugins/declarative/declarativepieseries.cpp +++ b/plugins/declarative/declarativepieseries.cpp @@ -69,6 +69,15 @@ QPieSlice *DeclarativePieSeries::at(int index) return 0; } +QPieSlice* DeclarativePieSeries::find(QString label) +{ + foreach (QPieSlice *slice, slices()) { + if (slice->label() == label) + return slice; + } + return 0; +} + QPieSlice* DeclarativePieSeries::append(QString name, qreal value) { // TODO: parameter order is wrong, switch it: diff --git a/plugins/declarative/declarativepieseries.h b/plugins/declarative/declarativepieseries.h index bcb03c5..5e0da11 100644 --- a/plugins/declarative/declarativepieseries.h +++ b/plugins/declarative/declarativepieseries.h @@ -48,7 +48,8 @@ public: DeclarativeTableModel *pieModel(); void setPieModel(DeclarativeTableModel *model); Q_INVOKABLE QPieSlice *at(int index); - Q_INVOKABLE QPieSlice* append(QString name, qreal value); + Q_INVOKABLE QPieSlice* find(QString label); + Q_INVOKABLE QPieSlice* append(QString label, qreal value); public: void classBegin(); diff --git a/plugins/declarative/declarativescatterseries.cpp b/plugins/declarative/declarativescatterseries.cpp index 12ff185..dd5eb6c 100644 --- a/plugins/declarative/declarativescatterseries.cpp +++ b/plugins/declarative/declarativescatterseries.cpp @@ -37,9 +37,10 @@ QDeclarativeListProperty DeclarativeScatterSeries::declarativeChildren( void DeclarativeScatterSeries::appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element) { - DeclarativeScatterSeries *series = qobject_cast(list->object); - if (series && qobject_cast(element)) - series->declarativeModel()->appendPoint(series->modelMapper(), qobject_cast(element)); + QXYSeries *series = qobject_cast(list->object); + DeclarativeXyPoint *point = qobject_cast(element); + if (series && point) + series->append(*point); } #include "moc_declarativescatterseries.cpp" diff --git a/plugins/declarative/declarativesplineseries.cpp b/plugins/declarative/declarativesplineseries.cpp index 2ba89e3..dfa05b6 100644 --- a/plugins/declarative/declarativesplineseries.cpp +++ b/plugins/declarative/declarativesplineseries.cpp @@ -29,6 +29,20 @@ DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : { } +QDeclarativeListProperty DeclarativeSplineSeries::declarativeChildren() +{ + return QDeclarativeListProperty(this, 0, &appendDeclarativeChildren); +} + +void DeclarativeSplineSeries::appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element) +{ + QXYSeries *series = qobject_cast(list->object); + DeclarativeXyPoint *point = qobject_cast(element); + if (series && point) { + qDebug() << "DeclarativeScatterSeries::appendDeclarativeChildren:" << *point; + series->append(*point); + } +} #include "moc_declarativesplineseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativesplineseries.h b/plugins/declarative/declarativesplineseries.h index cc9f5b4..955da1e 100644 --- a/plugins/declarative/declarativesplineseries.h +++ b/plugins/declarative/declarativesplineseries.h @@ -32,9 +32,15 @@ class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries { Q_OBJECT Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) + Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) + Q_CLASSINFO("DefaultProperty", "declarativeChildren") public: explicit DeclarativeSplineSeries(QObject *parent = 0); + QDeclarativeListProperty declarativeChildren(); + +public Q_SLOTS: + static void appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativexyseries.cpp b/plugins/declarative/declarativexyseries.cpp index a33a6f3..d94a36c 100644 --- a/plugins/declarative/declarativexyseries.cpp +++ b/plugins/declarative/declarativexyseries.cpp @@ -31,8 +31,7 @@ DeclarativeXySeries::DeclarativeXySeries() { // All the inherited objects must be of type QXYSeries, so it is safe to cast QXYSeries *series = reinterpret_cast(this); - // TODO: set default model on init? - series->setModel(new DeclarativeTableModel()); + // TODO: mapper should be available on the series by default QXYModelMapper *mapper = new QXYModelMapper(series); mapper->setMapX(0); mapper->setMapY(1); diff --git a/src/areachart/qareaseries.cpp b/src/areachart/qareaseries.cpp index 93c5fc9..d18345a 100644 --- a/src/areachart/qareaseries.cpp +++ b/src/areachart/qareaseries.cpp @@ -109,6 +109,14 @@ QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) } /*! + Constructs area series object without upper or lower series. +*/ +QAreaSeries::QAreaSeries(QObject *parent) + : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) +{ +} + +/*! Destroys the object. Series added to QChartView or QChart instances are owned by those, and are deleted when mentioned object are destroyed. */ @@ -122,12 +130,24 @@ QAbstractSeries::SeriesType QAreaSeries::type() const return QAbstractSeries::SeriesTypeArea; } +void QAreaSeries::setUpperSeries(QLineSeries* series) +{ + Q_D(QAreaSeries); + d->m_upperSeries = series; +} + QLineSeries* QAreaSeries::upperSeries() const { Q_D(const QAreaSeries); return d->m_upperSeries; } +void QAreaSeries::setLowerSeries(QLineSeries* series) +{ + Q_D(QAreaSeries); + d->m_lowerSeries = series; +} + QLineSeries* QAreaSeries::lowerSeries() const { Q_D(const QAreaSeries); diff --git a/src/areachart/qareaseries.h b/src/areachart/qareaseries.h index bd14938..b658486 100644 --- a/src/areachart/qareaseries.h +++ b/src/areachart/qareaseries.h @@ -34,13 +34,16 @@ class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QAbstractSeries { Q_OBJECT public: + explicit QAreaSeries(QObject *parent = 0); explicit QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries = 0); ~QAreaSeries(); public: QAbstractSeries::SeriesType type() const; + void setUpperSeries(QLineSeries* series); QLineSeries* upperSeries() const; + void setLowerSeries(QLineSeries* series); QLineSeries* lowerSeries() const; void setPen(const QPen &pen);