From dd901eae47dee9305cff3330d28f79f0fbc3e9f8 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 19 Feb 2010 14:10:54 +0100 Subject: Introduced the internal virtual method QmlView::setRootObject(object). Done-with: mae --- src/declarative/util/qmlview.cpp | 96 ++++++++++++++++++++++------------------ src/declarative/util/qmlview.h | 3 +- 2 files changed, 54 insertions(+), 45 deletions(-) diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index 4a6d697..a906554 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -429,52 +429,60 @@ void QmlView::continueExecute() return; } - if (obj) { - if (QmlGraphicsItem *item = qobject_cast(obj)) { - - d->scene.addItem(item); - - QPerformanceLog::displayData(); - QPerformanceLog::clear(); - d->root = item; - d->qmlRoot = item; - connect(item, SIGNAL(widthChanged()), this, SLOT(sizeChanged())); - connect(item, SIGNAL(heightChanged()), this, SLOT(sizeChanged())); - if (d->initialSize.height() <= 0 && d->qmlRoot->width() > 0) - d->initialSize.setWidth(d->qmlRoot->width()); - if (d->initialSize.height() <= 0 && d->qmlRoot->height() > 0) - d->initialSize.setHeight(d->qmlRoot->height()); - resize(d->initialSize); - - if (d->resizeMode == SizeRootObjectToView) { - d->qmlRoot->setWidth(width()); - d->qmlRoot->setHeight(height()); - } else { - QSize sz(d->qmlRoot->width(),d->qmlRoot->height()); - emit sceneResized(sz); - resize(sz); - } - updateGeometry(); - } else if (QGraphicsObject *item = qobject_cast(obj)) { - d->scene.addItem(item); - qWarning() << "QmlView::resizeMode is not honored for components of type QGraphicsObject"; - } else if (QWidget *wid = qobject_cast(obj)) { - window()->setAttribute(Qt::WA_OpaquePaintEvent, false); - window()->setAttribute(Qt::WA_NoSystemBackground, false); - if (!layout()) { - setLayout(new QVBoxLayout); - layout()->setContentsMargins(0, 0, 0, 0); - } else if (layout()->count()) { - // Hide the QGraphicsView in GV mode. - QLayoutItem *item = layout()->itemAt(0); - if (item->widget()) - item->widget()->hide(); - } - layout()->addWidget(wid); - emit sceneResized(wid->size()); + setRootObject(obj); + emit statusChanged(status()); +} + + +/*! + \internal +*/ +void QmlView::setRootObject(QObject *obj) +{ + Q_D(QmlView); + + if (QmlGraphicsItem *item = qobject_cast(obj)) { + d->scene.addItem(item); + + QPerformanceLog::displayData(); + QPerformanceLog::clear(); + d->root = item; + d->qmlRoot = item; + connect(item, SIGNAL(widthChanged()), this, SLOT(sizeChanged())); + connect(item, SIGNAL(heightChanged()), this, SLOT(sizeChanged())); + if (d->initialSize.height() <= 0 && d->qmlRoot->width() > 0) + d->initialSize.setWidth(d->qmlRoot->width()); + if (d->initialSize.height() <= 0 && d->qmlRoot->height() > 0) + d->initialSize.setHeight(d->qmlRoot->height()); + resize(d->initialSize); + + if (d->resizeMode == SizeRootObjectToView) { + d->qmlRoot->setWidth(width()); + d->qmlRoot->setHeight(height()); + } else { + QSize sz(d->qmlRoot->width(),d->qmlRoot->height()); + emit sceneResized(sz); + resize(sz); } + updateGeometry(); + } else if (QGraphicsObject *item = qobject_cast(obj)) { + d->scene.addItem(item); + qWarning() << "QmlView::resizeMode is not honored for components of type QGraphicsObject"; + } else if (QWidget *wid = qobject_cast(obj)) { + window()->setAttribute(Qt::WA_OpaquePaintEvent, false); + window()->setAttribute(Qt::WA_NoSystemBackground, false); + if (!layout()) { + setLayout(new QVBoxLayout); + layout()->setContentsMargins(0, 0, 0, 0); + } else if (layout()->count()) { + // Hide the QGraphicsView in GV mode. + QLayoutItem *item = layout()->itemAt(0); + if (item->widget()) + item->widget()->hide(); + } + layout()->addWidget(wid); + emit sceneResized(wid->size()); } - emit statusChanged(status()); } /*! diff --git a/src/declarative/util/qmlview.h b/src/declarative/util/qmlview.h index 1c6d865..7c9a97b 100644 --- a/src/declarative/util/qmlview.h +++ b/src/declarative/util/qmlview.h @@ -102,7 +102,8 @@ private Q_SLOTS: protected: virtual void resizeEvent(QResizeEvent *); virtual void paintEvent(QPaintEvent *event); - void timerEvent(QTimerEvent*); + virtual void timerEvent(QTimerEvent*); + virtual void setRootObject(QObject *obj); }; QT_END_NAMESPACE -- cgit v0.12 From 94164f66a6f3272e63b2fe12f63fba91d16ab0f0 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 19 Feb 2010 15:21:35 +0100 Subject: Introduced a new parser for qmldir files. --- src/declarative/qml/qml.pri | 6 +- src/declarative/qml/qmldirparser.cpp | 209 +++++++++++++++++++++++++++++++++++ src/declarative/qml/qmldirparser_p.h | 123 +++++++++++++++++++++ src/declarative/qml/qmlengine.cpp | 34 +++--- 4 files changed, 352 insertions(+), 20 deletions(-) create mode 100644 src/declarative/qml/qmldirparser.cpp create mode 100644 src/declarative/qml/qmldirparser_p.h diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index a8df61e..5e0c3e0 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -51,7 +51,8 @@ SOURCES += \ $$PWD/qmllistscriptclass.cpp \ $$PWD/qmlworkerscript.cpp \ $$PWD/qmlimageprovider.cpp \ - $$PWD/qmlnetworkaccessmanagerfactory.cpp + $$PWD/qmlnetworkaccessmanagerfactory.cpp \ + $$PWD/qmldirparser.cpp HEADERS += \ $$PWD/qmlparser_p.h \ $$PWD/qmlglobal_p.h \ @@ -119,7 +120,8 @@ HEADERS += \ $$PWD/qmlscriptclass_p.h \ $$PWD/qmlguard_p.h \ $$PWD/qmlimageprovider.h \ - $$PWD/qmlnetworkaccessmanagerfactory.h + $$PWD/qmlnetworkaccessmanagerfactory.h \ + $$PWD/qmldirparser_p.h QT += sql include(parser/parser.pri) include(rewriter/rewriter.pri) diff --git a/src/declarative/qml/qmldirparser.cpp b/src/declarative/qml/qmldirparser.cpp new file mode 100644 index 0000000..c7de233 --- /dev/null +++ b/src/declarative/qml/qmldirparser.cpp @@ -0,0 +1,209 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmldirparser_p.h" +#include "qmlerror.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +QmlDirParser::QmlDirParser() +{ +} + +QmlDirParser::~QmlDirParser() +{ +} + +QUrl QmlDirParser::url() const +{ + return _url; +} + +void QmlDirParser::setUrl(const QUrl &url) +{ + _url = url; +} + +QString QmlDirParser::source() const +{ + return _source; +} + +void QmlDirParser::setSource(const QString &source) +{ + _source = source; +} + +bool QmlDirParser::parse() +{ + _errors.clear(); + _plugins.clear(); + _components.clear(); + + QTextStream stream(&_source); + int lineNumber = 0; + + forever { + ++lineNumber; + + const QString line = stream.readLine(); + if (line.isNull()) + break; + + QString sections[3]; + int sectionCount = 0; + + int index = 0; + const int length = line.length(); + + while (index != length) { + const QChar ch = line.at(index); + + if (ch.isSpace()) { + do { ++index; } + while (index != length && line.at(index).isSpace()); + + } else if (ch == QLatin1Char('#')) { + // recognized a comment + break; + + } else { + const int start = index; + + do { ++index; } + while (index != length && !line.at(index).isSpace()); + + const QString lexeme = line.mid(start, index - start); + + if (sectionCount >= 3) { + reportError(lineNumber, start, QLatin1String("unexpected token")); + + } else { + sections[sectionCount++] = lexeme; + } + } + } + + if (sectionCount == 0) { + continue; // no sections, no party. + + } else if (sections[0] == QLatin1String("plugin")) { + if (sectionCount < 2) { + reportError(lineNumber, -1, + QString::fromUtf8("plugin directive requires 2 arguments, but %1 were provided").arg(sectionCount + 1)); + + continue; + } + + const Plugin entry(sections[1], sections[2]); + + _plugins.append(entry); + + } else if (sectionCount == 3) { + const QString &version = sections[1]; + const int dotIndex = version.indexOf(QLatin1Char('.')); + + if (dotIndex == -1) { + qWarning() << "expected '.'"; // ### use reportError + + } else if (version.indexOf(QLatin1Char('.'), dotIndex + 1) != -1) { + qWarning() << "unexpected '.'"; // ### use reportError + + } else { + bool validVersionNumber = false; + const int majorVersion = version.left(dotIndex).toInt(&validVersionNumber); + + if (validVersionNumber) { + const int minorVersion = version.mid(dotIndex + 1).toInt(&validVersionNumber); + + if (validVersionNumber) { + const Component entry(sections[0], sections[2], majorVersion, minorVersion); + + _components.append(entry); + } + } + } + } else { + // ### use reportError + qWarning() << "a component declaration requires 3 arguments, but" << (sectionCount + 1) << "were provided"; + } + } + + return hasError(); +} + +void QmlDirParser::reportError(int line, int column, const QString &description) +{ + QmlError error; + error.setUrl(_url); + error.setLine(line); + error.setColumn(column); + error.setDescription(description); + _errors.append(error); +} + +bool QmlDirParser::hasError() const +{ + if (! _errors.isEmpty()) + return true; + + return false; +} + +QList QmlDirParser::errors() const +{ + return _errors; +} + +QList QmlDirParser::plugins() const +{ + return _plugins; +} + +QList QmlDirParser::components() const +{ + return _components; +} + +QT_END_NAMESPACE diff --git a/src/declarative/qml/qmldirparser_p.h b/src/declarative/qml/qmldirparser_p.h new file mode 100644 index 0000000..ff8b0f8 --- /dev/null +++ b/src/declarative/qml/qmldirparser_p.h @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLDIRPARSER_P_H +#define QMLDIRPARSER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlError; + +class QmlDirParser +{ + Q_DISABLE_COPY(QmlDirParser) + +public: + QmlDirParser(); + ~QmlDirParser(); + + QUrl url() const; + void setUrl(const QUrl &url); + + QString source() const; + void setSource(const QString &source); + + bool parse(); + + bool hasError() const; + QList errors() const; + + struct Plugin + { + Plugin() {} + + Plugin(const QString &name, const QString &path) + : name(name), path(path) {} + + QString name; + QString path; + }; + + struct Component + { + Component() + : majorVersion(0), minorVersion(0) {} + + Component(const QString &typeName, const QString &fileName, int majorVersion, int minorVersion) + : typeName(typeName), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion) {} + + QString typeName; + QString fileName; + int majorVersion; + int minorVersion; + }; + + QList components() const; + QList plugins() const; + +private: + void reportError(int line, int column, const QString &message); + +private: + QList _errors; + QUrl _url; + QString _source; + QList _components; + QList _plugins; +}; + +QT_END_NAMESPACE + +#endif // QMLDIRPARSER_P_H diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index cf26f58..6f26a07 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -66,6 +66,7 @@ #include "qmlscriptclass_p.h" #include "qmlnetworkaccessmanagerfactory.h" #include "qmlimageprovider.h" +#include "qmldirparser_p.h" #include @@ -1262,24 +1263,21 @@ struct QmlEnginePrivate::ImportedNamespace { qmldircontent = QString::fromUtf8(qmldir.readAll()); } } - QString typespace = QString::fromUtf8(type)+QLatin1Char(' '); - QStringList lines = qmldircontent.split(QLatin1Char('\n')); - foreach (QString line, lines) { - if (line.isEmpty() || line.at(0) == QLatin1Char('#')) - continue; - if (line.startsWith(typespace)) { - int space1 = line.indexOf(QLatin1Char(' ')); - int space2 = space1 >=0 ? line.indexOf(QLatin1Char(' '),space1+1) : -1; - QString mapversions = line.mid(space1+1,space2<0?line.length()-space1-1:space2-space1-1); - int dot = mapversions.indexOf(QLatin1Char('.')); - int mapvmaj = mapversions.left(dot).toInt(); - if (mapvmaj<=vmaj) { - if (mapvmaj= mapversions.mid(dot+1).toInt()) { - QStringRef mapfile = space2<0 ? QStringRef() : line.midRef(space2+1,line.length()-space2-1); - if (url_return) - *url_return = url.resolved(QUrl(mapfile.toString())); - return true; - } + + const QString typespace = QString::fromUtf8(type); + + QmlDirParser qmldirParser; + qmldirParser.setUrl(url); + qmldirParser.setSource(qmldircontent); + qmldirParser.parse(); + + foreach (const QmlDirParser::Component &c, qmldirParser.components()) { // ### TODO: cache the components + if (c.majorVersion < vmaj || (c.majorVersion == vmaj && vmin >= c.minorVersion)) { + if (c.typeName == typespace) { + if (url_return) + *url_return = url.resolved(QUrl(c.fileName)); + + return true; } } } -- cgit v0.12 From af9bee69a9d902cffb4b590012cba79328fd2a1b Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 19 Feb 2010 15:29:33 +0100 Subject: Added QmlExtensionPlugin and QmlExtensionInterface. --- src/declarative/qml/qml.pri | 9 +++++++-- src/declarative/qml/qmlextensioninterface.h | 25 +++++++++++++++++++++++ src/declarative/qml/qmlextensionplugin.cpp | 12 +++++++++++ src/declarative/qml/qmlextensionplugin.h | 31 +++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/declarative/qml/qmlextensioninterface.h create mode 100644 src/declarative/qml/qmlextensionplugin.cpp create mode 100644 src/declarative/qml/qmlextensionplugin.h diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 5e0c3e0..6c74863 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -52,7 +52,9 @@ SOURCES += \ $$PWD/qmlworkerscript.cpp \ $$PWD/qmlimageprovider.cpp \ $$PWD/qmlnetworkaccessmanagerfactory.cpp \ - $$PWD/qmldirparser.cpp + $$PWD/qmldirparser.cpp \ + $$PWD/qmlextensionplugin.cpp + HEADERS += \ $$PWD/qmlparser_p.h \ $$PWD/qmlglobal_p.h \ @@ -121,7 +123,10 @@ HEADERS += \ $$PWD/qmlguard_p.h \ $$PWD/qmlimageprovider.h \ $$PWD/qmlnetworkaccessmanagerfactory.h \ - $$PWD/qmldirparser_p.h + $$PWD/qmldirparser_p.h \ + $$PWD/qmlextensioninterface.h \ + $$PWD/qmlextensionplugin.h + QT += sql include(parser/parser.pri) include(rewriter/rewriter.pri) diff --git a/src/declarative/qml/qmlextensioninterface.h b/src/declarative/qml/qmlextensioninterface.h new file mode 100644 index 0000000..d336e6e --- /dev/null +++ b/src/declarative/qml/qmlextensioninterface.h @@ -0,0 +1,25 @@ +#ifndef QMLEXTENSIONINTERFACE_H +#define QMLEXTENSIONINTERFACE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlEngine; + +struct Q_DECLARATIVE_EXPORT QmlExtensionInterface +{ + virtual void initialize(QmlEngine *engine) = 0; +}; + +Q_DECLARE_INTERFACE(QmlExtensionInterface, "com.trolltech.Qt.QmlExtensionInterface/1.0") + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLEXTENSIONINTERFACE_H diff --git a/src/declarative/qml/qmlextensionplugin.cpp b/src/declarative/qml/qmlextensionplugin.cpp new file mode 100644 index 0000000..15ad44e --- /dev/null +++ b/src/declarative/qml/qmlextensionplugin.cpp @@ -0,0 +1,12 @@ + +#include "qmlextensionplugin.h" + +QmlExtensionPlugin::QmlExtensionPlugin(QObject *parent) + : QObject(parent) +{ +} + +QmlExtensionPlugin::~QmlExtensionPlugin() +{ +} + diff --git a/src/declarative/qml/qmlextensionplugin.h b/src/declarative/qml/qmlextensionplugin.h new file mode 100644 index 0000000..8f3194f --- /dev/null +++ b/src/declarative/qml/qmlextensionplugin.h @@ -0,0 +1,31 @@ +#ifndef QMLEXTENSIONPLUGIN_H +#define QMLEXTENSIONPLUGIN_H + +#include + +#include "qmlextensioninterface.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlEngine; + +class Q_DECLARATIVE_EXPORT QmlExtensionPlugin : public QObject, public QmlExtensionInterface +{ + Q_OBJECT + Q_INTERFACES(QmlExtensionInterface) +public: + explicit QmlExtensionPlugin(QObject *parent = 0); + ~QmlExtensionPlugin(); + + virtual void initialize(QmlEngine *engine) = 0; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLEXTENSIONPLUGIN_H -- cgit v0.12 From 3731e214baeb44434f12f773b1c68e772f25323e Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 19 Feb 2010 18:16:36 +0100 Subject: Get rid of the unfriendly ImportedNamespace::isBuiltin flag. The `isBuiltin' flag doesn't play nice with hybrid apps where the types in a namespace are provided by both C++ and QML code. Done-with: mae --- src/declarative/qml/qmlengine.cpp | 43 +++++++++++++++------------------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 6f26a07..7a60f9c 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1227,7 +1227,6 @@ struct QmlEnginePrivate::ImportedNamespace { QList majversions; QList minversions; QList isLibrary; - QList isBuiltin; // Types provided by C++ code (including plugins) QList qmlDirContent; bool find(const QByteArray& type, int *vmajor, int *vminor, QmlType** type_return, QUrl* url_return) const @@ -1236,23 +1235,22 @@ struct QmlEnginePrivate::ImportedNamespace { int vmaj = majversions.at(i); int vmin = minversions.at(i); - if (isBuiltin.at(i)) { - QByteArray qt = uris.at(i).toUtf8(); - qt += '/'; - qt += type; + QByteArray qt = uris.at(i).toUtf8(); + qt += '/'; + qt += type; + if (qmlImportTrace()) + qDebug() << "Look in" << qt; + QmlType *t = QmlMetaType::qmlType(qt,vmaj,vmin); + if (vmajor) *vmajor = vmaj; + if (vminor) *vminor = vmin; + if (t) { if (qmlImportTrace()) - qDebug() << "Look in" << qt; - QmlType *t = QmlMetaType::qmlType(qt,vmaj,vmin); - if (vmajor) *vmajor = vmaj; - if (vminor) *vminor = vmin; - if (t) { - if (qmlImportTrace()) - qDebug() << "Found" << qt; - if (type_return) - *type_return = t; - return true; - } + qDebug() << "Found" << qt; + if (type_return) + *type_return = t; + return true; } + QUrl url = QUrl(urls.at(i) + QLatin1Char('/') + QString::fromUtf8(type) + QLatin1String(".qml")); QString qmldircontent = qmlDirContent.at(i); if (vmaj>=0 || !qmldircontent.isEmpty()) { @@ -1321,7 +1319,6 @@ public: set.insert(prefix,(s=new QmlEnginePrivate::ImportedNamespace)); } QString url = uri; - bool isbuiltin = false; if (importType == QmlScriptParser::Import::Library) { url.replace(QLatin1Char('.'),QLatin1Char('/')); bool found = false; @@ -1334,16 +1331,11 @@ public: break; } } - if (!found) { - // XXX assume it is a built-in type qualifier - isbuiltin = true; - } QFactoryLoader *l = loader(); QmlModuleFactoryInterface *factory = qobject_cast(l->instance(uri)); if (factory) { factory->defineModuleOnce(uri); - isbuiltin = true; } } else { url = base.resolved(QUrl(url)).toString(); @@ -1353,7 +1345,6 @@ public: s->majversions.prepend(vmaj); s->minversions.prepend(vmin); s->isLibrary.prepend(importType == QmlScriptParser::Import::Library); - s->isBuiltin.prepend(isbuiltin); s->qmlDirContent.prepend(qmldircontent); return true; } @@ -1376,10 +1367,11 @@ public: if (s) { if (s->find(unqualifiedtype,vmajor,vminor,type_return,url_return)) return true; - if (s->urls.count() == 1 && !s->isBuiltin[0] && !s->isLibrary[0] && url_return) { + if (s->urls.count() == 1 && !s->isLibrary[0] && url_return) { *url_return = QUrl(s->urls[0]+QLatin1Char('/')).resolved(QUrl(QString::fromUtf8(unqualifiedtype) + QLatin1String(".qml"))); return true; } + } if (url_return) { *url_return = base.resolved(QUrl(QString::fromUtf8(type + ".qml"))); @@ -1440,9 +1432,6 @@ static QmlTypeNameCache *cacheForNamespace(QmlEngine *engine, const QmlEnginePri QList types = QmlMetaType::qmlTypes(); for (int ii = 0; ii < set.uris.count(); ++ii) { - if (!set.isBuiltin.at(ii)) - continue; - QByteArray base = set.uris.at(ii).toUtf8() + '/'; int major = set.majversions.at(ii); int minor = set.minversions.at(ii); -- cgit v0.12 From 80fc5bf17e5f049a395d6a5612843c69c5b0fde1 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 22 Feb 2010 12:21:06 +0100 Subject: Introduced QmlEngine::importExtension. importExtension can be used to import QmlExtensionInterface(s) into a QmlEngine. --- src/declarative/qml/qmlengine.cpp | 21 ++++++++++++++++++++- src/declarative/qml/qmlengine.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 7a60f9c..1f5caa5 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -67,7 +67,7 @@ #include "qmlnetworkaccessmanagerfactory.h" #include "qmlimageprovider.h" #include "qmldirparser_p.h" - +#include "qmlextensioninterface.h" #include #include @@ -82,6 +82,7 @@ #include #include #include +#include #include #include #include @@ -1530,6 +1531,24 @@ void QmlEngine::addImportPath(const QString& path) } /*! + Imports the given \a extension into this QmlEngine. Returns + true if the extension was successfully imported. + + \sa QmlExtensionInterface +*/ +bool QmlEngine::importExtension(const QString &fileName) +{ + QPluginLoader loader(fileName); + + if (QmlExtensionInterface *iface = qobject_cast(loader.instance())) { + iface->initialize(this); + return true; + } + + return false; +} + +/*! \property QmlEngine::offlineStoragePath \brief the directory for storing offline user data diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h index 64d0b9d..13a67b0 100644 --- a/src/declarative/qml/qmlengine.h +++ b/src/declarative/qml/qmlengine.h @@ -78,6 +78,7 @@ public: void clearComponentCache(); void addImportPath(const QString& dir); + bool importExtension(const QString &fileName); void setNetworkAccessManagerFactory(QmlNetworkAccessManagerFactory *); QmlNetworkAccessManagerFactory *networkAccessManagerFactory() const; -- cgit v0.12 From e271f9c64f1be3a3608d2010a3561d512650f547 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 22 Feb 2010 13:52:46 +0100 Subject: Compile. --- src/declarative/util/qmlview.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index e990e83..8844430 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -427,8 +427,6 @@ void QmlView::continueExecute() */ void QmlView::setRootObject(QObject *obj) { - Q_D(QmlView); - if (QmlGraphicsItem *item = qobject_cast(obj)) { d->scene.addItem(item); -- cgit v0.12 From cdeb85498e4cbd37022ba2bf4dc594db2326d0a4 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 22 Feb 2010 14:02:08 +0100 Subject: Document the QmlExtensionPlugin interface. --- src/declarative/qml/qmlextensioninterface.h | 41 ++++++++++++++++ src/declarative/qml/qmlextensionplugin.cpp | 75 +++++++++++++++++++++++++++++ src/declarative/qml/qmlextensionplugin.h | 41 ++++++++++++++++ 3 files changed, 157 insertions(+) diff --git a/src/declarative/qml/qmlextensioninterface.h b/src/declarative/qml/qmlextensioninterface.h index d336e6e..d37a5bc 100644 --- a/src/declarative/qml/qmlextensioninterface.h +++ b/src/declarative/qml/qmlextensioninterface.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef QMLEXTENSIONINTERFACE_H #define QMLEXTENSIONINTERFACE_H diff --git a/src/declarative/qml/qmlextensionplugin.cpp b/src/declarative/qml/qmlextensionplugin.cpp index 15ad44e..c1195d2 100644 --- a/src/declarative/qml/qmlextensionplugin.cpp +++ b/src/declarative/qml/qmlextensionplugin.cpp @@ -1,6 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #include "qmlextensionplugin.h" +QT_BEGIN_NAMESPACE + +/*! + \since 4.7 + \class QmlExtensionPlugin + \brief The QmlExtensionPlugin class provides an abstract base for custom QML extension plugins. + + \ingroup plugins + + QmlExtensionPlugin is a plugin interface that makes it + possible to offer extensions that can be loaded dynamically into + applications using the QmlEngine class. + + Writing a QML extension plugin is achieved by subclassing this + base class, reimplementing the pure virtual initialize() + function, and exporting the class using the Q_EXPORT_PLUGIN2() + macro. See \l {How to Create Qt Plugins} for details. + + \sa QmlEngine::importExtension() +*/ + +/*! + \fn void QmlExtensionPlugin::initialize(QmlEngine *engine) + + Initializes the extension specified in the given \a engine. +*/ + +/*! + Constructs a QML extension plugin with the given \a parent. + + Note that this constructor is invoked automatically by the + Q_EXPORT_PLUGIN2() macro, so there is no need for calling it + explicitly. +*/ QmlExtensionPlugin::QmlExtensionPlugin(QObject *parent) : QObject(parent) { @@ -10,3 +84,4 @@ QmlExtensionPlugin::~QmlExtensionPlugin() { } +QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlextensionplugin.h b/src/declarative/qml/qmlextensionplugin.h index 8f3194f..eda7d0c 100644 --- a/src/declarative/qml/qmlextensionplugin.h +++ b/src/declarative/qml/qmlextensionplugin.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef QMLEXTENSIONPLUGIN_H #define QMLEXTENSIONPLUGIN_H -- cgit v0.12 From 20fc9f2e264f34dd8580949ddbe5511b78ab0ac4 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 22 Feb 2010 15:54:36 +0100 Subject: Load QML extensions. This allows projects which use the QtDeclarative module to register QML types and functions through C++ extensions. Reviewed-by: mae --- src/declarative/qml/qmldirparser.cpp | 11 +++++ src/declarative/qml/qmldirparser_p.h | 2 + src/declarative/qml/qmlengine.cpp | 67 +++++++++++++++++++---------- src/declarative/qml/qmlengine.h | 2 +- src/declarative/qml/qmlengine_p.h | 1 + src/declarative/qml/qmlextensioninterface.h | 2 +- src/declarative/qml/qmlextensionplugin.h | 2 +- 7 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/declarative/qml/qmldirparser.cpp b/src/declarative/qml/qmldirparser.cpp index c7de233..60beb72 100644 --- a/src/declarative/qml/qmldirparser.cpp +++ b/src/declarative/qml/qmldirparser.cpp @@ -48,6 +48,7 @@ QT_BEGIN_NAMESPACE QmlDirParser::QmlDirParser() + : _isParsed(false) { } @@ -72,11 +73,21 @@ QString QmlDirParser::source() const void QmlDirParser::setSource(const QString &source) { + _isParsed = false; _source = source; } +bool QmlDirParser::isParsed() const +{ + return _isParsed; +} + bool QmlDirParser::parse() { + if (_isParsed) + return true; + + _isParsed = true; _errors.clear(); _plugins.clear(); _components.clear(); diff --git a/src/declarative/qml/qmldirparser_p.h b/src/declarative/qml/qmldirparser_p.h index ff8b0f8..c58c03f 100644 --- a/src/declarative/qml/qmldirparser_p.h +++ b/src/declarative/qml/qmldirparser_p.h @@ -74,6 +74,7 @@ public: QString source() const; void setSource(const QString &source); + bool isParsed() const; bool parse(); bool hasError() const; @@ -116,6 +117,7 @@ private: QString _source; QList _components; QList _plugins; + unsigned _isParsed: 1; }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index ce2a693..d47db9b 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -97,7 +97,6 @@ #include #include -#include #include #include @@ -1249,12 +1248,13 @@ struct QmlEnginePrivate::ImportedNamespace { QByteArray qt = uris.at(i).toUtf8(); qt += '/'; qt += type; + if (qmlImportTrace()) qDebug() << "Look in" << qt; QmlType *t = QmlMetaType::qmlType(qt,vmaj,vmin); - if (vmajor) *vmajor = vmaj; - if (vminor) *vminor = vmin; if (t) { + if (vmajor) *vmajor = vmaj; + if (vminor) *vminor = vmin; if (qmlImportTrace()) qDebug() << "Found" << qt; if (type_return) @@ -1273,7 +1273,7 @@ struct QmlEnginePrivate::ImportedNamespace { } } - const QString typespace = QString::fromUtf8(type); + const QString typeName = QString::fromUtf8(type); QmlDirParser qmldirParser; qmldirParser.setUrl(url); @@ -1282,7 +1282,7 @@ struct QmlEnginePrivate::ImportedNamespace { foreach (const QmlDirParser::Component &c, qmldirParser.components()) { // ### TODO: cache the components if (c.majorVersion < vmaj || (c.majorVersion == vmaj && vmin >= c.minorVersion)) { - if (c.typeName == typespace) { + if (c.typeName == typeName) { if (url_return) *url_return = url.resolved(QUrl(c.fileName)); @@ -1290,6 +1290,7 @@ struct QmlEnginePrivate::ImportedNamespace { } } } + } else { // XXX search non-files too! (eg. zip files, see QT-524) QFileInfo f(toLocalFileOrQrc(url)); @@ -1304,9 +1305,6 @@ struct QmlEnginePrivate::ImportedNamespace { } }; -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QmlModuleFactoryInterface_iid, QLatin1String("/qmlmodules"))) - class QmlImportsPrivate { public: QmlImportsPrivate() : ref(1) @@ -1319,7 +1317,9 @@ public: delete s; } - bool add(const QUrl& base, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType, const QStringList& importPath) + QSet qmlDirFilesForWhichPluginsHaveBeenLoaded; + + bool add(const QUrl& base, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType, const QStringList& importPath, QmlEngine *engine) { QmlEnginePrivate::ImportedNamespace *s; if (prefix.isEmpty()) { @@ -1331,26 +1331,48 @@ public: } QString url = uri; if (importType == QmlScriptParser::Import::Library) { - url.replace(QLatin1Char('.'),QLatin1Char('/')); + url.replace(QLatin1Char('.'), QLatin1Char('/')); bool found = false; - foreach (QString p, importPath) { - QString dir = p+QLatin1Char('/')+url; + QString content; + QString dir; + QStringList paths = importPath; + paths.prepend(QFileInfo(base.toLocalFile()).path()); + foreach (const QString &p, paths) { + dir = p+QLatin1Char('/')+url; QFileInfo fi(dir+QLatin1String("/qmldir")); + const QString absoluteFilePath = fi.absoluteFilePath(); + if (fi.isFile()) { - url = QUrl::fromLocalFile(fi.absolutePath()).toString(); found = true; + + url = QUrl::fromLocalFile(fi.absolutePath()).toString(); + + QFile file(absoluteFilePath); + if (file.open(QFile::ReadOnly)) + content = QString::fromUtf8(file.readAll()); + + if (! qmlDirFilesForWhichPluginsHaveBeenLoaded.contains(absoluteFilePath)) { + qmlDirFilesForWhichPluginsHaveBeenLoaded.insert(absoluteFilePath); + + QmlDirParser qmldirParser; + qmldirParser.setSource(content); + qmldirParser.parse(); + + foreach (const QmlDirParser::Plugin &plugin, qmldirParser.plugins()) { + const QFileInfo pluginFileInfo(dir + QDir::separator() + plugin.path, plugin.name); + const QString pluginFilePath = pluginFileInfo.absoluteFilePath(); + engine->importExtension(pluginFilePath, uri); + } + } + break; } } - QFactoryLoader *l = loader(); - QmlModuleFactoryInterface *factory = - qobject_cast(l->instance(uri)); - if (factory) { - factory->defineModuleOnce(uri); - } + } else { url = base.resolved(QUrl(url)).toString(); } + s->uris.prepend(uri); s->urls.prepend(url); s->majversions.prepend(vmaj); @@ -1546,12 +1568,12 @@ void QmlEngine::addImportPath(const QString& path) \sa QmlExtensionInterface */ -bool QmlEngine::importExtension(const QString &fileName) +bool QmlEngine::importExtension(const QString &fileName, const QString &uri) { QPluginLoader loader(fileName); if (QmlExtensionInterface *iface = qobject_cast(loader.instance())) { - iface->initialize(this); + iface->initialize(this, uri); return true; } @@ -1604,7 +1626,8 @@ QString QmlEngine::offlineStoragePath() const */ bool QmlEnginePrivate::addToImport(Imports* imports, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const { - bool ok = imports->d->add(imports->d->base,qmldircontent,uri,prefix,vmaj,vmin,importType,fileImportPath); + QmlEngine *engine = QmlEnginePrivate::get(const_cast(this)); + bool ok = imports->d->add(imports->d->base,qmldircontent,uri,prefix,vmaj,vmin,importType,fileImportPath, engine); if (qmlImportTrace()) qDebug() << "QmlEngine::addToImport(" << imports << uri << prefix << vmaj << '.' << vmin << (importType==QmlScriptParser::Import::Library? "Library" : "File") << ": " << ok; return ok; diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h index 13a67b0..dd2012a 100644 --- a/src/declarative/qml/qmlengine.h +++ b/src/declarative/qml/qmlengine.h @@ -78,7 +78,7 @@ public: void clearComponentCache(); void addImportPath(const QString& dir); - bool importExtension(const QString &fileName); + bool importExtension(const QString &fileName, const QString &uri); void setNetworkAccessManagerFactory(QmlNetworkAccessManagerFactory *); QmlNetworkAccessManagerFactory *networkAccessManagerFactory() const; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 3fe7991..d916286 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -263,6 +263,7 @@ public: QmlImportsPrivate *d; }; + bool addToImport(Imports*, const QString& qmlDirContent,const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, diff --git a/src/declarative/qml/qmlextensioninterface.h b/src/declarative/qml/qmlextensioninterface.h index d37a5bc..cbdd34c 100644 --- a/src/declarative/qml/qmlextensioninterface.h +++ b/src/declarative/qml/qmlextensioninterface.h @@ -54,7 +54,7 @@ class QmlEngine; struct Q_DECLARATIVE_EXPORT QmlExtensionInterface { - virtual void initialize(QmlEngine *engine) = 0; + virtual void initialize(QmlEngine *engine, const QString &uri) = 0; }; Q_DECLARE_INTERFACE(QmlExtensionInterface, "com.trolltech.Qt.QmlExtensionInterface/1.0") diff --git a/src/declarative/qml/qmlextensionplugin.h b/src/declarative/qml/qmlextensionplugin.h index eda7d0c..82553e7 100644 --- a/src/declarative/qml/qmlextensionplugin.h +++ b/src/declarative/qml/qmlextensionplugin.h @@ -62,7 +62,7 @@ public: explicit QmlExtensionPlugin(QObject *parent = 0); ~QmlExtensionPlugin(); - virtual void initialize(QmlEngine *engine) = 0; + virtual void initialize(QmlEngine *engine, const QString &uri) = 0; }; QT_END_NAMESPACE -- cgit v0.12 From a2c998ecdabda8635151d0dcd29ba69354ab20ec Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 23 Feb 2010 10:50:58 +1000 Subject: Test bug QTBUG-5974 --- tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp index e70c7f1..8513a3b 100644 --- a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp +++ b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp @@ -249,6 +249,10 @@ void tst_QmlListModel::static_types_data() QTest::newRow("bool") << "ListElement { foo: true }" << QVariant(true); + + QTest::newRow("enum") + << "ListElement { foo: Text.AlignHCenter }" + << QVariant("QTBUG-5974:ListElement: constant script support for property value"); } void tst_QmlListModel::static_types() @@ -262,6 +266,10 @@ void tst_QmlListModel::static_types() QmlComponent component(&engine); component.setData(qml.toUtf8(), QUrl::fromLocalFile(QString("dummy.qml"))); + + if (value.toString().startsWith("QTBUG-")) + QEXPECT_FAIL("",value.toString().toLatin1(),Abort); + QVERIFY(!component.isError()); QmlListModel *obj = qobject_cast(component.create()); @@ -301,7 +309,7 @@ void tst_QmlListModel::error_data() QTest::newRow("bindings not allowed in ListElement") << "import Qt 4.6\nRectangle { id: rect; ListModel { ListElement { foo: rect.color } } }" - << "ListElement: cannot use script for property value"; + << "ListElement: cannot use script for property value"; // but note QTBUG-5974 QTest::newRow("random object list properties allowed in ListElement") << "import Qt 4.6\nListModel { ListElement { foo: [ ListElement { bar: 123 } ] } }" -- cgit v0.12 From d7c472e23b678b2898d34a37166e61402818e271 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 23 Feb 2010 11:35:38 +1000 Subject: run qmlmoduleplugin test --- tests/auto/declarative/declarative.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index b4a0d0f..45b5218 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -44,6 +44,7 @@ SUBDIRS += \ qmllistmodel \ # Cover qmlmetaproperty \ # Cover qmlmetatype \ # Cover + qmlmoduleplugin \ # Cover qmlnumberformatter \ # Cover qmlpixmapcache \ # Cover qmlpropertymap \ # Cover -- cgit v0.12 From ce78e4124d57a3c517e6de88696a09ad399c703f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 11:08:37 +1000 Subject: Add documentation on QMLs memory management assumptions --- doc/src/declarative/extending.qdoc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc index 0456f3f..d3e6c14 100644 --- a/doc/src/declarative/extending.qdoc +++ b/doc/src/declarative/extending.qdoc @@ -375,6 +375,37 @@ object will only be returned if it has previously been created. \l {Extending QML - Attached Properties Example} shows the complete code used to implement the rsvp attached property. +\section1 Memory Management and QVariant types + +It is an elements responsibility to ensure that it does not access or return +pointers to invalid objects. QML makes the following guarentees: + +\list +\o An object assigned to an QObject (or QObject-derived) pointer property will be +valid at the time of assignment. + +Following assignment, it is the responsibility of the class to subsequently guard +this pointer, either through a class specific method or the generic QPointer class. + +\o An object assigned to a QVariant will be valid at the time of assignment. + +When assigning an object to a QVariant property, QML will always use a QMetaType::QObjectStar +typed QVariant. It is the responsibility of the class to guard the pointer. A +general rule when writing a class that uses QVariant properties is to check the +type of the QVariant when it is set and if the type is not handled by your class, +reset it to an invalid variant. + +\o An object assigned to a QObject (or QObject-derived) list property will be +valid at the time of assignment. + +Following assignment, it is the responsibility of the class to subsequently guard +this pointer, either through a class specific method or the generic QPointer class. +\endlist + +Elements should assume that any QML assigned object can be deleted at any time, and +respond accordingly. If documented as such an element need not continue to work in +this situation, but it must not crash. + \section1 Signal Support \snippet examples/declarative/extending/signal/example.qml 0 -- cgit v0.12 From c41f7c7a4dbb2ac0c76e20628aaedeabec6f4497 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 22 Feb 2010 17:26:20 +1000 Subject: Better support modelData for object list models. modelData will now correctly return the actual object. --- src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index b96f399..9216793 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -415,7 +415,7 @@ int QmlGraphicsVisualDataModelDataMetaObject::createProperty(const char *name, c if (model->m_listAccessor->type() == QmlListAccessor::ListProperty) { model->ensureRoles(); QObject *object = model->m_listAccessor->at(data->m_index).value(); - if (object && object->property(name).isValid()) + if (object && (object->property(name).isValid() || qstrcmp(name,"modelData")==0)) return QmlOpenMetaObject::createProperty(name, type); } } -- cgit v0.12 From 5955a7bd3bcef20558238e2de0c66fac9eccdf57 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 12:41:24 +1000 Subject: Small QmlMetaProperty code cleanup --- src/declarative/qml/qmlmetaproperty.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 7c273dc..332d126 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -811,22 +811,22 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data return writeEnumProperty(prop, coreIdx, object, v, flags); } - int t = property.propType; - int vt = value.userType(); + int propertyType = property.propType; + int variantType = value.userType(); QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(context); - if (t == QVariant::Url) { + if (propertyType == QVariant::Url) { QUrl u; bool found = false; - if (vt == QVariant::Url) { + if (variantType == QVariant::Url) { u = value.toUrl(); found = true; - } else if (vt == QVariant::ByteArray) { + } else if (variantType == QVariant::ByteArray) { u = QUrl(QString::fromUtf8(value.toByteArray())); found = true; - } else if (vt == QVariant::String) { + } else if (variantType == QVariant::String) { u = QUrl(value.toString()); found = true; } @@ -840,12 +840,12 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data void *argv[] = { &u, 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv); - } else if (vt == t) { + } else if (variantType == propertyType) { void *a[] = { (void *)value.constData(), 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); - } else if (qMetaTypeId() == t) { + } else if (qMetaTypeId() == propertyType) { void *a[] = { (void *)&value, 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); @@ -858,7 +858,7 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data return false; QObject *o = *(QObject **)value.constData(); - const QMetaObject *propMo = rawMetaObjectForType(enginePriv, t); + const QMetaObject *propMo = rawMetaObjectForType(enginePriv, propertyType); if (o) valMo = o->metaObject(); @@ -914,25 +914,25 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data } } else { - Q_ASSERT(vt != t); + Q_ASSERT(variantType != propertyType); QVariant v = value; - if (v.convert((QVariant::Type)t)) { + if (v.convert((QVariant::Type)propertyType)) { void *a[] = { (void *)v.constData(), 0, &status, &flags}; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); - } else if ((uint)t >= QVariant::UserType && vt == QVariant::String) { - QmlMetaType::StringConverter con = QmlMetaType::customStringConverter(t); + } else if ((uint)propertyType >= QVariant::UserType && variantType == QVariant::String) { + QmlMetaType::StringConverter con = QmlMetaType::customStringConverter(propertyType); if (!con) return false; QVariant v = con(value.toString()); - if (v.userType() == t) { + if (v.userType() == propertyType) { void *a[] = { (void *)v.constData(), 0, &status, &flags}; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); } - } else if (vt == QVariant::String) { + } else if (variantType == QVariant::String) { bool ok = false; - QVariant v = QmlStringConverters::variantFromString(value.toString(), t, &ok); + QVariant v = QmlStringConverters::variantFromString(value.toString(), propertyType, &ok); if (!ok) return false; -- cgit v0.12 From 0bc70bc54e1e67468db1dd11ec4fad3a178768c3 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 12:45:21 +1000 Subject: Rename qmllist autotest to qmllistreference --- tests/auto/declarative/declarative.pro | 2 +- tests/auto/declarative/qmllist/data/MyType.qml | 5 - .../auto/declarative/qmllist/data/engineTypes.qml | 9 - .../declarative/qmllist/data/variantToList.qml | 10 - tests/auto/declarative/qmllist/qmllist.pro | 5 - tests/auto/declarative/qmllist/tst_qmllist.cpp | 574 --------------------- .../declarative/qmllistreference/data/MyType.qml | 5 + .../qmllistreference/data/engineTypes.qml | 9 + .../qmllistreference/data/variantToList.qml | 10 + .../qmllistreference/qmllistreference.pro | 5 + .../qmllistreference/tst_qmllistreference.cpp | 574 +++++++++++++++++++++ 11 files changed, 604 insertions(+), 604 deletions(-) delete mode 100644 tests/auto/declarative/qmllist/data/MyType.qml delete mode 100644 tests/auto/declarative/qmllist/data/engineTypes.qml delete mode 100644 tests/auto/declarative/qmllist/data/variantToList.qml delete mode 100644 tests/auto/declarative/qmllist/qmllist.pro delete mode 100644 tests/auto/declarative/qmllist/tst_qmllist.cpp create mode 100644 tests/auto/declarative/qmllistreference/data/MyType.qml create mode 100644 tests/auto/declarative/qmllistreference/data/engineTypes.qml create mode 100644 tests/auto/declarative/qmllistreference/data/variantToList.qml create mode 100644 tests/auto/declarative/qmllistreference/qmllistreference.pro create mode 100644 tests/auto/declarative/qmllistreference/tst_qmllistreference.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 645f794..870c92b 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -39,7 +39,7 @@ SUBDIRS += \ qmlinfo \ # Cover qmlinstruction \ # Cover qmllanguage \ # Cover - qmllist \ # Cover + qmllistreference \ # Cover qmllistmodel \ # Cover qmlmetaproperty \ # Cover qmlmetatype \ # Cover diff --git a/tests/auto/declarative/qmllist/data/MyType.qml b/tests/auto/declarative/qmllist/data/MyType.qml deleted file mode 100644 index d08f35b..0000000 --- a/tests/auto/declarative/qmllist/data/MyType.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt 4.6 - -QtObject { - property int a -} diff --git a/tests/auto/declarative/qmllist/data/engineTypes.qml b/tests/auto/declarative/qmllist/data/engineTypes.qml deleted file mode 100644 index 670aee4..0000000 --- a/tests/auto/declarative/qmllist/data/engineTypes.qml +++ /dev/null @@ -1,9 +0,0 @@ -import Qt 4.6 - -QtObject { - property list myList - - myList: [ MyType { a: 1 }, - MyType { a: 9 } ] - -} diff --git a/tests/auto/declarative/qmllist/data/variantToList.qml b/tests/auto/declarative/qmllist/data/variantToList.qml deleted file mode 100644 index 0c2d0aa..0000000 --- a/tests/auto/declarative/qmllist/data/variantToList.qml +++ /dev/null @@ -1,10 +0,0 @@ -import Qt 4.6 - -QtObject { - property list myList; - myList: QtObject {} - - property var value: myList - property int test: value.length -} - diff --git a/tests/auto/declarative/qmllist/qmllist.pro b/tests/auto/declarative/qmllist/qmllist.pro deleted file mode 100644 index b2145ed..0000000 --- a/tests/auto/declarative/qmllist/qmllist.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -macx:CONFIG -= app_bundle - -SOURCES += tst_qmllist.cpp diff --git a/tests/auto/declarative/qmllist/tst_qmllist.cpp b/tests/auto/declarative/qmllist/tst_qmllist.cpp deleted file mode 100644 index 76def1c..0000000 --- a/tests/auto/declarative/qmllist/tst_qmllist.cpp +++ /dev/null @@ -1,574 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -inline QUrl TEST_FILE(const QString &filename) -{ - QFileInfo fileInfo(__FILE__); - return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath("data/" + filename)); -} - -inline QUrl TEST_FILE(const char *filename) -{ - return TEST_FILE(QLatin1String(filename)); -} - -class tst_QmlList : public QObject -{ - Q_OBJECT -public: - tst_QmlList() {} - -private slots: - void qmllistreference(); - void qmllistreference_invalid(); - void isValid(); - void object(); - void listElementType(); - void canAppend(); - void canAt(); - void canClear(); - void canCount(); - void append(); - void at(); - void clear(); - void count(); - void copy(); - void qmlmetaproperty(); - void engineTypes(); - void variantToList(); -}; - -class TestType : public QObject -{ - Q_OBJECT - Q_PROPERTY(QmlListProperty data READ dataProperty); - Q_PROPERTY(int intProperty READ intProperty); - -public: - TestType() : property(this, data) {} - QmlListProperty dataProperty() { return property; } - int intProperty() const { return 10; } - - QList data; - QmlListProperty property; -}; -QML_DECLARE_TYPE(TestType); -QML_DEFINE_NOCREATE_TYPE(TestType); - -void tst_QmlList::qmllistreference() -{ - TestType tt; - - QmlListReference r(&tt, "data"); - QVERIFY(r.isValid() == true); - QCOMPARE(r.count(), 0); - - tt.data.append(&tt); - QCOMPARE(r.count(), 1); -} - -void tst_QmlList::qmllistreference_invalid() -{ - TestType tt; - - // Invalid - { - QmlListReference r; - QVERIFY(r.isValid() == false); - QVERIFY(r.object() == 0); - QVERIFY(r.listElementType() == 0); - QVERIFY(r.canAt() == false); - QVERIFY(r.canClear() == false); - QVERIFY(r.canCount() == false); - QVERIFY(r.append(0) == false); - QVERIFY(r.at(10) == 0); - QVERIFY(r.clear() == false); - QVERIFY(r.count() == 0); - } - - // Non-property - { - QmlListReference r(&tt, "blah"); - QVERIFY(r.isValid() == false); - QVERIFY(r.object() == 0); - QVERIFY(r.listElementType() == 0); - QVERIFY(r.canAt() == false); - QVERIFY(r.canClear() == false); - QVERIFY(r.canCount() == false); - QVERIFY(r.append(0) == false); - QVERIFY(r.at(10) == 0); - QVERIFY(r.clear() == false); - QVERIFY(r.count() == 0); - } - - // Non-list property - { - QmlListReference r(&tt, "intProperty"); - QVERIFY(r.isValid() == false); - QVERIFY(r.object() == 0); - QVERIFY(r.listElementType() == 0); - QVERIFY(r.canAt() == false); - QVERIFY(r.canClear() == false); - QVERIFY(r.canCount() == false); - QVERIFY(r.append(0) == false); - QVERIFY(r.at(10) == 0); - QVERIFY(r.clear() == false); - QVERIFY(r.count() == 0); - } -} - -void tst_QmlList::isValid() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.isValid() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.isValid() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.isValid() == true); - delete tt; - QVERIFY(ref.isValid() == false); - } -} - -void tst_QmlList::object() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.object() == 0); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.object() == 0); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.object() == tt); - delete tt; - QVERIFY(ref.object() == 0); - } -} - -void tst_QmlList::listElementType() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.listElementType() == 0); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.listElementType() == 0); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.listElementType() == &TestType::staticMetaObject); - delete tt; - QVERIFY(ref.listElementType() == 0); - } -} - -void tst_QmlList::canAppend() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.canAppend() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.canAppend() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.canAppend() == true); - delete tt; - QVERIFY(ref.canAppend() == false); - } - - { - TestType tt; - tt.property.append = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.canAppend() == false); - } -} - -void tst_QmlList::canAt() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.canAt() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.canAt() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.canAt() == true); - delete tt; - QVERIFY(ref.canAt() == false); - } - - { - TestType tt; - tt.property.at = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.canAt() == false); - } -} - -void tst_QmlList::canClear() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.canClear() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.canClear() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.canClear() == true); - delete tt; - QVERIFY(ref.canClear() == false); - } - - { - TestType tt; - tt.property.clear = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.canClear() == false); - } -} - -void tst_QmlList::canCount() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.canCount() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.canCount() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.canCount() == true); - delete tt; - QVERIFY(ref.canCount() == false); - } - - { - TestType tt; - tt.property.count = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.canCount() == false); - } -} - -void tst_QmlList::append() -{ - TestType *tt = new TestType; - QObject object; - - { - QmlListReference ref; - QVERIFY(ref.append(tt) == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.append(tt) == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.append(tt) == true); - QVERIFY(tt->data.count() == 1); - QVERIFY(tt->data.at(0) == tt); - QVERIFY(ref.append(&object) == false); - QVERIFY(tt->data.count() == 1); - QVERIFY(tt->data.at(0) == tt); - QVERIFY(ref.append(0) == true); - QVERIFY(tt->data.count() == 2); - QVERIFY(tt->data.at(0) == tt); - QVERIFY(tt->data.at(1) == 0); - delete tt; - QVERIFY(ref.append(0) == false); - } - - { - TestType tt; - tt.property.append = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.append(&tt) == false); - } -} - -void tst_QmlList::at() -{ - TestType *tt = new TestType; - tt->data.append(tt); - tt->data.append(0); - tt->data.append(tt); - - { - QmlListReference ref; - QVERIFY(ref.at(0) == 0); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.at(0) == 0); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.at(0) == tt); - QVERIFY(ref.at(1) == 0); - QVERIFY(ref.at(2) == tt); - delete tt; - QVERIFY(ref.at(0) == 0); - } - - { - TestType tt; - tt.data.append(&tt); - tt.property.at = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.at(0) == 0); - } -} - -void tst_QmlList::clear() -{ - TestType *tt = new TestType; - tt->data.append(tt); - tt->data.append(0); - tt->data.append(tt); - - { - QmlListReference ref; - QVERIFY(ref.clear() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.clear() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.clear() == true); - QVERIFY(tt->data.count() == 0); - delete tt; - QVERIFY(ref.clear() == false); - } - - { - TestType tt; - tt.property.clear = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.clear() == false); - } -} - -void tst_QmlList::count() -{ - TestType *tt = new TestType; - tt->data.append(tt); - tt->data.append(0); - tt->data.append(tt); - - { - QmlListReference ref; - QVERIFY(ref.count() == 0); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.count() == 0); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.count() == 3); - tt->data.removeAt(1); - QVERIFY(ref.count() == 2); - delete tt; - QVERIFY(ref.count() == 0); - } - - { - TestType tt; - tt.data.append(&tt); - tt.property.count = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.count() == 0); - } -} - -void tst_QmlList::copy() -{ - TestType tt; - tt.data.append(&tt); - tt.data.append(0); - tt.data.append(&tt); - - QmlListReference *r1 = new QmlListReference(&tt, "data"); - QVERIFY(r1->count() == 3); - - QmlListReference r2(*r1); - QmlListReference r3; - r3 = *r1; - - QVERIFY(r2.count() == 3); - QVERIFY(r3.count() == 3); - - delete r1; - - QVERIFY(r2.count() == 3); - QVERIFY(r3.count() == 3); - - tt.data.removeAt(2); - - QVERIFY(r2.count() == 2); - QVERIFY(r3.count() == 2); -} - -void tst_QmlList::qmlmetaproperty() -{ - TestType tt; - tt.data.append(&tt); - tt.data.append(0); - tt.data.append(&tt); - - QmlMetaProperty prop(&tt, QLatin1String("data")); - QVariant v = prop.read(); - QVERIFY(v.userType() == qMetaTypeId()); - QmlListReference ref = qvariant_cast(v); - QVERIFY(ref.count() == 3); - QVERIFY(ref.listElementType() == &TestType::staticMetaObject); -} - -void tst_QmlList::engineTypes() -{ - QmlEngine engine; - QmlComponent component(&engine, TEST_FILE("engineTypes.qml")); - - QObject *o = component.create(); - QVERIFY(o); - - QmlMetaProperty p1(o, QLatin1String("myList")); - QVERIFY(p1.propertyCategory() == QmlMetaProperty::Normal); - - QmlMetaProperty p2(o, QLatin1String("myList"), engine.rootContext()); - QVERIFY(p2.propertyCategory() == QmlMetaProperty::List); - QVariant v = p2.read(); - QVERIFY(v.userType() == qMetaTypeId()); - QmlListReference ref = qvariant_cast(v); - QVERIFY(ref.count() == 2); - QVERIFY(ref.listElementType()); - QVERIFY(ref.listElementType() != &QObject::staticMetaObject); - - delete o; -} - -void tst_QmlList::variantToList() -{ - QmlEngine engine; - QmlComponent component(&engine, TEST_FILE("variantToList.qml")); - - QObject *o = component.create(); - QVERIFY(o); - - QVERIFY(o->property("value").userType() == qMetaTypeId()); - QCOMPARE(o->property("test").toInt(), 1); - - delete o; -} - -QTEST_MAIN(tst_QmlList) - -#include "tst_qmllist.moc" diff --git a/tests/auto/declarative/qmllistreference/data/MyType.qml b/tests/auto/declarative/qmllistreference/data/MyType.qml new file mode 100644 index 0000000..d08f35b --- /dev/null +++ b/tests/auto/declarative/qmllistreference/data/MyType.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +QtObject { + property int a +} diff --git a/tests/auto/declarative/qmllistreference/data/engineTypes.qml b/tests/auto/declarative/qmllistreference/data/engineTypes.qml new file mode 100644 index 0000000..670aee4 --- /dev/null +++ b/tests/auto/declarative/qmllistreference/data/engineTypes.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +QtObject { + property list myList + + myList: [ MyType { a: 1 }, + MyType { a: 9 } ] + +} diff --git a/tests/auto/declarative/qmllistreference/data/variantToList.qml b/tests/auto/declarative/qmllistreference/data/variantToList.qml new file mode 100644 index 0000000..0c2d0aa --- /dev/null +++ b/tests/auto/declarative/qmllistreference/data/variantToList.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +QtObject { + property list myList; + myList: QtObject {} + + property var value: myList + property int test: value.length +} + diff --git a/tests/auto/declarative/qmllistreference/qmllistreference.pro b/tests/auto/declarative/qmllistreference/qmllistreference.pro new file mode 100644 index 0000000..fa49d5a --- /dev/null +++ b/tests/auto/declarative/qmllistreference/qmllistreference.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += tst_qmllistreference.cpp diff --git a/tests/auto/declarative/qmllistreference/tst_qmllistreference.cpp b/tests/auto/declarative/qmllistreference/tst_qmllistreference.cpp new file mode 100644 index 0000000..6122f1e --- /dev/null +++ b/tests/auto/declarative/qmllistreference/tst_qmllistreference.cpp @@ -0,0 +1,574 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +inline QUrl TEST_FILE(const QString &filename) +{ + QFileInfo fileInfo(__FILE__); + return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath("data/" + filename)); +} + +inline QUrl TEST_FILE(const char *filename) +{ + return TEST_FILE(QLatin1String(filename)); +} + +class tst_qmllistreference : public QObject +{ + Q_OBJECT +public: + tst_qmllistreference() {} + +private slots: + void qmllistreference(); + void qmllistreference_invalid(); + void isValid(); + void object(); + void listElementType(); + void canAppend(); + void canAt(); + void canClear(); + void canCount(); + void append(); + void at(); + void clear(); + void count(); + void copy(); + void qmlmetaproperty(); + void engineTypes(); + void variantToList(); +}; + +class TestType : public QObject +{ + Q_OBJECT + Q_PROPERTY(QmlListProperty data READ dataProperty); + Q_PROPERTY(int intProperty READ intProperty); + +public: + TestType() : property(this, data) {} + QmlListProperty dataProperty() { return property; } + int intProperty() const { return 10; } + + QList data; + QmlListProperty property; +}; +QML_DECLARE_TYPE(TestType); +QML_DEFINE_NOCREATE_TYPE(TestType); + +void tst_qmllistreference::qmllistreference() +{ + TestType tt; + + QmlListReference r(&tt, "data"); + QVERIFY(r.isValid() == true); + QCOMPARE(r.count(), 0); + + tt.data.append(&tt); + QCOMPARE(r.count(), 1); +} + +void tst_qmllistreference::qmllistreference_invalid() +{ + TestType tt; + + // Invalid + { + QmlListReference r; + QVERIFY(r.isValid() == false); + QVERIFY(r.object() == 0); + QVERIFY(r.listElementType() == 0); + QVERIFY(r.canAt() == false); + QVERIFY(r.canClear() == false); + QVERIFY(r.canCount() == false); + QVERIFY(r.append(0) == false); + QVERIFY(r.at(10) == 0); + QVERIFY(r.clear() == false); + QVERIFY(r.count() == 0); + } + + // Non-property + { + QmlListReference r(&tt, "blah"); + QVERIFY(r.isValid() == false); + QVERIFY(r.object() == 0); + QVERIFY(r.listElementType() == 0); + QVERIFY(r.canAt() == false); + QVERIFY(r.canClear() == false); + QVERIFY(r.canCount() == false); + QVERIFY(r.append(0) == false); + QVERIFY(r.at(10) == 0); + QVERIFY(r.clear() == false); + QVERIFY(r.count() == 0); + } + + // Non-list property + { + QmlListReference r(&tt, "intProperty"); + QVERIFY(r.isValid() == false); + QVERIFY(r.object() == 0); + QVERIFY(r.listElementType() == 0); + QVERIFY(r.canAt() == false); + QVERIFY(r.canClear() == false); + QVERIFY(r.canCount() == false); + QVERIFY(r.append(0) == false); + QVERIFY(r.at(10) == 0); + QVERIFY(r.clear() == false); + QVERIFY(r.count() == 0); + } +} + +void tst_qmllistreference::isValid() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.isValid() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.isValid() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.isValid() == true); + delete tt; + QVERIFY(ref.isValid() == false); + } +} + +void tst_qmllistreference::object() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.object() == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.object() == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.object() == tt); + delete tt; + QVERIFY(ref.object() == 0); + } +} + +void tst_qmllistreference::listElementType() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.listElementType() == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.listElementType() == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.listElementType() == &TestType::staticMetaObject); + delete tt; + QVERIFY(ref.listElementType() == 0); + } +} + +void tst_qmllistreference::canAppend() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canAppend() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canAppend() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canAppend() == true); + delete tt; + QVERIFY(ref.canAppend() == false); + } + + { + TestType tt; + tt.property.append = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canAppend() == false); + } +} + +void tst_qmllistreference::canAt() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canAt() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canAt() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canAt() == true); + delete tt; + QVERIFY(ref.canAt() == false); + } + + { + TestType tt; + tt.property.at = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canAt() == false); + } +} + +void tst_qmllistreference::canClear() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canClear() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canClear() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canClear() == true); + delete tt; + QVERIFY(ref.canClear() == false); + } + + { + TestType tt; + tt.property.clear = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canClear() == false); + } +} + +void tst_qmllistreference::canCount() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canCount() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canCount() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canCount() == true); + delete tt; + QVERIFY(ref.canCount() == false); + } + + { + TestType tt; + tt.property.count = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canCount() == false); + } +} + +void tst_qmllistreference::append() +{ + TestType *tt = new TestType; + QObject object; + + { + QmlListReference ref; + QVERIFY(ref.append(tt) == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.append(tt) == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.append(tt) == true); + QVERIFY(tt->data.count() == 1); + QVERIFY(tt->data.at(0) == tt); + QVERIFY(ref.append(&object) == false); + QVERIFY(tt->data.count() == 1); + QVERIFY(tt->data.at(0) == tt); + QVERIFY(ref.append(0) == true); + QVERIFY(tt->data.count() == 2); + QVERIFY(tt->data.at(0) == tt); + QVERIFY(tt->data.at(1) == 0); + delete tt; + QVERIFY(ref.append(0) == false); + } + + { + TestType tt; + tt.property.append = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.append(&tt) == false); + } +} + +void tst_qmllistreference::at() +{ + TestType *tt = new TestType; + tt->data.append(tt); + tt->data.append(0); + tt->data.append(tt); + + { + QmlListReference ref; + QVERIFY(ref.at(0) == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.at(0) == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.at(0) == tt); + QVERIFY(ref.at(1) == 0); + QVERIFY(ref.at(2) == tt); + delete tt; + QVERIFY(ref.at(0) == 0); + } + + { + TestType tt; + tt.data.append(&tt); + tt.property.at = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.at(0) == 0); + } +} + +void tst_qmllistreference::clear() +{ + TestType *tt = new TestType; + tt->data.append(tt); + tt->data.append(0); + tt->data.append(tt); + + { + QmlListReference ref; + QVERIFY(ref.clear() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.clear() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.clear() == true); + QVERIFY(tt->data.count() == 0); + delete tt; + QVERIFY(ref.clear() == false); + } + + { + TestType tt; + tt.property.clear = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.clear() == false); + } +} + +void tst_qmllistreference::count() +{ + TestType *tt = new TestType; + tt->data.append(tt); + tt->data.append(0); + tt->data.append(tt); + + { + QmlListReference ref; + QVERIFY(ref.count() == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.count() == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.count() == 3); + tt->data.removeAt(1); + QVERIFY(ref.count() == 2); + delete tt; + QVERIFY(ref.count() == 0); + } + + { + TestType tt; + tt.data.append(&tt); + tt.property.count = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.count() == 0); + } +} + +void tst_qmllistreference::copy() +{ + TestType tt; + tt.data.append(&tt); + tt.data.append(0); + tt.data.append(&tt); + + QmlListReference *r1 = new QmlListReference(&tt, "data"); + QVERIFY(r1->count() == 3); + + QmlListReference r2(*r1); + QmlListReference r3; + r3 = *r1; + + QVERIFY(r2.count() == 3); + QVERIFY(r3.count() == 3); + + delete r1; + + QVERIFY(r2.count() == 3); + QVERIFY(r3.count() == 3); + + tt.data.removeAt(2); + + QVERIFY(r2.count() == 2); + QVERIFY(r3.count() == 2); +} + +void tst_qmllistreference::qmlmetaproperty() +{ + TestType tt; + tt.data.append(&tt); + tt.data.append(0); + tt.data.append(&tt); + + QmlMetaProperty prop(&tt, QLatin1String("data")); + QVariant v = prop.read(); + QVERIFY(v.userType() == qMetaTypeId()); + QmlListReference ref = qvariant_cast(v); + QVERIFY(ref.count() == 3); + QVERIFY(ref.listElementType() == &TestType::staticMetaObject); +} + +void tst_qmllistreference::engineTypes() +{ + QmlEngine engine; + QmlComponent component(&engine, TEST_FILE("engineTypes.qml")); + + QObject *o = component.create(); + QVERIFY(o); + + QmlMetaProperty p1(o, QLatin1String("myList")); + QVERIFY(p1.propertyCategory() == QmlMetaProperty::Normal); + + QmlMetaProperty p2(o, QLatin1String("myList"), engine.rootContext()); + QVERIFY(p2.propertyCategory() == QmlMetaProperty::List); + QVariant v = p2.read(); + QVERIFY(v.userType() == qMetaTypeId()); + QmlListReference ref = qvariant_cast(v); + QVERIFY(ref.count() == 2); + QVERIFY(ref.listElementType()); + QVERIFY(ref.listElementType() != &QObject::staticMetaObject); + + delete o; +} + +void tst_qmllistreference::variantToList() +{ + QmlEngine engine; + QmlComponent component(&engine, TEST_FILE("variantToList.qml")); + + QObject *o = component.create(); + QVERIFY(o); + + QVERIFY(o->property("value").userType() == qMetaTypeId()); + QCOMPARE(o->property("test").toInt(), 1); + + delete o; +} + +QTEST_MAIN(tst_qmllistreference) + +#include "tst_qmllistreference.moc" -- cgit v0.12 From c151647c01dd8034ee77a00520430cfb516a6a38 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 12:56:39 +1000 Subject: Cleanup warnings in qmlmetaproperty test --- .../qmlmetaproperty/tst_qmlmetaproperty.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp index 050cd3f..b763b6e 100644 --- a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp +++ b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp @@ -129,7 +129,7 @@ void tst_qmlmetaproperty::qmlmetaproperty() { QmlMetaProperty prop; - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); QVERIFY(expression != 0); @@ -218,7 +218,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object() { QmlMetaProperty prop(&object); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); QVERIFY(expression != 0); @@ -264,7 +264,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object() { QmlMetaProperty prop(&dobject); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); @@ -319,7 +319,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() { QmlMetaProperty prop(&object, QString("defaultProperty")); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); QVERIFY(expression != 0); @@ -365,7 +365,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() { QmlMetaProperty prop(&dobject, QString("defaultProperty")); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); @@ -414,7 +414,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() { QmlMetaProperty prop(&dobject, QString("onClicked")); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); @@ -468,7 +468,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_context() { QmlMetaProperty prop(&object, engine.rootContext()); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); QVERIFY(expression != 0); @@ -514,7 +514,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_context() { QmlMetaProperty prop(&dobject, engine.rootContext()); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); @@ -569,7 +569,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() { QmlMetaProperty prop(&object, QString("defaultProperty"), engine.rootContext()); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); QVERIFY(expression != 0); @@ -615,7 +615,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() { QmlMetaProperty prop(&dobject, QString("defaultProperty"), engine.rootContext()); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); @@ -664,7 +664,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() { QmlMetaProperty prop(&dobject, QString("onClicked"), engine.rootContext()); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); -- cgit v0.12 From 23316b14f28eb1b135b6e8e90fa6fdb34dc39b59 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 13:06:22 +1000 Subject: Fix but in QmlMetaProperty assignment operator QTBUG-8166 --- src/declarative/qml/qmlmetaproperty.cpp | 2 + .../qmlmetaproperty/tst_qmlmetaproperty.cpp | 43 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 332d126..1742c43 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -378,7 +378,9 @@ QmlMetaProperty &QmlMetaProperty::operator=(const QmlMetaProperty &other) d->object = other.d->object; d->isDefaultProperty = other.d->isDefaultProperty; + d->isNameCached = other.d->isNameCached; d->core = other.d->core; + d->nameCache = other.d->nameCache; d->valueType = other.d->valueType; diff --git a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp index b763b6e..c289641 100644 --- a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp +++ b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp @@ -121,6 +121,7 @@ private slots: // Bugs void crashOnValueProperty(); + void copy(); private: QmlEngine engine; }; @@ -1131,6 +1132,48 @@ void tst_qmlmetaproperty::crashOnValueProperty() QCOMPARE(p.read(), QVariant(20)); } +void tst_qmlmetaproperty::copy() +{ + PropertyObject object; + + QmlMetaProperty *property = new QmlMetaProperty(&object, QLatin1String("defaultProperty")); + QCOMPARE(property->name(), QString("defaultProperty")); + QCOMPARE(property->read(), QVariant(10)); + QCOMPARE(property->type(), QmlMetaProperty::Property); + QCOMPARE(property->propertyCategory(), QmlMetaProperty::Normal); + QCOMPARE(property->propertyType(), (int)QVariant::Int); + + QmlMetaProperty p1(*property); + QCOMPARE(p1.name(), QString("defaultProperty")); + QCOMPARE(p1.read(), QVariant(10)); + QCOMPARE(p1.type(), QmlMetaProperty::Property); + QCOMPARE(p1.propertyCategory(), QmlMetaProperty::Normal); + QCOMPARE(p1.propertyType(), (int)QVariant::Int); + + QmlMetaProperty p2(&object, QLatin1String("url")); + QCOMPARE(p2.name(), QString("url")); + p2 = *property; + QCOMPARE(p2.name(), QString("defaultProperty")); + QCOMPARE(p2.read(), QVariant(10)); + QCOMPARE(p2.type(), QmlMetaProperty::Property); + QCOMPARE(p2.propertyCategory(), QmlMetaProperty::Normal); + QCOMPARE(p2.propertyType(), (int)QVariant::Int); + + delete property; property = 0; + + QCOMPARE(p1.name(), QString("defaultProperty")); + QCOMPARE(p1.read(), QVariant(10)); + QCOMPARE(p1.type(), QmlMetaProperty::Property); + QCOMPARE(p1.propertyCategory(), QmlMetaProperty::Normal); + QCOMPARE(p1.propertyType(), (int)QVariant::Int); + + QCOMPARE(p2.name(), QString("defaultProperty")); + QCOMPARE(p2.read(), QVariant(10)); + QCOMPARE(p2.type(), QmlMetaProperty::Property); + QCOMPARE(p2.propertyCategory(), QmlMetaProperty::Normal); + QCOMPARE(p2.propertyType(), (int)QVariant::Int); +} + QTEST_MAIN(tst_qmlmetaproperty) #include "tst_qmlmetaproperty.moc" -- cgit v0.12 From c48ce6292d52b6f0a2a0ba54109a426d33eb7842 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 23 Feb 2010 13:42:25 +1000 Subject: Work. --- tests/auto/declarative/qmlmoduleplugin/plugin/plugin.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/auto/declarative/qmlmoduleplugin/plugin/plugin.cpp b/tests/auto/declarative/qmlmoduleplugin/plugin/plugin.cpp index 0d7f985..ddd1e5e 100644 --- a/tests/auto/declarative/qmlmoduleplugin/plugin/plugin.cpp +++ b/tests/auto/declarative/qmlmoduleplugin/plugin/plugin.cpp @@ -77,6 +77,11 @@ public: { return QStringList() << QLatin1String("com.nokia.AutoTestQmlPluginType"); } + + void defineModule(const QString& uri) + { + Q_ASSERT(uri == "com.nokia.AutoTestQmlPluginType"); + } }; #include "plugin.moc" -- cgit v0.12 From e988763395625171bed001b5916d4da003d39aee Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 23 Feb 2010 13:58:24 +1000 Subject: Doc. --- doc/src/declarative/advtutorial1.qdoc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/src/declarative/advtutorial1.qdoc b/doc/src/declarative/advtutorial1.qdoc index 2c99819..e7f4f1a 100644 --- a/doc/src/declarative/advtutorial1.qdoc +++ b/doc/src/declarative/advtutorial1.qdoc @@ -51,20 +51,20 @@ Here is the QML code for the basic elements. The game window: \snippet declarative/tutorials/samegame/samegame1/samegame.qml 0 -This gives you a basic game window, with room for the game canvas. A new game -button and room to display the score. The one thing you may not recognize here +This gives you a basic game window, with room for the game canvas, a new game +button and room to display the score. One thing you may not recognize here is the \l SystemPalette item. This item provides access to the Qt system palette and is used to make the button look more like a system button (for exact native -feel you would use a \l QPushButton). Since we want a fully functional button, -we use the QML elements Text and MouseArea inside a Rectangle to assemble a -button. Below is the code which we wrote to do this: +feel you would use a \l QPushButton). In this case we've created our own custom +Button element using the QML elements Text and MouseArea inside a Rectangle. +Below is the code which we wrote to do this (Button.qml): \snippet declarative/tutorials/samegame/samegame1/Button.qml 0 Note that this Button component was written to be fairly generic, in case we want to use a similarly styled button later. -And here is a simple block: +And here is a simple block (Block.qml): \snippet declarative/tutorials/samegame/samegame1/Block.qml 0 -- cgit v0.12 From f8eee22dcdd9b6b530c0e5c346e16552352ec03b Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 23 Feb 2010 15:40:22 +1000 Subject: Add XmlRole::isKey property for incremental data changes when reload() is called. Task-number: QT-2831 --- src/declarative/util/qmlxmllistmodel.cpp | 175 +++++++++++--- .../qmlxmllistmodel/tst_qmlxmllistmodel.cpp | 254 +++++++++++++++++++++ 2 files changed, 400 insertions(+), 29 deletions(-) diff --git a/src/declarative/util/qmlxmllistmodel.cpp b/src/declarative/util/qmlxmllistmodel.cpp index df2102a..5de4d6f 100644 --- a/src/declarative/util/qmlxmllistmodel.cpp +++ b/src/declarative/util/qmlxmllistmodel.cpp @@ -63,6 +63,8 @@ QT_BEGIN_NAMESPACE QML_DEFINE_TYPE(Qt,4,6,XmlRole,QmlXmlListModelRole) QML_DEFINE_TYPE(Qt,4,6,XmlListModel,QmlXmlListModel) +typedef QPair QmlXmlListRange; + /*! \qmlclass XmlRole QmlXmlListModelRole \brief The XmlRole element allows you to specify a role for an XmlListModel. @@ -94,14 +96,26 @@ QML_DEFINE_TYPE(Qt,4,6,XmlListModel,QmlXmlListModel) \endqml */ +/*! + \qmlproperty bool XmlRole::isKey + Defines whether this is a key role. + + Key roles are used to to determine whether a set of values should + be updated or added to the XML list model when XmlListModel::reload() + is called. + + \sa XmlListModel +*/ + class Q_DECLARATIVE_EXPORT QmlXmlListModelRole : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString query READ query WRITE setQuery) + Q_PROPERTY(bool isKey READ isKey WRITE setIsKey) public: - QmlXmlListModelRole() {} + QmlXmlListModelRole() : m_isKey(false) {} ~QmlXmlListModelRole() {} QString name() const { return m_name; } @@ -117,6 +131,9 @@ public: m_query = query; } + bool isKey() const { return m_isKey; } + void setIsKey(bool b) { m_isKey = b; } + bool isValid() { return !m_name.isEmpty() && !m_query.isEmpty(); } @@ -124,6 +141,7 @@ public: private: QString m_name; QString m_query; + bool m_isKey; }; QT_END_NAMESPACE QML_DECLARE_TYPE(QmlXmlListModelRole) @@ -166,7 +184,6 @@ public: int doQuery(QString query, QString namespaces, QByteArray data, QmlXmlRoleList *roleObjects) { QMutexLocker locker(&m_mutex); - m_modelData.clear(); m_size = 0; m_data = data; m_query = QLatin1String("doc($src)") + query; @@ -188,6 +205,16 @@ public: return m_modelData; } + QList insertedItemRanges() { + QMutexLocker locker(&m_mutex); + return m_insertedItemRanges; + } + + QList removedItemRanges() { + QMutexLocker locker(&m_mutex); + return m_removedItemRanges; + } + Q_SIGNALS: void queryCompleted(int queryId, int size); @@ -197,13 +224,12 @@ protected: m_mutex.lock(); int queryId = m_queryId; doQueryJob(); - if (m_size > 0) - doSubQueryJob(); + doSubQueryJob(); m_data.clear(); // no longer needed m_mutex.unlock(); m_mutex.lock(); - if (!m_abort && m_size > 0) + if (!m_abort) emit queryCompleted(queryId, m_size); if (!m_restart) m_condition.wait(&m_mutex); @@ -216,6 +242,8 @@ protected: private: void doQueryJob(); void doSubQueryJob(); + void getValuesOfKeyRoles(QStringList *values, QXmlQuery *query) const; + void addIndexToRangeList(QList *ranges, int index) const; private: QMutex m_mutex; @@ -231,6 +259,9 @@ private: int m_queryId; const QmlXmlRoleList *m_roleObjects; QList > m_modelData; + QStringList m_keysValues; + QList m_insertedItemRanges; + QList m_removedItemRanges; }; void QmlXmlQuery::doQueryJob() @@ -275,6 +306,40 @@ void QmlXmlQuery::doQueryJob() m_size = count; } +void QmlXmlQuery::getValuesOfKeyRoles(QStringList *values, QXmlQuery *query) const +{ + QStringList keysQueries; + for (int i=0; icount(); i++) { + if (m_roleObjects->at(i)->isKey()) + keysQueries << m_roleObjects->at(i)->query(); + } + QString keysQuery; + if (keysQueries.count() == 1) + keysQuery = m_prefix + keysQueries[0]; + else if (keysQueries.count() > 1) + keysQuery = m_prefix + QLatin1String("concat(") + keysQueries.join(QLatin1String(",")) + QLatin1String(")"); + + if (!keysQuery.isEmpty()) { + query->setQuery(keysQuery); + QXmlResultItems resultItems; + query->evaluateTo(&resultItems); + QXmlItem item(resultItems.next()); + while (!item.isNull()) { + values->append(item.toAtomicValue().toString()); + item = resultItems.next(); + } + } +} + +void QmlXmlQuery::addIndexToRangeList(QList *ranges, int index) const { + if (ranges->isEmpty()) + ranges->append(qMakePair(index, 1)); + else if (ranges->last().first + ranges->last().second == index) + ranges->last().second += 1; + else + ranges->append(qMakePair(index, 1)); +} + void QmlXmlQuery::doSubQueryJob() { m_modelData.clear(); @@ -285,6 +350,35 @@ void QmlXmlQuery::doSubQueryJob() QXmlQuery subquery; subquery.bindVariable(QLatin1String("inputDocument"), &b); + QStringList keysValues; + getValuesOfKeyRoles(&keysValues, &subquery); + + // See if any values of key roles have been inserted or removed. + m_insertedItemRanges.clear(); + m_removedItemRanges.clear(); + if (m_keysValues.isEmpty()) { + m_insertedItemRanges << qMakePair(0, m_size); + } else { + if (keysValues != m_keysValues) { + QStringList temp; + for (int i=0; isize(); ++i) { QmlXmlListModelRole *role = m_roleObjects->at(i); @@ -296,13 +390,13 @@ void QmlXmlQuery::doSubQueryJob() continue; } subquery.setQuery(m_prefix + QLatin1String("(let $v := ") + role->query() + QLatin1String(" return if ($v) then ") + role->query() + QLatin1String(" else \"\")")); - QXmlResultItems output3; - subquery.evaluateTo(&output3); - QXmlItem item(output3.next()); + QXmlResultItems resultItems; + subquery.evaluateTo(&resultItems); + QXmlItem item(resultItems.next()); QList resultList; while (!item.isNull()) { resultList << item.toAtomicValue(); //### we used to trim strings - item = output3.next(); + item = resultItems.next(); } //### should warn here if things have gone wrong. while (resultList.count() < m_size) @@ -408,25 +502,40 @@ void QmlXmlRoleList::insert(int i, QmlXmlListModelRole *role) /*! \qmlclass XmlListModel QmlXmlListModel - \brief The XmlListModel element allows you to specify a model using XPath expressions. + \brief The XmlListModel element is used to specify a model using XPath expressions. - XmlListModel allows you to construct a model from XML data that can then be used as a data source - for the view classes (ListView, PathView, GridView) and any other classes that interact with model - data (like Repeater). + XmlListModel is used to create a model from XML data that can be used as a data source + for the view classes (such as ListView, PathView, GridView) and other classes that interact with model + data (such as Repeater). - The following is an example of a model containing news from a Yahoo RSS feed: + Here is an example of a model containing news from a Yahoo RSS feed: \qml XmlListModel { id: feedModel source: "http://rss.news.yahoo.com/rss/oceania" query: "/rss/channel/item" XmlRole { name: "title"; query: "title/string()" } - XmlRole { name: "link"; query: "link/string()" } + XmlRole { name: "pubDate"; query: "pubDate/string()" } XmlRole { name: "description"; query: "description/string()" } } \endqml - \note The model is currently static, so the above is really just a snapshot of an RSS feed. To force a - reload of the entire model, you can call the reload function. + + You can also define certain roles as "keys" so that the model only adds data + that contains new values for these keys when reload() is called. + + For example, if the roles above were defined like this: + + \qml + XmlRole { name: "title"; query: "title/string()"; isKey: true } + XmlRole { name: "pubDate"; query: "pubDate/string()"; isKey: true } + \endqml + + Then when reload() is called, the model will only add new items with a + "title" and "pubDate" value combination that is not already present in + the model. + + This is useful to provide incremental updates and avoid repainting an + entire model in a view. */ QmlXmlListModel::QmlXmlListModel(QObject *parent) @@ -632,8 +741,13 @@ void QmlXmlListModel::componentComplete() /*! \qmlmethod XmlListModel::reload() - Reloads the model. All the existing model data will be removed, and the model - will be rebuilt from scratch. + Reloads the model. + + If no key roles have been specified, all existing model + data is removed, and the model is rebuilt from scratch. + + Otherwise, items are only added if the model does not already + contain items with matching key role values. */ void QmlXmlListModel::reload() { @@ -645,12 +759,8 @@ void QmlXmlListModel::reload() d->qmlXmlQuery.abort(); d->queryId = -1; - //clear existing data - int count = d->size; - d->size = 0; - d->data.clear(); - if (count > 0) - emit itemsRemoved(0, count); + if (d->size < 0) + d->size = 0; if (d->src.isEmpty() && d->xml.isEmpty()) return; @@ -717,12 +827,19 @@ void QmlXmlListModel::queryCompleted(int id, int size) Q_D(QmlXmlListModel); if (id != d->queryId) return; + bool sizeChanged = size != d->size; d->size = size; - if (size > 0) { - d->data = d->qmlXmlQuery.modelData(); - emit itemsInserted(0, d->size); + d->data = d->qmlXmlQuery.modelData(); + + QList removed = d->qmlXmlQuery.removedItemRanges(); + for (int i=0; i inserted = d->qmlXmlQuery.insertedItemRanges(); + for (int i=0; i +#include +#include #ifdef QTEST_XMLPATTERNS #include @@ -46,6 +48,12 @@ #include #include "../../../shared/util.h" +typedef QPair QmlXmlListRange; +typedef QList QmlXmlModelData; + +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QmlXmlModelData) + class tst_qmlxmllistmodel : public QObject { @@ -61,8 +69,47 @@ private slots: void roles(); void roleErrors(); void uniqueRoleNames(); + void useKeys(); + void useKeys_data(); + void noKeysValueChanges(); + void keysChanged(); private: + QString makeItemXmlAndData(const QString &data, QmlXmlModelData *modelData = 0) const + { + if (modelData) + modelData->clear(); + QString xml; + + if (!data.isEmpty()) { + QStringList items = data.split(";"); + foreach(const QString &item, items) { + QVariantList variants; + xml += QLatin1String(""); + QStringList fields = item.split(","); + foreach(const QString &field, fields) { + QStringList values = field.split("="); + Q_ASSERT(values.count() == 2); + xml += QString("<%1>%2").arg(values[0], values[1]); + if (!modelData) + continue; + bool isNum = false; + int number = values[1].toInt(&isNum); + if (isNum) + variants << number; + else + variants << values[1]; + } + xml += QLatin1String(""); + if (modelData) + modelData->append(variants); + } + } + + QString decl = ""; + return decl + QLatin1String("") + xml + QLatin1String(""); + } + QmlEngine engine; }; @@ -194,6 +241,213 @@ void tst_qmlxmllistmodel::uniqueRoleNames() delete listModel; } +void tst_qmlxmllistmodel::useKeys() +{ + // If using incremental updates through keys, the model should only + // insert & remove some of the items, instead of throwing everything + // away and causing the view to repaint the whole view. + + QFETCH(QString, oldXml); + QFETCH(int, oldCount); + QFETCH(QString, newXml); + QFETCH(QmlXmlModelData, newData); + QFETCH(QList, insertRanges); + QFETCH(QList, removeRanges); + + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/roleKeys.qml")); + QmlXmlListModel *model = qobject_cast(component.create()); + QVERIFY(model != 0); + + model->setXml(oldXml); + QTRY_COMPARE(model->count(), oldCount); + + QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); + QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); + QSignalSpy spyCount(model, SIGNAL(countChanged())); + + model->setXml(newXml); + + if (oldCount != newData.count()) { + QTRY_COMPARE(model->count(), newData.count()); + QCOMPARE(spyCount.count(), 1); + } else { + QTRY_VERIFY(spyInsert.count() > 0 || spyRemove.count() > 0); + QCOMPARE(spyCount.count(), 0); + } + + QList roles = model->roles(); + for (int i=0; icount(); i++) { + for (int j=0; jdata(i, roles[j]), newData[i][j]); + } + + QCOMPARE(spyInsert.count(), insertRanges.count()); + for (int i=0; i("oldXml"); + QTest::addColumn("oldCount"); + QTest::addColumn("newXml"); + QTest::addColumn("newData"); + QTest::addColumn >("insertRanges"); + QTest::addColumn >("removeRanges"); + + QmlXmlModelData modelData; + + QTest::newRow("append 1") + << makeItemXmlAndData("name=A,age=25,sport=Football") << 1 + << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics", &modelData) + << modelData + << (QList() << qMakePair(1, 1)) + << QList(); + + QTest::newRow("append multiple") + << makeItemXmlAndData("name=A,age=25,sport=Football") << 1 + << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics;name=C,age=45,sport=Curling", &modelData) + << modelData + << (QList() << qMakePair(1, 2)) + << QList(); + + QTest::newRow("insert in different spots") + << makeItemXmlAndData("name=B,age=35,sport=Athletics") << 1 + << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics;name=C,age=45,sport=Curling;name=D,age=55,sport=Golf", &modelData) + << modelData + << (QList() << qMakePair(0, 1) << qMakePair(2,2)) + << QList(); + + QTest::newRow("insert in middle") + << makeItemXmlAndData("name=A,age=25,sport=Football;name=D,age=55,sport=Golf") << 2 + << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics;name=C,age=45,sport=Curling;name=D,age=55,sport=Golf", &modelData) + << modelData + << (QList() << qMakePair(1, 2)) + << QList(); + + QTest::newRow("remove first") + << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics") << 2 + << makeItemXmlAndData("name=B,age=35,sport=Athletics", &modelData) + << modelData + << QList() + << (QList() << qMakePair(0, 1)); + + QTest::newRow("remove last") + << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics") << 2 + << makeItemXmlAndData("name=A,age=25,sport=Football", &modelData) + << modelData + << QList() + << (QList() << qMakePair(1, 1)); + + QTest::newRow("remove from multiple spots") + << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics;name=C,age=45,sport=Curling;name=D,age=55,sport=Golf;name=E,age=65,sport=Fencing") << 5 + << makeItemXmlAndData("name=A,age=25,sport=Football;name=C,age=45,sport=Curling", &modelData) + << modelData + << QList() + << (QList() << qMakePair(1, 1) << qMakePair(3,2)); + + QTest::newRow("remove all") + << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics;name=C,age=45,sport=Curling") << 3 + << makeItemXmlAndData("", &modelData) + << modelData + << QList() + << (QList() << qMakePair(0, 3)); + + QTest::newRow("replace item") + << makeItemXmlAndData("name=A,age=25,sport=Football") << 1 + << makeItemXmlAndData("name=ZZZ,age=25,sport=Football", &modelData) + << modelData + << (QList() << qMakePair(0, 1)) + << (QList() << qMakePair(0, 1)); + + QTest::newRow("add and remove simultaneously") + << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics;name=C,age=45,sport=Curling;name=D,age=55,sport=Golf") << 4 + << makeItemXmlAndData("name=B,age=35,sport=Athletics;name=E,age=65,sport=Fencing", &modelData) + << modelData + << (QList() << qMakePair(1, 1)) + << (QList() << qMakePair(0, 1) << qMakePair(2,2)); +} + +void tst_qmlxmllistmodel::noKeysValueChanges() +{ + // The 'key' roles are 'name' and 'age', as defined in roleKeys.qml. + // If a 'sport' value is changed, the model should not be reloaded, + // since 'sport' is not marked as a key. + + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/roleKeys.qml")); + QmlXmlListModel *model = qobject_cast(component.create()); + QVERIFY(model != 0); + + QString xml; + + xml = makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics"); + model->setXml(xml); + QTRY_COMPARE(model->count(), 2); + + QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); + QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); + QSignalSpy spyCount(model, SIGNAL(countChanged())); + + xml = makeItemXmlAndData("name=A,age=25,sport=AussieRules;name=B,age=35,sport=Athletics"); + model->setXml(xml); + + // wait for the new xml data to be set, and verify no signals were emitted + for (int i=0; i<50; i++) { + QTest::qWait(100); + if (model->data(0, model->roles()[2]).toString() != QLatin1String("AussieRules")) + break; + } + QCOMPARE(model->data(0, model->roles()[2]).toString(), QLatin1String("AussieRules")); + + QVERIFY(spyInsert.count() == 0); + QVERIFY(spyRemove.count() == 0); + QVERIFY(spyCount.count() == 0); + + QCOMPARE(model->count(), 2); +} + +void tst_qmlxmllistmodel::keysChanged() +{ + // If the key roles change, the next time the data is reloaded, it should + // delete all its data and build a clean model (i.e. same behaviour as + // if no keys are set). + + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/roleKeys.qml")); + QmlXmlListModel *model = qobject_cast(component.create()); + QVERIFY(model != 0); + + QString xml = makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics"); + model->setXml(xml); + QTRY_COMPARE(model->count(), 2); + + QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); + QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); + QSignalSpy spyCount(model, SIGNAL(countChanged())); + + QVERIFY(QMetaObject::invokeMethod(model, "disableNameKey")); + model->setXml(xml); + + QTRY_VERIFY(spyInsert.count() > 0 && spyRemove.count() > 0); + + QCOMPARE(spyInsert.count(), 1); + QCOMPARE(spyInsert[0][0].toInt(), 0); + QCOMPARE(spyInsert[0][1].toInt(), 2); + + QCOMPARE(spyRemove.count(), 1); + QCOMPARE(spyRemove[0][0].toInt(), 0); + QCOMPARE(spyRemove[0][1].toInt(), 2); + + QCOMPARE(spyCount.count(), 0); +} + QTEST_MAIN(tst_qmlxmllistmodel) #include "tst_qmlxmllistmodel.moc" -- cgit v0.12 From 66b8d89feb2850dbc06503fa66f5963d48616c1d Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 23 Feb 2010 15:40:26 +1000 Subject: Add support for setting the root index when using a QAbstractItemModel. Task-number: QT-2777 --- doc/src/declarative/elements.qdoc | 1 + .../graphicsitems/qmlgraphicsvisualitemmodel.cpp | 165 ++++++++++++++++++++- .../graphicsitems/qmlgraphicsvisualitemmodel_p.h | 7 + 3 files changed, 169 insertions(+), 4 deletions(-) diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 682a2ac..b218b64 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -88,6 +88,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l Binding \o \l ListModel, \l ListElement \o \l VisualItemModel +\o \l VisualDataModel \o \l XmlListModel and XmlRole \o \l DateTimeFormatter \o \l NumberFormatter diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index b96f399..4f28da7 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -327,7 +327,7 @@ public: if (m_listModelInterface) return m_listModelInterface->count(); if (m_abstractItemModel) - return m_abstractItemModel->rowCount(); + return m_abstractItemModel->rowCount(m_root); if (m_listAccessor) return m_listAccessor->count(); return 0; @@ -348,6 +348,8 @@ public: QVariant m_modelVariant; QmlListAccessor *m_listAccessor; + + QModelIndex m_root; }; class QmlGraphicsVisualDataModelDataMetaObject : public QmlOpenMetaObject @@ -461,7 +463,7 @@ QVariant QmlGraphicsVisualDataModelDataMetaObject::initialValue(int propId) QHash::const_iterator it = model->m_roleNames.find(propName); if (it != model->m_roleNames.end()) { roleToProp.insert(*it, propId); - QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0); + QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0, model->m_root); return model->m_abstractItemModel->data(index, *it); } } @@ -560,6 +562,39 @@ QmlGraphicsVisualDataModelData *QmlGraphicsVisualDataModelPrivate::data(QObject //--------------------------------------------------------------------------- +/*! + \qmlclass VisualDataModel QmlGraphicsVisualDataModel + \brief The VisualDataModel encapsulates a model and delegate + + A VisualDataModel encapsulates a model and the delegate that will + be instantiated for items in the model. + + It is usually not necessary to create a VisualDataModel directly, + since the QML views will create one internally. + + The example below illustrates using a VisualDataModel with a ListView. + + \code + VisualDataModel { + id: visualModel + model: myModel + delegate: Component { + Rectangle { + height: 25 + width: 100 + Text { text: "Name:" + name} + } + } + } + ListView { + width: 100 + height: 100 + anchors.fill: parent + model: visualModel + } + \endcode +*/ + QmlGraphicsVisualDataModel::QmlGraphicsVisualDataModel() : QmlGraphicsVisualModel(*(new QmlGraphicsVisualDataModelPrivate(0))) { @@ -579,6 +614,20 @@ QmlGraphicsVisualDataModel::~QmlGraphicsVisualDataModel() d->m_delegateDataType->release(); } +/*! + \qmlproperty model VisualDataModel::model + This property holds the model providing data for the VisualDataModel. + + The model provides a set of data that is used to create the items + for a view. For large or dynamic datasets the model is usually + provided by a C++ model object. The C++ model object must be a \l + {QAbstractItemModel} subclass or a simple list. + + Models can also be created directly in QML, using a \l{ListModel} or + \l{XmlListModel}. + + \sa {qmlmodels}{Data Models} +*/ QVariant QmlGraphicsVisualDataModel::model() const { Q_D(const QmlGraphicsVisualDataModel); @@ -682,6 +731,16 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) } } +/*! + \qmlproperty component VisualDataModel::delegate + + The delegate provides a template defining each item instantiated by a view. + The index is exposed as an accessible \c index property. Properties of the + model are also available depending upon the type of \l {qmlmodels}{Data Model}. + + Here is an example delegate: + \snippet doc/src/snippets/declarative/listview/listview.qml 0 +*/ QmlComponent *QmlGraphicsVisualDataModel::delegate() const { Q_D(const QmlGraphicsVisualDataModel); @@ -705,6 +764,105 @@ void QmlGraphicsVisualDataModel::setDelegate(QmlComponent *delegate) } } +/*! + \qmlproperty QModelIndex VisualDataModel::rootIndex + + QAbstractItemModel provides a heirachical tree of data, whereas + QML only operates on list data. rootIndex allows the children of + any node in a QAbstractItemModel to be provided by this model. + + This property only affects models of type QAbstractItemModel. + + \code + // main.cpp + Q_DECLARE_METATYPE(QModelIndex) + + class MyModel : public QDirModel + { + Q_OBJECT + public: + MyModel(QmlContext *ctxt) : QDirModel(), context(ctxt) { + QHash roles = roleNames(); + roles.insert(FilePathRole, "path"); + setRoleNames(roles); + context->setContextProperty("myModel", this); + context->setContextProperty("myRoot", QVariant::fromValue(index(0,0,QModelIndex()))); + } + + Q_INVOKABLE void setRoot(const QString &path) { + QModelIndex root = index(path); + context->setContextProperty("myRoot", QVariant::fromValue(root)); + } + + QmlContext *context; + }; + + int main(int argc, char ** argv) + { + QApplication app(argc, argv); + + QmlView view; + view.setSource(QUrl("qrc:view.qml")); + + MyModel model(view.rootContext()); + + view.execute(); + view.show(); + + return app.exec(); + } + + #include "main.moc" + \endcode + + \code + // view.qml + import Qt 4.6 + + ListView { + width: 200 + height: 200 + model: VisualDataModel { + model: myModel + rootIndex: myRoot + delegate: Component { + Rectangle { + height: 25; width: 100 + Text { text: path } + MouseRegion { + anchors.fill: parent; + onClicked: myModel.setRoot(path) + } + } + } + } + } + \endcode + +*/ +QModelIndex QmlGraphicsVisualDataModel::rootIndex() const +{ + Q_D(const QmlGraphicsVisualDataModel); + return d->m_root; +} + +void QmlGraphicsVisualDataModel::setRootIndex(const QModelIndex &root) +{ + Q_D(QmlGraphicsVisualDataModel); + if (d->m_root != root) { + int oldCount = d->modelCount(); + d->m_root = root; + int newCount = d->modelCount(); + if (d->m_delegate && oldCount) + emit itemsRemoved(0, oldCount); + if (d->m_delegate && newCount) + emit itemsInserted(0, newCount); + if (newCount != oldCount) + emit countChanged(); + emit rootIndexChanged(); + } +} + QString QmlGraphicsVisualDataModel::part() const { Q_D(const QmlGraphicsVisualDataModel); @@ -786,7 +944,6 @@ QmlGraphicsItem *QmlGraphicsVisualDataModel::item(int index, const QByteArray &v if (d->modelCount() <= 0 || !d->m_delegate) return 0; - QObject *nobj = d->m_cache.getItem(index); if (!nobj) { QmlContext *ccontext = d->m_context; @@ -943,7 +1100,7 @@ void QmlGraphicsVisualDataModel::_q_itemsChanged(int index, int count, if (d->m_listModelInterface) { data->setValue(propId, d->m_listModelInterface->data(ii, QList() << role).value(role)); } else if (d->m_abstractItemModel) { - QModelIndex index = d->m_abstractItemModel->index(ii, 0); + QModelIndex index = d->m_abstractItemModel->index(ii, 0, d->m_root); data->setValue(propId, d->m_abstractItemModel->data(index, role)); } } diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h index 49f9b27..7dc41a8 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h @@ -49,6 +49,8 @@ QT_BEGIN_HEADER +Q_DECLARE_METATYPE(QModelIndex) + QT_BEGIN_NAMESPACE QT_MODULE(Declarative) @@ -147,6 +149,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsVisualDataModel : public QmlGraphicsVisual Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) Q_PROPERTY(QString part READ part WRITE setPart) Q_PROPERTY(QObject *parts READ parts CONSTANT) + Q_PROPERTY(QModelIndex rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged) Q_CLASSINFO("DefaultProperty", "delegate") public: QmlGraphicsVisualDataModel(); @@ -159,6 +162,9 @@ public: QmlComponent *delegate() const; void setDelegate(QmlComponent *); + QModelIndex rootIndex() const; + void setRootIndex(const QModelIndex &root); + QString part() const; void setPart(const QString &); @@ -178,6 +184,7 @@ public: Q_SIGNALS: void createdPackage(int index, QmlPackage *package); void destroyingPackage(QmlPackage *package); + void rootIndexChanged(); private Q_SLOTS: void _q_itemsChanged(int, int, const QList &); -- cgit v0.12 From cd8d8d49f78c1cbb8ad3546e66a461b9e6e29ff5 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 14:24:20 +1000 Subject: Make QmlBinding (and friends) private QmlBinding exposes way too many implementation details to be confident about making it public right now. --- doc/src/declarative/extending.qdoc | 12 -- src/declarative/qml/qml.pri | 2 +- src/declarative/qml/qmlbinding.cpp | 2 +- src/declarative/qml/qmlbinding.h | 132 --------------------- src/declarative/qml/qmlbinding_p.h | 76 +++++++++--- src/declarative/qml/qmlbinding_p_p.h | 89 ++++++++++++++ src/declarative/qml/qmlcompiledbindings_p.h | 2 +- src/declarative/qml/qmlcompiler.cpp | 2 +- src/declarative/qml/qmlcomponent.cpp | 2 +- src/declarative/qml/qmlengine.cpp | 2 +- src/declarative/qml/qmlenginedebug.cpp | 2 +- src/declarative/qml/qmlmetaproperty.cpp | 2 +- src/declarative/qml/qmlobjectscriptclass.cpp | 2 +- src/declarative/qml/qmlpropertycache.cpp | 4 +- src/declarative/qml/qmlvme.cpp | 4 +- src/declarative/util/qmlpropertychanges.cpp | 2 +- src/declarative/util/qmlstate.cpp | 2 +- src/declarative/util/qmlstategroup.cpp | 2 +- src/declarative/util/qmltransitionmanager.cpp | 2 +- tests/auto/declarative/qmldebug/tst_qmldebug.cpp | 2 +- .../qmlmetaproperty/tst_qmlmetaproperty.cpp | 2 +- 21 files changed, 169 insertions(+), 178 deletions(-) delete mode 100644 src/declarative/qml/qmlbinding.h create mode 100644 src/declarative/qml/qmlbinding_p_p.h diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc index d3e6c14..396ddab 100644 --- a/doc/src/declarative/extending.qdoc +++ b/doc/src/declarative/extending.qdoc @@ -557,18 +557,6 @@ to be used in bindings should have a NOTIFY signal instead. \l {Extending QML - Binding Example} shows the BirthdayParty example updated to include NOTIFY signals for use in binding. -\section1 Binding and Script Properties - -While generally no changes are needed to a C++ class to use property -binding, sometimes more advanced interaction between the binding engine and -an object is desirable. To facilitate this, there is a special exception -in the bind engine for allowing an object to access the binding directly. - -If a binding is assigned to a property with a type of QmlBinding -pointer (ie. \c {QmlBinding *}), each time the binding value changes, -a QmlBinding instance is assigned to that property. The QmlBinding instance -allows the object to read the binding and to evaluate the binding's current value. - \section1 Extension Objects \snippet examples/declarative/extending/extended/example.qml 0 diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 2313c37..f09a944 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -60,8 +60,8 @@ HEADERS += \ $$PWD/qmlinstruction_p.h \ $$PWD/qmlvmemetaobject_p.h \ $$PWD/qml.h \ - $$PWD/qmlbinding.h \ $$PWD/qmlbinding_p.h \ + $$PWD/qmlbinding_p_p.h \ $$PWD/qmlmetaproperty.h \ $$PWD/qmlmoduleplugin.h \ $$PWD/qmlcomponent.h \ diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index feadd0f..9f93fee 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qmlbinding.h" #include "qmlbinding_p.h" +#include "qmlbinding_p_p.h" #include "qml.h" #include "qmlcontext.h" diff --git a/src/declarative/qml/qmlbinding.h b/src/declarative/qml/qmlbinding.h deleted file mode 100644 index 151b71c..0000000 --- a/src/declarative/qml/qmlbinding.h +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLBINDING_H -#define QMLBINDING_H - -#include "qml.h" -#include "qmlpropertyvaluesource.h" -#include "qmlexpression.h" - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QmlAbstractBinding -{ -public: - QmlAbstractBinding(); - virtual ~QmlAbstractBinding(); - - virtual void destroy(); - - virtual QString expression() const; - - void setEnabled(bool e) { setEnabled(e, QmlMetaProperty::DontRemoveBinding); } - virtual void setEnabled(bool, QmlMetaProperty::WriteFlags) = 0; - virtual int propertyIndex() = 0; - - void update() { update(QmlMetaProperty::DontRemoveBinding); } - virtual void update(QmlMetaProperty::WriteFlags) = 0; - - void addToObject(QObject *); - void removeFromObject(); - -protected: - void clear(); - -private: - friend class QmlDeclarativeData; - friend class QmlMetaProperty; - friend class QmlMetaPropertyPrivate; - friend class QmlVME; - - QObject *m_object; - QmlAbstractBinding **m_mePtr; - QmlAbstractBinding **m_prevBinding; - QmlAbstractBinding *m_nextBinding; -}; - -class QmlContext; -class QmlBindingPrivate; -class Q_DECLARATIVE_EXPORT QmlBinding : public QmlExpression, - public QmlAbstractBinding -{ -Q_OBJECT -public: - QmlBinding(const QString &, QObject *, QmlContext *, QObject *parent=0); - QmlBinding(void *, QmlRefCount *, QObject *, QmlContext *, const QString &, int, - QObject *parent); - ~QmlBinding(); - - void setTarget(const QmlMetaProperty &); - QmlMetaProperty property() const; - - bool enabled() const; - - // Inherited from QmlAbstractBinding - virtual void setEnabled(bool, QmlMetaProperty::WriteFlags flags); - virtual int propertyIndex(); - virtual void update(QmlMetaProperty::WriteFlags flags); - virtual QString expression() const; - -public Q_SLOTS: - void update() { update(QmlMetaProperty::DontRemoveBinding); } - -protected: - void emitValueChanged(); - -private: - Q_DECLARE_PRIVATE(QmlBinding) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlBinding); - -QT_END_HEADER - -#endif // QMLBINDING_H diff --git a/src/declarative/qml/qmlbinding_p.h b/src/declarative/qml/qmlbinding_p.h index b4f88b5..4594476 100644 --- a/src/declarative/qml/qmlbinding_p.h +++ b/src/declarative/qml/qmlbinding_p.h @@ -53,36 +53,82 @@ // We mean it. // -#include "qmlbinding.h" +#include "qml.h" +#include "qmlpropertyvaluesource.h" +#include "qmlexpression.h" -#include "qmlmetaproperty.h" -#include "qmlexpression_p.h" +#include +#include QT_BEGIN_NAMESPACE -class QmlBindingData : public QmlExpressionData +class Q_AUTOTEST_EXPORT QmlAbstractBinding { public: - QmlBindingData(); - virtual ~QmlBindingData(); + QmlAbstractBinding(); + virtual ~QmlAbstractBinding(); - bool updating:1; - bool enabled:1; + virtual void destroy(); - QmlMetaProperty property; + virtual QString expression() const; - virtual void refresh(); + void setEnabled(bool e) { setEnabled(e, QmlMetaProperty::DontRemoveBinding); } + virtual void setEnabled(bool, QmlMetaProperty::WriteFlags) = 0; + virtual int propertyIndex() = 0; + + void update() { update(QmlMetaProperty::DontRemoveBinding); } + virtual void update(QmlMetaProperty::WriteFlags) = 0; + + void addToObject(QObject *); + void removeFromObject(); + +protected: + void clear(); + +private: + friend class QmlDeclarativeData; + friend class QmlMetaProperty; + friend class QmlMetaPropertyPrivate; + friend class QmlVME; + + QObject *m_object; + QmlAbstractBinding **m_mePtr; + QmlAbstractBinding **m_prevBinding; + QmlAbstractBinding *m_nextBinding; }; -class QmlBindingPrivate : public QmlExpressionPrivate +class QmlContext; +class QmlBindingPrivate; +class Q_AUTOTEST_EXPORT QmlBinding : public QmlExpression, public QmlAbstractBinding { - Q_DECLARE_PUBLIC(QmlBinding) +Q_OBJECT public: - QmlBindingPrivate(); + QmlBinding(const QString &, QObject *, QmlContext *, QObject *parent=0); + QmlBinding(void *, QmlRefCount *, QObject *, QmlContext *, const QString &, int, + QObject *parent); + ~QmlBinding(); + + void setTarget(const QmlMetaProperty &); + QmlMetaProperty property() const; + + bool enabled() const; + + // Inherited from QmlAbstractBinding + virtual void setEnabled(bool, QmlMetaProperty::WriteFlags flags); + virtual int propertyIndex(); + virtual void update(QmlMetaProperty::WriteFlags flags); + virtual QString expression() const; + +public Q_SLOTS: + void update() { update(QmlMetaProperty::DontRemoveBinding); } + +protected: + void emitValueChanged(); - QmlBindingData *bindingData() { return static_cast(data); } - const QmlBindingData *bindingData() const { return static_cast(data); } +private: + Q_DECLARE_PRIVATE(QmlBinding) }; +Q_DECLARE_METATYPE(QmlBinding*); QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlbinding_p_p.h b/src/declarative/qml/qmlbinding_p_p.h new file mode 100644 index 0000000..e5a06fc --- /dev/null +++ b/src/declarative/qml/qmlbinding_p_p.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLBINDING_P_P_H +#define QMLBINDING_P_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlbinding_p.h" + +#include "qmlmetaproperty.h" +#include "qmlexpression_p.h" + +QT_BEGIN_NAMESPACE + +class QmlBindingData : public QmlExpressionData +{ +public: + QmlBindingData(); + virtual ~QmlBindingData(); + + bool updating:1; + bool enabled:1; + + QmlMetaProperty property; + + virtual void refresh(); +}; + +class QmlBindingPrivate : public QmlExpressionPrivate +{ + Q_DECLARE_PUBLIC(QmlBinding) +public: + QmlBindingPrivate(); + + QmlBindingData *bindingData() { return static_cast(data); } + const QmlBindingData *bindingData() const { return static_cast(data); } +}; + +QT_END_NAMESPACE + +#endif // QMLBINDING_P_P_H diff --git a/src/declarative/qml/qmlcompiledbindings_p.h b/src/declarative/qml/qmlcompiledbindings_p.h index 38fb2a3..056cc21 100644 --- a/src/declarative/qml/qmlcompiledbindings_p.h +++ b/src/declarative/qml/qmlcompiledbindings_p.h @@ -54,7 +54,7 @@ // #include "qmlexpression_p.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" QT_BEGIN_HEADER diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index bbae201..10b6e4f 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -63,7 +63,7 @@ #include "qmlscriptstring.h" #include "qmlglobal_p.h" #include "qmlscriptparser_p.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" #include "qmlcompiledbindings_p.h" #include diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 87ecb8a..4ab4f70 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -49,8 +49,8 @@ #include "qmlvme_p.h" #include "qml.h" #include "qmlengine.h" -#include "qmlbinding.h" #include "qmlbinding_p.h" +#include "qmlbinding_p_p.h" #include "qmlglobal_p.h" #include "qmlscriptparser_p.h" diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 97d8250..2460f52 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -51,7 +51,7 @@ #include "qmlcomponent.h" #include "qmlmetaproperty_p.h" #include "qmlmoduleplugin.h" -#include "qmlbinding_p.h" +#include "qmlbinding_p_p.h" #include "qmlvme_p.h" #include "qmlenginedebug_p.h" #include "qmlstringconverters_p.h" diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index 654157c..2ab709a 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -45,7 +45,7 @@ #include "qmlengine.h" #include "qmlmetatype.h" #include "qmlmetaproperty.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" #include "qmlcontext_p.h" #include "qmlwatcher_p.h" diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 1742c43..ac619ec 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -44,7 +44,7 @@ #include "qmlcompositetypedata_p.h" #include "qml.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" #include "qmlcontext.h" #include "qmlcontext_p.h" #include "qmlboundsignal_p.h" diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp index 15ece1d..155a7d6 100644 --- a/src/declarative/qml/qmlobjectscriptclass.cpp +++ b/src/declarative/qml/qmlobjectscriptclass.cpp @@ -46,7 +46,7 @@ #include "qmldeclarativedata_p.h" #include "qmltypenamescriptclass_p.h" #include "qmllistscriptclass_p.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" #include "qmlguard_p.h" #include "qmlvmemetaobject_p.h" diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp index a3e655b..2d087b6 100644 --- a/src/declarative/qml/qmlpropertycache.cpp +++ b/src/declarative/qml/qmlpropertycache.cpp @@ -42,8 +42,8 @@ #include "qmlpropertycache_p.h" #include "qmlengine_p.h" -#include "qmlbinding.h" -#include "qdebug.h" +#include "qmlbinding_p.h" +#include Q_DECLARE_METATYPE(QScriptValue); diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 8655809..f8f1ff0 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -51,11 +51,11 @@ #include "qmlengine.h" #include "qmlcontext.h" #include "qmlcomponent.h" -#include "qmlbinding.h" +#include "qmlbinding_p.h" #include "qmlengine_p.h" #include "qmlcomponent_p.h" #include "qmlvmemetaobject_p.h" -#include "qmlbinding_p.h" +#include "qmlbinding_p_p.h" #include "qmlcontext_p.h" #include "qmlcompiledbindings_p.h" #include "qmlglobal_p.h" diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index 068cb4d..0ce3604 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index 4462b1f..ea99bd5 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -48,7 +48,7 @@ #include "qmlanimation_p.h" #include "qmlanimation_p_p.h" -#include +#include #include #include diff --git a/src/declarative/util/qmlstategroup.cpp b/src/declarative/util/qmlstategroup.cpp index 4ad77c8..7a5db1b 100644 --- a/src/declarative/util/qmlstategroup.cpp +++ b/src/declarative/util/qmlstategroup.cpp @@ -44,7 +44,7 @@ #include "qmltransition_p.h" #include "qmlstate_p_p.h" -#include +#include #include #include diff --git a/src/declarative/util/qmltransitionmanager.cpp b/src/declarative/util/qmltransitionmanager.cpp index f2a4d64..60d9a60 100644 --- a/src/declarative/util/qmltransitionmanager.cpp +++ b/src/declarative/util/qmltransitionmanager.cpp @@ -43,7 +43,7 @@ #include "qmlstate_p_p.h" -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/tests/auto/declarative/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp index ba07331..2f1a557 100644 --- a/tests/auto/declarative/qmldebug/tst_qmldebug.cpp +++ b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp @@ -51,8 +51,8 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp index c289641..540d658 100644 --- a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp +++ b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include class MyQmlObject : public QObject -- cgit v0.12 From 287a8757e348f56e2ae918d1aa5bf329c985f620 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 16:18:33 +1000 Subject: QmlExpression API review --- .../graphicsitems/qmlgraphicsvisualitemmodel.cpp | 3 -- src/declarative/qml/qmlbinding.cpp | 10 ++-- src/declarative/qml/qmlbinding_p_p.h | 2 + src/declarative/qml/qmlboundsignal.cpp | 3 +- src/declarative/qml/qmlenginedebug.cpp | 5 +- src/declarative/qml/qmlexpression.cpp | 62 ++++++++-------------- src/declarative/qml/qmlexpression.h | 11 ++-- src/declarative/qml/qmlexpression_p.h | 2 + src/declarative/qml/qmlwatcher.cpp | 1 + src/declarative/util/qmlanimation.cpp | 1 - src/declarative/util/qmlpropertychanges.cpp | 2 - src/declarative/util/qmlstateoperations.cpp | 1 - tests/auto/declarative/qmlecmascript/testtypes.h | 10 ++-- .../tst_qmlgraphicslistview.cpp | 1 - .../tst_qmlgraphicspathview.cpp | 1 - 15 files changed, 45 insertions(+), 70 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index bfa9e9b..9c11f25 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -187,7 +187,6 @@ QVariant QmlGraphicsVisualItemModel::evaluate(int index, const QString &expressi QmlContext *ctxt = new QmlContext(ccontext); ctxt->addDefaultObject(d->children.at(index)); QmlExpression e(ctxt, expression, objectContext); - e.setTrackChange(false); QVariant value = e.value(); delete ctxt; return value; @@ -1057,7 +1056,6 @@ QVariant QmlGraphicsVisualDataModel::evaluate(int index, const QString &expressi QmlGraphicsItem *item = qobject_cast(nobj); if (item) { QmlExpression e(qmlContext(item), expression, objectContext); - e.setTrackChange(false); value = e.value(); } } else { @@ -1067,7 +1065,6 @@ QVariant QmlGraphicsVisualDataModel::evaluate(int index, const QString &expressi QmlGraphicsVisualDataModelData *data = new QmlGraphicsVisualDataModelData(index, this); ctxt->addDefaultObject(data); QmlExpression e(ctxt, expression, objectContext); - e.setTrackChange(false); value = e.value(); delete data; delete ctxt; diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index 9f93fee..aeda28b 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -85,12 +85,14 @@ QmlBinding::QmlBinding(void *data, QmlRefCount *rc, QObject *obj, QmlContext *ct : QmlExpression(ctxt, data, rc, obj, url, lineNumber, *new QmlBindingPrivate) { setParent(parent); + setNotifyOnValueChanged(true); } QmlBinding::QmlBinding(const QString &str, QObject *obj, QmlContext *ctxt, QObject *parent) : QmlExpression(ctxt, str, obj, *new QmlBindingPrivate) { setParent(parent); + setNotifyOnValueChanged(true); } QmlBinding::~QmlBinding() @@ -198,17 +200,17 @@ void QmlBinding::update(QmlMetaProperty::WriteFlags flags) data->release(); } -void QmlBinding::emitValueChanged() +void QmlBindingPrivate::emitValueChanged() { - update(); - // don't bother calling valueChanged() + Q_Q(QmlBinding); + q->update(); } void QmlBinding::setEnabled(bool e, QmlMetaProperty::WriteFlags flags) { Q_D(QmlBinding); d->bindingData()->enabled = e; - setTrackChange(e); + setNotifyOnValueChanged(e); QmlAbstractBinding::setEnabled(e, flags); diff --git a/src/declarative/qml/qmlbinding_p_p.h b/src/declarative/qml/qmlbinding_p_p.h index e5a06fc..131bacc 100644 --- a/src/declarative/qml/qmlbinding_p_p.h +++ b/src/declarative/qml/qmlbinding_p_p.h @@ -82,6 +82,8 @@ public: QmlBindingData *bindingData() { return static_cast(data); } const QmlBindingData *bindingData() const { return static_cast(data); } + + virtual void emitValueChanged(); }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlboundsignal.cpp b/src/declarative/qml/qmlboundsignal.cpp index a075899..db5fd61 100644 --- a/src/declarative/qml/qmlboundsignal.cpp +++ b/src/declarative/qml/qmlboundsignal.cpp @@ -124,7 +124,6 @@ QmlBoundSignal::QmlBoundSignal(QmlContext *ctxt, const QString &val, QMetaObject::connect(scope, m_signal.methodIndex(), this, evaluateIdx); m_expression = new QmlExpression(ctxt, val, scope); - m_expression->setTrackChange(false); } QmlBoundSignal::~QmlBoundSignal() @@ -157,7 +156,7 @@ QmlExpression *QmlBoundSignal::setExpression(QmlExpression *e) { QmlExpression *rv = m_expression; m_expression = e; - if (m_expression) m_expression->setTrackChange(false); + if (m_expression) m_expression->setNotifyOnValueChanged(false); return rv; } diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index 2ab709a..973e5e5 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -408,14 +408,13 @@ void QmlEngineDebugServer::messageReceived(const QByteArray &message) QmlContext *context = qmlContext(object); QVariant result; if (object && context) { - QmlExpression *exprObj = new QmlExpression(context, expr, object); + QmlExpression exprObj(context, expr, object); bool undefined = false; - QVariant value = exprObj->value(&undefined); + QVariant value = exprObj.value(&undefined); if (undefined) result = QLatin1String(""); else result = valueContents(value); - delete exprObj; } else { result = QLatin1String(""); } diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index 8f0c945..64b2d7f 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -70,7 +70,7 @@ bool QmlDelayedError::addError(QmlEnginePrivate *e) QmlExpressionData::QmlExpressionData() : q(0), dataRef(0), expressionFunctionValid(false), expressionRewritten(false), me(0), - trackChange(true), isShared(false), line(-1), guardList(0), guardListLength(0) + trackChange(false), isShared(false), line(-1), guardList(0), guardListLength(0) { } @@ -273,14 +273,6 @@ QString QmlExpression::expression() const } /*! - Clear the expression. -*/ -void QmlExpression::clearExpression() -{ - setExpression(QString()); -} - -/*! Set the expression to \a expression. */ void QmlExpression::setExpression(const QString &expression) @@ -495,44 +487,34 @@ QVariant QmlExpression::value(bool *isUndefined) } /*! - Returns true if the expression results in a constant value. - QmlExpression::value() must have been invoked at least once before the - return from this method is valid. - */ -bool QmlExpression::isConstant() const -{ - Q_D(const QmlExpression); - return !d->data->guardList; -} - -/*! - Returns true if the changes are tracked in the expression's value. +Returns true if the valueChanged() signal is emitted when the expression's evaluated +value changes. */ -bool QmlExpression::trackChange() const +bool QmlExpression::notifyOnValueChanged() const { Q_D(const QmlExpression); return d->data->trackChange; } /*! - Set whether changes are tracked in the expression's value to \a trackChange. +Sets whether the valueChanged() signal is emitted when the expression's evaluated +value changes. - If true, the QmlExpression will monitor properties involved in the - expression's evaluation, and call QmlExpression::valueChanged() if they have - changed. This allows an application to ensure that any value associated - with the result of the expression remains up to date. +If true, the QmlExpression will monitor properties involved in the expression's +evaluation, and emit QmlExpression::valueChanged() if they have changed. This allows +an application to ensure that any value associated with the result of the expression +remains up to date. - If false, the QmlExpression will not montitor properties involved in the - expression's evaluation, and QmlExpression::valueChanged() will never be - called. This is more efficient if an application wants a "one off" - evaluation of the expression. +If false, the QmlExpression will not montitor properties involved in the expression's +evaluation, and QmlExpression::valueChanged() will never be emitted. This is more efficient +if an application wants a "one off" evaluation of the expression. - By default, trackChange is true. +By default, notifyOnChange is false. */ -void QmlExpression::setTrackChange(bool trackChange) +void QmlExpression::setNotifyOnValueChanged(bool notifyOnChange) { Q_D(QmlExpression); - d->data->trackChange = trackChange; + d->data->trackChange = notifyOnChange; } /*! @@ -618,7 +600,8 @@ QmlError QmlExpression::error() const /*! \internal */ void QmlExpression::__q_notify() { - emitValueChanged(); + Q_D(QmlExpression); + d->emitValueChanged(); } void QmlExpressionPrivate::clearGuards() @@ -765,13 +748,10 @@ void QmlExpressionPrivate::updateGuards(const QPODVectorvalueChanged(); } QmlAbstractExpression::QmlAbstractExpression() diff --git a/src/declarative/qml/qmlexpression.h b/src/declarative/qml/qmlexpression.h index 428eefa..61374f2 100644 --- a/src/declarative/qml/qmlexpression.h +++ b/src/declarative/qml/qmlexpression.h @@ -70,12 +70,10 @@ public: QmlContext *context() const; QString expression() const; - void clearExpression(); - virtual void setExpression(const QString &); - bool isConstant() const; + void setExpression(const QString &); - bool trackChange() const; - void setTrackChange(bool); + bool notifyOnValueChanged() const; + void setNotifyOnValueChanged(bool); QString sourceFile() const; int lineNumber() const; @@ -87,15 +85,12 @@ public: void clearError(); QmlError error() const; -public Q_SLOTS: QVariant value(bool *isUndefined = 0); Q_SIGNALS: void valueChanged(); protected: - virtual void emitValueChanged(); - QmlExpression(QmlContext *, const QString &, QObject *, QmlExpressionPrivate &dd); QmlExpression(QmlContext *, void *, QmlRefCount *rc, QObject *me, const QString &, diff --git a/src/declarative/qml/qmlexpression_p.h b/src/declarative/qml/qmlexpression_p.h index e52a199..e4bed05 100644 --- a/src/declarative/qml/qmlexpression_p.h +++ b/src/declarative/qml/qmlexpression_p.h @@ -177,6 +177,8 @@ public: return expr->q_func(); } + virtual void emitValueChanged(); + static void exceptionToError(QScriptEngine *, QmlError &); static QScriptValue evalInObjectScope(QmlContext *, QObject *, const QString &); static QScriptValue evalInObjectScope(QmlContext *, QObject *, const QScriptProgram &); diff --git a/src/declarative/qml/qmlwatcher.cpp b/src/declarative/qml/qmlwatcher.cpp index 59503de..a8a94c5 100644 --- a/src/declarative/qml/qmlwatcher.cpp +++ b/src/declarative/qml/qmlwatcher.cpp @@ -154,6 +154,7 @@ bool QmlWatcher::addWatch(int id, quint32 objectId, const QString &expr) QmlContext *context = qmlContext(object); if (context) { QmlExpression *exprObj = new QmlExpression(context, expr, object); + exprObj->setNotifyOnValueChanged(true); QmlWatchProxy *proxy = new QmlWatchProxy(id, exprObj, objectId, this); exprObj->setParent(proxy); m_proxies[id].append(proxy); diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index c044f97..6dcce58 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -793,7 +793,6 @@ void QmlScriptActionPrivate::execute() const QString &str = scriptStr.script(); if (!str.isEmpty()) { QmlExpression expr(scriptStr.context(), str, scriptStr.scopeObject()); - expr.setTrackChange(false); expr.value(); } } diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index 0ce3604..3abbadd 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -277,14 +277,12 @@ void QmlPropertyChangesPrivate::decode() QmlMetaProperty prop = property(name); //### better way to check for signal property? if (prop.type() & QmlMetaProperty::SignalProperty) { QmlExpression *expression = new QmlExpression(qmlContext(q), data.toString(), object); - expression->setTrackChange(false); QmlReplaceSignalHandler *handler = new QmlReplaceSignalHandler; handler->property = prop; handler->expression = expression; signalReplacements << handler; } else if (isScript) { QmlExpression *expression = new QmlExpression(qmlContext(q), data.toString(), object); - expression->setTrackChange(false); expressions << qMakePair(name, expression); } else { properties << qMakePair(name, data); diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index bd1f5f0..fff8774 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -373,7 +373,6 @@ void QmlStateChangeScript::execute() const QString &script = d->script.script(); if (!script.isEmpty()) { QmlExpression expr(d->script.context(), script, d->script.scopeObject()); - expr.setTrackChange(false); expr.value(); } } diff --git a/tests/auto/declarative/qmlecmascript/testtypes.h b/tests/auto/declarative/qmlecmascript/testtypes.h index 0af72cb..f511c29 100644 --- a/tests/auto/declarative/qmlecmascript/testtypes.h +++ b/tests/auto/declarative/qmlecmascript/testtypes.h @@ -173,17 +173,21 @@ QML_DECLARE_TYPE(MyQmlContainer); class MyExpression : public QmlExpression { + Q_OBJECT public: MyExpression(QmlContext *ctxt, const QString &expr) : QmlExpression(ctxt, expr, 0), changed(false) { + QObject::connect(this, SIGNAL(valueChanged()), this, SLOT(expressionValueChanged())); + setNotifyOnValueChanged(true); } - void emitValueChanged() { + bool changed; + +public slots: + void expressionValueChanged() { changed = true; - QmlExpression::emitValueChanged(); } - bool changed; }; diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index 13ed41d..0876520 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -1322,7 +1322,6 @@ T *tst_QmlGraphicsListView::findItem(QGraphicsObject *parent, const QString &obj if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { if (index != -1) { QmlExpression e(qmlContext(item), "index", item); - e.setTrackChange(false); if (e.value().toInt() == index) return static_cast(item); } else { diff --git a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp index b986a64..62b3cfc 100644 --- a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp +++ b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp @@ -452,7 +452,6 @@ T *tst_QmlGraphicsPathView::findItem(QGraphicsObject *parent, const QString &obj if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { if (index != -1) { QmlExpression e(qmlContext(item), "index", item); - e.setTrackChange(false); if (e.value().toInt() == index) return static_cast(item); } else { -- cgit v0.12 From c2988e5bc92c81e35e6b11092a2c4fa237cf9fdb Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 23 Feb 2010 16:39:30 +1000 Subject: Doc fix. Task-number: QT-2831 --- src/declarative/util/qmlxmllistmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/util/qmlxmllistmodel.cpp b/src/declarative/util/qmlxmllistmodel.cpp index 7e66576..6c9c03e 100644 --- a/src/declarative/util/qmlxmllistmodel.cpp +++ b/src/declarative/util/qmlxmllistmodel.cpp @@ -635,9 +635,9 @@ void QmlXmlListModel::setXml(const QString &xml) } /*! - \qmlproperty url XmlListModel::query + \qmlproperty string XmlListModel::query An absolute XPath query representing the base query for the model items. The query should start with - a '/' or '//'. + '/' or '//'. */ QString QmlXmlListModel::query() const { -- cgit v0.12 From c38be88e5314f43efd7cb6a2e8140d006e77afbe Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 23 Feb 2010 16:44:58 +1000 Subject: Make executable outside dir. --- .../qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp index b51266a..21c0efc 100644 --- a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp +++ b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp @@ -249,7 +249,7 @@ void tst_QmlGraphicsPositioners::test_vertical_animated() void tst_QmlGraphicsPositioners::test_grid() { - QmlView *canvas = createView("data/grid.qml"); + QmlView *canvas = createView(SRCDIR "/data/grid.qml"); canvas->execute(); @@ -278,7 +278,7 @@ void tst_QmlGraphicsPositioners::test_grid() void tst_QmlGraphicsPositioners::test_grid_spacing() { - QmlView *canvas = createView("data/grid-spacing.qml"); + QmlView *canvas = createView(SRCDIR "/data/grid-spacing.qml"); canvas->execute(); @@ -381,7 +381,7 @@ void tst_QmlGraphicsPositioners::test_grid_animated() void tst_QmlGraphicsPositioners::test_repeater() { - QmlView *canvas = createView("data/repeater.qml"); + QmlView *canvas = createView(SRCDIR "/data/repeater.qml"); canvas->execute(); -- cgit v0.12 From 5ffd6c0fba0ecc709551e414ed0649de15ac3754 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 23 Feb 2010 16:46:44 +1000 Subject: Remove QmlView::execute(). QmlView::setSource() does it all now. Task-number: QT-2538 --- demos/declarative/minehunt/main.cpp | 4 +- examples/declarative/imageprovider/main.cpp | 3 +- examples/declarative/objectlistmodel/main.cpp | 3 +- .../graphicsitems/qmlgraphicsvisualitemmodel.cpp | 3 +- src/declarative/util/qmlview.cpp | 60 ++++++++++++---------- src/declarative/util/qmlview.h | 3 +- tests/auto/declarative/layouts/tst_layouts.cpp | 1 - .../qmlanimations/tst_qmlanimations.cpp | 1 - .../qmlgraphicsanchors/tst_qmlgraphicsanchors.cpp | 45 ++++++---------- .../tst_qmlgraphicsgridview.cpp | 35 ++++++------- .../qmlgraphicsitem/tst_qmlgraphicsitem.cpp | 5 +- .../tst_qmlgraphicslistview.cpp | 55 ++++++++++---------- .../tst_qmlgraphicsmousearea.cpp | 1 - .../tst_qmlgraphicsparticles.cpp | 1 - .../tst_qmlgraphicspathview.cpp | 18 +++---- .../tst_qmlgraphicspositioners.cpp | 19 ------- .../tst_qmlgraphicsrepeater.cpp | 26 +++++----- .../tst_qmlgraphicstextedit.cpp | 7 --- .../tst_qmlgraphicstextinput.cpp | 7 --- tools/qmlviewer/qmlviewer.cpp | 6 +-- 20 files changed, 123 insertions(+), 180 deletions(-) diff --git a/demos/declarative/minehunt/main.cpp b/demos/declarative/minehunt/main.cpp index 0b862e3..a897919 100644 --- a/demos/declarative/minehunt/main.cpp +++ b/demos/declarative/minehunt/main.cpp @@ -167,13 +167,11 @@ MyWidget::MyWidget(int width, int height, QWidget *parent, Qt::WindowFlags flags canvas->setFixedSize(width, height); vbox->addWidget(canvas); - canvas->setSource(QUrl::fromLocalFile(fileName)); - QmlContext *ctxt = canvas->rootContext(); ctxt->addDefaultObject(this); ctxt->setContextProperty("tiles", QVariant::fromValue*>(&_tiles));//QTBUG-5675 - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(fileName)); } MyWidget::~MyWidget() diff --git a/examples/declarative/imageprovider/main.cpp b/examples/declarative/imageprovider/main.cpp index 9526105..eaaded2 100644 --- a/examples/declarative/imageprovider/main.cpp +++ b/examples/declarative/imageprovider/main.cpp @@ -75,7 +75,6 @@ int main(int argc, char ** argv) QApplication app(argc, argv); QmlView view; - view.setSource(QUrl("qrc:view.qml")); view.engine()->addImageProvider("colors", new ColorImageProvider); @@ -91,7 +90,7 @@ int main(int argc, char ** argv) QmlContext *ctxt = view.rootContext(); ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); - view.execute(); + view.setSource(QUrl("qrc:view.qml")); view.show(); return app.exec(); diff --git a/examples/declarative/objectlistmodel/main.cpp b/examples/declarative/objectlistmodel/main.cpp index 9e38bea..7ea742b 100644 --- a/examples/declarative/objectlistmodel/main.cpp +++ b/examples/declarative/objectlistmodel/main.cpp @@ -59,7 +59,6 @@ int main(int argc, char ** argv) QApplication app(argc, argv); QmlView view; - view.setSource(QUrl("qrc:view.qml")); QList dataList; dataList.append(new DataObject("Item 1", "red")); @@ -70,7 +69,7 @@ int main(int argc, char ** argv) QmlContext *ctxt = view.rootContext(); ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); - view.execute(); + view.setSource(QUrl("qrc:view.qml")); view.show(); return app.exec(); diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index bfa9e9b..a9d67ab 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -802,11 +802,10 @@ void QmlGraphicsVisualDataModel::setDelegate(QmlComponent *delegate) QApplication app(argc, argv); QmlView view; - view.setSource(QUrl("qrc:view.qml")); MyModel model(view.rootContext()); - view.execute(); + view.setSource(QUrl("qrc:view.qml")); view.show(); return app.exec(); diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index 400ae52..05c6460 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -132,6 +132,8 @@ public: QmlViewPrivate(QmlView *view) : q(view), root(0), component(0), resizeMode(QmlView::SizeViewToRootObject) {} + void execute(); + QmlView *q; QGuard root; @@ -152,6 +154,20 @@ public: QGraphicsScene scene; }; +void QmlViewPrivate::execute() +{ + delete root; + delete component; + component = new QmlComponent(&engine, source, q); + + if (!component->isLoading()) { + q->continueExecute(); + } else { + QObject::connect(component, SIGNAL(statusChanged(QmlComponent::Status)), q, SLOT(continueExecute())); + } +} + + /*! \class QmlView \brief The QmlView class provides a widget for displaying a Qt Declarative user interface. @@ -188,9 +204,6 @@ public: QUrl url(fileName); view->setSource(url); - ... - view->execute(); - ... view->show(); \endcode @@ -220,6 +233,19 @@ QmlView::QmlView(QWidget *parent) d->init(); } +/*! + \fn QmlView::QmlView(const QUrl &source, QWidget *parent) + + Constructs a QmlView with the given QML \a source and \a parent. +*/ +QmlView::QmlView(const QUrl &source, QWidget *parent) +: QGraphicsView(parent), d(new QmlViewPrivate(this)) +{ + setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); + d->init(); + setSource(source); +} + void QmlViewPrivate::init() { #ifdef Q_ENABLE_PERFORMANCE_LOG @@ -254,15 +280,14 @@ QmlView::~QmlView() } /*! - Sets the source to the \a url. - - Call \l execute() to load the QML and instantiate the component. - - \sa execute() + Sets the source to the \a url, loads the QML component and instantiates it. */ void QmlView::setSource(const QUrl& url) { - d->source = url; + if (url != d->source) { + d->source = url; + d->execute(); + } } /*! @@ -296,23 +321,6 @@ QmlContext* QmlView::rootContext() return d->engine.rootContext(); } -/*! - Loads and instantiates the QML component set by the \l setSource() method. - - \sa setSource() -*/ -void QmlView::execute() -{ - delete d->root; - delete d->component; - d->component = new QmlComponent(&d->engine, d->source, this); - - if (!d->component->isLoading()) { - continueExecute(); - } else { - connect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), this, SLOT(continueExecute())); - } -} /*! \enum QmlView::Status diff --git a/src/declarative/util/qmlview.h b/src/declarative/util/qmlview.h index 1d6ef1c..5f72781 100644 --- a/src/declarative/util/qmlview.h +++ b/src/declarative/util/qmlview.h @@ -67,6 +67,7 @@ class Q_DECLARATIVE_EXPORT QmlView : public QGraphicsView public: explicit QmlView(QWidget *parent = 0); + QmlView(const QUrl &source, QWidget *parent = 0); virtual ~QmlView(); QUrl source() const; @@ -74,7 +75,6 @@ public: QmlEngine* engine(); QmlContext* rootContext(); - void execute(); QGraphicsObject *rootObject() const; @@ -102,6 +102,7 @@ protected: virtual void paintEvent(QPaintEvent *event); void timerEvent(QTimerEvent*); + friend class QmlViewPrivate; QmlViewPrivate *d; }; diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index ee05574..53c1ede 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -67,7 +67,6 @@ void tst_QmlGraphicsLayouts::test_qml() { QmlView *canvas = createView(SRCDIR "/data/layouts.qml"); - canvas->execute(); qApp->processEvents(); QmlGraphicsLayoutItem *left = static_cast(canvas->rootObject()->findChild("left")); QVERIFY(left != 0); diff --git a/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp b/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp index 9eae308..1f6347e 100644 --- a/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp +++ b/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp @@ -261,7 +261,6 @@ void tst_qmlanimations::badTypes() QmlView *view = new QmlView; view->setSource(QUrl::fromLocalFile(SRCDIR "/data/badtype1.qml")); - view->execute(); qApp->processEvents(); delete view; diff --git a/tests/auto/declarative/qmlgraphicsanchors/tst_qmlgraphicsanchors.cpp b/tests/auto/declarative/qmlgraphicsanchors/tst_qmlgraphicsanchors.cpp index aa6b56a..721608e 100644 --- a/tests/auto/declarative/qmlgraphicsanchors/tst_qmlgraphicsanchors.cpp +++ b/tests/auto/declarative/qmlgraphicsanchors/tst_qmlgraphicsanchors.cpp @@ -104,7 +104,6 @@ void tst_qmlgraphicsanchors::basicAnchors() QmlView *view = new QmlView; view->setSource(QUrl::fromLocalFile(SRCDIR "/data/anchors.qml")); - view->execute(); qApp->processEvents(); //sibling horizontal @@ -171,28 +170,28 @@ void tst_qmlgraphicsanchors::basicAnchors() void tst_qmlgraphicsanchors::loops() { { - QmlView *view = new QmlView; - - view->setSource(QUrl::fromLocalFile(SRCDIR "/data/loop1.qml")); + QUrl source(QUrl::fromLocalFile(SRCDIR "/data/loop1.qml")); - QString expect = "QML Text (" + view->source().toString() + ":6:5" + ") Possible anchor loop detected on horizontal anchor."; + QString expect = "QML Text (" + source.toString() + ":6:5" + ") Possible anchor loop detected on horizontal anchor."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - view->execute(); + + QmlView *view = new QmlView; + view->setSource(source); qApp->processEvents(); delete view; } { - QmlView *view = new QmlView; + QUrl source(QUrl::fromLocalFile(SRCDIR "/data/loop2.qml")); - view->setSource(QUrl::fromLocalFile(SRCDIR "/data/loop2.qml")); - - QString expect = "QML Image (" + view->source().toString() + ":8:3" + ") Possible anchor loop detected on horizontal anchor."; + QString expect = "QML Image (" + source.toString() + ":8:3" + ") Possible anchor loop detected on horizontal anchor."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - view->execute(); + + QmlView *view = new QmlView; + view->setSource(source); qApp->processEvents(); delete view; @@ -370,14 +369,13 @@ void tst_qmlgraphicsanchors::nullItem_data() void tst_qmlgraphicsanchors::crash1() { - QmlView *view = new QmlView; + QUrl source(QUrl::fromLocalFile(SRCDIR "/data/crash1.qml")); - view->setSource(QUrl::fromLocalFile(SRCDIR "/data/crash1.qml")); - - QString expect = "QML Text (" + view->source().toString() + ":4:5" + ") Possible anchor loop detected on fill."; + QString expect = "QML Text (" + source.toString() + ":4:5" + ") Possible anchor loop detected on fill."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); // XXX ideally, should be one message - view->execute(); + + QmlView *view = new QmlView(source); qApp->processEvents(); delete view; @@ -385,11 +383,8 @@ void tst_qmlgraphicsanchors::crash1() void tst_qmlgraphicsanchors::fill() { - QmlView *view = new QmlView; - - view->setSource(QUrl::fromLocalFile(SRCDIR "/data/fill.qml")); + QmlView *view = new QmlView(QUrl::fromLocalFile(SRCDIR "/data/fill.qml")); - view->execute(); qApp->processEvents(); QmlGraphicsRectangle* rect = findItem(view->rootObject(), QLatin1String("filler")); QCOMPARE(rect->x(), 0.0 + 10.0); @@ -411,11 +406,8 @@ void tst_qmlgraphicsanchors::fill() void tst_qmlgraphicsanchors::centerIn() { - QmlView *view = new QmlView; - - view->setSource(QUrl::fromLocalFile(SRCDIR "/data/centerin.qml")); + QmlView *view = new QmlView(QUrl::fromLocalFile(SRCDIR "/data/centerin.qml")); - view->execute(); qApp->processEvents(); QmlGraphicsRectangle* rect = findItem(view->rootObject(), QLatin1String("centered")); QCOMPARE(rect->x(), 75.0 + 10); @@ -431,11 +423,8 @@ void tst_qmlgraphicsanchors::centerIn() void tst_qmlgraphicsanchors::margins() { - QmlView *view = new QmlView; - - view->setSource(QUrl::fromLocalFile(SRCDIR "/data/margins.qml")); + QmlView *view = new QmlView(QUrl::fromLocalFile(SRCDIR "/data/margins.qml")); - view->execute(); qApp->processEvents(); QmlGraphicsRectangle* rect = findItem(view->rootObject(), QLatin1String("filler")); QCOMPARE(rect->x(), 5.0); diff --git a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp index 2520d4a..7c8501c 100644 --- a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp +++ b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp @@ -68,7 +68,7 @@ private slots: void positionViewAtIndex(); private: - QmlView *createView(const QString &filename); + QmlView *createView(); template T *findItem(QGraphicsObject *parent, const QString &id, int index=-1); template @@ -142,7 +142,7 @@ tst_QmlGraphicsGridView::tst_QmlGraphicsGridView() void tst_QmlGraphicsGridView::items() { - QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + QmlView *canvas = createView(); TestModel model; model.addItem("Fred", "12345"); @@ -157,7 +157,7 @@ void tst_QmlGraphicsGridView::items() ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("testTopToBottom", QVariant(false)); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview.qml")); qApp->processEvents(); QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); @@ -190,7 +190,7 @@ void tst_QmlGraphicsGridView::items() void tst_QmlGraphicsGridView::changed() { - QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + QmlView *canvas = createView(); TestModel model; model.addItem("Fred", "12345"); @@ -205,7 +205,7 @@ void tst_QmlGraphicsGridView::changed() ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("testTopToBottom", QVariant(false)); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview.qml")); qApp->processEvents(); QmlGraphicsFlickable *gridview = findItem(canvas->rootObject(), "grid"); @@ -227,7 +227,7 @@ void tst_QmlGraphicsGridView::changed() void tst_QmlGraphicsGridView::inserted() { - QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + QmlView *canvas = createView(); TestModel model; model.addItem("Fred", "12345"); @@ -238,7 +238,7 @@ void tst_QmlGraphicsGridView::inserted() ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("testTopToBottom", QVariant(false)); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview.qml")); qApp->processEvents(); QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); @@ -309,7 +309,7 @@ void tst_QmlGraphicsGridView::inserted() void tst_QmlGraphicsGridView::removed() { - QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + QmlView *canvas = createView(); TestModel model; for (int i = 0; i < 40; i++) @@ -319,7 +319,7 @@ void tst_QmlGraphicsGridView::removed() ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("testTopToBottom", QVariant(false)); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview.qml")); qApp->processEvents(); QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); @@ -469,7 +469,7 @@ void tst_QmlGraphicsGridView::removed() void tst_QmlGraphicsGridView::moved() { - QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + QmlView *canvas = createView(); TestModel model; for (int i = 0; i < 30; i++) @@ -479,7 +479,7 @@ void tst_QmlGraphicsGridView::moved() ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("testTopToBottom", QVariant(false)); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview.qml")); qApp->processEvents(); QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); @@ -580,7 +580,6 @@ void tst_QmlGraphicsGridView::currentIndex() QString filename(SRCDIR "/data/gridview-initCurrent.qml"); canvas->setSource(QUrl::fromLocalFile(filename)); - canvas->execute(); qApp->processEvents(); QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); @@ -690,7 +689,7 @@ void tst_QmlGraphicsGridView::currentIndex() void tst_QmlGraphicsGridView::changeFlow() { - QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + QmlView *canvas = createView(); TestModel model; for (int i = 0; i < 30; i++) @@ -700,7 +699,7 @@ void tst_QmlGraphicsGridView::changeFlow() ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("testTopToBottom", QVariant(false)); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview.qml")); qApp->processEvents(); QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); @@ -795,7 +794,7 @@ void tst_QmlGraphicsGridView::properties() void tst_QmlGraphicsGridView::positionViewAtIndex() { - QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + QmlView *canvas = createView(); TestModel model; for (int i = 0; i < 40; i++) @@ -805,7 +804,7 @@ void tst_QmlGraphicsGridView::positionViewAtIndex() ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("testTopToBottom", QVariant(false)); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview.qml")); qApp->processEvents(); QmlGraphicsGridView *gridview = findItem(canvas->rootObject(), "grid"); @@ -883,13 +882,11 @@ void tst_QmlGraphicsGridView::positionViewAtIndex() delete canvas; } -QmlView *tst_QmlGraphicsGridView::createView(const QString &filename) +QmlView *tst_QmlGraphicsGridView::createView() { QmlView *canvas = new QmlView(0); canvas->setFixedSize(240,320); - canvas->setSource(QUrl::fromLocalFile(filename)); - return canvas; } diff --git a/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp b/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp index 820a6de..1bface4 100644 --- a/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp +++ b/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp @@ -112,14 +112,12 @@ void tst_QmlGraphicsItem::keys() QmlView *canvas = new QmlView(0); canvas->setFixedSize(240,320); - canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/keys.qml")); - KeysTestObject *testObject = new KeysTestObject; canvas->rootContext()->setContextProperty("keysTestObject", testObject); canvas->rootContext()->setContextProperty("enableKeyHanding", QVariant(true)); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/keys.qml")); canvas->show(); qApp->processEvents(); @@ -195,7 +193,6 @@ void tst_QmlGraphicsItem::keyNavigation() canvas->setFixedSize(240,320); canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/keynavigation.qml")); - canvas->execute(); canvas->show(); qApp->processEvents(); diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index 13ed41d..e535aaa 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -88,7 +88,7 @@ private: template void removed(bool animated); template void moved(); template void clear(); - QmlView *createView(const QString &filename); + QmlView *createView(); template T *findItem(QGraphicsObject *parent, const QString &id, int index=-1); template @@ -300,7 +300,7 @@ tst_QmlGraphicsListView::tst_QmlGraphicsListView() template void tst_QmlGraphicsListView::items() { - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + QmlView *canvas = createView(); T model; model.addItem("Fred", "12345"); @@ -313,7 +313,7 @@ void tst_QmlGraphicsListView::items() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -380,7 +380,7 @@ void tst_QmlGraphicsListView::items() template void tst_QmlGraphicsListView::changed() { - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + QmlView *canvas = createView(); T model; model.addItem("Fred", "12345"); @@ -393,7 +393,7 @@ void tst_QmlGraphicsListView::changed() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview.qml")); qApp->processEvents(); QmlGraphicsFlickable *listview = findItem(canvas->rootObject(), "list"); @@ -416,7 +416,7 @@ void tst_QmlGraphicsListView::changed() template void tst_QmlGraphicsListView::inserted() { - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + QmlView *canvas = createView(); T model; model.addItem("Fred", "12345"); @@ -429,7 +429,7 @@ void tst_QmlGraphicsListView::inserted() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -509,7 +509,7 @@ void tst_QmlGraphicsListView::inserted() template void tst_QmlGraphicsListView::removed(bool animated) { - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + QmlView *canvas = createView(); T model; for (int i = 0; i < 30; i++) @@ -522,7 +522,7 @@ void tst_QmlGraphicsListView::removed(bool animated) testObject->setAnimate(animated); ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -652,7 +652,7 @@ void tst_QmlGraphicsListView::removed(bool animated) template void tst_QmlGraphicsListView::clear() { - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + QmlView *canvas = createView(); T model; for (int i = 0; i < 30; i++) @@ -664,7 +664,7 @@ void tst_QmlGraphicsListView::clear() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -689,7 +689,7 @@ void tst_QmlGraphicsListView::clear() template void tst_QmlGraphicsListView::moved() { - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + QmlView *canvas = createView(); T model; for (int i = 0; i < 30; i++) @@ -701,7 +701,7 @@ void tst_QmlGraphicsListView::moved() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -785,7 +785,7 @@ void tst_QmlGraphicsListView::moved() void tst_QmlGraphicsListView::enforceRange() { - QmlView *canvas = createView(SRCDIR "/data/listview-enforcerange.qml"); + QmlView *canvas = createView(); TestModel model; for (int i = 0; i < 30; i++) @@ -794,7 +794,7 @@ void tst_QmlGraphicsListView::enforceRange() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview-enforcerange.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -830,7 +830,7 @@ void tst_QmlGraphicsListView::enforceRange() void tst_QmlGraphicsListView::spacing() { - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + QmlView *canvas = createView(); TestModel model; for (int i = 0; i < 30; i++) @@ -842,7 +842,7 @@ void tst_QmlGraphicsListView::spacing() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -888,7 +888,7 @@ void tst_QmlGraphicsListView::spacing() void tst_QmlGraphicsListView::sections() { - QmlView *canvas = createView(SRCDIR "/data/listview-sections.qml"); + QmlView *canvas = createView(); TestModel model; for (int i = 0; i < 30; i++) @@ -897,7 +897,7 @@ void tst_QmlGraphicsListView::sections() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview-sections.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -975,7 +975,6 @@ void tst_QmlGraphicsListView::currentIndex() QString filename(SRCDIR "/data/listview-initCurrent.qml"); canvas->setSource(QUrl::fromLocalFile(filename)); - canvas->execute(); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -1055,9 +1054,9 @@ void tst_QmlGraphicsListView::currentIndex() void tst_QmlGraphicsListView::itemList() { - QmlView *canvas = createView(SRCDIR "/data/itemlist.qml"); + QmlView *canvas = createView(); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/itemlist.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "view"); @@ -1096,7 +1095,7 @@ void tst_QmlGraphicsListView::itemList() void tst_QmlGraphicsListView::cacheBuffer() { - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + QmlView *canvas = createView(); TestModel model; for (int i = 0; i < 30; i++) @@ -1108,7 +1107,7 @@ void tst_QmlGraphicsListView::cacheBuffer() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -1148,7 +1147,7 @@ void tst_QmlGraphicsListView::cacheBuffer() void tst_QmlGraphicsListView::positionViewAtIndex() { - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + QmlView *canvas = createView(); TestModel model; for (int i = 0; i < 40; i++) @@ -1160,7 +1159,7 @@ void tst_QmlGraphicsListView::positionViewAtIndex() TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview.qml")); qApp->processEvents(); QmlGraphicsListView *listview = findItem(canvas->rootObject(), "list"); @@ -1295,13 +1294,11 @@ void tst_QmlGraphicsListView::qAbstractItemModel_clear() clear(); } -QmlView *tst_QmlGraphicsListView::createView(const QString &filename) +QmlView *tst_QmlGraphicsListView::createView() { QmlView *canvas = new QmlView(0); canvas->setFixedSize(240,320); - canvas->setSource(QUrl::fromLocalFile(filename)); - return canvas; } diff --git a/tests/auto/declarative/qmlgraphicsmousearea/tst_qmlgraphicsmousearea.cpp b/tests/auto/declarative/qmlgraphicsmousearea/tst_qmlgraphicsmousearea.cpp index 869a7bd..22a12a9 100644 --- a/tests/auto/declarative/qmlgraphicsmousearea/tst_qmlgraphicsmousearea.cpp +++ b/tests/auto/declarative/qmlgraphicsmousearea/tst_qmlgraphicsmousearea.cpp @@ -56,7 +56,6 @@ private: void tst_QmlGraphicsMouseArea::dragProperties() { QmlView *canvas = createView(SRCDIR "/data/dragproperties.qml"); - canvas->execute(); canvas->show(); canvas->setFocus(); QVERIFY(canvas->rootObject() != 0); diff --git a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp index a5c0b78..195c367 100644 --- a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp +++ b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp @@ -113,7 +113,6 @@ QmlView *tst_QmlGraphicsParticles::createView(const QString &filename) canvas->setFixedSize(240,320); canvas->setSource(QUrl::fromLocalFile(filename)); - canvas->execute(); return canvas; } diff --git a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp index b986a64..bb1c1af 100644 --- a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp +++ b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp @@ -69,7 +69,7 @@ private slots: void pathMoved(); private: - QmlView *createView(const QString &filename); + QmlView *createView(); template T *findItem(QGraphicsObject *parent, const QString &objectName, int index=-1); template @@ -191,7 +191,7 @@ void tst_QmlGraphicsPathView::initValues() void tst_QmlGraphicsPathView::items() { - QmlView *canvas = createView(SRCDIR "/data/pathview.qml"); + QmlView *canvas = createView(); TestModel model; model.addItem("Fred", "12345"); @@ -201,7 +201,7 @@ void tst_QmlGraphicsPathView::items() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/pathview.qml")); qApp->processEvents(); QmlGraphicsPathView *pathview = findItem(canvas->rootObject(), "view"); @@ -304,7 +304,7 @@ void tst_QmlGraphicsPathView::path() void tst_QmlGraphicsPathView::dataModel() { - QmlView *canvas = createView(SRCDIR "/data/datamodel.qml"); + QmlView *canvas = createView(); QmlContext *ctxt = canvas->rootContext(); TestObject *testObject = new TestObject; @@ -323,7 +323,7 @@ void tst_QmlGraphicsPathView::dataModel() ctxt->setContextProperty("testData", &model); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/datamodel.qml")); qApp->processEvents(); QmlGraphicsPathView *pathview = qobject_cast(canvas->rootObject()); @@ -384,7 +384,7 @@ void tst_QmlGraphicsPathView::dataModel() void tst_QmlGraphicsPathView::pathMoved() { - QmlView *canvas = createView(SRCDIR "/data/pathview.qml"); + QmlView *canvas = createView(); TestModel model; model.addItem("Ben", "12345"); @@ -395,7 +395,7 @@ void tst_QmlGraphicsPathView::pathMoved() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/pathview.qml")); qApp->processEvents(); QmlGraphicsPathView *pathview = findItem(canvas->rootObject(), "view"); @@ -425,13 +425,11 @@ void tst_QmlGraphicsPathView::pathMoved() delete canvas; } -QmlView *tst_QmlGraphicsPathView::createView(const QString &filename) +QmlView *tst_QmlGraphicsPathView::createView() { QmlView *canvas = new QmlView(0); canvas->setFixedSize(240,320); - canvas->setSource(QUrl::fromLocalFile(filename)); - return canvas; } diff --git a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp index b51266a..348f59b 100644 --- a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp +++ b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp @@ -75,8 +75,6 @@ void tst_QmlGraphicsPositioners::test_horizontal() { QmlView *canvas = createView(SRCDIR "/data/horizontal.qml"); - canvas->execute(); - QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); @@ -98,8 +96,6 @@ void tst_QmlGraphicsPositioners::test_horizontal_spacing() { QmlView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml"); - canvas->execute(); - QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); @@ -121,8 +117,6 @@ void tst_QmlGraphicsPositioners::test_horizontal_animated() { QmlView *canvas = createView(SRCDIR "/data/horizontal-animated.qml"); - canvas->execute(); - QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); @@ -163,8 +157,6 @@ void tst_QmlGraphicsPositioners::test_vertical() { QmlView *canvas = createView(SRCDIR "/data/vertical.qml"); - canvas->execute(); - QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); @@ -186,8 +178,6 @@ void tst_QmlGraphicsPositioners::test_vertical_spacing() { QmlView *canvas = createView(SRCDIR "/data/vertical-spacing.qml"); - canvas->execute(); - QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); @@ -209,8 +199,6 @@ void tst_QmlGraphicsPositioners::test_vertical_animated() { QmlView *canvas = createView(SRCDIR "/data/vertical-animated.qml"); - canvas->execute(); - //Note that they animate in QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); @@ -251,8 +239,6 @@ void tst_QmlGraphicsPositioners::test_grid() { QmlView *canvas = createView("data/grid.qml"); - canvas->execute(); - QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); @@ -280,8 +266,6 @@ void tst_QmlGraphicsPositioners::test_grid_spacing() { QmlView *canvas = createView("data/grid-spacing.qml"); - canvas->execute(); - QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); QmlGraphicsRectangle *two = canvas->rootObject()->findChild("two"); @@ -308,7 +292,6 @@ void tst_QmlGraphicsPositioners::test_grid_spacing() void tst_QmlGraphicsPositioners::test_grid_animated() { QmlView *canvas = createView(SRCDIR "/data/grid-animated.qml"); - canvas->execute(); //Note that all animate in QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); @@ -383,8 +366,6 @@ void tst_QmlGraphicsPositioners::test_repeater() { QmlView *canvas = createView("data/repeater.qml"); - canvas->execute(); - QmlGraphicsRectangle *one = canvas->rootObject()->findChild("one"); QVERIFY(one != 0); diff --git a/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp index c971840..9f3ff45 100644 --- a/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp +++ b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp @@ -68,7 +68,7 @@ private slots: void properties(); private: - QmlView *createView(const QString &filename); + QmlView *createView(); template T *findItem(QGraphicsObject *parent, const QString &id); }; @@ -164,14 +164,14 @@ tst_QmlGraphicsRepeater::tst_QmlGraphicsRepeater() void tst_QmlGraphicsRepeater::numberModel() { - QmlView *canvas = createView(SRCDIR "/data/intmodel.qml"); + QmlView *canvas = createView(); QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testData", 5); TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/intmodel.qml")); qApp->processEvents(); QmlGraphicsRepeater *repeater = findItem(canvas->rootObject(), "repeater"); @@ -186,7 +186,7 @@ void tst_QmlGraphicsRepeater::numberModel() void tst_QmlGraphicsRepeater::objectList() { - QmlView *canvas = createView(SRCDIR "/data/objlist.qml"); + QmlView *canvas = createView(); QObjectList data; for(int i=0; i<100; i++){ @@ -197,7 +197,7 @@ void tst_QmlGraphicsRepeater::objectList() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testData", QVariant::fromValue(data)); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/objlist.qml")); qApp->processEvents(); QmlGraphicsRepeater *repeater = findItem(canvas->rootObject(), "repeater"); @@ -213,7 +213,7 @@ elements to test this. */ void tst_QmlGraphicsRepeater::stringList() { - QmlView *canvas = createView(SRCDIR "/data/repeater.qml"); + QmlView *canvas = createView(); QStringList data; data << "One"; @@ -224,7 +224,7 @@ void tst_QmlGraphicsRepeater::stringList() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testData", data); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/repeater.qml")); qApp->processEvents(); QmlGraphicsRepeater *repeater = findItem(canvas->rootObject(), "repeater"); @@ -265,7 +265,7 @@ void tst_QmlGraphicsRepeater::stringList() void tst_QmlGraphicsRepeater::dataModel() { - QmlView *canvas = createView(SRCDIR "/data/repeater2.qml"); + QmlView *canvas = createView(); QmlContext *ctxt = canvas->rootContext(); TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); @@ -277,7 +277,7 @@ void tst_QmlGraphicsRepeater::dataModel() ctxt->setContextProperty("testData", &testModel); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/repeater2.qml")); qApp->processEvents(); QmlGraphicsRepeater *repeater = findItem(canvas->rootObject(), "repeater"); @@ -297,12 +297,12 @@ void tst_QmlGraphicsRepeater::dataModel() void tst_QmlGraphicsRepeater::itemModel() { - QmlView *canvas = createView(SRCDIR "/data/itemlist.qml"); + QmlView *canvas = createView(); QmlContext *ctxt = canvas->rootContext(); TestObject *testObject = new TestObject; ctxt->setContextProperty("testObject", testObject); - canvas->execute(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/itemlist.qml")); qApp->processEvents(); QmlGraphicsRepeater *repeater = findItem(canvas->rootObject(), "repeater"); @@ -354,13 +354,11 @@ void tst_QmlGraphicsRepeater::properties() QCOMPARE(delegateSpy.count(),1); } -QmlView *tst_QmlGraphicsRepeater::createView(const QString &filename) +QmlView *tst_QmlGraphicsRepeater::createView() { QmlView *canvas = new QmlView(0); canvas->setFixedSize(240,320); - canvas->setSource(QUrl::fromLocalFile(filename)); - return canvas; } diff --git a/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp b/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp index cc2f929..0d6ac77 100644 --- a/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp +++ b/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp @@ -604,7 +604,6 @@ void tst_qmlgraphicstextedit::selection() void tst_qmlgraphicstextedit::inputMethodHints() { QmlView *canvas = createView(SRCDIR "/data/inputmethodhints.qml"); - canvas->execute(); canvas->show(); canvas->setFocus(); @@ -619,7 +618,6 @@ void tst_qmlgraphicstextedit::inputMethodHints() void tst_qmlgraphicstextedit::cursorDelegate() { QmlView* view = createView(SRCDIR "/data/cursorTest.qml"); - view->execute(); view->show(); view->setFocus(); QmlGraphicsTextEdit *textEditObject = view->rootObject()->findChild("textEditObject"); @@ -651,7 +649,6 @@ void tst_qmlgraphicstextedit::delegateLoading() server.serveDirectory(SRCDIR "/data/http"); QmlView* view = new QmlView(0); view->setSource(QUrl("http://localhost:42332/cursorHttpTestPass.qml")); - view->execute(); view->show(); view->setFocus(); QTRY_VERIFY(view->rootObject());//Wait for loading to finish. @@ -665,12 +662,10 @@ void tst_qmlgraphicstextedit::delegateLoading() delegate = view->rootObject()->findChild("delegateSlow"); QVERIFY(delegate); view->setSource(QUrl("http://localhost:42332/cursorHttpTestFail1.qml")); - view->execute(); view->show(); view->setFocus(); QTRY_VERIFY(!view->rootObject()); // there is fail item inside this test view->setSource(QUrl("http://localhost:42332/cursorHttpTestFail2.qml")); - view->execute(); view->show(); view->setFocus(); QTRY_VERIFY(!view->rootObject()); // there is fail item inside this test @@ -688,7 +683,6 @@ the extent of the text, then they should ignore the keys. void tst_qmlgraphicstextedit::navigation() { QmlView *canvas = createView(SRCDIR "/data/navigation.qml"); - canvas->execute(); canvas->show(); canvas->setFocus(); @@ -711,7 +705,6 @@ void tst_qmlgraphicstextedit::navigation() void tst_qmlgraphicstextedit::readOnly() { QmlView *canvas = createView(SRCDIR "/data/readOnly.qml"); - canvas->execute(); canvas->show(); canvas->setFocus(); diff --git a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp index 8b45fc7..748cf5e 100644 --- a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp +++ b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp @@ -349,7 +349,6 @@ void tst_qmlgraphicstextinput::maxLength() { //QString componentStr = "import Qt 4.6\nTextInput { maximumLength: 10; }"; QmlView *canvas = createView(SRCDIR "/data/maxLength.qml"); - canvas->execute(); canvas->show(); canvas->setFocus(); QVERIFY(canvas->rootObject() != 0); @@ -378,7 +377,6 @@ void tst_qmlgraphicstextinput::masks() //Not a comprehensive test of the possible masks, that's done elsewhere (QLineEdit) //QString componentStr = "import Qt 4.6\nTextInput { inputMask: 'HHHHhhhh'; }"; QmlView *canvas = createView(SRCDIR "/data/masks.qml"); - canvas->execute(); canvas->show(); canvas->setFocus(); QVERIFY(canvas->rootObject() != 0); @@ -403,7 +401,6 @@ void tst_qmlgraphicstextinput::validators() // here to ensure that their exposure to QML is working. QmlView *canvas = createView(SRCDIR "/data/validators.qml"); - canvas->execute(); canvas->show(); canvas->setFocus(); @@ -493,7 +490,6 @@ void tst_qmlgraphicstextinput::validators() void tst_qmlgraphicstextinput::inputMethodHints() { QmlView *canvas = createView(SRCDIR "/data/inputmethodhints.qml"); - canvas->execute(); canvas->show(); canvas->setFocus(); @@ -513,7 +509,6 @@ the extent of the text, then they should ignore the keys. void tst_qmlgraphicstextinput::navigation() { QmlView *canvas = createView(SRCDIR "/data/navigation.qml"); - canvas->execute(); canvas->show(); canvas->setFocus(); @@ -546,7 +541,6 @@ void tst_qmlgraphicstextinput::navigation() void tst_qmlgraphicstextinput::cursorDelegate() { QmlView* view = createView(SRCDIR "/data/cursorTest.qml"); - view->execute(); view->show(); view->setFocus(); QmlGraphicsTextInput *textInputObject = view->rootObject()->findChild("textInputObject"); @@ -574,7 +568,6 @@ void tst_qmlgraphicstextinput::cursorDelegate() void tst_qmlgraphicstextinput::readOnly() { QmlView *canvas = createView(SRCDIR "/data/readOnly.qml"); - canvas->execute(); canvas->show(); canvas->setFocus(); diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 626e4c4..f881cd7 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -1063,11 +1063,11 @@ void QmlViewer::openQml(const QString& file_or_url) } } - canvas->setSource(url); - QTime t; t.start(); - canvas->execute(); + + canvas->setSource(url); + qWarning() << "Wall startup time:" << t.elapsed(); if (!skin) { -- cgit v0.12 From 23fb8f6e4f3f6fe4ae7611de84f09cc0095e240c Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Tue, 23 Feb 2010 15:41:25 +1000 Subject: Add missing NOTIFY signals to positioners, particles and webview Reviewed-by: Aaron Kennedy --- .../graphicsitems/qmlgraphicsparticles.cpp | 67 +++++++++++-- .../graphicsitems/qmlgraphicsparticles_p.h | 55 ++++++----- .../graphicsitems/qmlgraphicspositioners.cpp | 27 ++++- .../graphicsitems/qmlgraphicspositioners_p.h | 19 ++-- .../graphicsitems/qmlgraphicswebview.cpp | 20 +++- .../graphicsitems/qmlgraphicswebview_p.h | 15 ++- .../qmlgraphicsparticles/data/particlemotion.qml | 33 +++++++ .../tst_qmlgraphicsparticles.cpp | 88 +++++++++++++++++ .../data/propertychanges.qml | 39 ++++++++ .../tst_qmlgraphicspositioners.cpp | 59 ++++++++++- .../qmlgraphicswebview/data/propertychanges.qml | 33 +++++++ .../qmlgraphicswebview/tst_qmlgraphicswebview.cpp | 109 +++++++++++++++++++++ 12 files changed, 521 insertions(+), 43 deletions(-) create mode 100644 tests/auto/declarative/qmlgraphicsparticles/data/particlemotion.qml create mode 100644 tests/auto/declarative/qmlgraphicspositioners/data/propertychanges.qml create mode 100644 tests/auto/declarative/qmlgraphicswebview/data/propertychanges.qml diff --git a/src/declarative/graphicsitems/qmlgraphicsparticles.cpp b/src/declarative/graphicsitems/qmlgraphicsparticles.cpp index 08fce74..e23f6f0 100644 --- a/src/declarative/graphicsitems/qmlgraphicsparticles.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsparticles.cpp @@ -188,13 +188,13 @@ void QmlGraphicsParticleMotionLinear::advance(QmlGraphicsParticle &p, int interv */ /*! - \qmlproperty int ParticleMotionGravity::xattractor - \qmlproperty int ParticleMotionGravity::yattractor + \qmlproperty qreal ParticleMotionGravity::xattractor + \qmlproperty qreal ParticleMotionGravity::yattractor These properties hold the x and y coordinates of the point attracting the particles. */ /*! - \qmlproperty int ParticleMotionGravity::acceleration + \qmlproperty qreal ParticleMotionGravity::acceleration This property holds the acceleration to apply to the particles. */ @@ -213,6 +213,31 @@ void QmlGraphicsParticleMotionLinear::advance(QmlGraphicsParticle &p, int interv \brief the acceleration to apply to the particles. */ +void QmlGraphicsParticleMotionGravity::setXAttractor(qreal x) +{ + if (qFuzzyCompare(x, _xAttr)) + return; + _xAttr = x; + emit xattractorChanged(); +} + +void QmlGraphicsParticleMotionGravity::setYAttractor(qreal y) +{ + if (qFuzzyCompare(y, _yAttr)) + return; + _yAttr = y; + emit yattractorChanged(); +} + +void QmlGraphicsParticleMotionGravity::setAcceleration(qreal accel) +{ + qreal scaledAccel = accel/1000000.0; + if (qFuzzyCompare(scaledAccel, _accel)) + return; + _accel = scaledAccel; + emit accelerationChanged(); +} + void QmlGraphicsParticleMotionGravity::advance(QmlGraphicsParticle &p, int interval) { qreal xdiff = p.x - _xAttr; @@ -276,14 +301,14 @@ Rectangle { */ /*! - \qmlproperty int QmlGraphicsParticleMotionWander::xvariance - \qmlproperty int QmlGraphicsParticleMotionWander::yvariance + \qmlproperty qreal QmlGraphicsParticleMotionWander::xvariance + \qmlproperty qreal QmlGraphicsParticleMotionWander::yvariance These properties set the amount to wander in the x and y directions. */ /*! - \qmlproperty int QmlGraphicsParticleMotionWander::pace + \qmlproperty qreal QmlGraphicsParticleMotionWander::pace This property holds how quickly the paricles will move from side to side. */ @@ -335,6 +360,33 @@ void QmlGraphicsParticleMotionWander::destroy(QmlGraphicsParticle &p) delete (Data*)p.data; } +void QmlGraphicsParticleMotionWander::setXVariance(qreal var) +{ + qreal scaledVar = var / 1000.0; + if (qFuzzyCompare(scaledVar, _xvariance)) + return; + _xvariance = scaledVar; + emit xvarianceChanged(); +} + +void QmlGraphicsParticleMotionWander::setYVariance(qreal var) +{ + qreal scaledVar = var / 1000.0; + if (qFuzzyCompare(scaledVar, _yvariance)) + return; + _yvariance = scaledVar; + emit yvarianceChanged(); +} + +void QmlGraphicsParticleMotionWander::setPace(qreal pace) +{ + qreal scaledPace = pace / 1000.0; + if (qFuzzyCompare(scaledPace, _pace)) + return; + _pace = scaledPace; + emit paceChanged(); +} + //--------------------------------------------------------------------------- class QmlGraphicsParticlesPainter : public QmlGraphicsItem { @@ -1125,7 +1177,10 @@ QmlGraphicsParticleMotion *QmlGraphicsParticles::motion() const void QmlGraphicsParticles::setMotion(QmlGraphicsParticleMotion *motion) { Q_D(QmlGraphicsParticles); + if (motion == d->motion) + return; d->motion = motion; + emit motionChanged(); } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicsparticles_p.h b/src/declarative/graphicsitems/qmlgraphicsparticles_p.h index 7f0f9cd..8e66335 100644 --- a/src/declarative/graphicsitems/qmlgraphicsparticles_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsparticles_p.h @@ -77,27 +77,32 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionGravity : public QmlGraphics { Q_OBJECT - Q_PROPERTY(int xattractor READ xAttractor WRITE setXAttractor) - Q_PROPERTY(int yattractor READ yAttractor WRITE setYAttractor) - Q_PROPERTY(int acceleration READ acceleration WRITE setAcceleration) + Q_PROPERTY(qreal xattractor READ xAttractor WRITE setXAttractor NOTIFY xattractorChanged) + Q_PROPERTY(qreal yattractor READ yAttractor WRITE setYAttractor NOTIFY yattractorChanged) + Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged) public: QmlGraphicsParticleMotionGravity(QObject *parent=0) - : QmlGraphicsParticleMotion(parent), _xAttr(0), _yAttr(0), _accel(0.00005) {} + : QmlGraphicsParticleMotion(parent), _xAttr(0.0), _yAttr(0.0), _accel(0.00005) {} - int xAttractor() const { return _xAttr; } - void setXAttractor(int x) { _xAttr = x; } + qreal xAttractor() const { return _xAttr; } + void setXAttractor(qreal x); - int yAttractor() const { return _yAttr; } - void setYAttractor(int y) { _yAttr = y; } + qreal yAttractor() const { return _yAttr; } + void setYAttractor(qreal y); - int acceleration() const { return int(_accel * 1000000); } - void setAcceleration(int accel) { _accel = qreal(accel)/1000000.0; } + qreal acceleration() const { return _accel * 1000000; } + void setAcceleration(qreal accel); virtual void advance(QmlGraphicsParticle &, int interval); +Q_SIGNALS: + void xattractorChanged(); + void yattractorChanged(); + void accelerationChanged(); + private: - int _xAttr; - int _yAttr; + qreal _xAttr; + qreal _yAttr; qreal _accel; }; @@ -121,18 +126,23 @@ public: qreal y_var; }; - Q_PROPERTY(int xvariance READ xVariance WRITE setXVariance) - int xVariance() const { return int(_xvariance * 1000); } - void setXVariance(int var) { _xvariance = var / 1000.0; } + Q_PROPERTY(qreal xvariance READ xVariance WRITE setXVariance NOTIFY xvarianceChanged) + qreal xVariance() const { return _xvariance * 1000.0; } + void setXVariance(qreal var); - Q_PROPERTY(int yvariance READ yVariance WRITE setYVariance) - int yVariance() const { return int(_yvariance * 1000); } - void setYVariance(int var) { _yvariance = var / 1000.0; } + Q_PROPERTY(qreal yvariance READ yVariance WRITE setYVariance NOTIFY yvarianceChanged) + qreal yVariance() const { return _yvariance * 1000.0; } + void setYVariance(qreal var); - Q_PROPERTY(int pace READ pace WRITE setPace) - int pace() const { return int(_pace * 1000); } - void setPace(int pace) { _pace = pace / 1000.0; } + Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged) + qreal pace() const { return _pace * 1000.0; } + void setPace(qreal pace); +Q_SIGNALS: + void xvarianceChanged(); + void yvarianceChanged(); + void paceChanged(); + private: QmlGraphicsParticles *particles; qreal _xvariance; @@ -157,7 +167,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsParticles : public QmlGraphicsItem Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation NOTIFY angleDeviationChanged) Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged) Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation NOTIFY velocityDeviationChanged) - Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion) + Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion NOTIFY motionChanged) Q_CLASSINFO("DefaultProperty", "motion") public: @@ -225,6 +235,7 @@ Q_SIGNALS: void velocityChanged(); void velocityDeviationChanged(); void emittingChanged(); + void motionChanged(); private Q_SLOTS: void imageLoaded(); diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index 8adf239..805c912 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -138,7 +138,10 @@ QmlTransition *QmlGraphicsBasePositioner::move() const void QmlGraphicsBasePositioner::setMove(QmlTransition *mt) { Q_D(QmlGraphicsBasePositioner); + if (mt == d->moveTransition) + return; d->moveTransition = mt; + emit moveChanged(); } QmlTransition *QmlGraphicsBasePositioner::add() const @@ -150,7 +153,11 @@ QmlTransition *QmlGraphicsBasePositioner::add() const void QmlGraphicsBasePositioner::setAdd(QmlTransition *add) { Q_D(QmlGraphicsBasePositioner); + if (add == d->addTransition) + return; + d->addTransition = add; + emit addChanged(); } void QmlGraphicsBasePositioner::componentComplete() @@ -362,7 +369,7 @@ Column { move: Transition { NumberAnimation { properties: "y" - ease: "easeOutBounce" + easing: "easeOutBounce" } } } @@ -647,6 +654,24 @@ QmlGraphicsGrid::QmlGraphicsGrid(QmlGraphicsItem *parent) : many rows some rows will be of zero width. */ +void QmlGraphicsGrid::setColumns(const int columns) +{ + if (columns == _columns) + return; + _columns = columns; + prePositioning(); + emit columnsChanged(); +} + +void QmlGraphicsGrid::setRows(const int rows) +{ + if (rows == _rows) + return; + _rows = rows; + prePositioning(); + emit rowsChanged(); +} + void QmlGraphicsGrid::doPositioning() { int c=_columns,r=_rows;//Actual number of rows/columns diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h index 1fb687a..2f905e5 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h @@ -62,8 +62,8 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsBasePositioner : public QmlGraphicsItem Q_OBJECT Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) - Q_PROPERTY(QmlTransition *move READ move WRITE setMove) - Q_PROPERTY(QmlTransition *add READ add WRITE setAdd) + Q_PROPERTY(QmlTransition *move READ move WRITE setMove NOTIFY moveChanged) + Q_PROPERTY(QmlTransition *add READ add WRITE setAdd NOTIFY addChanged) public: enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 }; QmlGraphicsBasePositioner(PositionerType, QmlGraphicsItem *parent); @@ -86,6 +86,8 @@ protected: Q_SIGNALS: void spacingChanged(); + void moveChanged(); + void addChanged(); protected Q_SLOTS: virtual void doPositioning()=0; @@ -134,16 +136,21 @@ private: class Q_DECLARATIVE_EXPORT QmlGraphicsGrid : public QmlGraphicsBasePositioner { Q_OBJECT - Q_PROPERTY(int rows READ rows WRITE setRows) - Q_PROPERTY(int columns READ columns WRITE setcolumns) + Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowChanged) + Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged) public: QmlGraphicsGrid(QmlGraphicsItem *parent=0); int rows() const {return _rows;} - void setRows(const int rows){_rows = rows;} + void setRows(const int rows); int columns() const {return _columns;} - void setcolumns(const int columns){_columns = columns;} + void setColumns(const int columns); + +Q_SIGNALS: + void rowsChanged(); + void columnsChanged(); + protected Q_SLOTS: virtual void doPositioning(); diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index 0c21f75..f9bbb22 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -483,6 +483,8 @@ void QmlGraphicsWebView::setRenderingEnabled(bool enabled) if (d->rendering == enabled) return; d->rendering = enabled; + emit renderingEnabledChanged(); + setCacheFrozen(!enabled); if (enabled) clearCache(); @@ -596,7 +598,10 @@ int QmlGraphicsWebView::pressGrabTime() const void QmlGraphicsWebView::setPressGrabTime(int ms) { Q_D(QmlGraphicsWebView); + if (d->pressTime == ms) + return; d->pressTime = ms; + emit pressGrabTimeChanged(); } void QmlGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) @@ -1024,6 +1029,7 @@ void QmlGraphicsWebView::setHtml(const QString &html, const QUrl &baseUrl) d->pending_url = baseUrl; d->pending_string = html; } + emit htmlChanged(); } void QmlGraphicsWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) @@ -1116,8 +1122,10 @@ QmlComponent *QmlGraphicsWebView::newWindowComponent() const void QmlGraphicsWebView::setNewWindowComponent(QmlComponent *newWindow) { Q_D(QmlGraphicsWebView); - delete d->newWindowComponent; + if (newWindow == d->newWindowComponent) + return; d->newWindowComponent = newWindow; + emit newWindowComponentChanged(); } @@ -1137,8 +1145,16 @@ QmlGraphicsItem *QmlGraphicsWebView::newWindowParent() const void QmlGraphicsWebView::setNewWindowParent(QmlGraphicsItem *parent) { Q_D(QmlGraphicsWebView); - delete d->newWindowParent; + if (parent == d->newWindowParent) + return; + if (d->newWindowParent && parent) { + QList children = d->newWindowParent->childItems(); + for (int i = 0; i < children.count(); ++i) { + children.at(i)->setParentItem(parent); + } + } d->newWindowParent = parent; + emit newWindowParentChanged(); } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicswebview_p.h b/src/declarative/graphicsitems/qmlgraphicswebview_p.h index 30ba0e4..ca63be9 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicswebview_p.h @@ -97,9 +97,9 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) - Q_PROPERTY(QString html READ html WRITE setHtml) + Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged) - Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime) + Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime NOTIFY pressGrabTimeChanged) Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged) @@ -116,10 +116,10 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem Q_PROPERTY(QmlListProperty javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) - Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent) - Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent) + Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent NOTIFY newWindowComponentChanged) + Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent NOTIFY newWindowParentChanged) - Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled) + Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged) public: QmlGraphicsWebView(QmlGraphicsItem *parent=0); @@ -192,7 +192,12 @@ Q_SIGNALS: void titleChanged(const QString&); void iconChanged(); void statusTextChanged(); + void htmlChanged(); + void pressGrabTimeChanged(); void zoomFactorChanged(); + void newWindowComponentChanged(); + void newWindowParentChanged(); + void renderingEnabledChanged(); void loadStarted(); void loadFinished(); diff --git a/tests/auto/declarative/qmlgraphicsparticles/data/particlemotion.qml b/tests/auto/declarative/qmlgraphicsparticles/data/particlemotion.qml new file mode 100644 index 0000000..ace61fe --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/data/particlemotion.qml @@ -0,0 +1,33 @@ +import Qt 4.6 +Rectangle { + width: 240 + height: 320 + color: "black" + Particles { + objectName: "particles" + anchors.fill: parent + width: 1 + height: 1 + source: "particle.png" + lifeSpan: 5000 + count: 200 + angle: 270 + angleDeviation: 45 + velocity: 50 + velocityDeviation: 30 + ParticleMotionGravity { + objectName: "motionGravity" + yattractor: 1000 + xattractor: 0 + acceleration: 25 + } + } + resources: [ + ParticleMotionWander { + objectName: "motionWander" + xvariance: 30 + yvariance: 30 + pace: 100 + } + ] +} \ No newline at end of file diff --git a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp index 195c367..9436772 100644 --- a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp +++ b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include +#include #include #include @@ -50,6 +51,8 @@ public: private slots: void properties(); + void motionGravity(); + void motionWander(); void runs(); private: QmlView *createView(const QString &filename); @@ -98,6 +101,91 @@ void tst_QmlGraphicsParticles::properties() QCOMPARE(particles->emissionRate(), 12); } +void tst_QmlGraphicsParticles::motionGravity() +{ + QmlView *canvas = createView(SRCDIR "/data/particlemotion.qml"); + QVERIFY(canvas->rootObject()); + QmlGraphicsParticles* particles = canvas->rootObject()->findChild("particles"); + QVERIFY(particles); + + QmlGraphicsParticleMotionGravity* motionGravity = canvas->rootObject()->findChild("motionGravity"); + QCOMPARE(particles->motion(), motionGravity); + + QSignalSpy xattractorSpy(motionGravity, SIGNAL(xattractorChanged())); + QSignalSpy yattractorSpy(motionGravity, SIGNAL(yattractorChanged())); + QSignalSpy accelerationSpy(motionGravity, SIGNAL(accelerationChanged())); + + QCOMPARE(motionGravity->xAttractor(), 0.0); + QCOMPARE(motionGravity->yAttractor(), 1000.0); + QCOMPARE(motionGravity->acceleration(), 25.0); + + motionGravity->setXAttractor(20.0); + motionGravity->setYAttractor(10.0); + motionGravity->setAcceleration(10.0); + + QCOMPARE(motionGravity->xAttractor(), 20.0); + QCOMPARE(motionGravity->yAttractor(), 10.0); + QCOMPARE(motionGravity->acceleration(), 10.0); + + QCOMPARE(xattractorSpy.count(), 1); + QCOMPARE(yattractorSpy.count(), 1); + QCOMPARE(accelerationSpy.count(), 1); + + motionGravity->setXAttractor(20.0); + motionGravity->setYAttractor(10.0); + motionGravity->setAcceleration(10.0); + + QCOMPARE(xattractorSpy.count(), 1); + QCOMPARE(yattractorSpy.count(), 1); + QCOMPARE(accelerationSpy.count(), 1); +} + +void tst_QmlGraphicsParticles::motionWander() +{ + QmlView *canvas = createView(SRCDIR "/data/particlemotion.qml"); + QVERIFY(canvas->rootObject()); + QmlGraphicsParticles* particles = canvas->rootObject()->findChild("particles"); + QVERIFY(particles); + + QSignalSpy motionSpy(particles, SIGNAL(motionChanged())); + QmlGraphicsParticleMotionWander* motionWander = canvas->rootObject()->findChild("motionWander"); + + particles->setMotion(motionWander); + QCOMPARE(particles->motion(),motionWander); + QCOMPARE(motionSpy.count(), 1); + + particles->setMotion(motionWander); + QCOMPARE(motionSpy.count(), 1); + + QSignalSpy xvarianceSpy(motionWander, SIGNAL(xvarianceChanged())); + QSignalSpy yvarianceSpy(motionWander, SIGNAL(yvarianceChanged())); + QSignalSpy paceSpy(motionWander, SIGNAL(paceChanged())); + + QCOMPARE(motionWander->xVariance(), 30.0); + QCOMPARE(motionWander->yVariance(), 30.0); + QCOMPARE(motionWander->pace(), 100.0); + + motionWander->setXVariance(20.0); + motionWander->setYVariance(10.0); + motionWander->setPace(10.0); + + QCOMPARE(motionWander->xVariance(), 20.0); + QCOMPARE(motionWander->yVariance(), 10.0); + QCOMPARE(motionWander->pace(), 10.0); + + QCOMPARE(xvarianceSpy.count(), 1); + QCOMPARE(yvarianceSpy.count(), 1); + QCOMPARE(paceSpy.count(), 1); + + motionWander->setXVariance(20.0); + motionWander->setYVariance(10.0); + motionWander->setPace(10.0); + + QCOMPARE(xvarianceSpy.count(), 1); + QCOMPARE(yvarianceSpy.count(), 1); + QCOMPARE(paceSpy.count(), 1); +} + void tst_QmlGraphicsParticles::runs() { QmlView *canvas = createView(SRCDIR "/data/particles.qml"); diff --git a/tests/auto/declarative/qmlgraphicspositioners/data/propertychanges.qml b/tests/auto/declarative/qmlgraphicspositioners/data/propertychanges.qml new file mode 100644 index 0000000..c3dc7bf --- /dev/null +++ b/tests/auto/declarative/qmlgraphicspositioners/data/propertychanges.qml @@ -0,0 +1,39 @@ +import Qt 4.6 + +Grid { + id: myGrid + + width: 270 + height: 270 + x: 3 + y: 3 + columns: 4 + spacing: 3 + + add: columnTransition + move: columnTransition + + Repeater { + model: 20 + Rectangle { color: "black"; width: 50; height: 50 } + } + + data: [ + Transition { + id: rowTransition + objectName: "rowTransition" + NumberAnimation { + properties: "x,y"; + easing: "easeOutInCubic" + } + }, + Transition { + id: columnTransition + objectName: "columnTransition" + NumberAnimation { + properties: "x,y"; + easing: "easeOutInCubic" + } + } + ] +} diff --git a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp index 348f59b..5089dc5 100644 --- a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp +++ b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp @@ -42,6 +42,8 @@ #include #include #include +#include +#include #include #include "../../../shared/util.h" @@ -61,7 +63,7 @@ private slots: void test_grid(); void test_grid_spacing(); void test_grid_animated(); - + void test_propertychanges(); void test_repeater(); private: QmlView *createView(const QString &filename); @@ -361,6 +363,61 @@ void tst_QmlGraphicsPositioners::test_grid_animated() QTRY_COMPARE(five->y(), 50.0); } +void tst_QmlGraphicsPositioners::test_propertychanges() +{ + QmlView *canvas = createView("data/propertychanges.qml"); + + QmlGraphicsGrid *grid = qobject_cast(canvas->rootObject()); + QmlTransition *rowTransition = canvas->rootObject()->findChild("rowTransition"); + QmlTransition *columnTransition = canvas->rootObject()->findChild("columnTransition"); + + QSignalSpy addSpy(grid, SIGNAL(addChanged())); + QSignalSpy moveSpy(grid, SIGNAL(moveChanged())); + QSignalSpy columnsSpy(grid, SIGNAL(columnsChanged())); + QSignalSpy rowsSpy(grid, SIGNAL(rowsChanged())); + + QVERIFY(grid); + QVERIFY(rowTransition); + QVERIFY(columnTransition); + QCOMPARE(grid->add(), columnTransition); + QCOMPARE(grid->move(), columnTransition); + QCOMPARE(grid->columns(), 4); + QCOMPARE(grid->rows(), -1); + + grid->setAdd(rowTransition); + grid->setMove(rowTransition); + QCOMPARE(grid->add(), rowTransition); + QCOMPARE(grid->move(), rowTransition); + QCOMPARE(addSpy.count(),1); + QCOMPARE(moveSpy.count(),1); + + grid->setAdd(rowTransition); + grid->setMove(rowTransition); + QCOMPARE(addSpy.count(),1); + QCOMPARE(moveSpy.count(),1); + + grid->setAdd(0); + grid->setMove(0); + QCOMPARE(addSpy.count(),2); + QCOMPARE(moveSpy.count(),2); + + grid->setColumns(-1); + grid->setRows(3); + QCOMPARE(grid->columns(), -1); + QCOMPARE(grid->rows(), 3); + QCOMPARE(columnsSpy.count(),1); + QCOMPARE(rowsSpy.count(),1); + + grid->setColumns(-1); + grid->setRows(3); + QCOMPARE(columnsSpy.count(),1); + QCOMPARE(rowsSpy.count(),1); + + grid->setColumns(2); + grid->setRows(2); + QCOMPARE(columnsSpy.count(),2); + QCOMPARE(rowsSpy.count(),2); +} void tst_QmlGraphicsPositioners::test_repeater() { diff --git a/tests/auto/declarative/qmlgraphicswebview/data/propertychanges.qml b/tests/auto/declarative/qmlgraphicswebview/data/propertychanges.qml new file mode 100644 index 0000000..3dd4e51 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicswebview/data/propertychanges.qml @@ -0,0 +1,33 @@ +import Qt 4.6 + +Item { + width: 240 + height: 160 + Grid { + anchors.fill: parent + objectName: "newWindowParent" + id: newWindowParent + } + + Row { + anchors.fill: parent + id: oldWindowParent + objectName: "oldWindowParent" + } + + Loader { + sourceComponent: webViewComponent + } + Component { + id: webViewComponent + WebView { + id: webView + objectName: "webView" + newWindowComponent: webViewComponent + newWindowParent: oldWindowParent + url: "basic.html" + renderingEnabled: true + pressGrabTime: 200 + } + } +} \ No newline at end of file diff --git a/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp index f3c39f8..5815e22 100644 --- a/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp +++ b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include +#include #include "../../../shared/util.h" #include #include @@ -69,6 +70,10 @@ private slots: void javaScript(); void cleanupTestCase(); void pixelCache(); + void newWindowParent(); + void newWindowComponent(); + void renderingEnabled(); + void pressGrabTime(); private: void checkNoErrors(const QmlComponent& component); @@ -335,6 +340,10 @@ void tst_qmlgraphicswebview::setHtml() QmlGraphicsWebView *wv = qobject_cast(component.create()); QVERIFY(wv != 0); QCOMPARE(wv->html(),QString("

This is a string set on the WebView

")); + + QSignalSpy spy(wv, SIGNAL(htmlChanged())); + wv->setHtml(QString("Basic

text

")); + QCOMPARE(spy.count(),1); } void tst_qmlgraphicswebview::elementAreaAt() @@ -391,6 +400,106 @@ void tst_qmlgraphicswebview::pixelCache() QCOMPARE(wv->pixelsPainted(), expected*3); // repainted } +void tst_qmlgraphicswebview::newWindowParent() +{ + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + checkNoErrors(component); + QmlGraphicsItem *rootItem = qobject_cast(component.create()); + QmlGraphicsWebView *wv = rootItem->findChild("webView"); + QVERIFY(rootItem != 0); + QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + + QmlGraphicsItem* oldWindowParent = rootItem->findChild("oldWindowParent"); + QCOMPARE(wv->newWindowParent(), oldWindowParent); + QSignalSpy newWindowParentSpy(wv, SIGNAL(newWindowParentChanged())); + + QmlGraphicsItem* newWindowParent = rootItem->findChild("newWindowParent"); + wv->setNewWindowParent(newWindowParent); + QVERIFY(oldWindowParent); + QVERIFY(oldWindowParent->childItems().count() == 0); + QCOMPARE(wv->newWindowParent(), newWindowParent); + QCOMPARE(newWindowParentSpy.count(),1); + + wv->setNewWindowParent(newWindowParent); + QCOMPARE(newWindowParentSpy.count(),1); + + wv->setNewWindowParent(0); + QCOMPARE(newWindowParentSpy.count(),2); +} + +void tst_qmlgraphicswebview::newWindowComponent() +{ + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + checkNoErrors(component); + QmlGraphicsItem *rootItem = qobject_cast(component.create()); + QmlGraphicsWebView *wv = rootItem->findChild("webView"); + QVERIFY(rootItem != 0); + QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + + QmlComponent substituteComponent(&engine); + substituteComponent.setData("import Qt 4.6; WebView { objectName: 'newWebView'; url: 'basic.html'; }", QUrl::fromLocalFile("")); + QSignalSpy newWindowComponentSpy(wv, SIGNAL(newWindowComponentChanged())); + + wv->setNewWindowComponent(&substituteComponent); + QCOMPARE(wv->newWindowComponent(), &substituteComponent); + QCOMPARE(newWindowComponentSpy.count(),1); + + wv->setNewWindowComponent(&substituteComponent); + QCOMPARE(newWindowComponentSpy.count(),1); + + wv->setNewWindowComponent(0); + QCOMPARE(newWindowComponentSpy.count(),2); +} + +void tst_qmlgraphicswebview::renderingEnabled() +{ + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + checkNoErrors(component); + QmlGraphicsItem *rootItem = qobject_cast(component.create()); + QmlGraphicsWebView *wv = rootItem->findChild("webView"); + QVERIFY(rootItem != 0); + QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + + QVERIFY(wv->renderingEnabled()); + QSignalSpy renderingEnabledSpy(wv, SIGNAL(renderingEnabledChanged())); + + wv->setRenderingEnabled(false); + QVERIFY(!wv->renderingEnabled()); + QCOMPARE(renderingEnabledSpy.count(),1); + + wv->setRenderingEnabled(false); + QCOMPARE(renderingEnabledSpy.count(),1); + + wv->setRenderingEnabled(true); + QCOMPARE(renderingEnabledSpy.count(),2); +} + +void tst_qmlgraphicswebview::pressGrabTime() +{ + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + checkNoErrors(component); + QmlGraphicsItem *rootItem = qobject_cast(component.create()); + QmlGraphicsWebView *wv = rootItem->findChild("webView"); + QVERIFY(rootItem != 0); + QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + QCOMPARE(wv->pressGrabTime(), 200); + QSignalSpy pressGrabTimeSpy(wv, SIGNAL(pressGrabTimeChanged())); + + wv->setPressGrabTime(100); + QCOMPARE(wv->pressGrabTime(), 100); + QCOMPARE(pressGrabTimeSpy.count(),1); + + wv->setPressGrabTime(100); + QCOMPARE(pressGrabTimeSpy.count(),1); + + wv->setPressGrabTime(0); + QCOMPARE(pressGrabTimeSpy.count(),2); +} + QTEST_MAIN(tst_qmlgraphicswebview) #include "tst_qmlgraphicswebview.moc" -- cgit v0.12 From ab2497c20116399e963748adf0ed2bf691d42cbf Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Mon, 22 Feb 2010 18:51:40 +1000 Subject: Add QEasingCurve as builtin metatype This is needed for qml, in order to be able to use easing as a valuetype. Task-number: QTBUG-8235 Reviewed-by: thierry Reviewed-by: janarve --- src/corelib/kernel/qmetatype.cpp | 26 ++++++ src/corelib/kernel/qmetatype.h | 8 +- src/corelib/kernel/qvariant.cpp | 55 ++++++++++++- src/corelib/kernel/qvariant.h | 12 ++- src/corelib/tools/qeasingcurve.cpp | 69 +++++++++++++++- src/corelib/tools/qeasingcurve.h | 11 +++ tests/auto/qeasingcurve/tst_qeasingcurve.cpp | 115 +++++++++++++++++++++++++++ 7 files changed, 285 insertions(+), 11 deletions(-) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 870baab..9e187d4 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -48,6 +48,7 @@ #include "qstringlist.h" #include "qvector.h" #include "qlocale.h" +#include "qeasingcurve.h" #ifdef QT_BOOTSTRAPPED # ifndef QT_NO_GEOM_VARIANT @@ -176,6 +177,7 @@ QT_BEGIN_NAMESPACE \value QVector3D QVector3D \value QVector4D QVector4D \value QQuaternion QQuaternion + \value QEasingCurve QEasingCurve \value User Base value for user types @@ -256,6 +258,7 @@ static const struct { const char * typeName; int type; } types[] = { {"QPointF", QMetaType::QPointF}, {"QRegExp", QMetaType::QRegExp}, {"QVariantHash", QMetaType::QVariantHash}, + {"QEasingCurve", QMetaType::QEasingCurve}, /* All GUI types */ {"QColorGroup", 63}, @@ -666,6 +669,11 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data) stream << *static_cast(data); break; #endif +#ifndef QT_BOOTSTRAPPED + case QMetaType::QEasingCurve: + stream << *static_cast(data); + break; +#endif #ifdef QT3_SUPPORT case QMetaType::QColorGroup: #endif @@ -863,6 +871,11 @@ bool QMetaType::load(QDataStream &stream, int type, void *data) stream >> *static_cast< NS(QRegExp)*>(data); break; #endif +#ifndef QT_BOOTSTRAPPED + case QMetaType::QEasingCurve: + stream >> *static_cast< NS(QEasingCurve)*>(data); + break; +#endif #ifdef QT3_SUPPORT case QMetaType::QColorGroup: #endif @@ -1007,6 +1020,10 @@ void *QMetaType::construct(int type, const void *copy) case QMetaType::QRegExp: return new NS(QRegExp)(*static_cast(copy)); #endif +#ifndef QT_BOOTSTRAPPED + case QMetaType::QEasingCurve: + return new NS(QEasingCurve)(*static_cast(copy)); +#endif case QMetaType::Void: return 0; default: @@ -1098,6 +1115,10 @@ void *QMetaType::construct(int type, const void *copy) case QMetaType::QRegExp: return new NS(QRegExp); #endif +#ifndef QT_BOOTSTRAPPED + case QMetaType::QEasingCurve: + return new NS(QEasingCurve); +#endif case QMetaType::Void: return 0; default: @@ -1253,6 +1274,11 @@ void QMetaType::destroy(int type, void *data) delete static_cast< NS(QRegExp)* >(data); break; #endif +#ifndef QT_BOOTSTRAPPED + case QMetaType::QEasingCurve: + delete static_cast< NS(QEasingCurve)* >(data); + break; +#endif case QMetaType::Void: break; default: { diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index c23caed..33126e8 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -69,7 +69,7 @@ public: QBitArray = 13, QDate = 14, QTime = 15, QDateTime = 16, QUrl = 17, QLocale = 18, QRect = 19, QRectF = 20, QSize = 21, QSizeF = 22, QLine = 23, QLineF = 24, QPoint = 25, QPointF = 26, QRegExp = 27, - QVariantHash = 28, LastCoreType = 28 /* QVariantHash */, + QVariantHash = 28, QEasingCurve = 29, LastCoreType = QEasingCurve, FirstGuiType = 63 /* QColorGroup */, #ifdef QT3_SUPPORT @@ -81,12 +81,12 @@ public: QTextLength = 78, QTextFormat = 79, QMatrix = 80, QTransform = 81, QMatrix4x4 = 82, QVector2D = 83, QVector3D = 84, QVector4D = 85, QQuaternion = 86, - LastGuiType = 86 /* QQuaternion */, + LastGuiType = QQuaternion, FirstCoreExtType = 128 /* VoidStar */, VoidStar = 128, Long = 129, Short = 130, Char = 131, ULong = 132, UShort = 133, UChar = 134, Float = 135, QObjectStar = 136, QWidgetStar = 137, - LastCoreExtType = 137 /* QWidgetStar */, + LastCoreExtType = QWidgetStar, // This logic must match the one in qglobal.h #if defined(QT_COORD_TYPE) @@ -290,6 +290,7 @@ class QPointF; #ifndef QT_NO_REGEXP class QRegExp; #endif +class QEasingCurve; class QWidget; class QObject; @@ -359,6 +360,7 @@ Q_DECLARE_BUILTIN_METATYPE(QPointF, QPointF) #ifndef QT_NO_REGEXP Q_DECLARE_BUILTIN_METATYPE(QRegExp, QRegExp) #endif +Q_DECLARE_BUILTIN_METATYPE(QEasingCurve, QEasingCurve) #ifdef QT3_SUPPORT Q_DECLARE_BUILTIN_METATYPE(QColorGroup, QColorGroup) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index e1b5825..384a3cd 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -46,6 +46,7 @@ #include "qdebug.h" #include "qmap.h" #include "qdatetime.h" +#include "qeasingcurve.h" #include "qlist.h" #include "qstring.h" #include "qstringlist.h" @@ -146,6 +147,11 @@ static void construct(QVariant::Private *x, const void *copy) v_construct(x, copy); break; #endif +#ifndef QT_BOOTSTRAPPED + case QVariant::EasingCurve: + v_construct(x, copy); + break; +#endif case QVariant::Int: x->data.i = copy ? *static_cast(copy) : 0; break; @@ -259,6 +265,11 @@ static void clear(QVariant::Private *d) v_clear(d); break; #endif +#ifndef QT_BOOTSTRAPPED + case QVariant::EasingCurve: + v_clear(d); + break; +#endif case QVariant::LongLong: case QVariant::ULongLong: case QVariant::Double: @@ -317,6 +328,9 @@ static bool isNull(const QVariant::Private *d) case QVariant::PointF: return v_cast(d)->isNull(); #endif +#ifndef QT_BOOTSTRAPPED + case QVariant::EasingCurve: +#endif case QVariant::Url: case QVariant::Locale: case QVariant::RegExp: @@ -435,6 +449,10 @@ static bool compare(const QVariant::Private *a, const QVariant::Private *b) return *v_cast(a) == *v_cast(b); case QVariant::DateTime: return *v_cast(a) == *v_cast(b); +#ifndef QT_BOOTSTRAPPED + case QVariant::EasingCurve: + return *v_cast(a) == *v_cast(b); +#endif case QVariant::ByteArray: return *v_cast(a) == *v_cast(b); case QVariant::BitArray: @@ -1097,6 +1115,11 @@ static void streamDebug(QDebug dbg, const QVariant &v) case QVariant::DateTime: dbg.nospace() << v.toDateTime(); break; +#ifndef QT_BOOTSTRAPPED + case QVariant::EasingCurve: + dbg.nospace() << v.toEasingCurve(); + break; +#endif case QVariant::ByteArray: dbg.nospace() << v.toByteArray(); break; @@ -1265,6 +1288,7 @@ const QVariant::Handler *QVariant::handler = &qt_kernel_variant_handler; \value Date a QDate \value DateTime a QDateTime \value Double a double + \value EasingCurve a QEasingCurve \value Font a QFont \value Hash a QVariantHash \value Icon a QIcon @@ -1483,6 +1507,12 @@ QVariant::QVariant(const char *val) */ /*! + \fn QVariant::QVariant(const QEasingCurve &val) + + Constructs a new variant with an easing curve value, \a val. +*/ + +/*! \fn QVariant::QVariant(const QByteArray &val) Constructs a new variant with a bytearray value, \a val. @@ -1681,6 +1711,10 @@ QVariant::QVariant(const QTime &val) { d.is_null = false; d.type = Time; v_construct(&d, val); } QVariant::QVariant(const QDateTime &val) { d.is_null = false; d.type = DateTime; v_construct(&d, val); } +#ifndef QT_BOOTSTRAPPED +QVariant::QVariant(const QEasingCurve &val) +{ d.is_null = false; d.type = EasingCurve; v_construct(&d, val); } +#endif QVariant::QVariant(const QList &list) { d.is_null = false; d.type = List; v_construct(&d, list); } QVariant::QVariant(const QMap &map) @@ -1870,7 +1904,7 @@ QVariant::Type QVariant::nameToType(const char *name) } #ifndef QT_NO_DATASTREAM -enum { MapFromThreeCount = 35 }; +enum { MapFromThreeCount = 36 }; static const ushort map_from_three[MapFromThreeCount] = { QVariant::Invalid, @@ -1902,6 +1936,7 @@ static const ushort map_from_three[MapFromThreeCount] = QVariant::Date, QVariant::Time, QVariant::DateTime, + QVariant::EasingCurve, QVariant::ByteArray, QVariant::BitArray, QVariant::KeySequence, @@ -2165,6 +2200,21 @@ QDateTime QVariant::toDateTime() const } /*! + \fn QEasingCurve QVariant::toEasingCurve() const + + Returns the variant as a QEasingCurve if the variant has type() \l + EasingCurve; otherwise returns a default easing curve. + + \sa canConvert(), convert() +*/ +#ifndef QT_BOOTSTRAPPED +QEasingCurve QVariant::toEasingCurve() const +{ + return qVariantToHelper(d, EasingCurve, handler); +} +#endif + +/*! \fn QByteArray QVariant::toByteArray() const Returns the variant as a QByteArray if the variant has type() \l @@ -2605,8 +2655,9 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] = /*QRegExp*/ 0, -/*QHash*/ 0 +/*QHash*/ 0, +/*QEasingCurve*/ 0 }; /*! diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 1a9e43a..9628dbf 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -60,6 +60,7 @@ class QBitArray; class QDataStream; class QDate; class QDateTime; +class QEasingCurve; class QLine; class QLineF; class QLocale; @@ -128,9 +129,10 @@ class Q_CORE_EXPORT QVariant LineF = 24, Point = 25, PointF = 26, - RegExp = 27, + RegExp = 27, Hash = 28, - LastCoreType = Hash, + EasingCurve = 29, + LastCoreType = EasingCurve, // value 62 is internally reserved #ifdef QT3_SUPPORT @@ -219,6 +221,9 @@ class Q_CORE_EXPORT QVariant #ifndef QT_NO_REGEXP QVariant(const QRegExp ®Exp); #endif +#ifndef QT_BOOTSTRAPPED + QVariant(const QEasingCurve &easing); +#endif QVariant(Qt::GlobalColor color); QVariant& operator=(const QVariant &other); @@ -280,6 +285,9 @@ class Q_CORE_EXPORT QVariant #ifndef QT_NO_REGEXP QRegExp toRegExp() const; #endif +#ifndef QT_BOOTSTRAPPED + QEasingCurve toEasingCurve() const; +#endif #ifdef QT3_SUPPORT inline QT3_SUPPORT int &asInt(); diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index b6a2df4..6b26907 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -600,11 +600,11 @@ QEasingCurve::QEasingCurve(Type type) Construct a copy of \a other. */ QEasingCurve::QEasingCurve(const QEasingCurve &other) -: d_ptr(new QEasingCurvePrivate) + : d_ptr(new QEasingCurvePrivate) { // ### non-atomic, requires malloc on shallow copy *d_ptr = *other.d_ptr; - if(other.d_ptr->config) + if (other.d_ptr->config) d_ptr->config = other.d_ptr->config->copy(); } @@ -629,7 +629,7 @@ QEasingCurve &QEasingCurve::operator=(const QEasingCurve &other) } *d_ptr = *other.d_ptr; - if(other.d_ptr->config) + if (other.d_ptr->config) d_ptr->config = other.d_ptr->config->copy(); return *this; @@ -845,6 +845,67 @@ QDebug operator<<(QDebug debug, const QEasingCurve &item) } return debug; } -#endif +#endif // QT_NO_DEBUG_STREAM + +#ifndef QT_NO_DATASTREAM +/*! + \fn QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) + \relates QEasingCurve + + Writes the given \a easing curve to the given \a stream and returns a + reference to the stream. + + \sa {Format of the QDataStream Operators} +*/ + +QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) +{ + stream << easing.d_ptr->type; + stream << intptr_t(easing.d_ptr->func); + + bool hasConfig = easing.d_ptr->config; + stream << hasConfig; + if (hasConfig) { + stream << easing.d_ptr->config->_p; + stream << easing.d_ptr->config->_a; + stream << easing.d_ptr->config->_o; + } + return stream; +} + +/*! + \fn QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) + \relates QQuaternion + + Reads an easing curve from the given \a stream into the given \a quaternion + and returns a reference to the stream. + + \sa {Format of the QDataStream Operators} +*/ + +QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) +{ + QEasingCurve::Type type; + int int_type; + stream >> int_type; + type = static_cast(int_type); + easing.setType(type); + + intptr_t ptr_func; + stream >> ptr_func; + easing.d_ptr->func = QEasingCurve::EasingFunction(ptr_func); + + bool hasConfig; + stream >> hasConfig; + if (hasConfig) { + QEasingCurveFunction *config = curveToFunctionObject(type); + stream >> config->_p; + stream >> config->_a; + stream >> config->_o; + easing.d_ptr->config = config; + } + return stream; +} +#endif // QT_NO_DATASTREAM QT_END_NAMESPACE diff --git a/src/corelib/tools/qeasingcurve.h b/src/corelib/tools/qeasingcurve.h index ae8822e..173fba4 100644 --- a/src/corelib/tools/qeasingcurve.h +++ b/src/corelib/tools/qeasingcurve.h @@ -100,13 +100,24 @@ public: qreal valueForProgress(qreal progress) const; private: QEasingCurvePrivate *d_ptr; +#ifndef QT_NO_DEBUG_STREAM friend Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QEasingCurve &item); +#endif +#ifndef QT_NO_DATASTREAM + friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QEasingCurve&); + friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QEasingCurve &); +#endif }; #ifndef QT_NO_DEBUG_STREAM Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QEasingCurve &item); #endif +#ifndef QT_NO_DATASTREAM +Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QEasingCurve&); +Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QEasingCurve &); +#endif + QT_END_NAMESPACE QT_END_HEADER diff --git a/tests/auto/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/qeasingcurve/tst_qeasingcurve.cpp index 12ddff1..abb4014 100644 --- a/tests/auto/qeasingcurve/tst_qeasingcurve.cpp +++ b/tests/auto/qeasingcurve/tst_qeasingcurve.cpp @@ -69,6 +69,10 @@ private slots: void valueForProgress(); void setCustomType(); void operators(); + void dataStreamOperators_data(); + void dataStreamOperators(); + void properties(); + void metaTypes(); protected: }; @@ -505,6 +509,117 @@ void tst_QEasingCurve::operators() QVERIFY(curve2 == curve); } +void tst_QEasingCurve::dataStreamOperators_data() +{ + QTest::addColumn("type"); + QTest::addColumn("amplitude"); + QTest::addColumn("overshoot"); + QTest::addColumn("period"); + QTest::addColumn("easingCurve"); + QTest::newRow("Linear") << int(QEasingCurve::Linear) << -1.0 << -1.0 << -1.0 << QEasingCurve(QEasingCurve::Linear); + QTest::newRow("OutCubic") << int(QEasingCurve::OutCubic) << -1.0 << -1.0 << -1.0 << QEasingCurve(QEasingCurve::OutCubic); + QTest::newRow("InOutSine") << int(QEasingCurve::InOutSine) << -1.0 << -1.0 << -1.0 << QEasingCurve(QEasingCurve::InOutSine); + QEasingCurve inOutElastic(QEasingCurve::InOutElastic); + inOutElastic.setPeriod(1.5); + inOutElastic.setAmplitude(2.0); + QTest::newRow("InOutElastic") << int(QEasingCurve::InOutElastic) << 2.0 << -1.0 << 1.5 << inOutElastic; + QTest::newRow("OutInBack") << int(QEasingCurve::OutInBack) << -1.0 << -1.0 << -1.0 << QEasingCurve(QEasingCurve::OutInBack); + QTest::newRow("OutCurve") << int(QEasingCurve::OutCurve) << -1.0 << -1.0 << -1.0 << QEasingCurve(QEasingCurve::OutCurve); + QEasingCurve inOutBack(QEasingCurve::InOutBack); + inOutBack.setOvershoot(0.5); + QTest::newRow("InOutBack") << int(QEasingCurve::InOutBack) << -1.0 << 0.5 << -1.0 << inOutBack; +} + +void tst_QEasingCurve::dataStreamOperators() +{ + QFETCH(int, type); + QFETCH(qreal, amplitude); + QFETCH(qreal, overshoot); + QFETCH(qreal, period); + QFETCH(QEasingCurve, easingCurve); + + // operator << + QEasingCurve curve; + curve.setType(QEasingCurve::Type(type)); + if (amplitude != -1.0) + curve.setAmplitude(amplitude); + if (overshoot != -1.0) + curve.setOvershoot(overshoot); + if (period != -1.0) + curve.setPeriod(period); + + QVERIFY(easingCurve == curve); + + QByteArray array; + QDataStream out(&array, QIODevice::WriteOnly); + out << curve; + + QDataStream in(array); + QEasingCurve curve2; + in >> curve2; + + QVERIFY(curve2 == curve); +} + +class tst_QEasingProperties : public QObject +{ + Q_OBJECT + Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing) +public: + tst_QEasingProperties(QObject *parent = 0) : QObject(parent) {} + + QEasingCurve easing() const { return e; } + void setEasing(const QEasingCurve& value) { e = value; } + +private: + QEasingCurve e; +}; + +// Test getting and setting easing properties via the metaobject system. +void tst_QEasingCurve::properties() +{ + tst_QEasingProperties obj; + + QEasingCurve inOutBack(QEasingCurve::InOutBack); + qreal overshoot = 1.5f; + inOutBack.setOvershoot(overshoot); + qreal amplitude = inOutBack.amplitude(); + qreal period = inOutBack.period(); + + obj.setEasing(inOutBack); + + QEasingCurve easing = qVariantValue(obj.property("easing")); + QCOMPARE(easing.type(), QEasingCurve::InOutBack); + QCOMPARE(easing.overshoot(), overshoot); + QCOMPARE(easing.amplitude(), amplitude); + QCOMPARE(easing.period(), period); + + QEasingCurve linear(QEasingCurve::Linear); + overshoot = linear.overshoot(); + amplitude = linear.amplitude(); + period = linear.period(); + + obj.setProperty("easing", + qVariantFromValue(QEasingCurve(QEasingCurve::Linear))); + + easing = qVariantValue(obj.property("easing")); + QCOMPARE(easing.type(), QEasingCurve::Linear); + QCOMPARE(easing.overshoot(), overshoot); + QCOMPARE(easing.amplitude(), amplitude); + QCOMPARE(easing.period(), period); +} + +void tst_QEasingCurve::metaTypes() +{ + QVERIFY(QMetaType::type("QEasingCurve") == QMetaType::QEasingCurve); + + QCOMPARE(QByteArray(QMetaType::typeName(QMetaType::QEasingCurve)), + QByteArray("QEasingCurve")); + + QVERIFY(QMetaType::isRegistered(QMetaType::QEasingCurve)); + + QVERIFY(qMetaTypeId() == QMetaType::QEasingCurve); +} QTEST_MAIN(tst_QEasingCurve) #include "tst_qeasingcurve.moc" -- cgit v0.12 From 0a7ca8efdd292f317d4c95a80485d9d51f14a694 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Tue, 23 Feb 2010 13:29:04 +1000 Subject: Adds QmlEasingValueType to qml Now it's possible to use easing curve types directly in qml as value types, {easing.type: "OutBounce"; easing.amplitude: 3}, instead of the former ugly string format, like "easeOutBounce(amplitude:3.0)". Reviewed-by: akennedy --- doc/src/declarative/animation.qdoc | 12 +- src/declarative/qml/qmlvaluetype.cpp | 70 +++++++++ src/declarative/qml/qmlvaluetype_p.h | 57 +++++++ src/declarative/util/qmlanimation.cpp | 163 ++++++--------------- src/declarative/util/qmlanimation_p.h | 9 +- src/declarative/util/qmlanimation_p_p.h | 2 +- .../qmlanimations/tst_qmlanimations.cpp | 105 ++++++------- 7 files changed, 237 insertions(+), 181 deletions(-) diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc index d80c3fa..892535e 100644 --- a/doc/src/declarative/animation.qdoc +++ b/doc/src/declarative/animation.qdoc @@ -72,9 +72,9 @@ Rectangle { y: 0 y: SequentialAnimation { repeat: true - NumberAnimation { to: 200-img.height; easing: "easeOutBounce"; duration: 2000 } + NumberAnimation { to: 200-img.height; easing.type: "OutBounce"; duration: 2000 } PauseAnimation { duration: 1000 } - NumberAnimation { to: 0; easing: "easeOutQuad"; duration: 1000 } + NumberAnimation { to: 0; easing.type: "OutQuad"; duration: 1000 } } } } @@ -135,7 +135,7 @@ transitions: [ Transition { NumberAnimation { properties: "x,y" - easing: "easeOutBounce" + easing.type: "OutBounce" duration: 200 } } @@ -156,7 +156,7 @@ Transition { SequentialAnimation { NumberAnimation { duration: 1000 - easing: "easeOutBounce" + easing.type: "OutBounce" // animate myItem's x and y if they have changed in the state target: myItem properties: "x,y" @@ -198,7 +198,7 @@ Transition { ParallelAnimation { NumberAnimation { duration: 1000 - easing: "easeOutBounce" + easing.type: "OutBounce" targets: box1 properties: "x,y" } @@ -226,7 +226,7 @@ Rectangle { id: redRect color: "red" width: 100; height: 100 - x: Behavior { NumberAnimation { duration: 300; easing: "InOutQuad" } } + x: Behavior { NumberAnimation { duration: 300; easing.type: "InOutQuad" } } } \endqml diff --git a/src/declarative/qml/qmlvaluetype.cpp b/src/declarative/qml/qmlvaluetype.cpp index 33c3e76..e3b4219 100644 --- a/src/declarative/qml/qmlvaluetype.cpp +++ b/src/declarative/qml/qmlvaluetype.cpp @@ -75,6 +75,8 @@ QmlValueType *QmlValueTypeFactory::valueType(int t) return new QmlRectFValueType; case QVariant::Vector3D: return new QmlVector3DValueType; + case QVariant::EasingCurve: + return new QmlEasingValueType; case QVariant::Font: return new QmlFontValueType; default: @@ -473,6 +475,74 @@ void QmlVector3DValueType::setZ(qreal z) vector.setZ(z); } +QmlEasingValueType::QmlEasingValueType(QObject *parent) +: QmlValueType(parent) +{ +} + +void QmlEasingValueType::read(QObject *obj, int idx) +{ + void *a[] = { &easing, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QmlEasingValueType::write(QObject *obj, int idx, QmlMetaProperty::WriteFlags flags) +{ + int status = -1; + void *a[] = { &easing, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QVariant QmlEasingValueType::value() +{ + return QVariant(easing); +} + +void QmlEasingValueType::setValue(QVariant value) +{ + easing = qvariant_cast(value); +} + +QmlEasingValueType::Type QmlEasingValueType::type() const +{ + return (QmlEasingValueType::Type)easing.type(); +} + +qreal QmlEasingValueType::amplitude() const +{ + return easing.amplitude(); +} + +qreal QmlEasingValueType::overshoot() const +{ + return easing.overshoot(); +} + +qreal QmlEasingValueType::period() const +{ + return easing.period(); +} + +void QmlEasingValueType::setType(QmlEasingValueType::Type type) +{ + easing.setType((QEasingCurve::Type)type); +} + +void QmlEasingValueType::setAmplitude(qreal amplitude) +{ + easing.setAmplitude(amplitude); +} + +void QmlEasingValueType::setOvershoot(qreal overshoot) +{ + easing.setOvershoot(overshoot); +} + +void QmlEasingValueType::setPeriod(qreal period) +{ + easing.setPeriod(period); +} + QmlFontValueType::QmlFontValueType(QObject *parent) : QmlValueType(parent), hasPixelSize(false) { diff --git a/src/declarative/qml/qmlvaluetype_p.h b/src/declarative/qml/qmlvaluetype_p.h index 0a152e8..6dd3703 100644 --- a/src/declarative/qml/qmlvaluetype_p.h +++ b/src/declarative/qml/qmlvaluetype_p.h @@ -57,6 +57,7 @@ #include #include +#include #include #include #include @@ -256,6 +257,62 @@ private: QVector3D vector; }; +class Q_AUTOTEST_EXPORT QmlEasingValueType : public QmlValueType +{ + Q_OBJECT + Q_ENUMS(Type) + + Q_PROPERTY(QmlEasingValueType::Type type READ type WRITE setType) + Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude) + Q_PROPERTY(qreal overshoot READ overshoot WRITE setOvershoot) + Q_PROPERTY(qreal period READ period WRITE setPeriod) +public: + enum Type { + Linear = QEasingCurve::Linear, + InQuad = QEasingCurve::InQuad, OutQuad = QEasingCurve::OutQuad, + InOutQuad = QEasingCurve::InOutQuad, OutInQuad = QEasingCurve::OutInQuad, + InCubic = QEasingCurve::InCubic, OutCubic = QEasingCurve::OutCubic, + InOutCubic = QEasingCurve::InOutCubic, OutInCubic = QEasingCurve::OutInCubic, + InQuart = QEasingCurve::InQuart, OutQuart = QEasingCurve::OutQuart, + InOutQuart = QEasingCurve::InOutQuart, OutInQuart = QEasingCurve::OutInQuart, + InQuint = QEasingCurve::InQuint, OutQuint = QEasingCurve::OutQuint, + InOutQuint = QEasingCurve::InOutQuint, OutInQuint = QEasingCurve::OutInQuint, + InSine = QEasingCurve::InSine, OutSine = QEasingCurve::OutSine, + InOutSine = QEasingCurve::InOutSine, OutInSine = QEasingCurve::OutInSine, + InExpo = QEasingCurve::InExpo, OutExpo = QEasingCurve::OutExpo, + InOutExpo = QEasingCurve::InOutExpo, OutInExpo = QEasingCurve::OutInExpo, + InCirc = QEasingCurve::InCirc, OutCirc = QEasingCurve::OutCirc, + InOutCirc = QEasingCurve::InOutCirc, OutInCirc = QEasingCurve::OutInCirc, + InElastic = QEasingCurve::InElastic, OutElastic = QEasingCurve::OutElastic, + InOutElastic = QEasingCurve::InOutElastic, OutInElastic = QEasingCurve::OutInElastic, + InBack = QEasingCurve::InBack, OutBack = QEasingCurve::OutBack, + InOutBack = QEasingCurve::InOutBack, OutInBack = QEasingCurve::OutInBack, + InBounce = QEasingCurve::InBounce, OutBounce = QEasingCurve::OutBounce, + InOutBounce = QEasingCurve::InOutBounce, OutInBounce = QEasingCurve::OutInBounce, + InCurve = QEasingCurve::InCurve, OutCurve = QEasingCurve::OutCurve, + SineCurve = QEasingCurve::SineCurve, CosineCurve = QEasingCurve::CosineCurve, + }; + + QmlEasingValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int, QmlMetaProperty::WriteFlags); + virtual QVariant value(); + virtual void setValue(QVariant value); + + Type type() const; + qreal amplitude() const; + qreal overshoot() const; + qreal period() const; + void setType(Type); + void setAmplitude(qreal); + void setOvershoot(qreal); + void setPeriod(qreal); + +private: + QEasingCurve easing; +}; + class Q_AUTOTEST_EXPORT QmlFontValueType : public QmlValueType { Q_OBJECT diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 6dcce58..2f24167 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -66,79 +66,6 @@ QT_BEGIN_NAMESPACE -static QEasingCurve stringToCurve(const QString &curve, QObject *obj) -{ - QEasingCurve easingCurve; - - QString normalizedCurve = curve; - bool hasParams = curve.contains(QLatin1Char('(')); - QStringList props; - - if (hasParams) { - QString easeName = curve.trimmed(); - if (!easeName.endsWith(QLatin1Char(')'))) { - qmlInfo(obj) << QmlPropertyAnimation::tr("Unmatched parenthesis in easing function \"%1\"").arg(curve); - return easingCurve; - } - - int idx = easeName.indexOf(QLatin1Char('(')); - QString prop_str = - easeName.mid(idx + 1, easeName.length() - 1 - idx - 1); - normalizedCurve = easeName.left(idx); - if (!normalizedCurve.startsWith(QLatin1String("ease"))) { - qmlInfo(obj) << QmlPropertyAnimation::tr("Easing function \"%1\" must start with \"ease\"").arg(curve); - return easingCurve; - } - - props = prop_str.split(QLatin1Char(',')); - } - - if (normalizedCurve.startsWith(QLatin1String("ease"))) - normalizedCurve = normalizedCurve.mid(4); - - static int index = QEasingCurve::staticMetaObject.indexOfEnumerator("Type"); - static QMetaEnum me = QEasingCurve::staticMetaObject.enumerator(index); - - int value = me.keyToValue(normalizedCurve.toUtf8().constData()); - if (value < 0) { - qmlInfo(obj) << QmlPropertyAnimation::tr("Unknown easing curve \"%1\"").arg(curve); - return easingCurve; - } - easingCurve.setType((QEasingCurve::Type)value); - - if (hasParams) { - foreach(const QString &str, props) { - int sep = str.indexOf(QLatin1Char(':')); - - if (sep == -1) { - qmlInfo(obj) << QmlPropertyAnimation::tr("Improperly specified parameter in easing function \"%1\"").arg(curve); - continue; - } - - QString propName = str.left(sep).trimmed(); - bool isOk; - qreal propValue = str.mid(sep + 1).trimmed().toDouble(&isOk); - - if (propName.isEmpty() || !isOk) { - qmlInfo(obj) << QmlPropertyAnimation::tr("Improperly specified parameter in easing function \"%1\"").arg(curve); - continue; - } - - if (propName == QLatin1String("amplitude")) { - easingCurve.setAmplitude(propValue); - } else if (propName == QLatin1String("period")) { - easingCurve.setPeriod(propValue); - } else if (propName == QLatin1String("overshoot")) { - easingCurve.setOvershoot(propValue); - } else { - qmlInfo(obj) << QmlPropertyAnimation::tr("Unknown easing parameter \"%1\"").arg(propName); - continue; - } - } - } - return easingCurve; -} - QML_DEFINE_NOCREATE_TYPE(QmlAbstractAnimation) /*! @@ -1927,195 +1854,195 @@ void QmlPropertyAnimation::setTo(const QVariant &t) } /*! - \qmlproperty string PropertyAnimation::easing + \qmlproperty QEasingCurve PropertyAnimation::easing \brief the easing curve used for the transition. Available values are: \table \row - \o \c easeLinear + \o \c Linear \o Easing curve for a linear (t) function: velocity is constant. \o \inlineimage qeasingcurve-linear.png \row - \o \c easeInQuad + \o \c InQuad \o Easing curve for a quadratic (t^2) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inquad.png \row - \o \c easeOutQuad + \o \c OutQuad \o Easing curve for a quadratic (t^2) function: decelerating to zero velocity. \o \inlineimage qeasingcurve-outquad.png \row - \o \c easeInOutQuad + \o \c InOutQuad \o Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutquad.png \row - \o \c easeOutInQuad + \o \c OutInQuad \o Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinquad.png \row - \o \c easeInCubic + \o \c InCubic \o Easing curve for a cubic (t^3) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-incubic.png \row - \o \c easeOutCubic + \o \c OutCubic \o Easing curve for a cubic (t^3) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outcubic.png \row - \o \c easeInOutCubic + \o \c InOutCubic \o Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutcubic.png \row - \o \c easeOutInCubic + \o \c OutInCubic \o Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outincubic.png \row - \o \c easeInQuart + \o \c InQuart \o Easing curve for a quartic (t^4) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inquart.png \row - \o \c easeOutQuart + \o \c OutQuart \o Easing curve for a cubic (t^4) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outquart.png \row - \o \c easeInOutQuart + \o \c InOutQuart \o Easing curve for a cubic (t^4) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutquart.png \row - \o \c easeOutInQuart + \o \c OutInQuart \o Easing curve for a cubic (t^4) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinquart.png \row - \o \c easeInQuint + \o \c InQuint \o Easing curve for a quintic (t^5) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inquint.png \row - \o \c easeOutQuint + \o \c OutQuint \o Easing curve for a cubic (t^5) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outquint.png \row - \o \c easeInOutQuint + \o \c InOutQuint \o Easing curve for a cubic (t^5) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutquint.png \row - \o \c easeOutInQuint + \o \c OutInQuint \o Easing curve for a cubic (t^5) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinquint.png \row - \o \c easeInSine + \o \c InSine \o Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-insine.png \row - \o \c easeOutSine + \o \c OutSine \o Easing curve for a sinusoidal (sin(t)) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outsine.png \row - \o \c easeInOutSine + \o \c InOutSine \o Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutsine.png \row - \o \c easeOutInSine + \o \c OutInSine \o Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinsine.png \row - \o \c easeInExpo + \o \c InExpo \o Easing curve for an exponential (2^t) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inexpo.png \row - \o \c easeOutExpo + \o \c OutExpo \o Easing curve for an exponential (2^t) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outexpo.png \row - \o \c easeInOutExpo + \o \c InOutExpo \o Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutexpo.png \row - \o \c easeOutInExpo + \o \c OutInExpo \o Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinexpo.png \row - \o \c easeInCirc + \o \c InCirc \o Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-incirc.png \row - \o \c easeOutCirc + \o \c OutCirc \o Easing curve for a circular (sqrt(1-t^2)) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outcirc.png \row - \o \c easeInOutCirc + \o \c InOutCirc \o Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutcirc.png \row - \o \c easeOutInCirc + \o \c OutInCirc \o Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outincirc.png \row - \o \c easeInElastic + \o \c InElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity. \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. \o \inlineimage qeasingcurve-inelastic.png \row - \o \c easeOutElastic + \o \c OutElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: decelerating from zero velocity. \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. \o \inlineimage qeasingcurve-outelastic.png \row - \o \c easeInOutElastic + \o \c InOutElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutelastic.png \row - \o \c easeOutInElastic + \o \c OutInElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinelastic.png \row - \o \c easeInBack + \o \c InBack \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. \o \inlineimage qeasingcurve-inback.png \row - \o \c easeOutBack + \o \c OutBack \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity. \o \inlineimage qeasingcurve-outback.png \row - \o \c easeInOutBack + \o \c InOutBack \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutback.png \row - \o \c easeOutInBack + \o \c OutInBack \o Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinback.png \row - \o \c easeInBounce + \o \c InBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inbounce.png \row - \o \c easeOutBounce + \o \c OutBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outbounce.png \row - \o \c easeInOutBounce + \o \c InOutBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutbounce.png \row - \o \c easeOutInBounce + \o \c OutInBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinbounce.png \endtable */ -QString QmlPropertyAnimation::easing() const +QEasingCurve QmlPropertyAnimation::easing() const { Q_D(const QmlPropertyAnimation); return d->easing; } -void QmlPropertyAnimation::setEasing(const QString &e) +void QmlPropertyAnimation::setEasing(const QEasingCurve &e) { Q_D(QmlPropertyAnimation); if (d->easing == e) return; d->easing = e; - d->va->setEasingCurve(stringToCurve(d->easing, this)); + d->va->setEasingCurve(d->easing); emit easingChanged(e); } diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 623ad8d..fd868bc 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -261,7 +262,7 @@ class Q_AUTOTEST_EXPORT QmlPropertyAnimation : public QmlAbstractAnimation Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged) Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged) - Q_PROPERTY(QString easing READ easing WRITE setEasing NOTIFY easingChanged) + Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged) Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) @@ -281,8 +282,8 @@ public: QVariant to() const; void setTo(const QVariant &); - QString easing() const; - void setEasing(const QString &); + QEasingCurve easing() const; + void setEasing(const QEasingCurve &); QObject *target() const; void setTarget(QObject *); @@ -307,7 +308,7 @@ Q_SIGNALS: void durationChanged(int); void fromChanged(QVariant); void toChanged(QVariant); - void easingChanged(const QString &); + void easingChanged(const QEasingCurve &); void propertiesChanged(const QString &); void targetChanged(QObject *, const QString &); }; diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h index 056ce82..8c88f14 100644 --- a/src/declarative/util/qmlanimation_p_p.h +++ b/src/declarative/util/qmlanimation_p_p.h @@ -327,7 +327,7 @@ public: QVariant from; QVariant to; - QString easing; + QEasingCurve easing; QObject *target; QString propertyName; diff --git a/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp b/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp index 1f6347e..00e099e 100644 --- a/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp +++ b/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp @@ -45,6 +45,7 @@ #include #include #include +#include class tst_qmlanimations : public QObject { @@ -67,11 +68,11 @@ private slots: void mixedTypes(); void properties(); void propertiesTransition(); - void easingStringConversion(); void invalidDuration(); void attached(); void propertyValueSourceDefaultStart(); void dontStart(); + void easingProperties(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -517,57 +518,6 @@ void tst_qmlanimations::propertiesTransition() }*/ } -void tst_qmlanimations::easingStringConversion() -{ - QmlNumberAnimation *animation = new QmlNumberAnimation; - animation->setEasing("easeInOutQuad"); - QCOMPARE(animation->easing(),QLatin1String("easeInOutQuad")); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve(), QEasingCurve(QEasingCurve::InOutQuad)); - - animation->setEasing("OutQuad"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve(), QEasingCurve(QEasingCurve::OutQuad)); - - animation->setEasing("easeOutBounce(amplitude: 5)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::OutBounce); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().amplitude(), qreal(5)); - - animation->setEasing("easeOutElastic(amplitude: 5, period: 3)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::OutElastic); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().amplitude(), qreal(5)); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().period(), qreal(3)); - - animation->setEasing("easeInOutBack(overshoot: 2)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::InOutBack); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().overshoot(), qreal(2)); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Unmatched parenthesis in easing function \"easeInOutBack(overshoot: 2\""); - animation->setEasing("easeInOutBack(overshoot: 2"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::Linear); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Easing function \"InOutBack(overshoot: 2)\" must start with \"ease\""); - animation->setEasing("InOutBack(overshoot: 2)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::Linear); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Unknown easing curve \"NonExistantEase\""); - animation->setEasing("NonExistantEase"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::Linear); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Improperly specified parameter in easing function \"easeInOutElastic(amplitude 5)\""); - animation->setEasing("easeInOutElastic(amplitude 5)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::InOutElastic); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Improperly specified parameter in easing function \"easeInOutElastic(amplitude: yes)\""); - animation->setEasing("easeInOutElastic(amplitude: yes)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::InOutElastic); - QVERIFY(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().amplitude() != qreal(5)); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Unknown easing parameter \"nonexistentproperty\""); - animation->setEasing("easeOutQuad(nonexistentproperty: 12)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::OutQuad); - - delete animation; -} - void tst_qmlanimations::invalidDuration() { QmlPropertyAnimation *animation = new QmlPropertyAnimation; @@ -666,6 +616,57 @@ void tst_qmlanimations::dontStart() } } +void tst_qmlanimations::easingProperties() +{ + { + QmlEngine engine; + QString componentStr = "import Qt 4.6\nNumberAnimation { easing.type: \"InOutQuad\" }"; + QmlComponent animationComponent(&engine); + animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QmlPropertyAnimation *animObject = qobject_cast(animationComponent.create()); + + QVERIFY(animObject != 0); + QCOMPARE(animObject->easing().type(), QEasingCurve::InOutQuad); + } + + { + QmlEngine engine; + QString componentStr = "import Qt 4.6\nPropertyAnimation { easing.type: \"OutBounce\"; easing.amplitude: 5.0 }"; + QmlComponent animationComponent(&engine); + animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QmlPropertyAnimation *animObject = qobject_cast(animationComponent.create()); + + QVERIFY(animObject != 0); + QCOMPARE(animObject->easing().type(), QEasingCurve::OutBounce); + QCOMPARE(animObject->easing().amplitude(), 5.0); + } + + { + QmlEngine engine; + QString componentStr = "import Qt 4.6\nPropertyAnimation { easing.type: \"OutElastic\"; easing.amplitude: 5.0; easing.period: 3.0}"; + QmlComponent animationComponent(&engine); + animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QmlPropertyAnimation *animObject = qobject_cast(animationComponent.create()); + + QVERIFY(animObject != 0); + QCOMPARE(animObject->easing().type(), QEasingCurve::OutElastic); + QCOMPARE(animObject->easing().amplitude(), 5.0); + QCOMPARE(animObject->easing().period(), 3.0); + } + + { + QmlEngine engine; + QString componentStr = "import Qt 4.6\nPropertyAnimation { easing.type: \"InOutBack\"; easing.overshoot: 2 }"; + QmlComponent animationComponent(&engine); + animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QmlPropertyAnimation *animObject = qobject_cast(animationComponent.create()); + + QVERIFY(animObject != 0); + QCOMPARE(animObject->easing().type(), QEasingCurve::InOutBack); + QCOMPARE(animObject->easing().overshoot(), 2.0); + } +} + QTEST_MAIN(tst_qmlanimations) #include "tst_qmlanimations.moc" -- cgit v0.12 From 9701facad44f8e435f0efe6417ffb7d17d5712e7 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Tue, 23 Feb 2010 17:25:10 +1000 Subject: Updates all qml examples/demos to use the easing curve value type syntax --- demos/declarative/calculator/calculator.qml | 4 +- demos/declarative/flickr/common/ImageDetails.qml | 2 +- demos/declarative/flickr/common/MediaLineEdit.qml | 2 +- demos/declarative/flickr/common/Star.qml | 2 +- demos/declarative/flickr/flickr-desktop.qml | 6 +- demos/declarative/flickr/flickr-mobile.qml | 4 +- demos/declarative/flickr/mobile/GridDelegate.qml | 6 +- demos/declarative/flickr/mobile/ImageDetails.qml | 2 +- demos/declarative/flickr/mobile/TitleBar.qml | 2 +- demos/declarative/minehunt/minehunt.qml | 2 +- demos/declarative/twitter/content/HomeTitleBar.qml | 2 +- .../declarative/twitter/content/MultiTitleBar.qml | 2 +- demos/declarative/twitter/content/TitleBar.qml | 2 +- demos/declarative/twitter/twitter.qml | 2 +- .../webbrowser/content/FlickableWebView.qml | 6 +- .../content/RetractingWebBrowserHeader.qml | 2 +- demos/declarative/webbrowser/webbrowser.qml | 4 +- examples/declarative/animations/easing.qml | 86 +++++++++++----------- .../declarative/animations/property-animation.qml | 8 +- examples/declarative/behaviours/test.qml | 6 +- .../border-image/content/MyBorderImage.qml | 8 +- examples/declarative/connections/connections.qml | 2 +- examples/declarative/fonts/hello.qml | 2 +- examples/declarative/layouts/Button.qml | 2 +- examples/declarative/layouts/positioners.qml | 16 ++-- examples/declarative/parallax/qml/Smiley.qml | 8 +- .../declarative/slideswitch/content/Switch.qml | 2 +- examples/declarative/states/transitions.qml | 8 +- .../declarative/tutorials/helloworld/tutorial3.qml | 2 +- examples/declarative/xmldata/yahoonews.qml | 2 +- .../qmlgraphicslistview/data/listview.qml | 2 +- .../visual/Package_Views/packageviews.qml | 2 +- .../declarative/visual/animation/easing/easing.qml | 84 ++++++++++----------- .../animation/pauseAnimation/pauseAnimation.qml | 4 +- .../animation/propertyAction/propertyAction.qml | 2 +- .../visual/animation/scriptAction/scriptAction.qml | 4 +- .../content/MyBorderImage.qml | 8 +- .../visual/qmlgraphicsflipable/test-flipable.qml | 4 +- .../visual/qmlgraphicstextedit/cursorDelegate.qml | 4 +- .../visual/qmlgraphicstextinput/cursorDelegate.qml | 4 +- .../declarative/visual/qmlspringfollow/follow.qml | 4 +- 41 files changed, 164 insertions(+), 162 deletions(-) diff --git a/demos/declarative/calculator/calculator.qml b/demos/declarative/calculator/calculator.qml index 54af7ad..66705e2 100644 --- a/demos/declarative/calculator/calculator.qml +++ b/demos/declarative/calculator/calculator.qml @@ -118,7 +118,7 @@ Rectangle { } transitions: Transition { - NumberAnimation { properties: "x,y,width"; easing: "easeOutBounce"; duration: 500 } - NumberAnimation { properties: "opacity"; easing: "easeInOutQuad"; duration: 500 } + NumberAnimation { properties: "x,y,width"; easing.type: "OutBounce"; duration: 500 } + NumberAnimation { properties: "opacity"; easing.type: "InOutQuad"; duration: 500 } } } diff --git a/demos/declarative/flickr/common/ImageDetails.qml b/demos/declarative/flickr/common/ImageDetails.qml index 19cad06..ab94d7a 100644 --- a/demos/declarative/flickr/common/ImageDetails.qml +++ b/demos/declarative/flickr/common/ImageDetails.qml @@ -149,7 +149,7 @@ Flipable { property: "smooth" value: false } - NumberAnimation { easing: "easeInOutQuad"; properties: "angle"; duration: 500 } + NumberAnimation { easing.type: "InOutQuad"; properties: "angle"; duration: 500 } PropertyAction { target: bigImage property: "smooth" diff --git a/demos/declarative/flickr/common/MediaLineEdit.qml b/demos/declarative/flickr/common/MediaLineEdit.qml index 3dfd1f3..9559f6a 100644 --- a/demos/declarative/flickr/common/MediaLineEdit.qml +++ b/demos/declarative/flickr/common/MediaLineEdit.qml @@ -42,7 +42,7 @@ Item { ] transitions: [ Transition { - NumberAnimation { properties: "x,width"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { properties: "x,width"; duration: 500; easing.type: "InOutQuad" } } ] diff --git a/demos/declarative/flickr/common/Star.qml b/demos/declarative/flickr/common/Star.qml index 8cd47b4..748a5ec 100644 --- a/demos/declarative/flickr/common/Star.qml +++ b/demos/declarative/flickr/common/Star.qml @@ -38,7 +38,7 @@ Item { Transition { NumberAnimation { properties: "opacity,scale,x,y" - easing: "easeOutBounce" + easing.type: "OutBounce" } } ] diff --git a/demos/declarative/flickr/flickr-desktop.qml b/demos/declarative/flickr/flickr-desktop.qml index 1ca3cdc..3a86347 100644 --- a/demos/declarative/flickr/flickr-desktop.qml +++ b/demos/declarative/flickr/flickr-desktop.qml @@ -86,14 +86,14 @@ Item { from: "*"; to: "Details" SequentialAnimation { ParentAction { } - NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing.type: "InOutQuad" } } }, Transition { from: "Details"; to: "*" SequentialAnimation { ParentAction { } - NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing.type: "InOutQuad" } PropertyAction { targets: wrapper; properties: "z" } } } @@ -180,7 +180,7 @@ Item { transitions: [ Transition { from: "*"; to: "*" - NumberAnimation { properties: "y"; duration: 1000; easing: "easeOutBounce(amplitude:0.5)" } + NumberAnimation { properties: "y"; duration: 1000; easing.type: "OutBounce"; easing.amplitude: 0.5 } } ] } diff --git a/demos/declarative/flickr/flickr-mobile.qml b/demos/declarative/flickr/flickr-mobile.qml index 0a89c4f..77ccd08 100644 --- a/demos/declarative/flickr/flickr-mobile.qml +++ b/demos/declarative/flickr/flickr-mobile.qml @@ -38,7 +38,7 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { properties: "x"; duration: 500; easing.type: "InOutQuad" } } } @@ -76,7 +76,7 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { properties: "x"; duration: 500; easing.type: "InOutQuad" } } } } diff --git a/demos/declarative/flickr/mobile/GridDelegate.qml b/demos/declarative/flickr/mobile/GridDelegate.qml index 0f5b69c..5722f10 100644 --- a/demos/declarative/flickr/mobile/GridDelegate.qml +++ b/demos/declarative/flickr/mobile/GridDelegate.qml @@ -23,7 +23,7 @@ Item { anchors.centerIn: parent scale: 0.0 - scale: Behavior { NumberAnimation { easing: "easeInOutQuad"} } + scale: Behavior { NumberAnimation { easing.type: "InOutQuad"} } id: scaleMe Rectangle { height: 79; width: 79; id: blackRect; anchors.centerIn: parent; color: "black"; smooth: true } @@ -55,13 +55,13 @@ Transition { from: "Show"; to: "Details" ParentAction { } - NumberAnimation { properties: "x,y"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { properties: "x,y"; duration: 500; easing.type: "InOutQuad" } }, Transition { from: "Details"; to: "Show" SequentialAnimation { ParentAction { } - NumberAnimation { properties: "x,y"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { properties: "x,y"; duration: 500; easing.type: "InOutQuad" } PropertyAction { targets: wrapper; properties: "z" } } } diff --git a/demos/declarative/flickr/mobile/ImageDetails.qml b/demos/declarative/flickr/mobile/ImageDetails.qml index 1963bf5..415764e 100644 --- a/demos/declarative/flickr/mobile/ImageDetails.qml +++ b/demos/declarative/flickr/mobile/ImageDetails.qml @@ -117,7 +117,7 @@ Flipable { transitions: Transition { SequentialAnimation { PropertyAction { target: bigImage; property: "smooth"; value: false } - NumberAnimation { easing: "easeInOutQuad"; properties: "angle"; duration: 500 } + NumberAnimation { easing.type: "InOutQuad"; properties: "angle"; duration: 500 } PropertyAction { target: bigImage; property: "smooth"; value: !flickable.moving } } } diff --git a/demos/declarative/flickr/mobile/TitleBar.qml b/demos/declarative/flickr/mobile/TitleBar.qml index 07b9762..0a06771 100644 --- a/demos/declarative/flickr/mobile/TitleBar.qml +++ b/demos/declarative/flickr/mobile/TitleBar.qml @@ -71,6 +71,6 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; easing: "easeInOutQuad" } + NumberAnimation { properties: "x"; easing.type: "InOutQuad" } } } diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index 92555c2..617a6ed 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -92,7 +92,7 @@ Item { } } NumberAnimation { - easing: "easeInOutQuad" + easing.type: "InOutQuad" properties: "angle" } ScriptAction{ diff --git a/demos/declarative/twitter/content/HomeTitleBar.qml b/demos/declarative/twitter/content/HomeTitleBar.qml index 8054f2e..a206c87 100644 --- a/demos/declarative/twitter/content/HomeTitleBar.qml +++ b/demos/declarative/twitter/content/HomeTitleBar.qml @@ -115,7 +115,7 @@ Item { transitions: [ Transition { from: "*"; to: "*" - NumberAnimation { properties: "x,y,width,height"; easing: "easeInOutQuad" } + NumberAnimation { properties: "x,y,width,height"; easing.type: "InOutQuad" } } ] } diff --git a/demos/declarative/twitter/content/MultiTitleBar.qml b/demos/declarative/twitter/content/MultiTitleBar.qml index ef7de65..e0205b8 100644 --- a/demos/declarative/twitter/content/MultiTitleBar.qml +++ b/demos/declarative/twitter/content/MultiTitleBar.qml @@ -18,7 +18,7 @@ Item { } ] transitions: [ - Transition { NumberAnimation { properties: "x,y"; duration: 500; easing: "easeInOutQuad" } } + Transition { NumberAnimation { properties: "x,y"; duration: 500; easing.type: "InOutQuad" } } ] } diff --git a/demos/declarative/twitter/content/TitleBar.qml b/demos/declarative/twitter/content/TitleBar.qml index 42a6115..149aa82 100644 --- a/demos/declarative/twitter/content/TitleBar.qml +++ b/demos/declarative/twitter/content/TitleBar.qml @@ -72,6 +72,6 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; easing: "easeInOutQuad" } + NumberAnimation { properties: "x"; easing.type: "InOutQuad" } } } diff --git a/demos/declarative/twitter/twitter.qml b/demos/declarative/twitter/twitter.qml index d2abf28..b091b03 100644 --- a/demos/declarative/twitter/twitter.qml +++ b/demos/declarative/twitter/twitter.qml @@ -89,7 +89,7 @@ Item { } ] transitions: [ - Transition { NumberAnimation { properties: "x,y"; duration: 500; easing: "easeInOutQuad" } } + Transition { NumberAnimation { properties: "x,y"; duration: 500; easing.type: "InOutQuad" } } ] } } diff --git a/demos/declarative/webbrowser/content/FlickableWebView.qml b/demos/declarative/webbrowser/content/FlickableWebView.qml index 7c46d4c..b60a95f 100644 --- a/demos/declarative/webbrowser/content/FlickableWebView.qml +++ b/demos/declarative/webbrowser/content/FlickableWebView.qml @@ -104,14 +104,14 @@ Flickable { property: "scale" from: 1 to: 0 // set before calling - easing: "easeLinear" + easing.type: "Linear" duration: 200 } NumberAnimation { id: flickVX target: flickable property: "viewportX" - easing: "easeLinear" + easing.type: "Linear" duration: 200 from: 0 // set before calling to: 0 // set before calling @@ -120,7 +120,7 @@ Flickable { id: flickVY target: flickable property: "viewportY" - easing: "easeLinear" + easing.type: "Linear" duration: 200 from: 0 // set before calling to: 0 // set before calling diff --git a/demos/declarative/webbrowser/content/RetractingWebBrowserHeader.qml b/demos/declarative/webbrowser/content/RetractingWebBrowserHeader.qml index e58ab0a..f905150 100644 --- a/demos/declarative/webbrowser/content/RetractingWebBrowserHeader.qml +++ b/demos/declarative/webbrowser/content/RetractingWebBrowserHeader.qml @@ -98,7 +98,7 @@ Image { NumberAnimation { targets: header properties: "progressOff" - easing: "easeInOutQuad" + easing.type: "InOutQuad" duration: 300 } } diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index 934593c..faafd5d 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -98,7 +98,7 @@ Item { Transition { NumberAnimation { properties: "opacity" - easing: "easeInOutQuad" + easing.type: "InOutQuad" duration: 300 } } @@ -154,7 +154,7 @@ Item { Transition { NumberAnimation { properties: "opacity" - easing: "easeInOutQuad" + easing.type: "InOutQuad" duration: 320 } } diff --git a/examples/declarative/animations/easing.qml b/examples/declarative/animations/easing.qml index 9b5bcc6..a7ba1c5 100644 --- a/examples/declarative/animations/easing.qml +++ b/examples/declarative/animations/easing.qml @@ -6,47 +6,47 @@ Rectangle { ListModel { id: easingTypes - ListElement { type: "easeLinear"; ballColor: "DarkRed" } - ListElement { type: "easeInQuad"; ballColor: "IndianRed" } - ListElement { type: "easeOutQuad"; ballColor: "Salmon" } - ListElement { type: "easeInOutQuad"; ballColor: "Tomato" } - ListElement { type: "easeOutInQuad"; ballColor: "DarkOrange" } - ListElement { type: "easeInCubic"; ballColor: "Gold" } - ListElement { type: "easeOutCubic"; ballColor: "Yellow" } - ListElement { type: "easeInOutCubic"; ballColor: "PeachPuff" } - ListElement { type: "easeOutInCubic"; ballColor: "Thistle" } - ListElement { type: "easeInQuart"; ballColor: "Orchid" } - ListElement { type: "easeOutQuart"; ballColor: "Purple" } - ListElement { type: "easeInOutQuart"; ballColor: "SlateBlue" } - ListElement { type: "easeOutInQuart"; ballColor: "Chartreuse" } - ListElement { type: "easeInQuint"; ballColor: "LimeGreen" } - ListElement { type: "easeOutQuint"; ballColor: "SeaGreen" } - ListElement { type: "easeInOutQuint"; ballColor: "DarkGreen" } - ListElement { type: "easeOutInQuint"; ballColor: "Olive" } - ListElement { type: "easeInSine"; ballColor: "DarkSeaGreen" } - ListElement { type: "easeOutSine"; ballColor: "Teal" } - ListElement { type: "easeInOutSine"; ballColor: "Turquoise" } - ListElement { type: "easeOutInSine"; ballColor: "SteelBlue" } - ListElement { type: "easeInExpo"; ballColor: "SkyBlue" } - ListElement { type: "easeOutExpo"; ballColor: "RoyalBlue" } - ListElement { type: "easeInOutExpo"; ballColor: "MediumBlue" } - ListElement { type: "easeOutInExpo"; ballColor: "MidnightBlue" } - ListElement { type: "easeInCirc"; ballColor: "CornSilk" } - ListElement { type: "easeOutCirc"; ballColor: "Bisque" } - ListElement { type: "easeInOutCirc"; ballColor: "RosyBrown" } - ListElement { type: "easeOutInCirc"; ballColor: "SandyBrown" } - ListElement { type: "easeInElastic"; ballColor: "DarkGoldenRod" } - ListElement { type: "easeOutElastic"; ballColor: "Chocolate" } - ListElement { type: "easeInOutElastic"; ballColor: "SaddleBrown" } - ListElement { type: "easeOutInElastic"; ballColor: "Brown" } - ListElement { type: "easeInBack"; ballColor: "Maroon" } - ListElement { type: "easeOutBack"; ballColor: "LavenderBlush" } - ListElement { type: "easeInOutBack"; ballColor: "MistyRose" } - ListElement { type: "easeOutInBack"; ballColor: "Gainsboro" } - ListElement { type: "easeOutBounce"; ballColor: "Silver" } - ListElement { type: "easeInBounce"; ballColor: "DimGray" } - ListElement { type: "easeInOutBounce"; ballColor: "SlateGray" } - ListElement { type: "easeOutInBounce"; ballColor: "DarkSlateGray" } + ListElement { type: "Linear"; ballColor: "DarkRed" } + ListElement { type: "InQuad"; ballColor: "IndianRed" } + ListElement { type: "OutQuad"; ballColor: "Salmon" } + ListElement { type: "InOutQuad"; ballColor: "Tomato" } + ListElement { type: "OutInQuad"; ballColor: "DarkOrange" } + ListElement { type: "InCubic"; ballColor: "Gold" } + ListElement { type: "OutCubic"; ballColor: "Yellow" } + ListElement { type: "InOutCubic"; ballColor: "PeachPuff" } + ListElement { type: "OutInCubic"; ballColor: "Thistle" } + ListElement { type: "InQuart"; ballColor: "Orchid" } + ListElement { type: "OutQuart"; ballColor: "Purple" } + ListElement { type: "InOutQuart"; ballColor: "SlateBlue" } + ListElement { type: "OutInQuart"; ballColor: "Chartreuse" } + ListElement { type: "InQuint"; ballColor: "LimeGreen" } + ListElement { type: "OutQuint"; ballColor: "SeaGreen" } + ListElement { type: "InOutQuint"; ballColor: "DarkGreen" } + ListElement { type: "OutInQuint"; ballColor: "Olive" } + ListElement { type: "InSine"; ballColor: "DarkSeaGreen" } + ListElement { type: "OutSine"; ballColor: "Teal" } + ListElement { type: "InOutSine"; ballColor: "Turquoise" } + ListElement { type: "OutInSine"; ballColor: "SteelBlue" } + ListElement { type: "InExpo"; ballColor: "SkyBlue" } + ListElement { type: "OutExpo"; ballColor: "RoyalBlue" } + ListElement { type: "InOutExpo"; ballColor: "MediumBlue" } + ListElement { type: "OutInExpo"; ballColor: "MidnightBlue" } + ListElement { type: "InCirc"; ballColor: "CornSilk" } + ListElement { type: "OutCirc"; ballColor: "Bisque" } + ListElement { type: "InOutCirc"; ballColor: "RosyBrown" } + ListElement { type: "OutInCirc"; ballColor: "SandyBrown" } + ListElement { type: "InElastic"; ballColor: "DarkGoldenRod" } + ListElement { type: "OutElastic"; ballColor: "Chocolate" } + ListElement { type: "InOutElastic"; ballColor: "SaddleBrown" } + ListElement { type: "OutInElastic"; ballColor: "Brown" } + ListElement { type: "InBack"; ballColor: "Maroon" } + ListElement { type: "OutBack"; ballColor: "LavenderBlush" } + ListElement { type: "InOutBack"; ballColor: "MistyRose" } + ListElement { type: "OutInBack"; ballColor: "Gainsboro" } + ListElement { type: "OutBounce"; ballColor: "Silver" } + ListElement { type: "InBounce"; ballColor: "DimGray" } + ListElement { type: "InOutBounce"; ballColor: "SlateGray" } + ListElement { type: "OutInBounce"; ballColor: "DarkSlateGray" } } Component { @@ -80,8 +80,8 @@ Rectangle { transitions: Transition { ParallelAnimation { - NumberAnimation { properties: "x"; easing: type; duration: 1000 } - ColorAnimation { properties: "color"; easing: type; duration: 1000 } + NumberAnimation { properties: "x"; easing.type: type; duration: 1000 } + ColorAnimation { properties: "color"; easing.type: type; duration: 1000 } } } } diff --git a/examples/declarative/animations/property-animation.qml b/examples/declarative/animations/property-animation.qml index 9f76ee5..537ee26 100644 --- a/examples/declarative/animations/property-animation.qml +++ b/examples/declarative/animations/property-animation.qml @@ -45,16 +45,16 @@ Item { y: SequentialAnimation { repeat: true - // Move from minHeight to maxHeight in 300ms, using the easeOutExpo easing function + // Move from minHeight to maxHeight in 300ms, using the OutExpo easing function NumberAnimation { from: smiley.minHeight; to: smiley.maxHeight - easing: "easeOutExpo"; duration: 300 + easing.type: "OutExpo"; duration: 300 } - // Then move back to minHeight in 1 second, using the easeOutBounce easing function + // Then move back to minHeight in 1 second, using the OutBounce easing function NumberAnimation { from: smiley.maxHeight; to: smiley.minHeight - easing: "easeOutBounce"; duration: 1000 + easing.type: "OutBounce"; duration: 1000 } // Then pause for 500ms diff --git a/examples/declarative/behaviours/test.qml b/examples/declarative/behaviours/test.qml index fc3f4bf..8fffd59 100644 --- a/examples/declarative/behaviours/test.qml +++ b/examples/declarative/behaviours/test.qml @@ -64,7 +64,8 @@ Rectangle { property: "y" from: 0 to: 10 - easing: "easeOutBounce(amplitude:30)" + easing.type: "OutBounce" + easing.amplitude: 30 duration: 250 } NumberAnimation { @@ -72,7 +73,8 @@ Rectangle { property: "y" from: 10 to: 0 - easing: "easeOutBounce(amplitude:30)" + easing.type: "OutBounce" + easing.amplitude: 30 duration: 250 } } diff --git a/examples/declarative/border-image/content/MyBorderImage.qml b/examples/declarative/border-image/content/MyBorderImage.qml index a57acc7..ca886e9 100644 --- a/examples/declarative/border-image/content/MyBorderImage.qml +++ b/examples/declarative/border-image/content/MyBorderImage.qml @@ -19,14 +19,14 @@ Item { width: SequentialAnimation { repeat: true - NumberAnimation { from: container.minWidth; to: container.maxWidth; duration: 2000; easing: "easeInOutQuad"} - NumberAnimation { from: container.maxWidth; to: container.minWidth; duration: 2000; easing: "easeInOutQuad" } + NumberAnimation { from: container.minWidth; to: container.maxWidth; duration: 2000; easing.type: "InOutQuad"} + NumberAnimation { from: container.maxWidth; to: container.minWidth; duration: 2000; easing.type: "InOutQuad" } } height: SequentialAnimation { repeat: true - NumberAnimation { from: container.minHeight; to: container.maxHeight; duration: 2000; easing: "easeInOutQuad"} - NumberAnimation { from: container.maxHeight; to: container.minHeight; duration: 2000; easing: "easeInOutQuad" } + NumberAnimation { from: container.minHeight; to: container.maxHeight; duration: 2000; easing.type: "InOutQuad"} + NumberAnimation { from: container.maxHeight; to: container.minHeight; duration: 2000; easing.type: "InOutQuad" } } border.top: container.margin diff --git a/examples/declarative/connections/connections.qml b/examples/declarative/connections/connections.qml index 07f71bb..ef2cb54 100644 --- a/examples/declarative/connections/connections.qml +++ b/examples/declarative/connections/connections.qml @@ -14,7 +14,7 @@ Rectangle { Image { id: image; source: "content/bg1.jpg"; anchors.centerIn: parent; transformOrigin: Item.Center - rotation: Behavior { NumberAnimation { easing: "easeOutCubic"; duration: 300 } } + rotation: Behavior { NumberAnimation { easing.type: "OutCubic"; duration: 300 } } } Button { diff --git a/examples/declarative/fonts/hello.qml b/examples/declarative/fonts/hello.qml index c682477..fcc9580 100644 --- a/examples/declarative/fonts/hello.qml +++ b/examples/declarative/fonts/hello.qml @@ -11,7 +11,7 @@ Rectangle { font.letterSpacing: SequentialAnimation { repeat: true; - NumberAnimation { from: 100; to: 300; easing: "easeInQuad"; duration: 3000 } + NumberAnimation { from: 100; to: 300; easing.type: "InQuad"; duration: 3000 } ScriptAction { script: { container.y = (screen.height / 4) + (Math.random() * screen.height / 2) container.x = (screen.width / 4) + (Math.random() * screen.width / 2) diff --git a/examples/declarative/layouts/Button.qml b/examples/declarative/layouts/Button.qml index 0bdb9fc..7cbf68a 100644 --- a/examples/declarative/layouts/Button.qml +++ b/examples/declarative/layouts/Button.qml @@ -17,6 +17,6 @@ Rectangle { border.color: "black"; color: "steelblue"; radius: 5; width: pix.wid transitions: Transition{ - NumberAnimation { properties:"x,left"; easing:"easeInOutQuad"; duration:200 } + NumberAnimation { properties:"x,left"; easing.type:"InOutQuad"; duration:200 } } } diff --git a/examples/declarative/layouts/positioners.qml b/examples/declarative/layouts/positioners.qml index fefd964..7146702 100644 --- a/examples/declarative/layouts/positioners.qml +++ b/examples/declarative/layouts/positioners.qml @@ -11,12 +11,12 @@ Rectangle { y: 0 move: Transition { NumberAnimation { - properties: "y"; easing: "easeOutBounce" + properties: "y"; easing.type: "OutBounce" } } add: Transition { NumberAnimation { - properties: "y"; easing: "easeOutQuad" + properties: "y"; easing.type: "OutQuad" } } Rectangle { color: "red"; width: 100; height: 50; border.color: "black"; radius: 15 } @@ -35,12 +35,12 @@ Rectangle { y: 300 move: Transition { NumberAnimation { - properties: "x"; easing: "easeOutBounce" + properties: "x"; easing.type: "OutBounce" } } add: Transition { NumberAnimation { - properties: "x"; easing: "easeOutQuad" + properties: "x"; easing.type: "OutQuad" } } Rectangle { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 } @@ -101,13 +101,13 @@ Rectangle { move: Transition { NumberAnimation { - properties: "x,y"; easing: "easeOutBounce" + properties: "x,y"; easing.type: "OutBounce" } } add: Transition { NumberAnimation { - properties: "x,y"; easing: "easeOutBounce" + properties: "x,y"; easing.type: "OutBounce" } } @@ -136,13 +136,13 @@ Rectangle { move: Transition { NumberAnimation { - properties: "x,y"; easing: "easeOutBounce" + properties: "x,y"; easing.type: "OutBounce" } } add: Transition { NumberAnimation { - properties: "x,y"; easing: "easeOutBounce" + properties: "x,y"; easing.type: "OutBounce" } } Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } diff --git a/examples/declarative/parallax/qml/Smiley.qml b/examples/declarative/parallax/qml/Smiley.qml index fc5b4fe..81eadda 100644 --- a/examples/declarative/parallax/qml/Smiley.qml +++ b/examples/declarative/parallax/qml/Smiley.qml @@ -27,16 +27,16 @@ Item { y: SequentialAnimation { repeat: true - // Move from minHeight to maxHeight in 300ms, using the easeOutExpo easing function + // Move from minHeight to maxHeight in 300ms, using the OutExpo easing function NumberAnimation { from: smiley.minHeight; to: smiley.maxHeight - easing: "easeOutExpo"; duration: 300 + easing.type: "OutExpo"; duration: 300 } - // Then move back to minHeight in 1 second, using the easeOutBounce easing function + // Then move back to minHeight in 1 second, using the OutBounce easing function NumberAnimation { from: smiley.maxHeight; to: smiley.minHeight - easing: "easeOutBounce"; duration: 1000 + easing.type: "OutBounce"; duration: 1000 } // Then pause for 500ms diff --git a/examples/declarative/slideswitch/content/Switch.qml b/examples/declarative/slideswitch/content/Switch.qml index 930f471..758aee6 100644 --- a/examples/declarative/slideswitch/content/Switch.qml +++ b/examples/declarative/slideswitch/content/Switch.qml @@ -66,7 +66,7 @@ Item { //![7] transitions: Transition { - NumberAnimation { properties: "x"; easing: "easeInOutQuad"; duration: 200 } + NumberAnimation { properties: "x"; easing.type: "InOutQuad"; duration: 200 } } //![7] } diff --git a/examples/declarative/states/transitions.qml b/examples/declarative/states/transitions.qml index 48d5f60..8ad61ad 100644 --- a/examples/declarative/states/transitions.qml +++ b/examples/declarative/states/transitions.qml @@ -51,16 +51,16 @@ Rectangle { // transitions define how the properties change. transitions: [ // When transitioning to 'Position1' move x,y over a duration of 1 second, - // with easeOutBounce easing function. + // with OutBounce easing function. Transition { from: "*"; to: "Position1" - NumberAnimation { properties: "x,y"; easing: "easeOutBounce"; duration: 1000 } + NumberAnimation { properties: "x,y"; easing.type: "OutBounce"; duration: 1000 } }, // When transitioning to 'Position2' move x,y over a duration of 2 seconds, - // with easeInOutQuad easing function. + // with InOutQuad easing function. Transition { from: "*"; to: "Position2" - NumberAnimation { properties: "x,y"; easing: "easeInOutQuad"; duration: 2000 } + NumberAnimation { properties: "x,y"; easing.type: "InOutQuad"; duration: 2000 } }, // For any other state changes move x,y linearly over duration of 200ms. Transition { diff --git a/examples/declarative/tutorials/helloworld/tutorial3.qml b/examples/declarative/tutorials/helloworld/tutorial3.qml index 9eaa009..b8a4f77 100644 --- a/examples/declarative/tutorials/helloworld/tutorial3.qml +++ b/examples/declarative/tutorials/helloworld/tutorial3.qml @@ -28,7 +28,7 @@ Rectangle { transitions: Transition { from: ""; to: "down"; reversible: true ParallelAnimation { - NumberAnimation { properties: "y,rotation"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { properties: "y,rotation"; duration: 500; easing.type: "InOutQuad" } ColorAnimation { duration: 500 } } } diff --git a/examples/declarative/xmldata/yahoonews.qml b/examples/declarative/xmldata/yahoonews.qml index b80e29c..f7c269c 100644 --- a/examples/declarative/xmldata/yahoonews.qml +++ b/examples/declarative/xmldata/yahoonews.qml @@ -61,7 +61,7 @@ Rectangle { transitions: Transition { from: "*"; to: "Details"; reversible: true SequentialAnimation { - NumberAnimation { duration: 200; properties: "height"; easing: "easeOutQuad" } + NumberAnimation { duration: 200; properties: "height"; easing.type: "OutQuad" } NumberAnimation { duration: 200; properties: "opacity" } } } diff --git a/tests/auto/declarative/qmlgraphicslistview/data/listview.qml b/tests/auto/declarative/qmlgraphicslistview/data/listview.qml index 99b3db6..1c1b3f8 100644 --- a/tests/auto/declarative/qmlgraphicslistview/data/listview.qml +++ b/tests/auto/declarative/qmlgraphicslistview/data/listview.qml @@ -88,7 +88,7 @@ Rectangle { ScriptAction { script: console.log("Fix PropertyAction with attached properties") } /* PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: true } - NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } + NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: "InOutQuad" } PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: false } */ } diff --git a/tests/auto/declarative/visual/Package_Views/packageviews.qml b/tests/auto/declarative/visual/Package_Views/packageviews.qml index b577e45..cf3f9f7 100644 --- a/tests/auto/declarative/visual/Package_Views/packageviews.qml +++ b/tests/auto/declarative/visual/Package_Views/packageviews.qml @@ -64,7 +64,7 @@ Rectangle { from: "*"; to: "*" SequentialAnimation { ParentAction{} - NumberAnimation { properties: "x,y,width"; easing: "easeInOutQuad" } + NumberAnimation { properties: "x,y,width"; easing.type: "InOutQuad" } } } ] diff --git a/tests/auto/declarative/visual/animation/easing/easing.qml b/tests/auto/declarative/visual/animation/easing/easing.qml index 9c814eb..4248d88 100644 --- a/tests/auto/declarative/visual/animation/easing/easing.qml +++ b/tests/auto/declarative/visual/animation/easing/easing.qml @@ -9,127 +9,127 @@ Rectangle { ListModel { id: easingtypes ListElement { - type: "easeLinear" + type: "Linear" } ListElement { - type: "easeInQuad" + type: "InQuad" } ListElement { - type: "easeOutQuad" + type: "OutQuad" } ListElement { - type: "easeInOutQuad" + type: "InOutQuad" } ListElement { - type: "easeOutInQuad" + type: "OutInQuad" } ListElement { - type: "easeInCubic" + type: "InCubic" } ListElement { - type: "easeOutCubic" + type: "OutCubic" } ListElement { - type: "easeInOutCubic" + type: "InOutCubic" } ListElement { - type: "easeOutInCubic" + type: "OutInCubic" } ListElement { - type: "easeInQuart" + type: "InQuart" } ListElement { - type: "easeOutQuart" + type: "OutQuart" } ListElement { - type: "easeInOutQuart" + type: "InOutQuart" } ListElement { - type: "easeOutInQuart" + type: "OutInQuart" } ListElement { - type: "easeInQuint" + type: "InQuint" } ListElement { - type: "easeOutQuint" + type: "OutQuint" } ListElement { - type: "easeInOutQuint" + type: "InOutQuint" } ListElement { - type: "easeOutInQuint" + type: "OutInQuint" } ListElement { - type: "easeInSine" + type: "InSine" } ListElement { - type: "easeOutSine" + type: "OutSine" } ListElement { - type: "easeInOutSine" + type: "InOutSine" } ListElement { - type: "easeOutInSine" + type: "OutInSine" } ListElement { - type: "easeInExpo" + type: "InExpo" } ListElement { - type: "easeOutExpo" + type: "OutExpo" } ListElement { - type: "easeInOutExpo" + type: "InOutExpo" } ListElement { - type: "easeOutInExpo" + type: "OutInExpo" } ListElement { - type: "easeInCirc" + type: "InCirc" } ListElement { - type: "easeOutCirc" + type: "OutCirc" } ListElement { - type: "easeInOutCirc" + type: "InOutCirc" } ListElement { - type: "easeOutInCirc" + type: "OutInCirc" } ListElement { - type: "easeInElastic" + type: "InElastic" } ListElement { - type: "easeOutElastic" + type: "OutElastic" } ListElement { - type: "easeInOutElastic" + type: "InOutElastic" } ListElement { - type: "easeOutInElastic" + type: "OutInElastic" } ListElement { - type: "easeInBack" + type: "InBack" } ListElement { - type: "easeOutBack" + type: "OutBack" } ListElement { - type: "easeInOutBack" + type: "InOutBack" } ListElement { - type: "easeOutInBack" + type: "OutInBack" } ListElement { - type: "easeOutBounce" + type: "OutBounce" } ListElement { - type: "easeInBounce" + type: "InBounce" } ListElement { - type: "easeInOutBounce" + type: "InOutBounce" } ListElement { - type: "easeOutInBounce" + type: "OutInBounce" } } ] @@ -177,7 +177,7 @@ Rectangle { reversible: true NumberAnimation { properties: "x" - easing: type + easing.type: type duration: 1000 } } diff --git a/tests/auto/declarative/visual/animation/pauseAnimation/pauseAnimation.qml b/tests/auto/declarative/visual/animation/pauseAnimation/pauseAnimation.qml index f2e065d..24ca76b 100644 --- a/tests/auto/declarative/visual/animation/pauseAnimation/pauseAnimation.qml +++ b/tests/auto/declarative/visual/animation/pauseAnimation/pauseAnimation.qml @@ -14,11 +14,11 @@ Rectangle { repeat: true NumberAnimation { to: 0; duration: 500 - easing: "easeInOutQuad" + easing.type: "InOutQuad" } NumberAnimation { to: 200-img.height - easing: "easeOutBounce" + easing.type: "OutBounce" duration: 2000 } PauseAnimation { diff --git a/tests/auto/declarative/visual/animation/propertyAction/propertyAction.qml b/tests/auto/declarative/visual/animation/propertyAction/propertyAction.qml index 593f495..e18e770 100644 --- a/tests/auto/declarative/visual/animation/propertyAction/propertyAction.qml +++ b/tests/auto/declarative/visual/animation/propertyAction/propertyAction.qml @@ -28,7 +28,7 @@ Rectangle { SequentialAnimation { ColorAnimation {} PropertyAction { properties: "x" } - NumberAnimation { properties: "y"; easing: "InOutQuad" } + NumberAnimation { properties: "y"; easing.type: "InOutQuad" } } } } diff --git a/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml b/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml index 30d587a..ef4ed76 100644 --- a/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml +++ b/tests/auto/declarative/visual/animation/scriptAction/scriptAction.qml @@ -27,9 +27,9 @@ Rectangle { transitions: Transition { SequentialAnimation { - NumberAnimation { properties: "x"; easing: "InOutQuad" } + NumberAnimation { properties: "x"; easing.type: "InOutQuad" } ScriptAction { stateChangeScriptName: "setColor" } - NumberAnimation { properties: "y"; easing: "InOutQuad" } + NumberAnimation { properties: "y"; easing.type: "InOutQuad" } } } } diff --git a/tests/auto/declarative/visual/qmlgraphicsborderimage/content/MyBorderImage.qml b/tests/auto/declarative/visual/qmlgraphicsborderimage/content/MyBorderImage.qml index eb1ec00..e268ce7 100644 --- a/tests/auto/declarative/visual/qmlgraphicsborderimage/content/MyBorderImage.qml +++ b/tests/auto/declarative/visual/qmlgraphicsborderimage/content/MyBorderImage.qml @@ -20,14 +20,14 @@ Item { width: SequentialAnimation { repeat: true - NumberAnimation { from: container.minWidth; to: container.maxWidth; duration: 2000; easing: "easeInOutQuad"} - NumberAnimation { from: container.maxWidth; to: container.minWidth; duration: 2000; easing: "easeInOutQuad" } + NumberAnimation { from: container.minWidth; to: container.maxWidth; duration: 2000; easing.type: "InOutQuad"} + NumberAnimation { from: container.maxWidth; to: container.minWidth; duration: 2000; easing.type: "InOutQuad" } } height: SequentialAnimation { repeat: true - NumberAnimation { from: container.minHeight; to: container.maxHeight; duration: 2000; easing: "easeInOutQuad"} - NumberAnimation { from: container.maxHeight; to: container.minHeight; duration: 2000; easing: "easeInOutQuad" } + NumberAnimation { from: container.minHeight; to: container.maxHeight; duration: 2000; easing.type: "InOutQuad"} + NumberAnimation { from: container.maxHeight; to: container.minHeight; duration: 2000; easing.type: "InOutQuad" } } border.top: container.margin diff --git a/tests/auto/declarative/visual/qmlgraphicsflipable/test-flipable.qml b/tests/auto/declarative/visual/qmlgraphicsflipable/test-flipable.qml index c33a319..a27aa6e 100644 --- a/tests/auto/declarative/visual/qmlgraphicsflipable/test-flipable.qml +++ b/tests/auto/declarative/visual/qmlgraphicsflipable/test-flipable.qml @@ -36,7 +36,7 @@ Rectangle { } transitions: Transition { - NumberAnimation { easing: "easeInOutQuad"; properties: "angle"; duration: 3000 } + NumberAnimation { easing.type: "InOutQuad"; properties: "angle"; duration: 3000 } } } @@ -64,7 +64,7 @@ Rectangle { } transitions: Transition { - NumberAnimation { easing: "easeInOutQuad"; properties: "angle"; duration: 3000 } + NumberAnimation { easing.type: "InOutQuad"; properties: "angle"; duration: 3000 } } } diff --git a/tests/auto/declarative/visual/qmlgraphicstextedit/cursorDelegate.qml b/tests/auto/declarative/visual/qmlgraphicstextedit/cursorDelegate.qml index e0c5db4..176a5b8 100644 --- a/tests/auto/declarative/visual/qmlgraphicstextedit/cursorDelegate.qml +++ b/tests/auto/declarative/visual/qmlgraphicstextedit/cursorDelegate.qml @@ -11,8 +11,8 @@ import Qt 4.6 Rectangle { id:bottom; color: "black"; width: 3; height: 1; x: -1; anchors.bottom: parent.bottom;} opacity: 1 opacity: SequentialAnimation { running: cPage.parent.focus == true; repeat: true; - NumberAnimation { properties: "opacity"; to: 1; duration: 500; easing: "easeInQuad"} - NumberAnimation { properties: "opacity"; to: 0; duration: 500; easing: "easeOutQuad"} + NumberAnimation { properties: "opacity"; to: 1; duration: 500; easing.type: "InQuad"} + NumberAnimation { properties: "opacity"; to: 0; duration: 500; easing.type: "OutQuad"} } } width: 1; diff --git a/tests/auto/declarative/visual/qmlgraphicstextinput/cursorDelegate.qml b/tests/auto/declarative/visual/qmlgraphicstextinput/cursorDelegate.qml index 0038664..6a4e7fa 100644 --- a/tests/auto/declarative/visual/qmlgraphicstextinput/cursorDelegate.qml +++ b/tests/auto/declarative/visual/qmlgraphicstextinput/cursorDelegate.qml @@ -11,8 +11,8 @@ import Qt 4.6 Rectangle { id:bottom; color: "black"; width: 3; height: 1; x: -1; anchors.bottom: parent.bottom;} opacity: 1 opacity: SequentialAnimation { running: cPage.parent.focus == true; repeat: true; - NumberAnimation { properties: "opacity"; to: 1; duration: 500; easing: "easeInQuad"} - NumberAnimation { properties: "opacity"; to: 0; duration: 500; easing: "easeOutQuad"} + NumberAnimation { properties: "opacity"; to: 1; duration: 500; easing.type: "InQuad"} + NumberAnimation { properties: "opacity"; to: 0; duration: 500; easing.type: "OutQuad"} } } width: 1; diff --git a/tests/auto/declarative/visual/qmlspringfollow/follow.qml b/tests/auto/declarative/visual/qmlspringfollow/follow.qml index a85a778..62503e4 100644 --- a/tests/auto/declarative/visual/qmlspringfollow/follow.qml +++ b/tests/auto/declarative/visual/qmlspringfollow/follow.qml @@ -11,11 +11,11 @@ Rectangle { repeat: true NumberAnimation { to: 20; duration: 500 - easing: "easeInOutQuad" + easing.type: "InOutQuad" } NumberAnimation { to: 200; duration: 2000 - easing: "easeOutBounce" + easing.type: "OutBounce" } PauseAnimation { duration: 1000 } } -- cgit v0.12 From 48161233af2a6071bc0ba99e546da98f705b8281 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 18:34:41 +1000 Subject: String to enum conversion in value types Assigning a string to a value type enum property from a binding was not working as QmlMetaProperty didn't realise the property was of enum type. --- src/declarative/qml/qmlcompiler.cpp | 8 +++++++- src/declarative/qml/qmlmetaproperty.cpp | 10 ++++++++-- src/declarative/qml/qmlmetaproperty_p.h | 3 ++- src/declarative/qml/qmlpropertycache.cpp | 22 ++++++++++++++++------ src/declarative/qml/qmlpropertycache_p.h | 7 +++++-- .../declarative/qmlvaluetypes/data/enums.1.qml | 6 ++++++ .../declarative/qmlvaluetypes/data/enums.2.qml | 6 ++++++ .../qmlvaluetypes/tst_qmlvaluetypes.cpp | 21 +++++++++++++++++++++ 8 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 tests/auto/declarative/qmlvaluetypes/data/enums.1.qml create mode 100644 tests/auto/declarative/qmlvaluetypes/data/enums.2.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 10b6e4f..4508964 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -2609,7 +2609,13 @@ int QmlCompiler::genContextCache() int QmlCompiler::genValueTypeData(QmlParser::Property *valueTypeProp, QmlParser::Property *prop) { - return output->indexForByteArray(QmlMetaPropertyPrivate::saveValueType(prop->parent->metaObject(), prop->index, valueTypeProp->index, valueTypeProp->type)); + QByteArray data = + QmlMetaPropertyPrivate::saveValueType(prop->parent->metaObject(), prop->index, + QmlEnginePrivate::get(engine)->valueTypes[prop->type]->metaObject(), + valueTypeProp->index); +// valueTypeProp->index, valueTypeProp->type); + + return output->indexForByteArray(data); } int QmlCompiler::genPropertyData(QmlParser::Property *prop) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index ac619ec..d731393 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -777,6 +777,7 @@ bool QmlMetaPropertyPrivate::writeValueProperty(const QVariant &value, writeBack->read(object, core.coreIndex); QmlPropertyCache::Data data = core; + data.flags = valueType.flags; data.coreIndex = valueType.valueTypeCoreIdx; data.propType = valueType.valueTypePropType; rv = write(writeBack, data, value, context, flags); @@ -1082,15 +1083,20 @@ struct ValueTypeSerializedData : public SerializedData { }; QByteArray QmlMetaPropertyPrivate::saveValueType(const QMetaObject *metaObject, int index, - int subIndex, int subType) + const QMetaObject *subObject, int subIndex) { + QMetaProperty prop = metaObject->property(index); + QMetaProperty subProp = subObject->property(subIndex); + ValueTypeSerializedData sd; sd.type = QmlMetaProperty::ValueTypeProperty; sd.core.load(metaObject->property(index)); + sd.valueType.flags = QmlPropertyCache::Data::flagsForProperty(subProp); sd.valueType.valueTypeCoreIdx = subIndex; - sd.valueType.valueTypePropType = subType; + sd.valueType.valueTypePropType = subProp.userType(); QByteArray rv((const char *)&sd, sizeof(sd)); + return rv; } diff --git a/src/declarative/qml/qmlmetaproperty_p.h b/src/declarative/qml/qmlmetaproperty_p.h index b99e5be..9236bd3 100644 --- a/src/declarative/qml/qmlmetaproperty_p.h +++ b/src/declarative/qml/qmlmetaproperty_p.h @@ -111,7 +111,8 @@ public: static QmlAbstractBinding *setBinding(QObject *, const QmlPropertyCache::Data &, QmlAbstractBinding *, QmlMetaProperty::WriteFlags flags = QmlMetaProperty::DontRemoveBinding); - static QByteArray saveValueType(const QMetaObject *, int, int, int); + static QByteArray saveValueType(const QMetaObject *, int, + const QMetaObject *, int); static QByteArray saveProperty(const QMetaObject *, int); static QmlMetaProperty restore(const QByteArray &, QObject *, QmlContext * = 0); diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp index 2d087b6..81f8e51 100644 --- a/src/declarative/qml/qmlpropertycache.cpp +++ b/src/declarative/qml/qmlpropertycache.cpp @@ -49,13 +49,11 @@ Q_DECLARE_METATYPE(QScriptValue); QT_BEGIN_NAMESPACE -void QmlPropertyCache::Data::load(const QMetaProperty &p, QmlEngine *engine) +QmlPropertyCache::Data::Flags QmlPropertyCache::Data::flagsForProperty(const QMetaProperty &p, QmlEngine *engine) { - propType = p.userType(); - if (QVariant::Type(propType) == QVariant::LastType) - propType = qMetaTypeId(); - coreIndex = p.propertyIndex(); - notifyIndex = p.notifySignalIndex(); + int propType = p.userType(); + + Flags flags; if (p.isConstant()) flags |= Data::IsConstant; @@ -78,6 +76,18 @@ void QmlPropertyCache::Data::load(const QMetaProperty &p, QmlEngine *engine) else if (cat == QmlMetaType::List) flags |= Data::IsQList; } + + return flags; +} + +void QmlPropertyCache::Data::load(const QMetaProperty &p, QmlEngine *engine) +{ + propType = p.userType(); + if (QVariant::Type(propType) == QVariant::LastType) + propType = qMetaTypeId(); + coreIndex = p.propertyIndex(); + notifyIndex = p.notifySignalIndex(); + flags = flagsForProperty(p, engine); } void QmlPropertyCache::Data::load(const QMetaMethod &m) diff --git a/src/declarative/qml/qmlpropertycache_p.h b/src/declarative/qml/qmlpropertycache_p.h index 18eea80..4a98b88 100644 --- a/src/declarative/qml/qmlpropertycache_p.h +++ b/src/declarative/qml/qmlpropertycache_p.h @@ -104,6 +104,7 @@ public: int coreIndex; int notifyIndex; + static Flags flagsForProperty(const QMetaProperty &, QmlEngine *engine = 0); void load(const QMetaProperty &, QmlEngine *engine = 0); void load(const QMetaMethod &); QString name(QObject *); @@ -113,6 +114,7 @@ public: struct ValueTypeData { inline ValueTypeData(); inline bool operator==(const ValueTypeData &); + Data::Flags flags; // flags on the value type wrapper int valueTypeCoreIdx; // The prop index of the access property on the value type wrapper int valueTypePropType; // The QVariant::Type of access property on the value type wrapper }; @@ -173,13 +175,14 @@ QmlPropertyCache::property(const QScriptDeclarativeClass::Identifier &id) const } QmlPropertyCache::ValueTypeData::ValueTypeData() -: valueTypeCoreIdx(-1), valueTypePropType(0) +: flags(QmlPropertyCache::Data::NoFlags), valueTypeCoreIdx(-1), valueTypePropType(0) { } bool QmlPropertyCache::ValueTypeData::operator==(const ValueTypeData &o) { - return valueTypeCoreIdx == o.valueTypeCoreIdx && + return flags == o.flags && + valueTypeCoreIdx == o.valueTypeCoreIdx && valueTypePropType == o.valueTypePropType; } diff --git a/tests/auto/declarative/qmlvaluetypes/data/enums.1.qml b/tests/auto/declarative/qmlvaluetypes/data/enums.1.qml new file mode 100644 index 0000000..0eadd50 --- /dev/null +++ b/tests/auto/declarative/qmlvaluetypes/data/enums.1.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + font.capitalization: "MixedCase" +} + diff --git a/tests/auto/declarative/qmlvaluetypes/data/enums.2.qml b/tests/auto/declarative/qmlvaluetypes/data/enums.2.qml new file mode 100644 index 0000000..81f1c92 --- /dev/null +++ b/tests/auto/declarative/qmlvaluetypes/data/enums.2.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + font.capitalization: if (1) "MixedCase" +} + diff --git a/tests/auto/declarative/qmlvaluetypes/tst_qmlvaluetypes.cpp b/tests/auto/declarative/qmlvaluetypes/tst_qmlvaluetypes.cpp index f99d3ce..4faa0bc 100644 --- a/tests/auto/declarative/qmlvaluetypes/tst_qmlvaluetypes.cpp +++ b/tests/auto/declarative/qmlvaluetypes/tst_qmlvaluetypes.cpp @@ -74,6 +74,7 @@ private slots: void bindingVariantCopy(); void scriptVariantCopy(); void cppClasses(); + void enums(); private: QmlEngine engine; @@ -583,6 +584,26 @@ void tst_qmlvaluetypes::cppClasses() CPP_TEST(QmlFontValueType, QFont("Helvetica")); } + +void tst_qmlvaluetypes::enums() +{ + { + QmlComponent component(&engine, TEST_FILE("enums.1.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QVERIFY(object->font().capitalization() == QFont::MixedCase); + delete object; + } + + { + QmlComponent component(&engine, TEST_FILE("enums.2.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QVERIFY(object->font().capitalization() == QFont::MixedCase); + delete object; + } +} + QTEST_MAIN(tst_qmlvaluetypes) #include "tst_qmlvaluetypes.moc" -- cgit v0.12 From b4d55d5288ddae325046f62f65cbf667283b3859 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Tue, 23 Feb 2010 19:00:12 +1000 Subject: Fix compile error in QEasingCurve Reviewed-by: akennedy --- src/corelib/tools/qeasingcurve.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index 6b26907..89edb2d 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -861,7 +861,7 @@ QDebug operator<<(QDebug debug, const QEasingCurve &item) QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) { stream << easing.d_ptr->type; - stream << intptr_t(easing.d_ptr->func); + stream << quint64(intptr_t(easing.d_ptr->func)); bool hasConfig = easing.d_ptr->config; stream << hasConfig; @@ -891,9 +891,9 @@ QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) type = static_cast(int_type); easing.setType(type); - intptr_t ptr_func; + quint64 ptr_func; stream >> ptr_func; - easing.d_ptr->func = QEasingCurve::EasingFunction(ptr_func); + easing.d_ptr->func = QEasingCurve::EasingFunction(intptr_t(ptr_func)); bool hasConfig; stream >> hasConfig; -- cgit v0.12 From db817f85def9dcfd335bca46029b7eed168edb32 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Tue, 23 Feb 2010 19:00:12 +1000 Subject: Fix compile error in QEasingCurve Reviewed-by: akennedy --- src/corelib/tools/qeasingcurve.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index 6b26907..89edb2d 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -861,7 +861,7 @@ QDebug operator<<(QDebug debug, const QEasingCurve &item) QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) { stream << easing.d_ptr->type; - stream << intptr_t(easing.d_ptr->func); + stream << quint64(intptr_t(easing.d_ptr->func)); bool hasConfig = easing.d_ptr->config; stream << hasConfig; @@ -891,9 +891,9 @@ QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) type = static_cast(int_type); easing.setType(type); - intptr_t ptr_func; + quint64 ptr_func; stream >> ptr_func; - easing.d_ptr->func = QEasingCurve::EasingFunction(ptr_func); + easing.d_ptr->func = QEasingCurve::EasingFunction(intptr_t(ptr_func)); bool hasConfig; stream >> hasConfig; -- cgit v0.12 From d9a390c6d5f18f335fa0a4766180ffa62f28c363 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 23 Feb 2010 12:09:52 +0100 Subject: Added QmlEnginePrivate::resolvePlugin. resolvePlugin returns the merge of the plugin's base name with the platform suffix (e.g. .dylib) and prefix (e.g. lib). --- src/declarative/qml/qmlengine.cpp | 89 +++++++++++++++++++++++++++++++++++++-- src/declarative/qml/qmlengine_p.h | 6 +++ 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 67d8c7d..98e16aa 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1359,9 +1359,11 @@ public: qmldirParser.parse(); foreach (const QmlDirParser::Plugin &plugin, qmldirParser.plugins()) { - const QFileInfo pluginFileInfo(dir + QDir::separator() + plugin.path, plugin.name); - const QString pluginFilePath = pluginFileInfo.absoluteFilePath(); - engine->importExtension(pluginFilePath, uri); + QString resolvedFilePath = QmlEnginePrivate::get(engine)->resolvePlugin(dir + QDir::separator() + plugin.path, + plugin.name); + + if (!resolvedFilePath.isEmpty()) + engine->importExtension(resolvedFilePath, uri); } } @@ -1609,6 +1611,87 @@ QString QmlEngine::offlineStoragePath() const return d->scriptEngine.offlineStoragePath; } +/*! + \internal + + Returns the result of the merge of \a baseName with \a dir, \a suffixes, and \a prefix. + */ +QString QmlEnginePrivate::resolvePlugin(const QDir &dir, const QString &baseName, + const QStringList &suffixes, + const QString &prefix) +{ + foreach (const QString &suffix, suffixes) { + QString pluginFileName = prefix; + + pluginFileName += baseName; + pluginFileName += QLatin1Char('.'); + pluginFileName += suffix; + + QFileInfo fileInfo(dir, pluginFileName); + + if (fileInfo.exists()) + return fileInfo.absoluteFilePath(); + } + + return QString(); +} + +/*! + \internal + + Returns the result of the merge of \a baseName with \a dir and the platform suffix. + + \table + \header \i Platform \i Valid suffixes + \row \i Windows \i \c .dll + \row \i Unix/Linux \i \c .so + \row \i AIX \i \c .a + \row \i HP-UX \i \c .sl, \c .so (HP-UXi) + \row \i Mac OS X \i \c .dylib, \c .bundle, \c .so + \row \i Symbian \i \c .dll + \endtable + + Version number on unix are ignored. +*/ +QString QmlEnginePrivate::resolvePlugin(const QDir &dir, const QString &baseName) +{ +#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) + return resolvePlugin(dir, baseName, QStringList(QLatin1String("dll"))); +#elif defined(Q_OS_SYMBIAN) + return resolvePlugin(dir, baseName, QStringList() << QLatin1String("dll") << QLatin1String("qtplugin")); +#else + +# if defined(Q_OS_DARWIN) + + return resolvePlugin(dir, baseName, QStringList() << QLatin1String("dylib") << QLatin1String("so") << QLatin1String("bundle"), + QLatin1String("lib")); +# else // Generic Unix + QStringList validSuffixList; + +# if defined(Q_OS_HPUX) +/* + See "HP-UX Linker and Libraries User's Guide", section "Link-time Differences between PA-RISC and IPF": + "In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit), + the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix." + */ + validSuffixList << QLatin1String("sl"); +# if defined __ia64 + validSuffixList << QLatin1String("so"); +# endif +# elif defined(Q_OS_AIX) + validSuffixList << QLatin1String("a") << QLatin1String("so"); +# elif defined(Q_OS_UNIX) + validSuffixList << QLatin1String("so"); +# endif + + // Examples of valid library names: + // libfoo.so + + return resolvePlugin(dir, baseName, validSuffixList, QLatin1String("lib")); +# endif + +#endif +} /*! \internal diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index d916286..53a88b1 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -104,6 +104,7 @@ class QmlCleanup; class QmlDelayedError; class QmlWorkerScriptEngine; class QmlGlobalScriptClass; +class QDir; class QmlScriptEngine : public QScriptEngine { @@ -263,6 +264,11 @@ public: QmlImportsPrivate *d; }; + QString resolvePlugin(const QDir &dir, const QString &baseName, + const QStringList &suffixes, + const QString &prefix = QString()); + QString resolvePlugin(const QDir &dir, const QString &baseName); + bool addToImport(Imports*, const QString& qmlDirContent,const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; bool resolveType(const Imports&, const QByteArray& type, -- cgit v0.12 From d43ec1bdb12649c32f0f0067492857a70bef05b4 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 23 Feb 2010 12:45:38 +0100 Subject: More precise compiler errors People were having trouble figureing what was wrong based off the previous error message. This should now be rectified - at least for users who read the docs. Reviewed-by: mae --- src/declarative/qml/qmlcompiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 4508964..4365b17 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1132,10 +1132,10 @@ bool QmlCompiler::buildComponent(QmlParser::Object *obj, Property *idProp = 0; if (obj->properties.count() > 1 || (obj->properties.count() == 1 && obj->properties.begin().key() != "id")) - COMPILE_EXCEPTION(*obj->properties.begin(), QCoreApplication::translate("QmlCompiler","Invalid component specification")); + COMPILE_EXCEPTION(*obj->properties.begin(), QCoreApplication::translate("QmlCompiler","Component elements may not contain properties other than id")); if (!obj->scriptBlockObjects.isEmpty()) - COMPILE_EXCEPTION(obj->scriptBlockObjects.first(), QCoreApplication::translate("QmlCompiler","Invalid component specification")); + COMPILE_EXCEPTION(obj->scriptBlockObjects.first(), QCoreApplication::translate("QmlCompiler","Component elements may not contain script blocks")); if (obj->properties.count()) idProp = *obj->properties.begin(); -- cgit v0.12 From 5eb3c2fc8f90509cb368ab56f14364d6e17844f1 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 23 Feb 2010 12:48:16 +0100 Subject: Look for QML plugins in the paths specified in QML_PLUGIN_PATH env var. --- src/declarative/qml/qmlengine.cpp | 30 +++++++++++++++++++++++++---- src/declarative/qml/qmlengine_p.h | 3 +++ src/declarative/qml/qmlextensioninterface.h | 2 +- src/declarative/qml/qmlextensionplugin.h | 2 +- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 98e16aa..a7c3d08 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -158,6 +158,21 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) } globalClass = new QmlGlobalScriptClass(&scriptEngine); fileImportPath.append(QLibraryInfo::location(QLibraryInfo::DataPath)+QDir::separator()+QLatin1String("qml")); + + // env import paths + QByteArray envImportPath = qgetenv("QML_IMPORT_PATH"); + if (!envImportPath.isEmpty()) { +#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) + QLatin1Char pathSep(';'); +#else + QLatin1Char pathSep(':'); +#endif + foreach (const QString &path, QString::fromLatin1(envImportPath).split(pathSep, QString::SkipEmptyParts)) { + QString canonicalPath = QDir(path).canonicalPath(); + if (!canonicalPath.isEmpty() && !environmentImportPath.contains(canonicalPath)) + environmentImportPath.append(canonicalPath); + } + } } QUrl QmlScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url) @@ -1334,9 +1349,16 @@ public: url.replace(QLatin1Char('.'), QLatin1Char('/')); bool found = false; QString content; - QString dir; - QStringList paths = importPath; - paths.prepend(QFileInfo(base.toLocalFile()).path()); + QString dir; + + // user import paths + QStringList paths; + + // base.. + paths += QFileInfo(base.toLocalFile()).path(); + paths += importPath; + paths += QmlEnginePrivate::get(engine)->environmentImportPath; + foreach (const QString &p, paths) { dir = p+QLatin1Char('/')+url; QFileInfo fi(dir+QLatin1String("/qmldir")); @@ -1575,7 +1597,7 @@ bool QmlEngine::importExtension(const QString &fileName, const QString &uri) QPluginLoader loader(fileName); if (QmlExtensionInterface *iface = qobject_cast(loader.instance())) { - iface->initialize(this, uri); + iface->initialize(this, uri.toUtf8().constData()); return true; } diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 53a88b1..85c5fbe 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -264,6 +264,9 @@ public: QmlImportsPrivate *d; }; + + QStringList environmentImportPath; + QString resolvePlugin(const QDir &dir, const QString &baseName, const QStringList &suffixes, const QString &prefix = QString()); diff --git a/src/declarative/qml/qmlextensioninterface.h b/src/declarative/qml/qmlextensioninterface.h index cbdd34c..b993e82 100644 --- a/src/declarative/qml/qmlextensioninterface.h +++ b/src/declarative/qml/qmlextensioninterface.h @@ -54,7 +54,7 @@ class QmlEngine; struct Q_DECLARATIVE_EXPORT QmlExtensionInterface { - virtual void initialize(QmlEngine *engine, const QString &uri) = 0; + virtual void initialize(QmlEngine *engine, const char *uri) = 0; }; Q_DECLARE_INTERFACE(QmlExtensionInterface, "com.trolltech.Qt.QmlExtensionInterface/1.0") diff --git a/src/declarative/qml/qmlextensionplugin.h b/src/declarative/qml/qmlextensionplugin.h index 82553e7..8cc64ad 100644 --- a/src/declarative/qml/qmlextensionplugin.h +++ b/src/declarative/qml/qmlextensionplugin.h @@ -62,7 +62,7 @@ public: explicit QmlExtensionPlugin(QObject *parent = 0); ~QmlExtensionPlugin(); - virtual void initialize(QmlEngine *engine, const QString &uri) = 0; + virtual void initialize(QmlEngine *engine, const char *uri) = 0; }; QT_END_NAMESPACE -- cgit v0.12 From 743720c2d391f73bc376c337002c15cfa119139b Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Tue, 23 Feb 2010 13:16:52 +0100 Subject: Fixing deployment on Symbian Reviewed-by: TrustMe --- tests/benchmarks/declarative/binding/binding.pro | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/benchmarks/declarative/binding/binding.pro b/tests/benchmarks/declarative/binding/binding.pro index e25f186..aa4cc41 100644 --- a/tests/benchmarks/declarative/binding/binding.pro +++ b/tests/benchmarks/declarative/binding/binding.pro @@ -7,3 +7,9 @@ macx:CONFIG -= app_bundle SOURCES += tst_binding.cpp testtypes.cpp HEADERS += testtypes.h +symbian* { + data.sources = data/* + data.path = data + DEPLOYMENT = data +} + -- cgit v0.12 From fcd4c0dce69e22487d9141f3bf5de6d4c56a3432 Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Tue, 23 Feb 2010 13:32:48 +0100 Subject: Fixing deployment on Symbian platform Reviewed-by: TrustMe --- tests/benchmarks/declarative/creation/creation.pro | 9 +++++++-- tests/benchmarks/declarative/creation/tst_creation.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/benchmarks/declarative/creation/creation.pro b/tests/benchmarks/declarative/creation/creation.pro index fcc2987..3e0caf6 100644 --- a/tests/benchmarks/declarative/creation/creation.pro +++ b/tests/benchmarks/declarative/creation/creation.pro @@ -6,5 +6,10 @@ macx:CONFIG -= app_bundle SOURCES += tst_creation.cpp -DEFINES += SRCDIR=\\\"$$PWD\\\" - +symbian* { + data.sources = data/* + data.path = data + DEPLOYMENT += addFiles +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} \ No newline at end of file diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp index 23c820c..b99031a 100644 --- a/tests/benchmarks/declarative/creation/tst_creation.cpp +++ b/tests/benchmarks/declarative/creation/tst_creation.cpp @@ -49,6 +49,12 @@ #include #include +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +// Application private dir is default serach path for files, so SRCDIR can be set to empty +#define SRCDIR "" +#endif + class tst_creation : public QObject { Q_OBJECT -- cgit v0.12 From 8ad76444ad4589e0b69056cca283253070dae350 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 23 Feb 2010 13:36:36 +0100 Subject: Doc fix Remove stray '>' --- src/declarative/graphicsitems/qmlgraphicsgridview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index bf370ae..ab87c03 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -977,7 +977,7 @@ void QmlGraphicsGridView::setHighlight(QmlComponent *highlight) Component { id: myHighlight Rectangle { - id: wrapper; color: "lightsteelblue"; radius: 4; width: 320; height: 60 > + id: wrapper; color: "lightsteelblue"; radius: 4; width: 320; height: 60 y: SpringFollow { source: Wrapper.GridView.view.currentItem.y; spring: 3; damping: 0.2 } x: SpringFollow { source: Wrapper.GridView.view.currentItem.x; spring: 3; damping: 0.2 } } -- cgit v0.12 From b7dde7fc5df285c919df91daba7f07aef00c11bd Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Tue, 23 Feb 2010 13:46:47 +0100 Subject: Fixing deployment on Symbian Reviewed-by: TrustMe --- tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro b/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro index 6a86f58..a77eebb 100644 --- a/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro +++ b/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro @@ -7,3 +7,13 @@ macx:CONFIG -= app_bundle SOURCES += tst_qmlcomponent.cpp testtypes.cpp HEADERS += testtypes.h +symbian* { + data.sources = data/* + data.path = data + samegame.sources = data/samegame/* + samegame.path = data/samegame + samegame_pics.sources = data/samegame/pics/* + samegame_pics.path = data/samegame/pics + DEPLOYMENT += data samegame samegame_pics +} + -- cgit v0.12 From 9cf177099bfff8a00297f868b912723ca7b9551f Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Tue, 23 Feb 2010 13:58:30 +0100 Subject: Fixing deployment on Symbian Reviewed-by: TrustMe --- .../benchmarks/declarative/qmlgraphicsimage/qmlgraphicsimage.pro | 9 +++++++-- .../declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/benchmarks/declarative/qmlgraphicsimage/qmlgraphicsimage.pro b/tests/benchmarks/declarative/qmlgraphicsimage/qmlgraphicsimage.pro index 449d874..f14931c 100644 --- a/tests/benchmarks/declarative/qmlgraphicsimage/qmlgraphicsimage.pro +++ b/tests/benchmarks/declarative/qmlgraphicsimage/qmlgraphicsimage.pro @@ -7,5 +7,10 @@ CONFIG += release SOURCES += tst_qmlgraphicsimage.cpp -DEFINES += SRCDIR=\\\"$$PWD\\\" - +symbian* { + data.sources = image.png + data.path = . + DEPLOYMENT += data +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} diff --git a/tests/benchmarks/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp b/tests/benchmarks/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp index 7d7d24e..6d1aa0e 100644 --- a/tests/benchmarks/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp +++ b/tests/benchmarks/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp @@ -44,6 +44,12 @@ #include #include +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +// Application private dir is default serach path for files, so SRCDIR can be set to empty +#define SRCDIR "" +#endif + class tst_qmlgraphicsimage : public QObject { Q_OBJECT -- cgit v0.12 From 7f3896f6c0cff6c6ddac1fba480dedbbf78c2df1 Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Tue, 23 Feb 2010 14:07:40 +0100 Subject: Fixing deplyment on Symbian platform Reviewed-by: TrustMe --- tests/benchmarks/declarative/script/script.pro | 11 ++++++++++- tests/benchmarks/declarative/script/tst_script.cpp | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/benchmarks/declarative/script/script.pro b/tests/benchmarks/declarative/script/script.pro index 48fea81..6255acc 100644 --- a/tests/benchmarks/declarative/script/script.pro +++ b/tests/benchmarks/declarative/script/script.pro @@ -7,5 +7,14 @@ CONFIG += release SOURCES += tst_script.cpp -DEFINES += SRCDIR=\\\"$$PWD\\\" +symbian* { + data.sources = data/* + data.path = data + DEPLOYMENT += data +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} + + + diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp index dd21997..15902e4 100644 --- a/tests/benchmarks/declarative/script/tst_script.cpp +++ b/tests/benchmarks/declarative/script/tst_script.cpp @@ -48,6 +48,12 @@ #include #include +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +// Application private dir is default serach path for files, so SRCDIR can be set to empty +#define SRCDIR "." +#endif + class tst_script : public QObject { Q_OBJECT -- cgit v0.12 From 62fc581eb84504d05bca7b70ac3dc912982133d1 Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Tue, 23 Feb 2010 14:12:14 +0100 Subject: Fixing deployment and default values for Symbian Reviewed-by: TrustMe --- tests/benchmarks/declarative/qmltime/qmltime.cpp | 11 +++++++++++ tests/benchmarks/declarative/qmltime/qmltime.pro | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tests/benchmarks/declarative/qmltime/qmltime.cpp b/tests/benchmarks/declarative/qmltime/qmltime.cpp index 2cc5d0d..8e312be 100644 --- a/tests/benchmarks/declarative/qmltime/qmltime.cpp +++ b/tests/benchmarks/declarative/qmltime/qmltime.cpp @@ -183,7 +183,11 @@ int main(int argc, char ** argv) } if (filename.isEmpty()) +#ifdef Q_OS_SYMBIAN + filename = QLatin1String("./tests/item_creation/data.qml"); +#else usage(argv[0]); +#endif QmlEngine engine; QmlComponent component(&engine, filename); @@ -204,6 +208,9 @@ int main(int argc, char ** argv) return -1; } +#ifdef Q_OS_SYMBIAN + willParent = true; +#endif timer->setWillParent(willParent); if (!timer->component()) { @@ -211,6 +218,10 @@ int main(int argc, char ** argv) return -1; } +#ifdef Q_OS_SYMBIAN + iterations = 1024; +#endif + timer->run(iterations); return 0; diff --git a/tests/benchmarks/declarative/qmltime/qmltime.pro b/tests/benchmarks/declarative/qmltime/qmltime.pro index b077d1a..9352f3b 100644 --- a/tests/benchmarks/declarative/qmltime/qmltime.pro +++ b/tests/benchmarks/declarative/qmltime/qmltime.pro @@ -6,3 +6,18 @@ macx:CONFIG -= app_bundle SOURCES += qmltime.cpp +symbian* { + TARGET.CAPABILITY = "All -TCB" + example.sources = example.qml + esample.path = . + tests.sources = tests/* + tests.path = tests + anshors.sources = tests/anchors/* + anchors.path = tests/anchors + item_creation.sources = tests/item_creation/* + item_creation.path = tests/item_creation + positioner_creation.sources = tests/positioner_creation/* + positioner_creation.path = tests/positioner_creation + DEPLOYMENT += example tests anchors item_creation positioner_creation +} + -- cgit v0.12 From 466a3fc2f883344fc383be771e2de9975c98b194 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 23 Feb 2010 14:15:54 +0100 Subject: Fix build on solaris --- src/declarative/qml/qmlworkerscript.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlworkerscript.cpp b/src/declarative/qml/qmlworkerscript.cpp index a2e8c7a..9a48c4f 100644 --- a/src/declarative/qml/qmlworkerscript.cpp +++ b/src/declarative/qml/qmlworkerscript.cpp @@ -169,7 +169,7 @@ private: class QmlWorkerListModelAgent : public QObject { Q_OBJECT - Q_PROPERTY(int count READ count); + Q_PROPERTY(int count READ count) public: QmlWorkerListModelAgent(QmlWorkerListModel *); -- cgit v0.12 From 742befdd5077b27de79ca5ee6f9182540d0d5863 Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Tue, 23 Feb 2010 14:24:44 +0100 Subject: Avoiding PlatSec warnings for Symbian devices Reviewed-by: TrustMe --- tools/qmlviewer/qmlviewer.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro index aba3cf5..2da244c 100644 --- a/tools/qmlviewer/qmlviewer.pro +++ b/tools/qmlviewer/qmlviewer.pro @@ -54,5 +54,5 @@ symbian { TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 HEADERS += $$QT_SOURCE_TREE/examples/network/qftp/sym_iap_util.h LIBS += -lesock -lconnmon -linsock - TARGET.CAPABILITY = NetworkServices + TARGET.CAPABILITY = "All -TCB" } -- cgit v0.12 From 3fb191bbeb0e8a2d49c5107df07c5457872357b3 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 23 Feb 2010 09:46:34 +0100 Subject: Get rid of QmlModulePlugin. --- .../plugins/com/nokia/TimeExample/Clock.qml | 50 ++++++++++ .../plugins/com/nokia/TimeExample/center.png | Bin 0 -> 765 bytes .../plugins/com/nokia/TimeExample/clock.png | Bin 0 -> 20653 bytes .../plugins/com/nokia/TimeExample/hour.png | Bin 0 -> 625 bytes .../plugins/com/nokia/TimeExample/minute.png | Bin 0 -> 625 bytes examples/declarative/plugins/files/Clock.qml | 50 ---------- examples/declarative/plugins/files/center.png | Bin 765 -> 0 bytes examples/declarative/plugins/files/clock.png | Bin 20653 -> 0 bytes examples/declarative/plugins/files/hour.png | Bin 625 -> 0 bytes examples/declarative/plugins/files/minute.png | Bin 625 -> 0 bytes examples/declarative/plugins/plugin.cpp | 14 +-- examples/declarative/plugins/plugins.pro | 13 ++- src/declarative/qml/qml.pri | 2 - src/declarative/qml/qmlengine.cpp | 1 - src/declarative/qml/qmlmoduleplugin.cpp | 111 --------------------- src/declarative/qml/qmlmoduleplugin.h | 86 ---------------- src/multimedia/qml/qml.cpp | 10 +- src/multimedia/qml/qml.h | 4 +- src/plugins/qmlmodules/multimedia/multimedia.cpp | 16 +-- 19 files changed, 79 insertions(+), 278 deletions(-) create mode 100644 examples/declarative/plugins/com/nokia/TimeExample/Clock.qml create mode 100644 examples/declarative/plugins/com/nokia/TimeExample/center.png create mode 100644 examples/declarative/plugins/com/nokia/TimeExample/clock.png create mode 100644 examples/declarative/plugins/com/nokia/TimeExample/hour.png create mode 100644 examples/declarative/plugins/com/nokia/TimeExample/minute.png delete mode 100644 examples/declarative/plugins/files/Clock.qml delete mode 100644 examples/declarative/plugins/files/center.png delete mode 100644 examples/declarative/plugins/files/clock.png delete mode 100644 examples/declarative/plugins/files/hour.png delete mode 100644 examples/declarative/plugins/files/minute.png delete mode 100644 src/declarative/qml/qmlmoduleplugin.cpp delete mode 100644 src/declarative/qml/qmlmoduleplugin.h diff --git a/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml new file mode 100644 index 0000000..01ec686 --- /dev/null +++ b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml @@ -0,0 +1,50 @@ +import Qt 4.6 + +Item { + id: clock + width: 200; height: 200 + + property alias city: cityLabel.text + property var hours + property var minutes + property var shift : 0 + + Image { id: background; source: "clock.png" } + + Image { + x: 92.5; y: 27 + source: "hour.png" + smooth: true + transform: Rotation { + id: hourRotation + origin.x: 7.5; origin.y: 73; angle: 0 + angle: SpringFollow { + spring: 2; damping: 0.2; modulus: 360 + source: (clock.hours * 30) + (clock.minutes * 0.5) + } + } + } + + Image { + x: 93.5; y: 17 + source: "minute.png" + smooth: true + transform: Rotation { + id: minuteRotation + origin.x: 6.5; origin.y: 83; angle: 0 + angle: SpringFollow { + spring: 2; damping: 0.2; modulus: 360 + source: clock.minutes * 6 + } + } + } + + Image { + anchors.centerIn: background; source: "center.png" + } + + Text { + id: cityLabel; font.bold: true; font.pixelSize: 14; y:200; color: "white" + anchors.horizontalCenter: parent.horizontalCenter + } +} diff --git a/examples/declarative/plugins/com/nokia/TimeExample/center.png b/examples/declarative/plugins/com/nokia/TimeExample/center.png new file mode 100644 index 0000000..7fbd802 Binary files /dev/null and b/examples/declarative/plugins/com/nokia/TimeExample/center.png differ diff --git a/examples/declarative/plugins/com/nokia/TimeExample/clock.png b/examples/declarative/plugins/com/nokia/TimeExample/clock.png new file mode 100644 index 0000000..462edac Binary files /dev/null and b/examples/declarative/plugins/com/nokia/TimeExample/clock.png differ diff --git a/examples/declarative/plugins/com/nokia/TimeExample/hour.png b/examples/declarative/plugins/com/nokia/TimeExample/hour.png new file mode 100644 index 0000000..f8061a1 Binary files /dev/null and b/examples/declarative/plugins/com/nokia/TimeExample/hour.png differ diff --git a/examples/declarative/plugins/com/nokia/TimeExample/minute.png b/examples/declarative/plugins/com/nokia/TimeExample/minute.png new file mode 100644 index 0000000..1297ec7 Binary files /dev/null and b/examples/declarative/plugins/com/nokia/TimeExample/minute.png differ diff --git a/examples/declarative/plugins/files/Clock.qml b/examples/declarative/plugins/files/Clock.qml deleted file mode 100644 index 01ec686..0000000 --- a/examples/declarative/plugins/files/Clock.qml +++ /dev/null @@ -1,50 +0,0 @@ -import Qt 4.6 - -Item { - id: clock - width: 200; height: 200 - - property alias city: cityLabel.text - property var hours - property var minutes - property var shift : 0 - - Image { id: background; source: "clock.png" } - - Image { - x: 92.5; y: 27 - source: "hour.png" - smooth: true - transform: Rotation { - id: hourRotation - origin.x: 7.5; origin.y: 73; angle: 0 - angle: SpringFollow { - spring: 2; damping: 0.2; modulus: 360 - source: (clock.hours * 30) + (clock.minutes * 0.5) - } - } - } - - Image { - x: 93.5; y: 17 - source: "minute.png" - smooth: true - transform: Rotation { - id: minuteRotation - origin.x: 6.5; origin.y: 83; angle: 0 - angle: SpringFollow { - spring: 2; damping: 0.2; modulus: 360 - source: clock.minutes * 6 - } - } - } - - Image { - anchors.centerIn: background; source: "center.png" - } - - Text { - id: cityLabel; font.bold: true; font.pixelSize: 14; y:200; color: "white" - anchors.horizontalCenter: parent.horizontalCenter - } -} diff --git a/examples/declarative/plugins/files/center.png b/examples/declarative/plugins/files/center.png deleted file mode 100644 index 7fbd802..0000000 Binary files a/examples/declarative/plugins/files/center.png and /dev/null differ diff --git a/examples/declarative/plugins/files/clock.png b/examples/declarative/plugins/files/clock.png deleted file mode 100644 index 462edac..0000000 Binary files a/examples/declarative/plugins/files/clock.png and /dev/null differ diff --git a/examples/declarative/plugins/files/hour.png b/examples/declarative/plugins/files/hour.png deleted file mode 100644 index f8061a1..0000000 Binary files a/examples/declarative/plugins/files/hour.png and /dev/null differ diff --git a/examples/declarative/plugins/files/minute.png b/examples/declarative/plugins/files/minute.png deleted file mode 100644 index 1297ec7..0000000 Binary files a/examples/declarative/plugins/files/minute.png and /dev/null differ diff --git a/examples/declarative/plugins/plugin.cpp b/examples/declarative/plugins/plugin.cpp index 820d4eb..8e21263 100644 --- a/examples/declarative/plugins/plugin.cpp +++ b/examples/declarative/plugins/plugin.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include +#include #include #include #include @@ -140,19 +140,15 @@ MinuteTimer *Time::timer=0; QML_DECLARE_TYPE(Time); -class QExampleQmlPlugin : public QmlModulePlugin +class QExampleQmlPlugin : public QmlExtensionPlugin { Q_OBJECT public: - QStringList keys() const - { - return QStringList() << QLatin1String("com.nokia.TimeExample"); - } - - void defineModule(const QString& uri) + void initialize(QmlEngine *engine, const char *uri) { + Q_UNUSED(engine); Q_ASSERT(uri == QLatin1String("com.nokia.TimeExample")); - qmlRegisterType