diff options
28 files changed, 588 insertions, 36 deletions
@@ -107,6 +107,7 @@ tests/auto/qprocess/fileWriterProcess.txt tests/auto/qlibrary/libmylib.so* tests/auto/qresourceengine/runtime_resource.rcc tools/qdoc3/qdoc3* +tools/qtestlib/chart/chart* tools/qtestlib/updater/updater* tools/activeqt/testcon/testcon.tlb translations/*.qm diff --git a/examples/declarative/tabwidget/TabWidget.qml b/examples/declarative/tabwidget/TabWidget.qml new file mode 100644 index 0000000..c56f41e --- /dev/null +++ b/examples/declarative/tabwidget/TabWidget.qml @@ -0,0 +1,42 @@ +import Qt 4.6 + +Item { + id: page + property int current: 0 + default property alias content: stack.children + onCurrentChanged: setOpacities() + Component.onCompleted: setOpacities() + function setOpacities() + { + for (var i=0; i<stack.children.length; ++i) { + stack.children[i].opacity = i==current ? 1 : 0 + } + } + Row { + id: header + Repeater { + delegate: + Rectangle { + width: page.width / stack.children.length + height: 15 + color: page.current == index ? "grey" : "lightGrey" + Text { + anchors.fill: parent + text: stack.children[index].title + elide: Text.ElideRight + } + MouseRegion { + anchors.fill: parent + onClicked: page.current = index + } + } + model: stack.children.length + } + } + Item { + id: stack + anchors.top: header.bottom + anchors.bottom: page.bottom + width: page.width + } +} diff --git a/examples/declarative/tabwidget/tabs.qml b/examples/declarative/tabwidget/tabs.qml new file mode 100644 index 0000000..54ed7df --- /dev/null +++ b/examples/declarative/tabwidget/tabs.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +TabWidget { + id: tabs + width: 200 + height: 200 + current: 2 + Rectangle { + property string title: "Red" + color: "red" + anchors.fill: parent + Text { anchors.centerIn: parent; text: "<div align=center>Roses are red"; font.pixelSize: 24 + wrap: true; width: parent.width-20 } + } + Rectangle { + property string title: "Green" + color: "green" + anchors.fill: parent + Text { anchors.centerIn: parent; text: "<div align=center>Flower stems are green"; font.pixelSize: 24; + wrap: true; width: parent.width-20 } + } + Rectangle { + property string title: "Blue" + color: "blue" + anchors.fill: parent + Text { anchors.centerIn: parent; text: "<div align=center>Violets are blue"; color: "white"; font.pixelSize: 24 + wrap: true; width: parent.width-20 } + } +} diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index fb6afb1..263aea5 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -2307,7 +2307,7 @@ void QmlGraphicsItem::setBaselineOffset(qreal offset) Opacity is an \e inherited attribute. That is, the opacity is also applied individually to child items. In almost all cases this is what you want. If you can spot the issue in the following - example, you might need to use an opacity filter (not yet available) instead. + example, you might need to use an \l Opacity effect instead. \table \row diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index a3c5c59..5491fd7 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -732,11 +732,11 @@ bool QmlListModelParser::compileProperty(const QmlCustomParserProperty &prop, QL for(int jj = 0; jj < props.count(); ++jj) { const QmlCustomParserProperty &nodeProp = props.at(jj); if (nodeProp.name() == "") { - error(nodeProp, QLatin1String("Cannot use default property in ListModel")); + error(nodeProp, QmlListModel::tr("ListElement: cannot use default property")); return false; } if (nodeProp.name() == "id") { - error(nodeProp, QLatin1String("Cannot use reserved \"id\" property in ListModel")); + error(nodeProp, QmlListModel::tr("ListElement: cannot use reserved \"id\" property")); return false; } @@ -792,7 +792,7 @@ QByteArray QmlListModelParser::compile(const QList<QmlCustomParserProperty> &cus for(int ii = 0; ii < customProps.count(); ++ii) { const QmlCustomParserProperty &prop = customProps.at(ii); if(prop.name() != "") { // isn't default property - error(prop, QLatin1String("Cannot use default property")); + error(prop, QmlListModel::tr("ListModel: undefined property '%1'").arg(QString::fromUtf8(prop.name()))); return QByteArray(); } diff --git a/src/declarative/util/qmlnumberformatter.cpp b/src/declarative/util/qmlnumberformatter.cpp index b09be5b..fce35d9 100644 --- a/src/declarative/util/qmlnumberformatter.cpp +++ b/src/declarative/util/qmlnumberformatter.cpp @@ -97,7 +97,7 @@ QmlNumberFormatter::~QmlNumberFormatter() \qmlproperty string NumberFormatter::text The number in the specified format. - <br> + If no format is specified the text will be empty. */ @@ -123,38 +123,82 @@ qreal QmlNumberFormatter::number() const \qmlproperty string NumberFormatter::format The particular format the number will adhere to during the conversion to text. - <br> + The format syntax follows a style similar to the Unicode Standard (UTS35). The table below shows the characters, patterns that can be used in the format. - <table border="0" align="center"> - <tr style="background-color: #D6E2E8"><th> Character </th><th> Meaning </th></tr> - <tr><td> # </td><td> Any digit(s), zero shows as absent (for leading/trailing zeroes) </td></tr> - <tr><td> 0 </td><td> Implicit digit. Zero will show in the case that the input number is too small.</td></tr> - <tr><td> . </td><td> Decimal separator. Output decimal seperator will be dependant on system locale.</td></tr> - <tr><td> , </td><td> Grouping separator. The number of digits (either #, or 0) between the grouping separator and the decimal (or the rightmost digit) will determine the groupingSize)</td></tr> - <tr><td> other </td><td> Any other character will be taken as a string literal and placed directly into the output string </td></tr> - </table> + \table + \header + \o Character + \o Meaning + \row + \o # + \o Any digit(s), zero shows as absent (for leading/trailing zeroes). + \row + \o 0 + \o Implicit digit. Zero will show in the case that the input number is too small. + \row + \o . + \o Decimal separator. Output decimal seperator will be dependant on system locale. + \row + \o , + \o Grouping separator. The number of digits (either #, or 0) between the grouping separator and the decimal (or the rightmost digit) will determine the groupingSize). + \row + \o other + \o Any other character will be taken as a string literal and placed directly into the output string. + \endtable - Invalid formats will not guarantee a meaningful text output.<br> + Invalid formats will not guarantee a meaningful text output. - \note <i>Input numbers that are too long for the given format will be rounded dependent on precison based on the position of the decimal point </i> + \note Input numbers that are too long for the given format will be rounded dependent on precison based on the position of the decimal point. The following table illustrates the output text created by applying some examples of numeric formats to the formatter. - <table border="0" align="center"> - <tr style="background-color: #D6E2E8"><th> Format </th><th> Number </th><th> Output </th></tr> - <tr><td> ### </td><td> 123456 </td><td> 123456 </td></tr> - <tr><td> 000 </td><td> 123456 </td><td> 123456 </td></tr> - <tr><td> ###### </td><td> 1234 </td><td> 1234 </td></tr> - <tr><td> 000000 </td><td> 1234 </td><td> 001234 </td></tr> - <tr><td> ##,##0.## </td><td> 1234.456 </td><td> 1,234.46 (for US locale)<br> 1 234,46 (for FR locale)</td></tr> - <tr><td> 000000,000.# </td><td> 123456 </td><td> 000,123,456 (for US locale)<br> 000 123 456 (for FR locale)</td></tr> - <tr><td> 0.0### </td><td> 0.999997 </td><td> 1.0 </td></tr> - <tr><td> (000) 000 - 000 </td><td> 12345678 </td><td> (012) 345 - 678 </td></tr> - <tr><td> #A</td><td>12</td><td>12A</td></tr> - </table> + \table + \header + \o Format + \o Number + \o Output + \row + \o ### + \o 123456 + \o 123456 + \row + \o 000 + \o 123456 + \o 123456 + \row + \o ###### + \o 1234 + \o 1234 + \row + \o 000000 + \o 1234 + \o 001234 + \row + \o ##,##0.## + \o 1234.456 + \o 1,234.46 (for US locale) + \codeline 1 234,46 (for FR locale) + \row + \o 000000,000.# + \o 123456 + \o 000,123,456 (for US locale) + \codeline 000 123 456 (for FR locale) + \row + \o 0.0### + \o 0.999997 + \o 1.0 + \row + \o (000) 000 - 000 + \o 12345678 + \o (012) 345 - 678 + \row + \o #A + \o 12 + \o 12A + \endtable */ QString QmlNumberFormatter::format() const diff --git a/src/declarative/util/qmlstate_p_p.h b/src/declarative/util/qmlstate_p_p.h index 095a7d2..75eb3fd 100644 --- a/src/declarative/util/qmlstate_p_p.h +++ b/src/declarative/util/qmlstate_p_p.h @@ -102,7 +102,30 @@ public: QString name; QmlBinding *when; - QmlConcreteList<QmlStateOperation *> operations; + + class OperationList; + struct OperationGuard : public QGuard<QmlStateOperation> + { + OperationGuard(QObject *obj, OperationList *l) : list(l) { (QGuard<QObject>&)*this = obj; } + OperationList *list; + void objectDestroyed(QmlStateOperation *) { + // we assume priv will always be destroyed after objectDestroyed calls + list->removeOne(*this); + } + }; + + typedef QList<OperationGuard> GuardedOpList; + class OperationList : public GuardedOpList, public QmlList<QmlStateOperation*> + { + public: + virtual void append(QmlStateOperation* v) { GuardedOpList::append(OperationGuard(v, this)); } + virtual void insert(int i, QmlStateOperation* v) { GuardedOpList::insert(i, OperationGuard(v, this)); } + virtual void clear() { GuardedOpList::clear(); } + virtual QmlStateOperation* at(int i) const { return GuardedOpList::at(i); } + virtual void removeAt(int i) { GuardedOpList::removeAt(i); } + virtual int count() const { return GuardedOpList::count(); } + }; + OperationList operations; QmlTransitionManager transitionManager; diff --git a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp index 92b2c1a..1481dae 100644 --- a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp +++ b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp @@ -993,7 +993,6 @@ void tst_QMetaObjectBuilder::serialize() QMetaObjectBuilder builder; builder.setClassName("Test"); builder.addProperty("foo", "int"); - builder.setSuperClass(0); QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly | QIODevice::Append); diff --git a/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp index 6bd28fb..543ba3f 100644 --- a/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp +++ b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp @@ -143,6 +143,7 @@ void tst_qmlgraphicswebview::basicProperties() QCOMPARE(strippedHtml(fileContents(SRCDIR "/data/basic.html")), strippedHtml(wv->html())); QCOMPARE(wv->width(), 123.0); QCOMPARE(wv->preferredWidth(), 0); + QCOMPARE(wv->preferredHeight(), 0); QCOMPARE(wv->zoomFactor(), 1.0); QCOMPARE(wv->url(), QUrl::fromLocalFile(SRCDIR "/data/basic.html")); QCOMPARE(wv->status(), QmlGraphicsWebView::Ready); diff --git a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp index 80efd94..f2ffb7b 100644 --- a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp +++ b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp @@ -41,6 +41,7 @@ #include <qtest.h> #include <QtDeclarative/private/qmllistmodel_p.h> #include <QtDeclarative/private/qmlexpression_p.h> +#include <QmlComponent> #include <QDebug> class tst_QmlListModel : public QObject @@ -52,6 +53,8 @@ public: private slots: void dynamic_data(); void dynamic(); + void error_data(); + void error(); }; void tst_QmlListModel::dynamic_data() @@ -104,6 +107,7 @@ void tst_QmlListModel::dynamic_data() QTest::newRow("set4a") << "{set(0,{'foo':456})}" << 0 << "QML QmlListModel (unknown location) set: index 0 out of range"; QTest::newRow("set5a") << "{append({'foo':123,'bar':456});set(0,123)}" << 0 << "QML QmlListModel (unknown location) set: value is not an object"; QTest::newRow("set5b") << "{append({'foo':123,'bar':456});set(0,[1,2,3])}" << 0 << "QML QmlListModel (unknown location) set: value is not an object"; + QTest::newRow("set6") << "{append({'foo':123});set(1,{'foo':456});count}" << 2 << ""; QTest::newRow("setprop1") << "{append({'foo':123});set(0,'foo',456);count}" << 1 << ""; QTest::newRow("setprop2") << "{append({'foo':123});set(0,'foo',456);get(0).foo}" << 456 << ""; @@ -111,6 +115,7 @@ void tst_QmlListModel::dynamic_data() QTest::newRow("setprop3b") << "{append({'foo':123,'bar':456});set(0,'foo',999);get(0).bar}" << 456 << ""; QTest::newRow("setprop4a") << "{set(0,'foo',456)}" << 0 << "QML QmlListModel (unknown location) set: index 0 out of range"; QTest::newRow("setprop4a") << "{append({'foo':123,'bar':456});set(1,'foo',456)}" << 0 << "QML QmlListModel (unknown location) set: index 1 out of range"; + QTest::newRow("setprop5") << "{append({'foo':123,'bar':456});append({'foo':111});set(1,'bar',222);get(1).bar}" << 222 << ""; QTest::newRow("move1a") << "{append({'foo':123});append({'foo':456});move(0,1,1);count}" << 2 << ""; QTest::newRow("move1b") << "{append({'foo':123});append({'foo':456});move(0,1,1);get(0).foo}" << 456 << ""; @@ -153,6 +158,56 @@ void tst_QmlListModel::dynamic() QCOMPARE(actual,result); } +void tst_QmlListModel::error_data() +{ + QTest::addColumn<QString>("qml"); + QTest::addColumn<QString>("error"); + + QTest::newRow("id not allowed in ListElement") + << "import Qt 4.6\nListModel { ListElement { id: fred } }" + << "ListElement: cannot use reserved \"id\" property"; + + QTest::newRow("id allowed in ListModel") + << "import Qt 4.6\nListModel { id:model }" + << ""; + + QTest::newRow("random properties not allowed in ListModel") + << "import Qt 4.6\nListModel { foo:123 }" + << "ListModel: undefined property 'foo'"; + + QTest::newRow("random properties allowed in ListElement") + << "import Qt 4.6\nListModel { ListElement { foo:123 } }" + << ""; + + QTest::newRow("random object list properties allowed in ListElement") + << "import Qt 4.6\nListModel { ListElement { foo: [ ListElement { bar: 123 } ] } }" + << ""; + + QTest::newRow("default properties not allowed in ListElement") + << "import Qt 4.6\nListModel { ListElement { Item { } } }" + << "QTBUG-6082 ListElement should not allow child objects"; +} + +void tst_QmlListModel::error() +{ + QFETCH(QString, qml); + QFETCH(QString, error); + + QmlEngine engine; + QmlComponent component(&engine, qml.toUtf8(), + QUrl::fromLocalFile(QString("dummy.qml"))); + if (error.isEmpty()) { + QVERIFY(!component.isError()); + } else { + if (error.startsWith(QLatin1String("QTBUG-"))) + QEXPECT_FAIL("",error.toLatin1(),Abort); + QVERIFY(component.isError()); + QList<QmlError> errors = component.errors(); + QCOMPARE(errors.count(),1); + QCOMPARE(errors.at(0).description(),error); + } +} + QTEST_MAIN(tst_QmlListModel) #include "tst_qmllistmodel.moc" diff --git a/tests/auto/declarative/states/data/deleting.qml b/tests/auto/declarative/states/data/deleting.qml new file mode 100644 index 0000000..0c512dd --- /dev/null +++ b/tests/auto/declarative/states/data/deleting.qml @@ -0,0 +1,11 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { target: MyRectangle; color: "blue"; objectName: "pc1" } + PropertyChanges { target: MyRectangle; radius: 5; objectName: "pc2" } + } +} diff --git a/tests/auto/declarative/states/data/deletingState.qml b/tests/auto/declarative/states/data/deletingState.qml new file mode 100644 index 0000000..9dc46a6 --- /dev/null +++ b/tests/auto/declarative/states/data/deletingState.qml @@ -0,0 +1,13 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + StateGroup { + id: stateGroup + states: State { + name: "blue" + PropertyChanges { target: MyRectangle; color: "blue" } + } + } +} diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index a4da1f1..4847535 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -44,6 +44,7 @@ #include <private/qmlgraphicsanchors_p_p.h> #include <private/qmlgraphicsrectangle_p.h> #include <private/qmlpropertychanges_p.h> +#include <private/qmlstategroup_p.h> class tst_states : public QObject { @@ -69,6 +70,8 @@ private slots: void explicitChanges(); void propertyErrors(); void incorrectRestoreBug(); + void deletingChange(); + void deletingState(); }; void tst_states::basicChanges() @@ -738,6 +741,68 @@ void tst_states::incorrectRestoreBug() QCOMPARE(rect->color(),QColor("green")); } +void tst_states::deletingChange() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/deleting.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->radius(),qreal(5)); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->radius(),qreal(0)); + + QmlPropertyChanges *pc = rect->findChild<QmlPropertyChanges*>("pc1"); + QVERIFY(pc != 0); + delete pc; + + QmlState *state = rect->findChild<QmlState*>(); + QVERIFY(state != 0); + QCOMPARE(state->changes()->count(), 1); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->radius(),qreal(5)); + + delete rect; +} + +void tst_states::deletingState() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/deletingState.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlStateGroup *sg = rect->findChild<QmlStateGroup*>(); + QVERIFY(sg != 0); + QVERIFY(sg->findState("blue") != 0); + + sg->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + sg->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + QmlState *state = rect->findChild<QmlState*>(); + QVERIFY(state != 0); + delete state; + + QVERIFY(sg->findState("blue") == 0); + + //### should we warn that state doesn't exist + sg->setState("blue"); + QCOMPARE(rect->color(),QColor("red")); + + delete rect; +} + QTEST_MAIN(tst_states) #include "tst_states.moc" diff --git a/tests/benchmarks/declarative/binding/binding.pro b/tests/benchmarks/declarative/binding/binding.pro index 26ee4fa..e25f186 100644 --- a/tests/benchmarks/declarative/binding/binding.pro +++ b/tests/benchmarks/declarative/binding/binding.pro @@ -2,6 +2,7 @@ load(qttest_p4) TEMPLATE = app TARGET = tst_binding QT += declarative +macx:CONFIG -= app_bundle SOURCES += tst_binding.cpp testtypes.cpp HEADERS += testtypes.h diff --git a/tests/benchmarks/declarative/binding/idproperty.txt b/tests/benchmarks/declarative/binding/idproperty.txt index 0a98e0d..71e3c4e 100644 --- a/tests/benchmarks/declarative/binding/idproperty.txt +++ b/tests/benchmarks/declarative/binding/idproperty.txt @@ -1,3 +1,5 @@ +import Test 1.0 + MyQmlObject { id: MyObject diff --git a/tests/benchmarks/declarative/binding/localproperty.txt b/tests/benchmarks/declarative/binding/localproperty.txt index 4694d99..c7ca0ef 100644 --- a/tests/benchmarks/declarative/binding/localproperty.txt +++ b/tests/benchmarks/declarative/binding/localproperty.txt @@ -1,3 +1,5 @@ +import Test 1.0 + MyQmlObject { result: ### } diff --git a/tests/benchmarks/declarative/binding/testtypes.cpp b/tests/benchmarks/declarative/binding/testtypes.cpp index 9dad523..892738c 100644 --- a/tests/benchmarks/declarative/binding/testtypes.cpp +++ b/tests/benchmarks/declarative/binding/testtypes.cpp @@ -40,4 +40,4 @@ ****************************************************************************/ #include "testtypes.h" -QML_DEFINE_TYPE(MyQmlObject, MyQmlObject); +QML_DEFINE_TYPE(Test, 1, 0, MyQmlObject, MyQmlObject); diff --git a/tests/benchmarks/declarative/creation/creation.pro b/tests/benchmarks/declarative/creation/creation.pro new file mode 100644 index 0000000..fcc2987 --- /dev/null +++ b/tests/benchmarks/declarative/creation/creation.pro @@ -0,0 +1,10 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_creation +QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += tst_creation.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" + diff --git a/tests/benchmarks/declarative/creation/data/qobject.qml b/tests/benchmarks/declarative/creation/data/qobject.qml new file mode 100644 index 0000000..99d010f --- /dev/null +++ b/tests/benchmarks/declarative/creation/data/qobject.qml @@ -0,0 +1,4 @@ +import Qt 4.6 + +QtObject { +} diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp new file mode 100644 index 0000000..99411d4 --- /dev/null +++ b/tests/benchmarks/declarative/creation/tst_creation.cpp @@ -0,0 +1,247 @@ +/**************************************************************************** +** +** Copyright (C) 2009 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 <qtest.h> +#include <QmlEngine> +#include <QmlComponent> +#include <QmlMetaType> +#include <QDebug> +#include <QGraphicsItem> +#include <private/qobject_p.h> + +class tst_creation : public QObject +{ + Q_OBJECT +public: + tst_creation() {} + +private slots: + void qobject_cpp(); + void qobject_qml(); + void qobject_qmltype(); + void qobject_alloc(); + + void objects_qmltype_data(); + void objects_qmltype(); + + void qgraphicsitem(); + void qgraphicsitem_tree(); + +private: + QmlEngine engine; +}; + +inline QUrl TEST_FILE(const QString &filename) +{ + return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); +} + +void tst_creation::qobject_cpp() +{ + QBENCHMARK { + QObject *obj = new QObject; + delete obj; + } +} + +void tst_creation::qobject_qml() +{ + QmlComponent component(&engine, TEST_FILE("qobject.qml")); + QObject *obj = component.create(); + delete obj; + + QBENCHMARK { + QObject *obj = component.create(); + delete obj; + } +} + +void tst_creation::qobject_qmltype() +{ + QmlType *t = QmlMetaType::qmlType("Qt/QtObject", 4, 6); + + QBENCHMARK { + QObject *obj = t->create(); + delete obj; + } +} + +struct QObjectFakeData { + char data[sizeof(QObjectPrivate)]; +}; + +struct QObjectFake { + QObjectFake(); + virtual ~QObjectFake(); +private: + QObjectFakeData *d; +}; + +QObjectFake::QObjectFake() +{ + d = new QObjectFakeData; +} + +QObjectFake::~QObjectFake() +{ + delete d; +} + +void tst_creation::qobject_alloc() +{ + QBENCHMARK { + QObjectFake *obj = new QObjectFake; + delete obj; + } +} + +void tst_creation::objects_qmltype_data() +{ + QTest::addColumn<QByteArray>("type"); + + QList<QByteArray> types = QmlMetaType::qmlTypeNames(); + foreach (QByteArray type, types) + QTest::newRow(type.constData()) << type; +} + +void tst_creation::objects_qmltype() +{ + QFETCH(QByteArray, type); + QmlType *t = QmlMetaType::qmlType(type, 4, 6); + + QBENCHMARK { + QObject *obj = t->create(); + delete obj; + } +} + +class QGraphicsItemDummy : public QGraphicsItem +{ +public: + virtual QRectF boundingRect() const { return QRectF(); } + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} +}; + +void tst_creation::qgraphicsitem() +{ + QBENCHMARK { + QGraphicsItemDummy *i1 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i2 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i3 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i4 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i5 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i6 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i7 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i8 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i9 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i10 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i11 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i12 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i13 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i14 = new QGraphicsItemDummy(); + + delete i1; + delete i2; + delete i3; + delete i4; + delete i5; + delete i6; + delete i7; + delete i8; + delete i9; + delete i10; + delete i11; + delete i12; + delete i13; + delete i14; + } +} + +void tst_creation::qgraphicsitem_tree() +{ + QBENCHMARK { + // i1 + // +-------------------------+ + // i2 i3 + // +-----------+ +-----+-----+ + // i4 i5 i6 i7 + // +----+ +--+ +--+--+ +----+ + // i8 i9 i10 i11 i12 i13 i14 + + QGraphicsItemDummy *i1 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i2 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i3 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i4 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i5 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i6 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i7 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i8 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i9 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i10 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i11 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i12 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i13 = new QGraphicsItemDummy(); + QGraphicsItemDummy *i14 = new QGraphicsItemDummy(); + + i14->setParentItem(i7); + i13->setParentItem(i7); + i12->setParentItem(i6); + i11->setParentItem(i6); + i10->setParentItem(i5); + i9->setParentItem(i4); + i8->setParentItem(i4); + + i7->setParentItem(i3); + i6->setParentItem(i3); + i5->setParentItem(i2); + i4->setParentItem(i2); + + i3->setParentItem(i1); + i2->setParentItem(i1); + + delete i1; + } +} + + +QTEST_MAIN(tst_creation) + +#include "tst_creation.moc" diff --git a/tests/benchmarks/declarative/pointers/pointers.pro b/tests/benchmarks/declarative/pointers/pointers.pro index fafdcd6..6de6e31 100644 --- a/tests/benchmarks/declarative/pointers/pointers.pro +++ b/tests/benchmarks/declarative/pointers/pointers.pro @@ -1,6 +1,7 @@ load(qttest_p4) TEMPLATE = app TARGET = tst_pointers +macx:CONFIG -= app_bundle SOURCES += tst_pointers.cpp diff --git a/tests/benchmarks/declarative/qmlcomponent/object.txt b/tests/benchmarks/declarative/qmlcomponent/object.txt index 85e74b9..0d2d49b 100644 --- a/tests/benchmarks/declarative/qmlcomponent/object.txt +++ b/tests/benchmarks/declarative/qmlcomponent/object.txt @@ -1,3 +1,3 @@ import Qt 4.6 -Object {} +QtObject {} diff --git a/tests/benchmarks/declarative/qmlcomponent/object_id.txt b/tests/benchmarks/declarative/qmlcomponent/object_id.txt index 526b6ad..69114af 100644 --- a/tests/benchmarks/declarative/qmlcomponent/object_id.txt +++ b/tests/benchmarks/declarative/qmlcomponent/object_id.txt @@ -1,6 +1,6 @@ import Qt 4.6 -Object { +QtObject { id: Blah } diff --git a/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro b/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro index 5f0cbe6..6a86f58 100644 --- a/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro +++ b/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro @@ -2,6 +2,7 @@ load(qttest_p4) TEMPLATE = app TARGET = tst_qmlcomponent QT += declarative +macx:CONFIG -= app_bundle SOURCES += tst_qmlcomponent.cpp testtypes.cpp HEADERS += testtypes.h diff --git a/tests/benchmarks/declarative/qmlcomponent/synthesized_properties.2.txt b/tests/benchmarks/declarative/qmlcomponent/synthesized_properties.2.txt index 90db37c..27c5646 100644 --- a/tests/benchmarks/declarative/qmlcomponent/synthesized_properties.2.txt +++ b/tests/benchmarks/declarative/qmlcomponent/synthesized_properties.2.txt @@ -1,6 +1,6 @@ import Qt 4.6 -Object { +QtObject { property int a property bool b property double c diff --git a/tests/benchmarks/declarative/qmlcomponent/synthesized_properties.txt b/tests/benchmarks/declarative/qmlcomponent/synthesized_properties.txt index bb5469a..d08f35b 100644 --- a/tests/benchmarks/declarative/qmlcomponent/synthesized_properties.txt +++ b/tests/benchmarks/declarative/qmlcomponent/synthesized_properties.txt @@ -1,5 +1,5 @@ import Qt 4.6 -Object { +QtObject { property int a } diff --git a/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp b/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp index 8350211..56d20c6 100644 --- a/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp +++ b/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp @@ -40,4 +40,4 @@ ****************************************************************************/ #include "testtypes.h" -QML_DEFINE_TYPE(Qt/test, 4, 6, 6, MyQmlObject, MyQmlObject); +QML_DEFINE_TYPE(Qt.test, 4, 6, MyQmlObject, MyQmlObject); diff --git a/tests/benchmarks/declarative/qmlmetaproperty/qmlmetaproperty.pro b/tests/benchmarks/declarative/qmlmetaproperty/qmlmetaproperty.pro index b4e83d7..c18a56b 100644 --- a/tests/benchmarks/declarative/qmlmetaproperty/qmlmetaproperty.pro +++ b/tests/benchmarks/declarative/qmlmetaproperty/qmlmetaproperty.pro @@ -2,6 +2,7 @@ load(qttest_p4) TEMPLATE = app TARGET = tst_qmlmetaproperty QT += declarative +macx:CONFIG -= app_bundle SOURCES += tst_qmlmetaproperty.cpp |