From f208442b257015888d4903e6202772a7836d70a7 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 27 Apr 2010 14:49:46 +1000 Subject: make quitable --- demos/declarative/flickr/mobile/TitleBar.qml | 13 ++++++++++++- demos/declarative/flickr/mobile/images/quit.png | Bin 0 -> 2369 bytes 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 demos/declarative/flickr/mobile/images/quit.png diff --git a/demos/declarative/flickr/mobile/TitleBar.qml b/demos/declarative/flickr/mobile/TitleBar.qml index 71d9385..bb57429 100644 --- a/demos/declarative/flickr/mobile/TitleBar.qml +++ b/demos/declarative/flickr/mobile/TitleBar.qml @@ -18,10 +18,21 @@ Item { rssModel.tags = editor.text } + Image { + id: quitButton + anchors.left: parent.left//; anchors.leftMargin: 0 + anchors.verticalCenter: parent.verticalCenter + source: "images/quit.png" + MouseArea { + anchors.fill: parent + onClicked: Qt.quit() + } + } + Text { id: categoryText anchors { - left: parent.left; right: tagButton.left; leftMargin: 10; rightMargin: 10 + left: quitButton.right; right: tagButton.left; leftMargin: 10; rightMargin: 10 verticalCenter: parent.verticalCenter } elide: Text.ElideLeft diff --git a/demos/declarative/flickr/mobile/images/quit.png b/demos/declarative/flickr/mobile/images/quit.png new file mode 100644 index 0000000..5bda1b6 Binary files /dev/null and b/demos/declarative/flickr/mobile/images/quit.png differ -- cgit v0.12 From 946134b0ff303a1b44ae1ce5e3dcde7bfd8febcc Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Tue, 27 Apr 2010 19:06:32 +1000 Subject: Setting conflicting anchors to items inside positioners should print a warning Task-number: QTBUG-9025 Reviewed-by: Martin Jones --- .../graphicsitems/qdeclarativepositioners.cpp | 69 +++++++++++++++++++++ .../graphicsitems/qdeclarativepositioners_p.h | 6 +- .../tst_qdeclarativepositioners.cpp | 72 ++++++++++++++++++++++ 3 files changed, 146 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 21c33e2..32a512b 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -165,6 +166,7 @@ void QDeclarativeBasePositioner::componentComplete() QDeclarativeItem::componentComplete(); positionedItems.reserve(d->QGraphicsItemPrivate::children.count()); prePositioning(); + reportConflictingAnchors(); } QVariant QDeclarativeBasePositioner::itemChange(GraphicsItemChange change, @@ -436,6 +438,26 @@ void QDeclarativeColumn::doPositioning(QSizeF *contentSize) contentSize->setHeight(voffset - spacing()); } +void QDeclarativeColumn::reportConflictingAnchors() +{ + bool childsWithConflictingAnchors(false); + for (int ii = 0; ii < positionedItems.count(); ++ii) { + const PositionedItem &child = positionedItems.at(ii); + if (child.item) { + QDeclarativeAnchors::Anchors usedAnchors = child.item->anchors()->usedAnchors(); + if (usedAnchors & QDeclarativeAnchors::TopAnchor || + usedAnchors & QDeclarativeAnchors::BottomAnchor || + usedAnchors & QDeclarativeAnchors::VCenterAnchor) { + childsWithConflictingAnchors = true; + break; + } + } + } + if (childsWithConflictingAnchors) { + qmlInfo(this) << "Cannot specify top, bottom or verticalCenter anchors for items inside Column"; + } +} + /*! \qmlclass Row QDeclarativeRow \since 4.7 @@ -551,6 +573,25 @@ void QDeclarativeRow::doPositioning(QSizeF *contentSize) contentSize->setWidth(hoffset - spacing()); } +void QDeclarativeRow::reportConflictingAnchors() +{ + bool childsWithConflictingAnchors(false); + for (int ii = 0; ii < positionedItems.count(); ++ii) { + const PositionedItem &child = positionedItems.at(ii); + if (child.item) { + QDeclarativeAnchors::Anchors usedAnchors = child.item->anchors()->usedAnchors(); + if (usedAnchors & QDeclarativeAnchors::LeftAnchor || + usedAnchors & QDeclarativeAnchors::RightAnchor || + usedAnchors & QDeclarativeAnchors::HCenterAnchor) { + childsWithConflictingAnchors = true; + break; + } + } + } + if (childsWithConflictingAnchors) { + qmlInfo(this) << "Cannot specify left, right or horizontalCenter anchors for items inside Row"; + } +} /*! \qmlclass Grid QDeclarativeGrid @@ -823,6 +864,20 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize) } } +void QDeclarativeGrid::reportConflictingAnchors() +{ + bool childsWithConflictingAnchors(false); + for (int ii = 0; ii < positionedItems.count(); ++ii) { + const PositionedItem &child = positionedItems.at(ii); + if (child.item && child.item->anchors()->usedAnchors()) { + childsWithConflictingAnchors = true; + break; + } + } + if (childsWithConflictingAnchors) { + qmlInfo(this) << "Cannot specify anchors for items inside Grid"; + } +} /*! \qmlclass Flow QDeclarativeFlow @@ -966,5 +1021,19 @@ void QDeclarativeFlow::doPositioning(QSizeF *contentSize) } } +void QDeclarativeFlow::reportConflictingAnchors() +{ + bool childsWithConflictingAnchors(false); + for (int ii = 0; ii < positionedItems.count(); ++ii) { + const PositionedItem &child = positionedItems.at(ii); + if (child.item && child.item->anchors()->usedAnchors()) { + childsWithConflictingAnchors = true; + break; + } + } + if (childsWithConflictingAnchors) { + qmlInfo(this) << "Cannot specify anchors for items inside Flow"; + } +} QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativepositioners_p.h b/src/declarative/graphicsitems/qdeclarativepositioners_p.h index b5fc979..787dcd3 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners_p.h +++ b/src/declarative/graphicsitems/qdeclarativepositioners_p.h @@ -94,6 +94,7 @@ protected Q_SLOTS: protected: virtual void doPositioning(QSizeF *contentSize)=0; + virtual void reportConflictingAnchors()=0; struct PositionedItem { PositionedItem(QDeclarativeItem *i) : item(i), isNew(false), isVisible(true) {} bool operator==(const PositionedItem &other) const { return other.item == item; } @@ -118,6 +119,7 @@ public: QDeclarativeColumn(QDeclarativeItem *parent=0); protected: virtual void doPositioning(QSizeF *contentSize); + virtual void reportConflictingAnchors(); private: Q_DISABLE_COPY(QDeclarativeColumn) }; @@ -129,6 +131,7 @@ public: QDeclarativeRow(QDeclarativeItem *parent=0); protected: virtual void doPositioning(QSizeF *contentSize); + virtual void reportConflictingAnchors(); private: Q_DISABLE_COPY(QDeclarativeRow) }; @@ -161,6 +164,7 @@ Q_SIGNALS: protected: virtual void doPositioning(QSizeF *contentSize); + virtual void reportConflictingAnchors(); private: int m_rows; @@ -187,7 +191,7 @@ Q_SIGNALS: protected: virtual void doPositioning(QSizeF *contentSize); - + virtual void reportConflictingAnchors(); protected: QDeclarativeFlow(QDeclarativeFlowPrivate &dd, QDeclarativeItem *parent); private: diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp index b4ac0e1..8dc1416 100644 --- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp +++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,7 @@ private slots: void test_repeater(); void test_flow(); void test_flow_resize(); + void test_conflictinganchors(); private: QDeclarativeView *createView(const QString &filename); }; @@ -620,6 +622,76 @@ void tst_QDeclarativePositioners::test_flow_resize() QCOMPARE(five->y(), 50.0); } +QString warningMessage; + +void interceptWarnings(QtMsgType type, const char *msg) +{ + Q_UNUSED( type ); + warningMessage = msg; +} + +void tst_QDeclarativePositioners::test_conflictinganchors() +{ + qInstallMsgHandler(interceptWarnings); + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine); + + component.setData("import Qt 4.7\nColumn { Item {} }", QUrl::fromLocalFile("")); + QDeclarativeItem *item = qobject_cast(component.create()); + QVERIFY(item); + QVERIFY(warningMessage.isEmpty()); + + component.setData("import Qt 4.7\nRow { Item {} }", QUrl::fromLocalFile("")); + item = qobject_cast(component.create()); + QVERIFY(item); + QVERIFY(warningMessage.isEmpty()); + + component.setData("import Qt 4.7\nGrid { Item {} }", QUrl::fromLocalFile("")); + item = qobject_cast(component.create()); + QVERIFY(item); + QVERIFY(warningMessage.isEmpty()); + + component.setData("import Qt 4.7\nFlow { Item {} }", QUrl::fromLocalFile("")); + item = qobject_cast(component.create()); + QVERIFY(item); + QVERIFY(warningMessage.isEmpty()); + + component.setData("import Qt 4.7\nColumn { Item { anchors.top: parent.top } }", QUrl::fromLocalFile("")); + item = qobject_cast(component.create()); + QVERIFY(item); + QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom or verticalCenter anchors for items inside Column")); + warningMessage.clear(); + + component.setData("import Qt 4.7\nColumn { Item { anchors.left: parent.left } }", QUrl::fromLocalFile("")); + item = qobject_cast(component.create()); + QVERIFY(item); + QVERIFY(warningMessage.isEmpty()); + warningMessage.clear(); + + component.setData("import Qt 4.7\nRow { Item { anchors.left: parent.left } }", QUrl::fromLocalFile("")); + item = qobject_cast(component.create()); + QVERIFY(item); + QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right or horizontalCenter anchors for items inside Row")); + warningMessage.clear(); + + component.setData("import Qt 4.7\nRow { Item { anchors.top: parent.top } }", QUrl::fromLocalFile("")); + item = qobject_cast(component.create()); + QVERIFY(item); + QVERIFY(warningMessage.isEmpty()); + warningMessage.clear(); + + component.setData("import Qt 4.7\nGrid { Item { anchors.horizontalCenter: parent.horizontalCenter } }", QUrl::fromLocalFile("")); + item = qobject_cast(component.create()); + QVERIFY(item); + QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid")); + warningMessage.clear(); + + component.setData("import Qt 4.7\nFlow { Item { anchors.verticalCenter: parent.verticalCenter } }", QUrl::fromLocalFile("")); + item = qobject_cast(component.create()); + QVERIFY(item); + QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow")); +} + QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename) { QDeclarativeView *canvas = new QDeclarativeView(0); -- cgit v0.12 From 07bbd16e98a24ccc22804c3766d15f9da406107a Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Tue, 27 Apr 2010 19:11:18 +1000 Subject: Delete canvas after use in positioner unit tests Task-number: Reviewed-by: Martin Jones --- .../tst_qdeclarativepositioners.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp index 8dc1416..7a23773 100644 --- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp +++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp @@ -102,6 +102,8 @@ void tst_QDeclarativePositioners::test_horizontal() QDeclarativeItem *row = canvas->rootObject()->findChild("row"); QCOMPARE(row->width(), 110.0); QCOMPARE(row->height(), 50.0); + + delete canvas; } void tst_QDeclarativePositioners::test_horizontal_spacing() @@ -127,6 +129,8 @@ void tst_QDeclarativePositioners::test_horizontal_spacing() QDeclarativeItem *row = canvas->rootObject()->findChild("row"); QCOMPARE(row->width(), 130.0); QCOMPARE(row->height(), 50.0); + + delete canvas; } void tst_QDeclarativePositioners::test_horizontal_animated() @@ -177,6 +181,8 @@ void tst_QDeclarativePositioners::test_horizontal_animated() QTRY_COMPARE(two->x(), 50.0); QTRY_COMPARE(three->x(), 100.0); + + delete canvas; } void tst_QDeclarativePositioners::test_vertical() @@ -203,6 +209,8 @@ void tst_QDeclarativePositioners::test_vertical() QVERIFY(column); QCOMPARE(column->height(), 80.0); QCOMPARE(column->width(), 50.0); + + delete canvas; } void tst_QDeclarativePositioners::test_vertical_spacing() @@ -228,6 +236,8 @@ void tst_QDeclarativePositioners::test_vertical_spacing() QDeclarativeItem *column = canvas->rootObject()->findChild("column"); QCOMPARE(column->height(), 100.0); QCOMPARE(column->width(), 50.0); + + delete canvas; } void tst_QDeclarativePositioners::test_vertical_animated() @@ -275,6 +285,7 @@ void tst_QDeclarativePositioners::test_vertical_animated() QTRY_COMPARE(two->y(), 50.0); QTRY_COMPARE(three->y(), 100.0); + delete canvas; } void tst_QDeclarativePositioners::test_grid() @@ -306,6 +317,8 @@ void tst_QDeclarativePositioners::test_grid() QDeclarativeItem *grid = canvas->rootObject()->findChild("grid"); QCOMPARE(grid->width(), 120.0); QCOMPARE(grid->height(), 100.0); + + delete canvas; } void tst_QDeclarativePositioners::test_grid_topToBottom() @@ -337,6 +350,8 @@ void tst_QDeclarativePositioners::test_grid_topToBottom() QDeclarativeItem *grid = canvas->rootObject()->findChild("grid"); QCOMPARE(grid->width(), 100.0); QCOMPARE(grid->height(), 120.0); + + delete canvas; } void tst_QDeclarativePositioners::test_grid_spacing() @@ -368,6 +383,8 @@ void tst_QDeclarativePositioners::test_grid_spacing() QDeclarativeItem *grid = canvas->rootObject()->findChild("grid"); QCOMPARE(grid->width(), 128.0); QCOMPARE(grid->height(), 104.0); + + delete canvas; } void tst_QDeclarativePositioners::test_grid_animated() @@ -448,6 +465,7 @@ void tst_QDeclarativePositioners::test_grid_animated() QTRY_COMPARE(five->x(), 50.0); QTRY_COMPARE(five->y(), 50.0); + delete canvas; } void tst_QDeclarativePositioners::test_grid_zero_columns() @@ -479,6 +497,8 @@ void tst_QDeclarativePositioners::test_grid_zero_columns() QDeclarativeItem *grid = canvas->rootObject()->findChild("grid"); QCOMPARE(grid->width(), 170.0); QCOMPARE(grid->height(), 60.0); + + delete canvas; } void tst_QDeclarativePositioners::test_propertychanges() @@ -536,6 +556,8 @@ void tst_QDeclarativePositioners::test_propertychanges() grid->setRows(2); QCOMPARE(columnsSpy.count(),2); QCOMPARE(rowsSpy.count(),2); + + delete canvas; } void tst_QDeclarativePositioners::test_repeater() @@ -557,6 +579,8 @@ void tst_QDeclarativePositioners::test_repeater() QCOMPARE(two->y(), 0.0); QCOMPARE(three->x(), 100.0); QCOMPARE(three->y(), 0.0); + + delete canvas; } void tst_QDeclarativePositioners::test_flow() @@ -589,6 +613,8 @@ void tst_QDeclarativePositioners::test_flow() QVERIFY(flow); QCOMPARE(flow->width(), 90.0); QCOMPARE(flow->height(), 120.0); + + delete canvas; } void tst_QDeclarativePositioners::test_flow_resize() @@ -620,6 +646,8 @@ void tst_QDeclarativePositioners::test_flow_resize() QCOMPARE(four->y(), 50.0); QCOMPARE(five->x(), 50.0); QCOMPARE(five->y(), 50.0); + + delete canvas; } QString warningMessage; -- cgit v0.12 From 3b68034fc7690afc95aba8c049b94b1c6e0f4179 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 28 Apr 2010 11:57:36 +1000 Subject: Emit hoverChanged appropriately when Item visibility changes. Task-number: QTBUG-10243 --- .../graphicsitems/qdeclarativemousearea.cpp | 33 ++++++++++++++++++++++ .../graphicsitems/qdeclarativemousearea_p.h | 7 ++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index 126d041..0b9cf6e 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -599,6 +599,23 @@ void QDeclarativeMouseArea::geometryChanged(const QRectF &newGeometry, d->lastPos = mapFromScene(d->lastScenePos); } +/*! \internal */ +QVariant QDeclarativeMouseArea::itemChange(GraphicsItemChange change, + const QVariant &value) +{ + Q_D(QDeclarativeMouseArea); + switch (change) { + case ItemVisibleHasChanged: + if (acceptHoverEvents() && d->hovered != (isVisible() && isUnderMouse())) + setHovered(!d->hovered); + break; + default: + break; + } + + return QDeclarativeItem::itemChange(change, value); +} + /*! \qmlproperty bool MouseArea::hoverEnabled This property holds whether hover events are handled. @@ -609,6 +626,22 @@ void QDeclarativeMouseArea::geometryChanged(const QRectF &newGeometry, This property affects the containsMouse property and the onEntered, onExited and onPositionChanged signals. */ +bool QDeclarativeMouseArea::hoverEnabled() const +{ + return acceptHoverEvents(); +} + +void QDeclarativeMouseArea::setHoverEnabled(bool h) +{ + Q_D(QDeclarativeMouseArea); + if (h == acceptHoverEvents()) + return; + + setAcceptHoverEvents(h); + emit hoverEnabledChanged(); + if (d->hovered != isUnderMouse()) + setHovered(!d->hovered); +} /*! \qmlproperty bool MouseArea::containsMouse diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h index 4f7df62..e3f523b 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h +++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h @@ -121,7 +121,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeMouseArea : public QDeclarativeItem Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) - Q_PROPERTY(bool hoverEnabled READ acceptHoverEvents WRITE setAcceptHoverEvents) + Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged) Q_PROPERTY(QDeclarativeDrag *drag READ drag CONSTANT) //### add flicking to QDeclarativeDrag or add a QDeclarativeFlick ??? public: @@ -142,6 +142,9 @@ public: Qt::MouseButtons acceptedButtons() const; void setAcceptedButtons(Qt::MouseButtons buttons); + bool hoverEnabled() const; + void setHoverEnabled(bool h); + QDeclarativeDrag *drag(); Q_SIGNALS: @@ -149,6 +152,7 @@ Q_SIGNALS: void pressedChanged(); void enabledChanged(); void acceptedButtonsChanged(); + void hoverEnabledChanged(); void positionChanged(QDeclarativeMouseEvent *mouse); void mousePositionChanged(QDeclarativeMouseEvent *mouse); @@ -176,6 +180,7 @@ protected: virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + virtual QVariant itemChange(GraphicsItemChange change, const QVariant& value); private: void handlePress(); -- cgit v0.12 From f96710f689c8237fabbfb65f56279e2a4d1aca30 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 28 Apr 2010 12:12:05 +1000 Subject: Doc fixes --- doc/src/snippets/declarative/mouseregion.qml | 14 ++++-- .../graphicsitems/qdeclarativeimage.cpp | 2 +- .../graphicsitems/qdeclarativerectangle.cpp | 18 +++++-- .../graphicsitems/qdeclarativerepeater.cpp | 2 +- src/declarative/graphicsitems/qdeclarativetext.cpp | 30 +++++++----- .../graphicsitems/qdeclarativetextedit.cpp | 22 ++++++--- .../graphicsitems/qdeclarativetextinput.cpp | 57 ++++++++++++---------- 7 files changed, 90 insertions(+), 55 deletions(-) diff --git a/doc/src/snippets/declarative/mouseregion.qml b/doc/src/snippets/declarative/mouseregion.qml index a464069..683770b 100644 --- a/doc/src/snippets/declarative/mouseregion.qml +++ b/doc/src/snippets/declarative/mouseregion.qml @@ -3,13 +3,21 @@ import Qt 4.7 Rectangle { width: 200; height: 100 Row { //! [0] -Rectangle { width: 100; height: 100; color: "green" - MouseArea { anchors.fill: parent; onClicked: { parent.color = 'red' } } +Rectangle { + width: 100; height: 100 + color: "green" + + MouseArea { + anchors.fill: parent + onClicked: { parent.color = 'red' } + } } //! [0] //! [1] Rectangle { - width: 100; height: 100; color: "green" + width: 100; height: 100 + color: "green" + MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 247e348..1031493 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE \brief The Image element allows you to add bitmaps to a scene. \inherits Item - The Image element supports untransformed, stretched and tiled. + The Image element supports untransformed, stretched and tiled images. For an explanation of stretching and tiling, see the fillMode property description. diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index 0328f91..fe656fa 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -155,8 +155,8 @@ void QDeclarativeGradient::doUpdate() \brief The Rectangle item allows you to add rectangles to a scene. \inherits Item - A Rectangle is painted having a solid fill (color) and an optional border. - You can also create rounded rectangles using the radius property. + A Rectangle is painted using a solid fill (color) and an optional border. + You can also create rounded rectangles using the \l radius property. \qml Rectangle { @@ -223,14 +223,22 @@ QDeclarativePen *QDeclarativeRectangle::border() \o \image declarative-rect_gradient.png \o \qml - Rectangle { y: 0; width: 80; height: 80; color: "lightsteelblue" } - Rectangle { y: 100; width: 80; height: 80 + Rectangle { + y: 0; width: 80; height: 80 + color: "lightsteelblue" + } + + Rectangle { + y: 100; width: 80; height: 80 gradient: Gradient { GradientStop { position: 0.0; color: "lightsteelblue" } GradientStop { position: 1.0; color: "blue" } } } - Rectangle { rotation: 90; y: 200; width: 80; height: 80 + + Rectangle { + y: 200; width: 80; height: 80 + rotation: 90 gradient: Gradient { GradientStop { position: 0.0; color: "lightsteelblue" } GradientStop { position: 1.0; color: "blue" } diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp index d49bb02..ca0b8c6 100644 --- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp +++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp @@ -67,7 +67,7 @@ QDeclarativeRepeaterPrivate::~QDeclarativeRepeaterPrivate() \brief The Repeater item allows you to repeat an Item-based component using a model. - The Repeater item is used when you want to create a large number of + The Repeater item is used to create a large number of similar items. For each entry in the model, an item is instantiated in a context seeded with data from the model. If the repeater will be instantiating a large number of instances, it may be more efficient to diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 2b8da8e..37a63eb 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -116,7 +116,7 @@ QSet QTextDocumentWithImageResources::errors; \brief The Text item allows you to add formatted text to a scene. \inherits Item - It can display both plain and rich text. For example: + A Text item can display both plain and rich text. For example: \qml Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" } @@ -132,8 +132,8 @@ QSet QTextDocumentWithImageResources::errors; The \c elide property can alternatively be used to fit a single line of plain text to a set width. - Note that the \l{Supported HTML Subset} is limited, and that if IMG tags - load remote images, the text reloads (see resourcesLoading). + Note that the \l{Supported HTML Subset} is limited. Also, if the text contains + HTML img tags that load remote images, the text is reloaded. Text provides read-only text. For editable text, see \l TextEdit. */ @@ -191,7 +191,7 @@ QDeclarativeTextPrivate::~QDeclarativeTextPrivate() /*! \qmlproperty bool Text::font.bold - Sets the font's weight to bold. + Sets whether the font weight is bold. */ /*! @@ -216,25 +216,25 @@ QDeclarativeTextPrivate::~QDeclarativeTextPrivate() /*! \qmlproperty bool Text::font.italic - Sets the style of the text to italic. + Sets whether the font has an italic style. */ /*! \qmlproperty bool Text::font.underline - Set the style of the text to underline. + Sets whether the text is underlined. */ /*! \qmlproperty bool Text::font.outline - Set the style of the text to outline. + Sets whether the font has an outline style. */ /*! \qmlproperty bool Text::font.strikeout - Set the style of the text to strikeout. + Sets whether the font has a strikeout style. */ /*! @@ -531,7 +531,14 @@ void QDeclarativeText::setWrapMode(WrapMode mode) The way the text property should be displayed. - Supported text formats are \c AutoText, \c PlainText, \c RichText and \c StyledText + Supported text formats are: + + \list + \o AutoText + \o PlainText + \o RichText + \o StyledText + \endlist The default is AutoText. If the text format is AutoText the text element will automatically determine whether the text should be treated as @@ -1069,8 +1076,9 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid /*! \qmlproperty bool Text::smooth - Set this property if you want the text to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If + This property holds whether the text is smoothly scaled or transformed. + + Smooth filtering gives better visual quality, but is slower. If the item is displayed at its natural size, this property has no visual or performance effect. diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 25eaef6..31ed418 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -129,7 +129,7 @@ QString QDeclarativeTextEdit::text() const /*! \qmlproperty bool TextEdit::font.bold - Sets the font's weight to bold. + Sets whether the font weight is bold. */ /*! @@ -154,25 +154,25 @@ QString QDeclarativeTextEdit::text() const /*! \qmlproperty bool TextEdit::font.italic - Sets the style of the text to italic. + Sets whether the font has an italic style. */ /*! \qmlproperty bool TextEdit::font.underline - Set the style of the text to underline. + Sets whether the text is underlined. */ /*! \qmlproperty bool TextEdit::font.outline - Set the style of the text to outline. + Sets whether the font has an outline style. */ /*! \qmlproperty bool TextEdit::font.strikeout - Set the style of the text to strikeout. + Sets whether the font has a strikeout style. */ /*! @@ -255,7 +255,12 @@ void QDeclarativeTextEdit::setText(const QString &text) The way the text property should be displayed. - Supported text formats are \c AutoText, \c PlainText and \c RichText. + \list + \o AutoText + \o PlainText + \o RichText + \o StyledText + \endlist The default is AutoText. If the text format is AutoText the text edit will automatically determine whether the text should be treated as @@ -991,8 +996,9 @@ void QDeclarativeTextEdit::updateImgCache(const QRectF &r) /*! \qmlproperty bool TextEdit::smooth - Set this property if you want the text to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If + This property holds whether the text is smoothly scaled or transformed. + + Smooth filtering gives better visual quality, but is slower. If the item is displayed at its natural size, this property has no visual or performance effect. diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index b618183..43812b6 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -108,7 +108,7 @@ void QDeclarativeTextInput::setText(const QString &s) /*! \qmlproperty bool TextInput::font.bold - Sets the font's weight to bold. + Sets whether the font weight is bold. */ /*! @@ -133,25 +133,25 @@ void QDeclarativeTextInput::setText(const QString &s) /*! \qmlproperty bool TextInput::font.italic - Sets the style of the text to italic. + Sets whether the font has an italic style. */ /*! \qmlproperty bool TextInput::font.underline - Set the style of the text to underline. + Sets whether the text is underlined. */ /*! \qmlproperty bool TextInput::font.outline - Set the style of the text to outline. + Sets whether the font has an outline style. */ /*! \qmlproperty bool TextInput::font.strikeout - Set the style of the text to strikeout. + Sets whether the font has a strikeout style. */ /*! @@ -827,7 +827,7 @@ void QDeclarativeTextInput::moveCursor() d->cursorItem->setX(d->control->cursorToX() - d->hscroll); } -/* +/*! \qmlmethod int xToPosition(int x) This function returns the character position at @@ -1044,8 +1044,9 @@ void QDeclarativeTextInput::selectAll() /*! \qmlproperty bool TextInput::smooth - Set this property if you want the text to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If + This property holds whether the text is smoothly scaled or transformed. + + Smooth filtering gives better visual quality, but is slower. If the item is displayed at its natural size, this property has no visual or performance effect. @@ -1054,15 +1055,15 @@ void QDeclarativeTextInput::selectAll() filtering at the beginning of the animation and reenable it at the conclusion. */ -/* +/*! \qmlproperty string TextInput::passwordCharacter This is the character displayed when echoMode is set to Password or PasswordEchoOnEdit. By default it is an asterisk. - Attempting to set this to more than one character will set it to - the first character in the string. Attempting to set this to less - than one character will fail. + If this property is set to a string with more than one character, + the first character is used. If the string is empty, the value + is ignored and the property is not set. */ QString QDeclarativeTextInput::passwordCharacter() const { @@ -1079,15 +1080,15 @@ void QDeclarativeTextInput::setPasswordCharacter(const QString &str) d->control->setPasswordCharacter(str.constData()[0]); } -/* +/*! \qmlproperty string TextInput::displayText - This is the actual text displayed in the TextInput. When - echoMode is set to TextInput::Normal this will be exactly - the same as the TextInput::text property. When echoMode - is set to something else, this property will contain the text - the user sees, while the text property will contain the - entered text. + This is the text displayed in the TextInput. + + If \l echoMode is set to TextInput::Normal, this holds the + same value as the TextInput::text property. Otherwise, + this property holds the text visible to the user, while + the \l text property holds the actual entered text. */ QString QDeclarativeTextInput::displayText() const { @@ -1095,26 +1096,30 @@ QString QDeclarativeTextInput::displayText() const return d->control->displayText(); } -/* - \qmlmethod void moveCursorSelection(int pos) +/*! + \qmlmethod void moveCursorSelection(int position) - This method allows you to move the cursor while modifying the selection accordingly. - To simply move the cursor, set the cursorPosition property. + Moves the cursor to \a position and updates the selection accordingly. + (To only move the cursor, set the \l cursorPosition property.) When this method is called it additionally sets either the selectionStart or the selectionEnd (whichever was at the previous cursor position) to the specified position. This allows you to easily extend and contract the selected text range. - Example: The sequence of calls + For example, take this sequence of calls: + + \code cursorPosition = 5 moveCursorSelection(9) moveCursorSelection(7) - would move the cursor to position 5, extend the selection end from 5 to 9 + \endcode + + This moves the cursor to position 5, extend the selection end from 5 to 9 and then retract the selection end from 9 to 7, leaving the text from position 5 to 7 selected (the 6th and 7th characters). */ -void QDeclarativeTextInput::moveCursorSelection(int pos) +void QDeclarativeTextInput::moveCursorSelection(int position) { Q_D(QDeclarativeTextInput); d->control->moveCursor(pos, true); -- cgit v0.12 From 7ecfd4393149ce9b49e5da4e254fcecd6b8af420 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 28 Apr 2010 13:06:06 +1000 Subject: Fix snap at view boundaries with overshoot on. The view would flick slowly at the boundaries if overshoot and snapping was enabled. --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 11 +++++++---- src/declarative/graphicsitems/qdeclarativelistview.cpp | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index f79a853..febd34a 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -855,10 +855,13 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m qreal adjDist = -data.flickTarget + data.move.value(); if (qAbs(adjDist) > qAbs(dist)) { // Prevent painfully slow flicking - adjust velocity to suit flickDeceleration - v2 = accel * 2.0f * qAbs(dist); - v = qSqrt(v2); - if (dist > 0) - v = -v; + qreal adjv2 = accel * 2.0f * qAbs(adjDist); + if (adjv2 > v2) { + v2 = adjv2; + v = qSqrt(v2); + if (dist > 0) + v = -v; + } } dist = adjDist; accel = v2 / (2.0f * qAbs(dist)); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index c88dab2..3f150dc 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1230,10 +1230,13 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m qreal adjDist = -data.flickTarget + data.move.value(); if (qAbs(adjDist) > qAbs(dist)) { // Prevent painfully slow flicking - adjust velocity to suit flickDeceleration - v2 = accel * 2.0f * qAbs(dist); - v = qSqrt(v2); - if (dist > 0) - v = -v; + qreal adjv2 = accel * 2.0f * qAbs(adjDist); + if (adjv2 > v2) { + v2 = adjv2; + v = qSqrt(v2); + if (dist > 0) + v = -v; + } } dist = adjDist; accel = v2 / (2.0f * qAbs(dist)); -- cgit v0.12 From 49b10375dc9b5602bc83dbc4329c1e4c3881d226 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 28 Apr 2010 13:18:56 +1000 Subject: Small cleanups --- src/declarative/qml/qdeclarativeparser_p.h | 3 - src/declarative/qml/qdeclarativescriptparser.cpp | 75 ++++++------------------ 2 files changed, 19 insertions(+), 59 deletions(-) diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h index 0870cfb..25777f5 100644 --- a/src/declarative/qml/qdeclarativeparser_p.h +++ b/src/declarative/qml/qdeclarativeparser_p.h @@ -188,9 +188,6 @@ namespace QDeclarativeParser QList lineNumbers; QList pragmas; }; -#if 0 - QList scripts; -#endif // The bytes to cast instances by to get to the QDeclarativeParserStatus // interface. -1 indicates the type doesn't support this interface. diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp index 8b96733..219d759 100644 --- a/src/declarative/qml/qdeclarativescriptparser.cpp +++ b/src/declarative/qml/qdeclarativescriptparser.cpp @@ -104,17 +104,13 @@ public: void operator()(const QString &code, AST::Node *node); protected: + Object *defineObjectBinding(AST::UiQualifiedId *propertyName, bool onAssignment, - AST::UiQualifiedId *objectTypeName, + const QString &objectType, + AST::SourceLocation typeLocation, LocationSpan location, AST::UiObjectInitializer *initializer = 0); - Object *defineObjectBinding_helper(AST::UiQualifiedId *propertyName, bool onAssignment, - const QString &objectType, - AST::SourceLocation typeLocation, - LocationSpan location, - AST::UiObjectInitializer *initializer = 0); - QDeclarativeParser::Variant getVariant(AST::ExpressionNode *expr); LocationSpan location(AST::SourceLocation start, AST::SourceLocation end); @@ -240,12 +236,12 @@ QString ProcessAST::asString(AST::UiQualifiedId *node) const } Object * -ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, - bool onAssignment, - const QString &objectType, - AST::SourceLocation typeLocation, - LocationSpan location, - AST::UiObjectInitializer *initializer) +ProcessAST::defineObjectBinding(AST::UiQualifiedId *propertyName, + bool onAssignment, + const QString &objectType, + AST::SourceLocation typeLocation, + LocationSpan location, + AST::UiObjectInitializer *initializer) { int lastTypeDot = objectType.lastIndexOf(QLatin1Char('.')); bool isType = !objectType.isEmpty() && @@ -355,41 +351,6 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, } } -Object *ProcessAST::defineObjectBinding(AST::UiQualifiedId *qualifiedId, bool onAssignment, - AST::UiQualifiedId *objectTypeName, - LocationSpan location, - AST::UiObjectInitializer *initializer) -{ - const QString objectType = asString(objectTypeName); - const AST::SourceLocation typeLocation = objectTypeName->identifierToken; - - if (objectType == QLatin1String("Script")) { - - AST::UiObjectMemberList *it = initializer->members; - for (; it; it = it->next) { - AST::UiScriptBinding *scriptBinding = AST::cast(it->member); - if (! scriptBinding) - continue; - - QString propertyName = asString(scriptBinding->qualifiedId); - if (propertyName == QLatin1String("source")) { - if (AST::ExpressionStatement *stmt = AST::cast(scriptBinding->statement)) { - QDeclarativeParser::Variant string = getVariant(stmt->expression); - if (string.isStringList()) { - QStringList urls = string.asStringList(); - // We need to add this as a resource - for (int ii = 0; ii < urls.count(); ++ii) - _parser->_refUrls << QUrl(urls.at(ii)); - } - } - } - } - - } - - return defineObjectBinding_helper(qualifiedId, onAssignment, objectType, typeLocation, location, initializer); -} - LocationSpan ProcessAST::location(AST::UiQualifiedId *id) { return location(id->identifierToken, id->identifierToken); @@ -664,10 +625,11 @@ bool ProcessAST::visit(AST::UiObjectDefinition *node) LocationSpan l = location(node->firstSourceLocation(), node->lastSourceLocation()); - defineObjectBinding(/*propertyName = */ 0, false, - node->qualifiedTypeNameId, - l, - node->initializer); + const QString objectType = asString(node->qualifiedTypeNameId); + const AST::SourceLocation typeLocation = node->qualifiedTypeNameId->identifierToken; + + defineObjectBinding(/*propertyName = */ 0, false, objectType, + typeLocation, l, node->initializer); return false; } @@ -679,10 +641,11 @@ bool ProcessAST::visit(AST::UiObjectBinding *node) LocationSpan l = location(node->qualifiedTypeNameId->identifierToken, node->initializer->rbraceToken); - defineObjectBinding(node->qualifiedId, node->hasOnToken, - node->qualifiedTypeNameId, - l, - node->initializer); + const QString objectType = asString(node->qualifiedTypeNameId); + const AST::SourceLocation typeLocation = node->qualifiedTypeNameId->identifierToken; + + defineObjectBinding(node->qualifiedId, node->hasOnToken, objectType, + typeLocation, l, node->initializer); return false; } -- cgit v0.12 From 07cb08edf82ed5cb7cd0fd37aeb694fa01e42646 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 28 Apr 2010 13:35:17 +1000 Subject: Benchmark --- .../declarative/compilation/compilation.pro | 11 +++ .../declarative/compilation/data/BoomBlock.qml | 65 ++++++++++++++++ .../declarative/compilation/tst_compilation.cpp | 90 ++++++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 tests/benchmarks/declarative/compilation/compilation.pro create mode 100644 tests/benchmarks/declarative/compilation/data/BoomBlock.qml create mode 100644 tests/benchmarks/declarative/compilation/tst_compilation.cpp diff --git a/tests/benchmarks/declarative/compilation/compilation.pro b/tests/benchmarks/declarative/compilation/compilation.pro new file mode 100644 index 0000000..32f4aba --- /dev/null +++ b/tests/benchmarks/declarative/compilation/compilation.pro @@ -0,0 +1,11 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_compilation +QT += declarative +macx:CONFIG -= app_bundle + +CONFIG += release + +SOURCES += tst_compilation.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/benchmarks/declarative/compilation/data/BoomBlock.qml b/tests/benchmarks/declarative/compilation/data/BoomBlock.qml new file mode 100644 index 0000000..47f43c2 --- /dev/null +++ b/tests/benchmarks/declarative/compilation/data/BoomBlock.qml @@ -0,0 +1,65 @@ +import Qt 4.7 +import Qt.labs.particles 1.0 + +Item { + id: block + property bool dying: false + property bool spawned: false + property int type: 0 + property int targetX: 0 + property int targetY: 0 + + SpringFollow on x { enabled: spawned; to: targetX; spring: 2; damping: 0.2 } + SpringFollow on y { to: targetY; spring: 2; damping: 0.2 } + + Image { + id: img + source: { + if(type == 0){ + "pics/redStone.png"; + } else if(type == 1) { + "pics/blueStone.png"; + } else { + "pics/greenStone.png"; + } + } + opacity: 0 + Behavior on opacity { NumberAnimation { duration: 200 } } + anchors.fill: parent + } + + Particles { + id: particles + + width: 1; height: 1 + anchors.centerIn: parent + + emissionRate: 0 + lifeSpan: 700; lifeSpanDeviation: 600 + angle: 0; angleDeviation: 360; + velocity: 100; velocityDeviation: 30 + source: { + if(type == 0){ + "pics/redStar.png"; + } else if (type == 1) { + "pics/blueStar.png"; + } else { + "pics/greenStar.png"; + } + } + } + + states: [ + State { + name: "AliveState"; when: spawned == true && dying == false + PropertyChanges { target: img; opacity: 1 } + }, + + State { + name: "DeathState"; when: dying == true + StateChangeScript { script: particles.burst(50); } + PropertyChanges { target: img; opacity: 0 } + StateChangeScript { script: block.destroy(1000); } + } + ] +} diff --git a/tests/benchmarks/declarative/compilation/tst_compilation.cpp b/tests/benchmarks/declarative/compilation/tst_compilation.cpp new file mode 100644 index 0000000..5694d5b --- /dev/null +++ b/tests/benchmarks/declarative/compilation/tst_compilation.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 + +#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_compilation : public QObject +{ + Q_OBJECT +public: + tst_compilation(); + +private slots: + void boomblock(); + +private: + QDeclarativeEngine engine; +}; + +tst_compilation::tst_compilation() +{ +} + +inline QUrl TEST_FILE(const QString &filename) +{ + return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); +} + +void tst_compilation::boomblock() +{ + QFile f(SRCDIR + QLatin1String("/data/BoomBlock.qml")); + QVERIFY(f.open(QIODevice::ReadOnly)); + QByteArray data = f.readAll(); + + QBENCHMARK { + QDeclarativeComponent c(&engine); + c.setData(data, QUrl()); +// QVERIFY(c.isReady()); + } +} + +QTEST_MAIN(tst_compilation) + +#include "tst_compilation.moc" -- cgit v0.12 From 7a89d94c208347635fa0ad5c4da9bca4a9398f5c Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 28 Apr 2010 13:47:32 +1000 Subject: Make compile --- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 43812b6..775450a 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -1122,7 +1122,7 @@ QString QDeclarativeTextInput::displayText() const void QDeclarativeTextInput::moveCursorSelection(int position) { Q_D(QDeclarativeTextInput); - d->control->moveCursor(pos, true); + d->control->moveCursor(position, true); } void QDeclarativeTextInputPrivate::init() -- cgit v0.12 From bfe1ed3d92cc68e9ceeaa38803b77ed17cf93263 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 28 Apr 2010 13:56:45 +1000 Subject: Move snippets to correct location --- doc/src/declarative/integrating.qdoc | 12 ++-- doc/src/declarative/qtbinding.qdoc | 26 +++---- .../integrating/graphicswidgets/bluecircle.h | 55 --------------- .../graphicswidgets/graphicswidgets.pro | 13 ---- .../snippets/integrating/graphicswidgets/main.qml | 32 --------- .../snippets/integrating/graphicswidgets/qmldir | 1 - .../integrating/graphicswidgets/redsquare.h | 54 --------------- .../integrating/graphicswidgets/shapesplugin.cpp | 61 ----------------- .../contextproperties/contextproperties.pro | 2 - .../snippets/qtbinding/contextproperties/main.cpp | 79 --------------------- .../snippets/qtbinding/contextproperties/main.qml | 15 ---- .../qtbinding/custompalette/custompalette.h | 80 ---------------------- .../qtbinding/custompalette/custompalette.pro | 3 - .../snippets/qtbinding/custompalette/main.cpp | 62 ----------------- .../snippets/qtbinding/custompalette/main.qml | 22 ------ .../snippets/qtbinding/resources/example.qrc | 10 --- .../qtbinding/resources/images/background.png | 0 .../snippets/qtbinding/resources/main.cpp | 58 ---------------- .../snippets/qtbinding/resources/main.qml | 7 -- .../snippets/qtbinding/resources/resources.pro | 4 -- .../snippets/qtbinding/stopwatch/main.cpp | 63 ----------------- .../snippets/qtbinding/stopwatch/main.qml | 18 ----- .../snippets/qtbinding/stopwatch/stopwatch.cpp | 63 ----------------- .../snippets/qtbinding/stopwatch/stopwatch.h | 62 ----------------- .../snippets/qtbinding/stopwatch/stopwatch.pro | 3 - .../declarative/graphicswidgets/bluecircle.h | 55 +++++++++++++++ .../graphicswidgets/graphicswidgets.pro | 13 ++++ .../snippets/declarative/graphicswidgets/main.qml | 32 +++++++++ .../snippets/declarative/graphicswidgets/qmldir | 1 + .../declarative/graphicswidgets/redsquare.h | 54 +++++++++++++++ .../declarative/graphicswidgets/shapesplugin.cpp | 61 +++++++++++++++++ .../contextproperties/contextproperties.pro | 2 + .../qtbinding/contextproperties/main.cpp | 79 +++++++++++++++++++++ .../qtbinding/contextproperties/main.qml | 15 ++++ .../qtbinding/custompalette/custompalette.h | 80 ++++++++++++++++++++++ .../qtbinding/custompalette/custompalette.pro | 3 + .../declarative/qtbinding/custompalette/main.cpp | 62 +++++++++++++++++ .../declarative/qtbinding/custompalette/main.qml | 22 ++++++ .../declarative/qtbinding/resources/example.qrc | 10 +++ .../qtbinding/resources/images/background.png | 0 .../declarative/qtbinding/resources/main.cpp | 58 ++++++++++++++++ .../declarative/qtbinding/resources/main.qml | 7 ++ .../declarative/qtbinding/resources/resources.pro | 4 ++ .../declarative/qtbinding/stopwatch/main.cpp | 63 +++++++++++++++++ .../declarative/qtbinding/stopwatch/main.qml | 18 +++++ .../declarative/qtbinding/stopwatch/stopwatch.cpp | 63 +++++++++++++++++ .../declarative/qtbinding/stopwatch/stopwatch.h | 62 +++++++++++++++++ .../declarative/qtbinding/stopwatch/stopwatch.pro | 3 + 48 files changed, 786 insertions(+), 786 deletions(-) delete mode 100644 doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h delete mode 100644 doc/src/declarative/snippets/integrating/graphicswidgets/graphicswidgets.pro delete mode 100644 doc/src/declarative/snippets/integrating/graphicswidgets/main.qml delete mode 100644 doc/src/declarative/snippets/integrating/graphicswidgets/qmldir delete mode 100644 doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h delete mode 100644 doc/src/declarative/snippets/integrating/graphicswidgets/shapesplugin.cpp delete mode 100644 doc/src/declarative/snippets/qtbinding/contextproperties/contextproperties.pro delete mode 100644 doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp delete mode 100644 doc/src/declarative/snippets/qtbinding/contextproperties/main.qml delete mode 100644 doc/src/declarative/snippets/qtbinding/custompalette/custompalette.h delete mode 100644 doc/src/declarative/snippets/qtbinding/custompalette/custompalette.pro delete mode 100644 doc/src/declarative/snippets/qtbinding/custompalette/main.cpp delete mode 100644 doc/src/declarative/snippets/qtbinding/custompalette/main.qml delete mode 100644 doc/src/declarative/snippets/qtbinding/resources/example.qrc delete mode 100644 doc/src/declarative/snippets/qtbinding/resources/images/background.png delete mode 100644 doc/src/declarative/snippets/qtbinding/resources/main.cpp delete mode 100644 doc/src/declarative/snippets/qtbinding/resources/main.qml delete mode 100644 doc/src/declarative/snippets/qtbinding/resources/resources.pro delete mode 100644 doc/src/declarative/snippets/qtbinding/stopwatch/main.cpp delete mode 100644 doc/src/declarative/snippets/qtbinding/stopwatch/main.qml delete mode 100644 doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.cpp delete mode 100644 doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.h delete mode 100644 doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.pro create mode 100644 doc/src/snippets/declarative/graphicswidgets/bluecircle.h create mode 100644 doc/src/snippets/declarative/graphicswidgets/graphicswidgets.pro create mode 100644 doc/src/snippets/declarative/graphicswidgets/main.qml create mode 100644 doc/src/snippets/declarative/graphicswidgets/qmldir create mode 100644 doc/src/snippets/declarative/graphicswidgets/redsquare.h create mode 100644 doc/src/snippets/declarative/graphicswidgets/shapesplugin.cpp create mode 100644 doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro create mode 100644 doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp create mode 100644 doc/src/snippets/declarative/qtbinding/contextproperties/main.qml create mode 100644 doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h create mode 100644 doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro create mode 100644 doc/src/snippets/declarative/qtbinding/custompalette/main.cpp create mode 100644 doc/src/snippets/declarative/qtbinding/custompalette/main.qml create mode 100644 doc/src/snippets/declarative/qtbinding/resources/example.qrc create mode 100644 doc/src/snippets/declarative/qtbinding/resources/images/background.png create mode 100644 doc/src/snippets/declarative/qtbinding/resources/main.cpp create mode 100644 doc/src/snippets/declarative/qtbinding/resources/main.qml create mode 100644 doc/src/snippets/declarative/qtbinding/resources/resources.pro create mode 100644 doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp create mode 100644 doc/src/snippets/declarative/qtbinding/stopwatch/main.qml create mode 100644 doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp create mode 100644 doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h create mode 100644 doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro diff --git a/doc/src/declarative/integrating.qdoc b/doc/src/declarative/integrating.qdoc index 0051f09..1c07f8e 100644 --- a/doc/src/declarative/integrating.qdoc +++ b/doc/src/declarative/integrating.qdoc @@ -118,34 +118,34 @@ Here is an example. Suppose you have two classes, \c RedSquare and \c BlueCircle that both inherit from QGraphicsWidget: \c [graphicswidgets/redsquare.h] -\snippet doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h 0 +\snippet doc/src/snippets/declarative/graphicswidgets/redsquare.h 0 \c [graphicswidgets/bluecircle.h] -\snippet doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h 0 +\snippet doc/src/snippets/declarative/graphicswidgets/bluecircle.h 0 Then, create a plugin by subclassing QDeclarativeExtensionPlugin, and register the types by calling qmlRegisterType(). Also export the plugin with Q_EXPORT_PLUGIN2. \c [graphicswidgets/shapesplugin.cpp] -\snippet doc/src/declarative/snippets/integrating/graphicswidgets/shapesplugin.cpp 0 +\snippet doc/src/snippets/declarative/graphicswidgets/shapesplugin.cpp 0 Now write a project file that creates the plugin: \c [graphicswidgets/graphicswidgets.pro] -\quotefile doc/src/declarative/snippets/integrating/graphicswidgets/graphicswidgets.pro +\quotefile doc/src/snippets/declarative/graphicswidgets/graphicswidgets.pro And add a \c qmldir file that includes the \c graphicswidgets plugin from the \c lib subdirectory (as defined in the project file): \c [graphicswidgets/qmldir] -\quotefile doc/src/declarative/snippets/integrating/graphicswidgets/qmldir +\quotefile doc/src/snippets/declarative/graphicswidgets/qmldir Now, we can write a QML file that uses the \c RedSquare and \c BlueCircle widgets. (As an example, we can also create \c QGraphicsWidget items if we import the \c Qt.widgets module.) \c [main.qml] -\quotefile doc/src/declarative/snippets/integrating/graphicswidgets/main.qml +\quotefile doc/src/snippets/declarative/graphicswidgets/main.qml Here is a screenshot of the result: diff --git a/doc/src/declarative/qtbinding.qdoc b/doc/src/declarative/qtbinding.qdoc index d024ff2..7d696d7 100644 --- a/doc/src/declarative/qtbinding.qdoc +++ b/doc/src/declarative/qtbinding.qdoc @@ -97,17 +97,17 @@ The following example shows how to expose a background color to a QML file throu \row \o \c {// main.cpp} -\snippet doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp 0 +\snippet doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp 0 \o \c {// main.qml} -\snippet doc/src/declarative/snippets/qtbinding/contextproperties/main.qml 0 +\snippet doc/src/snippets/declarative/qtbinding/contextproperties/main.qml 0 \endtable Or, if you want \c main.cpp to create the component without showing it in a QDeclarativeView, you could create an instance of QDeclarativeContext using QDeclarativeEngine::rootContext() instead: -\snippet doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp 1 +\snippet doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp 1 Context properties work just like normal properties in QML bindings - if the \c backgroundColor context property in this example was changed to red, the component object instances would @@ -135,15 +135,15 @@ allow QML to set values. The following example creates a \c CustomPalette object, and sets it as the \c palette context property. -\snippet doc/src/declarative/snippets/qtbinding/custompalette/custompalette.h 0 +\snippet doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h 0 -\snippet doc/src/declarative/snippets/qtbinding/custompalette/main.cpp 0 +\snippet doc/src/snippets/declarative/qtbinding/custompalette/main.cpp 0 The QML that follows references the palette object, and its properties, to set the appropriate background and text colors. When the window is clicked, the palette's text color is changed, and the window text will update accordingly. -\snippet doc/src/declarative/snippets/qtbinding/custompalette/main.qml 0 +\snippet doc/src/snippets/declarative/qtbinding/custompalette/main.qml 0 To detect when a C++ property value - in this case the \c CustomPalette's \c text property - changes, the property must have a corresponding NOTIFY signal. The NOTIFY signal specifies a signal @@ -185,12 +185,12 @@ This example toggles the "Stopwatch" object on/off when the MouseArea is clicked \row \o \c {// main.cpp} -\snippet doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.h 0 -\snippet doc/src/declarative/snippets/qtbinding/stopwatch/main.cpp 0 +\snippet doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h 0 +\snippet doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp 0 \o \c {// main.qml} -\snippet doc/src/declarative/snippets/qtbinding/stopwatch/main.qml 0 +\snippet doc/src/snippets/declarative/qtbinding/stopwatch/main.qml 0 \endtable @@ -258,16 +258,16 @@ QML content can be loaded from \l {The Qt Resource System} using the \e qrc: URL For example: \c [project/example.qrc] -\quotefile doc/src/declarative/snippets/qtbinding/resources/example.qrc +\quotefile doc/src/snippets/declarative/qtbinding/resources/example.qrc \c [project/project.pro] -\quotefile doc/src/declarative/snippets/qtbinding/resources/resources.pro +\quotefile doc/src/snippets/declarative/qtbinding/resources/resources.pro \c [project/main.cpp] -\snippet doc/src/declarative/snippets/qtbinding/resources/main.cpp 0 +\snippet doc/src/snippets/declarative/qtbinding/resources/main.cpp 0 \c [project/main.qml] -\snippet doc/src/declarative/snippets/qtbinding/resources/main.qml 0 +\snippet doc/src/snippets/declarative/qtbinding/resources/main.qml 0 */ diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h b/doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h deleted file mode 100644 index 73d66b7..0000000 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/bluecircle.h +++ /dev/null @@ -1,55 +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 documentation 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$ -** -****************************************************************************/ -//![0] -#include -#include - -class BlueCircle : public QGraphicsWidget -{ - Q_OBJECT -public: - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) - { - painter->setPen(QColor(Qt::blue)); - painter->drawEllipse(0, 0, size().width(), size().height()); - } -}; -//![0] diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/graphicswidgets.pro b/doc/src/declarative/snippets/integrating/graphicswidgets/graphicswidgets.pro deleted file mode 100644 index 21c8a37..0000000 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/graphicswidgets.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = lib -CONFIG += qt plugin -QT += declarative - -HEADERS += redsquare.h \ - bluecircle.h - -SOURCES += shapesplugin.cpp - -DESTDIR = lib -OBJECTS_DIR = tmp -MOC_DIR = tmp - diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/main.qml b/doc/src/declarative/snippets/integrating/graphicswidgets/main.qml deleted file mode 100644 index ffcf79d..0000000 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/main.qml +++ /dev/null @@ -1,32 +0,0 @@ -import Qt 4.7 -import Qt.widgets 4.7 - -Rectangle { - width: 200 - height: 200 - - RedSquare { - id: square - width: 80 - height: 80 - } - - BlueCircle { - anchors.left: square.right - width: 80 - height: 80 - } - - QGraphicsWidget { - anchors.top: square.bottom - size.width: 80 - size.height: 80 - layout: QGraphicsLinearLayout { - LayoutItem { - preferredSize: "100x100" - Rectangle { color: "yellow"; anchors.fill: parent } - } - } - } -} - diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/qmldir b/doc/src/declarative/snippets/integrating/graphicswidgets/qmldir deleted file mode 100644 index f94dad2..0000000 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin graphicswidgets lib diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h b/doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h deleted file mode 100644 index 3050662..0000000 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/redsquare.h +++ /dev/null @@ -1,54 +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 documentation 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$ -** -****************************************************************************/ -//![0] -#include -#include - -class RedSquare : public QGraphicsWidget -{ - Q_OBJECT -public: - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) - { - painter->fillRect(0, 0, size().width(), size().height(), QColor(Qt::red)); - } -}; -//![0] diff --git a/doc/src/declarative/snippets/integrating/graphicswidgets/shapesplugin.cpp b/doc/src/declarative/snippets/integrating/graphicswidgets/shapesplugin.cpp deleted file mode 100644 index 4c18ef3..0000000 --- a/doc/src/declarative/snippets/integrating/graphicswidgets/shapesplugin.cpp +++ /dev/null @@ -1,61 +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 documentation 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$ -** -****************************************************************************/ -//![0] -#include "redsquare.h" -#include "bluecircle.h" - -#include -#include - -class ShapesPlugin : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - void registerTypes(const char *uri) { - qmlRegisterType(uri, 1, 0, "RedSquare"); - qmlRegisterType(uri, 1, 0, "BlueCircle"); - } -}; - -#include "shapesplugin.moc" - -Q_EXPORT_PLUGIN2(shapesplugin, ShapesPlugin); -//![0] diff --git a/doc/src/declarative/snippets/qtbinding/contextproperties/contextproperties.pro b/doc/src/declarative/snippets/qtbinding/contextproperties/contextproperties.pro deleted file mode 100644 index 68eeaf2..0000000 --- a/doc/src/declarative/snippets/qtbinding/contextproperties/contextproperties.pro +++ /dev/null @@ -1,2 +0,0 @@ -QT += declarative -SOURCES += main.cpp diff --git a/doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp b/doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp deleted file mode 100644 index 4073a6c..0000000 --- a/doc/src/declarative/snippets/qtbinding/contextproperties/main.cpp +++ /dev/null @@ -1,79 +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 documentation 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 - -//![0] -#include -#include -#include - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QDeclarativeView view; - QDeclarativeContext *context = view.rootContext(); - context->setContextProperty("backgroundColor", - QColor(Qt::yellow)); - - view.setSource(QUrl::fromLocalFile("main.qml")); - view.show(); - - return app.exec(); -} -//![0] - -static void alternative() -{ - // Alternatively, if we don't actually want to display main.qml: -//![1] - QDeclarativeEngine engine; - QDeclarativeContext *windowContext = new QDeclarativeContext(engine.rootContext()); - windowContext->setContextProperty("backgroundColor", QColor(Qt::yellow)); - - QDeclarativeComponent component(&engine, "main.qml"); - QObject *window = component.create(windowContext); -//![1] -} - - diff --git a/doc/src/declarative/snippets/qtbinding/contextproperties/main.qml b/doc/src/declarative/snippets/qtbinding/contextproperties/main.qml deleted file mode 100644 index 1053f73..0000000 --- a/doc/src/declarative/snippets/qtbinding/contextproperties/main.qml +++ /dev/null @@ -1,15 +0,0 @@ -//![0] -import Qt 4.7 - -Rectangle { - width: 300 - height: 300 - - color: backgroundColor - - Text { - anchors.centerIn: parent - text: "Hello Yellow World!" - } -} -//![0] diff --git a/doc/src/declarative/snippets/qtbinding/custompalette/custompalette.h b/doc/src/declarative/snippets/qtbinding/custompalette/custompalette.h deleted file mode 100644 index d0d253a..0000000 --- a/doc/src/declarative/snippets/qtbinding/custompalette/custompalette.h +++ /dev/null @@ -1,80 +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 documentation 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 - -//![0] -class CustomPalette : public QObject -{ - Q_OBJECT - Q_PROPERTY(QColor background READ background WRITE setBackground NOTIFY backgroundChanged) - Q_PROPERTY(QColor text READ text WRITE setText NOTIFY textChanged) - -public: - CustomPalette() : m_background(Qt::white), m_text(Qt::black) {} - - QColor background() const { return m_background; } - void setBackground(const QColor &c) { - if (c != m_background) { - m_background = c; - emit backgroundChanged(); - } - } - - QColor text() const { return m_text; } - void setText(const QColor &c) { - if (c != m_text) { - m_text = c; - emit textChanged(); - } - } - -signals: - void textChanged(); - void backgroundChanged(); - -private: - QColor m_background; - QColor m_text; -}; - -//![0] diff --git a/doc/src/declarative/snippets/qtbinding/custompalette/custompalette.pro b/doc/src/declarative/snippets/qtbinding/custompalette/custompalette.pro deleted file mode 100644 index e6af0d0..0000000 --- a/doc/src/declarative/snippets/qtbinding/custompalette/custompalette.pro +++ /dev/null @@ -1,3 +0,0 @@ -QT += declarative -HEADERS += custompalette.h -SOURCES += main.cpp diff --git a/doc/src/declarative/snippets/qtbinding/custompalette/main.cpp b/doc/src/declarative/snippets/qtbinding/custompalette/main.cpp deleted file mode 100644 index dc651f6..0000000 --- a/doc/src/declarative/snippets/qtbinding/custompalette/main.cpp +++ /dev/null @@ -1,62 +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 documentation 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 "custompalette.h" - -//![0] -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QDeclarativeView view; - view.rootContext()->setContextProperty("palette", new CustomPalette); - - view.setSource(QUrl::fromLocalFile("main.qml")); - view.show(); - - return app.exec(); -} -//![0] - diff --git a/doc/src/declarative/snippets/qtbinding/custompalette/main.qml b/doc/src/declarative/snippets/qtbinding/custompalette/main.qml deleted file mode 100644 index f1a3b4f..0000000 --- a/doc/src/declarative/snippets/qtbinding/custompalette/main.qml +++ /dev/null @@ -1,22 +0,0 @@ -//![0] -import Qt 4.7 - -Rectangle { - width: 240 - height: 320 - color: palette.background - - Text { - anchors.centerIn: parent - color: palette.text - text: "Click me to change color!" - } - - MouseArea { - anchors.fill: parent - onClicked: { - palette.text = "blue"; - } - } -} -//![0] diff --git a/doc/src/declarative/snippets/qtbinding/resources/example.qrc b/doc/src/declarative/snippets/qtbinding/resources/example.qrc deleted file mode 100644 index 5e49415..0000000 --- a/doc/src/declarative/snippets/qtbinding/resources/example.qrc +++ /dev/null @@ -1,10 +0,0 @@ - - - - - main.qml - images/background.png - - - - diff --git a/doc/src/declarative/snippets/qtbinding/resources/images/background.png b/doc/src/declarative/snippets/qtbinding/resources/images/background.png deleted file mode 100644 index e69de29..0000000 diff --git a/doc/src/declarative/snippets/qtbinding/resources/main.cpp b/doc/src/declarative/snippets/qtbinding/resources/main.cpp deleted file mode 100644 index 5459b9e..0000000 --- a/doc/src/declarative/snippets/qtbinding/resources/main.cpp +++ /dev/null @@ -1,58 +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 documentation 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 - -//![0] -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QDeclarativeView view; - view.setSource(QUrl("qrc:/main.qml")); - view.show(); - - return app.exec(); -} -//![0] - diff --git a/doc/src/declarative/snippets/qtbinding/resources/main.qml b/doc/src/declarative/snippets/qtbinding/resources/main.qml deleted file mode 100644 index dfe923f..0000000 --- a/doc/src/declarative/snippets/qtbinding/resources/main.qml +++ /dev/null @@ -1,7 +0,0 @@ -//![0] -import Qt 4.7 - -Image { - source: "images/background.png" -} -//![0] diff --git a/doc/src/declarative/snippets/qtbinding/resources/resources.pro b/doc/src/declarative/snippets/qtbinding/resources/resources.pro deleted file mode 100644 index cc01ee1..0000000 --- a/doc/src/declarative/snippets/qtbinding/resources/resources.pro +++ /dev/null @@ -1,4 +0,0 @@ -QT += declarative - -SOURCES += main.cpp -RESOURCES += example.qrc diff --git a/doc/src/declarative/snippets/qtbinding/stopwatch/main.cpp b/doc/src/declarative/snippets/qtbinding/stopwatch/main.cpp deleted file mode 100644 index 537a288..0000000 --- a/doc/src/declarative/snippets/qtbinding/stopwatch/main.cpp +++ /dev/null @@ -1,63 +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 documentation 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 "stopwatch.h" - -#include -#include -#include - -//![0] -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QDeclarativeView view; - view.rootContext()->setContextProperty("stopwatch", - new Stopwatch); - - view.setSource(QUrl::fromLocalFile("main.qml")); - view.show(); - - return app.exec(); -} -//![0] - diff --git a/doc/src/declarative/snippets/qtbinding/stopwatch/main.qml b/doc/src/declarative/snippets/qtbinding/stopwatch/main.qml deleted file mode 100644 index 2efa542..0000000 --- a/doc/src/declarative/snippets/qtbinding/stopwatch/main.qml +++ /dev/null @@ -1,18 +0,0 @@ -//![0] -import Qt 4.7 - -Rectangle { - width: 300 - height: 300 - - MouseArea { - anchors.fill: parent - onClicked: { - if (stopwatch.isRunning()) - stopwatch.stop() - else - stopwatch.start(); - } - } -} -//![0] diff --git a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.cpp b/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.cpp deleted file mode 100644 index 4954a5f..0000000 --- a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.cpp +++ /dev/null @@ -1,63 +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 documentation 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 "stopwatch.h" - -Stopwatch::Stopwatch() - : m_running(false) -{ -} - -bool Stopwatch::isRunning() const -{ - return m_running; -} - -void Stopwatch::start() -{ - m_running = true; -} - -void Stopwatch::stop() -{ - m_running = false; -} - diff --git a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.h b/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.h deleted file mode 100644 index 8d17121..0000000 --- a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.h +++ /dev/null @@ -1,62 +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 documentation 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 - -//![0] -class Stopwatch : public QObject -{ - Q_OBJECT -public: - Stopwatch(); - - Q_INVOKABLE bool isRunning() const; - -public slots: - void start(); - void stop(); - -private: - bool m_running; -}; - -//![0] - diff --git a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.pro b/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.pro deleted file mode 100644 index d803e6a..0000000 --- a/doc/src/declarative/snippets/qtbinding/stopwatch/stopwatch.pro +++ /dev/null @@ -1,3 +0,0 @@ -QT += declarative -HEADERS += stopwatch.h -SOURCES += main.cpp stopwatch.cpp diff --git a/doc/src/snippets/declarative/graphicswidgets/bluecircle.h b/doc/src/snippets/declarative/graphicswidgets/bluecircle.h new file mode 100644 index 0000000..73d66b7 --- /dev/null +++ b/doc/src/snippets/declarative/graphicswidgets/bluecircle.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 documentation 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$ +** +****************************************************************************/ +//![0] +#include +#include + +class BlueCircle : public QGraphicsWidget +{ + Q_OBJECT +public: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + { + painter->setPen(QColor(Qt::blue)); + painter->drawEllipse(0, 0, size().width(), size().height()); + } +}; +//![0] diff --git a/doc/src/snippets/declarative/graphicswidgets/graphicswidgets.pro b/doc/src/snippets/declarative/graphicswidgets/graphicswidgets.pro new file mode 100644 index 0000000..21c8a37 --- /dev/null +++ b/doc/src/snippets/declarative/graphicswidgets/graphicswidgets.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +CONFIG += qt plugin +QT += declarative + +HEADERS += redsquare.h \ + bluecircle.h + +SOURCES += shapesplugin.cpp + +DESTDIR = lib +OBJECTS_DIR = tmp +MOC_DIR = tmp + diff --git a/doc/src/snippets/declarative/graphicswidgets/main.qml b/doc/src/snippets/declarative/graphicswidgets/main.qml new file mode 100644 index 0000000..ffcf79d --- /dev/null +++ b/doc/src/snippets/declarative/graphicswidgets/main.qml @@ -0,0 +1,32 @@ +import Qt 4.7 +import Qt.widgets 4.7 + +Rectangle { + width: 200 + height: 200 + + RedSquare { + id: square + width: 80 + height: 80 + } + + BlueCircle { + anchors.left: square.right + width: 80 + height: 80 + } + + QGraphicsWidget { + anchors.top: square.bottom + size.width: 80 + size.height: 80 + layout: QGraphicsLinearLayout { + LayoutItem { + preferredSize: "100x100" + Rectangle { color: "yellow"; anchors.fill: parent } + } + } + } +} + diff --git a/doc/src/snippets/declarative/graphicswidgets/qmldir b/doc/src/snippets/declarative/graphicswidgets/qmldir new file mode 100644 index 0000000..f94dad2 --- /dev/null +++ b/doc/src/snippets/declarative/graphicswidgets/qmldir @@ -0,0 +1 @@ +plugin graphicswidgets lib diff --git a/doc/src/snippets/declarative/graphicswidgets/redsquare.h b/doc/src/snippets/declarative/graphicswidgets/redsquare.h new file mode 100644 index 0000000..3050662 --- /dev/null +++ b/doc/src/snippets/declarative/graphicswidgets/redsquare.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** 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 documentation 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$ +** +****************************************************************************/ +//![0] +#include +#include + +class RedSquare : public QGraphicsWidget +{ + Q_OBJECT +public: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + { + painter->fillRect(0, 0, size().width(), size().height(), QColor(Qt::red)); + } +}; +//![0] diff --git a/doc/src/snippets/declarative/graphicswidgets/shapesplugin.cpp b/doc/src/snippets/declarative/graphicswidgets/shapesplugin.cpp new file mode 100644 index 0000000..4c18ef3 --- /dev/null +++ b/doc/src/snippets/declarative/graphicswidgets/shapesplugin.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** 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 documentation 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$ +** +****************************************************************************/ +//![0] +#include "redsquare.h" +#include "bluecircle.h" + +#include +#include + +class ShapesPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + void registerTypes(const char *uri) { + qmlRegisterType(uri, 1, 0, "RedSquare"); + qmlRegisterType(uri, 1, 0, "BlueCircle"); + } +}; + +#include "shapesplugin.moc" + +Q_EXPORT_PLUGIN2(shapesplugin, ShapesPlugin); +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro b/doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro new file mode 100644 index 0000000..68eeaf2 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro @@ -0,0 +1,2 @@ +QT += declarative +SOURCES += main.cpp diff --git a/doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp b/doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp new file mode 100644 index 0000000..4073a6c --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 documentation 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 + +//![0] +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QDeclarativeView view; + QDeclarativeContext *context = view.rootContext(); + context->setContextProperty("backgroundColor", + QColor(Qt::yellow)); + + view.setSource(QUrl::fromLocalFile("main.qml")); + view.show(); + + return app.exec(); +} +//![0] + +static void alternative() +{ + // Alternatively, if we don't actually want to display main.qml: +//![1] + QDeclarativeEngine engine; + QDeclarativeContext *windowContext = new QDeclarativeContext(engine.rootContext()); + windowContext->setContextProperty("backgroundColor", QColor(Qt::yellow)); + + QDeclarativeComponent component(&engine, "main.qml"); + QObject *window = component.create(windowContext); +//![1] +} + + diff --git a/doc/src/snippets/declarative/qtbinding/contextproperties/main.qml b/doc/src/snippets/declarative/qtbinding/contextproperties/main.qml new file mode 100644 index 0000000..1053f73 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/contextproperties/main.qml @@ -0,0 +1,15 @@ +//![0] +import Qt 4.7 + +Rectangle { + width: 300 + height: 300 + + color: backgroundColor + + Text { + anchors.centerIn: parent + text: "Hello Yellow World!" + } +} +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h new file mode 100644 index 0000000..d0d253a --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h @@ -0,0 +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 documentation 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 + +//![0] +class CustomPalette : public QObject +{ + Q_OBJECT + Q_PROPERTY(QColor background READ background WRITE setBackground NOTIFY backgroundChanged) + Q_PROPERTY(QColor text READ text WRITE setText NOTIFY textChanged) + +public: + CustomPalette() : m_background(Qt::white), m_text(Qt::black) {} + + QColor background() const { return m_background; } + void setBackground(const QColor &c) { + if (c != m_background) { + m_background = c; + emit backgroundChanged(); + } + } + + QColor text() const { return m_text; } + void setText(const QColor &c) { + if (c != m_text) { + m_text = c; + emit textChanged(); + } + } + +signals: + void textChanged(); + void backgroundChanged(); + +private: + QColor m_background; + QColor m_text; +}; + +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro new file mode 100644 index 0000000..e6af0d0 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro @@ -0,0 +1,3 @@ +QT += declarative +HEADERS += custompalette.h +SOURCES += main.cpp diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/main.cpp b/doc/src/snippets/declarative/qtbinding/custompalette/main.cpp new file mode 100644 index 0000000..dc651f6 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/custompalette/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 documentation 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 "custompalette.h" + +//![0] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QDeclarativeView view; + view.rootContext()->setContextProperty("palette", new CustomPalette); + + view.setSource(QUrl::fromLocalFile("main.qml")); + view.show(); + + return app.exec(); +} +//![0] + diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/main.qml b/doc/src/snippets/declarative/qtbinding/custompalette/main.qml new file mode 100644 index 0000000..f1a3b4f --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/custompalette/main.qml @@ -0,0 +1,22 @@ +//![0] +import Qt 4.7 + +Rectangle { + width: 240 + height: 320 + color: palette.background + + Text { + anchors.centerIn: parent + color: palette.text + text: "Click me to change color!" + } + + MouseArea { + anchors.fill: parent + onClicked: { + palette.text = "blue"; + } + } +} +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/resources/example.qrc b/doc/src/snippets/declarative/qtbinding/resources/example.qrc new file mode 100644 index 0000000..5e49415 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/resources/example.qrc @@ -0,0 +1,10 @@ + + + + + main.qml + images/background.png + + + + diff --git a/doc/src/snippets/declarative/qtbinding/resources/images/background.png b/doc/src/snippets/declarative/qtbinding/resources/images/background.png new file mode 100644 index 0000000..e69de29 diff --git a/doc/src/snippets/declarative/qtbinding/resources/main.cpp b/doc/src/snippets/declarative/qtbinding/resources/main.cpp new file mode 100644 index 0000000..5459b9e --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/resources/main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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 documentation 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 + +//![0] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QDeclarativeView view; + view.setSource(QUrl("qrc:/main.qml")); + view.show(); + + return app.exec(); +} +//![0] + diff --git a/doc/src/snippets/declarative/qtbinding/resources/main.qml b/doc/src/snippets/declarative/qtbinding/resources/main.qml new file mode 100644 index 0000000..dfe923f --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/resources/main.qml @@ -0,0 +1,7 @@ +//![0] +import Qt 4.7 + +Image { + source: "images/background.png" +} +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/resources/resources.pro b/doc/src/snippets/declarative/qtbinding/resources/resources.pro new file mode 100644 index 0000000..cc01ee1 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/resources/resources.pro @@ -0,0 +1,4 @@ +QT += declarative + +SOURCES += main.cpp +RESOURCES += example.qrc diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp b/doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp new file mode 100644 index 0000000..537a288 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 documentation 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 "stopwatch.h" + +#include +#include +#include + +//![0] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QDeclarativeView view; + view.rootContext()->setContextProperty("stopwatch", + new Stopwatch); + + view.setSource(QUrl::fromLocalFile("main.qml")); + view.show(); + + return app.exec(); +} +//![0] + diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/main.qml b/doc/src/snippets/declarative/qtbinding/stopwatch/main.qml new file mode 100644 index 0000000..2efa542 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/stopwatch/main.qml @@ -0,0 +1,18 @@ +//![0] +import Qt 4.7 + +Rectangle { + width: 300 + height: 300 + + MouseArea { + anchors.fill: parent + onClicked: { + if (stopwatch.isRunning()) + stopwatch.stop() + else + stopwatch.start(); + } + } +} +//![0] diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp new file mode 100644 index 0000000..4954a5f --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 documentation 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 "stopwatch.h" + +Stopwatch::Stopwatch() + : m_running(false) +{ +} + +bool Stopwatch::isRunning() const +{ + return m_running; +} + +void Stopwatch::start() +{ + m_running = true; +} + +void Stopwatch::stop() +{ + m_running = false; +} + diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h new file mode 100644 index 0000000..8d17121 --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 documentation 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 + +//![0] +class Stopwatch : public QObject +{ + Q_OBJECT +public: + Stopwatch(); + + Q_INVOKABLE bool isRunning() const; + +public slots: + void start(); + void stop(); + +private: + bool m_running; +}; + +//![0] + diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro new file mode 100644 index 0000000..d803e6a --- /dev/null +++ b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro @@ -0,0 +1,3 @@ +QT += declarative +HEADERS += stopwatch.h +SOURCES += main.cpp stopwatch.cpp -- cgit v0.12 From 24dc1ade82174b250dae154b699391db9754937c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 28 Apr 2010 14:32:23 +1000 Subject: Share Rectangle pixmap caches between items. --- .../graphicsitems/qdeclarativerectangle.cpp | 72 +++++++++++++--------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index fe656fa..b21ecdc 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -342,21 +342,28 @@ void QDeclarativeRectangle::generateRoundedRect() if (d->rectImage.isNull()) { const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; const int radius = qCeil(d->radius); //ensure odd numbered width/height so we get 1-pixel center - d->rectImage = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); - d->rectImage.fill(Qt::transparent); - QPainter p(&(d->rectImage)); - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); + + QString key = QLatin1String("q_") % QString::number(pw) % d->color.name() % QLatin1Char('_') % QString::number(radius) + % (d->pen && d->pen->isValid() ? d->pen->color().name() : QString()); + + if (!QPixmapCache::find(key, &d->rectImage)) { + d->rectImage = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); + d->rectImage.fill(Qt::transparent); + QPainter p(&(d->rectImage)); + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(d->color); + if (pw%2) + p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)), d->radius, d->radius); + else + p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw), d->radius, d->radius); + QPixmapCache::insert(key, d->rectImage); } - p.setBrush(d->color); - if (pw%2) - p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)), d->radius, d->radius); - else - p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw), d->radius, d->radius); } } @@ -365,22 +372,29 @@ void QDeclarativeRectangle::generateBorderedRect() Q_D(QDeclarativeRectangle); if (d->rectImage.isNull()) { const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); - d->rectImage.fill(Qt::transparent); - QPainter p(&(d->rectImage)); - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - pn.setJoinStyle(Qt::MiterJoin); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); + + QString key = QLatin1String("q_") % QString::number(pw) % d->color.name() + % (d->pen && d->pen->isValid() ? d->pen->color().name() : QString()); + + if (!QPixmapCache::find(key, &d->rectImage)) { + d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); + d->rectImage.fill(Qt::transparent); + QPainter p(&(d->rectImage)); + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + pn.setJoinStyle(Qt::MiterJoin); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(d->color); + if (pw%2) + p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1))); + else + p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw)); + QPixmapCache::insert(key, d->rectImage); } - p.setBrush(d->color); - if (pw%2) - p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1))); - else - p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw)); } } -- cgit v0.12 From 2489ac6515d6ae5a403974e151b9a6cba4a3ea3f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 28 Apr 2010 14:43:56 +1000 Subject: Don't unnecessarily regenerate property cache Improves compilation:boomblock benchmark by 22% --- src/declarative/qml/qdeclarativecompiler.cpp | 17 +++++-- src/declarative/qml/qdeclarativeengine_p.h | 56 +++++++++++++++++----- src/declarative/qml/qdeclarativepropertycache.cpp | 29 ++++++----- src/declarative/qml/qdeclarativepropertycache_p.h | 1 + .../util/qdeclarativeopenmetaobject.cpp | 2 +- .../qdeclarativedom/tst_qdeclarativedom.cpp | 4 +- 6 files changed, 77 insertions(+), 32 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 1727687..59a0d4d 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -938,19 +938,28 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj) meta.storeMeta.propertyCache = output->propertyCaches.count(); // ### Surely the creation of this property cache could be more efficient QDeclarativePropertyCache *propertyCache = 0; - if (tr.component && QDeclarativeComponentPrivate::get(tr.component)->cc->rootPropertyCache) { + if (tr.component) propertyCache = QDeclarativeComponentPrivate::get(tr.component)->cc->rootPropertyCache->copy(); - } else { - propertyCache = QDeclarativePropertyCache::create(engine, obj->metaObject()->superClass()); - } + else + propertyCache = QDeclarativeEnginePrivate::get(engine)->cache(obj->metaObject()->superClass())->copy(); + propertyCache->append(engine, obj->metaObject(), QDeclarativePropertyCache::Data::NoFlags, QDeclarativePropertyCache::Data::IsVMEFunction); + if (obj == unitRoot) { propertyCache->addref(); output->rootPropertyCache = propertyCache; } + output->propertyCaches << propertyCache; output->bytecode << meta; + } else if (obj == unitRoot) { + if (tr.component) + output->rootPropertyCache = QDeclarativeComponentPrivate::get(tr.component)->cc->rootPropertyCache; + else + output->rootPropertyCache = QDeclarativeEnginePrivate::get(engine)->cache(obj->metaObject()); + + output->rootPropertyCache->addref(); } // Set the object id diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 743275e..ca033bf 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -244,18 +244,8 @@ public: QDeclarativeValueTypeFactory valueTypes; QHash propertyCache; - QDeclarativePropertyCache *cache(QObject *obj) { - Q_Q(QDeclarativeEngine); - if (!obj || QObjectPrivate::get(obj)->metaObject || - QObjectPrivate::get(obj)->wasDeleted) return 0; - const QMetaObject *mo = obj->metaObject(); - QDeclarativePropertyCache *rv = propertyCache.value(mo); - if (!rv) { - rv = QDeclarativePropertyCache::create(q, mo); - propertyCache.insert(mo, rv); - } - return rv; - } + inline QDeclarativePropertyCache *cache(QObject *obj); + inline QDeclarativePropertyCache *cache(const QMetaObject *); // ### This whole class is embarrassing struct Imports { @@ -361,6 +351,48 @@ public: static void defineModule(); }; +/*! +Returns a QDeclarativePropertyCache for \a obj if one is available. + +If \a obj is null, being deleted or contains a dynamic meta object 0 +is returned. +*/ +QDeclarativePropertyCache *QDeclarativeEnginePrivate::cache(QObject *obj) +{ + Q_Q(QDeclarativeEngine); + if (!obj || QObjectPrivate::get(obj)->metaObject || QObjectPrivate::get(obj)->wasDeleted) + return 0; + + const QMetaObject *mo = obj->metaObject(); + QDeclarativePropertyCache *rv = propertyCache.value(mo); + if (!rv) { + rv = new QDeclarativePropertyCache(q, mo); + propertyCache.insert(mo, rv); + } + return rv; +} + +/*! +Returns a QDeclarativePropertyCache for \a metaObject. + +As the cache is persisted for the life of the engine, \a metaObject must be +a static "compile time" meta-object, or a meta-object that is otherwise known to +exist for the lifetime of the QDeclarativeEngine. +*/ +QDeclarativePropertyCache *QDeclarativeEnginePrivate::cache(const QMetaObject *metaObject) +{ + Q_Q(QDeclarativeEngine); + Q_ASSERT(metaObject); + + QDeclarativePropertyCache *rv = propertyCache.value(metaObject); + if (!rv) { + rv = new QDeclarativePropertyCache(q, metaObject); + propertyCache.insert(metaObject, rv); + } + + return rv; +} + QT_END_NAMESPACE #endif // QDECLARATIVEENGINE_P_H diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 888945b..f04a706 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -106,9 +106,25 @@ void QDeclarativePropertyCache::Data::load(const QMetaMethod &m) } +/*! +Creates a new empty QDeclarativePropertyCache. +*/ QDeclarativePropertyCache::QDeclarativePropertyCache(QDeclarativeEngine *e) : QDeclarativeCleanup(e), engine(e) { + Q_ASSERT(engine); +} + +/*! +Creates a new QDeclarativePropertyCache of \a metaObject. +*/ +QDeclarativePropertyCache::QDeclarativePropertyCache(QDeclarativeEngine *e, const QMetaObject *metaObject) +: QDeclarativeCleanup(e), engine(e) +{ + Q_ASSERT(engine); + Q_ASSERT(metaObject); + + update(engine, metaObject); } QDeclarativePropertyCache::~QDeclarativePropertyCache() @@ -135,7 +151,7 @@ void QDeclarativePropertyCache::clear() } QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObject *metaObject, - const QString &property) + const QString &property) { Q_ASSERT(metaObject); @@ -245,17 +261,6 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb } } -// ### Optimize - check engine for the parent meta object etc. -QDeclarativePropertyCache *QDeclarativePropertyCache::create(QDeclarativeEngine *engine, const QMetaObject *metaObject) -{ - Q_ASSERT(engine); - Q_ASSERT(metaObject); - - QDeclarativePropertyCache *cache = new QDeclarativePropertyCache(engine); - cache->update(engine, metaObject); - return cache; -} - void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaObject *metaObject) { Q_ASSERT(engine); diff --git a/src/declarative/qml/qdeclarativepropertycache_p.h b/src/declarative/qml/qdeclarativepropertycache_p.h index 6b64a96..b01e5cc 100644 --- a/src/declarative/qml/qdeclarativepropertycache_p.h +++ b/src/declarative/qml/qdeclarativepropertycache_p.h @@ -69,6 +69,7 @@ class QDeclarativePropertyCache : public QDeclarativeRefCount, public QDeclarati { public: QDeclarativePropertyCache(QDeclarativeEngine *); + QDeclarativePropertyCache(QDeclarativeEngine *, const QMetaObject *); virtual ~QDeclarativePropertyCache(); struct Data { diff --git a/src/declarative/util/qdeclarativeopenmetaobject.cpp b/src/declarative/util/qdeclarativeopenmetaobject.cpp index 0e5aaa6..ba5d534 100644 --- a/src/declarative/util/qdeclarativeopenmetaobject.cpp +++ b/src/declarative/util/qdeclarativeopenmetaobject.cpp @@ -305,7 +305,7 @@ void QDeclarativeOpenMetaObject::setCached(bool c) QDeclarativeData *qmldata = QDeclarativeData::get(d->object, true); if (d->cacheProperties) { if (!d->type->d->cache) - d->type->d->cache = QDeclarativePropertyCache::create(d->type->d->engine, this); + d->type->d->cache = new QDeclarativePropertyCache(d->type->d->engine, this); qmldata->propertyCache = d->type->d->cache; d->type->d->cache->addref(); } else { diff --git a/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp b/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp index a951827..6c19566 100644 --- a/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp +++ b/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp @@ -419,10 +419,8 @@ void tst_qdeclarativedom::loadSyntaxErrors() void tst_qdeclarativedom::loadRemoteErrors() { QByteArray qml = "import Qt 4.7\n" + "import \"http://localhost/exampleQmlScript.js\" as Script\n" "Item {\n" - " Script {\n" - " source: \"http://localhost/exampleQmlScript.js\"" - " }\n" "}"; QDeclarativeDomDocument document; QVERIFY(false == document.load(&engine, qml)); -- cgit v0.12 From 1e39096b259ff7979986911bf71f868edceec547 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 28 Apr 2010 14:54:09 +1000 Subject: Don't test snippets with C++ components --- tests/auto/declarative/examples/tst_examples.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index 16b0cbe..058fda1 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -89,6 +89,8 @@ tst_examples::tst_examples() excludedDirs << "examples/declarative/imageprovider"; excludedDirs << "demos/declarative/minehunt"; + excludedDirs << "doc/src/snippets/declarative/graphicswidgets"; + #ifdef QT_NO_WEBKIT excludedDirs << "examples/declarative/webview"; excludedDirs << "demos/declarative/webbrowser"; -- cgit v0.12 From ced09b4453c4be5897d41288963da20f31742579 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 28 Apr 2010 14:58:31 +1000 Subject: Remove unused variable --- src/declarative/qml/qdeclarativecompiler.cpp | 4 +--- src/declarative/qml/qdeclarativecompiler_p.h | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 59a0d4d..f64efcb 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -688,14 +688,12 @@ void QDeclarativeCompiler::compileTree(Object *tree) def.type = QDeclarativeInstruction::SetDefault; output->bytecode << def; - output->imports = unit->imports; - output->importCache = new QDeclarativeTypeNameCache(engine); for (int ii = 0; ii < importedScriptIndexes.count(); ++ii) output->importCache->add(importedScriptIndexes.at(ii), ii); - output->imports.cache(output->importCache, engine); + unit->imports.cache(output->importCache, engine); Q_ASSERT(tree->metatype); diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index fefab7a..cd612d8 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -84,7 +84,6 @@ public: QString name; QUrl url; - QDeclarativeEnginePrivate::Imports imports; QDeclarativeTypeNameCache *importCache; struct TypeReference -- cgit v0.12 From ad15433463b0d28e7bd024cba8641e00dd8d376f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 28 Apr 2010 15:07:36 +1000 Subject: Code cleanup --- src/declarative/qml/qdeclarativeengine.cpp | 473 +++++++++++++++-------------- 1 file changed, 238 insertions(+), 235 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 0ee6dfe..1f7f4a0 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1676,280 +1676,300 @@ static bool greaterThan(const QString &s1, const QString &s2) class QDeclarativeImportsPrivate { public: - QDeclarativeImportsPrivate() : ref(1) - { - } + QDeclarativeImportsPrivate(); + ~QDeclarativeImportsPrivate(); - ~QDeclarativeImportsPrivate() - { - foreach (QDeclarativeEnginePrivate::ImportedNamespace* s, set.values()) - delete s; - } + bool importExtension(const QString &absoluteFilePath, const QString &uri, + QDeclarativeEngine *engine, QDeclarativeDirComponents* components, + QString *errorString); - QSet qmlDirFilesForWhichPluginsHaveBeenLoaded; + QString resolvedUri(const QString &dir_arg, QDeclarativeEngine *engine); + bool add(const QUrl& base, const QDeclarativeDirComponents &qmldircomponentsnetwork, + const QString& uri_arg, const QString& prefix, + int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, + QDeclarativeEngine *engine, QString *errorString); + bool find(const QByteArray& type, int *vmajor, int *vminor, + QDeclarativeType** type_return, QUrl* url_return, QString *errorString); - bool importExtension(const QString &absoluteFilePath, const QString &uri, QDeclarativeEngine *engine, QDeclarativeDirComponents* components, QString *errorString) { - QFile file(absoluteFilePath); - QString filecontent; - if (file.open(QFile::ReadOnly)) { - filecontent = QString::fromUtf8(file.readAll()); - if (qmlImportTrace()) - qDebug() << "QDeclarativeEngine::add: loaded" << absoluteFilePath; - } else { - if (errorString) - *errorString = QDeclarativeEngine::tr("module \"%1\" definition \"%2\" not readable").arg(uri).arg(absoluteFilePath); - return false; - } - QDir dir = QFileInfo(file).dir(); + QDeclarativeEnginePrivate::ImportedNamespace *findNamespace(const QString& type); - QDeclarativeDirParser qmldirParser; - qmldirParser.setSource(filecontent); - qmldirParser.parse(); + QUrl base; + int ref; - if (! qmlDirFilesForWhichPluginsHaveBeenLoaded.contains(absoluteFilePath)) { - qmlDirFilesForWhichPluginsHaveBeenLoaded.insert(absoluteFilePath); +private: + friend struct QDeclarativeEnginePrivate::Imports; + QSet qmlDirFilesForWhichPluginsHaveBeenLoaded; + QDeclarativeEnginePrivate::ImportedNamespace unqualifiedset; + QHash set; +}; - foreach (const QDeclarativeDirParser::Plugin &plugin, qmldirParser.plugins()) { +QDeclarativeEnginePrivate::Imports::Imports(const Imports ©) +: d(copy.d) +{ + ++d->ref; +} - QString resolvedFilePath = - QDeclarativeEnginePrivate::get(engine) - ->resolvePlugin(dir, plugin.path, - plugin.name); +QDeclarativeEnginePrivate::Imports & +QDeclarativeEnginePrivate::Imports::operator =(const Imports ©) +{ + ++copy.d->ref; + if (--d->ref == 0) + delete d; + d = copy.d; + return *this; +} - if (!resolvedFilePath.isEmpty()) { - if (!engine->importPlugin(resolvedFilePath, uri, errorString)) { - if (errorString) - *errorString = QDeclarativeEngine::tr("plugin cannot be loaded for module \"%1\": %2").arg(uri).arg(*errorString); - return false; - } - } else { - if (errorString) - *errorString = QDeclarativeEngine::tr("module \"%1\" plugin \"%2\" not found").arg(uri).arg(plugin.name); - return false; - } - } - } +QDeclarativeEnginePrivate::Imports::Imports() +: d(new QDeclarativeImportsPrivate) +{ +} - if (components) - *components = qmldirParser.components(); +QDeclarativeEnginePrivate::Imports::~Imports() +{ + if (--d->ref == 0) + delete d; +} - return true; +QDeclarativeImportsPrivate::QDeclarativeImportsPrivate() +: ref(1) +{ +} + +QDeclarativeImportsPrivate::~QDeclarativeImportsPrivate() +{ + foreach (QDeclarativeEnginePrivate::ImportedNamespace* s, set.values()) + delete s; +} + +bool QDeclarativeImportsPrivate::importExtension(const QString &absoluteFilePath, const QString &uri, QDeclarativeEngine *engine, + QDeclarativeDirComponents* components, QString *errorString) +{ + QFile file(absoluteFilePath); + QString filecontent; + if (file.open(QFile::ReadOnly)) { + filecontent = QString::fromUtf8(file.readAll()); + if (qmlImportTrace()) + qDebug() << "QDeclarativeEngine::add: loaded" << absoluteFilePath; + } else { + if (errorString) + *errorString = QDeclarativeEngine::tr("module \"%1\" definition \"%2\" not readable").arg(uri).arg(absoluteFilePath); + return false; } + QDir dir = QFileInfo(file).dir(); - QString resolvedUri(const QString &dir_arg, QDeclarativeEngine *engine) - { - QString dir = dir_arg; - if (dir.endsWith(QLatin1Char('/')) || dir.endsWith(QLatin1Char('\\'))) - dir.chop(1); + QDeclarativeDirParser qmldirParser; + qmldirParser.setSource(filecontent); + qmldirParser.parse(); - QStringList paths = QDeclarativeEnginePrivate::get(engine)->fileImportPath; - qSort(paths.begin(), paths.end(), greaterThan); // Ensure subdirs preceed their parents. + if (! qmlDirFilesForWhichPluginsHaveBeenLoaded.contains(absoluteFilePath)) { + qmlDirFilesForWhichPluginsHaveBeenLoaded.insert(absoluteFilePath); - QString stableRelativePath = dir; - foreach( QString path, paths) { - if (dir.startsWith(path)) { - stableRelativePath = dir.mid(path.length()+1); - break; + + foreach (const QDeclarativeDirParser::Plugin &plugin, qmldirParser.plugins()) { + + QString resolvedFilePath = + QDeclarativeEnginePrivate::get(engine) + ->resolvePlugin(dir, plugin.path, + plugin.name); + + if (!resolvedFilePath.isEmpty()) { + if (!engine->importPlugin(resolvedFilePath, uri, errorString)) { + if (errorString) + *errorString = QDeclarativeEngine::tr("plugin cannot be loaded for module \"%1\": %2").arg(uri).arg(*errorString); + return false; + } + } else { + if (errorString) + *errorString = QDeclarativeEngine::tr("module \"%1\" plugin \"%2\" not found").arg(uri).arg(plugin.name); + return false; } } - stableRelativePath.replace(QLatin1Char('/'), QLatin1Char('.')); - stableRelativePath.replace(QLatin1Char('\\'), QLatin1Char('.')); - return stableRelativePath; } + if (components) + *components = qmldirParser.components(); + return true; +} +QString QDeclarativeImportsPrivate::resolvedUri(const QString &dir_arg, QDeclarativeEngine *engine) +{ + QString dir = dir_arg; + if (dir.endsWith(QLatin1Char('/')) || dir.endsWith(QLatin1Char('\\'))) + dir.chop(1); - bool add(const QUrl& base, const QDeclarativeDirComponents &qmldircomponentsnetwork, const QString& uri_arg, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, QDeclarativeEngine *engine, QString *errorString) - { - QDeclarativeDirComponents qmldircomponents = qmldircomponentsnetwork; - QString uri = uri_arg; - QDeclarativeEnginePrivate::ImportedNamespace *s; - if (prefix.isEmpty()) { - s = &unqualifiedset; - } else { - s = set.value(prefix); - if (!s) - set.insert(prefix,(s=new QDeclarativeEnginePrivate::ImportedNamespace)); + QStringList paths = QDeclarativeEnginePrivate::get(engine)->fileImportPath; + qSort(paths.begin(), paths.end(), greaterThan); // Ensure subdirs preceed their parents. + + QString stableRelativePath = dir; + foreach( QString path, paths) { + if (dir.startsWith(path)) { + stableRelativePath = dir.mid(path.length()+1); + break; } + } + stableRelativePath.replace(QLatin1Char('/'), QLatin1Char('.')); + stableRelativePath.replace(QLatin1Char('\\'), QLatin1Char('.')); + return stableRelativePath; +} +bool QDeclarativeImportsPrivate::add(const QUrl& base, const QDeclarativeDirComponents &qmldircomponentsnetwork, const QString& uri_arg, + const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, + QDeclarativeEngine *engine, QString *errorString) +{ + QDeclarativeDirComponents qmldircomponents = qmldircomponentsnetwork; + QString uri = uri_arg; + QDeclarativeEnginePrivate::ImportedNamespace *s; + if (prefix.isEmpty()) { + s = &unqualifiedset; + } else { + s = set.value(prefix); + if (!s) + set.insert(prefix,(s=new QDeclarativeEnginePrivate::ImportedNamespace)); + } - QString url = uri; - if (importType == QDeclarativeScriptParser::Import::Library) { - url.replace(QLatin1Char('.'), QLatin1Char('/')); - bool found = false; - QString dir; + QString url = uri; + if (importType == QDeclarativeScriptParser::Import::Library) { + url.replace(QLatin1Char('.'), QLatin1Char('/')); + bool found = false; + QString dir; - foreach (const QString &p, - QDeclarativeEnginePrivate::get(engine)->fileImportPath) { - dir = p+QLatin1Char('/')+url; - QFileInfo fi(dir+QLatin1String("/qmldir")); - const QString absoluteFilePath = fi.absoluteFilePath(); + foreach (const QString &p, + QDeclarativeEnginePrivate::get(engine)->fileImportPath) { + dir = p+QLatin1Char('/')+url; - if (fi.isFile()) { - found = true; + QFileInfo fi(dir+QLatin1String("/qmldir")); + const QString absoluteFilePath = fi.absoluteFilePath(); - url = QUrl::fromLocalFile(fi.absolutePath()).toString(); - uri = resolvedUri(dir, engine); - if (!importExtension(absoluteFilePath, uri, engine, &qmldircomponents, errorString)) - return false; - break; - } + if (fi.isFile()) { + found = true; + + url = QUrl::fromLocalFile(fi.absolutePath()).toString(); + uri = resolvedUri(dir, engine); + if (!importExtension(absoluteFilePath, uri, engine, &qmldircomponents, errorString)) + return false; + break; } + } + if (!found) { + found = QDeclarativeMetaType::isModule(uri.toUtf8(), vmaj, vmin); if (!found) { - found = QDeclarativeMetaType::isModule(uri.toUtf8(), vmaj, vmin); - if (!found) { - if (errorString) { - bool anyversion = QDeclarativeMetaType::isModule(uri.toUtf8(), -1, -1); - if (anyversion) - *errorString = QDeclarativeEngine::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin); - else - *errorString = QDeclarativeEngine::tr("module \"%1\" is not installed").arg(uri_arg); - } - return false; + if (errorString) { + bool anyversion = QDeclarativeMetaType::isModule(uri.toUtf8(), -1, -1); + if (anyversion) + *errorString = QDeclarativeEngine::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin); + else + *errorString = QDeclarativeEngine::tr("module \"%1\" is not installed").arg(uri_arg); } + return false; } - } else { + } + } else { - if (importType == QDeclarativeScriptParser::Import::File && qmldircomponents.isEmpty()) { - QUrl importUrl = base.resolved(QUrl(uri + QLatin1String("/qmldir"))); - QString localFileOrQrc = toLocalFileOrQrc(importUrl); - if (!localFileOrQrc.isEmpty()) { - QString dir = toLocalFileOrQrc(base.resolved(QUrl(uri))); - if (dir.isEmpty() || !QDir().exists(dir)) { - if (errorString) - *errorString = QDeclarativeEngine::tr("\"%1\": no such directory").arg(uri_arg); - return false; // local import dirs must exist - } - uri = resolvedUri(toLocalFileOrQrc(base.resolved(QUrl(uri))), engine); - if (uri.endsWith(QLatin1Char('/'))) - uri.chop(1); - if (QFile::exists(localFileOrQrc)) { - if (!importExtension(localFileOrQrc,uri,engine,&qmldircomponents,errorString)) - return false; - } - } else { - if (prefix.isEmpty()) { - // directory must at least exist for valid import - QString localFileOrQrc = toLocalFileOrQrc(base.resolved(QUrl(uri))); - if (localFileOrQrc.isEmpty() || !QDir().exists(localFileOrQrc)) { - if (errorString) { - if (localFileOrQrc.isEmpty()) - *errorString = QDeclarativeEngine::tr("import \"%1\" has no qmldir and no namespace").arg(uri); - else - *errorString = QDeclarativeEngine::tr("\"%1\": no such directory").arg(uri); - } - return false; + if (importType == QDeclarativeScriptParser::Import::File && qmldircomponents.isEmpty()) { + QUrl importUrl = base.resolved(QUrl(uri + QLatin1String("/qmldir"))); + QString localFileOrQrc = toLocalFileOrQrc(importUrl); + if (!localFileOrQrc.isEmpty()) { + QString dir = toLocalFileOrQrc(base.resolved(QUrl(uri))); + if (dir.isEmpty() || !QDir().exists(dir)) { + if (errorString) + *errorString = QDeclarativeEngine::tr("\"%1\": no such directory").arg(uri_arg); + return false; // local import dirs must exist + } + uri = resolvedUri(toLocalFileOrQrc(base.resolved(QUrl(uri))), engine); + if (uri.endsWith(QLatin1Char('/'))) + uri.chop(1); + if (QFile::exists(localFileOrQrc)) { + if (!importExtension(localFileOrQrc,uri,engine,&qmldircomponents,errorString)) + return false; + } + } else { + if (prefix.isEmpty()) { + // directory must at least exist for valid import + QString localFileOrQrc = toLocalFileOrQrc(base.resolved(QUrl(uri))); + if (localFileOrQrc.isEmpty() || !QDir().exists(localFileOrQrc)) { + if (errorString) { + if (localFileOrQrc.isEmpty()) + *errorString = QDeclarativeEngine::tr("import \"%1\" has no qmldir and no namespace").arg(uri); + else + *errorString = QDeclarativeEngine::tr("\"%1\": no such directory").arg(uri); } + return false; } } } - - url = base.resolved(QUrl(url)).toString(); - if (url.endsWith(QLatin1Char('/'))) - url.chop(1); } - if (vmaj > -1 && vmin > -1 && !qmldircomponents.isEmpty()) { - QList::ConstIterator it = qmldircomponents.begin(); - for (; it != qmldircomponents.end(); ++it) { - if (it->majorVersion > vmaj || (it->majorVersion == vmaj && it->minorVersion >= vmin)) - break; - } - if (it == qmldircomponents.end()) { - *errorString = QDeclarativeEngine::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin); - return false; - } - } - - s->uris.prepend(uri); - s->urls.prepend(url); - s->majversions.prepend(vmaj); - s->minversions.prepend(vmin); - s->isLibrary.prepend(importType == QDeclarativeScriptParser::Import::Library); - s->qmlDirComponents.prepend(qmldircomponents); - return true; + url = base.resolved(QUrl(url)).toString(); + if (url.endsWith(QLatin1Char('/'))) + url.chop(1); } - bool find(const QByteArray& type, int *vmajor, int *vminor, QDeclarativeType** type_return, - QUrl* url_return, QString *errorString) - { - QDeclarativeEnginePrivate::ImportedNamespace *s = 0; - int slash = type.indexOf('/'); - if (slash >= 0) { - QString namespaceName = QString::fromUtf8(type.left(slash)); - s = set.value(namespaceName); - if (!s) { - if (errorString) - *errorString = QDeclarativeEngine::tr("- %1 is not a namespace").arg(namespaceName); - return false; - } - int nslash = type.indexOf('/',slash+1); - if (nslash > 0) { - if (errorString) - *errorString = QDeclarativeEngine::tr("- nested namespaces not allowed"); - return false; - } - } else { - s = &unqualifiedset; + if (vmaj > -1 && vmin > -1 && !qmldircomponents.isEmpty()) { + QList::ConstIterator it = qmldircomponents.begin(); + for (; it != qmldircomponents.end(); ++it) { + if (it->majorVersion > vmaj || (it->majorVersion == vmaj && it->minorVersion >= vmin)) + break; } - QByteArray unqualifiedtype = slash < 0 ? type : type.mid(slash+1); // common-case opt (QString::mid works fine, but slower) - if (s) { - if (s->find(unqualifiedtype,vmajor,vminor,type_return,url_return, &base, errorString)) - return true; - if (s->urls.count() == 1 && !s->isLibrary[0] && url_return && s != &unqualifiedset) { - // qualified, and only 1 url - *url_return = QUrl(s->urls[0]+QLatin1Char('/')).resolved(QUrl(QString::fromUtf8(unqualifiedtype) + QLatin1String(".qml"))); - return true; - } + if (it == qmldircomponents.end()) { + *errorString = QDeclarativeEngine::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin); + return false; } - - return false; - } - - QDeclarativeEnginePrivate::ImportedNamespace *findNamespace(const QString& type) - { - return set.value(type); } - QUrl base; - int ref; - -private: - friend struct QDeclarativeEnginePrivate::Imports; - QDeclarativeEnginePrivate::ImportedNamespace unqualifiedset; - QHash set; -}; - -QDeclarativeEnginePrivate::Imports::Imports(const Imports ©) : - d(copy.d) -{ - ++d->ref; + s->uris.prepend(uri); + s->urls.prepend(url); + s->majversions.prepend(vmaj); + s->minversions.prepend(vmin); + s->isLibrary.prepend(importType == QDeclarativeScriptParser::Import::Library); + s->qmlDirComponents.prepend(qmldircomponents); + return true; } -QDeclarativeEnginePrivate::Imports &QDeclarativeEnginePrivate::Imports::operator =(const Imports ©) +bool QDeclarativeImportsPrivate::find(const QByteArray& type, int *vmajor, int *vminor, QDeclarativeType** type_return, + QUrl* url_return, QString *errorString) { - ++copy.d->ref; - if (--d->ref == 0) - delete d; - d = copy.d; - return *this; -} + QDeclarativeEnginePrivate::ImportedNamespace *s = 0; + int slash = type.indexOf('/'); + if (slash >= 0) { + QString namespaceName = QString::fromUtf8(type.left(slash)); + s = set.value(namespaceName); + if (!s) { + if (errorString) + *errorString = QDeclarativeEngine::tr("- %1 is not a namespace").arg(namespaceName); + return false; + } + int nslash = type.indexOf('/',slash+1); + if (nslash > 0) { + if (errorString) + *errorString = QDeclarativeEngine::tr("- nested namespaces not allowed"); + return false; + } + } else { + s = &unqualifiedset; + } + QByteArray unqualifiedtype = slash < 0 ? type : type.mid(slash+1); // common-case opt (QString::mid works fine, but slower) + if (s) { + if (s->find(unqualifiedtype,vmajor,vminor,type_return,url_return, &base, errorString)) + return true; + if (s->urls.count() == 1 && !s->isLibrary[0] && url_return && s != &unqualifiedset) { + // qualified, and only 1 url + *url_return = QUrl(s->urls[0]+QLatin1Char('/')).resolved(QUrl(QString::fromUtf8(unqualifiedtype) + QLatin1String(".qml"))); + return true; + } + } -QDeclarativeEnginePrivate::Imports::Imports() : - d(new QDeclarativeImportsPrivate) -{ + return false; } -QDeclarativeEnginePrivate::Imports::~Imports() +QDeclarativeEnginePrivate::ImportedNamespace *QDeclarativeImportsPrivate::findNamespace(const QString& type) { - if (--d->ref == 0) - delete d; + return set.value(type); } static QDeclarativeTypeNameCache *cacheForNamespace(QDeclarativeEngine *engine, const QDeclarativeEnginePrivate::ImportedNamespace &set, QDeclarativeTypeNameCache *cache) @@ -2000,22 +2020,6 @@ void QDeclarativeEnginePrivate::Imports::cache(QDeclarativeTypeNameCache *cache, cacheForNamespace(engine, set, cache); } -/* -QStringList QDeclarativeEnginePrivate::Imports::unqualifiedSet() const -{ - QStringList rv; - - const QDeclarativeEnginePrivate::ImportedNamespace &set = d->unqualifiedset; - - for (int ii = 0; ii < set.urls.count(); ++ii) { - if (set.isBuiltin.at(ii)) - rv << set.urls.at(ii); - } - - return rv; -} -*/ - /*! Sets the base URL to be used for all relative file imports added. */ @@ -2054,7 +2058,6 @@ void QDeclarativeEngine::addImportPath(const QString& path) } } - /*! Returns the list of directories where the engine searches for installed modules in a URL-based directory structure. -- cgit v0.12 From c102278ade3445c72db4b3b7c6ae592ef72eee22 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 28 Apr 2010 15:19:29 +1000 Subject: Doc: overview for Image --- .../graphicsitems/qdeclarativeimage.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 1031493..e00a9fd 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -54,6 +54,26 @@ QT_BEGIN_NAMESPACE \brief The Image element allows you to add bitmaps to a scene. \inherits Item + Displays the image from the specified \l source. If a size is not specified explicitly, + the Image element will be sized to the loaded image. + + If the source resolves to a network resource, the image will be loaded asynchronously, + updating the \l progress and \l status properties appropriately. + + Images which are available locally + will be loaded immediately, blocking the user interface. This is typically the + correct behavior for user interface elements. For large local images, which do not need + to be visible immediately, it may be preferable to enable \l asynchronous loading. + This will load the image in the background using a low priority thread. + + Images are cached and shared internally, so if several Image elements have the same source + only one copy of the image will be loaded. + + \bold Note: Images are often the greatest user of memory in QML UIs. It is recommended + that images which do not form part of the user interface have their + size bounded via the \l sourceSize property. This is especially important for content + that is loaded from external sources or provided by the user. + The Image element supports untransformed, stretched and tiled images. For an explanation of stretching and tiling, see the fillMode property description. @@ -107,7 +127,7 @@ QT_BEGIN_NAMESPACE } \endqml \endtable - */ +*/ /*! \internal -- cgit v0.12 From 9542bf254ed1c184ea2a31c92d267b71f5442b11 Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Wed, 28 Apr 2010 07:25:49 +0200 Subject: Bunch of doc fixes. Warnings --. Reviewed-by:TrustMe --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 50 +++++++++++++++++++--- src/declarative/qml/qdeclarativeengine.cpp | 6 ++- src/gui/graphicsview/qgraphicsitem.cpp | 13 ++++++ src/gui/graphicsview/qgraphicswidget.cpp | 17 +++++--- 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index bc0c65e..928c504 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1268,11 +1268,6 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec */ /*! - \property QDeclarativeItem::effect - \internal -*/ - -/*! \property QDeclarativeItem::focus \internal */ @@ -2728,29 +2723,48 @@ void QDeclarativeItem::setSmooth(bool smooth) update(); } +/*! + \internal + Return the width of the item +*/ qreal QDeclarativeItem::width() const { Q_D(const QDeclarativeItem); return d->width(); } +/*! + \internal + Set the width of the item +*/ void QDeclarativeItem::setWidth(qreal w) { Q_D(QDeclarativeItem); d->setWidth(w); } +/*! + \internal + Reset the width of the item +*/ void QDeclarativeItem::resetWidth() { Q_D(QDeclarativeItem); d->resetWidth(); } +/*! + \internal + Return the width of the item +*/ qreal QDeclarativeItemPrivate::width() const { return mWidth; } +/*! + \internal +*/ void QDeclarativeItemPrivate::setWidth(qreal w) { Q_Q(QDeclarativeItem); @@ -2770,7 +2784,10 @@ void QDeclarativeItemPrivate::setWidth(qreal w) QRectF(q->x(), q->y(), oldWidth, height())); } -void QDeclarativeItemPrivate ::resetWidth() +/*! + \internal +*/ +void QDeclarativeItemPrivate::resetWidth() { Q_Q(QDeclarativeItem); widthValid = false; @@ -2815,29 +2832,47 @@ bool QDeclarativeItem::widthValid() const return d->widthValid; } +/*! + \internal + Return the height of the item +*/ qreal QDeclarativeItem::height() const { Q_D(const QDeclarativeItem); return d->height(); } +/*! + \internal + Set the height of the item +*/ void QDeclarativeItem::setHeight(qreal h) { Q_D(QDeclarativeItem); d->setHeight(h); } +/*! + \internal + Reset the height of the item +*/ void QDeclarativeItem::resetHeight() { Q_D(QDeclarativeItem); d->resetHeight(); } +/*! + \internal +*/ qreal QDeclarativeItemPrivate::height() const { return mHeight; } +/*! + \internal +*/ void QDeclarativeItemPrivate::setHeight(qreal h) { Q_Q(QDeclarativeItem); @@ -2857,6 +2892,9 @@ void QDeclarativeItemPrivate::setHeight(qreal h) QRectF(q->x(), q->y(), width(), oldHeight)); } +/*! + \internal +*/ void QDeclarativeItemPrivate::resetHeight() { Q_Q(QDeclarativeItem); diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 1f7f4a0..e097edc 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -456,7 +456,11 @@ QDeclarativeEngine::~QDeclarativeEngine() } /*! \fn void QDeclarativeEngine::quit() - This signal is emitted when the QDeclarativeEngine quits. + This signal is emitted when the QDeclarativeEngine quits. + */ + +/*! \fn void QDeclarativeEngine::warnings(const QList &warnings) + This signal is emitted when \a warnings messages are generated by QML. */ /*! diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 326f130..ba674dd 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -7637,7 +7637,13 @@ void QGraphicsObject::ungrabGesture(Qt::GestureType gesture) manager->cleanupCachedGestures(this, gesture); } } +/*! + Updates the item's micro focus. This is slot for convenience. + + \since 4.7 + \sa QInputContext +*/ void QGraphicsObject::updateMicroFocus() { QGraphicsItem::updateMicroFocus(); @@ -7946,6 +7952,13 @@ void QGraphicsItemPrivate::resetHeight() */ /*! + \property QGraphicsObject::effect + \brief the effect attached to this item + + \sa QGraphicsItem::setGraphicsEffect(), QGraphicsItem::graphicsEffect() +*/ + +/*! \class QAbstractGraphicsShapeItem \brief The QAbstractGraphicsShapeItem class provides a common base for all path items. diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index bc8ccb01..28b474b 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -408,12 +408,6 @@ void QGraphicsWidget::setGeometry(const QRectF &rect) } /*! - \fn QGraphicsWidget::geometryChanged() - - This signal gets emitted whenever the geometry is changed in setGeometry(). -*/ - -/*! \fn QRectF QGraphicsWidget::rect() const Returns the item's local rect as a QRectF. This function is equivalent @@ -755,6 +749,17 @@ QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c } /*! + \property QGraphicsWidget::layout + \brief The layout of the widget +*/ + +/*! + \fn void QGraphicsWidget::layoutChanged() + This signal gets emitted whenever the layout of the item changes + \internal +*/ + +/*! Returns this widget's layout, or 0 if no layout is currently managing this widget. -- cgit v0.12 From 533ad9afa7131eeca36ea499ed1e2ec97ad63c64 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 28 Apr 2010 15:54:47 +1000 Subject: Alpha needs to be part of rectangle cache key. --- src/declarative/graphicsitems/qdeclarativerectangle.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index b21ecdc..7d499da 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -343,8 +343,9 @@ void QDeclarativeRectangle::generateRoundedRect() const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; const int radius = qCeil(d->radius); //ensure odd numbered width/height so we get 1-pixel center - QString key = QLatin1String("q_") % QString::number(pw) % d->color.name() % QLatin1Char('_') % QString::number(radius) - % (d->pen && d->pen->isValid() ? d->pen->color().name() : QString()); + QString key = QLatin1String("q_") % QString::number(pw) % d->color.name() % QString::number(d->color.alpha(), 16) % QLatin1Char('_') % QString::number(radius); + if (d->pen && d->pen->isValid()) + key += d->pen->color().name() % QString::number(d->pen->color().alpha(), 16); if (!QPixmapCache::find(key, &d->rectImage)) { d->rectImage = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); @@ -373,8 +374,9 @@ void QDeclarativeRectangle::generateBorderedRect() if (d->rectImage.isNull()) { const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - QString key = QLatin1String("q_") % QString::number(pw) % d->color.name() - % (d->pen && d->pen->isValid() ? d->pen->color().name() : QString()); + QString key = QLatin1String("q_") % QString::number(pw) % d->color.name() % QString::number(d->color.alpha(), 16); + if (d->pen && d->pen->isValid()) + key += d->pen->color().name() % QString::number(d->pen->color().alpha(), 16); if (!QPixmapCache::find(key, &d->rectImage)) { d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); -- cgit v0.12 From 4dcf8065c125d20dff1502c8b50c5fe1420925a9 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 28 Apr 2010 16:27:26 +1000 Subject: Fix QML default property HTML generation... again. --- tools/qdoc3/htmlgenerator.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp index 6b7d350..6c0369b 100644 --- a/tools/qdoc3/htmlgenerator.cpp +++ b/tools/qdoc3/htmlgenerator.cpp @@ -4333,14 +4333,6 @@ void HtmlGenerator::generateDetailedQmlMember(const Node *node, out() << "default "; generateQmlItem(qpn, relative, marker, false); out() << ""; - if (qpgn->isDefault()) { - out() << "" - << "" - << "
" - << "
" - << "" - << ""; - } } ++p; } -- cgit v0.12 From 7a196b7ac3fc224de56737fc6f1dfa6443e8f46c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 28 Apr 2010 17:19:16 +1000 Subject: Doc - micro fix. --- src/declarative/graphicsitems/qdeclarativepositioners.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 32a512b..13ee4e6 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -331,7 +331,6 @@ Column { \qml Column { spacing: 2 - remove: ... add: ... move: ... ... -- cgit v0.12 From f485eb96e84bc1b430be72d9cfd3b25b4e09128c Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 28 Apr 2010 17:36:02 +1000 Subject: Update border image examples. --- examples/declarative/border-image/animated.qml | 54 ------------------- examples/declarative/border-image/border-image.qml | 57 +++++++++++++++++++++ examples/declarative/border-image/borders.qml | 17 ------ .../border-image/content/MyBorderImage.qml | 5 +- .../border-image/content/ShadowRectangle.qml | 14 +++++ .../declarative/border-image/content/shadow.png | Bin 0 -> 588 bytes examples/declarative/border-image/shadows.qml | 24 +++++++++ 7 files changed, 98 insertions(+), 73 deletions(-) delete mode 100644 examples/declarative/border-image/animated.qml create mode 100644 examples/declarative/border-image/border-image.qml delete mode 100644 examples/declarative/border-image/borders.qml create mode 100644 examples/declarative/border-image/content/ShadowRectangle.qml create mode 100644 examples/declarative/border-image/content/shadow.png create mode 100644 examples/declarative/border-image/shadows.qml diff --git a/examples/declarative/border-image/animated.qml b/examples/declarative/border-image/animated.qml deleted file mode 100644 index c3ff9ef..0000000 --- a/examples/declarative/border-image/animated.qml +++ /dev/null @@ -1,54 +0,0 @@ -import Qt 4.7 -import "content" - -Rectangle { - id: page - width: 1030; height: 540 - - MyBorderImage { - x: 20; y: 20; minWidth: 120; maxWidth: 240 - minHeight: 120; maxHeight: 240 - source: "content/colors.png"; margin: 30 - } - MyBorderImage { - x: 270; y: 20; minWidth: 120; maxWidth: 240 - minHeight: 120; maxHeight: 240 - source: "content/colors.png"; margin: 30 - horizontalMode: BorderImage.Repeat; verticalMode: BorderImage.Repeat - } - MyBorderImage { - x: 520; y: 20; minWidth: 120; maxWidth: 240 - minHeight: 120; maxHeight: 240 - source: "content/colors.png"; margin: 30 - horizontalMode: BorderImage.Stretch; verticalMode: BorderImage.Repeat - } - MyBorderImage { - x: 770; y: 20; minWidth: 120; maxWidth: 240 - minHeight: 120; maxHeight: 240 - source: "content/colors.png"; margin: 30 - horizontalMode: BorderImage.Round; verticalMode: BorderImage.Round - } - MyBorderImage { - x: 20; y: 280; minWidth: 60; maxWidth: 200 - minHeight: 40; maxHeight: 200 - source: "content/bw.png"; margin: 10 - } - MyBorderImage { - x: 270; y: 280; minWidth: 60; maxWidth: 200 - minHeight: 40; maxHeight: 200 - source: "content/bw.png"; margin: 10 - horizontalMode: BorderImage.Repeat; verticalMode: BorderImage.Repeat - } - MyBorderImage { - x: 520; y: 280; minWidth: 60; maxWidth: 200 - minHeight: 40; maxHeight: 200 - source: "content/bw.png"; margin: 10 - horizontalMode: BorderImage.Stretch; verticalMode: BorderImage.Repeat - } - MyBorderImage { - x: 770; y: 280; minWidth: 60; maxWidth: 200 - minHeight: 40; maxHeight: 200 - source: "content/bw.png"; margin: 10 - horizontalMode: BorderImage.Round; verticalMode: BorderImage.Round - } -} diff --git a/examples/declarative/border-image/border-image.qml b/examples/declarative/border-image/border-image.qml new file mode 100644 index 0000000..c334cea --- /dev/null +++ b/examples/declarative/border-image/border-image.qml @@ -0,0 +1,57 @@ +import Qt 4.7 +import "content" + +Rectangle { + id: page + width: 1030; height: 540 + + Grid { + anchors.centerIn: parent; spacing: 20 + + MyBorderImage { + minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 240 + source: "content/colors.png"; margin: 30 + } + + MyBorderImage { + minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 240 + source: "content/colors.png"; margin: 30 + horizontalMode: BorderImage.Repeat; verticalMode: BorderImage.Repeat + } + + MyBorderImage { + minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 240 + source: "content/colors.png"; margin: 30 + horizontalMode: BorderImage.Stretch; verticalMode: BorderImage.Repeat + } + + MyBorderImage { + minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 240 + source: "content/colors.png"; margin: 30 + horizontalMode: BorderImage.Round; verticalMode: BorderImage.Round + } + + MyBorderImage { + minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200 + source: "content/bw.png"; margin: 10 + } + + MyBorderImage { + minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200 + source: "content/bw.png"; margin: 10 + horizontalMode: BorderImage.Repeat; verticalMode: BorderImage.Repeat + } + + MyBorderImage { + minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200 + source: "content/bw.png"; margin: 10 + horizontalMode: BorderImage.Stretch; verticalMode: BorderImage.Repeat + } + + MyBorderImage { + minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200 + source: "content/bw.png"; margin: 10 + horizontalMode: BorderImage.Round; verticalMode: BorderImage.Round + } + } +} diff --git a/examples/declarative/border-image/borders.qml b/examples/declarative/border-image/borders.qml deleted file mode 100644 index 3743f7e..0000000 --- a/examples/declarative/border-image/borders.qml +++ /dev/null @@ -1,17 +0,0 @@ -import Qt 4.7 - -Rectangle { - id: page - width: 520; height: 280 - - BorderImage { - x: 20; y: 20; width: 230; height: 240 - smooth: true - source: "content/colors-stretch.sci" - } - BorderImage { - x: 270; y: 20; width: 230; height: 240 - smooth: true - source: "content/colors-round.sci" - } -} diff --git a/examples/declarative/border-image/content/MyBorderImage.qml b/examples/declarative/border-image/content/MyBorderImage.qml index f65f093..2573a14 100644 --- a/examples/declarative/border-image/content/MyBorderImage.qml +++ b/examples/declarative/border-image/content/MyBorderImage.qml @@ -1,6 +1,8 @@ import Qt 4.7 Item { + id: container + property alias horizontalMode: image.horizontalTileMode property alias verticalMode: image.verticalTileMode property alias source: image.source @@ -11,11 +13,10 @@ Item { property int maxHeight property int margin - id: container width: 240; height: 240 BorderImage { - id: image; x: container.width / 2 - width / 2; y: container.height / 2 - height / 2 + id: image; anchors.centerIn: parent SequentialAnimation on width { loops: Animation.Infinite diff --git a/examples/declarative/border-image/content/ShadowRectangle.qml b/examples/declarative/border-image/content/ShadowRectangle.qml new file mode 100644 index 0000000..629478b --- /dev/null +++ b/examples/declarative/border-image/content/ShadowRectangle.qml @@ -0,0 +1,14 @@ +import Qt 4.7 + +Item { + property alias color : rectangle.color + + BorderImage { + anchors.fill: rectangle + anchors { leftMargin: -6; topMargin: -6; rightMargin: -8; bottomMargin: -8 } + border { left: 10; top: 10; right: 10; bottom: 10 } + source: "shadow.png"; smooth: true + } + + Rectangle { id: rectangle; anchors.fill: parent } +} diff --git a/examples/declarative/border-image/content/shadow.png b/examples/declarative/border-image/content/shadow.png new file mode 100644 index 0000000..431af85 Binary files /dev/null and b/examples/declarative/border-image/content/shadow.png differ diff --git a/examples/declarative/border-image/shadows.qml b/examples/declarative/border-image/shadows.qml new file mode 100644 index 0000000..a08d133 --- /dev/null +++ b/examples/declarative/border-image/shadows.qml @@ -0,0 +1,24 @@ +import Qt 4.7 +import "content" + +Rectangle { + id: window + + width: 480; height: 320 + color: "gray" + + ShadowRectangle { + anchors.centerIn: parent; width: 250; height: 250 + color: "lightsteelblue" + } + + ShadowRectangle { + anchors.centerIn: parent; width: 200; height: 200 + color: "steelblue" + } + + ShadowRectangle { + anchors.centerIn: parent; width: 150; height: 150 + color: "thistle" + } +} -- cgit v0.12 From 2df82c21337506404c353a433adf48c62738a584 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 28 Apr 2010 18:31:03 +1000 Subject: Improve border image documentation. --- .../graphicsitems/qdeclarativeborderimage.cpp | 34 +++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp index 06f8363..14a2cab 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp @@ -57,9 +57,25 @@ QT_BEGIN_NAMESPACE \inherits Item \since 4.7 + A BorderImage breaks an image into 9 sections, as shown below: + + \image declarative-scalegrid.png + + When the image is scaled: + \list + \i the corners (sections 1, 3, 7, and 9) are not scaled at all + \i sections 2 and 8 are scaled according to \l{BorderImage::horizontalTileMode}{horizontalTileMode} + \i sections 4 and 6 are scaled according to \l{BorderImage::verticalTileMode}{verticalTileMode} + \i the middle (section 5) is scaled according to both \l{BorderImage::horizontalTileMode}{horizontalTileMode} and \l{BorderImage::verticalTileMode}{verticalTileMode} + \endlist + + Examples: \snippet snippets/declarative/border-image.qml 0 \image BorderImage.png + + The \l{declarative/border-image}{BorderImage example} shows how a BorderImage can be used to simulate a shadow effect on a + rectangular item. */ /*! @@ -255,21 +271,17 @@ void QDeclarativeBorderImage::load() \qmlproperty int BorderImage::border.top \qmlproperty int BorderImage::border.bottom - \target ImagexmlpropertiesscaleGrid - - The 4 border lines (2 horizontal and 2 vertical) break an image into 9 sections, as shown below: + The 4 border lines (2 horizontal and 2 vertical) break the image into 9 sections, as shown below: \image declarative-scalegrid.png - When the image is scaled: - \list - \i the corners (sections 1, 3, 7, and 9) are not scaled at all - \i sections 2 and 8 are scaled according to \l{BorderImage::horizontalTileMode}{horizontalTileMode} - \i sections 4 and 6 are scaled according to \l{BorderImage::verticalTileMode}{verticalTileMode} - \i the middle (section 5) is scaled according to both \l{BorderImage::horizontalTileMode}{horizontalTileMode} and \l{BorderImage::verticalTileMode}{verticalTileMode} - \endlist + Each border line (left, right, top, and bottom) specifies an offset in pixels from the respective side. - Each border line (left, right, top, and bottom) specifies an offset from the respective side. For example, \c{border.bottom: 10} sets the bottom line 10 pixels up from the bottom of the image. + For example: + \qml + border.bottom: 10 + \endqml + sets the bottom line 10 pixels up from the bottom of the image. The border lines can also be specified using a \l {BorderImage::source}{.sci file}. -- cgit v0.12 From f8f87a70993eaed6de9bd7c614663282e8d80e46 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 29 Apr 2010 09:17:31 +1000 Subject: Compile on OSX, hopefully. --- src/declarative/graphicsitems/qdeclarativerectangle.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index 7d499da..ccabbde 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -43,6 +43,7 @@ #include "private/qdeclarativerectangle_p_p.h" #include +#include #include QT_BEGIN_NAMESPACE -- cgit v0.12 From fd7c1acef4bd3b1aa4b160592af140bd87c21829 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 28 Apr 2010 17:35:59 +1000 Subject: Fix references to createComponent() and createQmlObject() to Qt.createComponent() and Qt.createQmlObject(). Also move code into snippets/ for verification. --- doc/src/declarative/advtutorial.qdoc | 2 +- doc/src/declarative/dynamicobjects.qdoc | 90 ++++++++++------------- doc/src/declarative/globalobject.qdoc | 81 +++++++------------- doc/src/snippets/declarative/Sprite.qml | 3 + doc/src/snippets/declarative/componentCreation.js | 57 ++++++++++++++ doc/src/snippets/declarative/createComponent.qml | 9 +++ doc/src/snippets/declarative/createQmlObject.qml | 18 +++++ 7 files changed, 151 insertions(+), 109 deletions(-) create mode 100644 doc/src/snippets/declarative/Sprite.qml create mode 100644 doc/src/snippets/declarative/componentCreation.js create mode 100644 doc/src/snippets/declarative/createComponent.qml create mode 100644 doc/src/snippets/declarative/createQmlObject.qml diff --git a/doc/src/declarative/advtutorial.qdoc b/doc/src/declarative/advtutorial.qdoc index 2d05850..42ce246 100644 --- a/doc/src/declarative/advtutorial.qdoc +++ b/doc/src/declarative/advtutorial.qdoc @@ -174,7 +174,7 @@ The \c createBlock() function creates a block from the \c Block.qml file and moves the new block to its position on the game canvas. This involves several steps: \list -\o \l {createComponent(url file)}{createComponent()} is called to generate an element from \c Block.qml. +\o \l {Qt.createComponent(url file)}{Qt.createComponent()} is called to generate an element from \c Block.qml. If the component is ready, we can call \c createObject() to create an instance of the \c Block item. \o If \c createObject() returned null (i.e. if there was an error while loading the object), print the error information. diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc index 4cb5198..a2b65a8 100644 --- a/doc/src/declarative/dynamicobjects.qdoc +++ b/doc/src/declarative/dynamicobjects.qdoc @@ -62,65 +62,49 @@ item which you want to manage dynamic instances of, and creating an item from a string of QML is intended for when the QML itself is generated at runtime. If you have a component specified in a QML file, you can dynamically load it with -the \l {createComponent(url file)}{createComponent()} function on the \l{QML Global Object}. +the \l {Qt.createComponent(url file)}{Qt.createComponent()} function on the \l{QML Global Object}. This function takes the URL of the QML file as its only argument and returns a component object which can be used to create and load that QML file. Once you have a component you can use its \c createObject() method to create an instance of -the component. Example QML script is below. Remember that QML files that might be loaded - over the network cannot be expected to be ready immediately. - \code - var component; - var sprite; - function finishCreation() { - if(component.isReady()) { - sprite = component.createObject(); - if(sprite == 0) { - // Error Handling - } else { - sprite.parent = page; - sprite.x = 200; - //... - } - } else if(component.isError()) { - // Error Handling - } - } +the component. - component = createComponent("Sprite.qml"); - if(component.isReady()) { - finishCreation(); - } else { - component.statusChanged.connect(finishCreation); - } - \endcode - - If you are certain the files will be local, you could simplify to - - \code - component = createComponent("Sprite.qml"); - sprite = component.createObject(); - if(sprite == 0) { - // Error Handling - console.log(component.errorsString()); - } else { - sprite.parent = page; - sprite.x = 200; - //... - } - \endcode +Here is an example. Here is a simple QML component defined in \c Sprite.qml: + +\quotefile doc/src/snippets/declarative/Sprite.qml + +Our main application file, \c main.qml, imports a \c componentCreation.js JavaScript file +that will create \c Sprite objects: + +\quotefile doc/src/snippets/declarative/createComponent.qml + +Here is \c componentCreation.js. Remember that QML files that might be loaded +over the network cannot be expected to be ready immediately: + +\snippet doc/src/snippets/declarative/componentCreation.js 0 +\codeline +\snippet doc/src/snippets/declarative/componentCreation.js 1 +\snippet doc/src/snippets/declarative/componentCreation.js 2 +\snippet doc/src/snippets/declarative/componentCreation.js 4 +\codeline +\snippet doc/src/snippets/declarative/componentCreation.js 5 + +If you are certain the files will be local, you could simplify to: + +\snippet doc/src/snippets/declarative/componentCreation.js 3 + +Notice that once a \c Sprite object is created, its parent is set to \c appWindow (defined +in \c main.qml). After creating an item, you must set its parent to an item within the scene. +Otherwise your dynamically created item will not appear in the scene. + +When using files with relative paths, the path should +be relative to the file where \l {Qt.createComponent(url file)}{Qt.createComponent()} is executed. -After creating the item, remember to set its parent to an item within the scene. -Otherwise your dynamically created item will not appear in the scene. When using files with relative paths, the path should -be relative to the file where \c createComponent() is executed. +If the QML component does not exist until runtime, you can create a QML item from +a string of QML using the \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} function, as in the following example: -If the QML does not exist until runtime, you can create a QML item from -a string of QML using the \l{createQmlObject(string qml, object parent, string filepath)}{createQmlObject()} function, as in the following example: +\snippet doc/src/snippets/declarative/createQmlObject.qml 0 - \code - newObject = createQmlObject('import Qt 4.7; Rectangle { color: "red"; width: 20; height: 20 }', - targetItem, "dynamicSnippet1"); - \endcode The first argument is the string of QML to create. Just like in a new file, you will need to import any types you wish to use. For importing files with relative paths, the path should be relative to the file where the item in the second argument is defined. Remember to set the parent after @@ -135,9 +119,9 @@ will not have an id in QML. A restriction which you need to manage with dynamically created items, is that the creation context must outlive the -created item. The creation context is the QDeclarativeContext in which \c createComponent() +created item. The creation context is the QDeclarativeContext in which \c Qt.createComponent() was called, or the context in which the Component element, or the item used as the -second argument to \c createQmlObject(), was specified. If the creation +second argument to \c Qt.createQmlObject(), was specified. If the creation context is destroyed before the dynamic item is, then bindings in the dynamic item will fail to work. diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 57eaae7..6e6d253 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -211,86 +211,57 @@ The following functions on the global object allow you to dynamically create QML items from files or strings. See \l{Dynamic Object Management} for an overview of their use. -\section2 createComponent(url file) +\section2 Qt.createComponent(url file) This function takes the URL of a QML file as its only argument. It returns a component object which can be used to create and load that QML file. - Example QML script is below. Remember that QML files that might be loaded + Here is an example. Remember that QML files that might be loaded over the network cannot be expected to be ready immediately. - \code - var component; - var sprite; - function finishCreation(){ - if(component.isReady()){ - sprite = component.createObject(); - if(sprite == null){ - // Error Handling - }else{ - sprite.parent = page; - sprite.x = 200; - //... - } - }else if(component.isError()){ - // Error Handling - } - } - - component = createComponent("Sprite.qml"); - if(component.isReady()){ - finishCreation(); - }else{ - component.statusChanged.connect(finishCreation); - } - \endcode - - If you are certain the files will be local, you could simplify to - - \code - component = createComponent("Sprite.qml"); - sprite = component.createObject(); - if(sprite == null){ - // Error Handling - console.log(component.errorsString()); - }else{ - sprite.parent = page; - sprite.x = 200; - //... - } - \endcode + + \snippet doc/src/snippets/declarative/componentCreation.js 0 + \codeline + \snippet doc/src/snippets/declarative/componentCreation.js 1 + \snippet doc/src/snippets/declarative/componentCreation.js 2 + \snippet doc/src/snippets/declarative/componentCreation.js 4 + \codeline + \snippet doc/src/snippets/declarative/componentCreation.js 5 + + If you are certain the files will be local, you could simplify to: + + \snippet doc/src/snippets/declarative/componentCreation.js 3 The methods and properties of the Component element are defined in its own page, but when using it dynamically only two methods are usually used. - Component.createObject() returns the created object or null if there is an error. - If there is an error, Component.errorsString() describes what the error was. + \c Component.createObject() returns the created object or \c null if there is an error. + If there is an error, \l {Component::errorsString()}{Component.errorsString()} describes + the error that occurred. If you want to just create an arbitrary string of QML, instead of - loading a QML file, consider the createQmlObject() function. + loading a QML file, consider the \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} function. -\section2 createQmlObject(string qml, object parent, string filepath) +\section2 Qt.createQmlObject(string qml, object parent, string filepath) Creates a new object from the specified string of QML. It requires a second argument, which is the id of an existing QML object to use as the new object's parent. If a third argument is provided, this is used for error reporting as the filepath that the QML came from. - Example (where targetItem is the id of an existing QML item): - \code - newObject = createQmlObject('import Qt 4.7; Rectangle {color: "red"; width: 20; height: 20}', - targetItem, "dynamicSnippet1"); - \endcode + Example (where \c targetItem is the id of an existing QML item): + + \snippet doc/src/snippets/declarative/createQmlObject.qml 0 This function is intended for use inside QML only. It is intended to behave similarly to eval, but for creating QML elements. - Returns the created object, or null if there is an error. In the case of an + Returns the created object, \c or null if there is an error. In the case of an error, a QtScript Error object is thrown. This object has the additional property, qmlErrors, which is an array of all the errors encountered when trying to execute the - QML. Each object in the array has the members: lineNumber, columnNumber, fileName and message. + QML. Each object in the array has the members \c lineNumber, \c columnNumber, \c fileName and \c message. Note that this function returns immediately, and therefore may not work if the QML loads new components. If you are trying to load a new component, - for example from a QML file, consider the createComponent() function + for example from a QML file, consider the \l{Qt.createComponent(url file)}{Qt.createComponent()} function instead. 'New components' refers to external QML files that have not yet - been loaded, and so it is safe to use createQmlObject to load built-in + been loaded, and so it is safe to use \c Qt.createQmlObject() to load built-in components. \section1 XMLHttpRequest diff --git a/doc/src/snippets/declarative/Sprite.qml b/doc/src/snippets/declarative/Sprite.qml new file mode 100644 index 0000000..6670703 --- /dev/null +++ b/doc/src/snippets/declarative/Sprite.qml @@ -0,0 +1,3 @@ +import Qt 4.7 + +Rectangle { width: 80; height: 50; color: "red" } diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js new file mode 100644 index 0000000..be3e4d6 --- /dev/null +++ b/doc/src/snippets/declarative/componentCreation.js @@ -0,0 +1,57 @@ +//![0] +var component; +var sprite; + +function finishCreation() { + if (component.isReady) { + sprite = component.createObject(); + if (sprite == null) { + // Error Handling + } else { + sprite.parent = appWindow; + sprite.x = 100; + sprite.y = 100; + // ... + } + } else if (component.isError()) { + // Error Handling + console.log("Error loading component:", component.errorsString()); + } +} +//![0] + +//![1] +function createSpriteObjects() { +//![1] + + //![2] + component = Qt.createComponent("Sprite.qml"); + if (component.isReady) + finishCreation(); + else + component.statusChanged.connect(finishCreation); + //![2] + + //![3] + component = Qt.createComponent("Sprite.qml"); + sprite = component.createObject(); + + if (sprite == null) { + // Error Handling + console.log("Error loading component:", component.errorsString()); + } else { + sprite.parent = appWindow; + sprite.x = 100; + sprite.y = 100; + // ... + } + //![3] + +//![4] +} +//![4] + +//![5] +createSpriteObjects(); +//![5] + diff --git a/doc/src/snippets/declarative/createComponent.qml b/doc/src/snippets/declarative/createComponent.qml new file mode 100644 index 0000000..c4a1617 --- /dev/null +++ b/doc/src/snippets/declarative/createComponent.qml @@ -0,0 +1,9 @@ +import Qt 4.7 +import "componentCreation.js" as MyModule + +Rectangle { + id: appWindow + width: 300; height: 300 + + Component.onCompleted: MyModule.createSpriteObjects(); +} diff --git a/doc/src/snippets/declarative/createQmlObject.qml b/doc/src/snippets/declarative/createQmlObject.qml new file mode 100644 index 0000000..6b331c4 --- /dev/null +++ b/doc/src/snippets/declarative/createQmlObject.qml @@ -0,0 +1,18 @@ +import Qt 4.7 + +Rectangle { + id: targetItem + property QtObject newObject + + width: 100 + height: 100 + + function createIt() { +//![0] +newObject = Qt.createQmlObject('import Qt 4.7; Rectangle {color: "red"; width: 20; height: 20}', + targetItem, "dynamicSnippet1"); +//![0] + } + + Component.onCompleted: createIt() +} -- cgit v0.12 From c7e48e0ff2b49856e62379845731defd21d2134c Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 29 Apr 2010 09:55:46 +1000 Subject: Ignore QWS verbosity. --- .../declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp b/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp index 36908d9..dc9c2b2 100644 --- a/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp +++ b/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp @@ -122,6 +122,9 @@ void tst_qdeclarativefontloader::failLocalFont() { QString componentStr = "import Qt 4.7\nFontLoader { source: \"" + QUrl::fromLocalFile(SRCDIR "/data/dummy.ttf").toString() + "\" }"; QTest::ignoreMessage(QtWarningMsg, QString("file::2:1: QML FontLoader: Cannot load font: \"" + QUrl::fromLocalFile(SRCDIR "/data/dummy.ttf").toString() + "\"").toUtf8().constData()); +#ifdef Q_WS_QWS + QTest::ignoreMessage(QtDebugMsg, QString("FT_New_Face failed with index 0 : 51 ").toLatin1()); +#endif QDeclarativeComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QDeclarativeFontLoader *fontObject = qobject_cast(component.create()); -- cgit v0.12 From 6b0a0f14b20d16977f902a025b61ebbd54e72fc4 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 29 Apr 2010 09:57:28 +1000 Subject: Doc: Qt.MidButton -> Qt.MiddleButton --- src/declarative/graphicsitems/qdeclarativeevents.cpp | 4 ++-- src/declarative/graphicsitems/qdeclarativemousearea.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeevents.cpp b/src/declarative/graphicsitems/qdeclarativeevents.cpp index 4425c97..81ec6e1 100644 --- a/src/declarative/graphicsitems/qdeclarativeevents.cpp +++ b/src/declarative/graphicsitems/qdeclarativeevents.cpp @@ -151,7 +151,7 @@ Item { \list \o Qt.LeftButton \o Qt.RightButton - \o Qt.MidButton + \o Qt.MiddleButton \endlist */ @@ -174,7 +174,7 @@ Item { \list \o Qt.LeftButton \o Qt.RightButton - \o Qt.MidButton + \o Qt.MiddleButton \endlist */ diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index 0b9cf6e..c7b209a 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -365,7 +365,7 @@ void QDeclarativeMouseArea::setEnabled(bool a) \list \o Qt.LeftButton \o Qt.RightButton - \o Qt.MidButton + \o Qt.MiddleButton \endlist The code below displays "right" when the right mouse buttons is pressed: @@ -684,7 +684,7 @@ void QDeclarativeMouseArea::setHovered(bool h) \list \o Qt.LeftButton \o Qt.RightButton - \o Qt.MidButton + \o Qt.MiddleButton \endlist To accept more than one button the flags can be combined with the -- cgit v0.12 From b3fc4d9671cf885cbd7145f125af9da190716d78 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 29 Apr 2010 09:30:24 +1000 Subject: Prevent Behavior from being triggered on initialization. Add an additional private notification mechanism that is triggered after all QDeclarativeParserStatus items have had their componentComplete called. Task-number: QTBUG-6332 --- src/declarative/qml/qdeclarativecomponent.cpp | 15 +++++++++++++++ src/declarative/qml/qdeclarativecomponent_p.h | 1 + src/declarative/qml/qdeclarativeengine_p.h | 5 +++++ src/declarative/qml/qdeclarativevme.cpp | 1 + src/declarative/util/qdeclarativebehavior.cpp | 15 +++++++++++++-- src/declarative/util/qdeclarativebehavior_p.h | 3 +++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index d8bbb70..b83e9f4 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -754,6 +754,7 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *ctxt, QDe state->bindValues = enginePriv->bindValues; state->parserStatus = enginePriv->parserStatus; + state->finalizedParserStatus = enginePriv->finalizedParserStatus; state->componentAttached = enginePriv->componentAttached; if (state->componentAttached) state->componentAttached->prev = &state->componentAttached; @@ -761,6 +762,7 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *ctxt, QDe enginePriv->componentAttached = 0; enginePriv->bindValues.clear(); enginePriv->parserStatus.clear(); + enginePriv->finalizedParserStatus.clear(); state->completePending = true; enginePriv->inProgressCreations++; } @@ -785,6 +787,7 @@ void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeEnginePrivate *engi state->bindValues = enginePriv->bindValues; state->parserStatus = enginePriv->parserStatus; + state->finalizedParserStatus = enginePriv->finalizedParserStatus; state->componentAttached = enginePriv->componentAttached; if (state->componentAttached) state->componentAttached->prev = &state->componentAttached; @@ -792,6 +795,7 @@ void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeEnginePrivate *engi enginePriv->componentAttached = 0; enginePriv->bindValues.clear(); enginePriv->parserStatus.clear(); + enginePriv->finalizedParserStatus.clear(); state->completePending = true; enginePriv->inProgressCreations++; } @@ -826,6 +830,16 @@ void QDeclarativeComponentPrivate::complete(QDeclarativeEnginePrivate *enginePri QDeclarativeEnginePrivate::clear(ps); } + for (int ii = 0; ii < state->finalizedParserStatus.count(); ++ii) { + QPair, int> status = state->finalizedParserStatus.at(ii); + QObject *obj = status.first; + if (obj) { + void *args[] = { 0 }; + QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, + status.second, args); + } + } + while (state->componentAttached) { QDeclarativeComponentAttached *a = state->componentAttached; a->rem(); @@ -838,6 +852,7 @@ void QDeclarativeComponentPrivate::complete(QDeclarativeEnginePrivate *enginePri state->bindValues.clear(); state->parserStatus.clear(); + state->finalizedParserStatus.clear(); state->completePending = false; enginePriv->inProgressCreations--; diff --git a/src/declarative/qml/qdeclarativecomponent_p.h b/src/declarative/qml/qdeclarativecomponent_p.h index 24e5386..19aac84 100644 --- a/src/declarative/qml/qdeclarativecomponent_p.h +++ b/src/declarative/qml/qdeclarativecomponent_p.h @@ -102,6 +102,7 @@ public: ConstructionState() : componentAttached(0), completePending(false) {} QList > bindValues; QList > parserStatus; + QList, int> > finalizedParserStatus; QDeclarativeComponentAttached *componentAttached; QList errors; bool completePending; diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index ca033bf..b669f30 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -217,8 +217,13 @@ public: QList > bindValues; QList > parserStatus; + QList,int> > finalizedParserStatus; QDeclarativeComponentAttached *componentAttached; + void registerFinalizedParserStatusObject(QObject *obj, int index) { + finalizedParserStatus.append(qMakePair(QDeclarativeGuard(obj), index)); + } + bool inBeginCreate; QNetworkAccessManager *createNetworkAccessManager(QObject *parent) const; diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index 57bf726..3e63e24 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -898,6 +898,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, QDeclarativeEnginePrivate::clear(bindValues); QDeclarativeEnginePrivate::clear(parserStatus); + ep->finalizedParserStatus.clear(); return 0; } diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index 1089d31..90344ab 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include @@ -57,12 +58,13 @@ class QDeclarativeBehaviorPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QDeclarativeBehavior) public: - QDeclarativeBehaviorPrivate() : animation(0), enabled(true) {} + QDeclarativeBehaviorPrivate() : animation(0), enabled(true), finalized(false) {} QDeclarativeProperty property; QVariant currentValue; QDeclarativeGuard animation; bool enabled; + bool finalized; }; /*! @@ -158,7 +160,7 @@ void QDeclarativeBehavior::write(const QVariant &value) { Q_D(QDeclarativeBehavior); qmlExecuteDeferred(this); - if (!d->animation || !d->enabled) { + if (!d->animation || !d->enabled || !d->finalized) { QDeclarativePropertyPrivate::write(d->property, value, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); return; } @@ -189,6 +191,15 @@ void QDeclarativeBehavior::setTarget(const QDeclarativeProperty &property) d->currentValue = property.read(); if (d->animation) d->animation->setDefaultTarget(property); + + QDeclarativeEnginePrivate *engPriv = QDeclarativeEnginePrivate::get(qmlEngine(this)); + engPriv->registerFinalizedParserStatusObject(this, this->metaObject()->indexOfSlot("componentFinalized()")); +} + +void QDeclarativeBehavior::componentFinalized() +{ + Q_D(QDeclarativeBehavior); + d->finalized = true; } QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativebehavior_p.h b/src/declarative/util/qdeclarativebehavior_p.h index e8a809f..6c10eec 100644 --- a/src/declarative/util/qdeclarativebehavior_p.h +++ b/src/declarative/util/qdeclarativebehavior_p.h @@ -82,6 +82,9 @@ public: Q_SIGNALS: void enabledChanged(); + +private Q_SLOTS: + void componentFinalized(); }; QT_END_NAMESPACE -- cgit v0.12 From efab34ea95560db007b1a75cce63cf8f6431a683 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 29 Apr 2010 09:56:53 +1000 Subject: Additional Behavior test + text fixes. --- .../qdeclarativebehaviors/data/startup2.qml | 16 ++++++ .../tst_qdeclarativebehaviors.cpp | 65 ++++++++++++++-------- 2 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativebehaviors/data/startup2.qml diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/startup2.qml b/tests/auto/declarative/qdeclarativebehaviors/data/startup2.qml new file mode 100644 index 0000000..1911cc4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativebehaviors/data/startup2.qml @@ -0,0 +1,16 @@ +import Qt 4.7 + +Rectangle { + width: 800; + height: 480; + + Text { id:theText; text: "hello world" } + + Rectangle { + objectName: "innerRect" + color: "red" + x: theText.width + Behavior on x { NumberAnimation {} } + width: 100; height: 100 + } +} diff --git a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp index ee9e282..5e0c9d5 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp +++ b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include "../../../shared/util.h" @@ -230,11 +231,11 @@ void tst_qdeclarativebehaviors::emptyBehavior() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/empty.qml")); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); + QVERIFY(rect); rect->setState("moved"); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QTRY_COMPARE(x, qreal(200)); //should change immediately + QCOMPARE(x, qreal(200)); //should change immediately delete rect; } @@ -244,7 +245,7 @@ void tst_qdeclarativebehaviors::explicitSelection() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/explicit.qml")); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); + QVERIFY(rect); rect->setState("moved"); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->x() > 0); @@ -259,11 +260,11 @@ void tst_qdeclarativebehaviors::nonSelectingBehavior() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/nonSelecting2.qml")); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); + QVERIFY(rect); rect->setState("moved"); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QTRY_COMPARE(x, qreal(200)); //should change immediately + QCOMPARE(x, qreal(200)); //should change immediately delete rect; } @@ -275,10 +276,9 @@ void tst_qdeclarativebehaviors::reassignedAnimation() QString warning = QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml").toString() + ":9:9: QML Behavior: Cannot change the animation assigned to a Behavior."; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); - QTRY_COMPARE(qobject_cast( - qobject_cast( - rect->findChild("MyBehavior"))->animation())->duration(), 200); + QVERIFY(rect); + QCOMPARE(qobject_cast( + rect->findChild("MyBehavior")->animation())->duration(), 200); delete rect; } @@ -288,12 +288,12 @@ void tst_qdeclarativebehaviors::disabled() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/disabled.qml")); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); - QTRY_COMPARE(rect->findChild("MyBehavior")->enabled(), false); + QVERIFY(rect); + QCOMPARE(rect->findChild("MyBehavior")->enabled(), false); rect->setState("moved"); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QTRY_COMPARE(x, qreal(200)); //should change immediately + QCOMPARE(x, qreal(200)); //should change immediately delete rect; } @@ -307,28 +307,47 @@ void tst_qdeclarativebehaviors::dontStart() QString warning = c.url().toString() + ":13:13: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes."; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); + QVERIFY(rect); QDeclarativeAbstractAnimation *myAnim = rect->findChild("MyAnim"); - QTRY_VERIFY(myAnim && myAnim->qtAnimation()); - QTRY_VERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); + QVERIFY(myAnim && myAnim->qtAnimation()); + QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); delete rect; } void tst_qdeclarativebehaviors::startup() { - QDeclarativeEngine engine; - QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/startup.qml")); - QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); + { + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/startup.qml")); + QDeclarativeRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); - QDeclarativeRectangle *innerRect = rect->findChild("innerRect"); - QTRY_VERIFY(innerRect); + QDeclarativeRectangle *innerRect = rect->findChild("innerRect"); + QVERIFY(innerRect); - QTRY_COMPARE(innerRect->x(), qreal(100)); //should be set immediately + QCOMPARE(innerRect->x(), qreal(100)); //should be set immediately - delete rect; + delete rect; + } + + { + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/startup2.qml")); + QDeclarativeRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QDeclarativeRectangle *innerRect = rect->findChild("innerRect"); + QVERIFY(innerRect); + + QDeclarativeText *text = rect->findChild(); + QVERIFY(text); + + QCOMPARE(innerRect->x(), text->width()); //should be set immediately + + delete rect; + } } QTEST_MAIN(tst_qdeclarativebehaviors) -- cgit v0.12 From 44708167042e95ab4b5cfef8a19a9ab4f9484a71 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 29 Apr 2010 10:31:18 +1000 Subject: Stricter (but controllable) error reporting on Connections signal-name error. And test. --- src/declarative/util/qdeclarativeconnections.cpp | 44 ++++++++++++++++++---- src/declarative/util/qdeclarativeconnections_p.h | 4 ++ .../tst_qdeclarativeconnection.cpp | 37 ++++++++++++++++++ 3 files changed, 77 insertions(+), 8 deletions(-) diff --git a/src/declarative/util/qdeclarativeconnections.cpp b/src/declarative/util/qdeclarativeconnections.cpp index 20d878b..c23b623 100644 --- a/src/declarative/util/qdeclarativeconnections.cpp +++ b/src/declarative/util/qdeclarativeconnections.cpp @@ -57,11 +57,13 @@ QT_BEGIN_NAMESPACE class QDeclarativeConnectionsPrivate : public QObjectPrivate { public: - QDeclarativeConnectionsPrivate() : target(0), componentcomplete(false) {} + QDeclarativeConnectionsPrivate() : target(0), ignoreUnknownSignals(false), componentcomplete(false) {} QList boundsignals; QObject *target; + bool targetSet; + bool ignoreUnknownSignals; bool componentcomplete; QByteArray data; @@ -139,17 +141,21 @@ QDeclarativeConnections::~QDeclarativeConnections() \qmlproperty Object Connections::target This property holds the object that sends the signal. - By default, the target is assumed to be the parent of the Connections. + If not set at all, the target defaults to be the parent of the Connections. + + If set to null, no connection is made and any signal handlers are ignored + until the target is not null. */ QObject *QDeclarativeConnections::target() const { Q_D(const QDeclarativeConnections); - return d->target ? d->target : parent(); + return d->targetSet ? d->target : parent(); } void QDeclarativeConnections::setTarget(QObject *obj) { Q_D(QDeclarativeConnections); + d->targetSet = true; // even if setting to 0, it is *set* if (d->target == obj) return; foreach (QDeclarativeBoundSignal *s, d->boundsignals) { @@ -166,6 +172,29 @@ void QDeclarativeConnections::setTarget(QObject *obj) emit targetChanged(); } +/*! + \qmlproperty bool Connections::ignoreUnknownSignals + + Normally, you will get a runtime error if you try to connect + to signals on an object which the object does not have. + + By setting this flag to true, such errors are ignored. This is + useful if you intend to connect to different types of object, handling + a different set of signals for each. +*/ +bool QDeclarativeConnections::ignoreUnknownSignals() const +{ + Q_D(const QDeclarativeConnections); + return d->ignoreUnknownSignals; +} + +void QDeclarativeConnections::setIgnoreUnknownSignals(bool ignore) +{ + Q_D(QDeclarativeConnections); + d->ignoreUnknownSignals = ignore; +} + + QByteArray QDeclarativeConnectionsParser::compile(const QList &props) @@ -220,7 +249,7 @@ void QDeclarativeConnectionsParser::setCustomData(QObject *object, void QDeclarativeConnections::connectSignals() { Q_D(QDeclarativeConnections); - if (!d->componentcomplete) + if (!d->componentcomplete || (d->targetSet && !target())) return; QDataStream ds(d->data); @@ -230,15 +259,14 @@ void QDeclarativeConnections::connectSignals() QString script; ds >> script; QDeclarativeProperty prop(target(), propName); - if (!prop.isValid()) { - qmlInfo(this) << tr("Cannot assign to non-existent property \"%1\"").arg(propName); - } else if (prop.type() & QDeclarativeProperty::SignalProperty) { + if (prop.isValid() && (prop.type() & QDeclarativeProperty::SignalProperty)) { QDeclarativeBoundSignal *signal = new QDeclarativeBoundSignal(target(), prop.method(), this); signal->setExpression(new QDeclarativeExpression(qmlContext(this), script, 0)); d->boundsignals += signal; } else { - qmlInfo(this) << tr("Cannot assign to non-existent property \"%1\"").arg(propName); + if (!d->ignoreUnknownSignals) + qmlInfo(this) << tr("Cannot assign to non-existent property \"%1\"").arg(propName); } } } diff --git a/src/declarative/util/qdeclarativeconnections_p.h b/src/declarative/util/qdeclarativeconnections_p.h index 3eacf12..b51899e 100644 --- a/src/declarative/util/qdeclarativeconnections_p.h +++ b/src/declarative/util/qdeclarativeconnections_p.h @@ -65,6 +65,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeConnections : public QObject, public QDec Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) + Q_PROPERTY(bool ignoreUnknownSignals READ ignoreUnknownSignals WRITE setIgnoreUnknownSignals) public: QDeclarativeConnections(QObject *parent=0); @@ -73,6 +74,9 @@ public: QObject *target() const; void setTarget(QObject *); + bool ignoreUnknownSignals() const; + void setIgnoreUnknownSignals(bool ignore); + Q_SIGNALS: void targetChanged(); diff --git a/tests/auto/declarative/qdeclarativeconnection/tst_qdeclarativeconnection.cpp b/tests/auto/declarative/qdeclarativeconnection/tst_qdeclarativeconnection.cpp index 0efae3b..00e97ca 100644 --- a/tests/auto/declarative/qdeclarativeconnection/tst_qdeclarativeconnection.cpp +++ b/tests/auto/declarative/qdeclarativeconnection/tst_qdeclarativeconnection.cpp @@ -59,6 +59,8 @@ private slots: void connection(); void trimming(); void targetChanged(); + void unknownSignals_data(); + void unknownSignals(); private: QDeclarativeEngine engine; @@ -156,6 +158,41 @@ void tst_qdeclarativeconnection::targetChanged() delete item; } +void tst_qdeclarativeconnection::unknownSignals_data() +{ + QTest::addColumn("file"); + QTest::addColumn("error"); + + QTest::newRow("basic") << "connection-unknownsignals.qml" << ":6:5: QML Connections: Cannot assign to non-existent property \"onFooBar\""; + QTest::newRow("parent") << "connection-unknownsignals-parent.qml" << ":6:5: QML Connections: Cannot assign to non-existent property \"onFooBar\""; + QTest::newRow("ignored") << "connection-unknownsignals-ignored.qml" << ""; // should be NO error + QTest::newRow("notarget") << "connection-unknownsignals-notarget.qml" << ""; // should be NO error +} + +void tst_qdeclarativeconnection::unknownSignals() +{ + QFETCH(QString, file); + QFETCH(QString, error); + + QUrl url = QUrl::fromLocalFile(SRCDIR "/data/" + file); + if (!error.isEmpty()) { + QTest::ignoreMessage(QtWarningMsg, (url.toString() + error).toLatin1()); + } else { + // QTest has no way to insist no message (i.e. fail) + } + + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, url); + QDeclarativeItem *item = qobject_cast(c.create()); + QVERIFY(item != 0); + + // check that connection is created (they are all runtime errors) + QDeclarativeConnections *connections = item->findChild("connections"); + QVERIFY(connections); + + delete item; +} + QTEST_MAIN(tst_qdeclarativeconnection) #include "tst_qdeclarativeconnection.moc" -- cgit v0.12 From 1748ca68f3e129c0cff6b31000f1e7447297dfaf Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 29 Apr 2010 10:34:38 +1000 Subject: undebuggery --- tools/qml/qdeclarativefolderlistmodel.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/qml/qdeclarativefolderlistmodel.cpp b/tools/qml/qdeclarativefolderlistmodel.cpp index 5a9d88b..2ac71ad 100644 --- a/tools/qml/qdeclarativefolderlistmodel.cpp +++ b/tools/qml/qdeclarativefolderlistmodel.cpp @@ -340,7 +340,6 @@ void QDeclarativeFolderListModel::removed(const QModelIndex &index, int start, i void QDeclarativeFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) { - qDebug() << "data changed"; if (start.parent() == d->folderIndex) emit itemsChanged(start.row(), end.row() - start.row() + 1, roles()); } -- cgit v0.12 From c06769436a081b9f828e7fe85cca20450292689e Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 28 Apr 2010 20:06:00 +1000 Subject: Cleanup: Move import stuff out of the QDeclarativeEngine --- .../qml/qdeclarativecompiledbindings.cpp | 6 +- .../qml/qdeclarativecompiledbindings_p.h | 2 +- src/declarative/qml/qdeclarativecompiler.cpp | 65 +- src/declarative/qml/qdeclarativecompiler_p.h | 3 +- .../qml/qdeclarativecompositetypedata_p.h | 2 +- .../qml/qdeclarativecompositetypemanager.cpp | 34 +- src/declarative/qml/qdeclarativeengine.cpp | 824 +----------------- src/declarative/qml/qdeclarativeengine_p.h | 46 +- src/declarative/qml/qdeclarativeimport.cpp | 925 +++++++++++++++++++++ src/declarative/qml/qdeclarativeimport_p.h | 139 ++++ src/declarative/qml/qml.pri | 2 + 11 files changed, 1129 insertions(+), 919 deletions(-) create mode 100644 src/declarative/qml/qdeclarativeimport.cpp create mode 100644 src/declarative/qml/qdeclarativeimport_p.h diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index 6596aba..05b7dc6 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -572,7 +572,7 @@ struct QDeclarativeBindingCompilerPrivate QDeclarativeParser::Object *component; QDeclarativeParser::Property *destination; QHash ids; - QDeclarativeEnginePrivate::Imports imports; + QDeclarativeImports imports; QDeclarativeEnginePrivate *engine; QString contextName() const { return QLatin1String("$$$SCOPE_") + QString::number((intptr_t)context, 16); } @@ -1795,8 +1795,8 @@ bool QDeclarativeBindingCompilerPrivate::parseName(AST::Node *node, Result &type if (nameParts.at(ii + 1).at(0).isUpper()) return false; - QDeclarativeEnginePrivate::ImportedNamespace *ns = 0; - if (!engine->resolveType(imports, name.toUtf8(), &attachType, 0, 0, 0, &ns)) + QDeclarativeImportedNamespace *ns = 0; + if (!engine->importDatabase.resolveType(imports, name.toUtf8(), &attachType, 0, 0, 0, &ns)) return false; if (ns || !attachType || !attachType->attachedPropertiesType()) return false; diff --git a/src/declarative/qml/qdeclarativecompiledbindings_p.h b/src/declarative/qml/qdeclarativecompiledbindings_p.h index a17bc84..29a1092 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings_p.h +++ b/src/declarative/qml/qdeclarativecompiledbindings_p.h @@ -77,7 +77,7 @@ public: QDeclarativeParser::Property *property; QDeclarativeParser::Variant expression; QHash ids; - QDeclarativeEnginePrivate::Imports imports; + QDeclarativeImports imports; }; // -1 on failure, otherwise the binding index to use diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index f64efcb..6d420a7 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -607,6 +607,7 @@ bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine, Q_ASSERT(root); this->engine = engine; + this->enginePrivate = QDeclarativeEnginePrivate::get(engine); this->unit = unit; this->unitRoot = root; compileTree(root); @@ -624,6 +625,7 @@ bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine, savedCompileStates.clear(); output = 0; this->engine = 0; + this->enginePrivate = 0; this->unit = 0; this->unitRoot = 0; @@ -704,7 +706,7 @@ void QDeclarativeCompiler::compileTree(Object *tree) output->root = &output->rootData; } if (!tree->metadata.isEmpty()) - QDeclarativeEnginePrivate::get(engine)->registerCompositeType(output); + enginePrivate->registerCompositeType(output); } static bool ValuePtrLessThan(const Value *t1, const Value *t2) @@ -939,7 +941,7 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj) if (tr.component) propertyCache = QDeclarativeComponentPrivate::get(tr.component)->cc->rootPropertyCache->copy(); else - propertyCache = QDeclarativeEnginePrivate::get(engine)->cache(obj->metaObject()->superClass())->copy(); + propertyCache = enginePrivate->cache(obj->metaObject()->superClass())->copy(); propertyCache->append(engine, obj->metaObject(), QDeclarativePropertyCache::Data::NoFlags, QDeclarativePropertyCache::Data::IsVMEFunction); @@ -955,7 +957,7 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj) if (tr.component) output->rootPropertyCache = QDeclarativeComponentPrivate::get(tr.component)->cc->rootPropertyCache; else - output->rootPropertyCache = QDeclarativeEnginePrivate::get(engine)->cache(obj->metaObject()); + output->rootPropertyCache = enginePrivate->cache(obj->metaObject()); output->rootPropertyCache->addref(); } @@ -1366,9 +1368,9 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop, } QDeclarativeType *type = 0; - QDeclarativeEnginePrivate::ImportedNamespace *typeNamespace = 0; - QDeclarativeEnginePrivate::get(engine)->resolveType(unit->imports, prop->name, - &type, 0, 0, 0, &typeNamespace); + QDeclarativeImportedNamespace *typeNamespace = 0; + enginePrivate->importDatabase.resolveType(unit->imports, prop->name, + &type, 0, 0, 0, &typeNamespace); if (typeNamespace) { // ### We might need to indicate that this property is a namespace @@ -1443,7 +1445,7 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop, COMPILE_CHECK(buildGroupedProperty(prop, obj, ctxt)); - } else if (QDeclarativeEnginePrivate::get(engine)->isList(prop->type)) { + } else if (enginePrivate->isList(prop->type)) { COMPILE_CHECK(buildListProperty(prop, obj, ctxt)); @@ -1460,11 +1462,10 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop, return true; } -bool -QDeclarativeCompiler::buildPropertyInNamespace(QDeclarativeEnginePrivate::ImportedNamespace *ns, - QDeclarativeParser::Property *nsProp, - QDeclarativeParser::Object *obj, - const BindingContext &ctxt) +bool QDeclarativeCompiler::buildPropertyInNamespace(QDeclarativeImportedNamespace *ns, + QDeclarativeParser::Property *nsProp, + QDeclarativeParser::Object *obj, + const BindingContext &ctxt) { if (!nsProp->value) COMPILE_EXCEPTION(nsProp, tr("Invalid use of namespace")); @@ -1477,8 +1478,7 @@ QDeclarativeCompiler::buildPropertyInNamespace(QDeclarativeEnginePrivate::Import // Setup attached property data QDeclarativeType *type = 0; - QDeclarativeEnginePrivate::get(engine)->resolveTypeInNamespace(ns, prop->name, - &type, 0, 0, 0); + enginePrivate->importDatabase.resolveTypeInNamespace(ns, prop->name, &type, 0, 0, 0); if (!type || !type->attachedPropertiesType()) COMPILE_EXCEPTION(prop, tr("Non-existent attached object")); @@ -1499,7 +1499,7 @@ QDeclarativeCompiler::buildPropertyInNamespace(QDeclarativeEnginePrivate::Import void QDeclarativeCompiler::genValueProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj) { - if (QDeclarativeEnginePrivate::get(engine)->isList(prop->type)) { + if (enginePrivate->isList(prop->type)) { genListProperty(prop, obj); } else { genPropertyAssignment(prop, obj); @@ -1509,7 +1509,7 @@ void QDeclarativeCompiler::genValueProperty(QDeclarativeParser::Property *prop, void QDeclarativeCompiler::genListProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj) { - int listType = QDeclarativeEnginePrivate::get(engine)->listType(prop->type); + int listType = enginePrivate->listType(prop->type); QDeclarativeInstruction fetch; fetch.type = QDeclarativeInstruction::FetchQList; @@ -1763,8 +1763,7 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr } else { // Load the nested property's meta type - prop->value->metatype = - QDeclarativeEnginePrivate::get(engine)->metaObjectForType(prop->type); + prop->value->metatype = enginePrivate->metaObjectForType(prop->type); if (!prop->value->metatype) COMPILE_EXCEPTION(prop, tr("Invalid grouped property access")); @@ -1843,13 +1842,13 @@ bool QDeclarativeCompiler::buildListProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, const BindingContext &ctxt) { - Q_ASSERT(QDeclarativeEnginePrivate::get(engine)->isList(prop->type)); + Q_ASSERT(enginePrivate->isList(prop->type)); int t = prop->type; obj->addValueProperty(prop); - int listType = QDeclarativeEnginePrivate::get(engine)->listType(t); + int listType = enginePrivate->listType(t); bool listTypeIsInterface = QDeclarativeMetaType::isInterface(listType); bool assignedBinding = false; @@ -1964,8 +1963,7 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Pro // We want to raw metaObject here as the raw metaobject is the // actual property type before we applied any extensions that might // effect the properties on the type, but don't effect assignability - const QMetaObject *propertyMetaObject = - QDeclarativeEnginePrivate::get(engine)->rawMetaObjectForType(prop->type); + const QMetaObject *propertyMetaObject = enginePrivate->rawMetaObjectForType(prop->type); // Will be true if the assgned type inherits propertyMetaObject bool isAssignable = false; @@ -2107,8 +2105,8 @@ bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop QString typeName = parts.at(0); QDeclarativeType *type = 0; - QDeclarativeEnginePrivate::get(engine)->resolveType(unit->imports, typeName.toUtf8(), - &type, 0, 0, 0, 0); + enginePrivate->importDatabase.resolveType(unit->imports, typeName.toUtf8(), + &type, 0, 0, 0, 0); if (!type || obj->typeName != type->qmlTypeName()) return true; @@ -2135,7 +2133,7 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const int dot = script.indexOf('.'); if (dot > 0) { QDeclarativeType *type = 0; - QDeclarativeEnginePrivate::get(engine)->resolveType(unit->imports, script.left(dot), &type, 0, 0, 0, 0); + enginePrivate->importDatabase.resolveType(unit->imports, script.left(dot), &type, 0, 0, 0, 0); if (!type) return -1; const QMetaObject *mo = type->metaObject(); @@ -2289,13 +2287,12 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn QByteArray customTypeName; QDeclarativeType *qmltype = 0; QUrl url; - QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(engine); - if (!priv->resolveType(unit->imports, p.customType, &qmltype, - &url, 0, 0, 0)) + if (!enginePrivate->importDatabase.resolveType(unit->imports, p.customType, &qmltype, + &url, 0, 0, 0)) COMPILE_EXCEPTION(&p, tr("Invalid property type")); if (!qmltype) { - QDeclarativeCompositeTypeData *tdata = priv->typeManager.get(url); + QDeclarativeCompositeTypeData *tdata = enginePrivate->typeManager.get(url); Q_ASSERT(tdata); Q_ASSERT(tdata->status == QDeclarativeCompositeTypeData::Complete); @@ -2467,7 +2464,7 @@ bool QDeclarativeCompiler::checkValidId(QDeclarativeParser::Value *v, const QStr } - if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(val)) + if (enginePrivate->globalClass->illegalNames().contains(val)) COMPILE_EXCEPTION(v, tr( "ID illegally masks global JavaScript property")); return true; @@ -2660,8 +2657,8 @@ int QDeclarativeCompiler::genValueTypeData(QDeclarativeParser::Property *valueTy { QByteArray data = QDeclarativePropertyPrivate::saveValueType(prop->parent->metaObject(), prop->index, - QDeclarativeEnginePrivate::get(engine)->valueTypes[prop->type]->metaObject(), - valueTypeProp->index); + enginePrivate->valueTypes[prop->type]->metaObject(), + valueTypeProp->index); // valueTypeProp->index, valueTypeProp->type); return output->indexForByteArray(data); @@ -2697,7 +2694,7 @@ bool QDeclarativeCompiler::completeComponentBuild() expr.expression = binding.expression; expr.imports = unit->imports; - int index = bindingCompiler.compile(expr, QDeclarativeEnginePrivate::get(engine)); + int index = bindingCompiler.compile(expr, enginePrivate); if (index != -1) { binding.dataType = BindingReference::Experimental; binding.compiledIndex = index; @@ -2805,7 +2802,7 @@ void QDeclarativeCompiler::dumpStats() bool QDeclarativeCompiler::canCoerce(int to, QDeclarativeParser::Object *from) { const QMetaObject *toMo = - QDeclarativeEnginePrivate::get(engine)->rawMetaObjectForType(to); + enginePrivate->rawMetaObjectForType(to); const QMetaObject *fromMo = from->metaObject(); while (fromMo) { diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index cd612d8..908c703 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -191,7 +191,7 @@ private: const BindingContext &); bool buildProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, const BindingContext &); - bool buildPropertyInNamespace(QDeclarativeEnginePrivate::ImportedNamespace *ns, + bool buildPropertyInNamespace(QDeclarativeImportedNamespace *ns, QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, const BindingContext &); @@ -335,6 +335,7 @@ private: QList exceptions; QDeclarativeCompiledData *output; QDeclarativeEngine *engine; + QDeclarativeEnginePrivate *enginePrivate; QDeclarativeParser::Object *unitRoot; QDeclarativeCompositeTypeData *unit; }; diff --git a/src/declarative/qml/qdeclarativecompositetypedata_p.h b/src/declarative/qml/qdeclarativecompositetypedata_p.h index 47cb3b3..a0e4cc2 100644 --- a/src/declarative/qml/qdeclarativecompositetypedata_p.h +++ b/src/declarative/qml/qdeclarativecompositetypedata_p.h @@ -83,7 +83,7 @@ public: QList errors; - QDeclarativeEnginePrivate::Imports imports; + QDeclarativeImports imports; QList dependants; diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp index 0eb7e1b..0ea198d 100644 --- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp +++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp @@ -525,16 +525,15 @@ void QDeclarativeCompositeTypeManager::checkComplete(QDeclarativeCompositeTypeDa int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData *unit) { // not called until all resources are loaded (they include import URLs) - int waiting = 0; + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); + QDeclarativeImportDatabase &importDatabase = ep->importDatabase; - /* - For local urls, add an implicit import "." as first (most overridden) lookup. This will also trigger - the loading of the qmldir and the import of any native types from available plugins. - */ + // For local urls, add an implicit import "." as first (most overridden) lookup. + // This will also trigger the loading of the qmldir and the import of any native + // types from available plugins. { - QDeclarativeDirComponents qmldircomponentsnetwork; if (QDeclarativeCompositeTypeResource *resource = resources.value(unit->imports.baseUrl().resolved(QUrl(QLatin1String("./qmldir"))))) { @@ -544,14 +543,9 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData qmldircomponentsnetwork = parser.components(); } - QDeclarativeEnginePrivate::get(engine)-> - addToImport(&unit->imports, - qmldircomponentsnetwork, - QLatin1String("."), - QString(), - -1, -1, - QDeclarativeScriptParser::Import::File, - 0); // error ignored (just means no fallback) + importDatabase.addToImport(&unit->imports, qmldircomponentsnetwork, QLatin1String("."), + QString(), -1, -1, QDeclarativeScriptParser::Import::File, + 0); // error ignored (just means no fallback) } @@ -588,9 +582,8 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData } QString errorString; - if (!QDeclarativeEnginePrivate::get(engine)-> - addToImport(&unit->imports, qmldircomponentsnetwork, imp.uri, imp.qualifier, vmaj, vmin, imp.type, &errorString)) - { + if (!importDatabase.addToImport(&unit->imports, qmldircomponentsnetwork, imp.uri, imp.qualifier, + vmaj, vmin, imp.type, &errorString)) { QDeclarativeError error; error.setUrl(unit->imports.baseUrl()); error.setDescription(errorString); @@ -616,11 +609,10 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData QUrl url; int majorVersion; int minorVersion; - QDeclarativeEnginePrivate::ImportedNamespace *typeNamespace = 0; + QDeclarativeImportedNamespace *typeNamespace = 0; QString errorString; - if (!QDeclarativeEnginePrivate::get(engine)->resolveType(unit->imports, typeName, &ref.type, &url, &majorVersion, &minorVersion, &typeNamespace, &errorString) - || typeNamespace) - { + if (!importDatabase.resolveType(unit->imports, typeName, &ref.type, &url, &majorVersion, &minorVersion, + &typeNamespace, &errorString) || typeNamespace) { // Known to not be a type: // - known to be a namespace (Namespace {}) // - type with unknown namespace (UnknownNamespace.SomeType {}) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index e097edc..a22011a 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -111,9 +111,6 @@ Q_DECLARE_METATYPE(QDeclarativeProperty) QT_BEGIN_NAMESPACE -DEFINE_BOOL_CONFIG_OPTION(qmlImportTrace, QML_IMPORT_TRACE) -DEFINE_BOOL_CONFIG_OPTION(qmlCheckTypes, QML_CHECK_TYPES) - /*! \qmlclass QtObject QObject \since 4.7 @@ -158,7 +155,7 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) objectClass(0), valueTypeClass(0), globalClass(0), cleanup(0), erroredBindings(0), inProgressCreations(0), scriptEngine(this), workerScriptEngine(0), componentAttached(0), inBeginCreate(false), networkAccessManager(0), networkAccessManagerFactory(0), - typeManager(e), uniqueId(1) + typeManager(e), importDatabase(e), uniqueId(1) { if (!qt_QmlQtModule_registered) { qt_QmlQtModule_registered = true; @@ -168,27 +165,6 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) QDeclarativeValueTypeFactory::registerValueTypes(); } globalClass = new QDeclarativeGlobalScriptClass(&scriptEngine); - - // 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() && !fileImportPath.contains(canonicalPath)) - fileImportPath.append(canonicalPath); - } - } - QString builtinPath = QLibraryInfo::location(QLibraryInfo::ImportsPath); - if (!builtinPath.isEmpty()) - fileImportPath += builtinPath; - - filePluginPath += QLatin1String("."); - } QUrl QDeclarativeScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url) @@ -345,9 +321,6 @@ void QDeclarativeEnginePrivate::clear(SimpleList &pss) } Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer); -typedef QMap StringStringMap; -Q_GLOBAL_STATIC(StringStringMap, qmlEnginePluginsWithRegisteredTypes); // stores the uri - void QDeclarativePrivate::qdeclarativeelement_destructor(QObject *o) { @@ -1526,520 +1499,6 @@ QVariant QDeclarativeEnginePrivate::scriptValueToVariant(const QScriptValue &val return val.toVariant(); } -// XXX this beyonds in QUrl::toLocalFile() -// WARNING, there is a copy of this function in qdeclarativecompositetypemanager.cpp -static QString toLocalFileOrQrc(const QUrl& url) -{ - if (url.scheme() == QLatin1String("qrc")) { - if (url.authority().isEmpty()) - return QLatin1Char(':') + url.path(); - return QString(); - } - return url.toLocalFile(); -} - -///////////////////////////////////////////////////////////// -struct QDeclarativeEnginePrivate::ImportedNamespace { - QStringList uris; - QStringList urls; - QList majversions; - QList minversions; - QList isLibrary; - QList qmlDirComponents; - - - bool find_helper(int i, const QByteArray& type, int *vmajor, int *vminor, - QDeclarativeType** type_return, QUrl* url_return, - QUrl *base = 0, bool *typeRecursionDetected = 0) - { - int vmaj = majversions.at(i); - int vmin = minversions.at(i); - - QByteArray qt = uris.at(i).toUtf8(); - qt += '/'; - qt += type; - - QDeclarativeType *t = QDeclarativeMetaType::qmlType(qt,vmaj,vmin); - if (t) { - if (vmajor) *vmajor = vmaj; - if (vminor) *vminor = vmin; - if (type_return) - *type_return = t; - return true; - } - - QUrl url = QUrl(urls.at(i) + QLatin1Char('/') + QString::fromUtf8(type) + QLatin1String(".qml")); - QDeclarativeDirComponents qmldircomponents = qmlDirComponents.at(i); - - bool typeWasDeclaredInQmldir = false; - if (!qmldircomponents.isEmpty()) { - const QString typeName = QString::fromUtf8(type); - foreach (const QDeclarativeDirParser::Component &c, qmldircomponents) { - if (c.typeName == typeName) { - typeWasDeclaredInQmldir = true; - - // importing version -1 means import ALL versions - if ((vmaj == -1) || (c.majorVersion < vmaj || (c.majorVersion == vmaj && vmin >= c.minorVersion))) { - QUrl candidate = url.resolved(QUrl(c.fileName)); - if (c.internal && base) { - if (base->resolved(QUrl(c.fileName)) != candidate) - continue; // failed attempt to access an internal type - } - if (base && *base == candidate) { - if (typeRecursionDetected) - *typeRecursionDetected = true; - continue; // no recursion - } - if (url_return) - *url_return = candidate; - return true; - } - } - } - } - - if (!typeWasDeclaredInQmldir && !isLibrary.at(i)) { - // XXX search non-files too! (eg. zip files, see QT-524) - QFileInfo f(toLocalFileOrQrc(url)); - if (f.exists()) { - if (base && *base == url) { // no recursion - if (typeRecursionDetected) - *typeRecursionDetected = true; - } else { - if (url_return) - *url_return = url; - return true; - } - } - } - return false; - } - - bool find(const QByteArray& type, int *vmajor, int *vminor, QDeclarativeType** type_return, - QUrl* url_return, QUrl *base = 0, QString *errorString = 0) - { - bool typeRecursionDetected = false; - for (int i=0; itoString(); - int slash = b.lastIndexOf(QLatin1Char('/')); - if (slash >= 0) { - b = b.left(slash+1); - QString l = b.left(slash); - if (u1.startsWith(b)) - u1 = u1.mid(b.count()); - else if (u1 == l) - u1 = QDeclarativeEngine::tr("local directory"); - if (u2.startsWith(b)) - u2 = u2.mid(b.count()); - else if (u2 == l) - u2 = QDeclarativeEngine::tr("local directory"); - } - } - - if (u1 != u2) - *errorString - = QDeclarativeEngine::tr("is ambiguous. Found in %1 and in %2") - .arg(u1).arg(u2); - else - *errorString - = QDeclarativeEngine::tr("is ambiguous. Found in %1 in version %2.%3 and %4.%5") - .arg(u1) - .arg(majversions.at(i)).arg(minversions.at(i)) - .arg(majversions.at(j)).arg(minversions.at(j)); - } - return false; - } - } - } - return true; - } - } - if (errorString) { - if (typeRecursionDetected) - *errorString = QDeclarativeEngine::tr("is instantiated recursively"); - else - *errorString = QDeclarativeEngine::tr("is not a type"); - } - return false; - } -}; - -static bool greaterThan(const QString &s1, const QString &s2) -{ - return s1 > s2; -} - -class QDeclarativeImportsPrivate { -public: - QDeclarativeImportsPrivate(); - ~QDeclarativeImportsPrivate(); - - bool importExtension(const QString &absoluteFilePath, const QString &uri, - QDeclarativeEngine *engine, QDeclarativeDirComponents* components, - QString *errorString); - - QString resolvedUri(const QString &dir_arg, QDeclarativeEngine *engine); - bool add(const QUrl& base, const QDeclarativeDirComponents &qmldircomponentsnetwork, - const QString& uri_arg, const QString& prefix, - int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, - QDeclarativeEngine *engine, QString *errorString); - bool find(const QByteArray& type, int *vmajor, int *vminor, - QDeclarativeType** type_return, QUrl* url_return, QString *errorString); - - QDeclarativeEnginePrivate::ImportedNamespace *findNamespace(const QString& type); - - QUrl base; - int ref; - -private: - friend struct QDeclarativeEnginePrivate::Imports; - - QSet qmlDirFilesForWhichPluginsHaveBeenLoaded; - QDeclarativeEnginePrivate::ImportedNamespace unqualifiedset; - QHash set; -}; - -QDeclarativeEnginePrivate::Imports::Imports(const Imports ©) -: d(copy.d) -{ - ++d->ref; -} - -QDeclarativeEnginePrivate::Imports & -QDeclarativeEnginePrivate::Imports::operator =(const Imports ©) -{ - ++copy.d->ref; - if (--d->ref == 0) - delete d; - d = copy.d; - return *this; -} - -QDeclarativeEnginePrivate::Imports::Imports() -: d(new QDeclarativeImportsPrivate) -{ -} - -QDeclarativeEnginePrivate::Imports::~Imports() -{ - if (--d->ref == 0) - delete d; -} - -QDeclarativeImportsPrivate::QDeclarativeImportsPrivate() -: ref(1) -{ -} - -QDeclarativeImportsPrivate::~QDeclarativeImportsPrivate() -{ - foreach (QDeclarativeEnginePrivate::ImportedNamespace* s, set.values()) - delete s; -} - -bool QDeclarativeImportsPrivate::importExtension(const QString &absoluteFilePath, const QString &uri, QDeclarativeEngine *engine, - QDeclarativeDirComponents* components, QString *errorString) -{ - QFile file(absoluteFilePath); - QString filecontent; - if (file.open(QFile::ReadOnly)) { - filecontent = QString::fromUtf8(file.readAll()); - if (qmlImportTrace()) - qDebug() << "QDeclarativeEngine::add: loaded" << absoluteFilePath; - } else { - if (errorString) - *errorString = QDeclarativeEngine::tr("module \"%1\" definition \"%2\" not readable").arg(uri).arg(absoluteFilePath); - return false; - } - QDir dir = QFileInfo(file).dir(); - - QDeclarativeDirParser qmldirParser; - qmldirParser.setSource(filecontent); - qmldirParser.parse(); - - if (! qmlDirFilesForWhichPluginsHaveBeenLoaded.contains(absoluteFilePath)) { - qmlDirFilesForWhichPluginsHaveBeenLoaded.insert(absoluteFilePath); - - - foreach (const QDeclarativeDirParser::Plugin &plugin, qmldirParser.plugins()) { - - QString resolvedFilePath = - QDeclarativeEnginePrivate::get(engine) - ->resolvePlugin(dir, plugin.path, - plugin.name); - - if (!resolvedFilePath.isEmpty()) { - if (!engine->importPlugin(resolvedFilePath, uri, errorString)) { - if (errorString) - *errorString = QDeclarativeEngine::tr("plugin cannot be loaded for module \"%1\": %2").arg(uri).arg(*errorString); - return false; - } - } else { - if (errorString) - *errorString = QDeclarativeEngine::tr("module \"%1\" plugin \"%2\" not found").arg(uri).arg(plugin.name); - return false; - } - } - } - - if (components) - *components = qmldirParser.components(); - - return true; -} - -QString QDeclarativeImportsPrivate::resolvedUri(const QString &dir_arg, QDeclarativeEngine *engine) -{ - QString dir = dir_arg; - if (dir.endsWith(QLatin1Char('/')) || dir.endsWith(QLatin1Char('\\'))) - dir.chop(1); - - QStringList paths = QDeclarativeEnginePrivate::get(engine)->fileImportPath; - qSort(paths.begin(), paths.end(), greaterThan); // Ensure subdirs preceed their parents. - - QString stableRelativePath = dir; - foreach( QString path, paths) { - if (dir.startsWith(path)) { - stableRelativePath = dir.mid(path.length()+1); - break; - } - } - stableRelativePath.replace(QLatin1Char('/'), QLatin1Char('.')); - stableRelativePath.replace(QLatin1Char('\\'), QLatin1Char('.')); - return stableRelativePath; -} - -bool QDeclarativeImportsPrivate::add(const QUrl& base, const QDeclarativeDirComponents &qmldircomponentsnetwork, const QString& uri_arg, - const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, - QDeclarativeEngine *engine, QString *errorString) -{ - QDeclarativeDirComponents qmldircomponents = qmldircomponentsnetwork; - QString uri = uri_arg; - QDeclarativeEnginePrivate::ImportedNamespace *s; - if (prefix.isEmpty()) { - s = &unqualifiedset; - } else { - s = set.value(prefix); - if (!s) - set.insert(prefix,(s=new QDeclarativeEnginePrivate::ImportedNamespace)); - } - - - - QString url = uri; - if (importType == QDeclarativeScriptParser::Import::Library) { - url.replace(QLatin1Char('.'), QLatin1Char('/')); - bool found = false; - QString dir; - - - foreach (const QString &p, - QDeclarativeEnginePrivate::get(engine)->fileImportPath) { - dir = p+QLatin1Char('/')+url; - - QFileInfo fi(dir+QLatin1String("/qmldir")); - const QString absoluteFilePath = fi.absoluteFilePath(); - - if (fi.isFile()) { - found = true; - - url = QUrl::fromLocalFile(fi.absolutePath()).toString(); - uri = resolvedUri(dir, engine); - if (!importExtension(absoluteFilePath, uri, engine, &qmldircomponents, errorString)) - return false; - break; - } - } - - if (!found) { - found = QDeclarativeMetaType::isModule(uri.toUtf8(), vmaj, vmin); - if (!found) { - if (errorString) { - bool anyversion = QDeclarativeMetaType::isModule(uri.toUtf8(), -1, -1); - if (anyversion) - *errorString = QDeclarativeEngine::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin); - else - *errorString = QDeclarativeEngine::tr("module \"%1\" is not installed").arg(uri_arg); - } - return false; - } - } - } else { - - if (importType == QDeclarativeScriptParser::Import::File && qmldircomponents.isEmpty()) { - QUrl importUrl = base.resolved(QUrl(uri + QLatin1String("/qmldir"))); - QString localFileOrQrc = toLocalFileOrQrc(importUrl); - if (!localFileOrQrc.isEmpty()) { - QString dir = toLocalFileOrQrc(base.resolved(QUrl(uri))); - if (dir.isEmpty() || !QDir().exists(dir)) { - if (errorString) - *errorString = QDeclarativeEngine::tr("\"%1\": no such directory").arg(uri_arg); - return false; // local import dirs must exist - } - uri = resolvedUri(toLocalFileOrQrc(base.resolved(QUrl(uri))), engine); - if (uri.endsWith(QLatin1Char('/'))) - uri.chop(1); - if (QFile::exists(localFileOrQrc)) { - if (!importExtension(localFileOrQrc,uri,engine,&qmldircomponents,errorString)) - return false; - } - } else { - if (prefix.isEmpty()) { - // directory must at least exist for valid import - QString localFileOrQrc = toLocalFileOrQrc(base.resolved(QUrl(uri))); - if (localFileOrQrc.isEmpty() || !QDir().exists(localFileOrQrc)) { - if (errorString) { - if (localFileOrQrc.isEmpty()) - *errorString = QDeclarativeEngine::tr("import \"%1\" has no qmldir and no namespace").arg(uri); - else - *errorString = QDeclarativeEngine::tr("\"%1\": no such directory").arg(uri); - } - return false; - } - } - } - } - - url = base.resolved(QUrl(url)).toString(); - if (url.endsWith(QLatin1Char('/'))) - url.chop(1); - } - - if (vmaj > -1 && vmin > -1 && !qmldircomponents.isEmpty()) { - QList::ConstIterator it = qmldircomponents.begin(); - for (; it != qmldircomponents.end(); ++it) { - if (it->majorVersion > vmaj || (it->majorVersion == vmaj && it->minorVersion >= vmin)) - break; - } - if (it == qmldircomponents.end()) { - *errorString = QDeclarativeEngine::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin); - return false; - } - } - - s->uris.prepend(uri); - s->urls.prepend(url); - s->majversions.prepend(vmaj); - s->minversions.prepend(vmin); - s->isLibrary.prepend(importType == QDeclarativeScriptParser::Import::Library); - s->qmlDirComponents.prepend(qmldircomponents); - return true; -} - -bool QDeclarativeImportsPrivate::find(const QByteArray& type, int *vmajor, int *vminor, QDeclarativeType** type_return, - QUrl* url_return, QString *errorString) -{ - QDeclarativeEnginePrivate::ImportedNamespace *s = 0; - int slash = type.indexOf('/'); - if (slash >= 0) { - QString namespaceName = QString::fromUtf8(type.left(slash)); - s = set.value(namespaceName); - if (!s) { - if (errorString) - *errorString = QDeclarativeEngine::tr("- %1 is not a namespace").arg(namespaceName); - return false; - } - int nslash = type.indexOf('/',slash+1); - if (nslash > 0) { - if (errorString) - *errorString = QDeclarativeEngine::tr("- nested namespaces not allowed"); - return false; - } - } else { - s = &unqualifiedset; - } - QByteArray unqualifiedtype = slash < 0 ? type : type.mid(slash+1); // common-case opt (QString::mid works fine, but slower) - if (s) { - if (s->find(unqualifiedtype,vmajor,vminor,type_return,url_return, &base, errorString)) - return true; - if (s->urls.count() == 1 && !s->isLibrary[0] && url_return && s != &unqualifiedset) { - // qualified, and only 1 url - *url_return = QUrl(s->urls[0]+QLatin1Char('/')).resolved(QUrl(QString::fromUtf8(unqualifiedtype) + QLatin1String(".qml"))); - return true; - } - } - - return false; -} - -QDeclarativeEnginePrivate::ImportedNamespace *QDeclarativeImportsPrivate::findNamespace(const QString& type) -{ - return set.value(type); -} - -static QDeclarativeTypeNameCache *cacheForNamespace(QDeclarativeEngine *engine, const QDeclarativeEnginePrivate::ImportedNamespace &set, QDeclarativeTypeNameCache *cache) -{ - if (!cache) - cache = new QDeclarativeTypeNameCache(engine); - - QList types = QDeclarativeMetaType::qmlTypes(); - - for (int ii = 0; ii < set.uris.count(); ++ii) { - QByteArray base = set.uris.at(ii).toUtf8() + '/'; - int major = set.majversions.at(ii); - int minor = set.minversions.at(ii); - - foreach (QDeclarativeType *type, types) { - if (type->qmlTypeName().startsWith(base) && - type->qmlTypeName().lastIndexOf('/') == (base.length() - 1) && - type->availableInVersion(major,minor)) - { - QString name = QString::fromUtf8(type->qmlTypeName().mid(base.length())); - - cache->add(name, type); - } - } - } - - return cache; -} - -void QDeclarativeEnginePrivate::Imports::cache(QDeclarativeTypeNameCache *cache, QDeclarativeEngine *engine) const -{ - const QDeclarativeEnginePrivate::ImportedNamespace &set = d->unqualifiedset; - - for (QHash::ConstIterator iter = d->set.begin(); - iter != d->set.end(); ++iter) { - - QDeclarativeTypeNameCache::Data *d = cache->data(iter.key()); - if (d) { - if (!d->typeNamespace) - cacheForNamespace(engine, *(*iter), d->typeNamespace); - } else { - QDeclarativeTypeNameCache *nc = cacheForNamespace(engine, *(*iter), 0); - cache->add(iter.key(), nc); - nc->release(); - } - } - - cacheForNamespace(engine, set, cache); -} - -/*! - Sets the base URL to be used for all relative file imports added. -*/ -void QDeclarativeEnginePrivate::Imports::setBaseUrl(const QUrl& url) -{ - d->base = url; -} - -/*! - Returns the base URL to be used for all relative file imports added. -*/ -QUrl QDeclarativeEnginePrivate::Imports::baseUrl() const -{ - return d->base; -} - /*! Adds \a path as a directory where the engine searches for installed modules in a URL-based directory structure. @@ -2050,16 +1509,8 @@ QUrl QDeclarativeEnginePrivate::Imports::baseUrl() const */ void QDeclarativeEngine::addImportPath(const QString& path) { - if (qmlImportTrace()) - qDebug() << "QDeclarativeEngine::addImportPath" << path; Q_D(QDeclarativeEngine); - QUrl url = QUrl(path); - if (url.isRelative() || url.scheme() == QString::fromLocal8Bit("file")) { - QDir dir = QDir(path); - d->fileImportPath.prepend(dir.canonicalPath()); - } else { - d->fileImportPath.prepend(path); - } + d->importDatabase.addImportPath(path); } /*! @@ -2080,7 +1531,7 @@ void QDeclarativeEngine::addImportPath(const QString& path) QStringList QDeclarativeEngine::importPathList() const { Q_D(const QDeclarativeEngine); - return d->fileImportPath; + return d->importDatabase.importPathList(); } /*! @@ -2095,7 +1546,7 @@ QStringList QDeclarativeEngine::importPathList() const void QDeclarativeEngine::setImportPathList(const QStringList &paths) { Q_D(QDeclarativeEngine); - d->fileImportPath = paths; + d->importDatabase.setImportPathList(paths); } @@ -2112,16 +1563,8 @@ void QDeclarativeEngine::setImportPathList(const QStringList &paths) */ void QDeclarativeEngine::addPluginPath(const QString& path) { - if (qmlImportTrace()) - qDebug() << "QDeclarativeEngine::addPluginPath" << path; Q_D(QDeclarativeEngine); - QUrl url = QUrl(path); - if (url.isRelative() || url.scheme() == QString::fromLocal8Bit("file")) { - QDir dir = QDir(path); - d->filePluginPath.prepend(dir.canonicalPath()); - } else { - d->filePluginPath.prepend(path); - } + d->importDatabase.addPluginPath(path); } @@ -2137,7 +1580,7 @@ void QDeclarativeEngine::addPluginPath(const QString& path) QStringList QDeclarativeEngine::pluginPathList() const { Q_D(const QDeclarativeEngine); - return d->filePluginPath; + return d->importDatabase.pluginPathList(); } /*! @@ -2153,7 +1596,7 @@ QStringList QDeclarativeEngine::pluginPathList() const void QDeclarativeEngine::setPluginPathList(const QStringList &paths) { Q_D(QDeclarativeEngine); - d->filePluginPath = paths; + d->importDatabase.setPluginPathList(paths); } @@ -2167,55 +1610,8 @@ void QDeclarativeEngine::setPluginPathList(const QStringList &paths) */ bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &uri, QString *errorString) { - if (qmlImportTrace()) - qDebug() << "QDeclarativeEngine::importPlugin" << uri << "from" << filePath; - QFileInfo fileInfo(filePath); - const QString absoluteFilePath = fileInfo.absoluteFilePath(); - - QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this); - bool engineInitialized = d->initializedPlugins.contains(absoluteFilePath); - bool typesRegistered = qmlEnginePluginsWithRegisteredTypes()->contains(absoluteFilePath); - - if (typesRegistered) { - Q_ASSERT_X(qmlEnginePluginsWithRegisteredTypes()->value(absoluteFilePath) == uri, - "QDeclarativeEngine::importExtension", - "Internal error: Plugin imported previously with different uri"); - } - - if (!engineInitialized || !typesRegistered) { - QPluginLoader loader(absoluteFilePath); - - if (!loader.load()) { - if (errorString) - *errorString = loader.errorString(); - return false; - } - - if (QDeclarativeExtensionInterface *iface = qobject_cast(loader.instance())) { - - const QByteArray bytes = uri.toUtf8(); - const char *moduleId = bytes.constData(); - if (!typesRegistered) { - - // ### this code should probably be protected with a mutex. - qmlEnginePluginsWithRegisteredTypes()->insert(absoluteFilePath, uri); - iface->registerTypes(moduleId); - } - if (!engineInitialized) { - // things on the engine (eg. adding new global objects) have to be done for every engine. - - // protect against double initialization - d->initializedPlugins.insert(absoluteFilePath); - iface->initializeEngine(this, moduleId); - } - } else { - if (errorString) - *errorString = loader.errorString(); - return false; - } - } - - return true; + Q_D(QDeclarativeEngine); + return d->importDatabase.importPlugin(filePath, uri, errorString); } /*! @@ -2247,208 +1643,6 @@ QString QDeclarativeEngine::offlineStoragePath() const return d->scriptEngine.offlineStoragePath; } -/*! - \internal - - Returns the result of the merge of \a baseName with \a path, \a suffixes, and \a prefix. - The \a prefix must contain the dot. - - \a qmldirPath is the location of the qmldir file. - */ -QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, const QString &baseName, - const QStringList &suffixes, - const QString &prefix) -{ - QStringList searchPaths = filePluginPath; - bool qmldirPluginPathIsRelative = QDir::isRelativePath(qmldirPluginPath); - if (!qmldirPluginPathIsRelative) - searchPaths.prepend(qmldirPluginPath); - - foreach (const QString &pluginPath, searchPaths) { - - QString resolvedPath; - - if (pluginPath == QLatin1String(".")) { - if (qmldirPluginPathIsRelative) - resolvedPath = qmldirPath.absoluteFilePath(qmldirPluginPath); - else - resolvedPath = qmldirPath.absolutePath(); - } else { - resolvedPath = pluginPath; - } - - // hack for resources, should probably go away - if (resolvedPath.startsWith(QLatin1Char(':'))) - resolvedPath = QCoreApplication::applicationDirPath(); - - QDir dir(resolvedPath); - foreach (const QString &suffix, suffixes) { - QString pluginFileName = prefix; - - pluginFileName += baseName; - pluginFileName += suffix; - - QFileInfo fileInfo(dir, pluginFileName); - - if (fileInfo.exists()) - return fileInfo.absoluteFilePath(); - } - } - - if (qmlImportTrace()) - qDebug() << "QDeclarativeEngine::resolvePlugin: Could not resolve plugin" << baseName << "in" << qmldirPath.absolutePath(); - 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 QDeclarativeEnginePrivate::resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, const QString &baseName) -{ -#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) - return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, - QStringList() -# ifdef QT_DEBUG - << QLatin1String("d.dll") // try a qmake-style debug build first -# endif - << QLatin1String(".dll")); -#elif defined(Q_OS_SYMBIAN) - return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, - QStringList() - << QLatin1String(".dll") - << QLatin1String(".qtplugin")); -#else - -# if defined(Q_OS_DARWIN) - - return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, - QStringList() -# ifdef QT_DEBUG - << QLatin1String("_debug.dylib") // try a qmake-style debug build first - << QLatin1String(".dylib") -# else - << QLatin1String(".dylib") - << QLatin1String("_debug.dylib") // try a qmake-style debug build after -# endif - << 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(qmldirPath, qmldirPluginPath, baseName, validSuffixList, QLatin1String("lib")); -# endif - -#endif -} - -/*! - \internal - - Adds information to \a imports such that subsequent calls to resolveType() - will resolve types qualified by \a prefix by considering types found at the given \a uri. - - The uri is either a directory (if importType is FileImport), or a URI resolved using paths - added via addImportPath() (if importType is LibraryImport). - - The \a prefix may be empty, in which case the import location is considered for - unqualified types. - - The base URL must already have been set with Import::setBaseUrl(). -*/ -bool QDeclarativeEnginePrivate::addToImport(Imports* imports, const QDeclarativeDirComponents &qmldircomponentsnetwork, const QString& uri, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, QString *errorString) const -{ - QDeclarativeEngine *engine = QDeclarativeEnginePrivate::get(const_cast(this)); - if (qmlImportTrace()) - qDebug().nospace() << "QDeclarativeEngine::addToImport " << imports << " " << uri << " " << vmaj << '.' << vmin << " " << (importType==QDeclarativeScriptParser::Import::Library? "Library" : "File") << " as " << prefix; - bool ok = imports->d->add(imports->d->base,qmldircomponentsnetwork, uri,prefix,vmaj,vmin,importType, engine, errorString); - return ok; -} - -/*! - \internal - - Using the given \a imports, the given (namespace qualified) \a type is resolved to either - an ImportedNamespace stored at \a ns_return, - a QDeclarativeType stored at \a type_return, or - a component located at \a url_return. - - If any return pointer is 0, the corresponding search is not done. - - \sa addToImport() -*/ -bool QDeclarativeEnginePrivate::resolveType(const Imports& imports, const QByteArray& type, QDeclarativeType** type_return, QUrl* url_return, int *vmaj, int *vmin, ImportedNamespace** ns_return, QString *errorString) const -{ - ImportedNamespace* ns = imports.d->findNamespace(QString::fromUtf8(type)); - if (ns) { - if (ns_return) - *ns_return = ns; - return true; - } - if (type_return || url_return) { - if (imports.d->find(type,vmaj,vmin,type_return,url_return, errorString)) { - if (qmlImportTrace()) { - if (type_return && *type_return && url_return && !url_return->isEmpty()) - qDebug() << "QDeclarativeEngine::resolveType" << type << '=' << (*type_return)->typeName() << *url_return; - if (type_return && *type_return) - qDebug() << "QDeclarativeEngine::resolveType" << type << '=' << (*type_return)->typeName(); - if (url_return && !url_return->isEmpty()) - qDebug() << "QDeclarativeEngine::resolveType" << type << '=' << *url_return; - } - return true; - } - } - return false; -} - -/*! - \internal - - Searching \e only in the namespace \a ns (previously returned in a call to - resolveType(), \a type is found and returned to either - a QDeclarativeType stored at \a type_return, or - a component located at \a url_return. - - If either return pointer is 0, the corresponding search is not done. -*/ -void QDeclarativeEnginePrivate::resolveTypeInNamespace(ImportedNamespace* ns, const QByteArray& type, QDeclarativeType** type_return, QUrl* url_return, int *vmaj, int *vmin ) const -{ - ns->find(type,vmaj,vmin,type_return,url_return); -} - static void voidptr_destructor(void *v) { void **ptr = (void **)v; diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index b669f30..45656e8 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -57,6 +57,7 @@ #include "private/qdeclarativeclassfactory_p.h" #include "private/qdeclarativecompositetypemanager_p.h" +#include "private/qdeclarativeimport_p.h" #include "private/qpodvector_p.h" #include "qdeclarative.h" #include "private/qdeclarativevaluetype_p.h" @@ -164,7 +165,6 @@ public: bool outputWarningsToStdErr; - struct ImportedNamespace; QDeclarativeContextScriptClass *contextClass; QDeclarativeContextData *sharedContext; QObject *sharedScope; @@ -237,8 +237,8 @@ public: mutable QMutex mutex; QDeclarativeCompositeTypeManager typeManager; - QStringList fileImportPath; - QStringList filePluginPath; + QDeclarativeImportDatabase importDatabase; + QString offlineStoragePath; mutable quint32 uniqueId; @@ -252,46 +252,6 @@ public: inline QDeclarativePropertyCache *cache(QObject *obj); inline QDeclarativePropertyCache *cache(const QMetaObject *); - // ### This whole class is embarrassing - struct Imports { - Imports(); - ~Imports(); - Imports(const Imports ©); - Imports &operator =(const Imports ©); - - void setBaseUrl(const QUrl& url); - QUrl baseUrl() const; - - void cache(QDeclarativeTypeNameCache *cache, QDeclarativeEngine *) const; - - private: - friend class QDeclarativeEnginePrivate; - QDeclarativeImportsPrivate *d; - }; - - - QSet initializedPlugins; - - QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, const QString &baseName, - const QStringList &suffixes, - const QString &prefix = QString()); - QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, const QString &baseName); - - - bool addToImport(Imports*, const QDeclarativeDirComponents &qmldircomponentsnetwork, - const QString& uri, const QString& prefix, int vmaj, int vmin, - QDeclarativeScriptParser::Import::Type importType, - QString *errorString) const; - bool resolveType(const Imports&, const QByteArray& type, - QDeclarativeType** type_return, QUrl* url_return, - int *version_major, int *version_minor, - ImportedNamespace** ns_return, - QString *errorString = 0) const; - void resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, - QDeclarativeType** type_return, QUrl* url_return, - int *version_major, int *version_minor ) const; - - void registerCompositeType(QDeclarativeCompiledData *); bool isQObject(int); diff --git a/src/declarative/qml/qdeclarativeimport.cpp b/src/declarative/qml/qdeclarativeimport.cpp new file mode 100644 index 0000000..65d42a1 --- /dev/null +++ b/src/declarative/qml/qdeclarativeimport.cpp @@ -0,0 +1,925 @@ +/**************************************************************************** +** +** 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 "qdeclarativeimport_p.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +DEFINE_BOOL_CONFIG_OPTION(qmlImportTrace, QML_IMPORT_TRACE) +DEFINE_BOOL_CONFIG_OPTION(qmlCheckTypes, QML_CHECK_TYPES) + +static QString toLocalFileOrQrc(const QUrl& url) +{ + if (url.scheme() == QLatin1String("qrc")) { + if (url.authority().isEmpty()) + return QLatin1Char(':') + url.path(); + return QString(); + } + return url.toLocalFile(); +} + +static bool greaterThan(const QString &s1, const QString &s2) +{ + return s1 > s2; +} + +typedef QMap StringStringMap; +Q_GLOBAL_STATIC(StringStringMap, qmlEnginePluginsWithRegisteredTypes); // stores the uri + +class QDeclarativeImportedNamespace +{ +public: + QStringList uris; + QStringList urls; + QList majversions; + QList minversions; + QList isLibrary; + QList qmlDirComponents; + + + bool find_helper(int i, const QByteArray& type, int *vmajor, int *vminor, + QDeclarativeType** type_return, QUrl* url_return, + QUrl *base = 0, bool *typeRecursionDetected = 0); + bool find(const QByteArray& type, int *vmajor, int *vminor, QDeclarativeType** type_return, + QUrl* url_return, QUrl *base = 0, QString *errorString = 0); +}; + +class QDeclarativeImportsPrivate { +public: + QDeclarativeImportsPrivate(); + ~QDeclarativeImportsPrivate(); + + bool importExtension(const QString &absoluteFilePath, const QString &uri, + QDeclarativeImportDatabase *database, QDeclarativeDirComponents* components, + QString *errorString); + + QString resolvedUri(const QString &dir_arg, QDeclarativeImportDatabase *database); + bool add(const QDeclarativeDirComponents &qmldircomponentsnetwork, + const QString& uri_arg, const QString& prefix, + int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, + QDeclarativeImportDatabase *database, QString *errorString); + bool find(const QByteArray& type, int *vmajor, int *vminor, + QDeclarativeType** type_return, QUrl* url_return, QString *errorString); + + QDeclarativeImportedNamespace *findNamespace(const QString& type); + + QUrl base; + int ref; + + QSet qmlDirFilesForWhichPluginsHaveBeenLoaded; + QDeclarativeImportedNamespace unqualifiedset; + QHash set; +}; + +QDeclarativeImports::QDeclarativeImports(const QDeclarativeImports ©) +: d(copy.d) +{ + ++d->ref; +} + +QDeclarativeImports & +QDeclarativeImports::operator =(const QDeclarativeImports ©) +{ + ++copy.d->ref; + if (--d->ref == 0) + delete d; + d = copy.d; + return *this; +} + +QDeclarativeImports::QDeclarativeImports() +: d(new QDeclarativeImportsPrivate) +{ +} + +QDeclarativeImports::~QDeclarativeImports() +{ + if (--d->ref == 0) + delete d; +} + +/*! + Sets the base URL to be used for all relative file imports added. +*/ +void QDeclarativeImports::setBaseUrl(const QUrl& url) +{ + d->base = url; +} + +/*! + Returns the base URL to be used for all relative file imports added. +*/ +QUrl QDeclarativeImports::baseUrl() const +{ + return d->base; +} + +static QDeclarativeTypeNameCache * +cacheForNamespace(QDeclarativeEngine *engine, const QDeclarativeImportedNamespace &set, + QDeclarativeTypeNameCache *cache) +{ + if (!cache) + cache = new QDeclarativeTypeNameCache(engine); + + QList types = QDeclarativeMetaType::qmlTypes(); + + for (int ii = 0; ii < set.uris.count(); ++ii) { + QByteArray base = set.uris.at(ii).toUtf8() + '/'; + int major = set.majversions.at(ii); + int minor = set.minversions.at(ii); + + foreach (QDeclarativeType *type, types) { + if (type->qmlTypeName().startsWith(base) && + type->qmlTypeName().lastIndexOf('/') == (base.length() - 1) && + type->availableInVersion(major,minor)) + { + QString name = QString::fromUtf8(type->qmlTypeName().mid(base.length())); + + cache->add(name, type); + } + } + } + + return cache; +} + +void QDeclarativeImports::cache(QDeclarativeTypeNameCache *cache, QDeclarativeEngine *engine) const +{ + const QDeclarativeImportedNamespace &set = d->unqualifiedset; + + for (QHash::ConstIterator iter = d->set.begin(); + iter != d->set.end(); ++iter) { + + QDeclarativeTypeNameCache::Data *d = cache->data(iter.key()); + if (d) { + if (!d->typeNamespace) + cacheForNamespace(engine, *(*iter), d->typeNamespace); + } else { + QDeclarativeTypeNameCache *nc = cacheForNamespace(engine, *(*iter), 0); + cache->add(iter.key(), nc); + nc->release(); + } + } + + cacheForNamespace(engine, set, cache); +} +bool QDeclarativeImportedNamespace::find_helper(int i, const QByteArray& type, int *vmajor, int *vminor, + QDeclarativeType** type_return, QUrl* url_return, + QUrl *base, bool *typeRecursionDetected) +{ + int vmaj = majversions.at(i); + int vmin = minversions.at(i); + + QByteArray qt = uris.at(i).toUtf8(); + qt += '/'; + qt += type; + + QDeclarativeType *t = QDeclarativeMetaType::qmlType(qt,vmaj,vmin); + if (t) { + if (vmajor) *vmajor = vmaj; + if (vminor) *vminor = vmin; + if (type_return) + *type_return = t; + return true; + } + + QUrl url = QUrl(urls.at(i) + QLatin1Char('/') + QString::fromUtf8(type) + QLatin1String(".qml")); + QDeclarativeDirComponents qmldircomponents = qmlDirComponents.at(i); + + bool typeWasDeclaredInQmldir = false; + if (!qmldircomponents.isEmpty()) { + const QString typeName = QString::fromUtf8(type); + foreach (const QDeclarativeDirParser::Component &c, qmldircomponents) { + if (c.typeName == typeName) { + typeWasDeclaredInQmldir = true; + + // importing version -1 means import ALL versions + if ((vmaj == -1) || (c.majorVersion < vmaj || (c.majorVersion == vmaj && vmin >= c.minorVersion))) { + QUrl candidate = url.resolved(QUrl(c.fileName)); + if (c.internal && base) { + if (base->resolved(QUrl(c.fileName)) != candidate) + continue; // failed attempt to access an internal type + } + if (base && *base == candidate) { + if (typeRecursionDetected) + *typeRecursionDetected = true; + continue; // no recursion + } + if (url_return) + *url_return = candidate; + return true; + } + } + } + } + + if (!typeWasDeclaredInQmldir && !isLibrary.at(i)) { + // XXX search non-files too! (eg. zip files, see QT-524) + QFileInfo f(toLocalFileOrQrc(url)); + if (f.exists()) { + if (base && *base == url) { // no recursion + if (typeRecursionDetected) + *typeRecursionDetected = true; + } else { + if (url_return) + *url_return = url; + return true; + } + } + } + return false; +} + +QDeclarativeImportsPrivate::QDeclarativeImportsPrivate() +: ref(1) +{ +} + +QDeclarativeImportsPrivate::~QDeclarativeImportsPrivate() +{ + foreach (QDeclarativeImportedNamespace* s, set.values()) + delete s; +} + +bool QDeclarativeImportsPrivate::importExtension(const QString &absoluteFilePath, const QString &uri, + QDeclarativeImportDatabase *database, + QDeclarativeDirComponents* components, QString *errorString) +{ + QFile file(absoluteFilePath); + QString filecontent; + if (file.open(QFile::ReadOnly)) { + filecontent = QString::fromUtf8(file.readAll()); + if (qmlImportTrace()) + qDebug() << "QDeclarativeImportDatabase::add: loaded" << absoluteFilePath; + } else { + if (errorString) + *errorString = QDeclarativeImportDatabase::tr("module \"%1\" definition \"%2\" not readable").arg(uri).arg(absoluteFilePath); + return false; + } + QDir dir = QFileInfo(file).dir(); + + QDeclarativeDirParser qmldirParser; + qmldirParser.setSource(filecontent); + qmldirParser.parse(); + + if (! qmlDirFilesForWhichPluginsHaveBeenLoaded.contains(absoluteFilePath)) { + qmlDirFilesForWhichPluginsHaveBeenLoaded.insert(absoluteFilePath); + + + foreach (const QDeclarativeDirParser::Plugin &plugin, qmldirParser.plugins()) { + + QString resolvedFilePath = database->resolvePlugin(dir, plugin.path, plugin.name); + + if (!resolvedFilePath.isEmpty()) { + if (!database->importPlugin(resolvedFilePath, uri, errorString)) { + if (errorString) + *errorString = QDeclarativeImportDatabase::tr("plugin cannot be loaded for module \"%1\": %2").arg(uri).arg(*errorString); + return false; + } + } else { + if (errorString) + *errorString = QDeclarativeImportDatabase::tr("module \"%1\" plugin \"%2\" not found").arg(uri).arg(plugin.name); + return false; + } + } + } + + if (components) + *components = qmldirParser.components(); + + return true; +} + +QString QDeclarativeImportsPrivate::resolvedUri(const QString &dir_arg, QDeclarativeImportDatabase *database) +{ + QString dir = dir_arg; + if (dir.endsWith(QLatin1Char('/')) || dir.endsWith(QLatin1Char('\\'))) + dir.chop(1); + + QStringList paths = database->fileImportPath; + qSort(paths.begin(), paths.end(), greaterThan); // Ensure subdirs preceed their parents. + + QString stableRelativePath = dir; + foreach( QString path, paths) { + if (dir.startsWith(path)) { + stableRelativePath = dir.mid(path.length()+1); + break; + } + } + stableRelativePath.replace(QLatin1Char('/'), QLatin1Char('.')); + stableRelativePath.replace(QLatin1Char('\\'), QLatin1Char('.')); + return stableRelativePath; +} + +bool QDeclarativeImportsPrivate::add(const QDeclarativeDirComponents &qmldircomponentsnetwork, + const QString& uri_arg, const QString& prefix, int vmaj, int vmin, + QDeclarativeScriptParser::Import::Type importType, + QDeclarativeImportDatabase *database, QString *errorString) +{ + QDeclarativeDirComponents qmldircomponents = qmldircomponentsnetwork; + QString uri = uri_arg; + QDeclarativeImportedNamespace *s; + if (prefix.isEmpty()) { + s = &unqualifiedset; + } else { + s = set.value(prefix); + if (!s) + set.insert(prefix,(s=new QDeclarativeImportedNamespace)); + } + + QString url = uri; + if (importType == QDeclarativeScriptParser::Import::Library) { + url.replace(QLatin1Char('.'), QLatin1Char('/')); + bool found = false; + QString dir; + + + foreach (const QString &p, database->fileImportPath) { + dir = p+QLatin1Char('/')+url; + + QFileInfo fi(dir+QLatin1String("/qmldir")); + const QString absoluteFilePath = fi.absoluteFilePath(); + + if (fi.isFile()) { + found = true; + + url = QUrl::fromLocalFile(fi.absolutePath()).toString(); + uri = resolvedUri(dir, database); + if (!importExtension(absoluteFilePath, uri, database, &qmldircomponents, errorString)) + return false; + break; + } + } + + if (!found) { + found = QDeclarativeMetaType::isModule(uri.toUtf8(), vmaj, vmin); + if (!found) { + if (errorString) { + bool anyversion = QDeclarativeMetaType::isModule(uri.toUtf8(), -1, -1); + if (anyversion) + *errorString = QDeclarativeImportDatabase::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin); + else + *errorString = QDeclarativeImportDatabase::tr("module \"%1\" is not installed").arg(uri_arg); + } + return false; + } + } + } else { + + if (importType == QDeclarativeScriptParser::Import::File && qmldircomponents.isEmpty()) { + QUrl importUrl = base.resolved(QUrl(uri + QLatin1String("/qmldir"))); + QString localFileOrQrc = toLocalFileOrQrc(importUrl); + if (!localFileOrQrc.isEmpty()) { + QString dir = toLocalFileOrQrc(base.resolved(QUrl(uri))); + if (dir.isEmpty() || !QDir().exists(dir)) { + if (errorString) + *errorString = QDeclarativeImportDatabase::tr("\"%1\": no such directory").arg(uri_arg); + return false; // local import dirs must exist + } + uri = resolvedUri(toLocalFileOrQrc(base.resolved(QUrl(uri))), database); + if (uri.endsWith(QLatin1Char('/'))) + uri.chop(1); + if (QFile::exists(localFileOrQrc)) { + if (!importExtension(localFileOrQrc,uri,database,&qmldircomponents,errorString)) + return false; + } + } else { + if (prefix.isEmpty()) { + // directory must at least exist for valid import + QString localFileOrQrc = toLocalFileOrQrc(base.resolved(QUrl(uri))); + if (localFileOrQrc.isEmpty() || !QDir().exists(localFileOrQrc)) { + if (errorString) { + if (localFileOrQrc.isEmpty()) + *errorString = QDeclarativeImportDatabase::tr("import \"%1\" has no qmldir and no namespace").arg(uri); + else + *errorString = QDeclarativeImportDatabase::tr("\"%1\": no such directory").arg(uri); + } + return false; + } + } + } + } + + url = base.resolved(QUrl(url)).toString(); + if (url.endsWith(QLatin1Char('/'))) + url.chop(1); + } + + if (vmaj > -1 && vmin > -1 && !qmldircomponents.isEmpty()) { + QList::ConstIterator it = qmldircomponents.begin(); + for (; it != qmldircomponents.end(); ++it) { + if (it->majorVersion > vmaj || (it->majorVersion == vmaj && it->minorVersion >= vmin)) + break; + } + if (it == qmldircomponents.end()) { + *errorString = QDeclarativeImportDatabase::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin); + return false; + } + } + + s->uris.prepend(uri); + s->urls.prepend(url); + s->majversions.prepend(vmaj); + s->minversions.prepend(vmin); + s->isLibrary.prepend(importType == QDeclarativeScriptParser::Import::Library); + s->qmlDirComponents.prepend(qmldircomponents); + return true; +} + +bool QDeclarativeImportsPrivate::find(const QByteArray& type, int *vmajor, int *vminor, QDeclarativeType** type_return, + QUrl* url_return, QString *errorString) +{ + QDeclarativeImportedNamespace *s = 0; + int slash = type.indexOf('/'); + if (slash >= 0) { + QString namespaceName = QString::fromUtf8(type.left(slash)); + s = set.value(namespaceName); + if (!s) { + if (errorString) + *errorString = QDeclarativeImportDatabase::tr("- %1 is not a namespace").arg(namespaceName); + return false; + } + int nslash = type.indexOf('/',slash+1); + if (nslash > 0) { + if (errorString) + *errorString = QDeclarativeImportDatabase::tr("- nested namespaces not allowed"); + return false; + } + } else { + s = &unqualifiedset; + } + QByteArray unqualifiedtype = slash < 0 ? type : type.mid(slash+1); // common-case opt (QString::mid works fine, but slower) + if (s) { + if (s->find(unqualifiedtype,vmajor,vminor,type_return,url_return, &base, errorString)) + return true; + if (s->urls.count() == 1 && !s->isLibrary[0] && url_return && s != &unqualifiedset) { + // qualified, and only 1 url + *url_return = QUrl(s->urls[0]+QLatin1Char('/')).resolved(QUrl(QString::fromUtf8(unqualifiedtype) + QLatin1String(".qml"))); + return true; + } + } + + return false; +} + +QDeclarativeImportedNamespace *QDeclarativeImportsPrivate::findNamespace(const QString& type) +{ + return set.value(type); +} + +bool QDeclarativeImportedNamespace::find(const QByteArray& type, int *vmajor, int *vminor, QDeclarativeType** type_return, + QUrl* url_return, QUrl *base, QString *errorString) +{ + bool typeRecursionDetected = false; + for (int i=0; itoString(); + int slash = b.lastIndexOf(QLatin1Char('/')); + if (slash >= 0) { + b = b.left(slash+1); + QString l = b.left(slash); + if (u1.startsWith(b)) + u1 = u1.mid(b.count()); + else if (u1 == l) + u1 = QDeclarativeImportDatabase::tr("local directory"); + if (u2.startsWith(b)) + u2 = u2.mid(b.count()); + else if (u2 == l) + u2 = QDeclarativeImportDatabase::tr("local directory"); + } + } + + if (u1 != u2) + *errorString + = QDeclarativeImportDatabase::tr("is ambiguous. Found in %1 and in %2") + .arg(u1).arg(u2); + else + *errorString + = QDeclarativeImportDatabase::tr("is ambiguous. Found in %1 in version %2.%3 and %4.%5") + .arg(u1) + .arg(majversions.at(i)).arg(minversions.at(i)) + .arg(majversions.at(j)).arg(minversions.at(j)); + } + return false; + } + } + } + return true; + } + } + if (errorString) { + if (typeRecursionDetected) + *errorString = QDeclarativeImportDatabase::tr("is instantiated recursively"); + else + *errorString = QDeclarativeImportDatabase::tr("is not a type"); + } + return false; +} + +QDeclarativeImportDatabase::QDeclarativeImportDatabase(QDeclarativeEngine *e) +: engine(e) +{ + filePluginPath << QLatin1String("."); + + QString builtinPath = QLibraryInfo::location(QLibraryInfo::ImportsPath); + if (!builtinPath.isEmpty()) + addImportPath(builtinPath); + + // 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 + QStringList paths = QString::fromLatin1(envImportPath).split(pathSep, QString::SkipEmptyParts); + for (int ii = paths.count() - 1; ii >= 0; --ii) + addImportPath(paths.at(ii)); + } +} + +QDeclarativeImportDatabase::~QDeclarativeImportDatabase() +{ +} + +/*! + \internal + + Adds information to \a imports such that subsequent calls to resolveType() + will resolve types qualified by \a prefix by considering types found at the given \a uri. + + The uri is either a directory (if importType is FileImport), or a URI resolved using paths + added via addImportPath() (if importType is LibraryImport). + + The \a prefix may be empty, in which case the import location is considered for + unqualified types. + + The base URL must already have been set with Import::setBaseUrl(). +*/ +bool QDeclarativeImportDatabase::addToImport(QDeclarativeImports* imports, + const QDeclarativeDirComponents &qmldircomponentsnetwork, + const QString& uri, const QString& prefix, int vmaj, int vmin, + QDeclarativeScriptParser::Import::Type importType, + QString *errorString) +{ + if (qmlImportTrace()) + qDebug().nospace() << "QDeclarativeImportDatabase::addToImport " << imports << " " << uri << " " + << vmaj << '.' << vmin << " " + << (importType==QDeclarativeScriptParser::Import::Library? "Library" : "File") + << " as " << prefix; + + bool ok = imports->d->add(qmldircomponentsnetwork, uri, prefix, vmaj, vmin, importType, this, errorString); + return ok; +} + +/*! + \internal + + Using the given \a imports, the given (namespace qualified) \a type is resolved to either + a QDeclarativeImportedNamespace stored at \a ns_return, + a QDeclarativeType stored at \a type_return, or + a component located at \a url_return. + + If any return pointer is 0, the corresponding search is not done. + + \sa addToImport() +*/ +bool QDeclarativeImportDatabase::resolveType(const QDeclarativeImports& imports, const QByteArray& type, + QDeclarativeType** type_return, QUrl* url_return, int *vmaj, int *vmin, + QDeclarativeImportedNamespace** ns_return, QString *errorString) const +{ + QDeclarativeImportedNamespace* ns = imports.d->findNamespace(QString::fromUtf8(type)); + if (ns) { + if (ns_return) + *ns_return = ns; + return true; + } + if (type_return || url_return) { + if (imports.d->find(type,vmaj,vmin,type_return,url_return, errorString)) { + if (qmlImportTrace()) { + if (type_return && *type_return && url_return && !url_return->isEmpty()) + qDebug() << "QDeclarativeImportDatabase::resolveType" << type << '=' << (*type_return)->typeName() << *url_return; + if (type_return && *type_return) + qDebug() << "QDeclarativeImportDatabase::resolveType" << type << '=' << (*type_return)->typeName(); + if (url_return && !url_return->isEmpty()) + qDebug() << "QDeclarativeImportDatabase::resolveType" << type << '=' << *url_return; + } + return true; + } + } + return false; +} + +/*! + \internal + + Searching \e only in the namespace \a ns (previously returned in a call to + resolveType(), \a type is found and returned to either + a QDeclarativeType stored at \a type_return, or + a component located at \a url_return. + + If either return pointer is 0, the corresponding search is not done. +*/ +void QDeclarativeImportDatabase::resolveTypeInNamespace(QDeclarativeImportedNamespace* ns, const QByteArray& type, + QDeclarativeType** type_return, QUrl* url_return, + int *vmaj, int *vmin) const +{ + ns->find(type,vmaj,vmin,type_return,url_return); +} + +/*! + \internal + + Returns the result of the merge of \a baseName with \a path, \a suffixes, and \a prefix. + The \a prefix must contain the dot. + + \a qmldirPath is the location of the qmldir file. + */ +QString QDeclarativeImportDatabase::resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, + const QString &baseName, const QStringList &suffixes, + const QString &prefix) +{ + QStringList searchPaths = filePluginPath; + bool qmldirPluginPathIsRelative = QDir::isRelativePath(qmldirPluginPath); + if (!qmldirPluginPathIsRelative) + searchPaths.prepend(qmldirPluginPath); + + foreach (const QString &pluginPath, searchPaths) { + + QString resolvedPath; + + if (pluginPath == QLatin1String(".")) { + if (qmldirPluginPathIsRelative) + resolvedPath = qmldirPath.absoluteFilePath(qmldirPluginPath); + else + resolvedPath = qmldirPath.absolutePath(); + } else { + resolvedPath = pluginPath; + } + + // hack for resources, should probably go away + if (resolvedPath.startsWith(QLatin1Char(':'))) + resolvedPath = QCoreApplication::applicationDirPath(); + + QDir dir(resolvedPath); + foreach (const QString &suffix, suffixes) { + QString pluginFileName = prefix; + + pluginFileName += baseName; + pluginFileName += suffix; + + QFileInfo fileInfo(dir, pluginFileName); + + if (fileInfo.exists()) + return fileInfo.absoluteFilePath(); + } + } + + if (qmlImportTrace()) + qDebug() << "QDeclarativeImportDatabase::resolvePlugin: Could not resolve plugin" << baseName + << "in" << qmldirPath.absolutePath(); + + 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 QDeclarativeImportDatabase::resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, + const QString &baseName) +{ +#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) + return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, + QStringList() +# ifdef QT_DEBUG + << QLatin1String("d.dll") // try a qmake-style debug build first +# endif + << QLatin1String(".dll")); +#elif defined(Q_OS_SYMBIAN) + return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, + QStringList() + << QLatin1String(".dll") + << QLatin1String(".qtplugin")); +#else + +# if defined(Q_OS_DARWIN) + + return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, + QStringList() +# ifdef QT_DEBUG + << QLatin1String("_debug.dylib") // try a qmake-style debug build first + << QLatin1String(".dylib") +# else + << QLatin1String(".dylib") + << QLatin1String("_debug.dylib") // try a qmake-style debug build after +# endif + << 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(qmldirPath, qmldirPluginPath, baseName, validSuffixList, QLatin1String("lib")); +# endif + +#endif +} + +QStringList QDeclarativeImportDatabase::pluginPathList() const +{ + return filePluginPath; +} + +void QDeclarativeImportDatabase::setPluginPathList(const QStringList &paths) +{ + filePluginPath = paths; +} + +void QDeclarativeImportDatabase::addPluginPath(const QString& path) +{ + if (qmlImportTrace()) + qDebug() << "QDeclarativeImportDatabase::addPluginPath" << path; + + QUrl url = QUrl(path); + if (url.isRelative() || url.scheme() == QString::fromLocal8Bit("file")) { + QDir dir = QDir(path); + filePluginPath.prepend(dir.canonicalPath()); + } else { + filePluginPath.prepend(path); + } +} + +void QDeclarativeImportDatabase::addImportPath(const QString& path) +{ + if (qmlImportTrace()) + qDebug() << "QDeclarativeImportDatabase::addImportPath" << path; + + QUrl url = QUrl(path); + QString cPath; + + if (url.isRelative() || url.scheme() == QString::fromLocal8Bit("file")) { + QDir dir = QDir(path); + cPath = dir.canonicalPath(); + } else { + cPath = path; + } + + if (!fileImportPath.contains(cPath)) + fileImportPath.prepend(cPath); +} + +QStringList QDeclarativeImportDatabase::importPathList() const +{ + return fileImportPath; +} + +void QDeclarativeImportDatabase::setImportPathList(const QStringList &paths) +{ + fileImportPath = paths; +} + + +bool QDeclarativeImportDatabase::importPlugin(const QString &filePath, const QString &uri, QString *errorString) +{ + if (qmlImportTrace()) + qDebug() << "QDeclarativeImportDatabase::importPlugin" << uri << "from" << filePath; + + QFileInfo fileInfo(filePath); + const QString absoluteFilePath = fileInfo.absoluteFilePath(); + + bool engineInitialized = initializedPlugins.contains(absoluteFilePath); + bool typesRegistered = qmlEnginePluginsWithRegisteredTypes()->contains(absoluteFilePath); + + if (typesRegistered) { + Q_ASSERT_X(qmlEnginePluginsWithRegisteredTypes()->value(absoluteFilePath) == uri, + "QDeclarativeImportDatabase::importExtension", + "Internal error: Plugin imported previously with different uri"); + } + + if (!engineInitialized || !typesRegistered) { + QPluginLoader loader(absoluteFilePath); + + if (!loader.load()) { + if (errorString) + *errorString = loader.errorString(); + return false; + } + + if (QDeclarativeExtensionInterface *iface = qobject_cast(loader.instance())) { + + const QByteArray bytes = uri.toUtf8(); + const char *moduleId = bytes.constData(); + if (!typesRegistered) { + + // ### this code should probably be protected with a mutex. + qmlEnginePluginsWithRegisteredTypes()->insert(absoluteFilePath, uri); + iface->registerTypes(moduleId); + } + if (!engineInitialized) { + // things on the engine (eg. adding new global objects) have to be done for every engine. + + // protect against double initialization + initializedPlugins.insert(absoluteFilePath); + iface->initializeEngine(engine, moduleId); + } + } else { + if (errorString) + *errorString = loader.errorString(); + return false; + } + } + + return true; +} + + +QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeimport_p.h b/src/declarative/qml/qdeclarativeimport_p.h new file mode 100644 index 0000000..62b0517 --- /dev/null +++ b/src/declarative/qml/qdeclarativeimport_p.h @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEIMPORT_P_H +#define QDECLARATIVEIMPORT_P_H + +#include +#include +#include +#include +#include +#include + +// +// 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. +// + +QT_BEGIN_NAMESPACE + +class QDeclarativeTypeNameCache; +class QDeclarativeEngine; +class QDir; + +class QDeclarativeImportedNamespace; +class QDeclarativeImportsPrivate; +class QDeclarativeImports +{ +public: + QDeclarativeImports(); + QDeclarativeImports(const QDeclarativeImports &); + ~QDeclarativeImports(); + QDeclarativeImports &operator=(const QDeclarativeImports &); + + void setBaseUrl(const QUrl &url); + QUrl baseUrl() const; + + void cache(QDeclarativeTypeNameCache *cache, QDeclarativeEngine *) const; +private: + friend class QDeclarativeImportDatabase; + QDeclarativeImportsPrivate *d; +}; + +class QDeclarativeImportDatabase +{ + Q_DECLARE_TR_FUNCTIONS(QDeclarativeImportDatabase) +public: + QDeclarativeImportDatabase(QDeclarativeEngine *); + ~QDeclarativeImportDatabase(); + + bool importPlugin(const QString &filePath, const QString &uri, QString *errorString); + + QStringList importPathList() const; + void setImportPathList(const QStringList &paths); + void addImportPath(const QString& dir); + + QStringList pluginPathList() const; + void setPluginPathList(const QStringList &paths); + void addPluginPath(const QString& path); + + + bool addToImport(QDeclarativeImports*, const QDeclarativeDirComponents &qmldircomponentsnetwork, + const QString& uri, const QString& prefix, int vmaj, int vmin, + QDeclarativeScriptParser::Import::Type importType, + QString *errorString); + bool resolveType(const QDeclarativeImports&, const QByteArray& type, + QDeclarativeType** type_return, QUrl* url_return, + int *version_major, int *version_minor, + QDeclarativeImportedNamespace** ns_return, + QString *errorString = 0) const; + void resolveTypeInNamespace(QDeclarativeImportedNamespace*, const QByteArray& type, + QDeclarativeType** type_return, QUrl* url_return, + int *version_major, int *version_minor ) const; + + +private: + friend class QDeclarativeImportsPrivate; + QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, + const QString &baseName, const QStringList &suffixes, + const QString &prefix = QString()); + QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, + const QString &baseName); + + + QStringList filePluginPath; + QStringList fileImportPath; + + QSet initializedPlugins; + QDeclarativeEngine *engine; +}; + +QT_END_NAMESPACE + +#endif // QDECLARATIVEIMPORT_P_H + diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 3848593..dab9767 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -54,6 +54,7 @@ SOURCES += \ $$PWD/qdeclarativenetworkaccessmanagerfactory.cpp \ $$PWD/qdeclarativedirparser.cpp \ $$PWD/qdeclarativeextensionplugin.cpp \ + $$PWD/qdeclarativeimport.cpp \ $$PWD/qdeclarativelist.cpp HEADERS += \ @@ -128,6 +129,7 @@ HEADERS += \ $$PWD/qdeclarativenetworkaccessmanagerfactory.h \ $$PWD/qdeclarativedirparser_p.h \ $$PWD/qdeclarativeextensioninterface.h \ + $$PWD/qdeclarativeimport_p.h \ $$PWD/qdeclarativeextensionplugin.h QT += sql -- cgit v0.12 From f5287ee035fe0c218de47b77038b881d9c857110 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 29 Apr 2010 12:27:35 +1000 Subject: Suppress transient errors from bindings If a binding generates > 1 transient error, only the first was being suppressed. QTBUG-10274 --- src/declarative/qml/qdeclarativeexpression.cpp | 4 +++- .../qdeclarativeecmascript/data/transientErrors.2.qml | 14 ++++++++++++++ .../tst_qdeclarativeecmascript.cpp | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/transientErrors.2.qml diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index f561a7e..5ceb918 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -57,10 +57,12 @@ QT_BEGIN_NAMESPACE bool QDeclarativeDelayedError::addError(QDeclarativeEnginePrivate *e) { - if (!e || prevError) return false; + if (!e) return false; if (e->inProgressCreations == 0) return false; // Not in construction + if (prevError) return true; // Already in error chain + prevError = &e->erroredBindings; nextError = e->erroredBindings; e->erroredBindings = this; diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/transientErrors.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/transientErrors.2.qml new file mode 100644 index 0000000..a36b4c0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/transientErrors.2.qml @@ -0,0 +1,14 @@ +import Qt 4.7 + +QtObject { + id: root + + property variant a: 10 + property int x: 10 + property int test: a.x + + Component.onCompleted: { + a = 11; + a = root; + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 491a736..6cde46b 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -1149,6 +1149,7 @@ static void transientErrorsMsgHandler(QtMsgType, const char *) // Check that transient binding errors are not displayed void tst_qdeclarativeecmascript::transientErrors() { + { QDeclarativeComponent component(&engine, TEST_FILE("transientErrors.qml")); transientErrorsMsgCount = 0; @@ -1160,6 +1161,22 @@ void tst_qdeclarativeecmascript::transientErrors() qInstallMsgHandler(old); QCOMPARE(transientErrorsMsgCount, 0); + } + + // One binding erroring multiple times, but then resolving + { + QDeclarativeComponent component(&engine, TEST_FILE("transientErrors.2.qml")); + + transientErrorsMsgCount = 0; + QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); + + QObject *object = component.create(); + QVERIFY(object != 0); + + qInstallMsgHandler(old); + + QCOMPARE(transientErrorsMsgCount, 0); + } } // Check that errors during shutdown are minimized -- cgit v0.12 From 6e061ee6bd2f516e6ae6ed8035fe7afe5abd5566 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Thu, 29 Apr 2010 14:23:49 +1000 Subject: Fix path view update on startX(Y) changes in qml Task-number: QTBUG-10290 Reviewed-by: Michael Brasser --- src/declarative/graphicsitems/qdeclarativepath.cpp | 13 ++++++++ src/declarative/graphicsitems/qdeclarativepath_p.h | 1 + .../graphicsitems/qdeclarativepath_p_p.h | 3 +- .../data/pathUpdateOnStartChanged.qml | 38 ++++++++++++++++++++++ .../tst_qdeclarativepathview.cpp | 23 +++++++++++++ 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativepathview/data/pathUpdateOnStartChanged.qml diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index e2042fc..e867a52 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -117,6 +117,7 @@ void QDeclarativePath::setStartX(qreal x) return; d->startX = x; emit startXChanged(); + processPath(); } qreal QDeclarativePath::startY() const @@ -132,6 +133,7 @@ void QDeclarativePath::setStartY(qreal y) return; d->startY = y; emit startYChanged(); + processPath(); } /*! @@ -220,6 +222,9 @@ void QDeclarativePath::processPath() { Q_D(QDeclarativePath); + if (!d->componentComplete) + return; + d->_pointCache.clear(); d->_attributePoints.clear(); d->_path = QPainterPath(); @@ -284,10 +289,18 @@ void QDeclarativePath::processPath() emit changed(); } +void QDeclarativePath::classBegin() +{ + Q_D(QDeclarativePath); + d->componentComplete = false; +} + void QDeclarativePath::componentComplete() { Q_D(QDeclarativePath); QSet attrs; + d->componentComplete = true; + // First gather up all the attributes foreach (QDeclarativePathElement *pathElement, d->_pathElements) { if (QDeclarativePathAttribute *attribute = diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h index d7cfca1..17a2ea3 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p.h @@ -224,6 +224,7 @@ Q_SIGNALS: protected: virtual void componentComplete(); + virtual void classBegin(); private Q_SLOTS: void processPath(); diff --git a/src/declarative/graphicsitems/qdeclarativepath_p_p.h b/src/declarative/graphicsitems/qdeclarativepath_p_p.h index e82bcf5..994090e 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p_p.h @@ -65,7 +65,7 @@ class QDeclarativePathPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QDeclarativePath) public: - QDeclarativePathPrivate() : startX(0), startY(0), closed(false) { } + QDeclarativePathPrivate() : startX(0), startY(0), closed(false), componentComplete(true) { } QPainterPath _path; QList _pathElements; @@ -75,6 +75,7 @@ public: int startX; int startY; bool closed; + bool componentComplete; }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathUpdateOnStartChanged.qml b/tests/auto/declarative/qdeclarativepathview/data/pathUpdateOnStartChanged.qml new file mode 100644 index 0000000..ce0f0c9 --- /dev/null +++ b/tests/auto/declarative/qdeclarativepathview/data/pathUpdateOnStartChanged.qml @@ -0,0 +1,38 @@ +import Qt 4.7 + +Rectangle { + width: 800 + height: 480 + color: "black" + resources: [ + ListModel { + id: appModel + ListElement { color: "green" } + }, + Component { + id: appDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + color: "green" + width: 100 + height: 100 + } + } + ] + PathView { + id: pathView + objectName: "pathView" + model: appModel + anchors.fill: parent + + transformOrigin: "Top" + delegate: appDelegate + path: Path { + objectName: "path" + startX: pathView.width / 2 // startX: 400 <- this works as expected + startY: 300 + PathLine { x: 400; y: 120 } + } + } +} diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index 0e3a74d..c32e9cc 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -77,6 +77,7 @@ private slots: void pathChanges(); void componentChanges(); void modelChanges(); + void pathUpdateOnStartChanged(); private: @@ -672,6 +673,28 @@ void tst_QDeclarativePathView::modelChanges() delete canvas; } +void tst_QDeclarativePathView::pathUpdateOnStartChanged() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/pathUpdateOnStartChanged.qml")); + + QDeclarativePathView *pathView = canvas->rootObject()->findChild("pathView"); + QVERIFY(pathView); + + QDeclarativePath *path = canvas->rootObject()->findChild("path"); + QVERIFY(path); + QCOMPARE(path->startX(), 400.0); + QCOMPARE(path->startY(), 300.0); + + QDeclarativeItem *item = findItem(pathView, "wrapper", 0); + QVERIFY(item); + QCOMPARE(item->x(), path->startX() - item->width() / 2.0); + QCOMPARE(item->y(), path->startY() - item->height() / 2.0); + + delete canvas; +} + QDeclarativeView *tst_QDeclarativePathView::createView() { QDeclarativeView *canvas = new QDeclarativeView(0); -- cgit v0.12 From 7c3c3900538b1734b2ef74b3eda0b4f9bca76af9 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Thu, 29 Apr 2010 14:27:27 +1000 Subject: Fix typo in qdeclarativeitem's doc --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 928c504..723ed34 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -444,7 +444,7 @@ void QDeclarativeItemKeyFilter::componentComplete() If an item has been set for a direction and the KeyNavigation attached property receives the corresponding key press and release events, the events will be accepted by - KeyNaviagtion and will not propagate any further. + KeyNavigation and will not propagate any further. \sa {Keys}{Keys attached property} */ -- cgit v0.12 From 9fb7035d59ffa582edabf53c5d617524ab92ae52 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 29 Apr 2010 15:32:34 +1000 Subject: Return enum property values as numbers, not QVariant values Task-number: QTBUG-10291 Reviewed-by: akennedy --- src/declarative/qml/qdeclarativeobjectscriptclass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index bb5c8b7..671a262 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -265,7 +265,7 @@ QDeclarativeObjectScriptClass::property(QObject *obj, const Identifier &name) void *args[] = { &rv, 0 }; QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args); return Value(scriptEngine, rv); - } else if (lastData->propType == QMetaType::Int) { + } else if (lastData->propType == QMetaType::Int || lastData->flags & QDeclarativePropertyCache::Data::IsEnumType) { int rv = 0; void *args[] = { &rv, 0 }; QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args); -- cgit v0.12 From 96551e8af08c6f5eb506468a1a79070f23525bca Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 29 Apr 2010 15:39:47 +1000 Subject: Remove Component's isReady, isLoading, isError and isNull properties. The Component status enum covers all of these properties already and removing these also makes the API consistent with Image and Loader. Note this change only affects the QML Component API; the methods are still available for QDeclarativeComponent. --- .../declarative/samegame/SamegameCore/samegame.js | 2 +- demos/declarative/snake/content/snake.js | 8 +-- doc/src/snippets/declarative/componentCreation.js | 6 +-- examples/declarative/dynamic/qml/itemCreation.js | 6 +-- .../tutorials/samegame/samegame2/samegame.js | 8 +-- .../tutorials/samegame/samegame3/samegame.js | 8 +-- .../samegame/samegame4/content/samegame.js | 8 +-- src/declarative/qml/qdeclarativecomponent.cpp | 58 ++-------------------- src/declarative/qml/qdeclarativecomponent.h | 5 +- 9 files changed, 28 insertions(+), 81 deletions(-) diff --git a/demos/declarative/samegame/SamegameCore/samegame.js b/demos/declarative/samegame/SamegameCore/samegame.js index bf99ca3..cc0a70d 100755 --- a/demos/declarative/samegame/SamegameCore/samegame.js +++ b/demos/declarative/samegame/SamegameCore/samegame.js @@ -175,7 +175,7 @@ function createBlock(column,row){ // only work if the block QML is a local file. Otherwise the component will // not be ready immediately. There is a statusChanged signal on the // component you could use if you want to wait to load remote files. - if(component.isReady){ + if(component.status == Component.Ready){ var dynamicObject = component.createObject(); if(dynamicObject == null){ console.log("error creating block"); diff --git a/demos/declarative/snake/content/snake.js b/demos/declarative/snake/content/snake.js index 02f9757..102bd87 100644 --- a/demos/declarative/snake/content/snake.js +++ b/demos/declarative/snake/content/snake.js @@ -52,8 +52,8 @@ function startNewGame() link.spawned = false; link.dying = false; } else { - if(linkComponent.isReady == false){ - if(linkComponent.isError == true) + if(linkComponent.status != Component.Ready) { + if(linkComponent.status == Component.Error) console.log(linkComponent.errorsString()); else console.log("Still loading linkComponent"); @@ -293,8 +293,8 @@ function createCookie(value) { } } - if(cookieComponent.isReady == false){ - if(cookieComponent.isError == true) + if(cookieComponent.status != Component.Ready) { + if(cookieComponent.status == Component.Error) console.log(cookieComponent.errorsString()); else console.log("Still loading cookieComponent"); diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js index be3e4d6..814545e 100644 --- a/doc/src/snippets/declarative/componentCreation.js +++ b/doc/src/snippets/declarative/componentCreation.js @@ -3,7 +3,7 @@ var component; var sprite; function finishCreation() { - if (component.isReady) { + if (component.status == Component.Ready) { sprite = component.createObject(); if (sprite == null) { // Error Handling @@ -13,7 +13,7 @@ function finishCreation() { sprite.y = 100; // ... } - } else if (component.isError()) { + } else if (component.status == Component.Error) { // Error Handling console.log("Error loading component:", component.errorsString()); } @@ -26,7 +26,7 @@ function createSpriteObjects() { //![2] component = Qt.createComponent("Sprite.qml"); - if (component.isReady) + if (component.status == Component.Ready) finishCreation(); else component.statusChanged.connect(finishCreation); diff --git a/examples/declarative/dynamic/qml/itemCreation.js b/examples/declarative/dynamic/qml/itemCreation.js index 98d48a8..3c1b975 100644 --- a/examples/declarative/dynamic/qml/itemCreation.js +++ b/examples/declarative/dynamic/qml/itemCreation.js @@ -33,7 +33,7 @@ function loadComponent() { itemComponent = Qt.createComponent(itemButton.file); //console.log(itemButton.file) - if(itemComponent.isLoading){ + if(itemComponent.status == Component.Loading){ component.statusChanged.connect(finishCreation); }else{//Depending on the content, it can be ready or error immediately createItem(); @@ -41,7 +41,7 @@ function loadComponent() { } function createItem() { - if (itemComponent.isReady && draggedItem == null) { + if (itemComponent.status == Component.Ready && draggedItem == null) { draggedItem = itemComponent.createObject(); draggedItem.parent = window; draggedItem.image = itemButton.image; @@ -49,7 +49,7 @@ function createItem() { draggedItem.y = yOffset; startingZ = draggedItem.z; draggedItem.z = 4;//On top - } else if (itemComponent.isError) { + } else if (itemComponent.status == Component.Error) { draggedItem = null; console.log("error creating component"); console.log(component.errorsString()); diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js index e5c790d..bcfb5b6 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js @@ -37,10 +37,10 @@ function createBlock(column, row) { if (component == null) component = Qt.createComponent("Block.qml"); - // Note that if Block.qml was not a local file, component.isReady would be - // false and we should wait for the component's statusChanged() signal to - // know when the file is downloaded and fully loaded before calling createObject(). - if (component.isReady) { + // Note that if Block.qml was not a local file, component.status would be + // Loading and we should wait for the component's statusChanged() signal to + // know when the file is downloaded and ready before calling createObject(). + if (component.status == Component.Ready) { var dynamicObject = component.createObject(); if (dynamicObject == null) { console.log("error creating block"); diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.js b/examples/declarative/tutorials/samegame/samegame3/samegame.js index da0f76e..4256aee 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.js @@ -34,10 +34,10 @@ function createBlock(column, row) { if (component == null) component = Qt.createComponent("Block.qml"); - // Note that if Block.qml was not a local file, component.isReady would be - // false and we should wait for the component's statusChanged() signal to - // know when the file is downloaded and fully loaded before calling createObject(). - if (component.isReady) { + // Note that if Block.qml was not a local file, component.status would be + // Loading and we should wait for the component's statusChanged() signal to + // know when the file is downloaded and ready before calling createObject(). + if (component.status == Component.Ready) { var dynamicObject = component.createObject(); if (dynamicObject == null) { console.log("error creating block"); diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js index 1454f0b..961cd66 100755 --- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js @@ -45,10 +45,10 @@ function createBlock(column, row) { if (component == null) component = Qt.createComponent("content/BoomBlock.qml"); - // Note that if Block.qml was not a local file, component.isReady would be - // false and we should wait for the component's statusChanged() signal to - // know when the file is downloaded and fully loaded before calling createObject(). - if (component.isReady) { + // Note that if Block.qml was not a local file, component.status would be + // Loading and we should wait for the component's statusChanged() signal to + // know when the file is downloaded and ready before calling createObject(). + if (component.status == Component.Ready) { var dynamicObject = component.createObject(); if (dynamicObject == null) { console.log("error creating block"); diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index b83e9f4..f312497 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -269,19 +269,7 @@ QDeclarativeComponent::Status QDeclarativeComponent::status() const } /*! - \qmlproperty bool Component::isNull - - Is true if the component is in the Null state, false otherwise. - - Equivalent to status == Component.Null. -*/ - -/*! - \property QDeclarativeComponent::isNull - - Is true if the component is in the Null state, false otherwise. - - Equivalent to status() == QDeclarativeComponent::Null. + Returns true if status() == QDeclarativeComponent::Null. */ bool QDeclarativeComponent::isNull() const { @@ -289,19 +277,7 @@ bool QDeclarativeComponent::isNull() const } /*! - \qmlproperty bool Component::isReady - - Is true if the component is in the Ready state, false otherwise. - - Equivalent to status == Component.Ready. -*/ - -/*! - \property QDeclarativeComponent::isReady - - Is true if the component is in the Ready state, false otherwise. - - Equivalent to status() == QDeclarativeComponent::Ready. + Returns true if status() == QDeclarativeComponent::Ready. */ bool QDeclarativeComponent::isReady() const { @@ -309,21 +285,7 @@ bool QDeclarativeComponent::isReady() const } /*! - \qmlproperty bool Component::isError - - Is true if the component is in the Error state, false otherwise. - - Equivalent to status == Component.Error. - - Calling errorsString() will provide a human-readable description of any errors. -*/ - -/*! - \property QDeclarativeComponent::isError - - Is true if the component is in the Error state, false otherwise. - - Equivalent to status() == QDeclarativeComponent::Error. + Returns true if status() == QDeclarativeComponent::Error. */ bool QDeclarativeComponent::isError() const { @@ -331,19 +293,7 @@ bool QDeclarativeComponent::isError() const } /*! - \qmlproperty bool Component::isLoading - - Is true if the component is in the Loading state, false otherwise. - - Equivalent to status == Component::Loading. -*/ - -/*! - \property QDeclarativeComponent::isLoading - - Is true if the component is in the Loading state, false otherwise. - - Equivalent to status() == QDeclarativeComponent::Loading. + Returns true if status() == QDeclarativeComponent::Loading. */ bool QDeclarativeComponent::isLoading() const { diff --git a/src/declarative/qml/qdeclarativecomponent.h b/src/declarative/qml/qdeclarativecomponent.h index f3cfe3c..b078174 100644 --- a/src/declarative/qml/qdeclarativecomponent.h +++ b/src/declarative/qml/qdeclarativecomponent.h @@ -64,10 +64,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeComponent : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativeComponent) - Q_PROPERTY(bool isNull READ isNull NOTIFY statusChanged) - Q_PROPERTY(bool isReady READ isReady NOTIFY statusChanged) - Q_PROPERTY(bool isError READ isError NOTIFY statusChanged) - Q_PROPERTY(bool isLoading READ isLoading NOTIFY statusChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(QUrl url READ url CONSTANT) -- cgit v0.12 From a5e5b178615cea0dc795fd2008ef258030d2e8e6 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 29 Apr 2010 15:41:55 +1000 Subject: Don't call qRegisterMetaType() in global scope --- src/declarative/qml/qdeclarativecomponent.cpp | 1 - src/declarative/qml/qdeclarativeengine.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index f312497..b81a32a 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -63,7 +63,6 @@ QT_BEGIN_NAMESPACE class QByteArray; -int statusId = qRegisterMetaType("QDeclarativeComponent::Status"); /*! \class QDeclarativeComponent diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index a22011a..19d4b57 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -347,6 +347,7 @@ void QDeclarativeEnginePrivate::init() qRegisterMetaType("QVariant"); qRegisterMetaType("QDeclarativeScriptString"); qRegisterMetaType("QScriptValue"); + qRegisterMetaType("QDeclarativeComponent::Status"); QDeclarativeData::init(); -- cgit v0.12 From f3a8575352e4d2f7b1100274bc9344040c668d01 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 29 Apr 2010 15:44:17 +1000 Subject: Add an example of creating a QDeclarativeNetworkAccessManagerFactory. --- examples/declarative/declarative.pro | 1 + examples/declarative/proxyviewer/main.cpp | 109 +++++++++++++++++++++++ examples/declarative/proxyviewer/proxyviewer.pro | 9 ++ examples/declarative/proxyviewer/proxyviewer.qrc | 5 ++ examples/declarative/proxyviewer/view.qml | 7 ++ 5 files changed, 131 insertions(+) create mode 100644 examples/declarative/proxyviewer/main.cpp create mode 100644 examples/declarative/proxyviewer/proxyviewer.pro create mode 100644 examples/declarative/proxyviewer/proxyviewer.qrc create mode 100644 examples/declarative/proxyviewer/view.qml diff --git a/examples/declarative/declarative.pro b/examples/declarative/declarative.pro index e37c3d4..ba9b628 100644 --- a/examples/declarative/declarative.pro +++ b/examples/declarative/declarative.pro @@ -6,6 +6,7 @@ SUBDIRS = \ imageprovider \ objectlistmodel \ stringlistmodel \ + proxyviewer \ plugins \ proxywidgets diff --git a/examples/declarative/proxyviewer/main.cpp b/examples/declarative/proxyviewer/main.cpp new file mode 100644 index 0000000..b82d2c9 --- /dev/null +++ b/examples/declarative/proxyviewer/main.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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 demonstration applications 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 + + +/* + This example illustrates using a QNetworkAccessManagerFactory to + create a QNetworkAccessManager with a proxy. + + Usage: + proxyviewer [-host -port ] [file] +*/ + +static QString proxyHost; +static int proxyPort = 0; + +class MyNetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory +{ +public: + virtual QNetworkAccessManager *create(QObject *parent); +}; + +QNetworkAccessManager *MyNetworkAccessManagerFactory::create(QObject *parent) +{ + QNetworkAccessManager *nam = new QNetworkAccessManager(parent); + if (!proxyHost.isEmpty()) { + qDebug() << "Created QNetworkAccessManager using proxy" << (proxyHost + ":" + QString::number(proxyPort)); + QNetworkProxy proxy(QNetworkProxy::HttpCachingProxy, proxyHost, proxyPort); + nam->setProxy(proxy); + } + + return nam; +} + +int main(int argc, char ** argv) +{ + QUrl source("qrc:view.qml"); + + QApplication app(argc, argv); + + for (int i = 1; i < argc; ++i) { + QString arg(argv[i]); + if (arg == "-host" && i < argc-1) { + proxyHost = argv[++i]; + } else if (arg == "-port" && i < argc-1) { + arg = argv[++i]; + proxyPort = arg.toInt(); + } else if (arg[0] != '-') { + source = QUrl::fromLocalFile(arg); + } else { + qWarning() << "Usage: proxyviewer [-host -port ] [file]"; + exit(1); + } + } + + QDeclarativeView view; + view.engine()->setNetworkAccessManagerFactory(new MyNetworkAccessManagerFactory); + + view.setSource(source); + view.show(); + + return app.exec(); +} + diff --git a/examples/declarative/proxyviewer/proxyviewer.pro b/examples/declarative/proxyviewer/proxyviewer.pro new file mode 100644 index 0000000..b6bfa7f --- /dev/null +++ b/examples/declarative/proxyviewer/proxyviewer.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = proxyviewer +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative network + +# Input +SOURCES += main.cpp +RESOURCES += proxyviewer.qrc diff --git a/examples/declarative/proxyviewer/proxyviewer.qrc b/examples/declarative/proxyviewer/proxyviewer.qrc new file mode 100644 index 0000000..17e9301 --- /dev/null +++ b/examples/declarative/proxyviewer/proxyviewer.qrc @@ -0,0 +1,5 @@ + + + view.qml + + diff --git a/examples/declarative/proxyviewer/view.qml b/examples/declarative/proxyviewer/view.qml new file mode 100644 index 0000000..7f1bdef --- /dev/null +++ b/examples/declarative/proxyviewer/view.qml @@ -0,0 +1,7 @@ +import Qt 4.7 + +Image { + width: 100 + height: 100 + source: "http://qt.nokia.com/logo.png" +} -- cgit v0.12 From 1517c4fb9199d32c69378808a27f83d2edf065b2 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 29 Apr 2010 16:05:51 +1000 Subject: Ensure filenames are correctly resolved Works around QUrl("file:a").isRelative() being false. Reviewed-by: Aaron Kennedy --- src/declarative/qml/qdeclarativecomponent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index b83e9f4..a80f183 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -421,7 +421,7 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeEngine *engine, const Q { Q_D(QDeclarativeComponent); d->engine = engine; - loadUrl(QUrl::fromLocalFile(fileName)); + loadUrl(d->engine->baseUrl().resolved(QUrl::fromLocalFile(fileName))); } /*! -- cgit v0.12 From 42945f30e9b3cb70c43d51575aac204e3371fe33 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 29 Apr 2010 16:14:05 +1000 Subject: Update QmlChanges.txt --- src/declarative/QmlChanges.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 9c46467..7218f78 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -2,6 +2,8 @@ The changes below are pre Qt 4.7.0 RC Flickable: overShoot is replaced by boundsBehavior enumeration. +Component: isReady, isLoading, isError and isNull properties removed, use + status property instead C++ API ------- -- cgit v0.12 From 4eb2e50b97a9933ab249517aa42cce9b3b4115e2 Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Thu, 29 Apr 2010 08:20:25 +0200 Subject: Mark some properties in QDeclarativeItem as private properties. QDeclarativeItem will be public, all properties that are relaying on private types must be private too. Reviewed-by:akennedy --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 128 +++-------- src/declarative/graphicsitems/qdeclarativeitem.h | 44 ++-- src/declarative/graphicsitems/qdeclarativeitem_p.h | 23 +- .../graphicsitems/qdeclarativepositioners.cpp | 8 +- .../util/qdeclarativestateoperations.cpp | 89 ++++---- .../tst_qdeclarativeanchors.cpp | 53 +++-- .../tst_qdeclarativeanimations.cpp | 21 +- .../tst_qdeclarativebehaviors.cpp | 25 ++- .../qdeclarativestates/tst_qdeclarativestates.cpp | 241 +++++++++++---------- 9 files changed, 295 insertions(+), 337 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 723ed34..65b996d 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1263,11 +1263,6 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec */ /*! - \property QDeclarativeItem::baseline - \internal -*/ - -/*! \property QDeclarativeItem::focus \internal */ @@ -1472,11 +1467,6 @@ QDeclarativeItem *QDeclarativeItem::parentItem() const */ /*! - \property QDeclarativeItem::resources - \internal -*/ - -/*! Returns true if construction of the QML component is complete; otherwise returns false. @@ -1491,18 +1481,6 @@ bool QDeclarativeItem::isComponentComplete() const return d->_componentComplete; } -/*! - \property QDeclarativeItem::anchors - \internal -*/ - -/*! \internal */ -QDeclarativeAnchors *QDeclarativeItem::anchors() -{ - Q_D(QDeclarativeItem); - return d->anchors(); -} - void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty *prop, QObject *o) { if (!o) @@ -1625,14 +1603,13 @@ void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeN */ /*! - \property QDeclarativeItem::data \internal */ /*! \internal */ -QDeclarativeListProperty QDeclarativeItem::data() +QDeclarativeListProperty QDeclarativeItemPrivate::data() { - return QDeclarativeListProperty(this, 0, QDeclarativeItemPrivate::data_append); + return QDeclarativeListProperty(q_func(), 0, QDeclarativeItemPrivate::data_append); } /*! @@ -1860,98 +1837,61 @@ QVariant QDeclarativeItem::inputMethodQuery(Qt::InputMethodQuery query) const /*! \internal */ -QDeclarativeAnchorLine QDeclarativeItem::left() const +QDeclarativeAnchorLine QDeclarativeItemPrivate::left() const { - Q_D(const QDeclarativeItem); - return d->anchorLines()->left; + return anchorLines()->left; } /*! \internal */ -QDeclarativeAnchorLine QDeclarativeItem::right() const +QDeclarativeAnchorLine QDeclarativeItemPrivate::right() const { - Q_D(const QDeclarativeItem); - return d->anchorLines()->right; + return anchorLines()->right; } /*! \internal */ -QDeclarativeAnchorLine QDeclarativeItem::horizontalCenter() const +QDeclarativeAnchorLine QDeclarativeItemPrivate::horizontalCenter() const { - Q_D(const QDeclarativeItem); - return d->anchorLines()->hCenter; + return anchorLines()->hCenter; } /*! \internal */ -QDeclarativeAnchorLine QDeclarativeItem::top() const +QDeclarativeAnchorLine QDeclarativeItemPrivate::top() const { - Q_D(const QDeclarativeItem); - return d->anchorLines()->top; + return anchorLines()->top; } /*! \internal */ -QDeclarativeAnchorLine QDeclarativeItem::bottom() const +QDeclarativeAnchorLine QDeclarativeItemPrivate::bottom() const { - Q_D(const QDeclarativeItem); - return d->anchorLines()->bottom; + return anchorLines()->bottom; } /*! \internal */ -QDeclarativeAnchorLine QDeclarativeItem::verticalCenter() const +QDeclarativeAnchorLine QDeclarativeItemPrivate::verticalCenter() const { - Q_D(const QDeclarativeItem); - return d->anchorLines()->vCenter; + return anchorLines()->vCenter; } /*! \internal */ -QDeclarativeAnchorLine QDeclarativeItem::baseline() const +QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const { - Q_D(const QDeclarativeItem); - return d->anchorLines()->baseline; + return anchorLines()->baseline; } /*! - \property QDeclarativeItem::top - \internal -*/ - -/*! - \property QDeclarativeItem::bottom - \internal -*/ - -/*! - \property QDeclarativeItem::left - \internal -*/ - -/*! - \property QDeclarativeItem::right - \internal -*/ - -/*! - \property QDeclarativeItem::horizontalCenter - \internal -*/ - -/*! - \property QDeclarativeItem::verticalCenter - \internal -*/ - -/*! \qmlproperty AnchorLine Item::top \qmlproperty AnchorLine Item::bottom \qmlproperty AnchorLine Item::left @@ -2291,9 +2231,9 @@ void QDeclarativeItemPrivate::focusChanged(bool flag) } /*! \internal */ -QDeclarativeListProperty QDeclarativeItem::resources() +QDeclarativeListProperty QDeclarativeItemPrivate::resources() { - return QDeclarativeListProperty(this, 0, QDeclarativeItemPrivate::resources_append, + return QDeclarativeListProperty(q_func(), 0, QDeclarativeItemPrivate::resources_append, QDeclarativeItemPrivate::resources_count, QDeclarativeItemPrivate::resources_at); } @@ -2315,15 +2255,10 @@ QDeclarativeListProperty QDeclarativeItem::resources() \sa {qmlstate}{States} */ -/*! - \property QDeclarativeItem::states - \internal -*/ /*! \internal */ -QDeclarativeListProperty QDeclarativeItem::states() +QDeclarativeListProperty QDeclarativeItemPrivate::states() { - Q_D(QDeclarativeItem); - return d->states()->statesProperty(); + return _states()->statesProperty(); } /*! @@ -2343,16 +2278,11 @@ QDeclarativeListProperty QDeclarativeItem::states() \sa {state-transitions}{Transitions} */ -/*! - \property QDeclarativeItem::transitions - \internal -*/ /*! \internal */ -QDeclarativeListProperty QDeclarativeItem::transitions() +QDeclarativeListProperty QDeclarativeItemPrivate::transitions() { - Q_D(QDeclarativeItem); - return d->states()->transitionsProperty(); + return _states()->transitionsProperty(); } /* @@ -2426,20 +2356,18 @@ QDeclarativeListProperty QDeclarativeItem::transitions() */ /*! \internal */ -QString QDeclarativeItem::state() const +QString QDeclarativeItemPrivate::state() const { - Q_D(const QDeclarativeItem); - if (!d->_stateGroup) + if (!_stateGroup) return QString(); else - return d->_stateGroup->state(); + return _stateGroup->state(); } /*! \internal */ -void QDeclarativeItem::setState(const QString &state) +void QDeclarativeItemPrivate::setState(const QString &state) { - Q_D(QDeclarativeItem); - d->states()->setState(state); + _states()->setState(state); } /*! @@ -2502,7 +2430,7 @@ void QDeclarativeItem::componentComplete() d->keyHandler->componentComplete(); } -QDeclarativeStateGroup *QDeclarativeItemPrivate::states() +QDeclarativeStateGroup *QDeclarativeItemPrivate::_states() { Q_Q(QDeclarativeItem); if (!_stateGroup) { diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h index da5a36e..3b05b09 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.h +++ b/src/declarative/graphicsitems/qdeclarativeitem.h @@ -70,20 +70,20 @@ class Q_DECLARATIVE_EXPORT QDeclarativeItem : public QGraphicsObject, public QDe Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QDeclarativeItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) - Q_PROPERTY(QDeclarativeListProperty data READ data DESIGNABLE false) - Q_PROPERTY(QDeclarativeListProperty resources READ resources DESIGNABLE false) - Q_PROPERTY(QDeclarativeListProperty states READ states DESIGNABLE false) - Q_PROPERTY(QDeclarativeListProperty transitions READ transitions DESIGNABLE false) - Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty data READ data DESIGNABLE false) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty resources READ resources DESIGNABLE false) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty states READ states DESIGNABLE false) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty transitions READ transitions DESIGNABLE false) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QString state READ state WRITE setState NOTIFY stateChanged) Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL) - Q_PROPERTY(QDeclarativeAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) - Q_PROPERTY(QDeclarativeAnchorLine left READ left CONSTANT FINAL) - Q_PROPERTY(QDeclarativeAnchorLine right READ right CONSTANT FINAL) - Q_PROPERTY(QDeclarativeAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL) - Q_PROPERTY(QDeclarativeAnchorLine top READ top CONSTANT FINAL) - Q_PROPERTY(QDeclarativeAnchorLine bottom READ bottom CONSTANT FINAL) - Q_PROPERTY(QDeclarativeAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL) - Q_PROPERTY(QDeclarativeAnchorLine baseline READ baseline CONSTANT FINAL) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine left READ left CONSTANT FINAL) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine right READ right CONSTANT FINAL) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine top READ top CONSTANT FINAL) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine bottom READ bottom CONSTANT FINAL) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL) + Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine baseline READ baseline CONSTANT FINAL) Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged) // ### move to QGI/QGO, NOTIFY Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL) @@ -107,21 +107,11 @@ public: QDeclarativeItem *parentItem() const; void setParentItem(QDeclarativeItem *parent); - QDeclarativeListProperty data(); - QDeclarativeListProperty resources(); - - QDeclarativeAnchors *anchors(); QRectF childrenRect(); bool clip() const; void setClip(bool); - QDeclarativeListProperty states(); - QDeclarativeListProperty transitions(); - - QString state() const; - void setState(const QString &); - qreal baselineOffset() const; void setBaselineOffset(qreal); @@ -159,14 +149,6 @@ public: Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const; Q_INVOKABLE void forceFocus(); - QDeclarativeAnchorLine left() const; - QDeclarativeAnchorLine right() const; - QDeclarativeAnchorLine horizontalCenter() const; - QDeclarativeAnchorLine top() const; - QDeclarativeAnchorLine bottom() const; - QDeclarativeAnchorLine verticalCenter() const; - QDeclarativeAnchorLine baseline() const; - Q_SIGNALS: void childrenChanged(); void childrenRectChanged(const QRectF &); diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index 3f5bf1a..b4dd60a 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -150,6 +150,22 @@ public: void setHeight(qreal); void resetHeight(); + QDeclarativeListProperty data(); + QDeclarativeListProperty resources(); + + QDeclarativeListProperty states(); + QDeclarativeListProperty transitions(); + + QString state() const; + void setState(const QString &); + + QDeclarativeAnchorLine left() const; + QDeclarativeAnchorLine right() const; + QDeclarativeAnchorLine horizontalCenter() const; + QDeclarativeAnchorLine top() const; + QDeclarativeAnchorLine bottom() const; + QDeclarativeAnchorLine verticalCenter() const; + QDeclarativeAnchorLine baseline() const; // data property static void data_append(QDeclarativeListProperty *, QObject *); @@ -165,6 +181,11 @@ public: static QGraphicsTransform *transform_at(QDeclarativeListProperty *list, int); static void transform_clear(QDeclarativeListProperty *list); + static QDeclarativeItemPrivate* get(QDeclarativeItem *item) + { + return item->d_func(); + } + // Accelerated property accessors QDeclarativeNotifier parentNotifier; static void parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e); @@ -224,7 +245,7 @@ public: void removeItemChangeListener(QDeclarativeItemChangeListener *, ChangeTypes types); QPODVector changeListeners; - QDeclarativeStateGroup *states(); + QDeclarativeStateGroup *_states(); QDeclarativeStateGroup *_stateGroup; QDeclarativeItem::TransformOrigin origin:4; diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 13ee4e6..3f1d2ac 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -443,7 +443,7 @@ void QDeclarativeColumn::reportConflictingAnchors() for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); if (child.item) { - QDeclarativeAnchors::Anchors usedAnchors = child.item->anchors()->usedAnchors(); + QDeclarativeAnchors::Anchors usedAnchors = QDeclarativeItemPrivate::get(child.item)->anchors()->usedAnchors(); if (usedAnchors & QDeclarativeAnchors::TopAnchor || usedAnchors & QDeclarativeAnchors::BottomAnchor || usedAnchors & QDeclarativeAnchors::VCenterAnchor) { @@ -578,7 +578,7 @@ void QDeclarativeRow::reportConflictingAnchors() for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); if (child.item) { - QDeclarativeAnchors::Anchors usedAnchors = child.item->anchors()->usedAnchors(); + QDeclarativeAnchors::Anchors usedAnchors = QDeclarativeItemPrivate::get(child.item)->anchors()->usedAnchors(); if (usedAnchors & QDeclarativeAnchors::LeftAnchor || usedAnchors & QDeclarativeAnchors::RightAnchor || usedAnchors & QDeclarativeAnchors::HCenterAnchor) { @@ -868,7 +868,7 @@ void QDeclarativeGrid::reportConflictingAnchors() bool childsWithConflictingAnchors(false); for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); - if (child.item && child.item->anchors()->usedAnchors()) { + if (child.item && QDeclarativeItemPrivate::get(child.item)->anchors()->usedAnchors()) { childsWithConflictingAnchors = true; break; } @@ -1025,7 +1025,7 @@ void QDeclarativeFlow::reportConflictingAnchors() bool childsWithConflictingAnchors(false); for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); - if (child.item && child.item->anchors()->usedAnchors()) { + if (child.item && QDeclarativeItemPrivate::get(child.item)->anchors()->usedAnchors()) { childsWithConflictingAnchors = true; break; } diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 689f53c..a93a25d 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -1056,40 +1056,41 @@ void QDeclarativeAnchorChanges::execute(Reason reason) if (!d->target) return; + QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); //incorporate any needed "reverts" if (d->applyOrigLeft) { if (!d->origLeftBinding) - d->target->anchors()->resetLeft(); + targetPrivate->anchors()->resetLeft(); QDeclarativePropertyPrivate::setBinding(d->leftProp, d->origLeftBinding); } if (d->applyOrigRight) { if (!d->origRightBinding) - d->target->anchors()->resetRight(); + targetPrivate->anchors()->resetRight(); QDeclarativePropertyPrivate::setBinding(d->rightProp, d->origRightBinding); } if (d->applyOrigHCenter) { if (!d->origHCenterBinding) - d->target->anchors()->resetHorizontalCenter(); + targetPrivate->anchors()->resetHorizontalCenter(); QDeclarativePropertyPrivate::setBinding(d->hCenterProp, d->origHCenterBinding); } if (d->applyOrigTop) { if (!d->origTopBinding) - d->target->anchors()->resetTop(); + targetPrivate->anchors()->resetTop(); QDeclarativePropertyPrivate::setBinding(d->topProp, d->origTopBinding); } if (d->applyOrigBottom) { if (!d->origBottomBinding) - d->target->anchors()->resetBottom(); + targetPrivate->anchors()->resetBottom(); QDeclarativePropertyPrivate::setBinding(d->bottomProp, d->origBottomBinding); } if (d->applyOrigVCenter) { if (!d->origVCenterBinding) - d->target->anchors()->resetVerticalCenter(); + targetPrivate->anchors()->resetVerticalCenter(); QDeclarativePropertyPrivate::setBinding(d->vCenterProp, d->origVCenterBinding); } if (d->applyOrigBaseline) { if (!d->origBaselineBinding) - d->target->anchors()->resetBaseline(); + targetPrivate->anchors()->resetBaseline(); QDeclarativePropertyPrivate::setBinding(d->baselineProp, d->origBaselineBinding); } @@ -1105,31 +1106,31 @@ void QDeclarativeAnchorChanges::execute(Reason reason) //reset any anchors that have been specified as "undefined" if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::LeftAnchor) { - d->target->anchors()->resetLeft(); + targetPrivate->anchors()->resetLeft(); QDeclarativePropertyPrivate::setBinding(d->leftProp, 0); } if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::RightAnchor) { - d->target->anchors()->resetRight(); + targetPrivate->anchors()->resetRight(); QDeclarativePropertyPrivate::setBinding(d->rightProp, 0); } if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::HCenterAnchor) { - d->target->anchors()->resetHorizontalCenter(); + targetPrivate->anchors()->resetHorizontalCenter(); QDeclarativePropertyPrivate::setBinding(d->hCenterProp, 0); } if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::TopAnchor) { - d->target->anchors()->resetTop(); + targetPrivate->anchors()->resetTop(); QDeclarativePropertyPrivate::setBinding(d->topProp, 0); } if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::BottomAnchor) { - d->target->anchors()->resetBottom(); + targetPrivate->anchors()->resetBottom(); QDeclarativePropertyPrivate::setBinding(d->bottomProp, 0); } if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::VCenterAnchor) { - d->target->anchors()->resetVerticalCenter(); + targetPrivate->anchors()->resetVerticalCenter(); QDeclarativePropertyPrivate::setBinding(d->vCenterProp, 0); } if (d->anchorSet->d_func()->resetAnchors & QDeclarativeAnchors::BaselineAnchor) { - d->target->anchors()->resetBaseline(); + targetPrivate->anchors()->resetBaseline(); QDeclarativePropertyPrivate::setBinding(d->baselineProp, 0); } @@ -1161,51 +1162,52 @@ void QDeclarativeAnchorChanges::reverse(Reason reason) if (!d->target) return; + QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); //reset any anchors set by the state if (d->leftBinding) { - d->target->anchors()->resetLeft(); + targetPrivate->anchors()->resetLeft(); QDeclarativePropertyPrivate::setBinding(d->leftBinding->property(), 0); if (reason == ActualChange) { d->leftBinding->destroy(); d->leftBinding = 0; } } if (d->rightBinding) { - d->target->anchors()->resetRight(); + targetPrivate->anchors()->resetRight(); QDeclarativePropertyPrivate::setBinding(d->rightBinding->property(), 0); if (reason == ActualChange) { d->rightBinding->destroy(); d->rightBinding = 0; } } if (d->hCenterBinding) { - d->target->anchors()->resetHorizontalCenter(); + targetPrivate->anchors()->resetHorizontalCenter(); QDeclarativePropertyPrivate::setBinding(d->hCenterBinding->property(), 0); if (reason == ActualChange) { d->hCenterBinding->destroy(); d->hCenterBinding = 0; } } if (d->topBinding) { - d->target->anchors()->resetTop(); + targetPrivate->anchors()->resetTop(); QDeclarativePropertyPrivate::setBinding(d->topBinding->property(), 0); if (reason == ActualChange) { d->topBinding->destroy(); d->topBinding = 0; } } if (d->bottomBinding) { - d->target->anchors()->resetBottom(); + targetPrivate->anchors()->resetBottom(); QDeclarativePropertyPrivate::setBinding(d->bottomBinding->property(), 0); if (reason == ActualChange) { d->bottomBinding->destroy(); d->bottomBinding = 0; } } if (d->vCenterBinding) { - d->target->anchors()->resetVerticalCenter(); + targetPrivate->anchors()->resetVerticalCenter(); QDeclarativePropertyPrivate::setBinding(d->vCenterBinding->property(), 0); if (reason == ActualChange) { d->vCenterBinding->destroy(); d->vCenterBinding = 0; } } if (d->baselineBinding) { - d->target->anchors()->resetBaseline(); + targetPrivate->anchors()->resetBaseline(); QDeclarativePropertyPrivate::setBinding(d->baselineBinding->property(), 0); if (reason == ActualChange) { d->baselineBinding->destroy(); d->baselineBinding = 0; @@ -1335,37 +1337,38 @@ void QDeclarativeAnchorChanges::clearBindings() d->fromWidth = d->target->width(); d->fromHeight = d->target->height(); + QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); //reset any anchors with corresponding reverts //reset any anchors that have been specified as "undefined" //reset any anchors that we'll be setting in the state QDeclarativeAnchors::Anchors combined = d->anchorSet->d_func()->resetAnchors | d->anchorSet->d_func()->usedAnchors; if (d->applyOrigLeft || (combined & QDeclarativeAnchors::LeftAnchor)) { - d->target->anchors()->resetLeft(); + targetPrivate->anchors()->resetLeft(); QDeclarativePropertyPrivate::setBinding(d->leftProp, 0); } if (d->applyOrigRight || (combined & QDeclarativeAnchors::RightAnchor)) { - d->target->anchors()->resetRight(); + targetPrivate->anchors()->resetRight(); QDeclarativePropertyPrivate::setBinding(d->rightProp, 0); } if (d->applyOrigHCenter || (combined & QDeclarativeAnchors::HCenterAnchor)) { - d->target->anchors()->resetHorizontalCenter(); + targetPrivate->anchors()->resetHorizontalCenter(); QDeclarativePropertyPrivate::setBinding(d->hCenterProp, 0); } if (d->applyOrigTop || (combined & QDeclarativeAnchors::TopAnchor)) { - d->target->anchors()->resetTop(); + targetPrivate->anchors()->resetTop(); QDeclarativePropertyPrivate::setBinding(d->topProp, 0); } if (d->applyOrigBottom || (combined & QDeclarativeAnchors::BottomAnchor)) { - d->target->anchors()->resetBottom(); + targetPrivate->anchors()->resetBottom(); QDeclarativePropertyPrivate::setBinding(d->bottomProp, 0); } if (d->applyOrigVCenter || (combined & QDeclarativeAnchors::VCenterAnchor)) { - d->target->anchors()->resetVerticalCenter(); + targetPrivate->anchors()->resetVerticalCenter(); QDeclarativePropertyPrivate::setBinding(d->vCenterProp, 0); } if (d->applyOrigBaseline || (combined & QDeclarativeAnchors::BaselineAnchor)) { - d->target->anchors()->resetBaseline(); + targetPrivate->anchors()->resetBaseline(); QDeclarativePropertyPrivate::setBinding(d->baselineProp, 0); } } @@ -1387,21 +1390,22 @@ void QDeclarativeAnchorChanges::rewind() if (!d->target) return; + QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); //restore previous anchors if (d->rewindLeft.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setLeft(d->rewindLeft); + targetPrivate->anchors()->setLeft(d->rewindLeft); if (d->rewindRight.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setRight(d->rewindRight); + targetPrivate->anchors()->setRight(d->rewindRight); if (d->rewindHCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setHorizontalCenter(d->rewindHCenter); + targetPrivate->anchors()->setHorizontalCenter(d->rewindHCenter); if (d->rewindTop.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setTop(d->rewindTop); + targetPrivate->anchors()->setTop(d->rewindTop); if (d->rewindBottom.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setBottom(d->rewindBottom); + targetPrivate->anchors()->setBottom(d->rewindBottom); if (d->rewindVCenter.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setVerticalCenter(d->rewindVCenter); + targetPrivate->anchors()->setVerticalCenter(d->rewindVCenter); if (d->rewindBaseline.anchorLine != QDeclarativeAnchorLine::Invalid) - d->target->anchors()->setBaseline(d->rewindBaseline); + targetPrivate->anchors()->setBaseline(d->rewindBaseline); d->target->setX(d->rewindX); d->target->setY(d->rewindY); @@ -1415,13 +1419,14 @@ void QDeclarativeAnchorChanges::saveCurrentValues() if (!d->target) return; - d->rewindLeft = d->target->anchors()->left(); - d->rewindRight = d->target->anchors()->right(); - d->rewindHCenter = d->target->anchors()->horizontalCenter(); - d->rewindTop = d->target->anchors()->top(); - d->rewindBottom = d->target->anchors()->bottom(); - d->rewindVCenter = d->target->anchors()->verticalCenter(); - d->rewindBaseline = d->target->anchors()->baseline(); + QDeclarativeItemPrivate *targetPrivate = QDeclarativeItemPrivate::get(d->target); + d->rewindLeft = targetPrivate->anchors()->left(); + d->rewindRight = targetPrivate->anchors()->right(); + d->rewindHCenter = targetPrivate->anchors()->horizontalCenter(); + d->rewindTop = targetPrivate->anchors()->top(); + d->rewindBottom = targetPrivate->anchors()->bottom(); + d->rewindVCenter = targetPrivate->anchors()->verticalCenter(); + d->rewindBaseline = targetPrivate->anchors()->baseline(); d->rewindX = d->target->x(); d->rewindY = d->target->y(); diff --git a/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp b/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp index dff62c7..e169fa2 100644 --- a/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp +++ b/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp @@ -48,6 +48,7 @@ #include #include #include +#include Q_DECLARE_METATYPE(QDeclarativeAnchors::Anchor) Q_DECLARE_METATYPE(QDeclarativeAnchorLine::AnchorLine) @@ -376,15 +377,16 @@ void tst_qdeclarativeanchors::reset() anchor.anchorLine = anchorLine; QDeclarativeItem *item = new QDeclarativeItem; + QDeclarativeItemPrivate *itemPrivate = QDeclarativeItemPrivate::get(item); - const QMetaObject *meta = item->anchors()->metaObject(); + const QMetaObject *meta = itemPrivate->anchors()->metaObject(); QMetaProperty p = meta->property(meta->indexOfProperty(side.toUtf8().constData())); - QVERIFY(p.write(item->anchors(), qVariantFromValue(anchor))); - QCOMPARE(item->anchors()->usedAnchors().testFlag(usedAnchor), true); + QVERIFY(p.write(itemPrivate->anchors(), qVariantFromValue(anchor))); + QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(usedAnchor), true); - QVERIFY(p.reset(item->anchors())); - QCOMPARE(item->anchors()->usedAnchors().testFlag(usedAnchor), false); + QVERIFY(p.reset(itemPrivate->anchors())); + QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(usedAnchor), false); delete item; delete baseItem; @@ -410,18 +412,19 @@ void tst_qdeclarativeanchors::resetConvenience() { QDeclarativeItem *baseItem = new QDeclarativeItem; QDeclarativeItem *item = new QDeclarativeItem; + QDeclarativeItemPrivate *itemPrivate = QDeclarativeItemPrivate::get(item); //fill - item->anchors()->setFill(baseItem); - QVERIFY(item->anchors()->fill() == baseItem); - item->anchors()->resetFill(); - QVERIFY(item->anchors()->fill() == 0); + itemPrivate->anchors()->setFill(baseItem); + QVERIFY(itemPrivate->anchors()->fill() == baseItem); + itemPrivate->anchors()->resetFill(); + QVERIFY(itemPrivate->anchors()->fill() == 0); //centerIn - item->anchors()->setCenterIn(baseItem); - QVERIFY(item->anchors()->centerIn() == baseItem); - item->anchors()->resetCenterIn(); - QVERIFY(item->anchors()->centerIn() == 0); + itemPrivate->anchors()->setCenterIn(baseItem); + QVERIFY(itemPrivate->anchors()->centerIn() == baseItem); + itemPrivate->anchors()->resetCenterIn(); + QVERIFY(itemPrivate->anchors()->centerIn() == 0); delete item; delete baseItem; @@ -433,12 +436,13 @@ void tst_qdeclarativeanchors::nullItem() QDeclarativeAnchorLine anchor; QDeclarativeItem *item = new QDeclarativeItem; + QDeclarativeItemPrivate *itemPrivate = QDeclarativeItemPrivate::get(item); - const QMetaObject *meta = item->anchors()->metaObject(); + const QMetaObject *meta = itemPrivate->anchors()->metaObject(); QMetaProperty p = meta->property(meta->indexOfProperty(side.toUtf8().constData())); QTest::ignoreMessage(QtWarningMsg, ": QML Item: Cannot anchor to a null item."); - QVERIFY(p.write(item->anchors(), qVariantFromValue(anchor))); + QVERIFY(p.write(itemPrivate->anchors(), qVariantFromValue(anchor))); delete item; } @@ -486,15 +490,16 @@ void tst_qdeclarativeanchors::fill() qApp->processEvents(); QDeclarativeRectangle* rect = findItem(view->rootObject(), QLatin1String("filler")); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QCOMPARE(rect->x(), 0.0 + 10.0); QCOMPARE(rect->y(), 0.0 + 30.0); QCOMPARE(rect->width(), 200.0 - 10.0 - 20.0); QCOMPARE(rect->height(), 200.0 - 30.0 - 40.0); //Alter Offsets (tests QTBUG-6631) - rect->anchors()->setLeftMargin(20.0); - rect->anchors()->setRightMargin(0.0); - rect->anchors()->setBottomMargin(0.0); - rect->anchors()->setTopMargin(10.0); + rectPrivate->anchors()->setLeftMargin(20.0); + rectPrivate->anchors()->setRightMargin(0.0); + rectPrivate->anchors()->setBottomMargin(0.0); + rectPrivate->anchors()->setTopMargin(10.0); QCOMPARE(rect->x(), 0.0 + 20.0); QCOMPARE(rect->y(), 0.0 + 10.0); QCOMPARE(rect->width(), 200.0 - 20.0); @@ -509,11 +514,12 @@ void tst_qdeclarativeanchors::centerIn() qApp->processEvents(); QDeclarativeRectangle* rect = findItem(view->rootObject(), QLatin1String("centered")); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QCOMPARE(rect->x(), 75.0 + 10); QCOMPARE(rect->y(), 75.0 + 30); //Alter Offsets (tests QTBUG-6631) - rect->anchors()->setHorizontalCenterOffset(-20.0); - rect->anchors()->setVerticalCenterOffset(-10.0); + rectPrivate->anchors()->setHorizontalCenterOffset(-20.0); + rectPrivate->anchors()->setVerticalCenterOffset(-10.0); QCOMPARE(rect->x(), 75.0 - 20.0); QCOMPARE(rect->y(), 75.0 - 10.0); @@ -526,13 +532,14 @@ void tst_qdeclarativeanchors::margins() qApp->processEvents(); QDeclarativeRectangle* rect = findItem(view->rootObject(), QLatin1String("filler")); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QCOMPARE(rect->x(), 5.0); QCOMPARE(rect->y(), 6.0); QCOMPARE(rect->width(), 200.0 - 5.0 - 10.0); QCOMPARE(rect->height(), 200.0 - 6.0 - 10.0); - rect->anchors()->setTopMargin(0.0); - rect->anchors()->setMargins(20.0); + rectPrivate->anchors()->setTopMargin(0.0); + rectPrivate->anchors()->setMargins(20.0); QCOMPARE(rect->x(), 5.0); QCOMPARE(rect->y(), 20.0); diff --git a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index e217e34..ed7e506 100644 --- a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -324,7 +325,7 @@ void tst_qdeclarativeanimations::badTypes() QDeclarativeRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - rect->setState("state1"); + QDeclarativeItemPrivate::get(rect)->setState("state1"); QTest::qWait(1000 + 50); QDeclarativeRectangle *myRect = rect->findChild("MyRect"); QVERIFY(myRect); @@ -366,7 +367,7 @@ void tst_qdeclarativeanimations::mixedTypes() QDeclarativeRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - rect->setState("state1"); + QDeclarativeItemPrivate::get(rect)->setState("state1"); QTest::qWait(500); QDeclarativeRectangle *myRect = rect->findChild("MyRect"); QVERIFY(myRect); @@ -382,7 +383,7 @@ void tst_qdeclarativeanimations::mixedTypes() QDeclarativeRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - rect->setState("state1"); + QDeclarativeItemPrivate::get(rect)->setState("state1"); QTest::qWait(500); QDeclarativeRectangle *myRect = rect->findChild("MyRect"); QVERIFY(myRect); @@ -468,7 +469,7 @@ void tst_qdeclarativeanimations::propertiesTransition() QDeclarativeRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); QDeclarativeRectangle *myRect = rect->findChild("TheRect"); QVERIFY(myRect); QTest::qWait(waitDuration); @@ -483,7 +484,7 @@ void tst_qdeclarativeanimations::propertiesTransition() QDeclarativeRectangle *myRect = rect->findChild("TheRect"); QVERIFY(myRect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); QCOMPARE(myRect->x(),qreal(200)); QCOMPARE(myRect->y(),qreal(100)); QTest::qWait(waitDuration); @@ -498,7 +499,7 @@ void tst_qdeclarativeanimations::propertiesTransition() QDeclarativeRectangle *myRect = rect->findChild("TheRect"); QVERIFY(myRect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); QCOMPARE(myRect->x(),qreal(200)); QCOMPARE(myRect->y(),qreal(100)); } @@ -511,7 +512,7 @@ void tst_qdeclarativeanimations::propertiesTransition() QDeclarativeRectangle *myRect = rect->findChild("TheRect"); QVERIFY(myRect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); QCOMPARE(myRect->x(),qreal(100)); QTest::qWait(waitDuration); QTIMED_COMPARE(myRect->x(),qreal(200)); @@ -525,7 +526,7 @@ void tst_qdeclarativeanimations::propertiesTransition() QDeclarativeRectangle *myRect = rect->findChild("TheRect"); QVERIFY(myRect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); QCOMPARE(myRect->x(),qreal(100)); QTest::qWait(waitDuration); QTIMED_COMPARE(myRect->x(),qreal(200)); @@ -539,7 +540,7 @@ void tst_qdeclarativeanimations::propertiesTransition() QDeclarativeRectangle *myRect = rect->findChild("TheRect"); QVERIFY(myRect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); QCOMPARE(myRect->x(),qreal(100)); QTest::qWait(waitDuration); QTIMED_COMPARE(myRect->x(),qreal(100)); @@ -709,7 +710,7 @@ void tst_qdeclarativeanimations::rotation() QDeclarativeRectangle *rr3 = rect->findChild("rr3"); QDeclarativeRectangle *rr4 = rect->findChild("rr4"); - rect->setState("state1"); + QDeclarativeItemPrivate::get(rect)->setState("state1"); QTest::qWait(800); qreal r1 = rr->rotation(); qreal r2 = rr2->rotation(); diff --git a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp index 5e0c9d5..1dc4b53 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp +++ b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include "../../../shared/util.h" class tst_qdeclarativebehaviors : public QObject @@ -81,7 +82,7 @@ void tst_qdeclarativebehaviors::simpleBehavior() QTRY_VERIFY(rect); QTRY_VERIFY(qobject_cast(rect->findChild("MyBehavior"))->animation()); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->x() < 200); //i.e. the behavior has been triggered @@ -129,7 +130,7 @@ void tst_qdeclarativebehaviors::loop() QTRY_VERIFY(rect); //don't crash - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); delete rect; } @@ -141,7 +142,7 @@ void tst_qdeclarativebehaviors::colorBehavior() QDeclarativeRectangle *rect = qobject_cast(c.create()); QTRY_VERIFY(rect); - rect->setState("red"); + QDeclarativeItemPrivate::get(rect)->setState("red"); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->color() != QColor("red")); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->color() != QColor("green")); //i.e. the behavior has been triggered @@ -156,7 +157,7 @@ void tst_qdeclarativebehaviors::parentBehavior() QDeclarativeRectangle *rect = qobject_cast(c.create()); QTRY_VERIFY(rect); - rect->setState("reparented"); + QDeclarativeItemPrivate::get(rect)->setState("reparented"); QTRY_VERIFY(rect->findChild("MyRect")->parentItem() != rect->findChild("NewParent")); QTRY_VERIFY(rect->findChild("MyRect")->parentItem() == rect->findChild("NewParent")); @@ -170,7 +171,7 @@ void tst_qdeclarativebehaviors::replaceBinding() QDeclarativeRectangle *rect = qobject_cast(c.create()); QTRY_VERIFY(rect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); QDeclarativeRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QTRY_VERIFY(innerRect); QTRY_VERIFY(innerRect->x() > 0); @@ -182,7 +183,7 @@ void tst_qdeclarativebehaviors::replaceBinding() rect->setProperty("movedx", 210); QTRY_COMPARE(innerRect->x(), (qreal)210); - rect->setState(""); + QDeclarativeItemPrivate::get(rect)->setState(""); QTRY_VERIFY(innerRect->x() > 10); QTRY_VERIFY(innerRect->x() < 210); //i.e. the behavior has been triggered QTRY_COMPARE(innerRect->x(), (qreal)10); @@ -202,7 +203,7 @@ void tst_qdeclarativebehaviors::group() QDeclarativeRectangle *rect = qobject_cast(c.create()); QTRY_VERIFY(rect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); //QTest::qWait(200); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->x() < 200); @@ -217,7 +218,7 @@ void tst_qdeclarativebehaviors::group() QDeclarativeRectangle *rect = qobject_cast(c.create()); QTRY_VERIFY(rect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->x() < 200); //i.e. the behavior has been triggered @@ -233,7 +234,7 @@ void tst_qdeclarativebehaviors::emptyBehavior() QDeclarativeRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QCOMPARE(x, qreal(200)); //should change immediately @@ -247,7 +248,7 @@ void tst_qdeclarativebehaviors::explicitSelection() QDeclarativeRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->x() < 200); //i.e. the behavior has been triggered @@ -262,7 +263,7 @@ void tst_qdeclarativebehaviors::nonSelectingBehavior() QDeclarativeRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QCOMPARE(x, qreal(200)); //should change immediately @@ -291,7 +292,7 @@ void tst_qdeclarativebehaviors::disabled() QVERIFY(rect); QCOMPARE(rect->findChild("MyBehavior")->enabled(), false); - rect->setState("moved"); + QDeclarativeItemPrivate::get(rect)->setState("moved"); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QCOMPARE(x, qreal(200)); //should change immediately diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index a016fa7..d384d26 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -47,6 +47,7 @@ #include #include #include +#include class MyRect : public QDeclarativeRectangle @@ -128,63 +129,66 @@ void tst_qdeclarativestates::basicChanges() { QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); } { QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicChanges2.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState("green"); + rectPrivate->setState("green"); QCOMPARE(rect->color(),QColor("green")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); - rect->setState("green"); + rectPrivate->setState("green"); QCOMPARE(rect->color(),QColor("green")); } { QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicChanges3.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); QCOMPARE(rect->border()->width(),1); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); QCOMPARE(rect->border()->width(),1); - rect->setState("bordered"); + rectPrivate->setState("bordered"); QCOMPARE(rect->color(),QColor("red")); QCOMPARE(rect->border()->width(),2); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); QCOMPARE(rect->border()->width(),1); //### we should be checking that this is an implicit rather than explicit 1 (which currently fails) - rect->setState("bordered"); + rectPrivate->setState("bordered"); QCOMPARE(rect->color(),QColor("red")); QCOMPARE(rect->border()->width(),2); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); QCOMPARE(rect->border()->width(),1); @@ -220,32 +224,33 @@ void tst_qdeclarativestates::basicExtension() { QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicExtension.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); QCOMPARE(rect->border()->width(),1); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); QCOMPARE(rect->border()->width(),1); - rect->setState("bordered"); + rectPrivate->setState("bordered"); QCOMPARE(rect->color(),QColor("blue")); QCOMPARE(rect->border()->width(),2); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); QCOMPARE(rect->border()->width(),1); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); QCOMPARE(rect->border()->width(),1); - rect->setState("bordered"); + rectPrivate->setState("bordered"); QCOMPARE(rect->color(),QColor("blue")); QCOMPARE(rect->border()->width(),2); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); QCOMPARE(rect->border()->width(),1); } @@ -253,26 +258,27 @@ void tst_qdeclarativestates::basicExtension() { QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/fakeExtension.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState("green"); + rectPrivate->setState("green"); QCOMPARE(rect->color(),QColor("green")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState("green"); + rectPrivate->setState("green"); QCOMPARE(rect->color(),QColor("green")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); - rect->setState("green"); + rectPrivate->setState("green"); QCOMPARE(rect->color(),QColor("green")); } } @@ -284,77 +290,80 @@ void tst_qdeclarativestates::basicBinding() { QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicBinding.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); rect->setProperty("sourceColor", QColor("green")); QCOMPARE(rect->color(),QColor("green")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); rect->setProperty("sourceColor", QColor("yellow")); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("yellow")); } { QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicBinding2.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); rect->setProperty("sourceColor", QColor("green")); QCOMPARE(rect->color(),QColor("blue")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("green")); rect->setProperty("sourceColor", QColor("yellow")); QCOMPARE(rect->color(),QColor("yellow")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("yellow")); } { QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicBinding3.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); rect->setProperty("sourceColor", QColor("green")); QCOMPARE(rect->color(),QColor("green")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); rect->setProperty("sourceColor", QColor("red")); QCOMPARE(rect->color(),QColor("blue")); rect->setProperty("sourceColor2", QColor("yellow")); QCOMPARE(rect->color(),QColor("yellow")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); rect->setProperty("sourceColor2", QColor("green")); QCOMPARE(rect->color(),QColor("red")); @@ -365,27 +374,28 @@ void tst_qdeclarativestates::basicBinding() { QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicBinding4.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); rect->setProperty("sourceColor", QColor("yellow")); QCOMPARE(rect->color(),QColor("yellow")); - rect->setState("green"); + rectPrivate->setState("green"); QCOMPARE(rect->color(),QColor("green")); rect->setProperty("sourceColor", QColor("purple")); QCOMPARE(rect->color(),QColor("green")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("purple")); - rect->setState("green"); + rectPrivate->setState("green"); QCOMPARE(rect->color(),QColor("green")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); } } @@ -403,7 +413,7 @@ void tst_qdeclarativestates::signalOverride() rect->doSomething(); QCOMPARE(rect->color(),QColor("blue")); - rect->setState("green"); + QDeclarativeItemPrivate::get(rect)->setState("green"); rect->doSomething(); QCOMPARE(rect->color(),QColor("green")); } @@ -418,8 +428,7 @@ void tst_qdeclarativestates::signalOverride() QCOMPARE(rect->color(),QColor("blue")); QDeclarativeRectangle *innerRect = qobject_cast(rect->findChild("extendedRect")); - - innerRect->setState("green"); + QDeclarativeItemPrivate::get(innerRect)->setState("green"); rect->doSomething(); QCOMPARE(rect->color(),QColor("blue")); QCOMPARE(innerRect->color(),QColor("green")); @@ -435,7 +444,7 @@ void tst_qdeclarativestates::signalOverrideCrash() MyRect *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - rect->setState("overridden"); + QDeclarativeItemPrivate::get(rect)->setState("overridden"); rect->doSomething(); } @@ -463,7 +472,7 @@ void tst_qdeclarativestates::parentChange() QCOMPARE(pChange->parent(), nParent); - rect->setState("reparented"); + QDeclarativeItemPrivate::get(rect)->setState("reparented"); QCOMPARE(innerRect->rotation(), qreal(0)); QCOMPARE(innerRect->scale(), qreal(1)); QCOMPARE(innerRect->x(), qreal(-133)); @@ -474,11 +483,11 @@ void tst_qdeclarativestates::parentChange() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/parentChange2.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QDeclarativeRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect != 0); - rect->setState("reparented"); + rectPrivate->setState("reparented"); QCOMPARE(innerRect->rotation(), qreal(15)); QCOMPARE(innerRect->scale(), qreal(.5)); QCOMPARE(QString("%1").arg(innerRect->x()), QString("%1").arg(-19.9075)); @@ -489,17 +498,17 @@ void tst_qdeclarativestates::parentChange() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/parentChange3.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QDeclarativeRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect != 0); - rect->setState("reparented"); + rectPrivate->setState("reparented"); QCOMPARE(innerRect->rotation(), qreal(-37)); QCOMPARE(innerRect->scale(), qreal(.25)); QCOMPARE(QString("%1").arg(innerRect->x()), QString("%1").arg(-217.305)); QCOMPARE(QString("%1").arg(innerRect->y()), QString("%1").arg(-164.413)); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(innerRect->rotation(), qreal(0)); QCOMPARE(innerRect->scale(), qreal(1)); QCOMPARE(innerRect->x(), qreal(5)); @@ -521,7 +530,7 @@ void tst_qdeclarativestates::parentChangeErrors() QVERIFY(innerRect != 0); QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/parentChange4.qml") + ":25:9: QML ParentChange: Unable to preserve appearance under non-uniform scale"); - rect->setState("reparented"); + QDeclarativeItemPrivate::get(rect)->setState("reparented"); QCOMPARE(innerRect->rotation(), qreal(0)); QCOMPARE(innerRect->scale(), qreal(1)); QCOMPARE(innerRect->x(), qreal(5)); @@ -537,7 +546,7 @@ void tst_qdeclarativestates::parentChangeErrors() QVERIFY(innerRect != 0); QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/parentChange5.qml") + ":25:9: QML ParentChange: Unable to preserve appearance under complex transform"); - rect->setState("reparented"); + QDeclarativeItemPrivate::get(rect)->setState("reparented"); QCOMPARE(innerRect->rotation(), qreal(0)); QCOMPARE(innerRect->scale(), qreal(1)); QCOMPARE(innerRect->x(), qreal(5)); @@ -552,6 +561,7 @@ void tst_qdeclarativestates::anchorChanges() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorChanges1.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QDeclarativeRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect != 0); @@ -564,14 +574,14 @@ void tst_qdeclarativestates::anchorChanges() QDeclarativeAnchorChanges *aChanges = qobject_cast(state->operationAt(0)); QVERIFY(aChanges != 0); - rect->setState("right"); + rectPrivate->setState("right"); QCOMPARE(innerRect->x(), qreal(150)); QCOMPARE(aChanges->object(), qobject_cast(innerRect)); - QCOMPARE(aChanges->object()->anchors()->left().anchorLine, QDeclarativeAnchorLine::Invalid); //### was reset (how do we distinguish from not set at all) - QCOMPARE(aChanges->object()->anchors()->right().item, rect->right().item); - QCOMPARE(aChanges->object()->anchors()->right().anchorLine, rect->right().anchorLine); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QDeclarativeAnchorLine::Invalid); //### was reset (how do we distinguish from not set at all) + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->right().item, rectPrivate->right().item); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->right().anchorLine, rectPrivate->right().anchorLine); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(innerRect->x(), qreal(5)); delete rect; @@ -584,14 +594,15 @@ void tst_qdeclarativestates::anchorChanges2() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorChanges2.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QDeclarativeRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect != 0); - rect->setState("right"); + rectPrivate->setState("right"); QCOMPARE(innerRect->x(), qreal(150)); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(innerRect->x(), qreal(5)); delete rect; @@ -604,6 +615,7 @@ void tst_qdeclarativestates::anchorChanges3() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorChanges3.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QDeclarativeRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect != 0); @@ -622,23 +634,23 @@ void tst_qdeclarativestates::anchorChanges3() QDeclarativeAnchorChanges *aChanges = qobject_cast(state->operationAt(0)); QVERIFY(aChanges != 0); - rect->setState("reanchored"); + rectPrivate->setState("reanchored"); QCOMPARE(aChanges->object(), qobject_cast(innerRect)); - QCOMPARE(aChanges->object()->anchors()->left().item, leftGuideline->left().item); - QCOMPARE(aChanges->object()->anchors()->left().anchorLine, leftGuideline->left().anchorLine); - QCOMPARE(aChanges->object()->anchors()->right().item, rect->right().item); - QCOMPARE(aChanges->object()->anchors()->right().anchorLine, rect->right().anchorLine); - QCOMPARE(aChanges->object()->anchors()->top().item, rect->top().item); - QCOMPARE(aChanges->object()->anchors()->top().anchorLine, rect->top().anchorLine); - QCOMPARE(aChanges->object()->anchors()->bottom().item, bottomGuideline->bottom().item); - QCOMPARE(aChanges->object()->anchors()->bottom().anchorLine, bottomGuideline->bottom().anchorLine); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->left().item, QDeclarativeItemPrivate::get(leftGuideline)->left().item); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QDeclarativeItemPrivate::get(leftGuideline)->left().anchorLine); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->right().item, rectPrivate->right().item); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->right().anchorLine, rectPrivate->right().anchorLine); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->top().item, rectPrivate->top().item); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->top().anchorLine, rectPrivate->top().anchorLine); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->bottom().item, QDeclarativeItemPrivate::get(bottomGuideline)->bottom().item); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->bottom().anchorLine, QDeclarativeItemPrivate::get(bottomGuideline)->bottom().anchorLine); QCOMPARE(innerRect->x(), qreal(10)); QCOMPARE(innerRect->y(), qreal(0)); QCOMPARE(innerRect->width(), qreal(190)); QCOMPARE(innerRect->height(), qreal(150)); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(innerRect->x(), qreal(0)); QCOMPARE(innerRect->y(), qreal(10)); QCOMPARE(innerRect->width(), qreal(150)); @@ -672,12 +684,12 @@ void tst_qdeclarativestates::anchorChanges4() QDeclarativeAnchorChanges *aChanges = qobject_cast(state->operationAt(0)); QVERIFY(aChanges != 0); - rect->setState("reanchored"); + QDeclarativeItemPrivate::get(rect)->setState("reanchored"); QCOMPARE(aChanges->object(), qobject_cast(innerRect)); - QCOMPARE(aChanges->object()->anchors()->horizontalCenter().item, bottomGuideline->horizontalCenter().item); - QCOMPARE(aChanges->object()->anchors()->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); - QCOMPARE(aChanges->object()->anchors()->verticalCenter().item, leftGuideline->verticalCenter().item); - QCOMPARE(aChanges->object()->anchors()->verticalCenter().anchorLine, leftGuideline->verticalCenter().anchorLine); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->horizontalCenter().item, QDeclarativeItemPrivate::get(bottomGuideline)->horizontalCenter().item); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->horizontalCenter().anchorLine, QDeclarativeItemPrivate::get(bottomGuideline)->horizontalCenter().anchorLine); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->verticalCenter().item, QDeclarativeItemPrivate::get(leftGuideline)->verticalCenter().item); + QCOMPARE(QDeclarativeItemPrivate::get(aChanges->object())->anchors()->verticalCenter().anchorLine, QDeclarativeItemPrivate::get(leftGuideline)->verticalCenter().anchorLine); delete rect; } @@ -707,7 +719,7 @@ void tst_qdeclarativestates::anchorChanges5() QDeclarativeAnchorChanges *aChanges = qobject_cast(state->operationAt(0)); QVERIFY(aChanges != 0); - rect->setState("reanchored"); + QDeclarativeItemPrivate::get(rect)->setState("reanchored"); QCOMPARE(aChanges->object(), qobject_cast(innerRect)); //QCOMPARE(aChanges->anchors()->horizontalCenter().item, bottomGuideline->horizontalCenter().item); //QCOMPARE(aChanges->anchors()->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); @@ -726,7 +738,7 @@ void tst_qdeclarativestates::anchorChangesCrash() QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - rect->setState("reanchored"); + QDeclarativeItemPrivate::get(rect)->setState("reanchored"); delete rect; } @@ -739,13 +751,13 @@ void tst_qdeclarativestates::script() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/script.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("blue")); // a script isn't reverted } } @@ -757,13 +769,13 @@ void tst_qdeclarativestates::restoreEntryValues() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/restoreEntryValues.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("blue")); } @@ -774,7 +786,7 @@ void tst_qdeclarativestates::explicitChanges() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/explicit.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QDeclarativeListReference list(rect, "states"); QDeclarativeState *state = qobject_cast(list.at(0)); QVERIFY(state != 0); @@ -786,18 +798,18 @@ void tst_qdeclarativestates::explicitChanges() QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); rect->setProperty("sourceColor", QColor("green")); QCOMPARE(rect->color(),QColor("blue")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); rect->setProperty("sourceColor", QColor("yellow")); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("yellow")); } @@ -812,7 +824,7 @@ void tst_qdeclarativestates::propertyErrors() QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/propertyErrors.qml") + ":8:9: QML PropertyChanges: Cannot assign to non-existent property \"colr\""); QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/propertyErrors.qml") + ":8:9: QML PropertyChanges: Cannot assign to read-only property \"wantsFocus\""); - rect->setState("blue"); + QDeclarativeItemPrivate::get(rect)->setState("blue"); } void tst_qdeclarativestates::incorrectRestoreBug() @@ -822,22 +834,22 @@ void tst_qdeclarativestates::incorrectRestoreBug() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QCOMPARE(rect->color(),QColor("red")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); // make sure if we change the base state value, we then restore to it correctly rect->setColor(QColor("green")); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("green")); } @@ -865,12 +877,12 @@ void tst_qdeclarativestates::deletingChange() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/deleting.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - - rect->setState("blue"); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("blue")); QCOMPARE(rect->radius(),qreal(5)); - rect->setState(""); + rectPrivate->setState(""); QCOMPARE(rect->color(),QColor("red")); QCOMPARE(rect->radius(),qreal(0)); @@ -883,7 +895,7 @@ void tst_qdeclarativestates::deletingChange() qmlExecuteDeferred(state); QCOMPARE(state->operationCount(), 1); - rect->setState("blue"); + rectPrivate->setState("blue"); QCOMPARE(rect->color(),QColor("red")); QCOMPARE(rect->radius(),qreal(5)); @@ -928,11 +940,11 @@ void tst_qdeclarativestates::tempState() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/legalTempState.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QTest::ignoreMessage(QtDebugMsg, "entering placed"); QTest::ignoreMessage(QtDebugMsg, "entering idle"); - rect->setState("placed"); - QCOMPARE(rect->state(), QLatin1String("idle")); + rectPrivate->setState("placed"); + QCOMPARE(rectPrivate->state(), QLatin1String("idle")); } void tst_qdeclarativestates::illegalTempState() @@ -942,10 +954,10 @@ void tst_qdeclarativestates::illegalTempState() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/illegalTempState.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QTest::ignoreMessage(QtWarningMsg, ": QML StateGroup: Can't apply a state change as part of a state definition."); - rect->setState("placed"); - QCOMPARE(rect->state(), QLatin1String("placed")); + rectPrivate->setState("placed"); + QCOMPARE(rectPrivate->state(), QLatin1String("placed")); } void tst_qdeclarativestates::nonExistantProperty() @@ -955,10 +967,10 @@ void tst_qdeclarativestates::nonExistantProperty() QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/nonExistantProp.qml"); QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); QTest::ignoreMessage(QtWarningMsg, fullDataPath("/data/nonExistantProp.qml") + ":9:9: QML PropertyChanges: Cannot assign to non-existent property \"colr\""); - rect->setState("blue"); - QCOMPARE(rect->state(), QLatin1String("blue")); + rectPrivate->setState("blue"); + QCOMPARE(rectPrivate->state(), QLatin1String("blue")); } void tst_qdeclarativestates::reset() @@ -974,7 +986,7 @@ void tst_qdeclarativestates::reset() QCOMPARE(text->width(), qreal(40.)); QVERIFY(text->width() < text->height()); - rect->setState("state1"); + QDeclarativeItemPrivate::get(rect)->setState("state1"); QVERIFY(text->width() > 41); QVERIFY(text->width() > text->height()); @@ -1000,19 +1012,20 @@ void tst_qdeclarativestates::whenOrdering() QDeclarativeComponent c(&engine, SRCDIR "/data/whenOrdering.qml"); QDeclarativeRectangle *rect = qobject_cast(c.create()); QVERIFY(rect != 0); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); - QCOMPARE(rect->state(), QLatin1String("")); + QCOMPARE(rectPrivate->state(), QLatin1String("")); rect->setProperty("condition2", true); - QCOMPARE(rect->state(), QLatin1String("state2")); + QCOMPARE(rectPrivate->state(), QLatin1String("state2")); rect->setProperty("condition1", true); - QCOMPARE(rect->state(), QLatin1String("state1")); + QCOMPARE(rectPrivate->state(), QLatin1String("state1")); rect->setProperty("condition2", false); - QCOMPARE(rect->state(), QLatin1String("state1")); + QCOMPARE(rectPrivate->state(), QLatin1String("state1")); rect->setProperty("condition2", true); - QCOMPARE(rect->state(), QLatin1String("state1")); + QCOMPARE(rectPrivate->state(), QLatin1String("state1")); rect->setProperty("condition1", false); rect->setProperty("condition2", false); - QCOMPARE(rect->state(), QLatin1String("")); + QCOMPARE(rectPrivate->state(), QLatin1String("")); } void tst_qdeclarativestates::urlResolution() @@ -1029,7 +1042,7 @@ void tst_qdeclarativestates::urlResolution() QDeclarativeImage *image3 = rect->findChild("image3"); QVERIFY(myType != 0 && image1 != 0 && image2 != 0 && image3 != 0); - myType->setState("SetImageState"); + QDeclarativeItemPrivate::get(myType)->setState("SetImageState"); QUrl resolved = QUrl::fromLocalFile(SRCDIR "/data/Implementation/images/qt-logo.png"); QCOMPARE(image1->source(), resolved); QCOMPARE(image2->source(), resolved); -- cgit v0.12 From 69efa1c869694666c66375179b43e2569cf2772b Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Thu, 29 Apr 2010 08:34:25 +0200 Subject: Update the input method sensitivity in case of complex widgets in QGraphicsProxyWidget. In case of a complex widget embedded in a proxy, we need to update the input method acceptance whenever the focus changes inside the proxy. Task-number:QTBUG-8847 Reviewed-by:janarve --- src/gui/kernel/qwidget.cpp | 6 ++++++ .../qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 20d1d30..60f38f2 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -6232,6 +6232,12 @@ void QWidget::setFocus(Qt::FocusReason reason) QApplication::sendEvent(that->style(), &event); } if (!isHidden()) { +#ifndef QT_NO_GRAPHICSVIEW + // Update proxy state + if (QWExtra *topData = window()->d_func()->extra) + if (topData->proxyWidget && topData->proxyWidget->hasFocus()) + topData->proxyWidget->d_func()->updateProxyInputMethodAcceptanceFromWidget(); +#endif // Send event to self QFocusEvent event(QEvent::FocusIn, reason); QPointer that = f; diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index d5f63d3..6cea834 100644 --- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -3436,6 +3436,21 @@ void tst_QGraphicsProxyWidget::inputMethod() qApp->sendEvent(proxy, &event); QCOMPARE(lineEdit->inputMethodEvents, i); } + + scene.clear(); + QGraphicsView view(&scene); + QWidget *w = new QWidget; + w->setLayout(new QVBoxLayout(w)); + QLineEdit *lineEdit = new QLineEdit; + lineEdit->setEchoMode(QLineEdit::Password); + w->layout()->addWidget(lineEdit); + lineEdit->setAttribute(Qt::WA_InputMethodEnabled, true); + QGraphicsProxyWidget *proxy = scene.addWidget(w); + view.show(); + QTest::qWaitForWindowShown(&view); + QTRY_VERIFY(!(proxy->flags() & QGraphicsItem::ItemAcceptsInputMethod)); + lineEdit->setFocus(); + QVERIFY((proxy->flags() & QGraphicsItem::ItemAcceptsInputMethod)); } void tst_QGraphicsProxyWidget::clickFocus() -- cgit v0.12 From 6b5d58554cdc1c18c73bfb39e736a3621959ca4c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 29 Apr 2010 16:44:00 +1000 Subject: Doc: some simple examples of sourceSize usage. Task-number: QTBUG-10252 --- .../graphicsitems/qdeclarativeimage.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index e00a9fd..3937778 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -316,6 +316,32 @@ qreal QDeclarativeImage::paintedHeight() const If the source is a non-scalable image (eg. JPEG), the loaded image will be no greater than this property specifies. For some formats (currently only JPEG), the whole image will never actually be loaded into memory. + + The example below will ensure that the size of the image in memory is + no larger than 1024x1024 pixels, regardless of the size of the Image element. + + \code + Image { + anchors.fill: parent + source: "images/reallyBigImage.jpg" + sourceSize.width: 1024 + sourceSize.height: 1024 + } + \endcode + + The example below will ensure that the memory used by the image is + no more than necessary to display the image at the size of the Image element. + Of course if the Image element is resized a costly reload will be required, so + use this technique \e only when the Image size is fixed. + + \code + Image { + anchors.fill: parent + source: "images/reallyBigImage.jpg" + sourceSize.width: width + sourceSize.height: height + } + \endcode */ void QDeclarativeImage::updatePaintedGeometry() -- cgit v0.12 From 31dae3d294b932c4fb2934b713273433ff4aff7c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 29 Apr 2010 17:59:58 +1000 Subject: Allow factor parameter to be passed to Qt.lighter() and Qt.darker() --- doc/src/declarative/globalobject.qdoc | 31 +++++++++++++++++++--- src/declarative/qml/qdeclarativeengine.cpp | 14 +++++++--- .../declarative/qdeclarativeqt/data/darker.qml | 3 ++- .../declarative/qdeclarativeqt/data/lighter.qml | 3 ++- .../qdeclarativeqt/tst_qdeclarativeqt.cpp | 8 +++--- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 6e6d253..85cbde2 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -166,10 +166,33 @@ If no format is specified the locale's short format is used. Alternatively, you \section2 Functions The Qt object also contains the following miscellaneous functions which expose Qt functionality for use in QML. -\section3 Qt.lighter(color baseColor) -This function returns a color 50% lighter than \c baseColor. See QColor::lighter() for further details. -\section3 Qt.darker(color baseColor) -This function returns a color 50% darker than \c baseColor. See QColor::darker() for further details. +\section3 Qt.lighter(color baseColor, real factor) +This function returns a color lighter than \c baseColor by the \c factor provided. + +If the factor is greater than 1.0, this functions returns a lighter color. +Setting factor to 1.5 returns a color that is 50% brighter. If the factor is less than 1.0, +the return color is darker, but we recommend using the Qt.darker() function for this purpose. +If the factor is 0 or negative, the return value is unspecified. + +The function converts the current RGB color to HSV, multiplies the value (V) component +by factor and converts the color back to RGB. + +If \c factor is not supplied, returns a color 50% lighter than \c baseColor (factor 1.5). + +\section3 Qt.darker(color baseColor, real factor) +This function returns a color darker than \c baseColor by the \c factor provided. + +If the factor is greater than 1.0, this function returns a darker color. +Setting factor to 3.0 returns a color that has one-third the brightness. +If the factor is less than 1.0, the return color is lighter, but we recommend using +the Qt.lighter() function for this purpose. If the factor is 0 or negative, the return +value is unspecified. + +The function converts the current RGB color to HSV, divides the value (V) component +by factor and converts the color back to RGB. + +If \c factor is not supplied, returns a color 50% darker than \c baseColor (factor 2.0). + \section3 Qt.tint(color baseColor, color tintColor) This function allows tinting one color with another. diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 19d4b57..8a61f1e 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1225,7 +1225,7 @@ QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine QScriptValue QDeclarativeEnginePrivate::lighter(QScriptContext *ctxt, QScriptEngine *engine) { - if(ctxt->argumentCount() != 1) + if(ctxt->argumentCount() != 1 && ctxt->argumentCount() != 2) return ctxt->throwError("Qt.lighter(): Invalid arguments"); QVariant v = ctxt->argument(0).toVariant(); QColor color; @@ -1238,13 +1238,16 @@ QScriptValue QDeclarativeEnginePrivate::lighter(QScriptContext *ctxt, QScriptEng return engine->nullValue(); } else return engine->nullValue(); - color = color.lighter(); + qsreal factor = 1.5; + if (ctxt->argumentCount() == 2) + factor = ctxt->argument(1).toNumber(); + color = color.lighter(int(qRound(factor*100.))); return qScriptValueFromValue(engine, qVariantFromValue(color)); } QScriptValue QDeclarativeEnginePrivate::darker(QScriptContext *ctxt, QScriptEngine *engine) { - if(ctxt->argumentCount() != 1) + if(ctxt->argumentCount() != 1 && ctxt->argumentCount() != 2) return ctxt->throwError("Qt.darker(): Invalid arguments"); QVariant v = ctxt->argument(0).toVariant(); QColor color; @@ -1257,7 +1260,10 @@ QScriptValue QDeclarativeEnginePrivate::darker(QScriptContext *ctxt, QScriptEngi return engine->nullValue(); } else return engine->nullValue(); - color = color.darker(); + qsreal factor = 2.0; + if (ctxt->argumentCount() == 2) + factor = ctxt->argument(1).toNumber(); + color = color.darker(int(qRound(factor*100.))); return qScriptValueFromValue(engine, qVariantFromValue(color)); } diff --git a/tests/auto/declarative/qdeclarativeqt/data/darker.qml b/tests/auto/declarative/qdeclarativeqt/data/darker.qml index f6333fe..738095d 100644 --- a/tests/auto/declarative/qdeclarativeqt/data/darker.qml +++ b/tests/auto/declarative/qdeclarativeqt/data/darker.qml @@ -3,9 +3,10 @@ import Qt 4.7 QtObject { property variant test1: Qt.darker(Qt.rgba(1, 0.8, 0.3)) property variant test2: Qt.darker() - property variant test3: Qt.darker(Qt.rgba(1, 0.8, 0.3), 10) + property variant test3: Qt.darker(Qt.rgba(1, 0.8, 0.3), 2.8) property variant test4: Qt.darker("red"); property variant test5: Qt.darker("perfectred"); // Non-existant color property variant test6: Qt.darker(10); + property variant test7: Qt.darker(Qt.rgba(1, 0.8, 0.3), 2.8, 10) } diff --git a/tests/auto/declarative/qdeclarativeqt/data/lighter.qml b/tests/auto/declarative/qdeclarativeqt/data/lighter.qml index 6c0053ba..ddaf78d 100644 --- a/tests/auto/declarative/qdeclarativeqt/data/lighter.qml +++ b/tests/auto/declarative/qdeclarativeqt/data/lighter.qml @@ -3,8 +3,9 @@ import Qt 4.7 QtObject { property variant test1: Qt.lighter(Qt.rgba(1, 0.8, 0.3)) property variant test2: Qt.lighter() - property variant test3: Qt.lighter(Qt.rgba(1, 0.8, 0.3), 10) + property variant test3: Qt.lighter(Qt.rgba(1, 0.8, 0.3), 1.8) property variant test4: Qt.lighter("red"); property variant test5: Qt.lighter("perfectred"); // Non-existant color property variant test6: Qt.lighter(10); + property variant test7: Qt.lighter(Qt.rgba(1, 0.8, 0.3), 1.8, 5) } diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index 7cbd8db..17b7925 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -232,7 +232,7 @@ void tst_qdeclarativeqt::lighter() QDeclarativeComponent component(&engine, TEST_FILE("lighter.qml")); QString warning1 = component.url().toString() + ":5: Error: Qt.lighter(): Invalid arguments"; - QString warning2 = component.url().toString() + ":6: Error: Qt.lighter(): Invalid arguments"; + QString warning2 = component.url().toString() + ":10: Error: Qt.lighter(): Invalid arguments"; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); @@ -241,7 +241,7 @@ void tst_qdeclarativeqt::lighter() QCOMPARE(qvariant_cast(object->property("test1")), QColor::fromRgbF(1, 0.8, 0.3).lighter()); QCOMPARE(qvariant_cast(object->property("test2")), QColor()); - QCOMPARE(qvariant_cast(object->property("test3")), QColor()); + QCOMPARE(qvariant_cast(object->property("test3")), QColor::fromRgbF(1, 0.8, 0.3).lighter(180)); QCOMPARE(qvariant_cast(object->property("test4")), QColor("red").lighter()); QCOMPARE(qvariant_cast(object->property("test5")), QColor()); QCOMPARE(qvariant_cast(object->property("test6")), QColor()); @@ -254,7 +254,7 @@ void tst_qdeclarativeqt::darker() QDeclarativeComponent component(&engine, TEST_FILE("darker.qml")); QString warning1 = component.url().toString() + ":5: Error: Qt.darker(): Invalid arguments"; - QString warning2 = component.url().toString() + ":6: Error: Qt.darker(): Invalid arguments"; + QString warning2 = component.url().toString() + ":10: Error: Qt.darker(): Invalid arguments"; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); @@ -263,7 +263,7 @@ void tst_qdeclarativeqt::darker() QCOMPARE(qvariant_cast(object->property("test1")), QColor::fromRgbF(1, 0.8, 0.3).darker()); QCOMPARE(qvariant_cast(object->property("test2")), QColor()); - QCOMPARE(qvariant_cast(object->property("test3")), QColor()); + QCOMPARE(qvariant_cast(object->property("test3")), QColor::fromRgbF(1, 0.8, 0.3).darker(280)); QCOMPARE(qvariant_cast(object->property("test4")), QColor("red").darker()); QCOMPARE(qvariant_cast(object->property("test5")), QColor()); QCOMPARE(qvariant_cast(object->property("test6")), QColor()); -- cgit v0.12 From 4c47079d367d44cf18b91965c351a5e9d834b343 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 29 Apr 2010 18:53:38 +1000 Subject: Simplify QDeclarativeGuard logic --- src/declarative/qml/qdeclarativedata_p.h | 10 ++++++---- src/declarative/qml/qdeclarativeengine.cpp | 12 ++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/declarative/qml/qdeclarativedata_p.h b/src/declarative/qml/qdeclarativedata_p.h index 4a56536..e916273 100644 --- a/src/declarative/qml/qdeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedata_p.h @@ -152,11 +152,11 @@ public: template void QDeclarativeGuard::addGuard() { - if (QObjectPrivate::get(o)->wasDeleted) { - if (prev) remGuard(); + Q_ASSERT(!prev); + + if (QObjectPrivate::get(o)->wasDeleted) return; - } - + QDeclarativeData *data = QDeclarativeData::get(o, true); next = data->guards; if (next) reinterpret_cast *>(next)->prev = &next; @@ -167,6 +167,8 @@ void QDeclarativeGuard::addGuard() template void QDeclarativeGuard::remGuard() { + Q_ASSERT(prev); + if (next) reinterpret_cast *>(next)->prev = prev; *prev = next; next = 0; diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 19d4b57..8992d50 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -870,14 +870,10 @@ void QDeclarativeData::destroyed(QObject *object) if (ownContext && context) context->destroy(); - QDeclarativeGuard *guard = guards; - while (guard) { - QDeclarativeGuard *g = guard; - guard = guard->next; - g->o = 0; - g->prev = 0; - g->next = 0; - g->objectDestroyed(object); + while (guards) { + QDeclarativeGuard *guard = guards; + *guard = (QObject *)0; + guard->objectDestroyed(object); } if (scriptValue) -- cgit v0.12 From e1a60c82d39af5bda99ebea12f6877d6cd9642ac Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 29 Apr 2010 19:04:09 +1000 Subject: Cleanup guards used in synthesized QML meta objects QTCREATORBUG-1289 --- src/declarative/qml/qdeclarativevmemetaobject.cpp | 3 +-- .../data/qtcreatorbug_1289.qml | 13 +++++++++++++ .../tst_qdeclarativeecmascript.cpp | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/qtcreatorbug_1289.qml diff --git a/src/declarative/qml/qdeclarativevmemetaobject.cpp b/src/declarative/qml/qdeclarativevmemetaobject.cpp index 45f04a0..13e9c26 100644 --- a/src/declarative/qml/qdeclarativevmemetaobject.cpp +++ b/src/declarative/qml/qdeclarativevmemetaobject.cpp @@ -106,8 +106,7 @@ QDeclarativeVMEVariant::~QDeclarativeVMEVariant() void QDeclarativeVMEVariant::cleanup() { if (type == QVariant::Invalid) { - } else if (type == QMetaType::QObjectStar || - type == QMetaType::Int || + } else if (type == QMetaType::Int || type == QMetaType::Bool || type == QMetaType::Double) { type = QVariant::Invalid; diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtcreatorbug_1289.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtcreatorbug_1289.qml new file mode 100644 index 0000000..b6d31d5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtcreatorbug_1289.qml @@ -0,0 +1,13 @@ +import Qt 4.7 + +QtObject { + id: root + property QtObject object: QtObject { + id: nested + property QtObject nestedObject + } + + Component.onCompleted: { + nested.nestedObject = root; + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 6cde46b..54c14c2 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -142,6 +142,7 @@ private slots: void libraryScriptAssert(); void variantsAssignedUndefined(); void qtbug_9792(); + void qtcreatorbug_1289(); void noSpuriousWarningsAtShutdown(); void canAssignNullToQObject(); @@ -2205,6 +2206,27 @@ void tst_qdeclarativeecmascript::qtbug_9792() delete object; } +// Verifies that QDeclarativeGuard<>s used in the vmemetaobject are cleaned correctly +void tst_qdeclarativeecmascript::qtcreatorbug_1289() +{ + QDeclarativeComponent component(&engine, TEST_FILE("qtcreatorbug_1289.qml")); + + QObject *o = component.create(); + QVERIFY(o != 0); + + QObject *nested = qvariant_cast(o->property("object")); + QVERIFY(nested != 0); + + QVERIFY(qvariant_cast(nested->property("nestedObject")) == o); + + delete nested; + nested = qvariant_cast(o->property("object")); + QVERIFY(nested == 0); + + // If the bug is present, the next line will crash + delete o; +} + // Test that we shut down without stupid warnings void tst_qdeclarativeecmascript::noSpuriousWarningsAtShutdown() { -- cgit v0.12 From e1c3dc3dad4604c8b0d2f70ef4602c5bead71ade Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 29 Apr 2010 15:01:58 +0200 Subject: Don't show warnings log window by default Disable it for the time being. The default annoyed more people then it helped. Reviewed-by: mae --- tools/qml/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 9ccc3d2..f2c0530 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -125,7 +125,7 @@ void usage() qWarning(" -sizeviewtorootobject .................... the view resizes to the changes in the content"); qWarning(" -sizerootobjecttoview .................... the content resizes to the changes in the view"); qWarning(" -qmlbrowser .............................. use a QML-based file browser"); - qWarning(" -nolog ................................... do not show log window"); + qWarning(" -warnings ................................ show warnings in a separate log window"); qWarning(" -recordfile ..................... set video recording file"); qWarning(" - ImageMagick 'convert' for GIF)"); qWarning(" - png file for raw frames"); @@ -229,7 +229,8 @@ int main(int argc, char ** argv) bool stayOnTop = false; bool maximized = false; bool useNativeFileBrowser = true; - bool showLogWidget = true; + + bool showLogWidget = false; bool sizeToView = true; #if defined(Q_OS_SYMBIAN) @@ -290,8 +291,8 @@ int main(int argc, char ** argv) useGL = true; } else if (arg == "-qmlbrowser") { useNativeFileBrowser = false; - } else if (arg == "-nolog") { - showLogWidget = false; + } else if (arg == "-warnings") { + showLogWidget = true; } else if (arg == "-I" || arg == "-L") { if (arg == "-L") qWarning("-L option provided for compatibility only, use -I instead"); -- cgit v0.12 From 204cf6be3d63b16981843b0ae6a544e30da35134 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 30 Apr 2010 08:19:00 +1000 Subject: Warn on assigning a function to a QML property. This is not supported, and should not silently be converting the function to a string. See QTBUG-10302 for why we check !isRegExp as well as isFunction. Task-number: QTBUG-10237 Reviewed-by: Aaron Kennedy --- src/declarative/qml/qdeclarativebinding.cpp | 13 +++++++- .../qml/qdeclarativeobjectscriptclass.cpp | 3 ++ .../data/functionAssignment.1.qml | 5 +++ .../data/functionAssignment.2.qml | 13 ++++++++ .../tst_qdeclarativeecmascript.cpp | 39 ++++++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/functionAssignment.1.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/functionAssignment.2.qml diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index d44e7fb..8043ea9 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -193,7 +193,18 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags) data->error.setColumn(-1); data->error.setDescription(QLatin1String("Unable to assign [undefined] to ") + QLatin1String(QMetaType::typeName(data->property.propertyType()))); - } else if (data->property.object() && + } else if (!scriptValue.isRegExp() && scriptValue.isFunction()) { + + QUrl url = QUrl(data->url); + int line = data->line; + if (url.isEmpty()) url = QUrl(QLatin1String("")); + + data->error.setUrl(url); + data->error.setLine(line); + data->error.setColumn(-1); + data->error.setDescription(QLatin1String("Unable to assign a function to a property.")); + + } else if (data->property.object() && !QDeclarativePropertyPrivate::write(data->property, value, flags)) { QUrl url = QUrl(data->url); diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 671a262..33e47fb 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -368,6 +368,9 @@ void QDeclarativeObjectScriptClass::setProperty(QObject *obj, QString error = QLatin1String("Cannot assign [undefined] to ") + QLatin1String(QMetaType::typeName(lastData->propType)); context->throwError(error); + } else if (!value.isRegExp() && value.isFunction()) { + QString error = QLatin1String("Cannot assign a function to a property."); + context->throwError(error); } else { QVariant v; if (lastData->flags & QDeclarativePropertyCache::Data::IsQList) diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/functionAssignment.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/functionAssignment.1.qml new file mode 100644 index 0000000..09540f1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/functionAssignment.1.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject { + property variant a: function myFunction() { return 2; } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/functionAssignment.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/functionAssignment.2.qml new file mode 100644 index 0000000..948b39c --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/functionAssignment.2.qml @@ -0,0 +1,13 @@ +import Qt.test 1.0 + +MyQmlObject { + property variant a + property bool runTest: false + onRunTestChanged: { + function myFunction() { + console.log("hello world"); + } + a = myFunction; + } + +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 54c14c2..49ee335 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -145,6 +145,7 @@ private slots: void qtcreatorbug_1289(); void noSpuriousWarningsAtShutdown(); void canAssignNullToQObject(); + void functionAssignment(); void callQtInvokables(); private: @@ -2291,6 +2292,44 @@ void tst_qdeclarativeecmascript::canAssignNullToQObject() } } +void tst_qdeclarativeecmascript::functionAssignment() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("functionAssignment.1.qml")); + + QString url = component.url().toString(); + QString warning = url + ":4: Unable to assign a function to a property."; + QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); + + MyQmlObject *o = qobject_cast(component.create()); + QVERIFY(o != 0); + + QVERIFY(!o->property("a").isValid()); + + delete o; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("functionAssignment.2.qml")); + + MyQmlObject *o = qobject_cast(component.create()); + QVERIFY(o != 0); + + QVERIFY(!o->property("a").isValid()); + + QString url = component.url().toString(); + QString warning = url + ":10: Error: Cannot assign a function to a property."; + QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); + + o->setProperty("runTest", true); + + QVERIFY(!o->property("a").isValid()); + + delete o; + } +} + + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" -- cgit v0.12 From ce20af2d343e2d707f93ac4cb724feb2562680c6 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 30 Apr 2010 09:38:43 +1000 Subject: missed files --- .../data/connection-unknownsignals-ignored.qml | 8 ++++++++ .../data/connection-unknownsignals-notarget.qml | 7 +++++++ .../data/connection-unknownsignals-parent.qml | 7 +++++++ .../qdeclarativeconnection/data/connection-unknownsignals.qml | 7 +++++++ 4 files changed, 29 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-ignored.qml create mode 100644 tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-notarget.qml create mode 100644 tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-parent.qml create mode 100644 tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals.qml diff --git a/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-ignored.qml b/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-ignored.qml new file mode 100644 index 0000000..764d5ab --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-ignored.qml @@ -0,0 +1,8 @@ +import Qt 4.7 + +Item { + id: screen + + Connections { target: screen; onNotFooBar1: {} ignoreUnknownSignals: true } + Connections { objectName: "connections"; onNotFooBar2: {} ignoreUnknownSignals: true } +} diff --git a/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-notarget.qml b/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-notarget.qml new file mode 100644 index 0000000..09e7812 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-notarget.qml @@ -0,0 +1,7 @@ +import Qt 4.7 + +Item { + id: screen + + Connections { objectName: "connections"; target: null; onNotFooBar: {} } +} diff --git a/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-parent.qml b/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-parent.qml new file mode 100644 index 0000000..478503d --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals-parent.qml @@ -0,0 +1,7 @@ +import Qt 4.7 + +Item { + id: screen + + Connections { objectName: "connections"; onFooBar: {} } +} diff --git a/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals.qml b/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals.qml new file mode 100644 index 0000000..d4e8d7e --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconnection/data/connection-unknownsignals.qml @@ -0,0 +1,7 @@ +import Qt 4.7 + +Item { + id: screen + + Connections { objectName: "connections"; target: screen; onFooBar: {} } +} -- cgit v0.12 From 5fc59b64642b8af7b449770bae471a2a72bfa490 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 30 Apr 2010 09:13:10 +1000 Subject: Fix translation context when qsTr is used in PropertyChanges. This should also lead to better error meesages coming from PropertyChanges. Task-number: QTBUG-10300 --- src/declarative/util/qdeclarativepropertychanges.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp index 4b2d5a0..c7e3bc5 100644 --- a/src/declarative/util/qdeclarativepropertychanges.cpp +++ b/src/declarative/util/qdeclarativepropertychanges.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include @@ -302,12 +303,18 @@ void QDeclarativePropertyChangesPrivate::decode() QDeclarativeProperty prop = property(name); //### better way to check for signal property? if (prop.type() & QDeclarativeProperty::SignalProperty) { QDeclarativeExpression *expression = new QDeclarativeExpression(qmlContext(q), data.toString(), object); + QDeclarativeData *ddata = QDeclarativeData::get(q); + if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) + expression->setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); QDeclarativeReplaceSignalHandler *handler = new QDeclarativeReplaceSignalHandler; handler->property = prop; handler->expression = expression; signalReplacements << handler; } else if (isScript) { QDeclarativeExpression *expression = new QDeclarativeExpression(qmlContext(q), data.toString(), object); + QDeclarativeData *ddata = QDeclarativeData::get(q); + if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) + expression->setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); expressions << qMakePair(name, expression); } else { properties << qMakePair(name, data); @@ -437,9 +444,11 @@ QDeclarativePropertyChanges::ActionList QDeclarativePropertyChanges::actions() if (d->isExplicit) { a.toValue = d->expressions.at(ii).second->evaluate(); } else { + QDeclarativeExpression *e = d->expressions.at(ii).second; QDeclarativeBinding *newBinding = - new QDeclarativeBinding(d->expressions.at(ii).second->expression(), object(), qmlContext(this)); + new QDeclarativeBinding(e->expression(), object(), qmlContext(this)); newBinding->setTarget(prop); + newBinding->setSourceLocation(e->sourceFile(), e->lineNumber()); a.toBinding = newBinding; a.deletableToBinding = true; } -- cgit v0.12 From 3ff9ff75f1caf9514dd43fb84826d57f2df91088 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 30 Apr 2010 10:58:58 +1000 Subject: Compile with QT_NO_GRAPHICSEFFECT. --- src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index 2945b6c..7c55009 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -143,7 +143,9 @@ void QDeclarativeItemModule::defineModule() qmlRegisterType(); qmlRegisterType(); qmlRegisterType(); +#ifndef QT_NO_GRAPHICSEFFECT qmlRegisterType(); +#endif qmlRegisterUncreatableType("Qt",4,7,"KeyNavigation",QDeclarativeKeyNavigationAttached::tr("KeyNavigation is only available via attached properties")); qmlRegisterUncreatableType("Qt",4,7,"Keys",QDeclarativeKeysAttached::tr("Keys is only available via attached properties")); -- cgit v0.12 From 62d4b6c36a916291cab91344c5a9fda4c4b2b490 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 30 Apr 2010 11:30:39 +1000 Subject: buffer new items on initialization. We weren't honoring buffer initially, only after a flick. Its better to buffer immediately, since it is often used to eliminate the cost of item creation in small lists. --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 5 +++-- src/declarative/graphicsitems/qdeclarativelistview.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index febd34a..777d6db 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -108,7 +108,7 @@ public: , highlightComponent(0), highlight(0), trackedItem(0) , moveReason(Other), buffer(0), highlightXAnimator(0), highlightYAnimator(0) , highlightMoveDuration(150) - , bufferMode(NoBuffer), snapMode(QDeclarativeGridView::NoSnap) + , bufferMode(BufferBefore | BufferAfter), snapMode(QDeclarativeGridView::NoSnap) , ownModel(false), wrap(false), autoHighlight(true) , fixCurrentVisibility(false), lazyRelease(false), layoutScheduled(false) , deferredRelease(false), haveHighlightRange(false) {} @@ -331,7 +331,7 @@ public: QSmoothedAnimation *highlightYAnimator; int highlightMoveDuration; enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 }; - BufferMode bufferMode; + int bufferMode; QDeclarativeGridView::SnapMode snapMode; bool ownModel : 1; @@ -1029,6 +1029,7 @@ void QDeclarativeGridView::setModel(const QVariant &model) dataModel->setModel(model); } if (d->model) { + d->bufferMode = QDeclarativeGridViewPrivate::BufferBefore | QDeclarativeGridViewPrivate::BufferAfter; if (isComponentComplete()) { refill(); if (d->currentIndex >= d->model->count() || d->currentIndex < 0) { diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 3f150dc..d50e734 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -161,9 +161,9 @@ public: , highlightResizeSpeed(400), highlightResizeDuration(-1), highlightRange(QDeclarativeListView::NoHighlightRange) , snapMode(QDeclarativeListView::NoSnap), overshootDist(0.0) , footerComponent(0), footer(0), headerComponent(0), header(0) - , bufferMode(NoBuffer) + , bufferMode(BufferBefore | BufferAfter) , ownModel(false), wrap(false), autoHighlight(true), haveHighlightRange(false) - , correctFlick(true), inFlickCorrection(false), lazyRelease(false) + , correctFlick(false), inFlickCorrection(false), lazyRelease(false) , deferredRelease(false), layoutScheduled(false), minExtentDirty(true), maxExtentDirty(true) {} @@ -1462,6 +1462,7 @@ void QDeclarativeListView::setModel(const QVariant &model) dataModel->setModel(model); } if (d->model) { + d->bufferMode = QDeclarativeListViewPrivate::BufferBefore | QDeclarativeListViewPrivate::BufferAfter; if (isComponentComplete()) { refill(); if (d->currentIndex >= d->model->count() || d->currentIndex < 0) { -- cgit v0.12 From 1b39890940ce8ea4298a1af16ba220f65f365e7e Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 30 Apr 2010 11:40:06 +1000 Subject: Doc: mention that size of delegate affects flicking performance. --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 5 +++++ src/declarative/graphicsitems/qdeclarativelistview.cpp | 5 +++++ src/declarative/graphicsitems/qdeclarativepathview.cpp | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 777d6db..8fb3632 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1057,6 +1057,11 @@ void QDeclarativeGridView::setModel(const QVariant &model) 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}. + The number of elements in the delegate has a direct effect on the + flicking performance of the view. If at all possible, place functionality + that is not needed for the normal display of the delegate in a \l Loader which + can load additional elements when needed. + Note that the GridView will layout the items based on the size of the root item in the delegate. diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index d50e734..0f3ee61 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1490,6 +1490,11 @@ void QDeclarativeListView::setModel(const QVariant &model) 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}. + The number of elements in the delegate has a direct effect on the + flicking performance of the view. If at all possible, place functionality + that is not needed for the normal display of the delegate in a \l Loader which + can load additional elements when needed. + Note that the ListView will layout the items based on the size of the root item in the delegate. diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index d0a3cd1..911f5a4 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -792,6 +792,11 @@ void QDeclarativePathView::setInteractive(bool interactive) 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}. + The number of elements in the delegate has a direct effect on the + flicking performance of the view when pathItemCount is specified. If at all possible, place functionality + that is not needed for the normal display of the delegate in a \l Loader which + can be created when needed. + Note that the PathView will layout the items based on the size of the root item in the delegate. -- cgit v0.12 From 4cd5bcf2aa093fdc3861cd4e91aa7850f38de158 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 30 Apr 2010 14:03:39 +1000 Subject: Initialize variable. --- src/declarative/util/qdeclarativeconnections.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativeconnections.cpp b/src/declarative/util/qdeclarativeconnections.cpp index c23b623..5dd825e 100644 --- a/src/declarative/util/qdeclarativeconnections.cpp +++ b/src/declarative/util/qdeclarativeconnections.cpp @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE class QDeclarativeConnectionsPrivate : public QObjectPrivate { public: - QDeclarativeConnectionsPrivate() : target(0), ignoreUnknownSignals(false), componentcomplete(false) {} + QDeclarativeConnectionsPrivate() : target(0), targetSet(false), ignoreUnknownSignals(false), componentcomplete(false) {} QList boundsignals; QObject *target; -- cgit v0.12 From 94853c6310bb0f9f3ca08e3c1fa0976ec3d8d285 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Fri, 30 Apr 2010 13:36:29 +1000 Subject: Avoid divisions by zero in qdeclarativetimeline Reviewed-by: Martin Jones --- src/declarative/util/qdeclarativetimeline.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/declarative/util/qdeclarativetimeline.cpp b/src/declarative/util/qdeclarativetimeline.cpp index 656c62b..291b2f3 100644 --- a/src/declarative/util/qdeclarativetimeline.cpp +++ b/src/declarative/util/qdeclarativetimeline.cpp @@ -387,7 +387,10 @@ void QDeclarativeTimeLine::set(QDeclarativeTimeLineValue &timeLineValue, qreal v */ int QDeclarativeTimeLine::accel(QDeclarativeTimeLineValue &timeLineValue, qreal velocity, qreal acceleration) { - if ((velocity > 0.0f) == (acceleration > 0.0f)) + if (acceleration == 0.0f) + return -1; + + if ((velocity > 0.0f) == (acceleration > 0.0f)) acceleration = acceleration * -1.0f; int time = static_cast(-1000 * velocity / acceleration); @@ -410,13 +413,16 @@ int QDeclarativeTimeLine::accel(QDeclarativeTimeLineValue &timeLineValue, qreal */ int QDeclarativeTimeLine::accel(QDeclarativeTimeLineValue &timeLineValue, qreal velocity, qreal acceleration, qreal maxDistance) { - Q_ASSERT(acceleration >= 0.0f && maxDistance >= 0.0f); + if (maxDistance == 0.0f || acceleration == 0.0f) + return -1; + + Q_ASSERT(acceleration > 0.0f && maxDistance > 0.0f); qreal maxAccel = (velocity * velocity) / (2.0f * maxDistance); if (maxAccel > acceleration) acceleration = maxAccel; - if ((velocity > 0.0f) == (acceleration > 0.0f)) + if ((velocity > 0.0f) == (acceleration > 0.0f)) acceleration = acceleration * -1.0f; int time = static_cast(-1000 * velocity / acceleration); @@ -438,6 +444,7 @@ int QDeclarativeTimeLine::accelDistance(QDeclarativeTimeLineValue &timeLineValue { if (distance == 0.0f || velocity == 0.0f) return -1; + Q_ASSERT((distance >= 0.0f) == (velocity >= 0.0f)); int time = static_cast(1000 * (2.0f * distance) / velocity); -- cgit v0.12 From 14b067f85f92194f2c444259e2a70fb095dfb73f Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Fri, 30 Apr 2010 13:53:20 +1000 Subject: Fix assert in qdeclarativepathview Task-number: QTBUG-10327 Reviewed-by: Martin Jones --- src/declarative/graphicsitems/qdeclarativepathview.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 911f5a4..2f963cd 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -966,7 +966,12 @@ void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) else dist = qRound(dist - d->offset) + d->offset; // Calculate accel required to stop on item boundary - accel = v2 / (2.0f * qAbs(dist)); + if (dist <= 0.) { + dist = 0.; + accel = 0.; + } else { + accel = v2 / (2.0f * qAbs(dist)); + } } d->moveOffset.setValue(d->offset); d->tl.accel(d->moveOffset, velocity, accel, dist); -- cgit v0.12 From b57ad033b5fa48efd2e57f17d26f541f1f50dc02 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Fri, 30 Apr 2010 12:47:48 +1000 Subject: Add QML value types for math3d types QVector3D was already supported. Add QVector2D, QVector4D, QQuaternion, and QMatrix4x4. Reviewed-by: Warwick Allison --- src/declarative/qml/qdeclarativevaluetype.cpp | 220 +++++++++++++++++++++ src/declarative/qml/qdeclarativevaluetype_p.h | 147 ++++++++++++++ .../qdeclarativevaluetypes/data/matrix4x4_read.qml | 22 +++ .../data/matrix4x4_write.qml | 21 ++ .../data/quaternion_read.qml | 10 + .../data/quaternion_write.qml | 9 + .../qdeclarativevaluetypes/data/vector2d_read.qml | 8 + .../qdeclarativevaluetypes/data/vector2d_write.qml | 7 + .../qdeclarativevaluetypes/data/vector4d_read.qml | 10 + .../qdeclarativevaluetypes/data/vector4d_write.qml | 9 + .../declarative/qdeclarativevaluetypes/testtypes.h | 30 ++- .../tst_qdeclarativevaluetypes.cpp | 134 +++++++++++++ 12 files changed, 626 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_read.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_write.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_read.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_write.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_read.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_write.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_read.qml create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_write.qml diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index c6fe161..dbc25bb 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -116,8 +116,16 @@ QDeclarativeValueType *QDeclarativeValueTypeFactory::valueType(int t) return new QDeclarativeRectValueType; case QVariant::RectF: return new QDeclarativeRectFValueType; + case QVariant::Vector2D: + return new QDeclarativeVector2DValueType; case QVariant::Vector3D: return new QDeclarativeVector3DValueType; + case QVariant::Vector4D: + return new QDeclarativeVector4DValueType; + case QVariant::Quaternion: + return new QDeclarativeQuaternionValueType; + case QVariant::Matrix4x4: + return new QDeclarativeMatrix4x4ValueType; case QVariant::EasingCurve: return new QDeclarativeEasingValueType; case QVariant::Font: @@ -460,6 +468,54 @@ void QDeclarativeRectValueType::setHeight(int h) rect.setHeight(h); } +QDeclarativeVector2DValueType::QDeclarativeVector2DValueType(QObject *parent) +: QDeclarativeValueType(parent) +{ +} + +void QDeclarativeVector2DValueType::read(QObject *obj, int idx) +{ + void *a[] = { &vector, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QDeclarativeVector2DValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) +{ + int status = -1; + void *a[] = { &vector, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QVariant QDeclarativeVector2DValueType::value() +{ + return QVariant(vector); +} + +void QDeclarativeVector2DValueType::setValue(QVariant value) +{ + vector = qvariant_cast(value); +} + +qreal QDeclarativeVector2DValueType::x() const +{ + return vector.x(); +} + +qreal QDeclarativeVector2DValueType::y() const +{ + return vector.y(); +} + +void QDeclarativeVector2DValueType::setX(qreal x) +{ + vector.setX(x); +} + +void QDeclarativeVector2DValueType::setY(qreal y) +{ + vector.setY(y); +} + QDeclarativeVector3DValueType::QDeclarativeVector3DValueType(QObject *parent) : QDeclarativeValueType(parent) { @@ -518,6 +574,170 @@ void QDeclarativeVector3DValueType::setZ(qreal z) vector.setZ(z); } +QDeclarativeVector4DValueType::QDeclarativeVector4DValueType(QObject *parent) +: QDeclarativeValueType(parent) +{ +} + +void QDeclarativeVector4DValueType::read(QObject *obj, int idx) +{ + void *a[] = { &vector, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QDeclarativeVector4DValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) +{ + int status = -1; + void *a[] = { &vector, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QVariant QDeclarativeVector4DValueType::value() +{ + return QVariant(vector); +} + +void QDeclarativeVector4DValueType::setValue(QVariant value) +{ + vector = qvariant_cast(value); +} + +qreal QDeclarativeVector4DValueType::x() const +{ + return vector.x(); +} + +qreal QDeclarativeVector4DValueType::y() const +{ + return vector.y(); +} + +qreal QDeclarativeVector4DValueType::z() const +{ + return vector.z(); +} + +qreal QDeclarativeVector4DValueType::w() const +{ + return vector.w(); +} + +void QDeclarativeVector4DValueType::setX(qreal x) +{ + vector.setX(x); +} + +void QDeclarativeVector4DValueType::setY(qreal y) +{ + vector.setY(y); +} + +void QDeclarativeVector4DValueType::setZ(qreal z) +{ + vector.setZ(z); +} + +void QDeclarativeVector4DValueType::setW(qreal w) +{ + vector.setW(w); +} + +QDeclarativeQuaternionValueType::QDeclarativeQuaternionValueType(QObject *parent) +: QDeclarativeValueType(parent) +{ +} + +void QDeclarativeQuaternionValueType::read(QObject *obj, int idx) +{ + void *a[] = { &quaternion, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QDeclarativeQuaternionValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) +{ + int status = -1; + void *a[] = { &quaternion, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QVariant QDeclarativeQuaternionValueType::value() +{ + return QVariant(quaternion); +} + +void QDeclarativeQuaternionValueType::setValue(QVariant value) +{ + quaternion = qvariant_cast(value); +} + +qreal QDeclarativeQuaternionValueType::scalar() const +{ + return quaternion.scalar(); +} + +qreal QDeclarativeQuaternionValueType::x() const +{ + return quaternion.x(); +} + +qreal QDeclarativeQuaternionValueType::y() const +{ + return quaternion.y(); +} + +qreal QDeclarativeQuaternionValueType::z() const +{ + return quaternion.z(); +} + +void QDeclarativeQuaternionValueType::setScalar(qreal scalar) +{ + quaternion.setScalar(scalar); +} + +void QDeclarativeQuaternionValueType::setX(qreal x) +{ + quaternion.setX(x); +} + +void QDeclarativeQuaternionValueType::setY(qreal y) +{ + quaternion.setY(y); +} + +void QDeclarativeQuaternionValueType::setZ(qreal z) +{ + quaternion.setZ(z); +} + +QDeclarativeMatrix4x4ValueType::QDeclarativeMatrix4x4ValueType(QObject *parent) +: QDeclarativeValueType(parent) +{ +} + +void QDeclarativeMatrix4x4ValueType::read(QObject *obj, int idx) +{ + void *a[] = { &matrix, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QDeclarativeMatrix4x4ValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) +{ + int status = -1; + void *a[] = { &matrix, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QVariant QDeclarativeMatrix4x4ValueType::value() +{ + return QVariant(matrix); +} + +void QDeclarativeMatrix4x4ValueType::setValue(QVariant value) +{ + matrix = qvariant_cast(value); +} + QDeclarativeEasingValueType::QDeclarativeEasingValueType(QObject *parent) : QDeclarativeValueType(parent) { diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h index d1833bb..476c73d 100644 --- a/src/declarative/qml/qdeclarativevaluetype_p.h +++ b/src/declarative/qml/qdeclarativevaluetype_p.h @@ -60,7 +60,11 @@ #include #include #include +#include #include +#include +#include +#include #include QT_BEGIN_NAMESPACE @@ -241,6 +245,28 @@ private: QRect rect; }; +class Q_AUTOTEST_EXPORT QDeclarativeVector2DValueType : public QDeclarativeValueType +{ + Q_PROPERTY(qreal x READ x WRITE setX) + Q_PROPERTY(qreal y READ y WRITE setY) + Q_OBJECT +public: + QDeclarativeVector2DValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); + virtual QVariant value(); + virtual void setValue(QVariant value); + + qreal x() const; + qreal y() const; + void setX(qreal); + void setY(qreal); + +private: + QVector2D vector; +}; + class Q_AUTOTEST_EXPORT QDeclarativeVector3DValueType : public QDeclarativeValueType { Q_PROPERTY(qreal x READ x WRITE setX) @@ -266,6 +292,127 @@ private: QVector3D vector; }; +class Q_AUTOTEST_EXPORT QDeclarativeVector4DValueType : public QDeclarativeValueType +{ + Q_PROPERTY(qreal x READ x WRITE setX) + Q_PROPERTY(qreal y READ y WRITE setY) + Q_PROPERTY(qreal z READ z WRITE setZ) + Q_PROPERTY(qreal w READ w WRITE setW) + Q_OBJECT +public: + QDeclarativeVector4DValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); + virtual QVariant value(); + virtual void setValue(QVariant value); + + qreal x() const; + qreal y() const; + qreal z() const; + qreal w() const; + void setX(qreal); + void setY(qreal); + void setZ(qreal); + void setW(qreal); + +private: + QVector4D vector; +}; + +class Q_AUTOTEST_EXPORT QDeclarativeQuaternionValueType : public QDeclarativeValueType +{ + Q_PROPERTY(qreal scalar READ scalar WRITE setScalar) + Q_PROPERTY(qreal x READ x WRITE setX) + Q_PROPERTY(qreal y READ y WRITE setY) + Q_PROPERTY(qreal z READ z WRITE setZ) + Q_OBJECT +public: + QDeclarativeQuaternionValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); + virtual QVariant value(); + virtual void setValue(QVariant value); + + qreal scalar() const; + qreal x() const; + qreal y() const; + qreal z() const; + void setScalar(qreal); + void setX(qreal); + void setY(qreal); + void setZ(qreal); + +private: + QQuaternion quaternion; +}; + +class Q_AUTOTEST_EXPORT QDeclarativeMatrix4x4ValueType : public QDeclarativeValueType +{ + Q_PROPERTY(qreal m11 READ m11 WRITE setM11) + Q_PROPERTY(qreal m12 READ m12 WRITE setM12) + Q_PROPERTY(qreal m13 READ m13 WRITE setM13) + Q_PROPERTY(qreal m14 READ m14 WRITE setM14) + Q_PROPERTY(qreal m21 READ m21 WRITE setM21) + Q_PROPERTY(qreal m22 READ m22 WRITE setM22) + Q_PROPERTY(qreal m23 READ m23 WRITE setM23) + Q_PROPERTY(qreal m24 READ m24 WRITE setM24) + Q_PROPERTY(qreal m31 READ m31 WRITE setM31) + Q_PROPERTY(qreal m32 READ m32 WRITE setM32) + Q_PROPERTY(qreal m33 READ m33 WRITE setM33) + Q_PROPERTY(qreal m34 READ m34 WRITE setM34) + Q_PROPERTY(qreal m41 READ m41 WRITE setM41) + Q_PROPERTY(qreal m42 READ m42 WRITE setM42) + Q_PROPERTY(qreal m43 READ m43 WRITE setM43) + Q_PROPERTY(qreal m44 READ m44 WRITE setM44) + Q_OBJECT +public: + QDeclarativeMatrix4x4ValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); + virtual QVariant value(); + virtual void setValue(QVariant value); + + qreal m11() const { return matrix(0, 0); } + qreal m12() const { return matrix(0, 1); } + qreal m13() const { return matrix(0, 2); } + qreal m14() const { return matrix(0, 3); } + qreal m21() const { return matrix(1, 0); } + qreal m22() const { return matrix(1, 1); } + qreal m23() const { return matrix(1, 2); } + qreal m24() const { return matrix(1, 3); } + qreal m31() const { return matrix(2, 0); } + qreal m32() const { return matrix(2, 1); } + qreal m33() const { return matrix(2, 2); } + qreal m34() const { return matrix(2, 3); } + qreal m41() const { return matrix(3, 0); } + qreal m42() const { return matrix(3, 1); } + qreal m43() const { return matrix(3, 2); } + qreal m44() const { return matrix(3, 3); } + + void setM11(qreal value) { matrix(0, 0) = value; } + void setM12(qreal value) { matrix(0, 1) = value; } + void setM13(qreal value) { matrix(0, 2) = value; } + void setM14(qreal value) { matrix(0, 3) = value; } + void setM21(qreal value) { matrix(1, 0) = value; } + void setM22(qreal value) { matrix(1, 1) = value; } + void setM23(qreal value) { matrix(1, 2) = value; } + void setM24(qreal value) { matrix(1, 3) = value; } + void setM31(qreal value) { matrix(2, 0) = value; } + void setM32(qreal value) { matrix(2, 1) = value; } + void setM33(qreal value) { matrix(2, 2) = value; } + void setM34(qreal value) { matrix(2, 3) = value; } + void setM41(qreal value) { matrix(3, 0) = value; } + void setM42(qreal value) { matrix(3, 1) = value; } + void setM43(qreal value) { matrix(3, 2) = value; } + void setM44(qreal value) { matrix(3, 3) = value; } + +private: + QMatrix4x4 matrix; +}; + class Q_AUTOTEST_EXPORT QDeclarativeEasingValueType : public QDeclarativeValueType { Q_OBJECT diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_read.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_read.qml new file mode 100644 index 0000000..6c4a682 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_read.qml @@ -0,0 +1,22 @@ +import Test 1.0 + +MyTypeObject { + property real v_m11: matrix.m11 + property real v_m12: matrix.m12 + property real v_m13: matrix.m13 + property real v_m14: matrix.m14 + property real v_m21: matrix.m21 + property real v_m22: matrix.m22 + property real v_m23: matrix.m23 + property real v_m24: matrix.m24 + property real v_m31: matrix.m31 + property real v_m32: matrix.m32 + property real v_m33: matrix.m33 + property real v_m34: matrix.m34 + property real v_m41: matrix.m41 + property real v_m42: matrix.m42 + property real v_m43: matrix.m43 + property real v_m44: matrix.m44 + property variant copy: matrix +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_write.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_write.qml new file mode 100644 index 0000000..2a9f154 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_write.qml @@ -0,0 +1,21 @@ +import Test 1.0 + +MyTypeObject { + matrix.m11: if (true) 11 + matrix.m12: if (true) 12 + matrix.m13: if (true) 13 + matrix.m14: if (true) 14 + matrix.m21: if (true) 21 + matrix.m22: if (true) 22 + matrix.m23: if (true) 23 + matrix.m24: if (true) 24 + matrix.m31: if (true) 31 + matrix.m32: if (true) 32 + matrix.m33: if (true) 33 + matrix.m34: if (true) 34 + matrix.m41: if (true) 41 + matrix.m42: if (true) 42 + matrix.m43: if (true) 43 + matrix.m44: if (true) 44 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_read.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_read.qml new file mode 100644 index 0000000..d1a21dc --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_read.qml @@ -0,0 +1,10 @@ +import Test 1.0 + +MyTypeObject { + property real v_scalar: quaternion.scalar + property real v_x: quaternion.x + property real v_y: quaternion.y + property real v_z: quaternion.z + property variant copy: quaternion +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_write.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_write.qml new file mode 100644 index 0000000..0c3e5af --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_write.qml @@ -0,0 +1,9 @@ +import Test 1.0 + +MyTypeObject { + quaternion.scalar: if (true) 88.5 + quaternion.x: if (true) -0.3 + quaternion.y: if (true) -12.9 + quaternion.z: if (true) 907.4 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_read.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_read.qml new file mode 100644 index 0000000..fc315f7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_read.qml @@ -0,0 +1,8 @@ +import Test 1.0 + +MyTypeObject { + property real v_x: vector2.x + property real v_y: vector2.y + property variant copy: vector2 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_write.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_write.qml new file mode 100644 index 0000000..f0e35ff --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_write.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyTypeObject { + vector2.x: if (true) -0.3 + vector2.y: if (true) -12.9 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_read.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_read.qml new file mode 100644 index 0000000..f9d5d60 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_read.qml @@ -0,0 +1,10 @@ +import Test 1.0 + +MyTypeObject { + property real v_x: vector4.x + property real v_y: vector4.y + property real v_z: vector4.z + property real v_w: vector4.w + property variant copy: vector4 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_write.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_write.qml new file mode 100644 index 0000000..5486981 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_write.qml @@ -0,0 +1,9 @@ +import Test 1.0 + +MyTypeObject { + vector4.x: if (true) -0.3 + vector4.y: if (true) -12.9 + vector4.z: if (true) 907.4 + vector4.w: if (true) 88.5 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h b/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h index 8a9b981..1da9990 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h +++ b/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h @@ -48,7 +48,11 @@ #include #include #include +#include #include +#include +#include +#include #include #include #include @@ -66,7 +70,11 @@ class MyTypeObject : public QObject Q_PROPERTY(QSize sizereadonly READ size NOTIFY changed) Q_PROPERTY(QRect rect READ rect WRITE setRect NOTIFY changed) Q_PROPERTY(QRectF rectf READ rectf WRITE setRectf NOTIFY changed) + Q_PROPERTY(QVector2D vector2 READ vector2 WRITE setVector2 NOTIFY changed) Q_PROPERTY(QVector3D vector READ vector WRITE setVector NOTIFY changed) + Q_PROPERTY(QVector4D vector4 READ vector4 WRITE setVector4 NOTIFY changed) + Q_PROPERTY(QQuaternion quaternion READ quaternion WRITE setQuaternion NOTIFY changed) + Q_PROPERTY(QMatrix4x4 matrix READ matrix WRITE setMatrix NOTIFY changed) Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed) public: @@ -77,7 +85,11 @@ public: m_sizef(0.1, 100923.2), m_rect(2, 3, 109, 102), m_rectf(103.8, 99.2, 88.1, 77.6), - m_vector(23.88, 3.1, 4.3) + m_vector2(32.88, 1.3), + m_vector(23.88, 3.1, 4.3), + m_vector4(54.2, 23.88, 3.1, 4.3), + m_quaternion(4.3, 54.2, 23.88, 3.1), + m_matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) { m_font.setFamily("Arial"); m_font.setBold(true); @@ -116,10 +128,26 @@ public: QRectF rectf() const { return m_rectf; } void setRectf(const QRectF &v) { m_rectf = v; emit changed(); } + QVector2D m_vector2; + QVector2D vector2() const { return m_vector2; } + void setVector2(const QVector2D &v) { m_vector2 = v; emit changed(); } + QVector3D m_vector; QVector3D vector() const { return m_vector; } void setVector(const QVector3D &v) { m_vector = v; emit changed(); } + QVector4D m_vector4; + QVector4D vector4() const { return m_vector4; } + void setVector4(const QVector4D &v) { m_vector4 = v; emit changed(); } + + QQuaternion m_quaternion; + QQuaternion quaternion() const { return m_quaternion; } + void setQuaternion(const QQuaternion &v) { m_quaternion = v; emit changed(); } + + QMatrix4x4 m_matrix; + QMatrix4x4 matrix() const { return m_matrix; } + void setMatrix(const QMatrix4x4 &v) { m_matrix = v; emit changed(); } + QFont m_font; QFont font() const { return m_font; } void setFont(const QFont &v) { m_font = v; emit changed(); } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index b733b10..c18fbf5 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -62,7 +62,11 @@ private slots: void sizereadonly(); void rect(); void rectf(); + void vector2d(); void vector3d(); + void vector4d(); + void quaternion(); + void matrix4x4(); void font(); void bindingAssignment(); @@ -293,6 +297,31 @@ void tst_qdeclarativevaluetypes::rectf() } } +void tst_qdeclarativevaluetypes::vector2d() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("vector2d_read.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE((float)object->property("v_x").toDouble(), (float)32.88); + QCOMPARE((float)object->property("v_y").toDouble(), (float)1.3); + QCOMPARE(object->property("copy"), QVariant(QVector2D(32.88, 1.3))); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("vector2d_write.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->vector2(), QVector2D(-0.3, -12.9)); + + delete object; + } +} + void tst_qdeclarativevaluetypes::vector3d() { { @@ -319,6 +348,106 @@ void tst_qdeclarativevaluetypes::vector3d() } } +void tst_qdeclarativevaluetypes::vector4d() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("vector4d_read.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE((float)object->property("v_x").toDouble(), (float)54.2); + QCOMPARE((float)object->property("v_y").toDouble(), (float)23.88); + QCOMPARE((float)object->property("v_z").toDouble(), (float)3.1); + QCOMPARE((float)object->property("v_w").toDouble(), (float)4.3); + QCOMPARE(object->property("copy"), QVariant(QVector4D(54.2, 23.88, 3.1, 4.3))); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("vector4d_write.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->vector4(), QVector4D(-0.3, -12.9, 907.4, 88.5)); + + delete object; + } +} + +void tst_qdeclarativevaluetypes::quaternion() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("quaternion_read.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE((float)object->property("v_scalar").toDouble(), (float)4.3); + QCOMPARE((float)object->property("v_x").toDouble(), (float)54.2); + QCOMPARE((float)object->property("v_y").toDouble(), (float)23.88); + QCOMPARE((float)object->property("v_z").toDouble(), (float)3.1); + QCOMPARE(object->property("copy"), QVariant(QQuaternion(4.3, 54.2, 23.88, 3.1))); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("quaternion_write.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->quaternion(), QQuaternion(88.5, -0.3, -12.9, 907.4)); + + delete object; + } +} + +void tst_qdeclarativevaluetypes::matrix4x4() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("matrix4x4_read.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE((float)object->property("v_m11").toDouble(), (float)1); + QCOMPARE((float)object->property("v_m12").toDouble(), (float)2); + QCOMPARE((float)object->property("v_m13").toDouble(), (float)3); + QCOMPARE((float)object->property("v_m14").toDouble(), (float)4); + QCOMPARE((float)object->property("v_m21").toDouble(), (float)5); + QCOMPARE((float)object->property("v_m22").toDouble(), (float)6); + QCOMPARE((float)object->property("v_m23").toDouble(), (float)7); + QCOMPARE((float)object->property("v_m24").toDouble(), (float)8); + QCOMPARE((float)object->property("v_m31").toDouble(), (float)9); + QCOMPARE((float)object->property("v_m32").toDouble(), (float)10); + QCOMPARE((float)object->property("v_m33").toDouble(), (float)11); + QCOMPARE((float)object->property("v_m34").toDouble(), (float)12); + QCOMPARE((float)object->property("v_m41").toDouble(), (float)13); + QCOMPARE((float)object->property("v_m42").toDouble(), (float)14); + QCOMPARE((float)object->property("v_m43").toDouble(), (float)15); + QCOMPARE((float)object->property("v_m44").toDouble(), (float)16); + QCOMPARE(object->property("copy"), + QVariant(QMatrix4x4(1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16))); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("matrix4x4_write.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->matrix(), QMatrix4x4(11, 12, 13, 14, + 21, 22, 23, 24, + 31, 32, 33, 34, + 41, 42, 43, 44)); + + delete object; + } +} + void tst_qdeclarativevaluetypes::font() { { @@ -665,7 +794,12 @@ void tst_qdeclarativevaluetypes::cppClasses() CPP_TEST(QDeclarativeSizeFValueType, QSizeF(-100.7, 18.2)); CPP_TEST(QDeclarativeRectValueType, QRect(13, 39, 10928, 88)); CPP_TEST(QDeclarativeRectFValueType, QRectF(88.2, -90.1, 103.2, 118)); + CPP_TEST(QDeclarativeVector2DValueType, QVector2D(19.7, 1002)); CPP_TEST(QDeclarativeVector3DValueType, QVector3D(18.2, 19.7, 1002)); + CPP_TEST(QDeclarativeVector4DValueType, QVector4D(18.2, 19.7, 1002, 54)); + CPP_TEST(QDeclarativeQuaternionValueType, QQuaternion(18.2, 19.7, 1002, 54)); + CPP_TEST(QDeclarativeMatrix4x4ValueType, + QMatrix4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)); CPP_TEST(QDeclarativeFontValueType, QFont("Helvetica")); } -- cgit v0.12 From e900d3b5c026ede908a5b8623f044fff6421fdeb Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 30 Apr 2010 10:56:57 +1000 Subject: Fix error string --- src/declarative/qml/qdeclarativeobjectscriptclass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 33e47fb..03366f0 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -444,7 +444,7 @@ QScriptValue QDeclarativeObjectScriptClass::destroy(QScriptContext *context, QSc QDeclarativeData *ddata = QDeclarativeData::get(data->object, false); if (!ddata || ddata->indestructible) - return engine->currentContext()->throwError(QLatin1String("Invalid attempt to destroy() an indestructible object")); + return engine->currentContext()->throwError(QLatin1String("Invalid attempt to destroy() an indestructible object")); QObject *obj = data->object; int delay = 0; -- cgit v0.12 From 77cddec6ea642b073d1d9c017c865e740c0c60bc Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 30 Apr 2010 15:26:55 +1000 Subject: Doc fixes --- doc/src/declarative/codingconventions.qdoc | 6 +- doc/src/declarative/dynamicobjects.qdoc | 65 +++++++++++-------- doc/src/declarative/globalobject.qdoc | 76 +++++++++++------------ doc/src/snippets/declarative/componentCreation.js | 48 +++++++------- src/declarative/qml/qdeclarativecomponent.cpp | 6 +- 5 files changed, 106 insertions(+), 95 deletions(-) diff --git a/doc/src/declarative/codingconventions.qdoc b/doc/src/declarative/codingconventions.qdoc index 7ca206b..d0f873d 100644 --- a/doc/src/declarative/codingconventions.qdoc +++ b/doc/src/declarative/codingconventions.qdoc @@ -57,7 +57,7 @@ Through our documentation and examples, QML objects are always structured in the \o id \o property declarations \o signal declarations -\o javascript functions +\o JavaScript functions \o object properties \o child objects \o states @@ -102,7 +102,7 @@ we will write this: \snippet doc/src/snippets/declarative/codingconventions/lists.qml 1 -\section1 Javascript code +\section1 JavaScript code If the script is a single expression, we recommend writing it inline: @@ -116,7 +116,7 @@ If the script is more than a couple of lines long or can be used by different ob \snippet doc/src/snippets/declarative/codingconventions/javascript.qml 2 -For long scripts, we will put the functions in their own javascript file and import it like this: +For long scripts, we will put the functions in their own JavaScript file and import it like this: \snippet doc/src/snippets/declarative/codingconventions/javascript-imports.qml 0 diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc index a2b65a8..c376266 100644 --- a/doc/src/declarative/dynamicobjects.qdoc +++ b/doc/src/declarative/dynamicobjects.qdoc @@ -43,23 +43,25 @@ \page qdeclarativedynamicobjects.html \title Dynamic Object Management -QML has some support for dynamically loading and managing QML objects from -within Javascript blocks. It is preferable to use the existing QML elements for -dynamic object management wherever possible; these are \l{Loader}, -\l{Repeater}, \l{ListView}, \l{GridView} and \l{PathView}. It is also possible -to dynamically create and manage objects from C++, and this is preferable for -hybrid QML/C++ applications - see \l{Using QML in C++ Applications}. -Dynamically creating and managing objects from -within Javascript blocks is intended for when none of the existing QML elements -fit the needs of your application, and you do not desire for your application -to involve C++ code. +QML provides a number of ways to dynamically create and manage QML objects. +The \l{Loader}, \l{Repeater}, \l{ListView}, \l{GridView} and \l{PathView} elements +all support dynamic object management. Objects can also be created and managed +from C++, and this is the preferred method for hybrid QML/C++ applications +(see \l{Using QML in C++ Applications}). + +QML also supports the dynamic creation of objects from within JavaScript +code. This is useful if the existing QML elements do not fit the needs of your +application, and there are no C++ components involved. + \section1 Creating Objects Dynamically -There are two ways of creating objects dynamically. You can either create -a component which instantiates items, or create an item from a string of QML. -Creating a component is better for the situation where you have a predefined -item which you want to manage dynamic instances of, and creating an item from -a string of QML is intended for when the QML itself is generated at runtime. +There are two ways to create objects dynamically from JavaScript. You can either call +\l {Qt.createComponent(url file)}{Qt.createComponent()} to create +a component which instantiates items, or use \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} +to create an item from a string of QML. +Creating a component is better if you have a predefined +item, and you want to create dynamic instances of that item; creating an item from +a string of QML is useful when the item QML itself is generated at runtime. If you have a component specified in a QML file, you can dynamically load it with the \l {Qt.createComponent(url file)}{Qt.createComponent()} function on the \l{QML Global Object}. @@ -69,7 +71,7 @@ a component object which can be used to create and load that QML file. Once you have a component you can use its \c createObject() method to create an instance of the component. -Here is an example. Here is a simple QML component defined in \c Sprite.qml: +Here is an example. Here is a \c Sprite.qml, which defines a simple QML component: \quotefile doc/src/snippets/declarative/Sprite.qml @@ -84,14 +86,10 @@ over the network cannot be expected to be ready immediately: \snippet doc/src/snippets/declarative/componentCreation.js 0 \codeline \snippet doc/src/snippets/declarative/componentCreation.js 1 -\snippet doc/src/snippets/declarative/componentCreation.js 2 -\snippet doc/src/snippets/declarative/componentCreation.js 4 -\codeline -\snippet doc/src/snippets/declarative/componentCreation.js 5 If you are certain the files will be local, you could simplify to: -\snippet doc/src/snippets/declarative/componentCreation.js 3 +\snippet doc/src/snippets/declarative/componentCreation.js 2 Notice that once a \c Sprite object is created, its parent is set to \c appWindow (defined in \c main.qml). After creating an item, you must set its parent to an item within the scene. @@ -114,8 +112,22 @@ item, which is used for error reporting. \section1 Maintaining Dynamically Created Objects -Dynamically created objects may be used the same as other objects, however they -will not have an id in QML. +When managing dynamically created items, you must ensure the creation context +outlives the created item. Otherwise, if the creation context is destroyed first, +the bindings in the dynamic item will no longer work. + +The actual creation context depends on how an item is created: + +\list +\o If \l {Qt.createComponent(url file)}{Qt.createComponent()} is used, the creation context + is the QDeclarativeContext in which this method is called +\o If \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} + if called, it is the context of the item used as the second argument to this method +\o If a \c {Component \{\}} item is defined and \c {Component::}{createObject()} is called, + it is the context in which the \c Component item is defined + +Also, note that while dynamically created objects may be used the same as other objects, they +do not have an id in QML. A restriction which you need to manage with dynamically created items, is that the creation context must outlive the @@ -134,7 +146,7 @@ a worthwhile performance benefit. Note that you should never manually delete items which were dynamically created by QML Elements such as \l{Loader}. To manually delete a QML item, call its destroy method. This method has one -argument, which is an approximate delay in ms and which defaults to zero. This +argument, which is an approximate delay in milliseconds and which defaults to zero. This allows you to wait until the completion of an animation or transition. An example: \code @@ -153,8 +165,9 @@ allows you to wait until the completion of an animation or transition. An exampl object.parent = parentItem; } \endcode -In the above example, the dynamically created rectangle calls destroy as soon as it's created, - but delays long enough for its fade out animation to play. + +In the above example, the dynamically created rectangle calls destroy as soon as it is created, + but delays long enough for its fade out animation to be played. */ diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 85cbde2..47460cf 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -234,58 +234,58 @@ The following functions on the global object allow you to dynamically create QML items from files or strings. See \l{Dynamic Object Management} for an overview of their use. + \section2 Qt.createComponent(url file) - This function takes the URL of a QML file as its only argument. It returns - a component object which can be used to create and load that QML file. - Here is an example. Remember that QML files that might be loaded - over the network cannot be expected to be ready immediately. +This function takes the URL of a QML file as its only argument. It returns +a component object which can be used to create and load that QML file. + +Here is an example. Remember that QML files that might be loaded +over the network cannot be expected to be ready immediately. - \snippet doc/src/snippets/declarative/componentCreation.js 0 - \codeline - \snippet doc/src/snippets/declarative/componentCreation.js 1 - \snippet doc/src/snippets/declarative/componentCreation.js 2 - \snippet doc/src/snippets/declarative/componentCreation.js 4 - \codeline - \snippet doc/src/snippets/declarative/componentCreation.js 5 +\snippet doc/src/snippets/declarative/componentCreation.js 0 +\codeline +\snippet doc/src/snippets/declarative/componentCreation.js 1 - If you are certain the files will be local, you could simplify to: +If you are certain the files will be local, you could simplify to: - \snippet doc/src/snippets/declarative/componentCreation.js 3 +\snippet doc/src/snippets/declarative/componentCreation.js 2 - The methods and properties of the Component element are defined in its own - page, but when using it dynamically only two methods are usually used. - \c Component.createObject() returns the created object or \c null if there is an error. - If there is an error, \l {Component::errorsString()}{Component.errorsString()} describes - the error that occurred. +The methods and properties of the Component element are defined in its own +page, but when using it dynamically only two methods are usually used. +\c Component.createObject() returns the created object or \c null if there is an error. +If there is an error, \l {Component::errorsString()}{Component.errorsString()} describes +the error that occurred. + +If you want to just create an arbitrary string of QML, instead of +loading a QML file, consider the \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} function. - If you want to just create an arbitrary string of QML, instead of - loading a QML file, consider the \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} function. \section2 Qt.createQmlObject(string qml, object parent, string filepath) - Creates a new object from the specified string of QML. It requires a - second argument, which is the id of an existing QML object to use as - the new object's parent. If a third argument is provided, this is used - for error reporting as the filepath that the QML came from. - Example (where \c targetItem is the id of an existing QML item): +Creates a new object from the specified string of QML. It requires a +second argument, which is the id of an existing QML object to use as +the new object's parent. If a third argument is provided, this is used +for error reporting as the filepath that the QML came from. + +Example (where \c targetItem is the id of an existing QML item): - \snippet doc/src/snippets/declarative/createQmlObject.qml 0 +\snippet doc/src/snippets/declarative/createQmlObject.qml 0 - This function is intended for use inside QML only. It is intended to behave - similarly to eval, but for creating QML elements. +This function is intended for use inside QML only. It is intended to behave +similarly to eval, but for creating QML elements. - Returns the created object, \c or null if there is an error. In the case of an - error, a QtScript Error object is thrown. This object has the additional property, - qmlErrors, which is an array of all the errors encountered when trying to execute the - QML. Each object in the array has the members \c lineNumber, \c columnNumber, \c fileName and \c message. +Returns the created object, \c or null if there is an error. In the case of an +error, a QtScript Error object is thrown. This object has the additional property, +qmlErrors, which is an array of all the errors encountered when trying to execute the +QML. Each object in the array has the members \c lineNumber, \c columnNumber, \c fileName and \c message. - Note that this function returns immediately, and therefore may not work if - the QML loads new components. If you are trying to load a new component, - for example from a QML file, consider the \l{Qt.createComponent(url file)}{Qt.createComponent()} function - instead. 'New components' refers to external QML files that have not yet - been loaded, and so it is safe to use \c Qt.createQmlObject() to load built-in - components. +Note that this function returns immediately, and therefore may not work if +the QML loads new components. If you are trying to load a new component, +for example from a QML file, consider the \l{Qt.createComponent(url file)}{Qt.createComponent()} function +instead. 'New components' refers to external QML files that have not yet +been loaded, and so it is safe to use \c Qt.createQmlObject() to load built-in +components. \section1 XMLHttpRequest diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js index 814545e..be928f0 100644 --- a/doc/src/snippets/declarative/componentCreation.js +++ b/doc/src/snippets/declarative/componentCreation.js @@ -20,38 +20,32 @@ function finishCreation() { } //![0] -//![1] function createSpriteObjects() { -//![1] - - //![2] - component = Qt.createComponent("Sprite.qml"); - if (component.status == Component.Ready) - finishCreation(); - else - component.statusChanged.connect(finishCreation); - //![2] - //![3] - component = Qt.createComponent("Sprite.qml"); - sprite = component.createObject(); +//![1] +component = Qt.createComponent("Sprite.qml"); +if (component.status == Component.Ready) + finishCreation(); +else + component.statusChanged.connect(finishCreation); +//![1] - if (sprite == null) { - // Error Handling - console.log("Error loading component:", component.errorsString()); - } else { - sprite.parent = appWindow; - sprite.x = 100; - sprite.y = 100; - // ... - } - //![3] +//![2] +component = Qt.createComponent("Sprite.qml"); +sprite = component.createObject(); + +if (sprite == null) { + // Error Handling + console.log("Error loading component:", component.errorsString()); +} else { + sprite.parent = appWindow; + sprite.x = 100; + sprite.y = 100; + // ... +} +//![2] -//![4] } -//![4] -//![5] createSpriteObjects(); -//![5] diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 6ebf470..3ca0707 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -547,7 +547,11 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q \qmlmethod object Component::createObject() Returns an object instance from this component, or null if object creation fails. - The object will be created in the same context as the component was created in. + The object will be created in the same context as the one in which the component + was created. + + Note that if the returned object is to be displayed, its \c parent must be set to + an existing item in a scene, or else the object will not be visible. */ /*! -- cgit v0.12 From 85db980578cb9f1b95be160a4386d9822c6ec6d0 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 30 Apr 2010 15:32:43 +1000 Subject: Make QDeclarativeParserStatus method pure virtual to encourage right code. Fix all code to be right, except multimedia. Currently, it's not *required* that types work without componentComplete, so not vital. --- src/declarative/qml/qdeclarativeparserstatus.cpp | 10 +++----- src/declarative/qml/qdeclarativeparserstatus.h | 4 +-- src/declarative/qml/qdeclarativeworkerscript.cpp | 29 ++++++++++++++++------ src/declarative/qml/qdeclarativeworkerscript_p.h | 3 +++ src/declarative/util/qdeclarativebind.cpp | 8 +++++- src/declarative/util/qdeclarativebind_p.h | 1 + src/declarative/util/qdeclarativeconnections.cpp | 8 +++++- src/declarative/util/qdeclarativeconnections_p.h | 1 + src/imports/multimedia/qdeclarativeaudio.cpp | 7 +++++- src/imports/multimedia/qdeclarativeaudio_p.h | 1 + .../declarative/qdeclarativelanguage/testtypes.h | 4 +-- .../tst_qdeclarativemetatype.cpp | 3 +++ tools/qml/qdeclarativefolderlistmodel.cpp | 4 +++ tools/qml/qdeclarativefolderlistmodel.h | 1 + 14 files changed, 64 insertions(+), 20 deletions(-) diff --git a/src/declarative/qml/qdeclarativeparserstatus.cpp b/src/declarative/qml/qdeclarativeparserstatus.cpp index 978bfb4..4c4e429 100644 --- a/src/declarative/qml/qdeclarativeparserstatus.cpp +++ b/src/declarative/qml/qdeclarativeparserstatus.cpp @@ -91,19 +91,17 @@ QDeclarativeParserStatus::~QDeclarativeParserStatus() } /*! + \fn void QDeclarativeParserStatus::classBegin() + Invoked after class creation, but before any properties have been set. */ -void QDeclarativeParserStatus::classBegin() -{ -} /*! + \fn void QDeclarativeParserStatus::componentComplete() + Invoked after the root component that caused this instantiation has completed construction. At this point all static values and binding values have been assigned to the class. */ -void QDeclarativeParserStatus::componentComplete() -{ -} QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeparserstatus.h b/src/declarative/qml/qdeclarativeparserstatus.h index 34528c1..60d423e 100644 --- a/src/declarative/qml/qdeclarativeparserstatus.h +++ b/src/declarative/qml/qdeclarativeparserstatus.h @@ -56,8 +56,8 @@ public: QDeclarativeParserStatus(); virtual ~QDeclarativeParserStatus(); - virtual void classBegin(); - virtual void componentComplete(); + virtual void classBegin()=0; + virtual void componentComplete()=0; private: friend class QDeclarativeVME; diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp index 138d979..c55998f 100644 --- a/src/declarative/qml/qdeclarativeworkerscript.cpp +++ b/src/declarative/qml/qdeclarativeworkerscript.cpp @@ -538,7 +538,7 @@ void QDeclarativeWorkerScriptEngine::run() by the \tt onMessage() handler of \tt myWorker. */ QDeclarativeWorkerScript::QDeclarativeWorkerScript(QObject *parent) -: QObject(parent), m_engine(0), m_scriptId(-1) +: QObject(parent), m_engine(0), m_scriptId(-1), m_componentComplete(true) { } @@ -565,7 +565,7 @@ void QDeclarativeWorkerScript::setSource(const QUrl &source) m_source = source; - if (m_engine) + if (engine()) m_engine->executeUrl(m_scriptId, m_source); emit sourceChanged(); @@ -580,7 +580,7 @@ void QDeclarativeWorkerScript::setSource(const QUrl &source) */ void QDeclarativeWorkerScript::sendMessage(const QScriptValue &message) { - if (!m_engine) { + if (!engine()) { qWarning("QDeclarativeWorkerScript: Attempt to send message before WorkerScript establishment"); return; } @@ -588,13 +588,19 @@ void QDeclarativeWorkerScript::sendMessage(const QScriptValue &message) m_engine->sendMessage(m_scriptId, QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(message)); } -void QDeclarativeWorkerScript::componentComplete() +void QDeclarativeWorkerScript::classBegin() { - if (!m_engine) { + m_componentComplete = false; +} + +QDeclarativeWorkerScriptEngine *QDeclarativeWorkerScript::engine() +{ + if (m_engine) return m_engine; + if (m_componentComplete) { QDeclarativeEngine *engine = qmlEngine(this); if (!engine) { - qWarning("QDeclarativeWorkerScript: componentComplete() called without qmlEngine() set"); - return; + qWarning("QDeclarativeWorkerScript: engine() called without qmlEngine() set"); + return 0; } m_engine = QDeclarativeEnginePrivate::get(engine)->getWorkerScriptEngine(); @@ -602,7 +608,16 @@ void QDeclarativeWorkerScript::componentComplete() if (m_source.isValid()) m_engine->executeUrl(m_scriptId, m_source); + + return m_engine; } + return 0; +} + +void QDeclarativeWorkerScript::componentComplete() +{ + m_componentComplete = true; + engine(); // Get it started now. } /*! diff --git a/src/declarative/qml/qdeclarativeworkerscript_p.h b/src/declarative/qml/qdeclarativeworkerscript_p.h index 6cce799..80ef5f3 100644 --- a/src/declarative/qml/qdeclarativeworkerscript_p.h +++ b/src/declarative/qml/qdeclarativeworkerscript_p.h @@ -108,13 +108,16 @@ signals: void message(const QScriptValue &messageObject); protected: + virtual void classBegin(); virtual void componentComplete(); virtual bool event(QEvent *); private: + QDeclarativeWorkerScriptEngine *engine(); QDeclarativeWorkerScriptEngine *m_engine; int m_scriptId; QUrl m_source; + bool m_componentComplete; }; QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativebind.cpp b/src/declarative/util/qdeclarativebind.cpp index 5516628..1f528e8 100644 --- a/src/declarative/util/qdeclarativebind.cpp +++ b/src/declarative/util/qdeclarativebind.cpp @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE class QDeclarativeBindPrivate : public QObjectPrivate { public: - QDeclarativeBindPrivate() : when(true), componentComplete(false), obj(0) {} + QDeclarativeBindPrivate() : when(true), componentComplete(true), obj(0) {} bool when : 1; bool componentComplete : 1; @@ -198,6 +198,12 @@ void QDeclarativeBind::setValue(const QVariant &v) eval(); } +void QDeclarativeBind::classBegin() +{ + Q_D(QDeclarativeBind); + d->componentComplete = false; +} + void QDeclarativeBind::componentComplete() { Q_D(QDeclarativeBind); diff --git a/src/declarative/util/qdeclarativebind_p.h b/src/declarative/util/qdeclarativebind_p.h index f756e80..f89c2eb 100644 --- a/src/declarative/util/qdeclarativebind_p.h +++ b/src/declarative/util/qdeclarativebind_p.h @@ -80,6 +80,7 @@ public: void setValue(const QVariant &); protected: + virtual void classBegin(); virtual void componentComplete(); private: diff --git a/src/declarative/util/qdeclarativeconnections.cpp b/src/declarative/util/qdeclarativeconnections.cpp index 5dd825e..ffa160f 100644 --- a/src/declarative/util/qdeclarativeconnections.cpp +++ b/src/declarative/util/qdeclarativeconnections.cpp @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE class QDeclarativeConnectionsPrivate : public QObjectPrivate { public: - QDeclarativeConnectionsPrivate() : target(0), targetSet(false), ignoreUnknownSignals(false), componentcomplete(false) {} + QDeclarativeConnectionsPrivate() : target(0), targetSet(false), ignoreUnknownSignals(false), componentcomplete(true) {} QList boundsignals; QObject *target; @@ -271,6 +271,12 @@ void QDeclarativeConnections::connectSignals() } } +void QDeclarativeConnections::classBegin() +{ + Q_D(QDeclarativeConnections); + d->componentcomplete=false; +} + void QDeclarativeConnections::componentComplete() { Q_D(QDeclarativeConnections); diff --git a/src/declarative/util/qdeclarativeconnections_p.h b/src/declarative/util/qdeclarativeconnections_p.h index b51899e..a914166 100644 --- a/src/declarative/util/qdeclarativeconnections_p.h +++ b/src/declarative/util/qdeclarativeconnections_p.h @@ -82,6 +82,7 @@ Q_SIGNALS: private: void connectSignals(); + void classBegin(); void componentComplete(); }; diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp index 896f9b7..3c35bc1 100644 --- a/src/imports/multimedia/qdeclarativeaudio.cpp +++ b/src/imports/multimedia/qdeclarativeaudio.cpp @@ -316,9 +316,14 @@ QDeclarativeAudio::Error QDeclarativeAudio::error() const return Error(m_error); } +void QDeclarativeAudio::classBegin() +{ +} + void QDeclarativeAudio::componentComplete() { - setObject(this); + if (m_playerControl == 0) + setObject(this); } diff --git a/src/imports/multimedia/qdeclarativeaudio_p.h b/src/imports/multimedia/qdeclarativeaudio_p.h index 24276ea..e960b9d 100644 --- a/src/imports/multimedia/qdeclarativeaudio_p.h +++ b/src/imports/multimedia/qdeclarativeaudio_p.h @@ -115,6 +115,7 @@ public: Status status() const; Error error() const; + void classBegin(); void componentComplete(); public Q_SLOTS: diff --git a/tests/auto/declarative/qdeclarativelanguage/testtypes.h b/tests/auto/declarative/qdeclarativelanguage/testtypes.h index 89f99c8..acbe219 100644 --- a/tests/auto/declarative/qdeclarativelanguage/testtypes.h +++ b/tests/auto/declarative/qdeclarativelanguage/testtypes.h @@ -99,7 +99,7 @@ private: int m_value2; }; -class MyQmlObject : public QObject, public MyInterface, public QDeclarativeParserStatus +class MyQmlObject : public QObject, public MyInterface { Q_OBJECT Q_PROPERTY(int value READ value WRITE setValue FINAL) @@ -113,7 +113,7 @@ class MyQmlObject : public QObject, public MyInterface, public QDeclarativeParse Q_PROPERTY(MyQmlObject *qmlobjectProperty READ qmlobject WRITE setQmlobject) Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) - Q_INTERFACES(MyInterface QDeclarativeParserStatus) + Q_INTERFACES(MyInterface) public: MyQmlObject() : m_value(-1), m_interface(0), m_qmlobject(0) { qRegisterMetaType("MyCustomVariantType"); } diff --git a/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp b/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp index 36efe13..76e86c9 100644 --- a/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp +++ b/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp @@ -88,7 +88,10 @@ QML_DECLARE_TYPE(TestType); class ParserStatusTestType : public QObject, public QDeclarativeParserStatus { Q_OBJECT + void classBegin(){} + void componentComplete(){} Q_CLASSINFO("DefaultProperty", "foo") // Missing default property + Q_INTERFACES(QDeclarativeParserStatus) }; QML_DECLARE_TYPE(ParserStatusTestType); diff --git a/tools/qml/qdeclarativefolderlistmodel.cpp b/tools/qml/qdeclarativefolderlistmodel.cpp index 2ac71ad..7ac25d6 100644 --- a/tools/qml/qdeclarativefolderlistmodel.cpp +++ b/tools/qml/qdeclarativefolderlistmodel.cpp @@ -256,6 +256,10 @@ void QDeclarativeFolderListModel::setNameFilters(const QStringList &filters) d->model.setNameFilters(d->nameFilters); } +void QDeclarativeFolderListModel::classBegin() +{ +} + void QDeclarativeFolderListModel::componentComplete() { if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile())) diff --git a/tools/qml/qdeclarativefolderlistmodel.h b/tools/qml/qdeclarativefolderlistmodel.h index 57b7fe5..1ecc784 100644 --- a/tools/qml/qdeclarativefolderlistmodel.h +++ b/tools/qml/qdeclarativefolderlistmodel.h @@ -87,6 +87,7 @@ public: QStringList nameFilters() const; void setNameFilters(const QStringList &filters); + virtual void classBegin(); virtual void componentComplete(); Q_INVOKABLE bool isFolder(int index) const; -- cgit v0.12 From e4b865ef512e338cf495226dc98540f45fba1d9f Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 30 Apr 2010 15:42:02 +1000 Subject: More doc fixes --- doc/src/declarative/dynamicobjects.qdoc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc index c376266..5cdd768 100644 --- a/doc/src/declarative/dynamicobjects.qdoc +++ b/doc/src/declarative/dynamicobjects.qdoc @@ -68,7 +68,7 @@ the \l {Qt.createComponent(url file)}{Qt.createComponent()} function on the \l{Q This function takes the URL of the QML file as its only argument and returns a component object which can be used to create and load that QML file. -Once you have a component you can use its \c createObject() method to create an instance of +Once you have a component you can use its \l {Component::createObject()}{createObject()} method to create an instance of the component. Here is an example. Here is a \c Sprite.qml, which defines a simple QML component: @@ -123,19 +123,13 @@ The actual creation context depends on how an item is created: is the QDeclarativeContext in which this method is called \o If \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} if called, it is the context of the item used as the second argument to this method -\o If a \c {Component \{\}} item is defined and \c {Component::}{createObject()} is called, - it is the context in which the \c Component item is defined +\o If a \c {Component{}} item is defined and \l {Component::createObject()}{createObject()} + is called on that item, it is the context in which the \c Component is defined +\endlist Also, note that while dynamically created objects may be used the same as other objects, they do not have an id in QML. -A restriction which you need to manage with dynamically created items, -is that the creation context must outlive the -created item. The creation context is the QDeclarativeContext in which \c Qt.createComponent() -was called, or the context in which the Component element, or the item used as the -second argument to \c Qt.createQmlObject(), was specified. If the creation -context is destroyed before the dynamic item is, then bindings in the dynamic item will -fail to work. \section1 Deleting Objects Dynamically You should generally avoid dynamically deleting objects that you did not -- cgit v0.12 From deb92c796c727c6ad0eaf28929cda6d000c1b3c1 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 30 Apr 2010 15:48:13 +1000 Subject: Fix assignment of value types to javascript var. Make sure the scriptclass is used. Task-number: QTBUG-10329 Reviewed-by: Aaron Kennedy --- src/declarative/qml/qdeclarativeengine.cpp | 8 ++++---- .../qdeclarativevaluetypes/data/varAssignment.qml | 14 ++++++++++++++ .../qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 3f4a735..4d23e8f 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1075,7 +1075,7 @@ QScriptValue QDeclarativeEnginePrivate::vector(QScriptContext *ctxt, QScriptEngi qsreal x = ctxt->argument(0).toNumber(); qsreal y = ctxt->argument(1).toNumber(); qsreal z = ctxt->argument(2).toNumber(); - return engine->newVariant(qVariantFromValue(QVector3D(x, y, z))); + return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QVector3D(x, y, z))); } QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptEngine*engine) @@ -1198,7 +1198,7 @@ QScriptValue QDeclarativeEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine if (w < 0 || h < 0) return engine->nullValue(); - return qScriptValueFromValue(engine, qVariantFromValue(QRectF(x, y, w, h))); + return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QRectF(x, y, w, h))); } QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine) @@ -1207,7 +1207,7 @@ QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngin return ctxt->throwError("Qt.point(): Invalid arguments"); qsreal x = ctxt->argument(0).toNumber(); qsreal y = ctxt->argument(1).toNumber(); - return qScriptValueFromValue(engine, qVariantFromValue(QPointF(x, y))); + return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QPointF(x, y))); } QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine) @@ -1216,7 +1216,7 @@ QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine return ctxt->throwError("Qt.size(): Invalid arguments"); qsreal w = ctxt->argument(0).toNumber(); qsreal h = ctxt->argument(1).toNumber(); - return qScriptValueFromValue(engine, qVariantFromValue(QSizeF(w, h))); + return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QSizeF(w, h))); } QScriptValue QDeclarativeEnginePrivate::lighter(QScriptContext *ctxt, QScriptEngine *engine) diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml new file mode 100644 index 0000000..e4715ab --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/varAssignment.qml @@ -0,0 +1,14 @@ +import Qt 4.7 + +QtObject { + property int x; + property int y; + property int z; + + Component.onCompleted: { + var vec3 = Qt.vector3d(1, 2, 3); + x = vec3.x; + y = vec3.y; + z = vec3.z; + } +} diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index c18fbf5..95b9baa 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -84,6 +84,7 @@ private slots: void enums(); void conflictingBindings(); void returnValues(); + void varAssignment(); private: QDeclarativeEngine engine; @@ -911,6 +912,19 @@ void tst_qdeclarativevaluetypes::returnValues() delete object; } +void tst_qdeclarativevaluetypes::varAssignment() +{ + QDeclarativeComponent component(&engine, TEST_FILE("varAssignment.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("x").toInt(), 1); + QCOMPARE(object->property("y").toInt(), 2); + QCOMPARE(object->property("z").toInt(), 3); + + delete object; +} + QTEST_MAIN(tst_qdeclarativevaluetypes) #include "tst_qdeclarativevaluetypes.moc" -- cgit v0.12 From 7b9d8b6b98378cb69b4276f4bc49331556a394c0 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 30 Apr 2010 16:13:07 +1000 Subject: When a model delegate is released, remove it from the scene immediately. Task-number: QTBUG-10289 --- src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 43cafe3..2addc77 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -55,6 +55,7 @@ #include #include +#include #include #include #include @@ -966,10 +967,8 @@ QDeclarativeVisualDataModel::ReleaseFlags QDeclarativeVisualDataModel::release(Q if (inPackage) { emit destroyingPackage(qobject_cast(obj)); } else { - if (item->hasFocus()) - item->clearFocus(); - item->setOpacity(0.0); - static_cast(item)->setParentItem(0); + if (item->scene()) + item->scene()->removeItem(item); } stat |= Destroyed; obj->deleteLater(); -- cgit v0.12 From 4a2c238a6dfbbdf3bd27a91efc96b747944e767a Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 30 Apr 2010 16:13:30 +1000 Subject: Avoid regenerating PathView delegates needlessly --- src/declarative/graphicsitems/qdeclarativepathview.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 911f5a4..b35d30d 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -795,7 +795,7 @@ void QDeclarativePathView::setInteractive(bool interactive) The number of elements in the delegate has a direct effect on the flicking performance of the view when pathItemCount is specified. If at all possible, place functionality that is not needed for the normal display of the delegate in a \l Loader which - can be created when needed. + can load additional elements when needed. Note that the PathView will layout the items based on the size of the root item in the delegate. @@ -1051,7 +1051,11 @@ void QDeclarativePathView::componentComplete() Q_D(QDeclarativePathView); QDeclarativeItem::componentComplete(); d->createHighlight(); - d->regenerate(); + // It is possible that a refill has already happended to to Path + // bindings being handled in the componentComplete(). If so + // don't do it again. + if (d->items.count() == 0) + d->regenerate(); d->updateHighlight(); } -- cgit v0.12 From 980e3f143505639ec8f1a8cc4d0ca2bbe59e69c7 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 30 Apr 2010 16:28:37 +1000 Subject: Add Qt.fontFamilies() method QTBUG-10239 --- doc/src/declarative/globalobject.qdoc | 3 +++ src/declarative/qml/qdeclarativeengine.cpp | 12 ++++++++++++ src/declarative/qml/qdeclarativeengine_p.h | 1 + .../declarative/qdeclarativeqt/data/fontFamilies.qml | 6 ++++++ .../declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 47460cf..7c27ae4 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -226,6 +226,9 @@ This function causes the QML engine to emit the quit signal, which in This function returns \c url resolved relative to the URL of the caller. +\section3 Qt.fontFamilies() +This function returns a list of the font families available to the application. + \section3 Qt.isQtObject(object) Returns true if \c object is a valid reference to a Qt or QML object, otherwise false. diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 4d23e8f..dee5ec6 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -82,6 +82,7 @@ #include #include #include +#include #include #include #include @@ -225,6 +226,7 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr //misc methods qtObject.setProperty(QLatin1String("openUrlExternally"),newFunction(QDeclarativeEnginePrivate::desktopOpenUrl, 1)); + qtObject.setProperty(QLatin1String("fontFamilies"),newFunction(QDeclarativeEnginePrivate::fontFamilies, 0)); qtObject.setProperty(QLatin1String("md5"),newFunction(QDeclarativeEnginePrivate::md5, 1)); qtObject.setProperty(QLatin1String("btoa"),newFunction(QDeclarativeEnginePrivate::btoa, 1)); qtObject.setProperty(QLatin1String("atob"),newFunction(QDeclarativeEnginePrivate::atob, 1)); @@ -1274,6 +1276,16 @@ QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QSc return QScriptValue(e, ret); } +QScriptValue QDeclarativeEnginePrivate::fontFamilies(QScriptContext *ctxt, QScriptEngine *e) +{ + if(ctxt->argumentCount() != 0) + return ctxt->throwError("Qt.fontFamilies(): Invalid arguments"); + + QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(e); + QFontDatabase database; + return p->scriptValueFromVariant(database.families()); +} + QScriptValue QDeclarativeEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *) { if (ctxt->argumentCount() != 1) diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 45656e8..531ac97 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -294,6 +294,7 @@ public: static QScriptValue tint(QScriptContext*, QScriptEngine*); static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*); + static QScriptValue fontFamilies(QScriptContext*, QScriptEngine*); static QScriptValue md5(QScriptContext*, QScriptEngine*); static QScriptValue btoa(QScriptContext*, QScriptEngine*); static QScriptValue atob(QScriptContext*, QScriptEngine*); diff --git a/tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml b/tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml new file mode 100644 index 0000000..e66c7be --- /dev/null +++ b/tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml @@ -0,0 +1,6 @@ +import Qt 4.7 + +QtObject { + property variant test1: Qt.fontFamilies(10) + property variant test2: Qt.fontFamilies(); +} diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index 17b7925..5095be8 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,7 @@ private slots: void isQtObject(); void btoa(); void atob(); + void fontFamilies(); private: QDeclarativeEngine engine; @@ -483,6 +485,22 @@ void tst_qdeclarativeqt::atob() delete object; } +void tst_qdeclarativeqt::fontFamilies() +{ + QDeclarativeComponent component(&engine, TEST_FILE("fontFamilies.qml")); + + QString warning1 = component.url().toString() + ":4: Error: Qt.fontFamilies(): Invalid arguments"; + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QFontDatabase database; + QCOMPARE(object->property("test2"), QVariant::fromValue(database.families())); + + delete object; +} + QTEST_MAIN(tst_qdeclarativeqt) #include "tst_qdeclarativeqt.moc" -- cgit v0.12 From 5d34515465d143d08d198b799489f472741a340f Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 30 Apr 2010 17:19:00 +1000 Subject: Add availableFonts.qml for fonts examples. --- examples/declarative/fonts/availableFonts.qml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 examples/declarative/fonts/availableFonts.qml diff --git a/examples/declarative/fonts/availableFonts.qml b/examples/declarative/fonts/availableFonts.qml new file mode 100644 index 0000000..defa4ce --- /dev/null +++ b/examples/declarative/fonts/availableFonts.qml @@ -0,0 +1,17 @@ +import Qt 4.7 + +Rectangle { + width: 480; height: 640; color: "steelblue" + + ListView { + anchors.fill: parent; model: Qt.fontFamilies() + + delegate: Item { + height: 40; width: ListView.view.width + Text { + anchors.centerIn: parent + text: modelData; font.family: modelData; font.pixelSize: 24; color: "white" + } + } + } +} -- cgit v0.12 From b742568492c56aee9445a1fbf3e90e9ef3cb5823 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 30 Apr 2010 17:27:47 +1000 Subject: Ensure eval and Function are in the correct scope QTBUG-10236 --- .../qml/qdeclarativeglobalscriptclass.cpp | 20 ++++++++++---- .../qdeclarativeecmascript/data/eval.qml | 23 ++++++++++++++++ .../qdeclarativeecmascript/data/function.qml | 19 +++++++++++++ .../tst_qdeclarativeecmascript.cpp | 31 ++++++++++++++++++++++ 4 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/eval.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/function.qml diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp index fc802b4..6e107fb 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp @@ -53,19 +53,29 @@ QT_BEGIN_NAMESPACE QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engine) : QScriptClass(engine) { + QString eval = QLatin1String("eval"); + QScriptValue globalObject = engine->globalObject(); + m_globalObject = engine->newObject(); + QScriptValue newGlobalObject = engine->newObject(); QScriptValueIterator iter(globalObject); + while (iter.hasNext()) { iter.next(); - m_globalObject.setProperty(iter.scriptName(), iter.value()); - m_illegalNames.insert(iter.name()); + + QString name = iter.name(); + + if (name != eval) + m_globalObject.setProperty(iter.scriptName(), iter.value()); + newGlobalObject.setProperty(iter.scriptName(), iter.value()); + + m_illegalNames.insert(name); } - QScriptValue v = engine->newObject(); - v.setScriptClass(this); - engine->setGlobalObject(v); + newGlobalObject.setScriptClass(this); + engine->setGlobalObject(newGlobalObject); } QScriptClass::QueryFlags diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml b/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml new file mode 100644 index 0000000..bc2df98 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml @@ -0,0 +1,23 @@ +import Qt 4.7 + +QtObject { + property bool test1: false; + property bool test2: false; + property bool test3: false; + property bool test4: false; + property bool test5: false; + + + property int a: 7 + property int b: 8 + + Component.onCompleted: { + var b = 9; + + test1 = (eval("a") == 7); + test2 = (eval("b") == 9); + test3 = (eval("c") == undefined); + test4 = (eval("console") == console); + test5 = (eval("Qt") == Qt); + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/function.qml b/tests/auto/declarative/qdeclarativeecmascript/data/function.qml new file mode 100644 index 0000000..b435f58 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/function.qml @@ -0,0 +1,19 @@ +import Qt 4.7 + +QtObject { + property bool test1: false; + property bool test2: false; + property bool test3: false; + + Component.onCompleted: { + var a = 10; + + var func1 = new Function("a", "return a + 7"); + var func2 = new Function("a", "return Qt.atob(a)"); + var func3 = new Function("return a"); + + test1 = (func1(4) == 11); + test2 = (func2("Hello World!") == Qt.atob("Hello World!")); + test3 = (func3() == undefined); + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 49ee335..6d39be2 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -146,6 +146,8 @@ private slots: void noSpuriousWarningsAtShutdown(); void canAssignNullToQObject(); void functionAssignment(); + void eval(); + void function(); void callQtInvokables(); private: @@ -2329,6 +2331,35 @@ void tst_qdeclarativeecmascript::functionAssignment() } } +void tst_qdeclarativeecmascript::eval() +{ + QDeclarativeComponent component(&engine, TEST_FILE("eval.qml")); + + QObject *o = component.create(); + QVERIFY(o != 0); + + QCOMPARE(o->property("test1").toBool(), true); + QCOMPARE(o->property("test2").toBool(), true); + QCOMPARE(o->property("test3").toBool(), true); + QCOMPARE(o->property("test4").toBool(), true); + QCOMPARE(o->property("test5").toBool(), true); + + delete o; +} + +void tst_qdeclarativeecmascript::function() +{ + QDeclarativeComponent component(&engine, TEST_FILE("function.qml")); + + QObject *o = component.create(); + QVERIFY(o != 0); + + QCOMPARE(o->property("test1").toBool(), true); + QCOMPARE(o->property("test2").toBool(), true); + QCOMPARE(o->property("test3").toBool(), true); + + delete o; +} QTEST_MAIN(tst_qdeclarativeecmascript) -- cgit v0.12 From 29cad9b72fb96b3e66bcbbc0d4db28fe26842598 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 30 Apr 2010 18:03:30 +1000 Subject: Don't create an anchors element so that we can check that there aren't any --- .../graphicsitems/qdeclarativepositioners.cpp | 48 ++++++++++++++-------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 3f1d2ac..c1ef04d 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -443,12 +443,15 @@ void QDeclarativeColumn::reportConflictingAnchors() for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); if (child.item) { - QDeclarativeAnchors::Anchors usedAnchors = QDeclarativeItemPrivate::get(child.item)->anchors()->usedAnchors(); - if (usedAnchors & QDeclarativeAnchors::TopAnchor || - usedAnchors & QDeclarativeAnchors::BottomAnchor || - usedAnchors & QDeclarativeAnchors::VCenterAnchor) { - childsWithConflictingAnchors = true; - break; + QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; + if (anchors) { + QDeclarativeAnchors::Anchors usedAnchors = anchors->usedAnchors(); + if (usedAnchors & QDeclarativeAnchors::TopAnchor || + usedAnchors & QDeclarativeAnchors::BottomAnchor || + usedAnchors & QDeclarativeAnchors::VCenterAnchor) { + childsWithConflictingAnchors = true; + break; + } } } } @@ -578,12 +581,15 @@ void QDeclarativeRow::reportConflictingAnchors() for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); if (child.item) { - QDeclarativeAnchors::Anchors usedAnchors = QDeclarativeItemPrivate::get(child.item)->anchors()->usedAnchors(); - if (usedAnchors & QDeclarativeAnchors::LeftAnchor || - usedAnchors & QDeclarativeAnchors::RightAnchor || - usedAnchors & QDeclarativeAnchors::HCenterAnchor) { - childsWithConflictingAnchors = true; - break; + QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; + if (anchors) { + QDeclarativeAnchors::Anchors usedAnchors = anchors->usedAnchors(); + if (usedAnchors & QDeclarativeAnchors::LeftAnchor || + usedAnchors & QDeclarativeAnchors::RightAnchor || + usedAnchors & QDeclarativeAnchors::HCenterAnchor) { + childsWithConflictingAnchors = true; + break; + } } } } @@ -868,9 +874,12 @@ void QDeclarativeGrid::reportConflictingAnchors() bool childsWithConflictingAnchors(false); for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); - if (child.item && QDeclarativeItemPrivate::get(child.item)->anchors()->usedAnchors()) { - childsWithConflictingAnchors = true; - break; + if (child.item) { + QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; + if (anchors && anchors->usedAnchors()) { + childsWithConflictingAnchors = true; + break; + } } } if (childsWithConflictingAnchors) { @@ -1025,9 +1034,12 @@ void QDeclarativeFlow::reportConflictingAnchors() bool childsWithConflictingAnchors(false); for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); - if (child.item && QDeclarativeItemPrivate::get(child.item)->anchors()->usedAnchors()) { - childsWithConflictingAnchors = true; - break; + if (child.item) { + QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; + if (anchors && anchors->usedAnchors()) { + childsWithConflictingAnchors = true; + break; + } } } if (childsWithConflictingAnchors) { -- cgit v0.12 From e0c8fc977738ca4ac6d31e45bdd2aa1b32828f54 Mon Sep 17 00:00:00 2001 From: mae Date: Mon, 3 May 2010 19:44:52 +0200 Subject: Remove QDeclarativeLoader::resizeMode The explicit resizeMode is superfluous, all usecases could be achieved with the corrected default behaviour of the former ResizeLoaderToItem mode. The NoResize usecase is covered by wrapping the loader in an extra item. That means: A loader automatically gets its size from the item loaded unless the loader has an explicit size itself. Go-ahead-by: Michael Brasser --- examples/declarative/parallax/parallax.qml | 2 +- .../graphicsitems/qdeclarativeloader.cpp | 118 +++++---------------- .../graphicsitems/qdeclarativeloader_p.h | 7 -- .../graphicsitems/qdeclarativeloader_p_p.h | 3 +- .../qdeclarativeloader/data/NoResize.qml | 7 +- .../data/NoResizeGraphicsWidget.qml | 9 +- .../data/SizeGraphicsWidgetToLoader.qml | 1 - .../data/SizeLoaderToGraphicsWidget.qml | 1 - .../qdeclarativeloader/data/SizeToItem.qml | 1 - .../qdeclarativeloader/data/SizeToLoader.qml | 1 - .../qdeclarativeloader/tst_qdeclarativeloader.cpp | 67 ++++++------ 11 files changed, 68 insertions(+), 149 deletions(-) diff --git a/examples/declarative/parallax/parallax.qml b/examples/declarative/parallax/parallax.qml index cb0437d..ca00176 100644 --- a/examples/declarative/parallax/parallax.qml +++ b/examples/declarative/parallax/parallax.qml @@ -31,7 +31,7 @@ Rectangle { Loader { anchors { top: parent.top; topMargin: 10; horizontalCenter: parent.horizontalCenter } width: 300; height: 400 - clip: true; resizeMode: Loader.SizeItemToLoader + clip: true; source: "../../../demos/declarative/samegame/samegame.qml" } } diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index bdd2c87..62fa4db 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -49,7 +49,6 @@ QT_BEGIN_NAMESPACE QDeclarativeLoaderPrivate::QDeclarativeLoaderPrivate() : item(0), component(0), ownComponent(false) - , resizeMode(QDeclarativeLoader::SizeLoaderToItem) { } @@ -59,9 +58,8 @@ QDeclarativeLoaderPrivate::~QDeclarativeLoaderPrivate() void QDeclarativeLoaderPrivate::itemGeometryChanged(QDeclarativeItem *resizeItem, const QRectF &newGeometry, const QRectF &oldGeometry) { - if (resizeItem == item && resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - _q_updateSize(); - } + if (resizeItem == item) + _q_updateSize(false); QDeclarativeItemChangeListener::itemGeometryChanged(resizeItem, newGeometry, oldGeometry); } @@ -76,11 +74,9 @@ void QDeclarativeLoaderPrivate::clear() if (item) { if (QDeclarativeItem *qmlItem = qobject_cast(item)) { - if (resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - QDeclarativeItemPrivate *p = + QDeclarativeItemPrivate *p = static_cast(QGraphicsItemPrivate::get(qmlItem)); - p->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry); - } + p->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry); } // We can't delete immediately because our item may have triggered @@ -96,16 +92,12 @@ void QDeclarativeLoaderPrivate::initResize() { Q_Q(QDeclarativeLoader); if (QDeclarativeItem *qmlItem = qobject_cast(item)) { - if (resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - QDeclarativeItemPrivate *p = + QDeclarativeItemPrivate *p = static_cast(QGraphicsItemPrivate::get(qmlItem)); - p->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); - } + p->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); } else if (item && item->isWidget()) { QGraphicsWidget *widget = static_cast(item); - if (resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - widget->installEventFilter(q); - } + widget->installEventFilter(q); } _q_updateSize(); } @@ -390,83 +382,30 @@ qreal QDeclarativeLoader::progress() const return 0.0; } -/*! - \qmlproperty enumeration Loader::resizeMode - - This property determines how the Loader or item are resized: - \list - \o NoResize - no item will be resized - \o SizeLoaderToItem - the Loader will be sized to the size of the item, unless the size of the Loader has been otherwise specified. - \o SizeItemToLoader - the item will be sized to the size of the Loader. - \endlist - - Note that changing from SizeItemToLoader to SizeLoaderToItem - after the component is loaded will not return the item or Loader - to it's original size. This is due to the item size being adjusted - to the Loader size, thereby losing the original size of the item. - Future changes to the item's size will affect the loader, however. - - The default resizeMode is SizeLoaderToItem. -*/ -QDeclarativeLoader::ResizeMode QDeclarativeLoader::resizeMode() const -{ - Q_D(const QDeclarativeLoader); - return d->resizeMode; -} - -void QDeclarativeLoader::setResizeMode(ResizeMode mode) -{ - Q_D(QDeclarativeLoader); - if (mode == d->resizeMode) - return; - - if (QDeclarativeItem *qmlItem = qobject_cast(d->item)) { - if (d->resizeMode == SizeLoaderToItem) { - QDeclarativeItemPrivate *p = - static_cast(QGraphicsItemPrivate::get(qmlItem)); - p->removeItemChangeListener(d, QDeclarativeItemPrivate::Geometry); - } - } else if (d->item && d->item->isWidget()) { - if (d->resizeMode == SizeLoaderToItem) - d->item->removeEventFilter(this); - } - d->resizeMode = mode; - emit resizeModeChanged(); - d->initResize(); -} - -void QDeclarativeLoaderPrivate::_q_updateSize() +void QDeclarativeLoaderPrivate::_q_updateSize(bool loaderGeometryChanged) { Q_Q(QDeclarativeLoader); if (!item) return; if (QDeclarativeItem *qmlItem = qobject_cast(item)) { - if (resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - q->setWidth(qmlItem->width()); - q->setHeight(qmlItem->height()); - } else if (resizeMode == QDeclarativeLoader::SizeItemToLoader) { + q->setImplicitWidth(qmlItem->width()); + if (loaderGeometryChanged && q->widthValid()) qmlItem->setWidth(q->width()); + q->setImplicitHeight(qmlItem->height()); + if (loaderGeometryChanged && q->heightValid()) qmlItem->setHeight(q->height()); - } } else if (item && item->isWidget()) { QGraphicsWidget *widget = static_cast(item); - if (resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - QSizeF newSize = widget->size(); - if (newSize.isValid()) { - q->setWidth(newSize.width()); - q->setHeight(newSize.height()); - } - } else if (resizeMode == QDeclarativeLoader::SizeItemToLoader) { - QSizeF oldSize = widget->size(); - QSizeF newSize = oldSize; - if (q->heightValid()) - newSize.setHeight(q->height()); - if (q->widthValid()) - newSize.setWidth(q->width()); - if (oldSize != newSize) - widget->resize(newSize); - } + QSizeF widgetSize = widget->size(); + q->setImplicitWidth(widgetSize.width()); + if (loaderGeometryChanged && q->widthValid()) + widgetSize.setWidth(q->width()); + q->setImplicitHeight(widgetSize.height()); + if (loaderGeometryChanged && q->heightValid()) + widgetSize.setHeight(q->height()); + if (widget->size() != widgetSize) + widget->resize(widgetSize); } } @@ -484,9 +423,7 @@ void QDeclarativeLoader::geometryChanged(const QRectF &newGeometry, const QRectF { Q_D(QDeclarativeLoader); if (newGeometry != oldGeometry) { - if (d->resizeMode == SizeItemToLoader) { - d->_q_updateSize(); - } + d->_q_updateSize(); } QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); } @@ -496,10 +433,8 @@ QVariant QDeclarativeLoader::itemChange(GraphicsItemChange change, const QVarian Q_D(QDeclarativeLoader); if (change == ItemSceneHasChanged) { if (d->item && d->item->isWidget()) { - if (d->resizeMode == SizeLoaderToItem) { - d->item->removeEventFilter(this); - d->item->installEventFilter(this); - } + d->item->removeEventFilter(this); + d->item->installEventFilter(this); } } return QDeclarativeItem::itemChange(change, value); @@ -509,9 +444,8 @@ bool QDeclarativeLoader::eventFilter(QObject *watched, QEvent *e) { Q_D(QDeclarativeLoader); if (watched == d->item && e->type() == QEvent::GraphicsSceneResize) { - if (d->item && d->item->isWidget() && d->resizeMode == SizeLoaderToItem) { - d->_q_updateSize(); - } + if (d->item && d->item->isWidget()) + d->_q_updateSize(false); } return QDeclarativeItem::eventFilter(watched, e); } diff --git a/src/declarative/graphicsitems/qdeclarativeloader_p.h b/src/declarative/graphicsitems/qdeclarativeloader_p.h index e9fd8e9..49dfa11 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader_p.h +++ b/src/declarative/graphicsitems/qdeclarativeloader_p.h @@ -55,11 +55,9 @@ class Q_DECLARATIVE_EXPORT QDeclarativeLoader : public QDeclarativeItem { Q_OBJECT Q_ENUMS(Status) - Q_ENUMS(ResizeMode) Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(QDeclarativeComponent *sourceComponent READ sourceComponent WRITE setSourceComponent RESET resetSourceComponent NOTIFY sourceChanged) - Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode NOTIFY resizeModeChanged) Q_PROPERTY(QGraphicsObject *item READ item NOTIFY itemChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) @@ -79,10 +77,6 @@ public: Status status() const; qreal progress() const; - enum ResizeMode { NoResize, SizeLoaderToItem, SizeItemToLoader }; - ResizeMode resizeMode() const; - void setResizeMode(ResizeMode mode); - QGraphicsObject *item() const; Q_SIGNALS: @@ -90,7 +84,6 @@ Q_SIGNALS: void sourceChanged(); void statusChanged(); void progressChanged(); - void resizeModeChanged(); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); diff --git a/src/declarative/graphicsitems/qdeclarativeloader_p_p.h b/src/declarative/graphicsitems/qdeclarativeloader_p_p.h index 49069f9..0d4c4d0 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeloader_p_p.h @@ -77,10 +77,9 @@ public: QGraphicsObject *item; QDeclarativeComponent *component; bool ownComponent : 1; - QDeclarativeLoader::ResizeMode resizeMode; void _q_sourceLoaded(); - void _q_updateSize(); + void _q_updateSize(bool loaderGeometryChanged = true); }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/qdeclarativeloader/data/NoResize.qml b/tests/auto/declarative/qdeclarativeloader/data/NoResize.qml index 6aa3d2f..72cd3b9 100644 --- a/tests/auto/declarative/qdeclarativeloader/data/NoResize.qml +++ b/tests/auto/declarative/qdeclarativeloader/data/NoResize.qml @@ -1,7 +1,8 @@ import Qt 4.7 -Loader { - resizeMode: "NoResize" +Item { width: 200; height: 80 - source: "Rect120x60.qml" + Loader { + source: "Rect120x60.qml" + } } diff --git a/tests/auto/declarative/qdeclarativeloader/data/NoResizeGraphicsWidget.qml b/tests/auto/declarative/qdeclarativeloader/data/NoResizeGraphicsWidget.qml index 9322141..0cff506 100644 --- a/tests/auto/declarative/qdeclarativeloader/data/NoResizeGraphicsWidget.qml +++ b/tests/auto/declarative/qdeclarativeloader/data/NoResizeGraphicsWidget.qml @@ -1,8 +1,9 @@ import Qt 4.7 -Loader { - resizeMode: Loader.NoResize - source: "GraphicsWidget250x250.qml" +Item { width: 200 - height: 80 + height: 80 + Loader { + source: "GraphicsWidget250x250.qml" + } } diff --git a/tests/auto/declarative/qdeclarativeloader/data/SizeGraphicsWidgetToLoader.qml b/tests/auto/declarative/qdeclarativeloader/data/SizeGraphicsWidgetToLoader.qml index 0cfb4df..81610ad 100644 --- a/tests/auto/declarative/qdeclarativeloader/data/SizeGraphicsWidgetToLoader.qml +++ b/tests/auto/declarative/qdeclarativeloader/data/SizeGraphicsWidgetToLoader.qml @@ -1,7 +1,6 @@ import Qt 4.7 Loader { - resizeMode: Loader.SizeItemToLoader width: 200 height: 80 source: "GraphicsWidget250x250.qml" diff --git a/tests/auto/declarative/qdeclarativeloader/data/SizeLoaderToGraphicsWidget.qml b/tests/auto/declarative/qdeclarativeloader/data/SizeLoaderToGraphicsWidget.qml index b588c9d..a801a42 100644 --- a/tests/auto/declarative/qdeclarativeloader/data/SizeLoaderToGraphicsWidget.qml +++ b/tests/auto/declarative/qdeclarativeloader/data/SizeLoaderToGraphicsWidget.qml @@ -1,6 +1,5 @@ import Qt 4.7 Loader { - resizeMode: Loader.SizeLoaderToItem source: "GraphicsWidget250x250.qml" } diff --git a/tests/auto/declarative/qdeclarativeloader/data/SizeToItem.qml b/tests/auto/declarative/qdeclarativeloader/data/SizeToItem.qml index 93be6f1..77aa8d9 100644 --- a/tests/auto/declarative/qdeclarativeloader/data/SizeToItem.qml +++ b/tests/auto/declarative/qdeclarativeloader/data/SizeToItem.qml @@ -1,6 +1,5 @@ import Qt 4.7 Loader { - resizeMode: "SizeLoaderToItem" source: "Rect120x60.qml" } diff --git a/tests/auto/declarative/qdeclarativeloader/data/SizeToLoader.qml b/tests/auto/declarative/qdeclarativeloader/data/SizeToLoader.qml index 04b46fb..0098927 100644 --- a/tests/auto/declarative/qdeclarativeloader/data/SizeToLoader.qml +++ b/tests/auto/declarative/qdeclarativeloader/data/SizeToLoader.qml @@ -1,7 +1,6 @@ import Qt 4.7 Loader { - resizeMode: "SizeItemToLoader" width: 200; height: 80 source: "Rect120x60.qml" } diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp index 7cdadb4..b56ff13 100644 --- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp +++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp @@ -270,7 +270,6 @@ void tst_QDeclarativeLoader::sizeLoaderToItem() QDeclarativeComponent component(&engine, TEST_FILE("/SizeToItem.qml")); QDeclarativeLoader *loader = qobject_cast(component.create()); QVERIFY(loader != 0); - QVERIFY(loader->resizeMode() == QDeclarativeLoader::SizeLoaderToItem); QCOMPARE(loader->width(), 120.0); QCOMPARE(loader->height(), 60.0); @@ -282,20 +281,28 @@ void tst_QDeclarativeLoader::sizeLoaderToItem() QCOMPARE(loader->width(), 150.0); QCOMPARE(loader->height(), 45.0); + // Check explicit width + loader->setWidth(200.0); + QCOMPARE(loader->width(), 200.0); + QCOMPARE(rect->width(), 200.0); + rect->setWidth(100.0); // when rect changes ... + QCOMPARE(rect->width(), 100.0); // ... it changes + QCOMPARE(loader->width(), 200.0); // ... but loader stays the same + + // Check explicit height + loader->setHeight(200.0); + QCOMPARE(loader->height(), 200.0); + QCOMPARE(rect->height(), 200.0); + rect->setHeight(100.0); // when rect changes ... + QCOMPARE(rect->height(), 100.0); // ... it changes + QCOMPARE(loader->height(), 200.0); // ... but loader stays the same + // Switch mode - loader->setResizeMode(QDeclarativeLoader::SizeItemToLoader); loader->setWidth(180); loader->setHeight(30); QCOMPARE(rect->width(), 180.0); QCOMPARE(rect->height(), 30.0); - // notify - QSignalSpy spy(loader, SIGNAL(resizeModeChanged())); - loader->setResizeMode(QDeclarativeLoader::NoResize); - QCOMPARE(spy.count(),1); - loader->setResizeMode(QDeclarativeLoader::NoResize); - QCOMPARE(spy.count(),1); - delete loader; } @@ -304,7 +311,6 @@ void tst_QDeclarativeLoader::sizeItemToLoader() QDeclarativeComponent component(&engine, TEST_FILE("/SizeToLoader.qml")); QDeclarativeLoader *loader = qobject_cast(component.create()); QVERIFY(loader != 0); - QVERIFY(loader->resizeMode() == QDeclarativeLoader::SizeItemToLoader); QCOMPARE(loader->width(), 200.0); QCOMPARE(loader->height(), 80.0); @@ -320,7 +326,8 @@ void tst_QDeclarativeLoader::sizeItemToLoader() QCOMPARE(rect->height(), 30.0); // Switch mode - loader->setResizeMode(QDeclarativeLoader::SizeLoaderToItem); + loader->resetWidth(); // reset explicit size + loader->resetHeight(); rect->setWidth(160); rect->setHeight(45); QCOMPARE(loader->width(), 160.0); @@ -332,17 +339,12 @@ void tst_QDeclarativeLoader::sizeItemToLoader() void tst_QDeclarativeLoader::noResize() { QDeclarativeComponent component(&engine, TEST_FILE("/NoResize.qml")); - QDeclarativeLoader *loader = qobject_cast(component.create()); - QVERIFY(loader != 0); - QCOMPARE(loader->width(), 200.0); - QCOMPARE(loader->height(), 80.0); - - QDeclarativeItem *rect = qobject_cast(loader->item()); - QVERIFY(rect); - QCOMPARE(rect->width(), 120.0); - QCOMPARE(rect->height(), 60.0); + QDeclarativeItem* item = qobject_cast(component.create()); + QVERIFY(item != 0); + QCOMPARE(item->width(), 200.0); + QCOMPARE(item->height(), 80.0); - delete loader; + delete item; } void tst_QDeclarativeLoader::sizeLoaderToGraphicsWidget() @@ -353,7 +355,6 @@ void tst_QDeclarativeLoader::sizeLoaderToGraphicsWidget() scene.addItem(loader); QVERIFY(loader != 0); - QVERIFY(loader->resizeMode() == QDeclarativeLoader::SizeLoaderToItem); QCOMPARE(loader->width(), 250.0); QCOMPARE(loader->height(), 250.0); @@ -365,7 +366,6 @@ void tst_QDeclarativeLoader::sizeLoaderToGraphicsWidget() QCOMPARE(loader->height(), 45.0); // Switch mode - loader->setResizeMode(QDeclarativeLoader::SizeItemToLoader); loader->setWidth(180); loader->setHeight(30); QCOMPARE(widget->size().width(), 180.0); @@ -382,7 +382,6 @@ void tst_QDeclarativeLoader::sizeGraphicsWidgetToLoader() scene.addItem(loader); QVERIFY(loader != 0); - QVERIFY(loader->resizeMode() == QDeclarativeLoader::SizeItemToLoader); QCOMPARE(loader->width(), 200.0); QCOMPARE(loader->height(), 80.0); @@ -398,7 +397,8 @@ void tst_QDeclarativeLoader::sizeGraphicsWidgetToLoader() QCOMPARE(widget->size().height(), 30.0); // Switch mode - loader->setResizeMode(QDeclarativeLoader::SizeLoaderToItem); + loader->resetWidth(); // reset explicit size + loader->resetHeight(); widget->resize(QSizeF(160,45)); QCOMPARE(loader->width(), 160.0); QCOMPARE(loader->height(), 45.0); @@ -409,20 +409,15 @@ void tst_QDeclarativeLoader::sizeGraphicsWidgetToLoader() void tst_QDeclarativeLoader::noResizeGraphicsWidget() { QDeclarativeComponent component(&engine, TEST_FILE("/NoResizeGraphicsWidget.qml")); - QDeclarativeLoader *loader = qobject_cast(component.create()); + QDeclarativeItem *item = qobject_cast(component.create()); QGraphicsScene scene; - scene.addItem(loader); - - QVERIFY(loader != 0); - QCOMPARE(loader->width(), 200.0); - QCOMPARE(loader->height(), 80.0); + scene.addItem(item); - QGraphicsWidget *widget = qobject_cast(loader->item()); - QVERIFY(widget); - QCOMPARE(widget->size().width(), 250.0); - QCOMPARE(widget->size().height(), 250.0); + QVERIFY(item != 0); + QCOMPARE(item->width(), 200.0); + QCOMPARE(item->height(), 80.0); - delete loader; + delete item; } void tst_QDeclarativeLoader::networkRequestUrl() -- cgit v0.12 From 56dcdada14f1a499da5a458bdada2127e73dc630 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 4 May 2010 11:13:24 +1000 Subject: Doc improvements --- doc/src/declarative/dynamicobjects.qdoc | 48 ++++++++------------- doc/src/snippets/declarative/dynamicObjects.qml | 30 +++++++++++++ .../snippets/declarative/flickableScrollbar.qml | 26 +++++++++++ .../graphicsitems/qdeclarativeflickable.cpp | 50 ++++++++++++---------- 4 files changed, 102 insertions(+), 52 deletions(-) create mode 100644 doc/src/snippets/declarative/dynamicObjects.qml create mode 100644 doc/src/snippets/declarative/flickableScrollbar.qml diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc index 5cdd768..dc0277d 100644 --- a/doc/src/declarative/dynamicobjects.qdoc +++ b/doc/src/declarative/dynamicobjects.qdoc @@ -132,36 +132,24 @@ do not have an id in QML. \section1 Deleting Objects Dynamically -You should generally avoid dynamically deleting objects that you did not -dynamically create. In many UIs, it is sufficient to set the opacity to 0 or -to move the item off of the edge of the screen. If you have lots of dynamically -created items however, deleting them when they are no longer used will provide -a worthwhile performance benefit. Note that you should never manually delete -items which were dynamically created by QML Elements such as \l{Loader}. - -To manually delete a QML item, call its destroy method. This method has one -argument, which is an approximate delay in milliseconds and which defaults to zero. This -allows you to wait until the completion of an animation or transition. An example: - -\code - Component { - id: fadesOut - Rectangle{ - id: rect - width: 40; height: 40; - NumberAnimation on opacity { from:1; to:0; duration: 1000 } - Component.onCompleted: rect.destroy(1000); - } - } - function createFadesOut(parentItem) - { - var object = fadesOut.createObject(); - object.parent = parentItem; - } -\endcode - -In the above example, the dynamically created rectangle calls destroy as soon as it is created, - but delays long enough for its fade out animation to be played. +In many user interfaces, it is sufficient to set an item's opacity to 0 or +to move the item off the screen instead of deleting the item. If you have +lots of dynamically created items, however, you may receive a worthwhile +performance benefit if unused items are deleted. + +Note that you should never manually delete items that were dynamically created +by QML elements (such as \l Loader). Also, you should generally avoid deleting +items that you did not dynamically create yourself. + +Items can be deleted using the \c destroy() method. This method has an optional +argument (which defaults to 0) that specifies the approximate delay in milliseconds +before the object is to be destroyed. This allows you to wait until the completion of +an animation or transition. An example: + +\snippet doc/src/snippets/declarative/dynamicObjects.qml 0 + +Here, \c Rectangle objects are destroyed one second after they are created, which is long +enough for the \c NumberAnimation to be played before the object is destroyed. */ diff --git a/doc/src/snippets/declarative/dynamicObjects.qml b/doc/src/snippets/declarative/dynamicObjects.qml new file mode 100644 index 0000000..dd55d78 --- /dev/null +++ b/doc/src/snippets/declarative/dynamicObjects.qml @@ -0,0 +1,30 @@ +import Qt 4.7 + +//![0] +Rectangle { + id: rootItem + width: 300 + height: 300 + + Component { + id: rectComponent + + Rectangle { + id: rect + width: 40; height: 40; + color: "red" + + NumberAnimation on opacity { from: 1; to: 0; duration: 1000 } + + Component.onCompleted: rect.destroy(1000); + } + } + + function createRectangle() { + var object = rectComponent.createObject(); + object.parent = rootItem; + } + + Component.onCompleted: createRectangle() +} +//![0] diff --git a/doc/src/snippets/declarative/flickableScrollbar.qml b/doc/src/snippets/declarative/flickableScrollbar.qml new file mode 100644 index 0000000..147751a --- /dev/null +++ b/doc/src/snippets/declarative/flickableScrollbar.qml @@ -0,0 +1,26 @@ +import Qt 4.7 + +//![0] +Rectangle { + width: 200; height: 200 + + Flickable { + id: flickable +//![0] + anchors.fill: parent + contentWidth: image.width; contentHeight: image.height + + Image { id: image; source: "pics/qt.png" } +//![1] + } + + Rectangle { + id: scrollbar + anchors.right: flickable.right + y: flickable.visibleArea.yPosition * flickable.height + width: 10 + height: flickable.visibleArea.heightRatio * flickable.height + color: "black" + } +} +//![1] diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index b462443..35aa0f8 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -345,19 +345,21 @@ void QDeclarativeFlickablePrivate::updateBeginningEnd() \code Flickable { - width: 200; height: 200; contentWidth: image.width; contentHeight: image.height - Image { id: image; source: "bigimage.png" } + width: 200; height: 200 + contentWidth: image.width; contentHeight: image.height + + Image { id: image; source: "bigImage.png" } } \endcode \image flickable.gif - \note Flickable does not automatically clip its contents. If - it is not full-screen it is likely that \c clip should be set - to true. + Flickable does not automatically clip its contents. If + it is not full-screen it is likely that \l {Item::clip}{clip} should be set + to \c true. - \note Due to an implementation detail items placed inside a flickable cannot anchor to it by - id, use 'parent' instead. + \note Due to an implementation detail, items placed inside a Flickable cannot anchor to it by + \c id. Use \c parent instead. */ /*! @@ -400,18 +402,17 @@ void QDeclarativeFlickablePrivate::updateBeginningEnd() These properties describe the position and size of the currently viewed area. The size is defined as the percentage of the full view currently visible, scaled to 0.0 - 1.0. The page position is usually in the range 0.0 (beginning) to - 1.0 minus size ratio (end), i.e. yPosition is in the range 0.0 to 1.0-heightRatio. + 1.0 minus size ratio (end), i.e. \c yPosition is in the range 0.0 to 1.0-\c heightRatio. However, it is possible for the contents to be dragged outside of the normal range, resulting in the page positions also being outside the normal range. - These properties are typically used to draw a scrollbar, for example: - \code - Rectangle { - opacity: 0.5; anchors.right: MyListView.right-2; width: 6 - y: MyListView.visibleArea.yPosition * MyListView.height - height: MyListView.visibleArea.heightRatio * MyListView.height - } - \endcode + These properties are typically used to draw a scrollbar. For example: + + \snippet doc/src/snippets/declarative/flickableScrollbar.qml 0 + \dots 4 + \snippet doc/src/snippets/declarative/flickableScrollbar.qml 1 + + \sa {declarative/scrollbar}{scrollbar example} */ QDeclarativeFlickable::QDeclarativeFlickable(QDeclarativeItem *parent) @@ -479,11 +480,12 @@ void QDeclarativeFlickable::setContentY(qreal pos) /*! \qmlproperty bool Flickable::interactive - A user cannot drag or flick a Flickable that is not interactive. + This property holds whether the user can interact with the Flickable. A user + cannot drag or flick a Flickable that is not interactive. This property is useful for temporarily disabling flicking. This allows special interaction with Flickable's children: for example, you might want to - freeze a flickable map while viewing detailed information on a location popup that is a child of the Flickable. + freeze a flickable map while scrolling through a pop-up dialog that is a child of the Flickable. */ bool QDeclarativeFlickable::isInteractive() const { @@ -1026,7 +1028,7 @@ void QDeclarativeFlickable::setOverShoot(bool o) This enables the feeling that the edges of the view are soft, rather than a hard physical boundary. - boundsBehavior can be one of: + The \c boundsBehavior can be one of: \list \o \e StopAtBounds - the contents can not be dragged beyond the boundary @@ -1059,12 +1061,16 @@ void QDeclarativeFlickable::setBoundsBehavior(BoundsBehavior b) \qmlproperty int Flickable::contentHeight The dimensions of the content (the surface controlled by Flickable). Typically this - should be set to the combined size of the items placed in the Flickable. + should be set to the combined size of the items placed in the Flickable. Note this + can be set automatically using \l {Item::childrenRect.width}{childrenRect.width} + and \l {Item::childrenRect.height}{childrenRect.height}. For example: \code Flickable { - width: 320; height: 480; contentWidth: image.width; contentHeight: image.height - Image { id: image; source: "bigimage.png" } + width: 320; height: 480 + contentWidth: childrenRect.width; contentHeight: childrenRect.height + + Image { id: image; source: "bigImage.png" } } \endcode */ -- cgit v0.12 From b5957435b36500e92d7ae9a6d01e9cdffa657275 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 4 May 2010 11:55:26 +1000 Subject: Remove obsolete doc groupings. --- .../graphicsitems/qdeclarativeanchors.cpp | 1 - .../graphicsitems/qdeclarativeflipable.cpp | 2 -- .../graphicsitems/qdeclarativeimage.cpp | 2 -- src/declarative/graphicsitems/qdeclarativeitem.cpp | 39 ---------------------- .../graphicsitems/qdeclarativemousearea.cpp | 2 -- src/declarative/graphicsitems/qdeclarativepath.cpp | 7 ---- .../graphicsitems/qdeclarativepositioners.cpp | 5 --- src/declarative/graphicsitems/qdeclarativetext.cpp | 1 - .../graphicsitems/qdeclarativetextedit.cpp | 1 - src/declarative/util/qdeclarativebind.cpp | 1 - src/declarative/util/qdeclarativefontloader.cpp | 1 - src/declarative/util/qdeclarativestate.cpp | 1 - src/declarative/util/qdeclarativesystempalette.cpp | 1 - src/declarative/util/qdeclarativetimeline.cpp | 2 -- src/declarative/util/qdeclarativetransition.cpp | 4 +-- 15 files changed, 1 insertion(+), 69 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeanchors.cpp b/src/declarative/graphicsitems/qdeclarativeanchors.cpp index f15316b..ef07cbb 100644 --- a/src/declarative/graphicsitems/qdeclarativeanchors.cpp +++ b/src/declarative/graphicsitems/qdeclarativeanchors.cpp @@ -128,7 +128,6 @@ static qreal adjustedPosition(QGraphicsObject *item, QDeclarativeAnchorLine::Anc \internal \class QDeclarativeAnchors \since 4.7 - \ingroup group_layouts \brief The QDeclarativeAnchors class provides a way to lay out items relative to other items. \warning Currently, only anchoring to siblings or parent is supported. diff --git a/src/declarative/graphicsitems/qdeclarativeflipable.cpp b/src/declarative/graphicsitems/qdeclarativeflipable.cpp index 57045f1..85f40c3 100644 --- a/src/declarative/graphicsitems/qdeclarativeflipable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflipable.cpp @@ -94,8 +94,6 @@ public: \class QDeclarativeFlipable \brief The Flipable item provides a surface that can be flipped. - \ingroup group_widgets - Flipable is an item that can be visibly "flipped" between its front and back sides. */ diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 3937778..1c32b45 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -134,8 +134,6 @@ QT_BEGIN_NAMESPACE \class QDeclarativeImage Image \brief The QDeclarativeImage class provides an image item that you can add to a QDeclarativeView. - \ingroup group_coreitems - Example: \qml Image { source: "pics/star.png" } diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index dc34725..e5faa42 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -219,46 +219,9 @@ QT_BEGIN_NAMESPACE The angle to rotate, in degrees clockwise. */ - -/*! - \group group_animation - \title Animation -*/ - -/*! - \group group_coreitems - \title Basic Items -*/ - -/*! - \group group_layouts - \title Layouts -*/ - -/*! - \group group_states - \title States and Transitions -*/ - -/*! - \group group_utility - \title Utility -*/ - -/*! - \group group_views - \title Views -*/ - -/*! - \group group_widgets - \title Widgets -*/ - /*! \internal \class QDeclarativeContents - \ingroup group_utility \brief The QDeclarativeContents class gives access to the height and width of an item's contents. */ @@ -1258,8 +1221,6 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec changes. For many properties in Item or Item derivatives this can be used to add a touch of imperative logic to your application (when absolutely necessary). - - \ingroup group_coreitems */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index c7b209a..d178107 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -292,8 +292,6 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() \class QDeclarativeMouseArea \brief The QDeclarativeMouseArea class provides a simple mouse handling abstraction for use within Qml. - \ingroup group_coreitems - All QDeclarativeItem derived classes can do mouse handling but the QDeclarativeMouseArea class exposes mouse handling data as properties and tracks flicking and dragging of the mouse. diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index e867a52..4d8b619 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -63,7 +63,6 @@ QT_BEGIN_NAMESPACE /*! \internal \class QDeclarativePathElement - \ingroup group_utility */ /*! @@ -86,7 +85,6 @@ QT_BEGIN_NAMESPACE /*! \internal \class QDeclarativePath - \ingroup group_utility \brief The QDeclarativePath class defines a path. \sa QDeclarativePathView */ @@ -513,7 +511,6 @@ void QDeclarativeCurve::setY(qreal y) /*! \internal \class QDeclarativePathAttribute - \ingroup group_utility \brief The QDeclarativePathAttribute class allows to set the value of an attribute at a given position in the path. \sa QDeclarativePath @@ -586,7 +583,6 @@ void QDeclarativePathAttribute::setValue(qreal value) /*! \internal \class QDeclarativePathLine - \ingroup group_utility \brief The QDeclarativePathLine class defines a straight line. \sa QDeclarativePath @@ -630,7 +626,6 @@ void QDeclarativePathLine::addToPath(QPainterPath &path) /*! \internal \class QDeclarativePathQuad - \ingroup group_utility \brief The QDeclarativePathQuad class defines a quadratic Bezier curve with a control point. \sa QDeclarativePath @@ -718,7 +713,6 @@ void QDeclarativePathQuad::addToPath(QPainterPath &path) /*! \internal \class QDeclarativePathCubic - \ingroup group_utility \brief The QDeclarativePathCubic class defines a cubic Bezier curve with two control points. \sa QDeclarativePath @@ -844,7 +838,6 @@ void QDeclarativePathCubic::addToPath(QPainterPath &path) /*! \internal \class QDeclarativePathPercent - \ingroup group_utility \brief The QDeclarativePathPercent class manipulates the way a path is interpreted. QDeclarativePathPercent allows you to bunch up items (or spread out items) along various diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index c1ef04d..7e4549f 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -76,7 +76,6 @@ void QDeclarativeBasePositionerPrivate::unwatchChanges(QDeclarativeItem* other) /*! \internal \class QDeclarativeBasePositioner - \ingroup group_layouts \brief The QDeclarativeBasePositioner class provides a base for QDeclarativeGraphics layouts. To create a QDeclarativeGraphics Positioner, simply subclass QDeclarativeBasePositioner and implement @@ -404,7 +403,6 @@ Column { \internal \class QDeclarativeColumn \brief The QDeclarativeColumn class lines up items vertically. - \ingroup group_positioners */ QDeclarativeColumn::QDeclarativeColumn(QDeclarativeItem *parent) : QDeclarativeBasePositioner(Vertical, parent) @@ -547,7 +545,6 @@ Row { \internal \class QDeclarativeRow \brief The QDeclarativeRow class lines up items horizontally. - \ingroup group_positioners */ QDeclarativeRow::QDeclarativeRow(QDeclarativeItem *parent) : QDeclarativeBasePositioner(Horizontal, parent) @@ -698,8 +695,6 @@ Grid { \internal \class QDeclarativeGrid \brief The QDeclarativeGrid class lays out items in a grid. - \ingroup group_layouts - */ QDeclarativeGrid::QDeclarativeGrid(QDeclarativeItem *parent) : QDeclarativeBasePositioner(Both, parent), m_rows(-1), m_columns(-1), m_flow(LeftToRight) diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 37a63eb..eeff0c3 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -142,7 +142,6 @@ QSet QTextDocumentWithImageResources::errors; \internal \class QDeclarativeText \qmlclass Text - \ingroup group_coreitems \brief The QDeclarativeText class provides a formatted text item that you can add to a QDeclarativeView. diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 31ed418..762640c 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -85,7 +85,6 @@ TextEdit { \internal \class QDeclarativeTextEdit \qmlclass TextEdit - \ingroup group_coreitems \brief The QDeclarativeTextEdit class provides an editable formatted text item that you can add to a QDeclarativeView. diff --git a/src/declarative/util/qdeclarativebind.cpp b/src/declarative/util/qdeclarativebind.cpp index 1f528e8..5fab631 100644 --- a/src/declarative/util/qdeclarativebind.cpp +++ b/src/declarative/util/qdeclarativebind.cpp @@ -98,7 +98,6 @@ public: /*! \internal \class QDeclarativeBind - \ingroup group_utility \brief The QDeclarativeBind class allows arbitrary property bindings to be created. Simple bindings are usually earier to do in-place rather than creating a diff --git a/src/declarative/util/qdeclarativefontloader.cpp b/src/declarative/util/qdeclarativefontloader.cpp index 4115193..f98ce8b 100644 --- a/src/declarative/util/qdeclarativefontloader.cpp +++ b/src/declarative/util/qdeclarativefontloader.cpp @@ -78,7 +78,6 @@ public: /*! \qmlclass FontLoader QDeclarativeFontLoader \since 4.7 - \ingroup group_utility \brief This item allows using fonts by name or url. Example: diff --git a/src/declarative/util/qdeclarativestate.cpp b/src/declarative/util/qdeclarativestate.cpp index 861cbc8..ea209aa 100644 --- a/src/declarative/util/qdeclarativestate.cpp +++ b/src/declarative/util/qdeclarativestate.cpp @@ -149,7 +149,6 @@ QDeclarativeStateOperation::QDeclarativeStateOperation(QObjectPrivate &dd, QObje \class QDeclarativeState \brief The QDeclarativeState class allows you to define configurations of objects and properties. - \ingroup group_states QDeclarativeState allows you to specify a state as a set of batched changes from the default configuration. diff --git a/src/declarative/util/qdeclarativesystempalette.cpp b/src/declarative/util/qdeclarativesystempalette.cpp index 9bb3f69..6c62446 100644 --- a/src/declarative/util/qdeclarativesystempalette.cpp +++ b/src/declarative/util/qdeclarativesystempalette.cpp @@ -59,7 +59,6 @@ public: /*! \qmlclass SystemPalette QDeclarativeSystemPalette \since 4.7 - \ingroup group_utility \brief The SystemPalette item gives access to the Qt palettes. \sa QPalette diff --git a/src/declarative/util/qdeclarativetimeline.cpp b/src/declarative/util/qdeclarativetimeline.cpp index 291b2f3..0258b3c 100644 --- a/src/declarative/util/qdeclarativetimeline.cpp +++ b/src/declarative/util/qdeclarativetimeline.cpp @@ -255,7 +255,6 @@ qreal QDeclarativeTimeLinePrivate::value(const Op &op, int time, qreal base, boo /*! \internal \class QDeclarativeTimeLine - \ingroup group_animation \brief The QDeclarativeTimeLine class provides a timeline for controlling animations. QDeclarativeTimeLine is similar to QTimeLine except: @@ -875,7 +874,6 @@ void QDeclarativeTimeLine::remove(QDeclarativeTimeLineObject *v) /*! \internal \class QDeclarativeTimeLineValue - \ingroup group_animation \brief The QDeclarativeTimeLineValue class provides a value that can be modified by QDeclarativeTimeLine. */ diff --git a/src/declarative/util/qdeclarativetransition.cpp b/src/declarative/util/qdeclarativetransition.cpp index f284156..ab8b116 100644 --- a/src/declarative/util/qdeclarativetransition.cpp +++ b/src/declarative/util/qdeclarativetransition.cpp @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE /*! \qmlclass Transition QDeclarativeTransition - \since 4.7 + \since 4.7 \brief The Transition element defines animated transitions that occur on state changes. \sa {qmlstates}{States}, {state-transitions}{Transitions}, {QtDeclarative} @@ -63,8 +63,6 @@ QT_BEGIN_NAMESPACE \internal \class QDeclarativeTransition \brief The QDeclarativeTransition class allows you to define animated transitions that occur on state changes. - - \ingroup group_states */ //ParallelAnimationWrapper allows us to do a "callback" when the animation finishes, rather than connecting -- cgit v0.12 From b23f371b5908a507f0eafcc5070b756b17672d71 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 4 May 2010 13:19:59 +1000 Subject: Optimize childrenRect. --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 115 ++++++++++++++------- src/declarative/graphicsitems/qdeclarativeitem_p.h | 15 ++- 2 files changed, 87 insertions(+), 43 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index e5faa42..04c1f85 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -230,62 +230,93 @@ QDeclarativeContents::QDeclarativeContents() : m_x(0), m_y(0), m_width(0), m_hei { } +QDeclarativeContents::~QDeclarativeContents() +{ + QList children = m_item->childItems(); + for (int i = 0; i < children.count(); ++i) { + QDeclarativeItem *child = qobject_cast(children.at(i)); + if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? + continue; + QDeclarativeItemPrivate::get(child)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry); + } +} + QRectF QDeclarativeContents::rectF() const { return QRectF(m_x, m_y, m_width, m_height); } -//TODO: optimization: only check sender(), if there is one -void QDeclarativeContents::calcHeight() +void QDeclarativeContents::calcHeight(QDeclarativeItem *changed) { qreal oldy = m_y; qreal oldheight = m_height; - qreal top = FLT_MAX; - qreal bottom = 0; - - QList children = m_item->childItems(); - for (int i = 0; i < children.count(); ++i) { - QDeclarativeItem *child = qobject_cast(children.at(i)); - if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? - continue; - qreal y = child->y(); - if (y + child->height() > bottom) - bottom = y + child->height(); + if (changed) { + qreal top = oldy; + qreal bottom = oldy + oldheight; + qreal y = changed->y(); + if (y + changed->height() > bottom) + bottom = y + changed->height(); if (y < top) top = y; - } - if (!children.isEmpty()) m_y = top; - m_height = qMax(bottom - top, qreal(0.0)); + m_height = bottom - top; + } else { + qreal top = FLT_MAX; + qreal bottom = 0; + QList children = m_item->childItems(); + for (int i = 0; i < children.count(); ++i) { + QDeclarativeItem *child = qobject_cast(children.at(i)); + if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? + continue; + qreal y = child->y(); + if (y + child->height() > bottom) + bottom = y + child->height(); + if (y < top) + top = y; + } + if (!children.isEmpty()) + m_y = top; + m_height = qMax(bottom - top, qreal(0.0)); + } if (m_height != oldheight || m_y != oldy) emit rectChanged(rectF()); } -//TODO: optimization: only check sender(), if there is one -void QDeclarativeContents::calcWidth() +void QDeclarativeContents::calcWidth(QDeclarativeItem *changed) { qreal oldx = m_x; qreal oldwidth = m_width; - qreal left = FLT_MAX; - qreal right = 0; - - QList children = m_item->childItems(); - for (int i = 0; i < children.count(); ++i) { - QDeclarativeItem *child = qobject_cast(children.at(i)); - if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? - continue; - qreal x = child->x(); - if (x + child->width() > right) - right = x + child->width(); + if (changed) { + qreal left = oldx; + qreal right = oldx + oldwidth; + qreal x = changed->x(); + if (x + changed->width() > right) + right = x + changed->width(); if (x < left) left = x; - } - if (!children.isEmpty()) m_x = left; - m_width = qMax(right - left, qreal(0.0)); + m_width = right - left; + } else { + qreal left = FLT_MAX; + qreal right = 0; + QList children = m_item->childItems(); + for (int i = 0; i < children.count(); ++i) { + QDeclarativeItem *child = qobject_cast(children.at(i)); + if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? + continue; + qreal x = child->x(); + if (x + child->width() > right) + right = x + child->width(); + if (x < left) + left = x; + } + if (!children.isEmpty()) + m_x = left; + m_width = qMax(right - left, qreal(0.0)); + } if (m_width != oldwidth || m_x != oldx) emit rectChanged(rectF()); @@ -294,23 +325,31 @@ void QDeclarativeContents::calcWidth() void QDeclarativeContents::setItem(QDeclarativeItem *item) { m_item = item; + //### optimize + connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF))); QList children = m_item->childItems(); for (int i = 0; i < children.count(); ++i) { QDeclarativeItem *child = qobject_cast(children.at(i)); if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? continue; - connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight())); - connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight())); - connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth())); - connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth())); - connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF))); + QDeclarativeItemPrivate::get(child)->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); + //###what about changes to visibility? } + //### defer until componentComplete calcHeight(); calcWidth(); } +void QDeclarativeContents::itemGeometryChanged(QDeclarativeItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry) +{ + if (newGeometry.width() != oldGeometry.width()) + calcWidth(changed); + if (newGeometry.height() != oldGeometry.height()) + calcHeight(changed); +} + QDeclarativeItemKeyFilter::QDeclarativeItemKeyFilter(QDeclarativeItem *item) : m_next(0) { @@ -1349,6 +1388,7 @@ QDeclarativeItem::~QDeclarativeItem() delete d->_anchorLines; d->_anchorLines = 0; delete d->_anchors; d->_anchors = 0; delete d->_stateGroup; d->_stateGroup = 0; + delete d->_contents; d->_contents = 0; } /*! @@ -1589,7 +1629,6 @@ QRectF QDeclarativeItem::childrenRect() Q_D(QDeclarativeItem); if (!d->_contents) { d->_contents = new QDeclarativeContents; - QDeclarative_setParent_noEvent(d->_contents, this); d->_contents->setItem(this); } return d->_contents->rectF(); diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index b4dd60a..467d58a 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -79,24 +79,29 @@ class QNetworkReply; class QDeclarativeItemKeyFilter; //### merge into private? -class QDeclarativeContents : public QObject +class QDeclarativeContents : public QObject, public QDeclarativeItemChangeListener { Q_OBJECT public: QDeclarativeContents(); + ~QDeclarativeContents(); QRectF rectF() const; void setItem(QDeclarativeItem *item); -public Q_SLOTS: - void calcHeight(); - void calcWidth(); - Q_SIGNALS: void rectChanged(QRectF); +protected: + void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); + //void itemDestroyed(QDeclarativeItem *item); + //void itemVisibilityChanged(QDeclarativeItem *item) + private: + void calcHeight(QDeclarativeItem *changed = 0); + void calcWidth(QDeclarativeItem *changed = 0); + QDeclarativeItem *m_item; qreal m_x; qreal m_y; -- cgit v0.12 From 1e3a6ac738b54c4ea3652b9f6ede665a1fafc72c Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 4 May 2010 14:03:01 +1000 Subject: Update childrenRect when children are added or removed. Task-number: QT-714 --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 38 ++++++++++++++++++++-- src/declarative/graphicsitems/qdeclarativeitem_p.h | 5 ++- .../qdeclarativeitem/data/childrenRect.qml | 27 +++++++++++++++ .../qdeclarativeitem/tst_qdeclarativeitem.cpp | 28 ++++++++++++++++ 4 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeitem/data/childrenRect.qml diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 04c1f85..14f6b4a 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -237,7 +237,7 @@ QDeclarativeContents::~QDeclarativeContents() QDeclarativeItem *child = qobject_cast(children.at(i)); if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? continue; - QDeclarativeItemPrivate::get(child)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry); + QDeclarativeItemPrivate::get(child)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); } } @@ -333,7 +333,7 @@ void QDeclarativeContents::setItem(QDeclarativeItem *item) QDeclarativeItem *child = qobject_cast(children.at(i)); if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? continue; - QDeclarativeItemPrivate::get(child)->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); + QDeclarativeItemPrivate::get(child)->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); //###what about changes to visibility? } @@ -350,6 +350,30 @@ void QDeclarativeContents::itemGeometryChanged(QDeclarativeItem *changed, const calcHeight(changed); } +void QDeclarativeContents::itemDestroyed(QDeclarativeItem *item) +{ + if (item) + QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); + calcWidth(); + calcHeight(); +} + +void QDeclarativeContents::childRemoved(QDeclarativeItem *item) +{ + if (item) + QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); + calcWidth(); + calcHeight(); +} + +void QDeclarativeContents::childAdded(QDeclarativeItem *item) +{ + if (item) + QDeclarativeItemPrivate::get(item)->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); + calcWidth(item); + calcHeight(item); +} + QDeclarativeItemKeyFilter::QDeclarativeItemKeyFilter(QDeclarativeItem *item) : m_next(0) { @@ -2551,6 +2575,16 @@ QVariant QDeclarativeItem::itemChange(GraphicsItemChange change, } } break; + case ItemChildAddedChange: + if (d->_contents) + d->_contents->childAdded(qobject_cast( + value.value())); + break; + case ItemChildRemovedChange: + if (d->_contents) + d->_contents->childRemoved(qobject_cast( + value.value())); + break; default: break; } diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index 467d58a..516d6d0 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -90,12 +90,15 @@ public: void setItem(QDeclarativeItem *item); + void childRemoved(QDeclarativeItem *item); + void childAdded(QDeclarativeItem *item); + Q_SIGNALS: void rectChanged(QRectF); protected: void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); - //void itemDestroyed(QDeclarativeItem *item); + void itemDestroyed(QDeclarativeItem *item); //void itemVisibilityChanged(QDeclarativeItem *item) private: diff --git a/tests/auto/declarative/qdeclarativeitem/data/childrenRect.qml b/tests/auto/declarative/qdeclarativeitem/data/childrenRect.qml new file mode 100644 index 0000000..f351b53 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeitem/data/childrenRect.qml @@ -0,0 +1,27 @@ +import Qt 4.7 + +Rectangle { + width: 400 + height: 400 + + property int childCount: 0; + + Item { + objectName: "testItem" + width: childrenRect.width + height: childrenRect.height + + Repeater { + id: repeater + model: childCount + delegate: Rectangle { + x: index*10 + y: index*20 + width: 10 + height: 20 + + color: "red" + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index d2c328e..e0ca746 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -63,6 +63,7 @@ private slots: void propertyChanges(); void transforms(); void transforms_data(); + void childrenRect(); void childrenProperty(); void resourcesProperty(); @@ -537,6 +538,33 @@ void tst_QDeclarativeItem::propertyChanges() delete canvas; } +void tst_QDeclarativeItem::childrenRect() +{ + QDeclarativeView *canvas = new QDeclarativeView(0); + canvas->setFixedSize(240,320); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/childrenRect.qml")); + canvas->show(); + + QGraphicsObject *o = canvas->rootObject(); + QDeclarativeItem *item = o->findChild("testItem"); + QCOMPARE(item->width(), qreal(0)); + QCOMPARE(item->height(), qreal(0)); + + o->setProperty("childCount", 1); + QCOMPARE(item->width(), qreal(10)); + QCOMPARE(item->height(), qreal(20)); + + o->setProperty("childCount", 5); + QCOMPARE(item->width(), qreal(50)); + QCOMPARE(item->height(), qreal(100)); + + o->setProperty("childCount", 0); + QCOMPARE(item->width(), qreal(0)); + QCOMPARE(item->height(), qreal(0)); + + delete o; +} + template T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName) { -- cgit v0.12 From a5aadcea4c12c7926bf3b4d218ce476723cd7e10 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 4 May 2010 15:13:59 +1000 Subject: Optimization for QDeclarativePaintedItem. --- .../graphicsitems/qdeclarativepainteditem.cpp | 27 +++++++++++++--------- .../graphicsitems/qdeclarativepainteditem_p.h | 5 +++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp index f52636f..5dd7e5d 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp +++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp @@ -59,8 +59,8 @@ QT_BEGIN_NAMESPACE \brief The QDeclarativePaintedItem class is an abstract base class for QDeclarativeView items that want cached painting. \internal - This is a convenience class for implementing items that paint their contents - using a QPainter. The contents of the item are cached behind the scenes. + This is a convenience class for implementing items that cache their painting. + The contents of the item are cached behind the scenes. The dirtyCache() function should be called if the contents change to ensure the cache is refreshed the next time painting occurs. @@ -184,7 +184,6 @@ void QDeclarativePaintedItem::setContentsScale(qreal scale) QDeclarativePaintedItem::QDeclarativePaintedItem(QDeclarativeItem *parent) : QDeclarativeItem(*(new QDeclarativePaintedItemPrivate), parent) { - init(); } /*! @@ -195,7 +194,6 @@ QDeclarativePaintedItem::QDeclarativePaintedItem(QDeclarativeItem *parent) QDeclarativePaintedItem::QDeclarativePaintedItem(QDeclarativePaintedItemPrivate &dd, QDeclarativeItem *parent) : QDeclarativeItem(dd, parent) { - init(); } /*! @@ -206,14 +204,21 @@ QDeclarativePaintedItem::~QDeclarativePaintedItem() clearCache(); } -/*! - \internal -*/ -void QDeclarativePaintedItem::init() +void QDeclarativePaintedItem::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) { - connect(this,SIGNAL(widthChanged()),this,SLOT(clearCache())); - connect(this,SIGNAL(heightChanged()),this,SLOT(clearCache())); - connect(this,SIGNAL(visibleChanged()),this,SLOT(clearCache())); + if (newGeometry.width() != oldGeometry.width() || + newGeometry.height() != oldGeometry.height()) + clearCache(); +} + +QVariant QDeclarativePaintedItem::itemChange(GraphicsItemChange change, + const QVariant &value) +{ + if (change == ItemVisibleHasChanged) + clearCache(); + + return QDeclarativeItem::itemChange(change, value); } void QDeclarativePaintedItem::setCacheFrozen(bool frozen) diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem_p.h b/src/declarative/graphicsitems/qdeclarativepainteditem_p.h index cc616af..8d08ba2 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem_p.h +++ b/src/declarative/graphicsitems/qdeclarativepainteditem_p.h @@ -87,6 +87,10 @@ protected: QDeclarativePaintedItem(QDeclarativePaintedItemPrivate &dd, QDeclarativeItem *parent); virtual void drawContents(QPainter *p, const QRect &) = 0; + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + virtual QVariant itemChange(GraphicsItemChange change, + const QVariant &value); void setCacheFrozen(bool); @@ -100,7 +104,6 @@ protected Q_SLOTS: void clearCache(); private: - void init(); Q_DISABLE_COPY(QDeclarativePaintedItem) Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativePaintedItem) }; -- cgit v0.12
default