summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRitt Konstantin <ritt.ks@gmail.com>2009-07-06 17:29:07 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-07-06 17:57:09 (GMT)
commit1222ea208587ed039e436d58aa6d7ea6ea6c014e (patch)
tree3113095c15748aa23155065644c02a7d6aabe294 /tools
parente07e95da3d35a2ea1ab2b325df6c91620f948497 (diff)
downloadQt-1222ea208587ed039e436d58aa6d7ea6ea6c014e.zip
Qt-1222ea208587ed039e436d58aa6d7ea6ea6c014e.tar.gz
Qt-1222ea208587ed039e436d58aa6d7ea6ea6c014e.tar.bz2
Update Russian Qt phrase book
Merge-request: 803 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/linguist/phrasebooks/russian.qph52
1 files changed, 42 insertions, 10 deletions
diff --git a/tools/linguist/phrasebooks/russian.qph b/tools/linguist/phrasebooks/russian.qph
index 629c60b..69af041 100644
--- a/tools/linguist/phrasebooks/russian.qph
+++ b/tools/linguist/phrasebooks/russian.qph
@@ -10,7 +10,7 @@
</phrase>
<phrase>
<source>accessibility</source>
- <target>удобство</target>
+ <target>специальные возможности</target>
</phrase>
<phrase>
<source>action handle</source>
@@ -345,8 +345,8 @@
<target>активная зона</target>
</phrase>
<phrase>
- <source>icon</source>
- <target>пиктограмма</target>
+ <source>Icon</source>
+ <target>Значок</target>
</phrase>
<phrase>
<source>inactive</source>
@@ -402,7 +402,7 @@
</phrase>
<phrase>
<source>list view</source>
- <target>древовидный список</target>
+ <target>список</target>
</phrase>
<phrase>
<source>manual link</source>
@@ -901,10 +901,6 @@
<target>панель инструментов</target>
</phrase>
<phrase>
- <source>tooltip</source>
- <target>всплывающая подсказка</target>
-</phrase>
-<phrase>
<source>tree view control</source>
<target>древовидный список</target>
</phrase>
@@ -1054,10 +1050,46 @@
</phrase>
<phrase>
<source>Case Sensitive</source>
- <target>Регистрозависимо</target>
+ <target>Учитывать регистр</target>
</phrase>
<phrase>
<source>Whole words</source>
- <target>Слова полностью</target>
+ <target>Слова целиком</target>
+</phrase>
+<phrase>
+ <source>Find Next</source>
+ <target>Найти следующее</target>
+</phrase>
+<phrase>
+ <source>Find Previous</source>
+ <target>Найти предыдущее</target>
+</phrase>
+<phrase>
+ <source>Case Sensitive</source>
+ <target>Учитывать регистр символов</target>
+</phrase>
+<phrase>
+ <source>Whole words only</source>
+ <target>Только слова целиком</target>
+</phrase>
+<phrase>
+ <source>Subwindow</source>
+ <target>Дочернее окно</target>
+</phrase>
+<phrase>
+ <source>Next</source>
+ <target>Далее</target>
+</phrase>
+<phrase>
+ <source>tree view</source>
+ <target>древовидный список</target>
+</phrase>
+<phrase>
+ <source>ToolTip</source>
+ <target>Подсказка</target>
+</phrase>
+<phrase>
+ <source>Checkable</source>
+ <target>Переключаемое</target>
</phrase>
</QPH>
sage +** 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 1f049c91f91e069a975a72c1087a279d011535a5 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Sun, 21 Feb 2010 19:47:01 +0100 Subject: loopback network example: Make use of bytesToWrite() Reviewed-by: TrustMe --- examples/network/loopback/dialog.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/network/loopback/dialog.cpp b/examples/network/loopback/dialog.cpp index 27cff31..b504e36 100644 --- a/examples/network/loopback/dialog.cpp +++ b/examples/network/loopback/dialog.cpp @@ -44,12 +44,12 @@ #include "dialog.h" -#if !defined(Q_OS_WINCE) +#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) static const int TotalBytes = 50 * 1024 * 1024; #else static const int TotalBytes = 5 * 1024 * 1024; #endif -static const int PayloadSize = 65536; +static const int PayloadSize = 64 * 1024; // 64 KB Dialog::Dialog(QWidget *parent) : QDialog(parent) @@ -130,6 +130,7 @@ void Dialog::acceptConnection() void Dialog::startTransfer() { + // called when the TCP client connected to the loopback server bytesToWrite = TotalBytes - (int)tcpClient.write(QByteArray(PayloadSize, '@')); clientStatusLabel->setText(tr("Connected")); } @@ -155,8 +156,11 @@ void Dialog::updateServerProgress() void Dialog::updateClientProgress(qint64 numBytes) { + // callen when the TCP client has written some bytes bytesWritten += (int)numBytes; - if (bytesToWrite > 0) + + // only write more if not finished and when the Qt write buffer is below a certain size. + if (bytesToWrite > 0 && tcpClient.bytesToWrite() <= 4*PayloadSize) bytesToWrite -= (int)tcpClient.write(QByteArray(qMin(bytesToWrite, PayloadSize), '@')); clientProgressBar->setMaximum(TotalBytes); -- cgit v0.12 From 6f63f4a78090f50f40f2c65af85120a715835dab Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Mon, 22 Feb 2010 13:17:11 +1000 Subject: Fixed shadow builds on Unix. --- qmake/Makefile.unix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index fa98fd6..d4f5849 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -66,7 +66,7 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge CPPFLAGS = -I. -Igenerators -Igenerators/unix -Igenerators/win32 -Igenerators/mac -Igenerators/symbian \ -I$(BUILD_PATH)/include -I$(BUILD_PATH)/include/QtCore \ -I$(BUILD_PATH)/src/corelib/global -I$(BUILD_PATH)/src/corelib/xml \ - -I$(BUILD_PATH)/tools/shared \ + -I$(SOURCE_PATH)/tools/shared \ -DQT_NO_PCRE \ -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_STL \ -- cgit v0.12 From 30ae64eaf42a2d7f80f70fb01c77a6ebcdfd1e98 Mon Sep 17 00:00:00 2001 From: Bill King Date: Mon, 22 Feb 2010 16:17:46 +1000 Subject: Fixes: make check not checking that target is up to date Builds the target executable if needed before running the test LR on BKing's machine. Reviewed-by: Lincoln Ramsay --- mkspecs/features/qttest_p4.prf | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/mkspecs/features/qttest_p4.prf b/mkspecs/features/qttest_p4.prf index e0b22f2..53c0d74 100644 --- a/mkspecs/features/qttest_p4.prf +++ b/mkspecs/features/qttest_p4.prf @@ -20,12 +20,32 @@ check.path = . macx: check.commands += ./$(QMAKE_TARGET).app/Contents/MacOS/$(QMAKE_TARGET) else:unix: check.commands += ./$(QMAKE_TARGET) else:win32: { - CONFIG(debug, debug|release):check.commands += debug\\$(QMAKE_TARGET) - else:check.commands += release\\$(QMAKE_TARGET) + CONFIG(debug, debug|release):check.commands += $(DESTDIR_TARGET) + else:check.commands += $(DESTDIR_TARGET) } embedded: check.commands += -qws QMAKE_EXTRA_TARGETS += check +!debug_and_release|build_pass { + check.depends = $(DESTDIR_TARGET) +} else { + check.CONFIG = recursive + # In debug and release mode, only run the test once. + # Run debug if available, release otherwise. + debug_and_release { + check.target = dummy_check + check.recurse_target = check + debug { + real_check.depends = debug-check + real_check.target = check + QMAKE_EXTRA_TARGETS += real_check + } else { + real_check.depends = release-check + real_check.target = check + QMAKE_EXTRA_TARGETS += real_check + } + } +} target.path += $$[QT_INSTALL_PREFIX]/tests/qt4 INSTALLS += target -- cgit v0.12 From 0a1e2e645bc1952c89d6ef560eccbe68e51f6ca8 Mon Sep 17 00:00:00 2001 From: ninerider Date: Mon, 22 Feb 2010 09:34:19 +0100 Subject: Fixes for the Windows Mobile plattform These fixes mainly concern compiling issues. --- tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp | 2 +- tests/benchmarks/corelib/io/qfileinfo/qfileinfo.pro | 2 +- .../gui/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp | 7 +++++++ .../gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp | 6 ++++++ .../gui/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp | 6 ++++++ .../qfile_vs_qnetworkaccessmanager.pro | 2 +- 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp index b325250..1238804 100644 --- a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp +++ b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp @@ -156,6 +156,7 @@ private slots: } void sizeSpeedWithoutFilterLowLevel() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); #ifdef Q_OS_WIN const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16(); wchar_t appendedPath[MAX_PATH]; @@ -173,7 +174,6 @@ private slots: } FindClose(hSearch); #else - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); DIR *dir = opendir(qPrintable(testdir.absolutePath())); QVERIFY(dir); diff --git a/tests/benchmarks/corelib/io/qfileinfo/qfileinfo.pro b/tests/benchmarks/corelib/io/qfileinfo/qfileinfo.pro index 295cb50..eca619f 100644 --- a/tests/benchmarks/corelib/io/qfileinfo/qfileinfo.pro +++ b/tests/benchmarks/corelib/io/qfileinfo/qfileinfo.pro @@ -1,6 +1,6 @@ load(qttest_p4) TEMPLATE = app -TARGET = qfileinfo +TARGET = tst_qfileinfo DEPENDPATH += . INCLUDEPATH += . diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp index 1028f42..6c4ca08 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp @@ -42,7 +42,14 @@ #include "view.h" #include + +#ifdef Q_WS_WIN +#define CALLGRIND_START_INSTRUMENTATION {} +#define CALLGRIND_STOP_INSTRUMENTATION {} +#else #include "valgrind/callgrind.h" +#endif + #ifndef QT_NO_OPENGL #include #endif diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp index 527713f..63b0da9 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp @@ -39,7 +39,13 @@ ** ****************************************************************************/ #include + +#ifdef Q_WS_WIN +#define CALLGRIND_START_INSTRUMENTATION {} +#define CALLGRIND_STOP_INSTRUMENTATION {} +#else #include "valgrind/callgrind.h" +#endif #ifdef Q_WS_X11 extern void qt_x11_wait_for_window_manager(QWidget *); diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp index 7419206..3f30393 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp @@ -39,7 +39,13 @@ ** ****************************************************************************/ #include + +#ifdef Q_WS_WIN +#define CALLGRIND_START_INSTRUMENTATION {} +#define CALLGRIND_STOP_INSTRUMENTATION {} +#else #include "valgrind/callgrind.h" +#endif class ItemMover : public QObject { diff --git a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro index 99d1935..89f5d31 100644 --- a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro +++ b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro @@ -1,6 +1,6 @@ load(qttest_p4) TEMPLATE = app -TARGET = qfile_vs_qnetworkaccessmanager +TARGET = tst_qfile_vs_qnetworkaccessmanager DEPENDPATH += . INCLUDEPATH += . -- cgit v0.12 From 1eb303d4f14dfcffcca3f11cacca7a73f1e53342 Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Fri, 19 Feb 2010 12:05:44 +0100 Subject: Don't use vgClear() for semi-transparent brushes. If the brush is not totally opaque we should not use vgClear() at this point because vgClear() does not support blending. Instead it writes the values directly into the surface which clobbers any existing content. The bug exhibits itself when a child widget fills itself with any transparent color. Instead of blending with the parent widget's content, it writes the semi-transparent color directly to the surface, overwriting the parent content and leaving the surface in a somewhat undefined state because the alpha channel is not honoured unless Qt::WA_TranslucentBackground is set. Task-number: QTBUG-8007 Reviewed-by: Rhys Weatherley --- src/openvg/qpaintengine_vg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index 6813d2f..da47f06 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -2399,7 +2399,7 @@ void QVGPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) return; // Check to see if we can use vgClear() for faster filling. - if (brush.style() == Qt::SolidPattern && + if (brush.style() == Qt::SolidPattern && brush.isOpaque() && clipTransformIsSimple(d->transform) && d->opacity == 1.0f && clearRect(rect, brush.color())) { return; @@ -2442,7 +2442,7 @@ void QVGPaintEngine::fillRect(const QRectF &rect, const QColor &color) Q_D(QVGPaintEngine); // Check to see if we can use vgClear() for faster filling. - if (clipTransformIsSimple(d->transform) && d->opacity == 1.0f && + if (clipTransformIsSimple(d->transform) && d->opacity == 1.0f && color.alpha() == 255 && clearRect(rect, color)) { return; } -- cgit v0.12 From a8af0c1aba81716bd0f609b1d9afe5c10951b303 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 22 Feb 2010 10:44:32 +0200 Subject: Changed canonical paths to absolute paths in symmake. Canonical paths were resolving to empty if the paths didn't exist, which causes problems for clean platform builds. Using absolute paths instead will generate all required paths. This will cause a minor inconvenience of warnings about some nonexistent paths during makefile generation phase of abld builds, but this is unavoidable. Sbsv2 builds do not display any warnings. Reviewed-by: Janne Anttila --- qmake/generators/symbian/symmake.cpp | 35 +++++++++++++---------------------- qmake/generators/symbian/symmake.h | 2 +- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/qmake/generators/symbian/symmake.cpp b/qmake/generators/symbian/symmake.cpp index a712434..217c1c3 100644 --- a/qmake/generators/symbian/symmake.cpp +++ b/qmake/generators/symbian/symmake.cpp @@ -109,11 +109,13 @@ QString SymbianMakefileGenerator::fixPathForMmp(const QString& origPath, const Q { static QString epocRootStr; if (epocRootStr.isEmpty()) { - QFileInfo efi(epocRoot()); - epocRootStr = efi.canonicalFilePath(); - if (epocRootStr.isEmpty()) { + epocRootStr = epocRoot(); + QFileInfo efi(epocRootStr); + if (!efi.exists() || epocRootStr.isEmpty()) { fprintf(stderr, "Unable to resolve epocRoot '%s' to real dir on current drive, defaulting to '/' for mmp paths\n", qPrintable(epocRoot())); epocRootStr = "/"; + } else { + epocRootStr = efi.absoluteFilePath(); } if (!epocRootStr.endsWith("/")) epocRootStr += "/"; @@ -137,16 +139,8 @@ QString SymbianMakefileGenerator::fixPathForMmp(const QString& origPath, const Q return resultPath; } -QString SymbianMakefileGenerator::canonizePath(const QString& origPath) +QString SymbianMakefileGenerator::absolutizePath(const QString& origPath) { - // Since current path gets appended almost always anyway, use it as default - // for nonexisting paths. - static QString defaultPath; - if (defaultPath.isEmpty()) { - QFileInfo fi("."); - defaultPath = fi.canonicalFilePath(); - } - // Prepend epocroot to any paths beginning with "/epoc32/" QString resultPath = QDir::fromNativeSeparators(origPath); if (resultPath.startsWith("/epoc32/", Qt::CaseInsensitive)) @@ -154,16 +148,13 @@ QString SymbianMakefileGenerator::canonizePath(const QString& origPath) QFileInfo fi(fileInfo(resultPath)); if (fi.isDir()) { - resultPath = fi.canonicalFilePath(); + resultPath = fi.absoluteFilePath(); } else { - resultPath = fi.canonicalPath(); + resultPath = fi.absolutePath(); } resultPath = QDir::cleanPath(resultPath); - if (resultPath.isEmpty()) - resultPath = defaultPath; - return resultPath; } @@ -695,7 +686,7 @@ void SymbianMakefileGenerator::initMmpVariables() srcpaths << project->values("UI_DIR"); QDir current = QDir::current(); - QString canonizedCurrent = canonizePath("."); + QString absolutizedCurrent = absolutizePath("."); for (int j = 0; j < srcpaths.size(); ++j) { QFileInfo fi(fileInfo(srcpaths.at(j))); @@ -703,10 +694,10 @@ void SymbianMakefileGenerator::initMmpVariables() if (fi.suffix().startsWith("c")) { if (fi.filePath().length() > fi.fileName().length()) { appendIfnotExist(srcincpaths, fi.path()); - sources[canonizePath(fi.path())] += fi.fileName(); + sources[absolutizePath(fi.path())] += fi.fileName(); } else { - sources[canonizedCurrent] += fi.fileName(); - appendIfnotExist(srcincpaths, canonizedCurrent); + sources[absolutizedCurrent] += fi.fileName(); + appendIfnotExist(srcincpaths, absolutizedCurrent); } } } @@ -720,7 +711,7 @@ void SymbianMakefileGenerator::initMmpVariables() incpaths << project->values("UI_DIR"); for (int j = 0; j < incpaths.size(); ++j) { - QString includepath = canonizePath(incpaths.at(j)); + QString includepath = absolutizePath(incpaths.at(j)); appendIfnotExist(sysincspaths, includepath); appendAbldTempDirs(sysincspaths, includepath); } diff --git a/qmake/generators/symbian/symmake.h b/qmake/generators/symbian/symmake.h index 77d61da..542284c 100644 --- a/qmake/generators/symbian/symmake.h +++ b/qmake/generators/symbian/symmake.h @@ -84,7 +84,7 @@ protected: void removeSpecialCharacters(QString& str); QString fixPathForMmp(const QString& origPath, const QDir& parentDir); - QString canonizePath(const QString& origPath); + QString absolutizePath(const QString& origPath); virtual bool writeMakefile(QTextStream &t); void generatePkgFile(const QString &iconFile, DeploymentList &depList); -- cgit v0.12 From 561f2a3bf1ec74df87c3cd7c2641d34ce321c842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Mon, 22 Feb 2010 11:40:41 +0100 Subject: Stabilize style sheet benchmarks. --- tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp b/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp index 226b661..d051b12 100644 --- a/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp +++ b/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp @@ -82,6 +82,7 @@ void tst_qstylesheetstyle::empty() { QWidget *w = buildSimpleWidgets(); w->setStyleSheet("/* */"); + QApplication::processEvents(); int i = 0; QBENCHMARK { w->setStyleSheet("/*" + QString::number(i) + "*/"); @@ -94,6 +95,7 @@ void tst_qstylesheetstyle::empty_events() { QWidget *w = buildSimpleWidgets(); w->setStyleSheet("/* */"); + QApplication::processEvents(); int i = 0; QBENCHMARK { w->setStyleSheet("/*" + QString::number(i) + "*/"); @@ -112,6 +114,7 @@ void tst_qstylesheetstyle::simple() { QWidget *w = buildSimpleWidgets(); w->setStyleSheet("/* */"); + QApplication::processEvents(); int i = 0; QBENCHMARK { w->setStyleSheet(QString(simple_css) + "/*" + QString::number(i) + "*/"); @@ -124,6 +127,7 @@ void tst_qstylesheetstyle::simple_events() { QWidget *w = buildSimpleWidgets(); w->setStyleSheet("/* */"); + QApplication::processEvents(); int i = 0; QBENCHMARK { w->setStyleSheet(QString(simple_css) + "/*" + QString::number(i) + "*/"); @@ -175,8 +179,13 @@ void tst_qstylesheetstyle::grid() w->setStyleSheet("/* */"); if(show) { w->show(); + QTest::qWaitForWindowShown(w); + QApplication::flush(); + QApplication::processEvents(); QTest::qWait(30); + QApplication::processEvents(); } + QApplication::processEvents(); int i = 0; QBENCHMARK { w->setStyleSheet(stylesheet + "/*" + QString::number(i) + "*/"); -- 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 0406b2665167d85b3cf348b615a049fb757afa62 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 22 Feb 2010 12:32:58 +0100 Subject: amend the doc, as suggested by rittk Task-number: QTBUG-8070 --- src/corelib/io/qdatastream.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp index f27ecc1..0b98e1e 100644 --- a/src/corelib/io/qdatastream.cpp +++ b/src/corelib/io/qdatastream.cpp @@ -158,10 +158,9 @@ QT_BEGIN_NAMESPACE \section1 Reading and writing Qt collection classes - The Qt collection classes can also be serialized to a QDataStream. + The Qt container classes can also be serialized to a QDataStream. These include QList, QLinkedList, QVector, QSet, QHash, and QMap. - These classes have have stream operators declared as non-member of - the class. + The stream operators are declared as non-members of the classes. \target Serializing Qt Classes \section1 Reading and writing other Qt classes. -- cgit v0.12 From 4f2d34ed13bd63413e726229fd50c4b33f2d0127 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 22 Feb 2010 12:36:30 +0100 Subject: Port http example to QNetworkAccessManager QHttp. Must. Die. Reviewed-by: Peter Hartmann --- examples/network/http/httpwindow.cpp | 129 ++++++++++++++++++----------------- examples/network/http/httpwindow.h | 23 ++++--- examples/network/http/main.cpp | 1 - 3 files changed, 82 insertions(+), 71 deletions(-) diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp index 95fc82f..ec7cd33 100644 --- a/examples/network/http/httpwindow.cpp +++ b/examples/network/http/httpwindow.cpp @@ -49,9 +49,9 @@ HttpWindow::HttpWindow(QWidget *parent) : QDialog(parent) { #ifndef QT_NO_OPENSSL - urlLineEdit = new QLineEdit("https://"); + urlLineEdit = new QLineEdit("https://qt.nokia.com/"); #else - urlLineEdit = new QLineEdit("http://"); + urlLineEdit = new QLineEdit("http://qt.nokia.com/"); #endif urlLabel = new QLabel(tr("&URL:")); @@ -70,21 +70,14 @@ HttpWindow::HttpWindow(QWidget *parent) progressDialog = new QProgressDialog(this); - http = new QHttp(this); - connect(urlLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableDownloadButton())); - connect(http, SIGNAL(requestFinished(int,bool)), - this, SLOT(httpRequestFinished(int,bool))); - connect(http, SIGNAL(dataReadProgress(int,int)), - this, SLOT(updateDataReadProgress(int,int))); - connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), - this, SLOT(readResponseHeader(QHttpResponseHeader))); - connect(http, SIGNAL(authenticationRequired(QString,quint16,QAuthenticator*)), - this, SLOT(slotAuthenticationRequired(QString,quint16,QAuthenticator*))); + + connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*))); #ifndef QT_NO_OPENSSL - connect(http, SIGNAL(sslErrors(QList)), - this, SLOT(sslErrors(QList))); + connect(&qnam, SIGNAL(sslErrors(QNetworkReply*,QList)), + this, SLOT(sslErrors(QNetworkReply*,QList))); #endif connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile())); @@ -104,9 +97,21 @@ HttpWindow::HttpWindow(QWidget *parent) urlLineEdit->setFocus(); } +void HttpWindow::startRequest(QUrl url) +{ + reply = qnam.get(QNetworkRequest(url)); + connect(reply, SIGNAL(finished()), + this, SLOT(httpFinished())); + connect(reply, SIGNAL(readyRead()), + this, SLOT(httpReadyRead())); + connect(reply, SIGNAL(downloadProgress(qint64,qint64)), + this, SLOT(updateDataReadProgress(qint64,qint64))); +} + void HttpWindow::downloadFile() { - QUrl url(urlLineEdit->text()); + url = urlLineEdit->text(); + QFileInfo fileInfo(url.path()); QString fileName = fileInfo.fileName(); if (fileName.isEmpty()) @@ -132,35 +137,26 @@ void HttpWindow::downloadFile() return; } - QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp; - http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port()); - - if (!url.userName().isEmpty()) - http->setUser(url.userName(), url.password()); - - httpRequestAborted = false; - QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/"); - if (path.isEmpty()) - path = "/"; - httpGetId = http->get(path, file); progressDialog->setWindowTitle(tr("HTTP")); progressDialog->setLabelText(tr("Downloading %1.").arg(fileName)); downloadButton->setEnabled(false); + + // schedule the request + httpRequestAborted = false; + startRequest(url); } void HttpWindow::cancelDownload() { statusLabel->setText(tr("Download canceled.")); httpRequestAborted = true; - http->abort(); + reply->abort(); downloadButton->setEnabled(true); } -void HttpWindow::httpRequestFinished(int requestId, bool error) +void HttpWindow::httpFinished() { - if (requestId != httpGetId) - return; if (httpRequestAborted) { if (file) { file->close(); @@ -168,54 +164,58 @@ void HttpWindow::httpRequestFinished(int requestId, bool error) delete file; file = 0; } - + reply->deleteLater(); progressDialog->hide(); return; } - if (requestId != httpGetId) - return; - progressDialog->hide(); + file->flush(); file->close(); - if (error) { + + QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (reply->error()) { file->remove(); QMessageBox::information(this, tr("HTTP"), tr("Download failed: %1.") - .arg(http->errorString())); + .arg(reply->errorString())); + downloadButton->setEnabled(true); + } else if (!redirectionTarget.isNull()) { + QUrl newUrl = url.resolved(redirectionTarget.toUrl()); + if (QMessageBox::question(this, tr("HTTP"), + tr("Redirect to %1 ?").arg(newUrl.toString()), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + url = newUrl; + reply->deleteLater(); + file->open(QIODevice::WriteOnly); + file->resize(0); + startRequest(url); + return; + } } else { QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName(); statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName)); + downloadButton->setEnabled(true); } - downloadButton->setEnabled(true); + reply->deleteLater(); + reply = 0; delete file; file = 0; } -void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader) +void HttpWindow::httpReadyRead() { - switch (responseHeader.statusCode()) { - case 200: // Ok - case 301: // Moved Permanently - case 302: // Found - case 303: // See Other - case 307: // Temporary Redirect - // these are not error conditions - break; - - default: - QMessageBox::information(this, tr("HTTP"), - tr("Download failed: %1.") - .arg(responseHeader.reasonPhrase())); - httpRequestAborted = true; - progressDialog->hide(); - http->abort(); - } + // this slot gets called everytime the QNetworkReply has new data. + // We read all of its new data and write it into the file. + // That way we use less RAM than when reading it at the finished() + // signal of the QNetworkReply + if (file) + file->write(reply->readAll()); } -void HttpWindow::updateDataReadProgress(int bytesRead, int totalBytes) +void HttpWindow::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes) { if (httpRequestAborted) return; @@ -229,14 +229,19 @@ void HttpWindow::enableDownloadButton() downloadButton->setEnabled(!urlLineEdit->text().isEmpty()); } -void HttpWindow::slotAuthenticationRequired(const QString &hostName, quint16, QAuthenticator *authenticator) +void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authenticator) { QDialog dlg; Ui::Dialog ui; ui.setupUi(&dlg); dlg.adjustSize(); - ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(hostName)); - + ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host())); + + // Did the URL have information? Fill the UI + // This is only relevant if the URL-supplied credentials were wrong + ui.userEdit->setText(url.userName()); + ui.passwordEdit->setText(url.password()); + if (dlg.exec() == QDialog::Accepted) { authenticator->setUser(ui.userEdit->text()); authenticator->setPassword(ui.passwordEdit->text()); @@ -244,7 +249,7 @@ void HttpWindow::slotAuthenticationRequired(const QString &hostName, quint16, QA } #ifndef QT_NO_OPENSSL -void HttpWindow::sslErrors(const QList &errors) +void HttpWindow::sslErrors(QNetworkReply*,const QList &errors) { QString errorString; foreach (const QSslError &error, errors) { @@ -253,10 +258,10 @@ void HttpWindow::sslErrors(const QList &errors) errorString += error.errorString(); } - if (QMessageBox::warning(this, tr("HTTP Example"), + if (QMessageBox::warning(this, tr("HTTP"), tr("One or more SSL errors has occurred: %1").arg(errorString), QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) { - http->ignoreSslErrors(); + reply->ignoreSslErrors(); } } #endif diff --git a/examples/network/http/httpwindow.h b/examples/network/http/httpwindow.h index 9dca8a5..83898af 100644 --- a/examples/network/http/httpwindow.h +++ b/examples/network/http/httpwindow.h @@ -43,18 +43,21 @@ #define HTTPWINDOW_H #include +#include +#include QT_BEGIN_NAMESPACE class QDialogButtonBox; class QFile; -class QHttp; -class QHttpResponseHeader; class QLabel; class QLineEdit; class QProgressDialog; class QPushButton; class QSslError; class QAuthenticator; +class QNetworkReply; + + QT_END_NAMESPACE class HttpWindow : public QDialog @@ -64,16 +67,18 @@ class HttpWindow : public QDialog public: HttpWindow(QWidget *parent = 0); + void startRequest(QUrl url); + private slots: void downloadFile(); void cancelDownload(); - void httpRequestFinished(int requestId, bool error); - void readResponseHeader(const QHttpResponseHeader &responseHeader); - void updateDataReadProgress(int bytesRead, int totalBytes); + void httpFinished(); + void httpReadyRead(); + void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes); void enableDownloadButton(); - void slotAuthenticationRequired(const QString &, quint16, QAuthenticator *); + void slotAuthenticationRequired(QNetworkReply*,QAuthenticator *); #ifndef QT_NO_OPENSSL - void sslErrors(const QList &errors); + void sslErrors(QNetworkReply*,const QList &errors); #endif private: @@ -85,7 +90,9 @@ private: QPushButton *quitButton; QDialogButtonBox *buttonBox; - QHttp *http; + QUrl url; + QNetworkAccessManager qnam; + QNetworkReply *reply; QFile *file; int httpGetId; bool httpRequestAborted; diff --git a/examples/network/http/main.cpp b/examples/network/http/main.cpp index ecbe100..817b2be 100644 --- a/examples/network/http/main.cpp +++ b/examples/network/http/main.cpp @@ -46,7 +46,6 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - qWarning("The usage of QHttp is not recommended anymore, please use QNetworkAccessManager."); HttpWindow httpWin; httpWin.show(); return httpWin.exec(); -- cgit v0.12 From 5e95e1bb510d24b9b7889191144a4842fd8569c1 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 22 Feb 2010 12:43:57 +0100 Subject: QNetworkRequest: Doc enhancement Reviewed-by: David Boddie --- src/network/access/qnetworkrequest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index a2bef67..c4ff24d 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -138,6 +138,8 @@ QT_BEGIN_NAMESPACE default follow redirections: it's up to the application to determine if the requested redirection should be allowed, according to its security policies. + The returned URL might be relative. Use QUrl::resolved() + to create an absolute URL out of it. \value ConnectionEncryptedAttribute Replies only, type: QVariant::Bool (default: false) -- cgit v0.12 From bab18de3932a802568d6d9e0cea9e76f02e6bf5d Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 22 Feb 2010 12:53:50 +0100 Subject: fix crash on Windows CE on WM_SETTINGCHANGE On Windows CE, lParam parameter is a constant, not a char pointer. The only valid value is INI_INTL. Task-number: QTBUG-7943 Reviewed-by: ninerider --- src/gui/kernel/qapplication_win.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index 0a4869b..aac834d 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -1905,8 +1905,13 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam break; if (!msg.wParam) { +#ifdef Q_WS_WINCE + // On Windows CE, lParam parameter is a constant, not a char pointer. + if (msg.lParam == INI_INTL) { +#else QString area = QString::fromWCharArray((wchar_t*)msg.lParam); if (area == QLatin1String("intl")) { +#endif QLocalePrivate::updateSystemPrivate(); if (!widget->testAttribute(Qt::WA_SetLocale)) widget->dptr()->setLocale_helper(QLocale(), true); -- cgit v0.12 From 93ba9e3bc2bb4879d6b35b98d7d16c19f7c8221f Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 22 Feb 2010 13:39:40 +0100 Subject: Stylesheet: Fix size specified in QToolbar::handle Regression since f0243e70e05a3368582fd0478d840096d6b60c3f We added a new rule (SE_ToolBarHandle) and the baseStyle was calling pixelMetric(PM_ToolBarHandleExtent) on itself, bypassing the QStyleSheetStyle Reviewed-by: Thierry Task-number: QTBUG-8348 --- src/gui/styles/qstylesheetstyle.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index b36294a..c550938 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -5743,6 +5743,13 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c return positionRect(w, subRule, subRule2, pe, opt->rect, opt->direction); } +#ifndef QT_NO_TOOLBAR + case SE_ToolBarHandle: + if (hasStyleRule(w, PseudoElement_ToolBarHandle)) + return ParentStyle::subElementRect(se, opt, w); + break; +#endif //QT_NO_TOOLBAR + default: break; } -- 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 d9838f300b652fe58c8c5af7097b236d93eb9725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Mon, 22 Feb 2010 14:33:19 +0100 Subject: Stabilize QWidget benchmarks. This commit also removes the complexToplevelResize test; it is not suitable for automated testing as the output is too unstable. --- .../benchmarks/gui/kernel/qwidget/tst_qwidget.cpp | 297 ++++++++------------- 1 file changed, 110 insertions(+), 187 deletions(-) diff --git a/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp b/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp index f21bd44..8c30be4 100644 --- a/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp +++ b/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp @@ -42,33 +42,35 @@ #include #include -class tst_QWidget : public QObject +static void processEvents() { - Q_OBJECT - - -private slots: - void update_data(); - void updateOpaque_data(); - void updateOpaque(); - void updateTransparent_data(); - void updateTransparent(); - void updatePartial_data(); - void updatePartial(); - void updateComplex_data(); - void updateComplex(); - - void complexToplevelResize(); -}; + QApplication::flush(); + QApplication::processEvents(); + QApplication::processEvents(); +} class UpdateWidget : public QWidget { public: - UpdateWidget(int rows, int columns) : QWidget(0) + UpdateWidget(int rows, int columns) + : QWidget(0), rowCount(0), columnCount(0), opaqueChildren(false) { + fill(rows, columns); + } + + UpdateWidget(QWidget *parent = 0) + : QWidget(parent), rowCount(0), columnCount(0), opaqueChildren(false) {} + + void fill(int rows, int columns) + { + if (rows == rowCount && columns == columnCount) + return; + delete layout(); QGridLayout *layout = new QGridLayout; - for (int row = 0; row < rows; ++row) { - for (int column = 0; column < columns; ++column) { + rowCount = rows; + columnCount = columns; + for (int row = 0; row < rowCount; ++row) { + for (int column = 0; column < columnCount; ++column) { UpdateWidget *widget = new UpdateWidget; widget->setFixedSize(20, 20); layout->addWidget(widget, row, column); @@ -76,9 +78,20 @@ public: } } setLayout(layout); + adjustSize(); + QTest::qWait(250); + processEvents(); } - UpdateWidget(QWidget *parent = 0) : QWidget(parent) {} + void setOpaqueChildren(bool enable) + { + if (opaqueChildren != enable) { + foreach (QWidget *w, children) + w->setAttribute(Qt::WA_OpaquePaintEvent, enable); + opaqueChildren = enable; + processEvents(); + } + } void paintEvent(QPaintEvent *) { @@ -93,75 +106,86 @@ public: QRegion updateRegion; QList children; + int rowCount; + int columnCount; + bool opaqueChildren; }; -void tst_QWidget::update_data() +class tst_QWidget : public QObject { - QTest::addColumn("rows"); - QTest::addColumn("columns"); - QTest::addColumn("numUpdates"); - - QTest::newRow("10x10x1") << 10 << 10 << 1; - QTest::newRow("10x10x10") << 10 << 10 << 10; - QTest::newRow("25x25x1") << 25 << 25 << 1; - QTest::newRow("25x25x10") << 25 << 25 << 10; - QTest::newRow("25x25x100") << 25 << 25 << 100; -} + Q_OBJECT -void tst_QWidget::updateOpaque_data() -{ - update_data(); -} +public slots: + void initTestCase(); + void init(); -void tst_QWidget::updateOpaque() -{ - QFETCH(int, rows); - QFETCH(int, columns); - QFETCH(int, numUpdates); +private slots: + void update_data(); + void update(); + void updatePartial_data(); + void updatePartial(); + void updateComplex_data(); + void updateComplex(); - UpdateWidget widget(rows, columns); - foreach (QWidget *w, widget.children) { - w->setAttribute(Qt::WA_OpaquePaintEvent); - } +private: + UpdateWidget widget; +}; +void tst_QWidget::initTestCase() +{ widget.show(); - QApplication::processEvents(); + QTest::qWaitForWindowShown(&widget); + QTest::qWait(300); + processEvents(); +} - int i = 0; - const int n = widget.children.size(); - QBENCHMARK { - for (int j = 0; j < numUpdates; ++j) { - widget.children[i]->update(); - QApplication::processEvents(); - i = (i + 1) % n; - } - } +void tst_QWidget::init() +{ + QVERIFY(widget.isVisible()); + for (int i = 0; i < 3; ++i) + processEvents(); } -void tst_QWidget::updateTransparent_data() +void tst_QWidget::update_data() { - update_data(); + QTest::addColumn("rows"); + QTest::addColumn("columns"); + QTest::addColumn("numUpdates"); + QTest::addColumn("opaque"); + + QTest::newRow("10x10x1 transparent") << 10 << 10 << 1 << false; + QTest::newRow("10x10x10 transparent") << 10 << 10 << 10 << false; + QTest::newRow("10x10x100 transparent") << 10 << 10 << 100 << false; + QTest::newRow("10x10x1 opaque") << 10 << 10 << 1 << true; + QTest::newRow("10x10x10 opaque") << 10 << 10 << 10 << true; + QTest::newRow("10x10x100 opaque") << 10 << 10 << 100 << true; + QTest::newRow("25x25x1 transparent ") << 25 << 25 << 1 << false; + QTest::newRow("25x25x10 transparent") << 25 << 25 << 10 << false; + QTest::newRow("25x25x100 transparent") << 25 << 25 << 100 << false; + QTest::newRow("25x25x1 opaque") << 25 << 25 << 1 << true; + QTest::newRow("25x25x10 opaque") << 25 << 25 << 10 << true; + QTest::newRow("25x25x100 opaque") << 25 << 25 << 100 << true; } -void tst_QWidget::updateTransparent() +void tst_QWidget::update() { QFETCH(int, rows); QFETCH(int, columns); QFETCH(int, numUpdates); + QFETCH(bool, opaque); - UpdateWidget widget(rows, columns); - widget.show(); - QApplication::processEvents(); + widget.fill(rows, columns); + widget.setOpaqueChildren(opaque); - int i = 0; - const int n = widget.children.size(); QBENCHMARK { - for (int j = 0; j < numUpdates; ++j) { - widget.children[i]->update(); + for (int i = 0; i < widget.children.size(); ++i) { + for (int j = 0; j < numUpdates; ++j) + widget.children.at(i)->update(); QApplication::processEvents(); - i = (i + 1) % n; } } + + QApplication::flush(); } void tst_QWidget::updatePartial_data() @@ -174,24 +198,23 @@ void tst_QWidget::updatePartial() QFETCH(int, rows); QFETCH(int, columns); QFETCH(int, numUpdates); + QFETCH(bool, opaque); - UpdateWidget widget(rows, columns); - widget.show(); - QApplication::processEvents(); + widget.fill(rows, columns); + widget.setOpaqueChildren(opaque); - int i = 0; - const int n = widget.children.size(); QBENCHMARK { - for (int j = 0; j < numUpdates; ++j) { + for (int i = 0; i < widget.children.size(); ++i) { QWidget *w = widget.children[i]; const int x = w->width() / 2; const int y = w->height() / 2; - w->update(0, 0, x, y); - w->update(x, 0, x, y); - w->update(0, y, x, y); - w->update(x, y, x, y); + for (int j = 0; j < numUpdates; ++j) { + w->update(0, 0, x, y); + w->update(x, 0, x, y); + w->update(0, y, x, y); + w->update(x, y, x, y); + } QApplication::processEvents(); - i = (i + 1) % n; } } } @@ -206,127 +229,27 @@ void tst_QWidget::updateComplex() QFETCH(int, rows); QFETCH(int, columns); QFETCH(int, numUpdates); + QFETCH(bool, opaque); - UpdateWidget widget(rows, columns); - widget.show(); - QApplication::processEvents(); + widget.fill(rows, columns); + widget.setOpaqueChildren(opaque); - int i = 0; - const int n = widget.children.size(); QBENCHMARK { - for (int j = 0; j < numUpdates; ++j) { + for (int i = 0; i < widget.children.size(); ++i) { QWidget *w = widget.children[i]; const int x = w->width() / 2; const int y = w->height() / 2; - w->update(QRegion(0, 0, x, y, QRegion::Ellipse)); - w->update(QRegion(x, y, x, y, QRegion::Ellipse)); + QRegion r1(0, 0, x, y, QRegion::Ellipse); + QRegion r2(x, y, x, y, QRegion::Ellipse); + for (int j = 0; j < numUpdates; ++j) { + w->update(r1); + w->update(r2); + } QApplication::processEvents(); - i = (i + 1) % n; } } } -class ResizeWidget : public QWidget -{ -public: - ResizeWidget(); -}; - -ResizeWidget::ResizeWidget() : QWidget(0) -{ - QBoxLayout *topLayout = new QVBoxLayout; - - QMenuBar *menubar = new QMenuBar; - QMenu* popup = menubar->addMenu("&File"); - popup->addAction("&Quit", qApp, SLOT(quit())); - topLayout->setMenuBar(menubar); - - QBoxLayout *buttons = new QHBoxLayout; - buttons->setMargin(5); - buttons->addStretch(10); - for (int i = 1; i <= 4; i++ ) { - QPushButton* button = new QPushButton; - button->setText(QString("Button %1").arg(i)); - buttons->addWidget(button); - } - topLayout->addLayout(buttons); - - buttons = new QHBoxLayout; - buttons->addStretch(10); - for (int i = 11; i <= 16; i++) { - QPushButton* button = new QPushButton; - button->setText(QString("Button %1").arg(i)); - buttons->addWidget(button); - } - topLayout->addLayout(buttons); - - QBoxLayout *buttons2 = new QHBoxLayout; - buttons2->addStretch(10); - topLayout->addLayout(buttons2); - - QPushButton *button = new QPushButton; - button->setText("Button five"); - buttons2->addWidget(button); - - button = new QPushButton; - button->setText("Button 6"); - buttons2->addWidget(button); - - QTextEdit *bigWidget = new QTextEdit; - bigWidget->setText("This widget will get all the remaining space"); - bigWidget->setFrameStyle(QFrame::Panel | QFrame::Plain); - topLayout->addWidget(bigWidget); - - const int numRows = 6; - const int labelCol = 0; - const int linedCol = 1; - const int multiCol = 2; - - QGridLayout *grid = new QGridLayout; - for (int row = 0; row < numRows; row++) { - QLineEdit *lineEdit = new QLineEdit; - grid->addWidget(lineEdit, row, linedCol); - QLabel *label = new QLabel(QString("Line &%1").arg(row + 1)); - grid->addWidget(label, row, labelCol); - } - topLayout->addLayout(grid); - - QTextEdit *multiLineEdit = new QTextEdit; - grid->addWidget(multiLineEdit, 0, labelCol + 1, multiCol, multiCol); - - grid->setColumnStretch(linedCol, 10); - grid->setColumnStretch(multiCol, 20); - - QLabel* statusBar = new QLabel; - statusBar->setText("Let's pretend this is a status bar"); - statusBar->setFrameStyle(QFrame::Panel | QFrame::Sunken); - statusBar->setFixedHeight(statusBar->sizeHint().height()); - statusBar->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); - topLayout->addWidget(statusBar); - - topLayout->activate(); - setLayout(topLayout); -} - -void tst_QWidget::complexToplevelResize() -{ - ResizeWidget w; - w.show(); - - QApplication::processEvents(); - - const int minSize = 100; - const int maxSize = 800; - int size = minSize; - - QBENCHMARK { - w.resize(size, size); - size = qMax(minSize, (size + 10) % maxSize); - QApplication::processEvents(); - QApplication::processEvents(); - } -} - QTEST_MAIN(tst_QWidget) #include "tst_qwidget.moc" -- cgit v0.12 From 976a2b6ad1f95175d8d0be2d1eb7603cf4e4026a Mon Sep 17 00:00:00 2001 From: Carlos Manuel Duclos Vergara Date: Mon, 22 Feb 2010 14:58:41 +0100 Subject: QFontDialog::exec() never returns on OSX The problem is the fact that this dialog is never meant to be used this way. Instead it should be called through the static function ::getFont(...). I reimplemented this code path and made sure that this works. Task-number: QTBUG-7769 Reviewed-by: Richard Moe Gustavsen --- src/gui/dialogs/qfontdialog.cpp | 58 ++++++++------- src/gui/dialogs/qfontdialog.h | 3 + src/gui/dialogs/qfontdialog_mac.mm | 148 ++++++++++++++++++++++++++++++++++++- src/gui/dialogs/qfontdialog_p.h | 6 ++ 4 files changed, 188 insertions(+), 27 deletions(-) diff --git a/src/gui/dialogs/qfontdialog.cpp b/src/gui/dialogs/qfontdialog.cpp index 56580a9..4358313 100644 --- a/src/gui/dialogs/qfontdialog.cpp +++ b/src/gui/dialogs/qfontdialog.cpp @@ -989,33 +989,23 @@ void QFontDialog::open(QObject *receiver, const char *member) void QFontDialog::setVisible(bool visible) { Q_D(QFontDialog); - if (visible) - d->selectedFont = QFont(); - -#if defined(Q_WS_MAC) - bool isCurrentlyVisible = (isVisible() || d->delegate); - - if (!visible == !isCurrentlyVisible) - return; - if (visible) { - if (!(d->opts & DontUseNativeDialog) && QFontDialogPrivate::sharedFontPanelAvailable) { - d->delegate = QFontDialogPrivate::openCocoaFontPanel( - currentFont(), parentWidget(), windowTitle(), options(), d); - QFontDialogPrivate::sharedFontPanelAvailable = false; + if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) return; - } + } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) + return; - setWindowFlags(windowModality() == Qt::WindowModal ? Qt::Sheet : DefaultWindowFlags); - } else { - if (d->delegate) { - QFontDialogPrivate::closeCocoaFontPanel(d->delegate); - d->delegate = 0; - QFontDialogPrivate::sharedFontPanelAvailable = true; - return; + if (d->canBeNativeDialog()){ + if (d->setVisible_sys(visible)){ + d->nativeDialogInUse = true; + // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below + // updates the state correctly, but skips showing the non-native version: + setAttribute(Qt::WA_DontShowOnScreen, true); + } else { + d->nativeDialogInUse = false; + setAttribute(Qt::WA_DontShowOnScreen, false); } } -#endif QDialog::setVisible(visible); } @@ -1032,11 +1022,14 @@ void QFontDialog::done(int result) Q_D(QFontDialog); QDialog::done(result); if (result == Accepted) { - d->selectedFont = currentFont(); + // We check if this is the same font we had before, if so we emit currentFontChanged + QFont selectedFont = currentFont(); + if(selectedFont != d->selectedFont) + emit(currentFontChanged(selectedFont)); + d->selectedFont = selectedFont; emit fontSelected(d->selectedFont); - } else { + } else d->selectedFont = QFont(); - } if (d->receiverToDisconnectOnClose) { disconnect(this, SIGNAL(fontSelected(QFont)), d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); @@ -1045,6 +1038,21 @@ void QFontDialog::done(int result) d->memberToDisconnectOnClose.clear(); } +bool QFontDialogPrivate::canBeNativeDialog() +{ + Q_Q(QFontDialog); + if (nativeDialogInUse) + return true; + if (q->testAttribute(Qt::WA_DontShowOnScreen)) + return false; + if (opts & QFontDialog::DontUseNativeDialog) + return false; + + QLatin1String staticName(QFontDialog::staticMetaObject.className()); + QLatin1String dynamicName(q->metaObject()->className()); + return (staticName == dynamicName); +} + /*! \fn QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget* parent, const char* name) \since 4.5 diff --git a/src/gui/dialogs/qfontdialog.h b/src/gui/dialogs/qfontdialog.h index e6f209e..6035a3a 100644 --- a/src/gui/dialogs/qfontdialog.h +++ b/src/gui/dialogs/qfontdialog.h @@ -131,6 +131,9 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_styleHighlighted(int)) Q_PRIVATE_SLOT(d_func(), void _q_sizeHighlighted(int)) Q_PRIVATE_SLOT(d_func(), void _q_updateSample()) +#if defined(Q_WS_MAC) + Q_PRIVATE_SLOT(d_func(), void _q_macRunNativeAppModalPanel()) +#endif }; Q_DECLARE_OPERATORS_FOR_FLAGS(QFontDialog::FontDialogOptions) diff --git a/src/gui/dialogs/qfontdialog_mac.mm b/src/gui/dialogs/qfontdialog_mac.mm index 68f5f00..67d32b8 100644 --- a/src/gui/dialogs/qfontdialog_mac.mm +++ b/src/gui/dialogs/qfontdialog_mac.mm @@ -49,6 +49,7 @@ #include #include #include +#include #include #import #import @@ -372,7 +373,12 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) [NSApp endModalSession:mModalSession]; mModalSession = 0; } - + // Hack alert! + // Since this code path was never intended to be followed when starting from exec + // we need to force the dialog to communicate the new font, otherwise the signal + // won't get emitted. + if(code == NSOKButton) + mPriv->sampleEdit->setFont([self qtFont]); mPriv->done((code == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); } else { [NSApp stopModalWithCode:code]; @@ -567,7 +573,6 @@ void *QFontDialogPrivate::openCocoaFontPanel(const QFont &initial, [ourPanel makeKeyAndOrderFront:ourPanel]; } } - return delegate; } @@ -640,6 +645,145 @@ void QFontDialogPrivate::setFont(void *delegate, const QFont &font) [static_cast(delegate) setQtFont:font]; } +void *QFontDialogPrivate::_q_constructNativePanel() +{ + QMacCocoaAutoReleasePool pool; + + bool sharedFontPanelExisted = [NSFontPanel sharedFontPanelExists]; + NSFontPanel *sharedFontPanel = [NSFontPanel sharedFontPanel]; + [sharedFontPanel setHidesOnDeactivate:false]; + + // hack to ensure that QCocoaApplication's validModesForFontPanel: + // implementation is honored + if (!sharedFontPanelExisted) { + [sharedFontPanel makeKeyAndOrderFront:sharedFontPanel]; + [sharedFontPanel close]; + } + + NSPanel *ourPanel = 0; + NSView *stolenContentView = 0; + NSButton *okButton = 0; + NSButton *cancelButton = 0; + + CGFloat dialogExtraWidth = 0.0; + CGFloat dialogExtraHeight = 0.0; + + // compute dialogExtra{Width,Height} + dialogExtraWidth = 2.0 * DialogSideMargin; + dialogExtraHeight = DialogTopMargin + ButtonTopMargin + ButtonMinHeight + + ButtonBottomMargin; + + // compute initial contents rectangle + NSRect contentRect = [sharedFontPanel contentRectForFrameRect:[sharedFontPanel frame]]; + contentRect.size.width += dialogExtraWidth; + contentRect.size.height += dialogExtraHeight; + + // create the new panel + ourPanel = [[NSPanel alloc] initWithContentRect:contentRect + styleMask:StyleMask + backing:NSBackingStoreBuffered + defer:YES]; + [ourPanel setReleasedWhenClosed:YES]; + + stolenContentView = [sharedFontPanel contentView]; + + // steal the font panel's contents view + [stolenContentView retain]; + [sharedFontPanel setContentView:0]; + + { + // create a new content view and add the stolen one as a subview + NSRect frameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } }; + NSView *ourContentView = [[NSView alloc] initWithFrame:frameRect]; + [ourContentView addSubview:stolenContentView]; + + // create OK and Cancel buttons and add these as subviews + okButton = macCreateButton("&OK", ourContentView); + cancelButton = macCreateButton("Cancel", ourContentView); + + [ourPanel setContentView:ourContentView]; + [ourPanel setDefaultButtonCell:[okButton cell]]; + } + // create a delegate and set it + QCocoaFontPanelDelegate *delegate = + [[QCocoaFontPanelDelegate alloc] initWithFontPanel:sharedFontPanel + stolenContentView:stolenContentView + okButton:okButton + cancelButton:cancelButton + priv:this + extraWidth:dialogExtraWidth + extraHeight:dialogExtraHeight]; + [ourPanel setDelegate:delegate]; + [[NSFontManager sharedFontManager] setDelegate:delegate]; +#ifdef QT_MAC_USE_COCOA + [[NSFontManager sharedFontManager] setTarget:delegate]; +#endif + setFont(delegate, QApplication::font()); + + { + // hack to get correct initial layout + NSRect frameRect = [ourPanel frame]; + frameRect.size.width += 1.0; + [ourPanel setFrame:frameRect display:NO]; + frameRect.size.width -= 1.0; + frameRect.size = [delegate windowWillResize:ourPanel toSize:frameRect.size]; + [ourPanel setFrame:frameRect display:NO]; + [ourPanel center]; + } + NSString *title = @"Select font"; + [ourPanel setTitle:title]; + + [delegate setModalSession:[NSApp beginModalSessionForWindow:ourPanel]]; + return delegate; +} + +void QFontDialogPrivate::mac_nativeDialogModalHelp() +{ + // Copied from QFileDialogPrivate + // Do a queued meta-call to open the native modal dialog so it opens after the new + // event loop has started to execute (in QDialog::exec). Using a timer rather than + // a queued meta call is intentional to ensure that the call is only delivered when + // [NSApp run] runs (timers are handeled special in cocoa). If NSApp is not + // running (which is the case if e.g a top-most QEventLoop has been + // interrupted, and the second-most event loop has not yet been reactivated (regardless + // if [NSApp run] is still on the stack)), showing a native modal dialog will fail. + if (nativeDialogInUse) { + Q_Q(QFontDialog); + QTimer::singleShot(1, q, SLOT(_q_macRunNativeAppModalPanel())); + } +} + +// The problem with the native font dialog is that OS X does not +// offer a proper dialog, but a panel (i.e. without Ok and Cancel buttons). +// This means we need to "construct" a native dialog by taking the panel +// and "adding" the buttons. +void QFontDialogPrivate::_q_macRunNativeAppModalPanel() +{ + QBoolBlocker nativeDialogOnTop(QApplicationPrivate::native_modal_dialog_active); + Q_Q(QFontDialog); + QCocoaFontPanelDelegate *delegate = (QCocoaFontPanelDelegate *)_q_constructNativePanel(); + NSWindow *ourPanel = [delegate actualPanel]; + [ourPanel retain]; + int rval = [NSApp runModalForWindow:ourPanel]; + QAbstractEventDispatcher::instance()->interrupt(); + [ourPanel release]; + [delegate cleanUpAfterMyself]; + [delegate release]; + bool isOk = (rval == NSOKButton); + if(isOk) + rescode = QDialog::Accepted; + else + rescode = QDialog::Rejected; +} + +bool QFontDialogPrivate::setVisible_sys(bool visible) +{ + Q_Q(QFontDialog); + if (!visible == q->isHidden()) + return false; + return visible; +} + QT_END_NAMESPACE #endif diff --git a/src/gui/dialogs/qfontdialog_p.h b/src/gui/dialogs/qfontdialog_p.h index ca2b10b..7654a80 100644 --- a/src/gui/dialogs/qfontdialog_p.h +++ b/src/gui/dialogs/qfontdialog_p.h @@ -152,6 +152,12 @@ public: inline QFontDialog *fontDialog() { return q_func(); } void *delegate; + bool nativeDialogInUse; + bool canBeNativeDialog(); + bool setVisible_sys(bool visible); + void *_q_constructNativePanel(); + void _q_macRunNativeAppModalPanel(); + void mac_nativeDialogModalHelp(); static bool sharedFontPanelAvailable; #endif -- cgit v0.12 From 0094e35f2303f5cf43d8fb97330efce916250bf9 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 22 Feb 2010 13:40:17 +0100 Subject: QAbstractSocket: Clarify documentation Reviewed-by: Thiago --- src/network/socket/qabstractsocket.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 829df89..275c436 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -155,6 +155,9 @@ See the \l network/fortuneclient and \l network/blockingfortuneclient examples for an overview of both approaches. + \note We discourage the use of the blocking functions together + with signals. One of the two possibilities should be used. + QAbstractSocket can be used with QTextStream and QDataStream's stream operators (operator<<() and operator>>()). There is one issue to be aware of, though: You must make sure that enough data @@ -1682,9 +1685,12 @@ static int qt_timeout_value(int msecs, int elapsed) If msecs is -1, this function will not time out. - Note: This function may wait slightly longer than \a msecs, + \note This function may wait slightly longer than \a msecs, depending on the time it takes to complete the host lookup. + \note Multiple calls to this functions do not accumulate the time. + If the function times out, the connecting process will be aborted. + \sa connectToHost(), connected() */ bool QAbstractSocket::waitForConnected(int msecs) @@ -1722,7 +1728,7 @@ bool QAbstractSocket::waitForConnected(int msecs) d->_q_startConnecting(QHostInfo::fromName(d->hostName)); } if (state() == UnconnectedState) - return false; + return false; // connect not im progress anymore! bool timedOut = true; #if defined (QABSTRACTSOCKET_DEBUG) -- cgit v0.12 From 7a328e4f69f10f4fea6d48746ff214030794328d Mon Sep 17 00:00:00 2001 From: Carlos Manuel Duclos Vergara Date: Mon, 22 Feb 2010 16:19:44 +0100 Subject: Build fix for 976a2b6ad1f95175d8d0be2d1eb7603cf4e4026a. Forgot to add some #ifdef's. Reviewed-by: Richard Moe Gustavsen --- src/gui/dialogs/qfontdialog.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/dialogs/qfontdialog.cpp b/src/gui/dialogs/qfontdialog.cpp index 4358313..a4bf15d 100644 --- a/src/gui/dialogs/qfontdialog.cpp +++ b/src/gui/dialogs/qfontdialog.cpp @@ -994,7 +994,7 @@ void QFontDialog::setVisible(bool visible) return; } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) return; - +#ifdef Q_WS_MAC if (d->canBeNativeDialog()){ if (d->setVisible_sys(visible)){ d->nativeDialogInUse = true; @@ -1006,7 +1006,7 @@ void QFontDialog::setVisible(bool visible) setAttribute(Qt::WA_DontShowOnScreen, false); } } - +#endif // Q_WS_MAC QDialog::setVisible(visible); } @@ -1038,6 +1038,7 @@ void QFontDialog::done(int result) d->memberToDisconnectOnClose.clear(); } +#ifdef Q_WS_MAC bool QFontDialogPrivate::canBeNativeDialog() { Q_Q(QFontDialog); @@ -1052,6 +1053,7 @@ bool QFontDialogPrivate::canBeNativeDialog() QLatin1String dynamicName(q->metaObject()->className()); return (staticName == dynamicName); } +#endif // Q_WS_MAC /*! \fn QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget* parent, const char* name) -- 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 bab4c3056c11ba3607acce3314ecfe172d00cf96 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Mon, 22 Feb 2010 17:59:59 +0100 Subject: Fix memory leak when lazily binding QScriptValue to an engine Avoid the engine's list of free script values from growing without bounds. When a QScriptValue is initially not bound, its private will be allocated from the normal heap (and not from the engine's pool of privates, because there is no engine at this point). But when a value is later bound (e.g. by setting it as a property of an object, or by passing it as argument to QScriptValue::call()) and is subsequently destroyed, its private will be handed to the engine, which will add it to its free-list (hence the memory is not freed). This allocation/deallocation asymmetry causes this list go keep growing. The solution is to limit the size of the free-list, and free the memory of the private immediately when the list has reached a certain size. Task-number: QTBUG-8400 Reviewed-by: Olivier Goffart --- src/script/api/qscriptengine.cpp | 2 +- src/script/api/qscriptengine_p.h | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 1bd7377..1199263 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -768,7 +768,7 @@ static QScriptValue __setupPackage__(QScriptContext *ctx, QScriptEngine *eng) } // namespace QScript QScriptEnginePrivate::QScriptEnginePrivate() - : registeredScriptValues(0), freeScriptValues(0), + : registeredScriptValues(0), freeScriptValues(0), freeScriptValuesCount(0), registeredScriptStrings(0), inEval(false) { qMetaTypeId(); diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index 6780b2c..401d6d2 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -255,6 +255,8 @@ public: int agentLineNumber; QScriptValuePrivate *registeredScriptValues; QScriptValuePrivate *freeScriptValues; + static const int maxFreeScriptValues = 256; + int freeScriptValuesCount; QScriptStringPrivate *registeredScriptStrings; QHash m_typeInfos; int processEventsInterval; @@ -377,6 +379,7 @@ inline QScriptValuePrivate *QScriptEnginePrivate::allocateScriptValuePrivate(siz if (freeScriptValues) { QScriptValuePrivate *p = freeScriptValues; freeScriptValues = p->next; + --freeScriptValuesCount; return p; } return reinterpret_cast(qMalloc(size)); @@ -384,8 +387,13 @@ inline QScriptValuePrivate *QScriptEnginePrivate::allocateScriptValuePrivate(siz inline void QScriptEnginePrivate::freeScriptValuePrivate(QScriptValuePrivate *p) { - p->next = freeScriptValues; - freeScriptValues = p; + if (freeScriptValuesCount < maxFreeScriptValues) { + p->next = freeScriptValues; + freeScriptValues = p; + ++freeScriptValuesCount; + } else { + qFree(p); + } } inline void QScriptEnginePrivate::registerScriptValue(QScriptValuePrivate *value) -- cgit v0.12 From 8597e03495f54614e53c6063f1f13077a08109fd Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 23 Feb 2010 08:46:27 +1000 Subject: Improve performance of VGPath creation by reusing the same path The vgClearPath() function can be used to clear a path for reuse more efficiently than destroying the path and creating a new one. Task-number: QT-2974 Reviewed-by: Daniel Pope --- src/openvg/qpaintengine_vg.cpp | 124 ++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 57 deletions(-) diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index da47f06..4192dbb 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -131,8 +131,9 @@ public: void draw(VGPath path, const QPen& pen, const QBrush& brush, VGint rule = VG_EVEN_ODD); void stroke(VGPath path, const QPen& pen); void fill(VGPath path, const QBrush& brush, VGint rule = VG_EVEN_ODD); - VGPath vectorPathToVGPath(const QVectorPath& path); - VGPath painterPathToVGPath(const QPainterPath& path); + inline void releasePath(VGPath path); + VGPath vectorPathToVGPath(const QVectorPath& path, bool forceNewPath = false); + VGPath painterPathToVGPath(const QPainterPath& path, bool forceNewPath = false); VGPath roundedRectPath(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode); VGPaintType setBrush (VGPaint paint, const QBrush& brush, VGMatrixMode mode, @@ -178,6 +179,8 @@ public: VGPath roundRectPath; // Cached path for quick drawing of rounded rects. #endif + VGPath reusablePath; // Reusable path for vectorPathToVGPath(), etc. + QTransform transform; // Currently active transform. bool simpleTransform; // True if the transform is simple (non-projective). qreal penScale; // Pen scaling factor from "transform". @@ -350,6 +353,8 @@ void QVGPaintEnginePrivate::init() roundRectPath = 0; #endif + reusablePath = 0; + simpleTransform = true; pathTransformSet = false; penScale = 1.0; @@ -446,6 +451,15 @@ void QVGPaintEnginePrivate::initObjects() VG_PATH_CAPABILITY_ALL); vgAppendPathData(linePath, 2, segments, coords); #endif + + // This path can be reused over and over by calling vgClearPath(). + reusablePath = vgCreatePath(VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, + 1.0f, // scale + 0.0f, // bias + 32 + 1, // segmentCapacityHint + 32 * 2, // coordCapacityHint + VG_PATH_CAPABILITY_ALL); } void QVGPaintEnginePrivate::destroy() @@ -465,6 +479,8 @@ void QVGPaintEnginePrivate::destroy() if (roundRectPath) vgDestroyPath(roundRectPath); #endif + if (reusablePath) + vgDestroyPath(reusablePath); #if !defined(QVG_NO_DRAW_GLYPHS) QVGFontCache::Iterator it; @@ -541,19 +557,32 @@ void QVGPaintEnginePrivate::updateTransform(QPaintDevice *pdev) qt_scaleForTransform(transform, &penScale); } -VGPath QVGPaintEnginePrivate::vectorPathToVGPath(const QVectorPath& path) +inline void QVGPaintEnginePrivate::releasePath(VGPath path) +{ + if (path == reusablePath) + vgClearPath(path, VG_PATH_CAPABILITY_ALL); + else + vgDestroyPath(path); +} + +VGPath QVGPaintEnginePrivate::vectorPathToVGPath(const QVectorPath& path, bool forceNewPath) { int count = path.elementCount(); const qreal *points = path.points(); const QPainterPath::ElementType *elements = path.elements(); - VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - count + 1, // segmentCapacityHint - count * 2, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath vgpath; + if (forceNewPath) { + vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, + 1.0f, // scale + 0.0f, // bias + count + 1, // segmentCapacityHint + count * 2, // coordCapacityHint + VG_PATH_CAPABILITY_ALL); + } else { + vgpath = reusablePath; + } // Size is sufficient segments for drawRoundedRect() paths. QVarLengthArray segments; @@ -725,17 +754,22 @@ VGPath QVGPaintEnginePrivate::vectorPathToVGPath(const QVectorPath& path) return vgpath; } -VGPath QVGPaintEnginePrivate::painterPathToVGPath(const QPainterPath& path) +VGPath QVGPaintEnginePrivate::painterPathToVGPath(const QPainterPath& path, bool forceNewPath) { int count = path.elementCount(); - VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - count + 1, // segmentCapacityHint - count * 2, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath vgpath; + if (forceNewPath) { + vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, + 1.0f, // scale + 0.0f, // bias + count + 1, // segmentCapacityHint + count * 2, // coordCapacityHint + VG_PATH_CAPABILITY_ALL); + } else { + vgpath = reusablePath; + } if (count == 0) return vgpath; @@ -954,13 +988,7 @@ VGPath QVGPaintEnginePrivate::roundedRectPath(const QRectF &rect, qreal xRadius, vgModifyPathCoords(vgpath, 0, 9, pts); } #else - VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - 10, // segmentCapacityHint - 17 * 2, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath vgpath = reusablePath; vgAppendPathData(vgpath, 10, roundedrect_types, pts); #endif @@ -1516,7 +1544,7 @@ void QVGPaintEngine::draw(const QVectorPath &path) d->draw(vgpath, s->pen, s->brush, VG_EVEN_ODD); else d->draw(vgpath, s->pen, s->brush, VG_NON_ZERO); - vgDestroyPath(vgpath); + d->releasePath(vgpath); } void QVGPaintEngine::fill(const QVectorPath &path, const QBrush &brush) @@ -1527,7 +1555,7 @@ void QVGPaintEngine::fill(const QVectorPath &path, const QBrush &brush) d->fill(vgpath, brush, VG_EVEN_ODD); else d->fill(vgpath, brush, VG_NON_ZERO); - vgDestroyPath(vgpath); + d->releasePath(vgpath); } void QVGPaintEngine::stroke(const QVectorPath &path, const QPen &pen) @@ -1535,7 +1563,7 @@ void QVGPaintEngine::stroke(const QVectorPath &path, const QPen &pen) Q_D(QVGPaintEngine); VGPath vgpath = d->vectorPathToVGPath(path); d->stroke(vgpath, pen); - vgDestroyPath(vgpath); + d->releasePath(vgpath); } // Determine if a co-ordinate transform is simple enough to allow @@ -1731,7 +1759,7 @@ void QVGPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) default: break; } - vgDestroyPath(vgpath); + d->releasePath(vgpath); vgSeti(VG_MASKING, VG_TRUE); d->maskValid = true; @@ -2048,7 +2076,7 @@ void QVGPaintEngine::clip(const QPainterPath &path, Qt::ClipOperation op) default: break; } - vgDestroyPath(vgpath); + d->releasePath(vgpath); vgSeti(VG_MASKING, VG_TRUE); d->maskValid = true; @@ -2487,7 +2515,7 @@ void QVGPaintEngine::drawRoundedRect(const QRectF &rect, qreal xrad, qreal yrad, VGPath vgpath = d->roundedRectPath(rect, xrad, yrad, mode); d->draw(vgpath, s->pen, s->brush); #if defined(QVG_NO_MODIFY_PATH) - vgDestroyPath(vgpath); + d->releasePath(vgpath); #endif } else { QPaintEngineEx::drawRoundedRect(rect, xrad, yrad, mode); @@ -2636,13 +2664,7 @@ void QVGPaintEngine::drawEllipse(const QRectF &r) Q_D(QVGPaintEngine); if (d->simpleTransform) { QVGPainterState *s = state(); - VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - 4, // segmentCapacityHint - 12, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath path = d->reusablePath; static VGubyte segments[4] = { VG_MOVE_TO_ABS, VG_SCCWARC_TO_REL, @@ -2666,7 +2688,7 @@ void QVGPaintEngine::drawEllipse(const QRectF &r) coords[11] = 0.0f; vgAppendPathData(path, 4, segments, coords); d->draw(path, s->pen, s->brush); - vgDestroyPath(path); + d->releasePath(path); } else { // The projective transform version of an ellipse is difficult. // Generate a QVectorPath containing cubic curves and transform that. @@ -2690,7 +2712,7 @@ void QVGPaintEngine::drawPath(const QPainterPath &path) d->draw(vgpath, s->pen, s->brush, VG_EVEN_ODD); else d->draw(vgpath, s->pen, s->brush, VG_NON_ZERO); - vgDestroyPath(vgpath); + d->releasePath(vgpath); } void QVGPaintEngine::drawPoints(const QPointF *points, int pointCount) @@ -2765,13 +2787,7 @@ void QVGPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonD { Q_D(QVGPaintEngine); QVGPainterState *s = state(); - VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - pointCount + 1, // segmentCapacityHint - pointCount * 2, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath path = d->reusablePath; QVarLengthArray coords; QVarLengthArray segments; for (int i = 0; i < pointCount; ++i, ++points) { @@ -2805,20 +2821,14 @@ void QVGPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonD d->draw(path, s->pen, s->brush, VG_EVEN_ODD); break; } - vgDestroyPath(path); + d->releasePath(path); } void QVGPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) { Q_D(QVGPaintEngine); QVGPainterState *s = state(); - VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - pointCount + 1, // segmentCapacityHint - pointCount * 2, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath path = d->reusablePath; QVarLengthArray coords; QVarLengthArray segments; for (int i = 0; i < pointCount; ++i, ++points) { @@ -2852,7 +2862,7 @@ void QVGPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDr d->draw(path, s->pen, s->brush, VG_EVEN_ODD); break; } - vgDestroyPath(path); + d->releasePath(path); } void QVGPaintEnginePrivate::setImageOptions() @@ -3251,7 +3261,7 @@ void QVGFontGlyphCache::cacheGlyphs ti.fontEngine->getUnscaledGlyph(glyph, &path, &metrics); VGPath vgPath; if (!path.isEmpty()) { - vgPath = d->painterPathToVGPath(path); + vgPath = d->painterPathToVGPath(path, true); } else { // Probably a "space" character with no visible outline. vgPath = VG_INVALID_HANDLE; -- cgit v0.12 From f91f64ee2d0caa86b004bf3653f286116681fa3d Mon Sep 17 00:00:00 2001 From: Kurt Korbatits Date: Tue, 23 Feb 2010 10:24:22 +1000 Subject: Updates to low-level audio documentation. Detail state changes and error states in QAudioInput and QAudioOutput documentation. Reviewed-by: Derick Hawcroft --- src/multimedia/audio/qaudioinput.cpp | 74 +++++++++++++++------------------ src/multimedia/audio/qaudiooutput.cpp | 78 +++++++++++++++-------------------- 2 files changed, 66 insertions(+), 86 deletions(-) diff --git a/src/multimedia/audio/qaudioinput.cpp b/src/multimedia/audio/qaudioinput.cpp index 45cafc1..fd892dd 100644 --- a/src/multimedia/audio/qaudioinput.cpp +++ b/src/multimedia/audio/qaudioinput.cpp @@ -190,18 +190,18 @@ QAudioInput::~QAudioInput() Passing a QIODevice allows the data to be transfered without any extra code. All that is required is to open the QIODevice. + If able to successfully get audio data from the systems audio device the + state() is set to either QAudio::ActiveState or QAudio::IdleState, + error() is set to QAudio::NoError and the stateChanged() signal is emitted. + + If a problem occurs during this process the error() is set to QAudio::OpenError, + state() is set to QAudio::StoppedState and stateChanged() signal is emitted. + \sa QIODevice */ void QAudioInput::start(QIODevice* device) { - /* - -If currently not StoppedState, stop - -If previous start was push mode, delete internal QIODevice. - -open audio input. - If ok, NoError and ActiveState, else OpenError and StoppedState. - -emit stateChanged() - */ d->start(device); } @@ -210,19 +210,18 @@ void QAudioInput::start(QIODevice* device) transfer. This QIODevice can be used to read() audio data directly. + If able to access the systems audio device the state() is set to + QAudio::IdleState, error() is set to QAudio::NoError + and the stateChanged() signal is emitted. + + If a problem occurs during this process the error() is set to QAudio::OpenError, + state() is set to QAudio::StoppedState and stateChanged() signal is emitted. + \sa QIODevice */ QIODevice* QAudioInput::start() { - /* - -If currently not StoppedState, stop - -If no internal QIODevice, create one. - -open audio input. - -If ok, NoError and IdleState, else OpenError and StoppedState - -emit stateChanged() - -return internal QIODevice - */ return d->start(0); } @@ -236,17 +235,14 @@ QAudioFormat QAudioInput::format() const } /*! - Stops the audio input. + Stops the audio input, detaching from the system resource. + + Sets error() to QAudio::NoError, state() to QAudio::StoppedState and + emit stateChanged() signal. */ void QAudioInput::stop() { - /* - -If StoppedState, return - -set to StoppedState - -detach from audio device - -emit stateChanged() - */ d->stop(); } @@ -256,42 +252,32 @@ void QAudioInput::stop() void QAudioInput::reset() { - /* - -drop all buffered audio, set buffers to zero. - -call stop() - */ d->reset(); } /*! Stops processing audio data, preserving buffered audio data. + + Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and + emit stateChanged() signal. */ void QAudioInput::suspend() { - /* - -If not ActiveState|IdleState, return - -stop processing audio, saving all buffered audio data - -set NoError and SuspendedState - -emit stateChanged() - */ d->suspend(); } /*! Resumes processing audio data after a suspend(). + + Sets error() to QAudio::NoError. + Sets state() to QAudio::ActiveState if you previously called start(QIODevice*). + Sets state() to QAudio::IdleState if you previously called start(). + emits stateChanged() signal. */ void QAudioInput::resume() { - /* - -If SuspendedState, return - -resume audio - -(PULL MODE): set ActiveState, NoError - -(PUSH MODE): set IdleState, NoError - -kick start audio if needed - -emit stateChanged() - */ d->resume(); } @@ -327,6 +313,9 @@ int QAudioInput::bufferSize() const /*! Returns the amount of audio data available to read in bytes. + + NOTE: returned value is only valid while in QAudio::ActiveState or QAudio::IdleState + state, otherwise returns zero. */ int QAudioInput::bytesReady() const @@ -352,7 +341,10 @@ int QAudioInput::periodSize() const /*! Sets the interval for notify() signal to be emitted. This is based on the \a ms of audio data processed - not on actual real-time. The resolution of the timer is platform specific. + not on actual real-time. + The minimum resolution of the timer is platform specific and values + should be checked with notifyInterval() to confirm actual value + being used. */ void QAudioInput::setNotifyInterval(int ms) diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp index afd8a84..b0b5244 100644 --- a/src/multimedia/audio/qaudiooutput.cpp +++ b/src/multimedia/audio/qaudiooutput.cpp @@ -202,18 +202,18 @@ QAudioFormat QAudioOutput::format() const Passing a QIODevice allows the data to be transfered without any extra code. All that is required is to open the QIODevice. + If able to successfully output audio data to the systems audio device the + state() is set to QAudio::ActiveState, error() is set to QAudio::NoError + and the stateChanged() signal is emitted. + + If a problem occurs during this process the error() is set to QAudio::OpenError, + state() is set to QAudio::StoppedState and stateChanged() signal is emitted. + \sa QIODevice */ void QAudioOutput::start(QIODevice* device) { - /* - -If currently not StoppedState, stop. - -If previous start was push mode, delete internal QIODevice. - -open audio output. - -If ok, NoError and ActiveState, else OpenError and StoppedState - -emit stateChanged() - */ d->start(device); } @@ -221,34 +221,30 @@ void QAudioOutput::start(QIODevice* device) Returns a pointer to the QIODevice being used to handle the data transfer. This QIODevice can be used to write() audio data directly. + If able to access the systems audio device the state() is set to + QAudio::IdleState, error() is set to QAudio::NoError + and the stateChanged() signal is emitted. + + If a problem occurs during this process the error() is set to QAudio::OpenError, + state() is set to QAudio::StoppedState and stateChanged() signal is emitted. + \sa QIODevice */ QIODevice* QAudioOutput::start() { - /* - -If currently not StoppedState, stop. - -If no internal QIODevice, create one. - -open audio output. - -If ok, NoError and IdleState, else OpenError and StoppedState - -emit stateChanged() - -return internal QIODevice - */ return d->start(0); } /*! - Stops the audio output. + Stops the audio output, detaching from the system resource. + + Sets error() to QAudio::NoError, state() to QAudio::StoppedState and + emit stateChanged() signal. */ void QAudioOutput::stop() { - /* - -If StoppedState, return - -set to StoppedState - -detach from audio device - -emit stateChanged() - */ d->stop(); } @@ -258,55 +254,44 @@ void QAudioOutput::stop() void QAudioOutput::reset() { - /* - -drop all buffered audio, set buffers to zero. - -call stop() - */ d->reset(); } /*! Stops processing audio data, preserving buffered audio data. + + Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and + emit stateChanged() signal. */ void QAudioOutput::suspend() { - /* - -If not ActiveState|IdleState, return - -stop processing audio, saving all buffered audio data - -set NoError and SuspendedState - -emit stateChanged() - */ d->suspend(); } /*! Resumes processing audio data after a suspend(). + + Sets error() to QAudio::NoError. + Sets state() to QAudio::ActiveState if you previously called start(QIODevice*). + Sets state() to QAudio::IdleState if you previously called start(). + emits stateChanged() signal. */ void QAudioOutput::resume() { - /* - -If SuspendedState, return - -resume audio - -(PULL MODE): set ActiveState, NoError - -(PUSH MODE): set IdleState, NoError - -kick start audio if needed - -emit stateChanged() - */ d->resume(); } /*! Returns the free space available in bytes in the audio buffer. + + NOTE: returned value is only valid while in QAudio::ActiveState or QAudio::IdleState + state, otherwise returns zero. */ int QAudioOutput::bytesFree() const { - /* - -If not ActiveState|IdleState, return 0 - -return space available in audio buffer in bytes - */ return d->bytesFree(); } @@ -353,7 +338,10 @@ int QAudioOutput::bufferSize() const /*! Sets the interval for notify() signal to be emitted. This is based on the \a ms of audio data processed - not on actual real-time. The resolution of the timer is platform specific. + not on actual real-time. + The minimum resolution of the timer is platform specific and values + should be checked with notifyInterval() to confirm actual value + being used. */ void QAudioOutput::setNotifyInterval(int ms) -- 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 04532ba052559b265b1bc85dc143d8aeeb02149f Mon Sep 17 00:00:00 2001 From: Kurt Korbatits Date: Tue, 23 Feb 2010 13:40:03 +1000 Subject: alsa backend for low-level audio doesn't pass new unit tests New unit tests have identified issues with alsa backend. These issues need to be resolved before new unit tests are added. * stateChanged() signal should only be emitted on change of state currently signals can be emitted multiple times. * elapsedUSecs() currently uses alsa to provide this value but this is not reliable enough and this time is reset when suspend/resuming. This is not correct operation. * for output data is being lost when input cant be read from QIODevice but cannot be written to audio sub system. Task-number:QTBUG-8440 Reviewed-by:Dmytro Poplavskiy --- src/multimedia/audio/qaudioinput_alsa_p.cpp | 121 +++++++++------------------ src/multimedia/audio/qaudiooutput_alsa_p.cpp | 64 ++++++-------- 2 files changed, 67 insertions(+), 118 deletions(-) diff --git a/src/multimedia/audio/qaudioinput_alsa_p.cpp b/src/multimedia/audio/qaudioinput_alsa_p.cpp index 26e46b3..6010f3c 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.cpp +++ b/src/multimedia/audio/qaudioinput_alsa_p.cpp @@ -217,9 +217,11 @@ QIODevice* QAudioInputPrivate::start(QIODevice* device) //set to pull mode pullMode = true; audioSource = device; + deviceState = QAudio::ActiveState; } else { //set to push mode pullMode = false; + deviceState = QAudio::IdleState; audioSource = new InputPrivate(this); audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered); } @@ -413,7 +415,6 @@ bool QAudioInputPrivate::open() timer->start(period_time*chunks/2000); errorState = QAudio::NoError; - deviceState = QAudio::ActiveState; totalTimeValue = 0; @@ -439,7 +440,7 @@ int QAudioInputPrivate::bytesReady() const if(resuming) return period_size; - if(deviceState != QAudio::ActiveState) + if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) return 0; int frames = snd_pcm_avail_update(handle); if((int)frames > (int)buffer_frames) @@ -450,8 +451,8 @@ int QAudioInputPrivate::bytesReady() const qint64 QAudioInputPrivate::read(char* data, qint64 len) { - Q_UNUSED(data) Q_UNUSED(len) + // Read in some audio data and write it to QIODevice, pull mode if ( !handle ) return 0; @@ -468,7 +469,7 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len) if (readFrames >= 0) { err = snd_pcm_frames_to_bytes(handle, readFrames); #ifdef DEBUG_AUDIO - qDebug()< 0) { // got some send it onward #ifdef DEBUG_AUDIO - qDebug()<<"PULL: frames to write to QIODevice = "<< + qDebug()<<"frames to write to QIODevice = "<< snd_pcm_bytes_to_frames( handle, (int)err )<<" ("<write(audioBuffer,err); + if(l < 0) { + close(); + errorState = QAudio::IOError; + deviceState = QAudio::StoppedState; + emit stateChanged(deviceState); + } else if(l == 0) { + if (deviceState != QAudio::IdleState) { + errorState = QAudio::NoError; + deviceState = QAudio::IdleState; + emit stateChanged(deviceState); + } + } else { + totalTimeValue += err; + resuming = false; + if (deviceState != QAudio::ActiveState) { + errorState = QAudio::NoError; + deviceState = QAudio::ActiveState; + emit stateChanged(deviceState); + } + } + return l; - qint64 l = audioSource->write(audioBuffer,err); - if(l < 0) { - close(); - errorState = QAudio::IOError; - deviceState = QAudio::StoppedState; - emit stateChanged(deviceState); - } else if(l == 0) { - errorState = QAudio::NoError; - deviceState = QAudio::IdleState; } else { - totalTimeValue += snd_pcm_bytes_to_frames(handle, err)*1000000/settings.frequency(); + memcpy(data,audioBuffer,err); + totalTimeValue += err; resuming = false; - errorState = QAudio::NoError; - deviceState = QAudio::ActiveState; + if (deviceState != QAudio::ActiveState) { + errorState = QAudio::NoError; + deviceState = QAudio::ActiveState; + emit stateChanged(deviceState); + } + return err; } - return l; } return 0; } @@ -569,7 +588,7 @@ int QAudioInputPrivate::notifyInterval() const qint64 QAudioInputPrivate::processedUSecs() const { - return totalTimeValue; + return qint64(1000000) * totalTimeValue / settings.frequency(); } void QAudioInputPrivate::suspend() @@ -617,34 +636,10 @@ bool QAudioInputPrivate::deviceReady() qint64 QAudioInputPrivate::elapsedUSecs() const { - if(!handle) - return 0; - if (deviceState == QAudio::StoppedState) return 0; -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - snd_pcm_status_t* status; - snd_pcm_status_alloca(&status); - - snd_timestamp_t t1,t2; - if( snd_pcm_status(handle, status) >= 0) { - snd_pcm_status_get_tstamp(status,&t1); - snd_pcm_status_get_trigger_tstamp(status,&t2); - t1.tv_sec-=t2.tv_sec; - - signed long l = (signed long)t1.tv_usec - (signed long)t2.tv_usec; - if(l < 0) { - t1.tv_sec--; - l = -l; - l %= 1000000; - } - return ((t1.tv_sec * 1000000)+l); - } else - return 0; -#else return clockStamp.elapsed()*1000; -#endif } void QAudioInputPrivate::reset() @@ -670,43 +665,7 @@ InputPrivate::~InputPrivate() qint64 InputPrivate::readData( char* data, qint64 len) { - // push mode, user read() called - if((audioDevice->state() != QAudio::ActiveState) && !audioDevice->resuming) - return 0; - - int readFrames; - int count=0, err = 0; - - while(count < 5) { - int frames = snd_pcm_bytes_to_frames(audioDevice->handle, len); - readFrames = snd_pcm_readi(audioDevice->handle, data, frames); - if (readFrames >= 0) { - err = snd_pcm_frames_to_bytes(audioDevice->handle, readFrames); -#ifdef DEBUG_AUDIO - qDebug()<errorState = QAudio::IOError; - err = 0; - break; - } else { - if(readFrames == -EPIPE) { - audioDevice->errorState = QAudio::UnderrunError; - err = snd_pcm_prepare(audioDevice->handle); - } else if(readFrames == -ESTRPIPE) { - err = snd_pcm_prepare(audioDevice->handle); - } - if(err != 0) break; - } - count++; - } - if(err > 0 && readFrames > 0) { - audioDevice->totalTimeValue += readFrames*1000/audioDevice->settings.frequency()*1000; - audioDevice->deviceState = QAudio::ActiveState; - return err; - } - return 0; + return audioDevice->read(data,len); } qint64 InputPrivate::writeData(const char* data, qint64 len) diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/audio/qaudiooutput_alsa_p.cpp index 7b89cef..b127103 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp +++ b/src/multimedia/audio/qaudiooutput_alsa_p.cpp @@ -259,6 +259,7 @@ void QAudioOutputPrivate::stop() { if(deviceState == QAudio::StoppedState) return; + errorState = QAudio::NoError; deviceState = QAudio::StoppedState; close(); emit stateChanged(deviceState); @@ -494,10 +495,13 @@ qint64 QAudioOutputPrivate::write( const char *data, qint64 len ) err = snd_pcm_writei( handle, data, frames ); } if(err > 0) { - totalTimeValue += err*1000000/settings.frequency(); + totalTimeValue += err; resuming = false; errorState = QAudio::NoError; - deviceState = QAudio::ActiveState; + if (deviceState != QAudio::ActiveState) { + deviceState = QAudio::ActiveState; + emit stateChanged(deviceState); + } return snd_pcm_frames_to_bytes( handle, err ); } else err = xrun_recovery(err); @@ -542,7 +546,7 @@ int QAudioOutputPrivate::notifyInterval() const qint64 QAudioOutputPrivate::processedUSecs() const { - return totalTimeValue; + return qint64(1000000) * totalTimeValue / settings.frequency(); } void QAudioOutputPrivate::resume() @@ -562,10 +566,8 @@ void QAudioOutputPrivate::resume() bytesAvailable = (int)snd_pcm_frames_to_bytes(handle, buffer_frames); } resuming = true; - if(pullMode) - deviceState = QAudio::ActiveState; - else - deviceState = QAudio::IdleState; + + deviceState = QAudio::ActiveState; errorState = QAudio::NoError; timer->start(period_time/1000); @@ -637,7 +639,9 @@ bool QAudioOutputPrivate::deviceReady() // Got some data to output if(deviceState != QAudio::ActiveState) return true; - write(audioBuffer,l); + qint64 bytesWritten = write(audioBuffer,l); + if (bytesWritten != l) + audioSource->seek(audioSource->pos()-(l-bytesWritten)); bytesAvailable = bytesFree(); } else if(l == 0) { @@ -645,9 +649,11 @@ bool QAudioOutputPrivate::deviceReady() bytesAvailable = bytesFree(); if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) { // Underrun - errorState = QAudio::UnderrunError; - deviceState = QAudio::IdleState; - emit stateChanged(deviceState); + if (deviceState != QAudio::IdleState) { + errorState = QAudio::UnderrunError; + deviceState = QAudio::IdleState; + emit stateChanged(deviceState); + } } } else if(l < 0) { @@ -655,8 +661,17 @@ bool QAudioOutputPrivate::deviceReady() errorState = QAudio::IOError; emit stateChanged(deviceState); } - } else + } else { bytesAvailable = bytesFree(); + if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) { + // Underrun + if (deviceState != QAudio::IdleState) { + errorState = QAudio::UnderrunError; + deviceState = QAudio::IdleState; + emit stateChanged(deviceState); + } + } + } if(deviceState != QAudio::ActiveState) return true; @@ -671,35 +686,10 @@ bool QAudioOutputPrivate::deviceReady() qint64 QAudioOutputPrivate::elapsedUSecs() const { - if(!handle) - return 0; - if (deviceState == QAudio::StoppedState) return 0; -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - snd_pcm_status_t* status; - snd_pcm_status_alloca(&status); - - snd_timestamp_t t1,t2; - if( snd_pcm_status(handle, status) >= 0) { - snd_pcm_status_get_tstamp(status,&t1); - snd_pcm_status_get_trigger_tstamp(status,&t2); - t1.tv_sec-=t2.tv_sec; - - signed long l = (signed long)t1.tv_usec - (signed long)t2.tv_usec; - if(l < 0) { - t1.tv_sec--; - l = -l; - l %= 1000000; - } - return ((t1.tv_sec * 1000000)+l); - } else - return 0; -#else return clockStamp.elapsed()*1000; -#endif - return 0; } void QAudioOutputPrivate::reset() -- 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 2b7e46886d7a77257b64823e959bd8d8a007380d Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 23 Feb 2010 09:38:20 +0100 Subject: doc: Removed some erroneous text. Task: QTBUG-7965 --- src/gui/graphicsview/qgraphicsitem.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 2f208b7..d19a102 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -414,12 +414,6 @@ /*! \enum QGraphicsItem::GraphicsItemChange - ItemVisibleHasChanged, - ItemEnabledHasChanged, - ItemSelectedHasChanged, - ItemParentHasChanged, - ItemSceneHasChanged - This enum describes the state changes that are notified by QGraphicsItem::itemChange(). The notifications are sent as the state changes, and in some cases, adjustments can be made (see the documentation -- cgit v0.12 From c02de9aaa2d27d43ec64b04b609af4f1233c620a Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 22 Feb 2010 14:09:22 +0100 Subject: enable bytepair compression for S60 3.2 and newer Bytepair compression allows libraries to be paged properly and drastically reduces RAM consumption. Reviewed-By: Jason Barron --- mkspecs/common/symbian/symbian.conf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mkspecs/common/symbian/symbian.conf b/mkspecs/common/symbian/symbian.conf index 7b2ee91..f3026ad 100644 --- a/mkspecs/common/symbian/symbian.conf +++ b/mkspecs/common/symbian/symbian.conf @@ -115,7 +115,7 @@ symbian-abld { } else { MMP_RULES_DONT_EXPORT_ALL_CLASS_IMPEDIMENTA = "OPTION_REPLACE ARMCC --export_all_vtbl // don't use --export_all_vtbl" } -MMP_RULES += PAGED +MMP_RULES += PAGED BYTEPAIRCOMPRESSTARGET MMP_RULES += $$MMP_RULES_DONT_EXPORT_ALL_CLASS_IMPEDIMENTA SYMBIAN_PLATFORMS = WINSCW GCCE ARMV5 ARMV6 @@ -145,7 +145,7 @@ exists($${EPOCROOT}epoc32/release/winscw/udeb/z/system/install/Series60v5.0.sis S60_VERSION = 3.2 } else { S60_VERSION = 3.1 - MMP_RULES -= PAGED + MMP_RULES -= PAGED BYTEPAIRCOMPRESSTARGET } } @@ -163,4 +163,4 @@ symbian { # [TODO] QMAKE_CXXFLAGS.GCCE += $${QMAKE_CXXFLAGS_FAST_VFP.GCCE} } } -} \ No newline at end of file +} -- cgit v0.12 From 1ef21425463204ff60defb9ca97813ff07db2149 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 23 Feb 2010 09:53:22 +0100 Subject: doc: Added \since 4.6 to the properties. Task: QTBUG-8333 --- src/svg/qgraphicssvgitem.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/svg/qgraphicssvgitem.cpp b/src/svg/qgraphicssvgitem.cpp index 7e80e50..69ff7a3 100644 --- a/src/svg/qgraphicssvgitem.cpp +++ b/src/svg/qgraphicssvgitem.cpp @@ -267,6 +267,7 @@ int QGraphicsSvgItem::type() const /*! \property QGraphicsSvgItem::maximumCacheSize + \since 4.6 This property holds the maximum size of the device coordinate cache for this item. @@ -312,7 +313,8 @@ QSize QGraphicsSvgItem::maximumCacheSize() const /*! \property QGraphicsSvgItem::elementId - + \since 4.6 + This property holds the element's XML ID. */ -- 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 0a1a01ea6e6496d79a59cd9b5f845d56fa1e53d6 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 23 Feb 2010 10:28:39 +0100 Subject: doc: Added \obsolete. Task: QTBUG-8083 --- src/corelib/io/qdir.cpp | 8 ++++---- src/corelib/io/qresource.cpp | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index dc7f17e..69b3af4 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -993,15 +993,15 @@ void QDir::setNameFilters(const QStringList &nameFilters) /*! \obsolete + + Use QDir::addSearchPath() with a prefix instead. + Adds \a path to the search paths searched in to find resources that are not specified with an absolute path. The default search path is to search only in the root (\c{:/}). - Use QDir::addSearchPath() with a prefix instead. - - \sa {The Qt Resource System}, QResource::addSearchPath() + \sa {The Qt Resource System} */ - void QDir::addResourceSearchPath(const QString &path) { #ifdef QT_BUILD_CORE_LIB diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index adfbb15..6d33c8b 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -555,16 +555,15 @@ QStringList QResource::children() const /*! \obsolete + Use QDir::addSearchPath() with a prefix instead. + Adds \a path to the search paths searched in to find resources that are not specified with an absolute path. The \a path must be an absolute path (start with \c{/}). The default search path is to search only in the root (\c{:/}). The last path added will be consulted first upon next QResource creation. - - Use QDir::addSearchPath() with a prefix instead. */ - void QResource::addSearchPath(const QString &path) { @@ -578,6 +577,10 @@ QResource::addSearchPath(const QString &path) } /*! + \obsolete + + Use QDir::searchPaths() instead. + Returns the current search path list. This list is consulted when creating a relative resource. -- cgit v0.12 From 48a1b43743481a646ad0ebef116f249f891e4e10 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 23 Feb 2010 10:40:12 +0100 Subject: doc: Removed bad grammar. Task: QTBUG-8033 --- doc/src/examples/scribble.qdoc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/src/examples/scribble.qdoc b/doc/src/examples/scribble.qdoc index 3c6d136..5c66410 100644 --- a/doc/src/examples/scribble.qdoc +++ b/doc/src/examples/scribble.qdoc @@ -74,9 +74,8 @@ \o \c MainWindow provides a menu above the \c ScribbleArea. \endlist - We will start by reviewing the \c ScribbleArea class, which - contains the interesting, then we will take a look at the \c - MainWindow class that uses it. + We will start by reviewing the \c ScribbleArea class. Then we will + review the \c MainWindow class, which uses \c ScribbleArea. \section1 ScribbleArea Class Definition -- cgit v0.12 From bbb996e6cbe4a19ceb72650dd82a8b3cf60553db Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Mon, 22 Feb 2010 12:41:23 +0100 Subject: Use the SYMBIAN_BUILD_GCE macro to check if the GCE variant can be used The correct macro for determing when we can enable the NGA specific functions in Symbian is SYMBIAN_BUILD_GCE. Reviewed-by: Iain --- src/corelib/global/qglobal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 9edf929..4b1232d 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -2409,7 +2409,7 @@ QT3_SUPPORT Q_CORE_EXPORT const char *qInstallPathSysconf(); #if defined(Q_OS_SYMBIAN) -#ifdef SYMBIAN_GRAPHICS_USE_GCE +#ifdef SYMBIAN_BUILD_GCE //RWsPointerCursor is fixed, so don't use low performance sprites #define Q_SYMBIAN_FIXED_POINTER_CURSORS #define Q_SYMBIAN_HAS_EXTENDED_BITMAP_TYPE -- cgit v0.12 From 925dac20184820222765385b391a78d776ee61bb Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Mon, 22 Feb 2010 13:54:20 +0100 Subject: Enable window size caching on Symbian NGA variants. Enabling this flag saves us the round-trip to WSERV whenever RWindow::Size() is called because the size is cached on the client side. This can improve performance because functions like eglSwapBuffers() call Size() to see if the window size has changed and without the cache this introduces an extra IPC call for every frame. Task-number: QT-2849 Reviewed-by: Iain --- src/corelib/global/qglobal.h | 1 + src/gui/kernel/qapplication_s60.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 4b1232d..04aac12 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -2413,6 +2413,7 @@ QT3_SUPPORT Q_CORE_EXPORT const char *qInstallPathSysconf(); //RWsPointerCursor is fixed, so don't use low performance sprites #define Q_SYMBIAN_FIXED_POINTER_CURSORS #define Q_SYMBIAN_HAS_EXTENDED_BITMAP_TYPE +#define Q_SYMBIAN_WINDOW_SIZE_CACHE //enabling new graphics resources #define QT_SYMBIAN_SUPPORTS_SGIMAGE #define QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index bf3ad71..fdbbeb2 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1146,6 +1146,10 @@ void qt_init(QApplicationPrivate * /* priv */, int) #endif S60->wsSession().SetAutoFlush(ETrue); +#ifdef Q_SYMBIAN_WINDOW_SIZE_CACHE + TRAP_IGNORE(S60->wsSession().EnableWindowSizeCacheL()); +#endif + S60->updateScreenSize(); -- cgit v0.12 From 9be36306cd19626344cdedf5d99f5b142c2356d0 Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Tue, 23 Feb 2010 09:57:35 +0100 Subject: Always define Q_WS_S60 on Symbian unless configured with -no-s60. Previously we were relying on the toolchain to define the S60 version for us and were enabling Q_WS_S60 based on this. Since the S60 macros are no longer defined for us, let's assume we always want S60 support unless Qt is configured with -no-s60. Reviewed-by: axis --- src/corelib/global/qglobal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 04aac12..82210f3 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -813,7 +813,7 @@ namespace QT_NAMESPACE {} # define Q_WS_MAC32 # endif # elif defined(Q_OS_SYMBIAN) -# if (defined(__SERIES60_31__) || defined(__S60_32__) || defined(__S60_50__)) && !defined(QT_NO_S60) +# if !defined(QT_NO_S60) # define Q_WS_S60 # endif # elif !defined(Q_WS_QWS) -- cgit v0.12 From 9629681e7b3d69456bd6c5905c267b3d08b6243f Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 23 Feb 2010 11:38:23 +0100 Subject: doc: Corrected typo. Task: QTBUG-8450 --- src/corelib/io/qiodevice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 4e14ba8..662100a 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -1003,8 +1003,8 @@ QByteArray QIODevice::readAll() to a maximum of \a maxSize - 1 bytes, stores the characters in \a data, and returns the number of bytes read. If a line could not be read but no error ocurred, this function returns 0. If an error - occurs, this function returns what it could the length of what - could be read, or -1 if nothing was read. + occurs, this function returns the length of what could be read, or + -1 if nothing was read. A terminating '\0' byte is always appended to \a data, so \a maxSize must be larger than 1. -- 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 12b1dbb1a0911d421d9e19129291dcd8151c3f50 Mon Sep 17 00:00:00 2001 From: Carlos Manuel Duclos Vergara Date: Tue, 23 Feb 2010 12:28:17 +0100 Subject: QColorDialog::open() freezes the app the *second* time it is used on Mac The problem here is caused by a boolean flag used to prevent recursion. The flag was set and never reset. This patch resets the flag the moment open is called. Task-number: QTBUG-7825 Reviewed-by: Richard Moe Gustavsen --- src/gui/dialogs/qcolordialog_mac.mm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gui/dialogs/qcolordialog_mac.mm b/src/gui/dialogs/qcolordialog_mac.mm index bdcb872..8af0d2b 100644 --- a/src/gui/dialogs/qcolordialog_mac.mm +++ b/src/gui/dialogs/qcolordialog_mac.mm @@ -96,6 +96,7 @@ QT_USE_NAMESPACE - (void)finishOffWithCode:(NSInteger)result; - (void)showColorPanel; - (void)exec; +- (void)setResultSet:(BOOL)result; @end @implementation QCocoaColorPanelDelegate @@ -158,6 +159,11 @@ QT_USE_NAMESPACE [super dealloc]; } +- (void)setResultSet:(BOOL)result +{ + mResultSet = result; +} + - (BOOL)windowShouldClose:(id)window { Q_UNUSED(window); @@ -320,7 +326,7 @@ QT_USE_NAMESPACE } else { mPriv->colorDialog()->accept(); } - } + } } } @@ -433,7 +439,7 @@ void QColorDialogPrivate::openCocoaColorPanel(const QColor &initial, priv:this]; [colorPanel setDelegate:static_cast(delegate)]; } - + [delegate setResultSet:false]; setCocoaPanelColor(initial); [static_cast(delegate) showColorPanel]; } -- cgit v0.12 From 57f716aab87ad517ccd6a36bdd5ca8178c561572 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Tue, 23 Feb 2010 12:31:10 +0100 Subject: Improve test coverage of QScriptString::toArrayIndex() Test decimals and scientific notation. "0.0" is not a valid array index even though it can be converted to a whole integer, because the number converted back to a string again is "0", which is different from "0.0". (See ECMA 15.4) --- tests/auto/qscriptstring/tst_qscriptstring.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/auto/qscriptstring/tst_qscriptstring.cpp b/tests/auto/qscriptstring/tst_qscriptstring.cpp index 808b643..ea4a92b 100644 --- a/tests/auto/qscriptstring/tst_qscriptstring.cpp +++ b/tests/auto/qscriptstring/tst_qscriptstring.cpp @@ -177,6 +177,12 @@ void tst_QScriptString::toArrayIndex_data() QTest::newRow("101a") << QString::fromLatin1("101a") << false << quint32(0xffffffff); QTest::newRow("4294967294") << QString::fromLatin1("4294967294") << true << quint32(0xfffffffe); QTest::newRow("4294967295") << QString::fromLatin1("4294967295") << false << quint32(0xffffffff); + QTest::newRow("0.0") << QString::fromLatin1("0.0") << false << quint32(0xffffffff); + QTest::newRow("1.0") << QString::fromLatin1("1.0") << false << quint32(0xffffffff); + QTest::newRow("1.5") << QString::fromLatin1("1.5") << false << quint32(0xffffffff); + QTest::newRow("1.") << QString::fromLatin1("1.") << false << quint32(0xffffffff); + QTest::newRow(".1") << QString::fromLatin1(".1") << false << quint32(0xffffffff); + QTest::newRow("1e0") << QString::fromLatin1("1e0") << false << quint32(0xffffffff); } void tst_QScriptString::toArrayIndex() -- 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 28e3d3516ebe88f7353fde44194aba5b7d1d8710 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 23 Feb 2010 13:43:50 +0100 Subject: doc: Added QScopedArrayPointer and corrected QScopedPointer snippet. Task: QTBUG-7766 --- .../code/src_corelib_tools_qscopedpointer.cpp | 2 +- src/corelib/tools/qscopedpointer.cpp | 55 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp index c068ba9..4158388 100644 --- a/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp +++ b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp @@ -128,7 +128,7 @@ private: QScopedPointer > arrayPointer(new int[42]); // this QScopedPointer frees its data using free(): -QScopedPointer > podPointer(reinterpret_cast(malloc(42))); +QScopedPointer podPointer(reinterpret_cast(malloc(42))); // this struct calls "myCustomDeallocator" to delete the pointer struct ScopedPointerCustomDeleter diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp index 12badf0..e7dd769 100644 --- a/src/corelib/tools/qscopedpointer.cpp +++ b/src/corelib/tools/qscopedpointer.cpp @@ -225,4 +225,59 @@ QT_BEGIN_NAMESPACE Swap this pointer with \a other. */ +/*! + \class QScopedArrayPointer + + \brief The QScopedArrayPointer class stores a pointer to a + dynamically allocated array of objects, and deletes it upon + destruction. + + \since 4.6 + \reentrant + \ingroup misc + + A QScopedArrayPointer is a QScopedPointer that defaults to + deleting the object it is pointing to with the delete[] operator. It + also features operator[] for convenience, so we can write: + + \code + void foo() + { + QScopedArrayPointer i(new int[10]); + i[2] = 42; + ... + return; // our integer array is now deleted using delete[] + } + \endcode +*/ + +/*! + \fn QScopedArrayPointer::QScopedArrayPointer(T *p = 0) + + Constructs this QScopedArrayPointer instance and sets its pointer + to \a p. +*/ + +/*! + \fn T *QScopedArrayPointer::operator[](int i) + + Provides access to entry \a i of the scoped pointer's array of + objects. + + If the contained pointer is \c null, behavior is undefined. + + \sa isNull() +*/ + +/*! + \fn T *QScopedArrayPointer::operator[](int i) const + + Provides access to entry \a i of the scoped pointer's array of + objects. + + If the contained pointer is \c null, behavior is undefined. + + \sa isNull() +*/ + QT_END_NAMESPACE -- 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