From 5664856ed1d470dc96be1dd7ab0ec2680e47bd02 2012-05-28 13:09:21 From: Tero Ahola Date: 2012-05-28 13:09:21 Subject: [PATCH] App for demonstrating QML customization apis --- diff --git a/demos/demos.pro b/demos/demos.pro index d392a29..ce22c87 100644 --- a/demos/demos.pro +++ b/demos/demos.pro @@ -10,4 +10,5 @@ SUBDIRS += chartthemes \ qmlchart \ qmlweather \ qmlf1legends \ + qmlcustomizations \ qmlcustommodel diff --git a/demos/qmlcustomizations/main.cpp b/demos/qmlcustomizations/main.cpp new file mode 100644 index 0000000..adb8f56 --- /dev/null +++ b/demos/qmlcustomizations/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/qmlcustomizations/loader.qml")); + viewer->showExpanded(); + + return app->exec(); +} diff --git a/demos/qmlcustomizations/qml/qmlcustomizations/View1.qml b/demos/qmlcustomizations/qml/qmlcustomizations/View1.qml new file mode 100644 index 0000000..7d99670 --- /dev/null +++ b/demos/qmlcustomizations/qml/qmlcustomizations/View1.qml @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** 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 { + anchors.fill: parent + + ChartView { + id: chart + title: "Top-5 car brand shares in Finland" + anchors.fill: parent + theme: ChartView.ChartThemeLight + legend: ChartView.LegendBottom + animationOptions: ChartView.SeriesAnimations + + PieSeries { + id: pieSeries + PieSlice { label: "Volkswagen"; value: 13.5 } + PieSlice { label: "Toyota"; value: 10.9 } + PieSlice { label: "Ford"; value: 8.6 } + PieSlice { label: "Skoda"; value: 8.2 } + PieSlice { label: "Volvo"; value: 6.8 } + } + } +} diff --git a/demos/qmlcustomizations/qml/qmlcustomizations/loader.qml b/demos/qmlcustomizations/qml/qmlcustomizations/loader.qml new file mode 100644 index 0000000..7668f0c --- /dev/null +++ b/demos/qmlcustomizations/qml/qmlcustomizations/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/qmlcustomizations/qml/qmlcustomizations/main.qml b/demos/qmlcustomizations/qml/qmlcustomizations/main.qml new file mode 100644 index 0000000..c8ae550 --- /dev/null +++ b/demos/qmlcustomizations/qml/qmlcustomizations/main.qml @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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 + property int __activeIndex: 1 + property real __intervalCoefficient: 0 + + + ChartView { + id: chartView + anchors.fill: parent + title: "Wheel of fortune" + legend: ChartView.LegendDisabled + + PieSeries { + id: wheelOfFortune + } + + SplineSeries { + id: splineSeries + } + + ScatterSeries { + id: scatterSeries + } + } + + + Component.onCompleted: { + __intervalCoefficient = Math.random() + 0.1; + console.log("__intervalCoefficient: " + __intervalCoefficient); + + for (var i = 0; i < 20; i++) + wheelOfFortune.append("", 1); + + var interval = 1; + for (var j = 0; interval < 800; j++) { + interval = __intervalCoefficient * j * j; + splineSeries.append(j, interval); + } + chartView.axisX.max = j; + chartView.axisY.max = 1000; + } + + Timer { + triggeredOnStart: true + running: true + repeat: true + interval: 100 + onTriggered: { +// console.log("interval: " + interval); + var index = __activeIndex % wheelOfFortune.count; + if (interval < 700) { + scatterSeries.clear(); + wheelOfFortune.at(index).exploded = false; + __activeIndex++; + index = __activeIndex % wheelOfFortune.count; + wheelOfFortune.at(index).exploded = true; + interval = splineSeries.at(__activeIndex).y; + scatterSeries.append(__activeIndex, interval); + } else { + // Switch the colors of the slice and the border + wheelOfFortune.at(index).borderWidth = 2; + var borderColor = wheelOfFortune.at(index).borderColor; + wheelOfFortune.at(index).borderColor = wheelOfFortune.at(index).color; + wheelOfFortune.at(index).color = borderColor; + } + } + } + +// Loader { +// id: loader +// anchors.fill: parent +// source: "View" + (__viewNumber % 5 + 1) + ".qml"; +// } +} diff --git a/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.cpp b/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.cpp new file mode 100644 index 0000000..8ba6e88 --- /dev/null +++ b/demos/qmlcustomizations/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/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.h b/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.h new file mode 100644 index 0000000..f8008f5 --- /dev/null +++ b/demos/qmlcustomizations/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/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.pri b/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.pri new file mode 100644 index 0000000..567c6dc --- /dev/null +++ b/demos/qmlcustomizations/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/qmlcustomizations/qmlcustomizations.pro b/demos/qmlcustomizations/qmlcustomizations.pro new file mode 100644 index 0000000..394db8f --- /dev/null +++ b/demos/qmlcustomizations/qmlcustomizations.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/qmlcustomizations/resources.qrc b/demos/qmlcustomizations/resources.qrc new file mode 100644 index 0000000..e32c350 --- /dev/null +++ b/demos/qmlcustomizations/resources.qrc @@ -0,0 +1,7 @@ + + + qml/qmlcustomizations/loader.qml + qml/qmlcustomizations/main.qml + qml/qmlcustomizations/View1.qml + + diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index a8426a3..e6a5bcb 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -71,25 +71,6 @@ QDeclarativeListProperty DeclarativeBarSeries::initialBarSets return QDeclarativeListProperty(this, 0, &DeclarativeBarSeries::appendInitialBarSets); } -bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeTableModel *model) -{ - QAbstractItemModel *m = qobject_cast(model); - bool value(false); - if (m) { -// setModel(m); - //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); -// setModelMapping(0, 1, 1, Qt::Vertical); - } else { - qWarning("DeclarativeBarSeries: Illegal model"); - } - return value; -} - -DeclarativeTableModel *DeclarativeBarSeries::declarativeModel() -{ - return 0;//qobject_cast(model()); -} - void DeclarativeBarSeries::setBarCategories(QStringList categories) { setCategories(categories); @@ -123,25 +104,6 @@ QDeclarativeListProperty DeclarativeGroupedBarSeries::initial return QDeclarativeListProperty(this, 0, &DeclarativeGroupedBarSeries::appendInitialBarSets); } -bool DeclarativeGroupedBarSeries::setDeclarativeModel(DeclarativeTableModel *model) -{ - QAbstractItemModel *m = qobject_cast(model); - bool value(false); - if (m) { -// setModel(m); - //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); -// setModelMapping(0, 1, 1, Qt::Vertical); - } else { - qWarning("DeclarativeGroupedBarSeries: Illegal model"); - } - return value; -} - -DeclarativeTableModel *DeclarativeGroupedBarSeries::declarativeModel() -{ - return 0; //qobject_cast(model()); -} - void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories) { setCategories(categories); diff --git a/plugins/declarative/declarativebarseries.h b/plugins/declarative/declarativebarseries.h index e7f74b2..7b0f0de 100644 --- a/plugins/declarative/declarativebarseries.h +++ b/plugins/declarative/declarativebarseries.h @@ -51,7 +51,6 @@ class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) Q_PROPERTY(QDeclarativeListProperty initialBarSets READ initialBarSets) Q_CLASSINFO("DefaultProperty", "initialBarSets") @@ -67,10 +66,6 @@ public: // from QDeclarativeParserStatus void classBegin(); void componentComplete(); -public: - bool setDeclarativeModel(DeclarativeTableModel *model); - DeclarativeTableModel *declarativeModel(); - public Q_SLOTS: static void appendInitialBarSets(QDeclarativeListProperty * /*list*/, DeclarativeBarSet * /*element*/) {} }; @@ -79,7 +74,6 @@ class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativ { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) Q_PROPERTY(QDeclarativeListProperty initialBarSets READ initialBarSets) Q_CLASSINFO("DefaultProperty", "initialBarSets") @@ -95,8 +89,6 @@ public: // from QDeclarativeParserStatus public: void setBarCategories(QStringList categories); QStringList barCategories(); - bool setDeclarativeModel(DeclarativeTableModel *model); - DeclarativeTableModel *declarativeModel(); public Q_SLOTS: static void appendInitialBarSets(QDeclarativeListProperty * /*list*/, DeclarativeBarSet * /*element*/) {} diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index 5d5ca72..4745afc 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -57,6 +57,7 @@ void DeclarativeChart::componentComplete() // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max(); foreach(QObject *child, children()) { if (qobject_cast(child)) { +// qDebug() << "DeclarativeChart::componentComplete(), add: " << child; m_chart->addSeries(qobject_cast(child)); } } diff --git a/plugins/declarative/declarativelineseries.h b/plugins/declarative/declarativelineseries.h index be5227d..356ff31 100644 --- a/plugins/declarative/declarativelineseries.h +++ b/plugins/declarative/declarativelineseries.h @@ -32,7 +32,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries { Q_OBJECT - Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) Q_CLASSINFO("DefaultProperty", "declarativeChildren") @@ -45,6 +44,7 @@ public: // from QLineSeries Q_INVOKABLE void append(qreal x, qreal y) { QLineSeries::append(x, y); } Q_INVOKABLE void remove(qreal x, qreal y) { QLineSeries::remove(x, y); } Q_INVOKABLE void clear() { QLineSeries::removeAll(); } + Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } public Q_SLOTS: static void appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element); diff --git a/plugins/declarative/declarativepieseries.cpp b/plugins/declarative/declarativepieseries.cpp index 42c04cb..9744c6e 100644 --- a/plugins/declarative/declarativepieseries.cpp +++ b/plugins/declarative/declarativepieseries.cpp @@ -27,6 +27,47 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE +DeclarativePieSlice::DeclarativePieSlice(QObject *parent) : + QPieSlice(parent) +{ +} + +QColor DeclarativePieSlice::color() +{ + return brush().color(); +} + +void DeclarativePieSlice::setColor(QColor color) +{ + QBrush b = brush(); + b.setColor(color); + setBrush(b); +} + +QColor DeclarativePieSlice::borderColor() +{ + return pen().color(); +} + +void DeclarativePieSlice::setBorderColor(QColor color) +{ + QPen p = pen(); + p.setColor(color); + setPen(p); +} + +int DeclarativePieSlice::borderWidth() +{ + return pen().width(); +} + +void DeclarativePieSlice::setBorderWidth(int width) +{ + QPen p = pen(); + p.setWidth(width); + setPen(p); +} + DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : QPieSeries(parent) { @@ -39,8 +80,8 @@ void DeclarativePieSeries::classBegin() void DeclarativePieSeries::componentComplete() { foreach(QObject *child, children()) { - if (qobject_cast(child)) { - QPieSeries::append(qobject_cast(child)); + if (qobject_cast(child)) { + QPieSeries::append(qobject_cast(child)); } else if(qobject_cast(child)) { QVPieModelMapper *mapper = qobject_cast(child); mapper->setSeries(this); @@ -63,43 +104,32 @@ void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty sliceList = slices(); if (index < sliceList.count()) - return sliceList[index]; + return qobject_cast(sliceList[index]); return 0; } -QPieSlice* DeclarativePieSeries::find(QString label) +DeclarativePieSlice* DeclarativePieSeries::find(QString label) { foreach (QPieSlice *slice, slices()) { if (slice->label() == label) - return slice; + return qobject_cast(slice); } return 0; } -QPieSlice* DeclarativePieSeries::append(QString name, qreal value) +DeclarativePieSlice* DeclarativePieSeries::append(QString label, qreal value) { // TODO: parameter order is wrong, switch it: - return QPieSeries::append(name, value); -} - -void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model) -{ - QAbstractItemModel *m = qobject_cast(model); - if (m) { -// QPieSeries::setModel(m); - } else { - qWarning("DeclarativePieSeries: Illegal model"); - } -} - -DeclarativeTableModel *DeclarativePieSeries::pieModel() -{ - return 0;//qobject_cast(model()); + DeclarativePieSlice *slice = new DeclarativePieSlice(this); + slice->setLabel(label); + slice->setValue(value); + QPieSeries::append(slice); + return slice; } #include "moc_declarativepieseries.cpp" diff --git a/plugins/declarative/declarativepieseries.h b/plugins/declarative/declarativepieseries.h index 5c02821..c10e01f 100644 --- a/plugins/declarative/declarativepieseries.h +++ b/plugins/declarative/declarativepieseries.h @@ -33,22 +33,36 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class QChart; +class DeclarativePieSlice: public QPieSlice +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor) + Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth) + +public: + explicit DeclarativePieSlice(QObject *parent = 0); + QColor color(); + void setColor(QColor color); + QColor borderColor(); + void setBorderColor(QColor color); + int borderWidth(); + void setBorderWidth(int width); +}; + class DeclarativePieSeries : public QPieSeries, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(DeclarativeTableModel *model READ pieModel WRITE setPieModel) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativePieSeries(QObject *parent = 0); QDeclarativeListProperty seriesChildren(); - DeclarativeTableModel *pieModel(); - void setPieModel(DeclarativeTableModel *model); - Q_INVOKABLE QPieSlice *at(int index); - Q_INVOKABLE QPieSlice* find(QString label); - Q_INVOKABLE QPieSlice* append(QString label, qreal value); + Q_INVOKABLE DeclarativePieSlice *at(int index); + Q_INVOKABLE DeclarativePieSlice* find(QString label); + Q_INVOKABLE DeclarativePieSlice* append(QString label, qreal value); public: void classBegin(); diff --git a/plugins/declarative/declarativescatterseries.h b/plugins/declarative/declarativescatterseries.h index 2595639..3053b06 100644 --- a/plugins/declarative/declarativescatterseries.h +++ b/plugins/declarative/declarativescatterseries.h @@ -30,7 +30,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries { Q_OBJECT - Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) Q_CLASSINFO("DefaultProperty", "declarativeChildren") @@ -43,6 +42,7 @@ public: // from QScatterSeries Q_INVOKABLE void append(qreal x, qreal y) { QScatterSeries::append(x, y); } Q_INVOKABLE void remove(qreal x, qreal y) { QScatterSeries::remove(x, y); } Q_INVOKABLE void clear() { QScatterSeries::removeAll(); } + Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } public Q_SLOTS: static void appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element); diff --git a/plugins/declarative/declarativesplineseries.cpp b/plugins/declarative/declarativesplineseries.cpp index 866f6dd..4dcdff5 100644 --- a/plugins/declarative/declarativesplineseries.cpp +++ b/plugins/declarative/declarativesplineseries.cpp @@ -21,6 +21,7 @@ #include "declarativesplineseries.h" #include "declarativechart.h" #include +#include "declarativexypoint.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE diff --git a/plugins/declarative/declarativesplineseries.h b/plugins/declarative/declarativesplineseries.h index 0839262..1e189e2 100644 --- a/plugins/declarative/declarativesplineseries.h +++ b/plugins/declarative/declarativesplineseries.h @@ -31,7 +31,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries { Q_OBJECT - Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) Q_CLASSINFO("DefaultProperty", "declarativeChildren") @@ -44,6 +43,7 @@ public: // from QSplineSeries Q_INVOKABLE void append(qreal x, qreal y) { QSplineSeries::append(x, y); } Q_INVOKABLE void remove(qreal x, qreal y) { QSplineSeries::remove(x, y); } Q_INVOKABLE void clear() { QSplineSeries::removeAll(); } + Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } public Q_SLOTS: static void appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element); diff --git a/plugins/declarative/declarativexypoint.h b/plugins/declarative/declarativexypoint.h index 5228932..be853db 100644 --- a/plugins/declarative/declarativexypoint.h +++ b/plugins/declarative/declarativexypoint.h @@ -31,6 +31,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class DeclarativeXyPoint : public QObject, public QPointF { Q_OBJECT + // TODO: make the setters change the value, if parented by a series Q_PROPERTY(qreal x READ x WRITE setX /*NOTIFY dataXChanged*/) Q_PROPERTY(qreal y READ y WRITE setY /*NOTIFY dataYChanged*/) diff --git a/plugins/declarative/declarativexyseries.cpp b/plugins/declarative/declarativexyseries.cpp index 1ade5b2..cc6d12f 100644 --- a/plugins/declarative/declarativexyseries.cpp +++ b/plugins/declarative/declarativexyseries.cpp @@ -29,45 +29,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeXySeries::DeclarativeXySeries() { - // TODO: XYModelMapper implementation has changed, this code has to be updated - - // All the inherited objects must be of type QXYSeries, so it is safe to cast -// QXYSeries *series = reinterpret_cast(this); -// // TODO: mapper should be available on the series by default -// QXYModelMapper *mapper = new QXYModelMapper(series); -// mapper->setMapX(0); -// mapper->setMapY(1); -// mapper->setFirst(0); -// mapper->setCount(-1); -// mapper->setOrientation(Qt::Vertical); -// series->setModelMapper(mapper); } DeclarativeXySeries::~DeclarativeXySeries() { } -bool DeclarativeXySeries::setDeclarativeModel(DeclarativeTableModel *model) -{ - QAbstractItemModel *m = qobject_cast(model); - bool value(false); - if (m) { - // All the inherited objects must be of type QXYSeries, so it is safe to cast -// QXYSeries *series = reinterpret_cast(this); -// series->setModel(m); - } else { - qWarning("DeclarativeXySeries: Illegal model"); - } - return value; -} - -DeclarativeTableModel *DeclarativeXySeries::declarativeModel() -{ - // All the inherited objects must be of type QXYSeries, so it is safe to cast -// QXYSeries *series = reinterpret_cast(this); - return 0; //qobject_cast(series->model()); -} - QColor DeclarativeXySeries::color() { // All the inherited objects must be of type QXYSeries, so it is safe to cast @@ -83,5 +50,18 @@ void DeclarativeXySeries::setColor(QColor color) series->setPen(pen); } +DeclarativeXyPoint *DeclarativeXySeries::at(int index) +{ + QXYSeries *series = reinterpret_cast(this); + if (index < series->count()) { + QPointF point = series->points().at(index); + DeclarativeXyPoint *xyPoint = new DeclarativeXyPoint(series); + xyPoint->setX(point.x()); + xyPoint->setY(point.y()); + return xyPoint; + } + return 0; +} + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativexyseries.h b/plugins/declarative/declarativexyseries.h index fad9c3a..cfef132 100644 --- a/plugins/declarative/declarativexyseries.h +++ b/plugins/declarative/declarativexyseries.h @@ -37,10 +37,9 @@ public: ~DeclarativeXySeries(); public: - bool setDeclarativeModel(DeclarativeTableModel *model); - DeclarativeTableModel *declarativeModel(); QColor color(); void setColor(QColor color); + DeclarativeXyPoint *at(int index); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index 12ce09b..fb542ee 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -54,7 +54,7 @@ public: qmlRegisterType(uri, 1, 0, "BarSeries"); qmlRegisterType(uri, 1, 0, "GroupedBarSeries"); qmlRegisterType(uri, 1, 0, "PieSeries"); - qmlRegisterType(uri, 1, 0, "PieSlice"); + qmlRegisterType(uri, 1, 0, "PieSlice"); qmlRegisterType(uri, 1, 0, "ChartModel"); qmlRegisterType(uri, 1, 0, "ChartModelElement"); qmlRegisterType(uri, 1, 0, "BarSet");