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 a9a97a9f1ed78d55888679f7ae1a1534f2b20fad Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 4 May 2010 13:39:34 +1000 Subject: Ensure flick endpoint is recalculated for variable height lists. --- src/declarative/graphicsitems/qdeclarativeflickable.cpp | 4 ++-- src/declarative/graphicsitems/qdeclarativelistview.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index b462443..b713987 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -1085,7 +1085,7 @@ void QDeclarativeFlickable::setContentWidth(qreal w) else d->viewport->setWidth(w); // Make sure that we're entirely in view. - if (!d->pressed) { + if (!d->pressed && !d->moving) { int oldDuration = d->fixupDuration; d->fixupDuration = 0; d->fixupX(); @@ -1112,7 +1112,7 @@ void QDeclarativeFlickable::setContentHeight(qreal h) else d->viewport->setHeight(h); // Make sure that we're entirely in view. - if (!d->pressed) { + if (!d->pressed && !d->moving) { int oldDuration = d->fixupDuration; d->fixupDuration = 0; d->fixupY(); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 0f3ee61..0aa68db 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1164,6 +1164,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m moveReason = Mouse; if ((!haveHighlightRange || highlightRange != QDeclarativeListView::StrictlyEnforceRange) && snapMode == QDeclarativeListView::NoSnap) { + correctFlick = true; QDeclarativeFlickablePrivate::flick(data, minExtent, maxExtent, vSize, fixupCallback, velocity); return; } -- 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 From f82a929a9f896b73e25b06f5eb4cf1a313dce60a Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 4 May 2010 12:57:03 +0200 Subject: Allow dynamic deletion of objects created with createQmlObject Task-number: QTBUG-10328 --- src/declarative/qml/qdeclarativeengine.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index dee5ec6..d31e3d5 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1029,7 +1029,10 @@ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QS if (!component.isReady()) return ctxt->throwError("Qt.createQmlObject(): Component is not ready"); - QObject *obj = component.create(context->asQDeclarativeContext()); + QObject *obj = component.beginCreate(context->asQDeclarativeContext()); + if(obj) + QDeclarativeData::get(obj, true)->setImplicitDestructible(); + component.completeCreate(); if(component.isError()) { QList errors = component.errors(); -- cgit v0.12 From 3b3ec6bc4114db82462eef812a47db420d4505c2 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Wed, 5 May 2010 10:19:40 +1000 Subject: Fix a crash with null objects returned from a Q_INVOKABLE Task-number: QTBUG-10412 Reviewed-by: Aaron Kennedy --- src/declarative/qml/qdeclarativeobjectscriptclass.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 03366f0..170f440 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -775,7 +775,8 @@ QScriptDeclarativeClass::Value MetaCallArgument::toValue(QDeclarativeEngine *e) return QScriptDeclarativeClass::Value(engine, *((QString *)&data)); } else if (type == QMetaType::QObjectStar) { QObject *object = *((QObject **)&data); - QDeclarativeData::get(object, true)->setImplicitDestructible(); + if (object) + QDeclarativeData::get(object, true)->setImplicitDestructible(); QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(e); return QScriptDeclarativeClass::Value(engine, priv->objectClass->newQObject(object)); } else if (type == qMetaTypeId >()) { -- cgit v0.12 From 4982b883c31874206aaa05268852fbcee81a8a39 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 5 May 2010 11:49:20 +1000 Subject: Enable states to be activated via their 'when' clause even if unnamed. Autogenerate a name for unnamed states: "anonymousState1", etc. Task-number: QTBUG-10352 Reviewed-by: Aaron Kennedy --- src/declarative/util/qdeclarativestategroup.cpp | 10 +++++++++- .../qdeclarativestates/data/unnamedWhen.qml | 14 ++++++++++++++ .../qdeclarativestates/tst_qdeclarativestates.cpp | 20 ++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativestates/data/unnamedWhen.qml diff --git a/src/declarative/util/qdeclarativestategroup.cpp b/src/declarative/util/qdeclarativestategroup.cpp index 5b51495..9b042d7 100644 --- a/src/declarative/util/qdeclarativestategroup.cpp +++ b/src/declarative/util/qdeclarativestategroup.cpp @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -62,7 +63,7 @@ class QDeclarativeStateGroupPrivate : public QObjectPrivate public: QDeclarativeStateGroupPrivate() : nullState(0), componentComplete(true), - ignoreTrans(false), applyingState(false) {} + ignoreTrans(false), applyingState(false), unnamedCount(0) {} QString currentState; QDeclarativeState *nullState; @@ -78,6 +79,7 @@ public: bool componentComplete; bool ignoreTrans; bool applyingState; + int unnamedCount; QDeclarativeTransition *findTransition(const QString &from, const QString &to); void setCurrentStateInternal(const QString &state, bool = false); @@ -259,6 +261,12 @@ void QDeclarativeStateGroup::componentComplete() Q_D(QDeclarativeStateGroup); d->componentComplete = true; + for (int ii = 0; ii < d->states.count(); ++ii) { + QDeclarativeState *state = d->states.at(ii); + if (state->name().isEmpty()) + state->setName(QLatin1String("anonymousState") % QString::number(++d->unnamedCount)); + } + if (d->updateAutoState()) { return; } else if (!d->currentState.isEmpty()) { diff --git a/tests/auto/declarative/qdeclarativestates/data/unnamedWhen.qml b/tests/auto/declarative/qdeclarativestates/data/unnamedWhen.qml new file mode 100644 index 0000000..a70840c --- /dev/null +++ b/tests/auto/declarative/qdeclarativestates/data/unnamedWhen.qml @@ -0,0 +1,14 @@ +import Qt 4.7 + +Rectangle { + id: theRect + property bool triggerState: false + property string stateString: "" + states: State { + when: triggerState + PropertyChanges { + target: theRect + stateString: "inState" + } + } +} diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index d384d26..13992ad 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -110,6 +110,7 @@ private slots: void illegalObjectCreation(); void whenOrdering(); void urlResolution(); + void unnamedWhen(); }; void tst_qdeclarativestates::initTestCase() @@ -1049,6 +1050,25 @@ void tst_qdeclarativestates::urlResolution() QCOMPARE(image3->source(), resolved); } +void tst_qdeclarativestates::unnamedWhen() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent c(&engine, SRCDIR "/data/unnamedWhen.qml"); + QDeclarativeRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect != 0); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); + + QCOMPARE(rectPrivate->state(), QLatin1String("")); + QCOMPARE(rect->property("stateString").toString(), QLatin1String("")); + rect->setProperty("triggerState", true); + QCOMPARE(rectPrivate->state(), QLatin1String("anonymousState1")); + QCOMPARE(rect->property("stateString").toString(), QLatin1String("inState")); + rect->setProperty("triggerState", false); + QCOMPARE(rectPrivate->state(), QLatin1String("")); + QCOMPARE(rect->property("stateString").toString(), QLatin1String("")); +} + QTEST_MAIN(tst_qdeclarativestates) #include "tst_qdeclarativestates.moc" -- cgit v0.12 From a5d15c36ae3db3caff4eeb86fd7eb5cdbb928f2d Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 5 May 2010 12:16:28 +1000 Subject: syntax update --- src/imports/gestures/qdeclarativegesturearea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imports/gestures/qdeclarativegesturearea.cpp b/src/imports/gestures/qdeclarativegesturearea.cpp index 615c674..19afe0c 100644 --- a/src/imports/gestures/qdeclarativegesturearea.cpp +++ b/src/imports/gestures/qdeclarativegesturearea.cpp @@ -259,7 +259,7 @@ bool QDeclarativeGestureAreaPrivate::gestureEvent(QGestureEvent *event) bool accept = true; for (Bindings::Iterator it = bindings.begin(); it != bindings.end(); ++it) { if ((gesture = event->gesture(it.key()))) { - it.value()->value(); + it.value()->evaluate(); event->setAccepted(true); // XXX only if value returns true? } } -- cgit v0.12 From 326dab74ba8df7707d1054ca5e0280c5f131c148 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 5 May 2010 12:51:02 +1000 Subject: Null objects should appear as JS null --- src/declarative/qml/qdeclarativeobjectscriptclass.cpp | 3 ++- tests/auto/declarative/qdeclarativeecmascript/data/deletedObject.qml | 4 ++-- .../declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 170f440..8b64e0e 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -104,7 +104,8 @@ QScriptValue QDeclarativeObjectScriptClass::newQObject(QObject *object, int type QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); if (!object) - return newObject(scriptEngine, this, new ObjectData(object, type)); + return scriptEngine->nullValue(); +// return newObject(scriptEngine, this, new ObjectData(object, type)); if (QObjectPrivate::get(object)->wasDeleted) return scriptEngine->undefinedValue(); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/deletedObject.qml b/tests/auto/declarative/qdeclarativeecmascript/data/deletedObject.qml index 72b59ae..2337e44 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/deletedObject.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/deletedObject.qml @@ -19,7 +19,7 @@ QtObject { myObject.deleteOnSet = 1; - test3 = myObject.value == undefined; - test4 = obj.value == undefined; + test3 = myObject == null + test4 = obj == null } } diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 6d39be2..8c9290f 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -1104,7 +1104,7 @@ void tst_qdeclarativeecmascript::exceptionClearsOnReeval() QDeclarativeComponent component(&engine, TEST_FILE("exceptionClearsOnReeval.qml")); QString url = component.url().toString(); - QString warning = url + ":4: TypeError: Result of expression 'objectProperty.objectProperty' [undefined] is not an object."; + QString warning = url + ":4: TypeError: Result of expression 'objectProperty' [null] is not an object."; QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); MyQmlObject *object = qobject_cast(component.create()); -- cgit v0.12 From dcee637a9f7a024803f0e5cc1bf57d878dca2ac3 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 5 May 2010 09:50:53 +1000 Subject: Doc improvements, simplify example code --- doc/src/declarative/advtutorial.qdoc | 50 +++++++++++++++---- doc/src/declarative/tutorial.qdoc | 15 +++--- .../declarative/tutorials/helloworld/tutorial1.qml | 3 +- .../declarative/tutorials/helloworld/tutorial2.qml | 3 +- .../declarative/tutorials/helloworld/tutorial3.qml | 3 +- .../tutorials/samegame/samegame1/Block.qml | 2 +- .../tutorials/samegame/samegame1/Button.qml | 17 +++++-- .../tutorials/samegame/samegame1/samegame.qml | 7 ++- .../tutorials/samegame/samegame2/Block.qml | 2 +- .../tutorials/samegame/samegame2/Button.qml | 17 +++++-- .../tutorials/samegame/samegame2/samegame.qml | 5 +- .../tutorials/samegame/samegame3/Button.qml | 17 +++++-- .../tutorials/samegame/samegame3/Dialog.qml | 33 ++++++------- .../tutorials/samegame/samegame3/samegame.js | 9 ++-- .../tutorials/samegame/samegame3/samegame.qml | 14 +++--- .../samegame/samegame4/content/Button.qml | 17 +++++-- .../samegame/samegame4/content/Dialog.qml | 57 ++++++++++++++++------ .../samegame/samegame4/content/samegame.js | 17 ++++--- .../tutorials/samegame/samegame4/samegame.qml | 38 +++++---------- 19 files changed, 208 insertions(+), 118 deletions(-) diff --git a/doc/src/declarative/advtutorial.qdoc b/doc/src/declarative/advtutorial.qdoc index 42ce246..7d2967e 100644 --- a/doc/src/declarative/advtutorial.qdoc +++ b/doc/src/declarative/advtutorial.qdoc @@ -109,12 +109,16 @@ Notice the anchors for the \c Item, \c Button and \c Text elements are set using \section2 Adding \c Button and \c Block components -The \c Button item in the code above is defined in a separate file named \c Button.qml. +The \c Button item in the code above is defined in a separate component file named \c Button.qml. To create a functional button, we use the QML elements \l Text and \l MouseArea inside a \l Rectangle. Here is the \c Button.qml code: \snippet declarative/tutorials/samegame/samegame1/Button.qml 0 +This essentially defines a rectangle that contains text and can be clicked. The \l MouseArea +has an \c onClicked() handler that is implemented to emit the \c clicked() signal of the +\c container when the area is clicked. + In Same Game, the screen is filled with small blocks when the game begins. Each block is just an item that contains an image. The block code is defined in a separate \c Block.qml file: @@ -226,14 +230,14 @@ until it is won or lost. To do this, we have added the following functions to \c samegame.js: \list -\o function \c{handleClick(x,y)} -\o function \c{floodFill(xIdx,yIdx,type)} -\o function \c{shuffleDown()} -\o function \c{victoryCheck()} -\o function \c{floodMoveCheck(xIdx, yIdx, type)} +\o \c{handleClick(x,y)} +\o \c{floodFill(xIdx,yIdx,type)} +\o \c{shuffleDown()} +\o \c{victoryCheck()} +\o \c{floodMoveCheck(xIdx, yIdx, type)} \endlist -As this is a tutorial about QML, not game design, we will only discuss \c handleClick() and \c victoryCheck() below since they interface directly with the QML elements. Note that although the game logic here is written in JavaScript, it could have been written in C++ and then exposed to JavaScript. +As this is a tutorial about QML, not game design, we will only discuss \c handleClick() and \c victoryCheck() below since they interface directly with the QML elements. Note that although the game logic here is written in JavaScript, it could have been written in C++ and then exposed to QML. \section3 Enabling mouse click interaction @@ -269,6 +273,8 @@ And this is how it is used in the main \c samegame.qml file: \snippet declarative/tutorials/samegame/samegame3/samegame.qml 2 +We give the dialog a \l {Item::z}{z} value of 100 to ensure it is displayed on top of our other components. The default \c z value for an item is 0. + \section3 A dash of color @@ -383,15 +389,41 @@ The theme change here is produced simply by replacing the block images. This can Another feature we might want to add to the game is a method of storing and retrieving high scores. -In \c samegame.qml we now pop up a dialog when the game is over and requests the player's name so it can be added to a High Scores table. The dialog is created using \c Dialog.qml: +To do this, we will show a dialog when the game is over to request the player's name and add it to a High Scores table. +This requires a few changes to \c Dialog.qml. In addition to a \c Text element, it now has a +\c TextInput child item for receiving keyboard text input: + +\snippet declarative/tutorials/samegame/samegame4/content/Dialog.qml 0 +\dots 4 +\snippet declarative/tutorials/samegame/samegame4/content/Dialog.qml 2 +\dots 4 +\snippet declarative/tutorials/samegame/samegame4/content/Dialog.qml 3 + +We'll also add a \c showWithInput() function. The text input will only be visible if this function +is called instead of \c show(). When the dialog is closed, it emits a \c closed() signal, and +other elements can retrieve the text entered by the user through an \c inputText property: + +\snippet declarative/tutorials/samegame/samegame4/content/Dialog.qml 0 +\snippet declarative/tutorials/samegame/samegame4/content/Dialog.qml 1 +\dots 4 +\snippet declarative/tutorials/samegame/samegame4/content/Dialog.qml 3 + +Now the dialog can be used in \c samegame.qml: \snippet declarative/tutorials/samegame/samegame4/samegame.qml 0 -When the dialog is closed, we call the new \c saveHighScore() function in \c samegame.js, which stores the high score locally in an SQL database and also send the score to an online database if possible. +When the dialog emits the \c closed signal, we call the new \c saveHighScore() function in \c samegame.js, which stores the high score locally in an SQL database and also send the score to an online database if possible. +The \c nameInputDialog is activated in the \c victoryCheck() function in \c samegame.js: + +\snippet declarative/tutorials/samegame/samegame4/content/samegame.js 3 +\dots 4 +\snippet declarative/tutorials/samegame/samegame4/content/samegame.js 4 \section3 Storing high scores offline +Now we need to implement the functionality to actually save the High Scores table. + Here is the \c saveHighScore() function in \c samegame.js: \snippet declarative/tutorials/samegame/samegame4/content/samegame.js 2 diff --git a/doc/src/declarative/tutorial.qdoc b/doc/src/declarative/tutorial.qdoc index 1a93d05..4cfb999 100644 --- a/doc/src/declarative/tutorial.qdoc +++ b/doc/src/declarative/tutorial.qdoc @@ -86,7 +86,7 @@ Here is the QML code for the application: \section2 Import First, we need to import the types that we need for this example. Most QML files will import the built-in QML -types (like \l{Rectangle}, \l{Image}, ...) that come with Qt with: +types (like \l{Rectangle}, \l{Image}, ...) that come with Qt, using: \snippet examples/declarative/tutorials/helloworld/tutorial1.qml 3 @@ -95,7 +95,7 @@ types (like \l{Rectangle}, \l{Image}, ...) that come with Qt with: \snippet examples/declarative/tutorials/helloworld/tutorial1.qml 1 We declare a root element of type \l{Rectangle}. It is one of the basic building blocks you can use to create an application in QML. -We give it an \c{id} to be able to refer to it later. In this case, we call it \e page. +We give it an \c{id} to be able to refer to it later. In this case, we call it "page". We also set the \c width, \c height and \c color properties. The \l{Rectangle} element contains many other properties (such as \c x and \c y), but these are left at their default values. @@ -103,15 +103,16 @@ The \l{Rectangle} element contains many other properties (such as \c x and \c y) \snippet examples/declarative/tutorials/helloworld/tutorial1.qml 2 -We add a \l Text element as a child of our root element that will display the text 'Hello world!'. +We add a \l Text element as a child of the root Rectangle element that displays the text 'Hello world!'. The \c y property is used to position the text vertically at 30 pixels from the top of its parent. -The \c font.pointSize and \c font.bold properties are related to fonts and use the \l{dot properties}{dot notation}. - The \c anchors.horizontalCenter property refers to the horizontal center of an element. In this case, we specify that our text element should be horizontally centered in the \e page element (see \l{anchor-layout}{Anchor-based Layout}). +The \c font.pointSize and \c font.bold properties are related to fonts and use the \l{dot properties}{dot notation}. + + \section2 Viewing the example To view what you have created, run the \l{Qt Declarative UI Runtime}{qml} tool (located in the \c bin directory) with your filename as the first argument. @@ -134,10 +135,10 @@ This chapter adds a color picker to change the color of the text. \image declarative-tutorial2.png Our color picker is made of six cells with different colors. -To avoid writing the same code multiple times, we first create a new \c Cell component. +To avoid writing the same code multiple times for each cell, we create a new \c Cell component. A component provides a way of defining a new type that we can re-use in other QML files. A QML component is like a black-box and interacts with the outside world through properties, signals and slots and is generally -defined in its own QML file (for more details, see \l {Defining new Components}). +defined in its own QML file. (For more details, see \l {Defining new Components}). The component's filename must always start with a capital letter. Here is the QML code for \c Cell.qml: diff --git a/examples/declarative/tutorials/helloworld/tutorial1.qml b/examples/declarative/tutorials/helloworld/tutorial1.qml index 5e27b45..04cd155 100644 --- a/examples/declarative/tutorials/helloworld/tutorial1.qml +++ b/examples/declarative/tutorials/helloworld/tutorial1.qml @@ -14,8 +14,9 @@ Rectangle { Text { id: helloText text: "Hello world!" + y: 30 + anchors.horizontalCenter: page.horizontalCenter font.pointSize: 24; font.bold: true - y: 30; anchors.horizontalCenter: page.horizontalCenter } //![2] } diff --git a/examples/declarative/tutorials/helloworld/tutorial2.qml b/examples/declarative/tutorials/helloworld/tutorial2.qml index 085efa4..66be509 100644 --- a/examples/declarative/tutorials/helloworld/tutorial2.qml +++ b/examples/declarative/tutorials/helloworld/tutorial2.qml @@ -9,8 +9,9 @@ Rectangle { Text { id: helloText text: "Hello world!" + y: 30 + anchors.horizontalCenter: page.horizontalCenter font.pointSize: 24; font.bold: true - y: 30; anchors.horizontalCenter: page.horizontalCenter } Grid { diff --git a/examples/declarative/tutorials/helloworld/tutorial3.qml b/examples/declarative/tutorials/helloworld/tutorial3.qml index 4bf4970..041d9a9 100644 --- a/examples/declarative/tutorials/helloworld/tutorial3.qml +++ b/examples/declarative/tutorials/helloworld/tutorial3.qml @@ -9,8 +9,9 @@ Rectangle { Text { id: helloText text: "Hello world!" + y: 30 + anchors.horizontalCenter: page.horizontalCenter font.pointSize: 24; font.bold: true - y: 30; anchors.horizontalCenter: page.horizontalCenter //![1] MouseArea { id: mouseArea; anchors.fill: parent } diff --git a/examples/declarative/tutorials/samegame/samegame1/Block.qml b/examples/declarative/tutorials/samegame/samegame1/Block.qml index a23654b..11fd844 100644 --- a/examples/declarative/tutorials/samegame/samegame1/Block.qml +++ b/examples/declarative/tutorials/samegame/samegame1/Block.qml @@ -7,7 +7,7 @@ Item { Image { id: img anchors.fill: parent - source: "../shared/pics/redStone.png"; + source: "../shared/pics/redStone.png" } } //![0] diff --git a/examples/declarative/tutorials/samegame/samegame1/Button.qml b/examples/declarative/tutorials/samegame/samegame1/Button.qml index e84b1ce..96a80eb 100644 --- a/examples/declarative/tutorials/samegame/samegame1/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame1/Button.qml @@ -8,9 +8,9 @@ Rectangle { signal clicked - width: buttonLabel.width + 20; height: buttonLabel.height + 6 - smooth: true + width: buttonLabel.width + 20; height: buttonLabel.height + 5 border { width: 1; color: Qt.darker(activePalette.button) } + smooth: true radius: 8 // color the button with a gradient @@ -27,8 +27,17 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: container.clicked(); + } - Text { id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText } + Text { + id: buttonLabel + anchors.centerIn: container + color: activePalette.buttonText + text: container.text + } } //![0] diff --git a/examples/declarative/tutorials/samegame/samegame1/samegame.qml b/examples/declarative/tutorials/samegame/samegame1/samegame.qml index b6e01fd..f2974be 100644 --- a/examples/declarative/tutorials/samegame/samegame1/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame1/samegame.qml @@ -22,21 +22,20 @@ Rectangle { Rectangle { id: toolBar - width: parent.width; height: 32 + width: parent.width; height: 30 color: activePalette.window anchors.bottom: screen.bottom Button { - anchors { left: parent.left; leftMargin: 3; verticalCenter: parent.verticalCenter } + anchors { left: parent.left; verticalCenter: parent.verticalCenter } text: "New Game" onClicked: console.log("This doesn't do anything yet...") } Text { id: score - anchors { right: parent.right; rightMargin: 3; verticalCenter: parent.verticalCenter } + anchors { right: parent.right; verticalCenter: parent.verticalCenter } text: "Score: Who knows?" - font.bold: true } } } diff --git a/examples/declarative/tutorials/samegame/samegame2/Block.qml b/examples/declarative/tutorials/samegame/samegame2/Block.qml index 4e71e60..39da84e 100644 --- a/examples/declarative/tutorials/samegame/samegame2/Block.qml +++ b/examples/declarative/tutorials/samegame/samegame2/Block.qml @@ -6,6 +6,6 @@ Item { Image { id: img anchors.fill: parent - source: "../shared/pics/redStone.png"; + source: "../shared/pics/redStone.png" } } diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml index 737d886..4ed856b 100644 --- a/examples/declarative/tutorials/samegame/samegame2/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml @@ -7,9 +7,9 @@ Rectangle { signal clicked - width: buttonLabel.width + 20; height: buttonLabel.height + 6 - smooth: true + width: buttonLabel.width + 20; height: buttonLabel.height + 5 border { width: 1; color: Qt.darker(activePalette.button) } + smooth: true radius: 8 // color the button with a gradient @@ -26,7 +26,16 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: container.clicked(); + } - Text { id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText } + Text { + id: buttonLabel + anchors.centerIn: container + color: activePalette.buttonText + text: container.text + } } diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.qml b/examples/declarative/tutorials/samegame/samegame2/samegame.qml index a7d1fba..9b4d4d5 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.qml @@ -30,7 +30,7 @@ Rectangle { //![1] Button { - anchors { left: parent.left; leftMargin: 3; verticalCenter: parent.verticalCenter } + anchors { left: parent.left; verticalCenter: parent.verticalCenter } text: "New Game" onClicked: SameGame.startNewGame() } @@ -38,9 +38,8 @@ Rectangle { Text { id: score - anchors { right: parent.right; rightMargin: 3; verticalCenter: parent.verticalCenter } + anchors { right: parent.right; verticalCenter: parent.verticalCenter } text: "Score: Who knows?" - font.bold: true } } } diff --git a/examples/declarative/tutorials/samegame/samegame3/Button.qml b/examples/declarative/tutorials/samegame/samegame3/Button.qml index 737d886..4ed856b 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Button.qml @@ -7,9 +7,9 @@ Rectangle { signal clicked - width: buttonLabel.width + 20; height: buttonLabel.height + 6 - smooth: true + width: buttonLabel.width + 20; height: buttonLabel.height + 5 border { width: 1; color: Qt.darker(activePalette.button) } + smooth: true radius: 8 // color the button with a gradient @@ -26,7 +26,16 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: container.clicked(); + } - Text { id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText } + Text { + id: buttonLabel + anchors.centerIn: container + color: activePalette.buttonText + text: container.text + } } diff --git a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml index 15b3b2f..3efed2f 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml @@ -2,31 +2,30 @@ import Qt 4.7 Rectangle { - id: page + id: container - signal closed - - function forceClose() { - page.closed(); - page.opacity = 0; + function show(text) { + dialogText.text = text; + container.opacity = 1; } - function show(txt) { - dialogText.text = txt; - page.opacity = 1; + function hide() { + container.opacity = 0; } - width: dialogText.width + 20; height: dialogText.height + 20 - color: "white" - border.width: 1 + width: dialogText.width + 20 + height: dialogText.height + 20 opacity: 0 - Behavior on opacity { - NumberAnimation { duration: 1000 } + Text { + id: dialogText + anchors.centerIn: parent + text: "" } - Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" } - - MouseArea { anchors.fill: parent; onClicked: forceClose(); } + MouseArea { + anchors.fill: parent + onClicked: hide(); + } } //![0] diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.js b/examples/declarative/tutorials/samegame/samegame3/samegame.js index 4256aee..84439fc 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.js @@ -17,7 +17,7 @@ function startNewGame() { maxIndex = maxRow * maxColumn; //Close dialogs - dialog.forceClose(); + dialog.hide(); //Initialize Board board = new Array(maxIndex); @@ -59,10 +59,9 @@ function createBlock(column, row) { return true; } -var fillFound; -//Set after a floodFill call to the number of blocks found -var floodBoard; -//Set to 1 if the floodFill reaches off that node +var fillFound; //Set after a floodFill call to the number of blocks found +var floodBoard; //Set to 1 if the floodFill reaches off that node + //![1] function handleClick(xPos, yPos) { var column = Math.floor(xPos / gameCanvas.blockSize); diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.qml b/examples/declarative/tutorials/samegame/samegame3/samegame.qml index 50f9d5d..ac93eb1 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.qml @@ -30,7 +30,6 @@ Rectangle { width: parent.width - (parent.width % blockSize) height: parent.height - (parent.height % blockSize) anchors.centerIn: parent - z: 20 MouseArea { anchors.fill: parent @@ -41,26 +40,29 @@ Rectangle { } //![2] - Dialog { id: dialog; anchors.centerIn: parent; z: 21 } + Dialog { + id: dialog + anchors.centerIn: parent + z: 100 + } //![2] Rectangle { id: toolBar - width: parent.width; height: 32 + width: parent.width; height: 30 color: activePalette.window anchors.bottom: screen.bottom Button { - anchors { left: parent.left; leftMargin: 3; verticalCenter: parent.verticalCenter } + anchors { left: parent.left; verticalCenter: parent.verticalCenter } text: "New Game" onClicked: SameGame.startNewGame() } Text { id: score - anchors { right: parent.right; rightMargin: 3; verticalCenter: parent.verticalCenter } + anchors { right: parent.right; verticalCenter: parent.verticalCenter } text: "Score: Who knows?" - font.bold: true } } } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml index 737d886..4ed856b 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml @@ -7,9 +7,9 @@ Rectangle { signal clicked - width: buttonLabel.width + 20; height: buttonLabel.height + 6 - smooth: true + width: buttonLabel.width + 20; height: buttonLabel.height + 5 border { width: 1; color: Qt.darker(activePalette.button) } + smooth: true radius: 8 // color the button with a gradient @@ -26,7 +26,16 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: container.clicked(); + } - Text { id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText } + Text { + id: buttonLabel + anchors.centerIn: container + color: activePalette.buttonText + text: container.text + } } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml index 6848534..2f45362 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml @@ -1,30 +1,59 @@ import Qt 4.7 +//![0] Rectangle { - id: page + id: container +//![0] +//![1] + property string inputText: textInput.text signal closed - function forceClose() { - page.closed(); - page.opacity = 0; + function show(text) { + dialogText.text = text; + container.opacity = 1; + textInput.opacity = 0; } - function show(txt) { - dialogText.text = txt; - page.opacity = 1; + function showWithInput(text) { + show(text); + textInput.opacity = 1; + textInput.text = "" } - width: dialogText.width + 20; height: dialogText.height + 20 - color: "white" - border.width: 1 + function hide() { + container.opacity = 0; + container.closed(); + } +//![1] + + width: dialogText.width + textInput.width + 20 + height: dialogText.height + 20 opacity: 0 - Behavior on opacity { - NumberAnimation { duration: 1000 } + Text { + id: dialogText + anchors { verticalCenter: parent.verticalCenter; left: parent.left; leftMargin: 10 } + text: "" + } + +//![2] + TextInput { + id: textInput + anchors { verticalCenter: parent.verticalCenter; left: dialogText.right } + width: 80 + focus: true + text: "" + + onAccepted: container.hide() // close dialog when Enter is pressed } +//![2] - Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" } + MouseArea { + anchors.fill: parent + onClicked: hide(); + } - MouseArea { anchors.fill: parent; onClicked: forceClose(); } +//![3] } +//![3] diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js index 961cd66..06d21e6 100755 --- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js @@ -25,8 +25,8 @@ function startNewGame() { maxIndex = maxRow * maxColumn; //Close dialogs - nameInputDialog.forceClose(); - dialog.forceClose(); + nameInputDialog.hide(); + dialog.hide(); //Initialize Board board = new Array(maxIndex); @@ -72,10 +72,9 @@ function createBlock(column, row) { return true; } -var fillFound; -//Set after a floodFill call to the number of blocks found -var floodBoard; -//Set to 1 if the floodFill reaches off that node +var fillFound; //Set after a floodFill call to the number of blocks found +var floodBoard; //Set to 1 if the floodFill reaches off that node + function handleClick(xPos, yPos) { var column = Math.floor(xPos / gameCanvas.blockSize); var row = Math.floor(yPos / gameCanvas.blockSize); @@ -157,7 +156,9 @@ function shuffleDown() { } } +//![3] function victoryCheck() { +//![3] //Award bonus points if no blocks left var deservesBonus = true; for (var column = maxColumn - 1; column >= 0; column--) @@ -166,12 +167,14 @@ function victoryCheck() { if (deservesBonus) gameCanvas.score += 500; +//![4] //Check whether game has finished if (deservesBonus || !(floodMoveCheck(0, maxRow - 1, -1))) { gameDuration = new Date() - gameDuration; - nameInputDialog.show("You won! Please enter your name: "); + nameInputDialog.showWithInput("You won! Please enter your name: "); } } +//![4] //only floods up and right, to see if it can find adjacent same-typed blocks function floodMoveCheck(column, row, type) { diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml index 404af0a..feb61fd 100644 --- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml @@ -25,7 +25,7 @@ Rectangle { property int score: 0 property int blockSize: 40 - z: 20; anchors.centerIn: parent + anchors.centerIn: parent width: parent.width - (parent.width % blockSize); height: parent.height - (parent.height % blockSize); @@ -35,53 +35,41 @@ Rectangle { } } - Dialog { id: dialog; anchors.centerIn: parent; z: 21 } + Dialog { + id: dialog + anchors.centerIn: parent + z: 100 + } //![0] Dialog { id: nameInputDialog - anchors.centerIn: parent - z: 22 + z: 100 - Text { - id: dialogText - opacity: 0 - text: " You won! Please enter your name:" - } - - TextInput { - id: nameInput - width: 72 - anchors { verticalCenter: parent.verticalCenter; left: dialogText.right } - focus: true - - onAccepted: { - if (nameInputDialog.opacity == 1 && nameInput.text != "") - SameGame.saveHighScore(nameInput.text); - nameInputDialog.forceClose(); - } + onClosed: { + if (nameInputDialog.inputText != "") + SameGame.saveHighScore(nameInputDialog.inputText); } } //![0] Rectangle { id: toolBar - width: parent.width; height: 32 + width: parent.width; height: 30 color: activePalette.window anchors.bottom: screen.bottom Button { - anchors { left: parent.left; leftMargin: 3; verticalCenter: parent.verticalCenter } + anchors { left: parent.left; verticalCenter: parent.verticalCenter } text: "New Game" onClicked: SameGame.startNewGame() } Text { id: score - anchors { right: parent.right; rightMargin: 3; verticalCenter: parent.verticalCenter } + anchors { right: parent.right; verticalCenter: parent.verticalCenter } text: "Score: " + gameCanvas.score - font.bold: true } } } -- cgit v0.12 From c76d98da76fd687d2953f0026b16bca3c7fcf485 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 5 May 2010 13:24:25 +1000 Subject: Allow translations without extra command-line args, and document both. --- doc/src/declarative/qmlruntime.qdoc | 17 +++++++++ tools/qml/qmlruntime.cpp | 72 +++++++++++++++++++++++-------------- tools/qml/qmlruntime.h | 6 ++++ 3 files changed, 68 insertions(+), 27 deletions(-) diff --git a/doc/src/declarative/qmlruntime.qdoc b/doc/src/declarative/qmlruntime.qdoc index a724c7d..23c5c32 100644 --- a/doc/src/declarative/qmlruntime.qdoc +++ b/doc/src/declarative/qmlruntime.qdoc @@ -112,6 +112,23 @@ When run with the \c -help option, qml shows available options. + \section2 Translations + + When the runtime loads an initial QML file, it will install a translation file from + a "i18n" subdirectory relative to that initial QML file. The actual translation file + loaded will be according to the system locale and have the form + "qml_.qm", where is a two-letter ISO 639 language, + such as "qml_fr.qm", optionally followed by an underscore and an uppercase two-letter ISO 3166 country + code, such as "qml_fr_FR.qm" or "qml_fr_CA.qm". + + Such files can be created using \l{Qt Linguist}. + + See \l{scripting.html#internationalization} for information about how to make + the JavaScript in QML files use translatable strings. + + Additionally, the QML runtime will load translation files specified on the + command line via the \c -translation option. + \section2 Dummy Data The secondary use of the qml runtime is to allow QML files to be viewed with diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 008f163..da31284 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -464,6 +465,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) , frame_stream(0), scaleSkin(true), mb(0) , portraitOrientation(0), landscapeOrientation(0) , m_scriptOptions(0), tester(0), useQmlFileBrowser(true) + , translator(0) { QDeclarativeViewer::registerTypes(); setWindowTitle(tr("Qt Qml Runtime")); @@ -937,6 +939,46 @@ void QDeclarativeViewer::launch(const QString& file_or_url) QMetaObject::invokeMethod(this, "open", Qt::QueuedConnection, Q_ARG(QString, file_or_url)); } +void QDeclarativeViewer::loadTranslationFile(const QString& directory) +{ + if (!translator) { + translator = new QTranslator(this); + QApplication::installTranslator(translator); + } + + translator->load(QLatin1String("qml_" )+QLocale::system().name(), directory + QLatin1String("/i18n")); +} + +void QDeclarativeViewer::loadDummyDataFiles(const QString& directory) +{ + QDir dir(directory+"/dummydata", "*.qml"); + QStringList list = dir.entryList(); + for (int i = 0; i < list.size(); ++i) { + QString qml = list.at(i); + QFile f(dir.filePath(qml)); + f.open(QIODevice::ReadOnly); + QByteArray data = f.readAll(); + QDeclarativeComponent comp(canvas->engine()); + comp.setData(data, QUrl()); + QObject *dummyData = comp.create(); + + if(comp.isError()) { + QList errors = comp.errors(); + foreach (const QDeclarativeError &error, errors) { + qWarning() << error; + } + if (tester) tester->executefailure(); + } + + if (dummyData) { + qWarning() << "Loaded dummy data:" << dir.filePath(qml); + qml.truncate(qml.length()-4); + canvas->rootContext()->setContextProperty(qml, dummyData); + dummyData->setParent(this); + } + } +} + bool QDeclarativeViewer::open(const QString& file_or_url) { currentFileOrUrl = file_or_url; @@ -966,39 +1008,15 @@ bool QDeclarativeViewer::open(const QString& file_or_url) QString fileName = url.toLocalFile(); if (!fileName.isEmpty()) { - QFileInfo fi(fileName); if (fi.exists()) { if (fi.suffix().toLower() != QLatin1String("qml")) { qWarning() << "qml cannot open non-QML file" << fileName; return false; } - QDir dir(fi.path()+"/dummydata", "*.qml"); - QStringList list = dir.entryList(); - for (int i = 0; i < list.size(); ++i) { - QString qml = list.at(i); - QFile f(dir.filePath(qml)); - f.open(QIODevice::ReadOnly); - QByteArray data = f.readAll(); - QDeclarativeComponent comp(canvas->engine()); - comp.setData(data, QUrl()); - QObject *dummyData = comp.create(); - - if(comp.isError()) { - QList errors = comp.errors(); - foreach (const QDeclarativeError &error, errors) { - qWarning() << error; - } - if (tester) tester->executefailure(); - } - - if (dummyData) { - qWarning() << "Loaded dummy data:" << dir.filePath(qml); - qml.truncate(qml.length()-4); - ctxt->setContextProperty(qml, dummyData); - dummyData->setParent(this); - } - } + QFileInfo fi(fileName); + loadTranslationFile(fi.path()); + loadDummyDataFiles(fi.path()); } else { qWarning() << "qml cannot find file:" << fileName; return false; diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 2a0a07d..0b23303 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -59,6 +59,7 @@ class QDeclarativeTester; class QNetworkReply; class QNetworkCookieJar; class NetworkAccessManagerFactory; +class QTranslator; class QDeclarativeViewer #if defined(Q_OS_SYMBIAN) @@ -192,6 +193,11 @@ private: NetworkAccessManagerFactory *namFactory; bool useQmlFileBrowser; + + QTranslator *translator; + void loadTranslationFile(const QString& directory); + + void loadDummyDataFiles(const QString& directory); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeViewer::ScriptOptions) -- cgit v0.12 From 9719866c686805d69b0026f555c97594e09c836f Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 5 May 2010 13:35:11 +1000 Subject: Example i18n. --- examples/declarative/i18n/i18n.qml | 33 ++++++++++++++++++++++++++++ examples/declarative/i18n/i18n/base.ts | 12 ++++++++++ examples/declarative/i18n/i18n/qml_en_AU.qm | Bin 0 -> 81 bytes examples/declarative/i18n/i18n/qml_en_AU.ts | 12 ++++++++++ examples/declarative/i18n/i18n/qml_fr.qm | Bin 0 -> 85 bytes examples/declarative/i18n/i18n/qml_fr.ts | 12 ++++++++++ 6 files changed, 69 insertions(+) create mode 100644 examples/declarative/i18n/i18n.qml create mode 100644 examples/declarative/i18n/i18n/base.ts create mode 100644 examples/declarative/i18n/i18n/qml_en_AU.qm create mode 100644 examples/declarative/i18n/i18n/qml_en_AU.ts create mode 100644 examples/declarative/i18n/i18n/qml_fr.qm create mode 100644 examples/declarative/i18n/i18n/qml_fr.ts diff --git a/examples/declarative/i18n/i18n.qml b/examples/declarative/i18n/i18n.qml new file mode 100644 index 0000000..3b1279a --- /dev/null +++ b/examples/declarative/i18n/i18n.qml @@ -0,0 +1,33 @@ +import Qt 4.7 + +// +// The QML runtime automatically loads a translation from the i18n subdirectory of the root +// QML file, based on the system language. +// +// The files are created/updated by running: +// +// lupdate i18n.qml -ts i18n/*.ts +// +// The .ts files can then be edited with Linguist: +// +// linguist i18n/qml_fr.ts +// +// The run-time translation files are then generaeted by running: +// +// lrelease i18n/*.ts +// +// Translations for new languages are created by copying i18n/base.ts to i18n/qml_.ts +// and editing the result with Linguist. +// + +Column { + Text { + text: "If a translation is available for the system language (eg. Franch) then the string below will translated (eg. 'Bonjour'). Otherwise is will show 'Hello'." + width: 200 + wrapMode: Text.WordWrap + } + Text { + text: qsTr("Hello") + font.pointSize: 25 + } +} diff --git a/examples/declarative/i18n/i18n/base.ts b/examples/declarative/i18n/i18n/base.ts new file mode 100644 index 0000000..82547a1 --- /dev/null +++ b/examples/declarative/i18n/i18n/base.ts @@ -0,0 +1,12 @@ + + + + + i18n + + + Hello + + + + diff --git a/examples/declarative/i18n/i18n/qml_en_AU.qm b/examples/declarative/i18n/i18n/qml_en_AU.qm new file mode 100644 index 0000000..fb8b710 Binary files /dev/null and b/examples/declarative/i18n/i18n/qml_en_AU.qm differ diff --git a/examples/declarative/i18n/i18n/qml_en_AU.ts b/examples/declarative/i18n/i18n/qml_en_AU.ts new file mode 100644 index 0000000..e991aff --- /dev/null +++ b/examples/declarative/i18n/i18n/qml_en_AU.ts @@ -0,0 +1,12 @@ + + + + + i18n + + + Hello + G'day + + + diff --git a/examples/declarative/i18n/i18n/qml_fr.qm b/examples/declarative/i18n/i18n/qml_fr.qm new file mode 100644 index 0000000..583562e Binary files /dev/null and b/examples/declarative/i18n/i18n/qml_fr.qm differ diff --git a/examples/declarative/i18n/i18n/qml_fr.ts b/examples/declarative/i18n/i18n/qml_fr.ts new file mode 100644 index 0000000..365abd9 --- /dev/null +++ b/examples/declarative/i18n/i18n/qml_fr.ts @@ -0,0 +1,12 @@ + + + + + i18n + + + Hello + Bonjour + + + -- cgit v0.12 From 846210c6381827396868d15cdbb6d42daabda147 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 5 May 2010 14:32:45 +1000 Subject: Don't start valuesource animations until all component objects have been completed. Task-number: QTBUG-9413 --- src/declarative/util/qdeclarativeanimation.cpp | 10 ++++++++++ src/declarative/util/qdeclarativeanimation_p.h | 1 + .../animation/pauseAnimation/pauseAnimation-visual.qml | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 4059522..d9abe71 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -178,6 +179,10 @@ void QDeclarativeAbstractAnimation::setRunning(bool r) d->running = r; if (r == false) d->avoidPropertyValueSourceStart = true; + else { + QDeclarativeEnginePrivate *engPriv = QDeclarativeEnginePrivate::get(qmlEngine(this)); + engPriv->registerFinalizedParserStatusObject(this, this->metaObject()->indexOfSlot("componentFinalized()")); + } return; } @@ -268,6 +273,11 @@ void QDeclarativeAbstractAnimation::componentComplete() { Q_D(QDeclarativeAbstractAnimation); d->componentComplete = true; +} + +void QDeclarativeAbstractAnimation::componentFinalized() +{ + Q_D(QDeclarativeAbstractAnimation); if (d->running) { d->running = false; setRunning(true); diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h index 40c893c..e7cd8a8 100644 --- a/src/declarative/util/qdeclarativeanimation_p.h +++ b/src/declarative/util/qdeclarativeanimation_p.h @@ -133,6 +133,7 @@ public: private Q_SLOTS: void timelineComplete(); + void componentFinalized(); private: virtual void setTarget(const QDeclarativeProperty &); diff --git a/tests/auto/declarative/qmlvisual/animation/pauseAnimation/pauseAnimation-visual.qml b/tests/auto/declarative/qmlvisual/animation/pauseAnimation/pauseAnimation-visual.qml index d82c6df..cc9a639 100644 --- a/tests/auto/declarative/qmlvisual/animation/pauseAnimation/pauseAnimation-visual.qml +++ b/tests/auto/declarative/qmlvisual/animation/pauseAnimation/pauseAnimation-visual.qml @@ -16,7 +16,7 @@ Rectangle { id: img source: "pics/qtlogo.png" x: 60-width/2 - y: 100 + y: 200-img.height SequentialAnimation on y { loops: Animation.Infinite NumberAnimation { @@ -24,7 +24,7 @@ Rectangle { easing.type: "InOutQuad" } NumberAnimation { - to: 100 + to: 200-img.height easing.type: "OutBounce" duration: 2000 } -- cgit v0.12 From ce9bc843443f2c61361afa75a62a7d39029557e6 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 5 May 2010 14:38:55 +1000 Subject: QList models now update their properties when they change. Task-number: QTBUG-10348 --- doc/src/declarative/qdeclarativemodels.qdoc | 11 +++++++++-- examples/declarative/objectlistmodel/dataobject.cpp | 10 ++++++++-- examples/declarative/objectlistmodel/dataobject.h | 8 ++++++-- examples/declarative/objectlistmodel/view.qml | 2 +- src/declarative/QmlChanges.txt | 4 ++++ .../graphicsitems/qdeclarativevisualitemmodel.cpp | 8 ++++++-- .../declarative/qdeclarativerepeater/data/objlist.qml | 2 +- .../qdeclarativerepeater/tst_qdeclarativerepeater.cpp | 19 ++++++++++++++----- 8 files changed, 49 insertions(+), 15 deletions(-) diff --git a/doc/src/declarative/qdeclarativemodels.qdoc b/doc/src/declarative/qdeclarativemodels.qdoc index 91acb3c..9b706a1 100644 --- a/doc/src/declarative/qdeclarativemodels.qdoc +++ b/doc/src/declarative/qdeclarativemodels.qdoc @@ -283,7 +283,9 @@ QDeclarativeContext *ctxt = view.rootContext(); ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); \endcode -The properties of the object may then be accessed in the delegate: +The QObject* is available as the \c modelData property. As a convenience, +the properties of the object are also made available directly in the +delegate's context: \code ListView { @@ -295,13 +297,18 @@ ListView { Rectangle { height: 25 width: 100 - color: model.color + color: model.modelData.color Text { text: name } } } } \endcode +Note the use of the fully qualified access to the \c color property. +The properties of the object are not replicated in the \c model +object, since they are easily available via the modelData +object. + Note: There is no way for the view to know that the contents of a QList have changed. If the QList is changed, it will be necessary to reset the model by calling QDeclarativeContext::setContextProperty() again. diff --git a/examples/declarative/objectlistmodel/dataobject.cpp b/examples/declarative/objectlistmodel/dataobject.cpp index 4c44ee4..14be1b9 100644 --- a/examples/declarative/objectlistmodel/dataobject.cpp +++ b/examples/declarative/objectlistmodel/dataobject.cpp @@ -59,7 +59,10 @@ QString DataObject::name() const void DataObject::setName(const QString &name) { - m_name = name; + if (name != m_name) { + m_name = name; + emit nameChanged(); + } } QString DataObject::color() const @@ -69,5 +72,8 @@ QString DataObject::color() const void DataObject::setColor(const QString &color) { - m_color = color; + if (color != m_color) { + m_color = color; + emit colorChanged(); + } } diff --git a/examples/declarative/objectlistmodel/dataobject.h b/examples/declarative/objectlistmodel/dataobject.h index 6804474..852110d 100644 --- a/examples/declarative/objectlistmodel/dataobject.h +++ b/examples/declarative/objectlistmodel/dataobject.h @@ -48,8 +48,8 @@ class DataObject : public QObject { Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString color READ color WRITE setColor) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged) public: DataObject(QObject *parent=0); @@ -61,6 +61,10 @@ public: QString color() const; void setColor(const QString &color); +signals: + void nameChanged(); + void colorChanged(); + private: QString m_name; QString m_color; diff --git a/examples/declarative/objectlistmodel/view.qml b/examples/declarative/objectlistmodel/view.qml index 908e388..2b8383f 100644 --- a/examples/declarative/objectlistmodel/view.qml +++ b/examples/declarative/objectlistmodel/view.qml @@ -9,7 +9,7 @@ ListView { Rectangle { height: 25 width: 100 - color: model.color + color: model.modelData.color Text { text: name } } } diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 7218f78..dfc4244 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -4,6 +4,10 @@ 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 +QList models no longer provide properties in model object. The +properties are now updated when the object changes. An object's property +"foo" may now be accessed as "foo", modelData.foo" or model.modelData.foo" + C++ API ------- diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 2addc77..f01d4c2 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -437,8 +437,7 @@ int QDeclarativeVisualDataModelDataMetaObject::createProperty(const char *name, if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { if (model->m_listAccessor->type() == QDeclarativeListAccessor::ListProperty) { model->ensureRoles(); - QObject *object = model->m_listAccessor->at(data->m_index).value(); - if (object && (object->property(name).isValid() || qstrcmp(name,"modelData")==0)) + if (qstrcmp(name,"modelData") == 0) return QDeclarativeOpenMetaObject::createProperty(name, type); } } @@ -1029,6 +1028,11 @@ QDeclarativeItem *QDeclarativeVisualDataModel::item(int index, const QByteArray if (!ccontext) ccontext = qmlContext(this); QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this); + if ((!d->m_listModelInterface || !d->m_abstractItemModel) && d->m_listAccessor + && d->m_listAccessor->type() == QDeclarativeListAccessor::ListProperty) { + ctxt->setContextObject(d->m_listAccessor->at(index).value()); + ctxt = new QDeclarativeContext(ctxt, ctxt); + } ctxt->setContextProperty(QLatin1String("model"), data); ctxt->setContextObject(data); d->m_completePending = false; diff --git a/tests/auto/declarative/qdeclarativerepeater/data/objlist.qml b/tests/auto/declarative/qdeclarativerepeater/data/objlist.qml index 17c5d8d..e1bd2e2 100644 --- a/tests/auto/declarative/qdeclarativerepeater/data/objlist.qml +++ b/tests/auto/declarative/qdeclarativerepeater/data/objlist.qml @@ -14,7 +14,7 @@ Rectangle { property int instantiated: 0 Component { Item{ - Component.onCompleted: {if(index!=model.idx) repeater.errors += 1; repeater.instantiated++} + Component.onCompleted: {if(index!=modelData.idx) repeater.errors += 1; repeater.instantiated++} } } } diff --git a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp index 8be7d80..e6b2fdd 100644 --- a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp +++ b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp @@ -185,15 +185,24 @@ void tst_QDeclarativeRepeater::numberModel() delete canvas; } +class MyObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int idx READ idx CONSTANT) +public: + MyObject(int i) : QObject(), m_idx(i) {} + + int idx() const { return m_idx; } + + int m_idx; +}; + void tst_QDeclarativeRepeater::objectList() { QDeclarativeView *canvas = createView(); - QObjectList data; - for(int i=0; i<100; i++){ - data << new QObject(); - data.back()->setProperty("idx", i); - } + for(int i=0; i<100; i++) + data << new MyObject(i); QDeclarativeContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testData", QVariant::fromValue(data)); -- cgit v0.12 From de5728c826d44808529a681472b899f30e18e325 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 5 May 2010 14:51:11 +1000 Subject: doc Task-number: QTBUG-10386 --- .../graphicsitems/qdeclarativeborderimage.cpp | 14 +-- .../graphicsitems/qdeclarativeflickable.cpp | 14 +-- .../graphicsitems/qdeclarativeflipable.cpp | 2 +- .../graphicsitems/qdeclarativegridview.cpp | 18 ++-- .../graphicsitems/qdeclarativeimage.cpp | 20 ++-- src/declarative/graphicsitems/qdeclarativeitem.cpp | 2 +- .../graphicsitems/qdeclarativelistview.cpp | 18 ++-- .../graphicsitems/qdeclarativeloader.cpp | 8 +- .../graphicsitems/qdeclarativepathview.cpp | 8 +- .../graphicsitems/qdeclarativepositioners.cpp | 14 +-- src/declarative/graphicsitems/qdeclarativetext.cpp | 73 +++++++------ .../graphicsitems/qdeclarativetextedit.cpp | 46 ++++----- .../graphicsitems/qdeclarativetextinput.cpp | 28 ++--- src/declarative/qml/qdeclarativecomponent.cpp | 8 +- src/declarative/util/qdeclarativeanimation.cpp | 114 ++++++++++----------- src/declarative/util/qdeclarativefontloader.cpp | 8 +- .../util/qdeclarativesmoothedanimation.cpp | 6 +- .../util/qdeclarativesmoothedfollow.cpp | 6 +- src/declarative/util/qdeclarativexmllistmodel.cpp | 8 +- 19 files changed, 210 insertions(+), 205 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp index 14a2cab..018bd55 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp @@ -102,10 +102,10 @@ QDeclarativeBorderImage::~QDeclarativeBorderImage() This property holds the status of image loading. It can be one of: \list - \o Null - no image has been set - \o Ready - the image has been loaded - \o Loading - the image is currently being loaded - \o Error - an error occurred while loading the image + \o BorderImage.Null - no image has been set + \o BorderImage.Ready - the image has been loaded + \o BorderImage.Loading - the image is currently being loaded + \o BorderImage.Error - an error occurred while loading the image \endlist \sa progress @@ -300,9 +300,9 @@ QDeclarativeScaleGrid *QDeclarativeBorderImage::border() This property describes how to repeat or stretch the middle parts of the border image. \list - \o Stretch - Scale the image to fit to the available area. - \o Repeat - Tile the image until there is no more space. May crop the last image. - \o Round - Like Repeat, but scales the images down to ensure that the last image is not cropped. + \o BorderImage.Stretch - Scale the image to fit to the available area. + \o BorderImage.Repeat - Tile the image until there is no more space. May crop the last image. + \o BorderImage.Round - Like Repeat, but scales the images down to ensure that the last image is not cropped. \endlist */ QDeclarativeBorderImage::TileMode QDeclarativeBorderImage::horizontalTileMode() const diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 35aa0f8..3128851 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -587,13 +587,13 @@ QDeclarativeFlickableVisibleArea *QDeclarativeFlickable::visibleArea() This property determines which directions the view can be flicked. \list - \o AutoFlickDirection (default) - allows flicking vertically if the + \o Flickable.AutoFlickDirection (default) - allows flicking vertically if the \e contentHeight is not equal to the \e height of the Flickable. Allows flicking horizontally if the \e contentWidth is not equal to the \e width of the Flickable. - \o HorizontalFlick - allows flicking horizontally. - \o VerticalFlick - allows flicking vertically. - \o HorizontalAndVerticalFlick - allows flicking in both directions. + \o Flickable.HorizontalFlick - allows flicking horizontally. + \o Flickable.VerticalFlick - allows flicking vertically. + \o Flickable.HorizontalAndVerticalFlick - allows flicking in both directions. \endlist */ QDeclarativeFlickable::FlickDirection QDeclarativeFlickable::flickDirection() const @@ -1031,11 +1031,11 @@ void QDeclarativeFlickable::setOverShoot(bool o) The \c boundsBehavior can be one of: \list - \o \e StopAtBounds - the contents can not be dragged beyond the boundary + \o \e Flickable.StopAtBounds - the contents can not be dragged beyond the boundary of the flickable, and flicks will not overshoot. - \o \e DragOverBounds - the contents can be dragged beyond the boundary + \o \e Flickable.DragOverBounds - the contents can be dragged beyond the boundary of the Flickable, but flicks will not overshoot. - \o \e DragAndOvershootBounds (default) - the contents can be dragged + \o \e Flickable.DragAndOvershootBounds (default) - the contents can be dragged beyond the boundary of the Flickable, and can overshoot the boundary when flicked. \endlist diff --git a/src/declarative/graphicsitems/qdeclarativeflipable.cpp b/src/declarative/graphicsitems/qdeclarativeflipable.cpp index 85f40c3..e2fc809 100644 --- a/src/declarative/graphicsitems/qdeclarativeflipable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflipable.cpp @@ -167,7 +167,7 @@ void QDeclarativeFlipable::retransformBack() \qmlproperty enumeration Flipable::side The side of the Flippable currently visible. Possible values are \c - Front and \c Back. + Flippable.Front and \c Flippable.Back. */ QDeclarativeFlipable::Side QDeclarativeFlipable::side() const { diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 8fb3632..f55c483 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1280,17 +1280,17 @@ void QDeclarativeGridView::setHighlightMoveDuration(int duration) highlight range. Furthermore, the behaviour of the current item index will occur whether or not a highlight exists. - If highlightRangeMode is set to \e ApplyRange the view will + If highlightRangeMode is set to \e GridView.ApplyRange the view will attempt to maintain the highlight within the range, however the highlight can move outside of the range at the ends of the list or due to a mouse interaction. - If highlightRangeMode is set to \e StrictlyEnforceRange the highlight will never + If highlightRangeMode is set to \e GridView.StrictlyEnforceRange the highlight will never move outside of the range. This means that the current item will change if a keyboard or mouse action would cause the highlight to move outside of the range. - The default value is \e NoHighlightRange. + The default value is \e GridView.NoHighlightRange. Note that a valid range requires preferredHighlightEnd to be greater than or equal to preferredHighlightBegin. @@ -1348,10 +1348,10 @@ void QDeclarativeGridView::setHighlightRangeMode(HighlightRangeMode mode) \qmlproperty enumeration GridView::flow This property holds the flow of the grid. - Possible values are \c LeftToRight (default) and \c TopToBottom. + Possible values are \c GridView.LeftToRight (default) and \c GridView.TopToBottom. - If \a flow is \c LeftToRight, the view will scroll vertically. - If \a flow is \c TopToBottom, the view will scroll horizontally. + If \a flow is \c GridView.LeftToRight, the view will scroll vertically. + If \a flow is \c GridView.TopToBottom, the view will scroll horizontally. */ QDeclarativeGridView::Flow QDeclarativeGridView::flow() const { @@ -1474,10 +1474,10 @@ void QDeclarativeGridView::setCellHeight(int cellHeight) The allowed values are: \list - \o NoSnap (default) - the view will stop anywhere within the visible area. - \o SnapToRow - the view will settle with a row (or column for TopToBottom flow) + \o GridView.NoSnap (default) - the view will stop anywhere within the visible area. + \o GridView.SnapToRow - the view will settle with a row (or column for TopToBottom flow) aligned with the start of the view. - \o SnapOneRow - the view will settle no more than one row (or column for TopToBottom flow) + \o GridView.SnapOneRow - the view will settle no more than one row (or column for TopToBottom flow) away from the first visible row at the time the mouse button is released. This mode is particularly useful for moving one page at a time. \endlist diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 1c32b45..aeddb15 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -199,12 +199,12 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap) than the size of the item. \list - \o Stretch - the image is scaled to fit - \o PreserveAspectFit - the image is scaled uniformly to fit without cropping - \o PreserveAspectCrop - the image is scaled uniformly to fill, cropping if necessary - \o Tile - the image is duplicated horizontally and vertically - \o TileVertically - the image is stretched horizontally and tiled vertically - \o TileHorizontally - the image is stretched vertically and tiled horizontally + \o Image.Stretch - the image is scaled to fit + \o Image.PreserveAspectFit - the image is scaled uniformly to fit without cropping + \o Image.PreserveAspectCrop - the image is scaled uniformly to fill, cropping if necessary + \o Image.Tile - the image is duplicated horizontally and vertically + \o Image.TileVertically - the image is stretched horizontally and tiled vertically + \o Image.TileHorizontally - the image is stretched vertically and tiled horizontally \endlist \image declarative-image_fillMode.gif @@ -243,10 +243,10 @@ qreal QDeclarativeImage::paintedHeight() const This property holds the status of image loading. It can be one of: \list - \o Null - no image has been set - \o Ready - the image has been loaded - \o Loading - the image is currently being loaded - \o Error - an error occurred while loading the image + \o Image.Null - no image has been set + \o Image.Ready - the image has been loaded + \o Image.Loading - the image is currently being loaded + \o Image.Error - an error occurred while loading the image \endlist Note that a change in the status property does not cause anything to happen diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 14f6b4a..a0983cc 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1432,7 +1432,7 @@ QDeclarativeItem::~QDeclarativeItem() } \endqml - The default transform origin is \c Center. + The default transform origin is \c Item.Center. */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 0f3ee61..3b77ff8 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1690,17 +1690,17 @@ void QDeclarativeListView::setHighlightFollowsCurrentItem(bool autoHighlight) highlight range. Furthermore, the behaviour of the current item index will occur whether or not a highlight exists. - If highlightRangeMode is set to \e ApplyRange the view will + If highlightRangeMode is set to \e ListView.ApplyRange the view will attempt to maintain the highlight within the range, however the highlight can move outside of the range at the ends of the list or due to a mouse interaction. - If highlightRangeMode is set to \e StrictlyEnforceRange the highlight will never + If highlightRangeMode is set to \e ListView.StrictlyEnforceRange the highlight will never move outside of the range. This means that the current item will change if a keyboard or mouse action would cause the highlight to move outside of the range. - The default value is \e NoHighlightRange. + The default value is \e ListView.NoHighlightRange. Note that a valid range requires preferredHighlightEnd to be greater than or equal to preferredHighlightBegin. @@ -1780,9 +1780,9 @@ void QDeclarativeListView::setSpacing(qreal spacing) Possible values are \c Vertical (default) and \c Horizontal. - Vertical Example: + ListView.Vertical Example: \image trivialListView.png - Horizontal Example: + ListView.Horizontal Example: \image ListViewHorizontal.png */ QDeclarativeListView::Orientation QDeclarativeListView::orientation() const @@ -1996,17 +1996,17 @@ void QDeclarativeListView::setHighlightResizeDuration(int duration) The allowed values are: \list - \o NoSnap (default) - the view will stop anywhere within the visible area. - \o SnapToItem - the view will settle with an item aligned with the start of + \o ListView.NoSnap (default) - the view will stop anywhere within the visible area. + \o ListView.SnapToItem - the view will settle with an item aligned with the start of the view. - \o SnapOneItem - the view will settle no more than one item away from the first + \o ListView.SnapOneItem - the view will settle no more than one item away from the first visible item at the time the mouse button is released. This mode is particularly useful for moving one page at a time. \endlist snapMode does not affect the currentIndex. To update the currentIndex as the list is moved set \e highlightRangeMode - to \e StrictlyEnforceRange. + to \e ListView.StrictlyEnforceRange. \sa highlightRangeMode */ diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index 62fa4db..7edd53c 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -329,10 +329,10 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded() This property holds the status of QML loading. It can be one of: \list - \o Null - no QML source has been set - \o Ready - the QML source has been loaded - \o Loading - the QML source is currently being loaded - \o Error - an error occurred while loading the QML source + \o Loader.Null - no QML source has been set + \o Loader.Ready - the QML source has been loaded + \o Loader.Loading - the QML source is currently being loaded + \o Loader.Error - an error occurred while loading the QML source \endlist Note that a change in the status property does not cause anything to happen diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 7cb723c..9ae6f9d 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -618,12 +618,12 @@ QDeclarativeItem *QDeclarativePathView::highlightItem() These properties set the preferred range of the highlight (current item) within the view. The preferred values must be in the range 0.0-1.0. - If highlightRangeMode is set to \e ApplyRange the view will + If highlightRangeMode is set to \e PathView.ApplyRange the view will attempt to maintain the highlight within the range, however the highlight can move outside of the range at the ends of the path or due to a mouse interaction. - If highlightRangeMode is set to \e StrictlyEnforceRange the highlight will never + If highlightRangeMode is set to \e PathView.StrictlyEnforceRange the highlight will never move outside of the range. This means that the current item will change if a keyboard or mouse action would cause the highlight to move outside of the range. @@ -631,14 +631,14 @@ QDeclarativeItem *QDeclarativePathView::highlightItem() Note that this is the correct way to influence where the current item ends up when the view moves. For example, if you want the currently selected item to be in the middle of the path, then set the - highlight range to be 0.5,0.5 and highlightRangeMode to StrictlyEnforceRange. + highlight range to be 0.5,0.5 and highlightRangeMode to PathView.StrictlyEnforceRange. Then, when the path scrolls, the currently selected item will be the item at that position. This also applies to when the currently selected item changes - it will scroll to within the preferred highlight range. Furthermore, the behaviour of the current item index will occur whether or not a highlight exists. - The default value is \e StrictlyEnforceRange. + The default value is \e PathView.StrictlyEnforceRange. Note that a valid range requires preferredHighlightEnd to be greater than or equal to preferredHighlightBegin. diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 7e4549f..206b09d 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -738,14 +738,14 @@ void QDeclarativeGrid::setRows(const int rows) } /*! - \qmlproperty enumeration Flow::flow + \qmlproperty enumeration Grid::flow This property holds the flow of the layout. - Possible values are \c LeftToRight (default) and \c TopToBottom. + Possible values are \c Grid.LeftToRight (default) and \c Grid.TopToBottom. - If \a flow is \c LeftToRight, the items are positioned next to + If \a flow is \c Grid.LeftToRight, the items are positioned next to to each other from left to right, then wrapped to the next line. - If \a flow is \c TopToBottom, the items are positioned next to each + If \a flow is \c Grid.TopToBottom, the items are positioned next to each other from top to bottom, then wrapped to the next column. */ QDeclarativeGrid::Flow QDeclarativeGrid::flow() const @@ -952,12 +952,12 @@ QDeclarativeFlow::QDeclarativeFlow(QDeclarativeItem *parent) \qmlproperty enumeration Flow::flow This property holds the flow of the layout. - Possible values are \c LeftToRight (default) and \c TopToBottom. + Possible values are \c Flow.LeftToRight (default) and \c Flow.TopToBottom. - If \a flow is \c LeftToRight, the items are positioned next to + If \a flow is \c Flow.LeftToRight, the items are positioned next to to each other from left to right until the width of the Flow is exceeded, then wrapped to the next line. - If \a flow is \c TopToBottom, the items are positioned next to each + If \a flow is \c Flow.TopToBottom, the items are positioned next to each other from top to bottom until the height of the Flow is exceeded, then wrapped to the next column. */ diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index eeff0c3..4e7e0fd 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -200,11 +200,11 @@ QDeclarativeTextPrivate::~QDeclarativeTextPrivate() The weight can be one of: \list - \o Light - \o Normal - the default - \o DemiBold - \o Bold - \o Black + \o Font.Light + \o Font.Normal - the default + \o Font.DemiBold + \o Font.Bold + \o Font.Black \endlist \qml @@ -277,11 +277,11 @@ QDeclarativeTextPrivate::~QDeclarativeTextPrivate() Sets the capitalization for the text. \list - \o MixedCase - This is the normal text rendering option where no capitalization change is applied. - \o AllUppercase - This alters the text to be rendered in all uppercase type. - \o AllLowercase - This alters the text to be rendered in all lowercase type. - \o SmallCaps - This alters the text to be rendered in small-caps type. - \o Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character. + \o Font.MixedCase - This is the normal text rendering option where no capitalization change is applied. + \o Font.AllUppercase - This alters the text to be rendered in all uppercase type. + \o Font.AllLowercase - This alters the text to be rendered in all lowercase type. + \o Font.SmallCaps - This alters the text to be rendered in small-caps type. + \o Font.Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character. \endlist \qml @@ -380,10 +380,10 @@ QColor QDeclarativeText::color() const Supported text styles are: \list - \o Normal - the default - \o Outline - \o Raised - \o Sunken + \o Text.Normal - the default + \o Text.Outline + \o Text.Raised + \o Text.Sunken \endlist \qml @@ -451,9 +451,14 @@ QColor QDeclarativeText::styleColor() const Sets the horizontal and vertical alignment of the text within the Text items width and height. By default, the text is top-left aligned. - The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and - \c AlignHCenter. The valid values for \c verticalAlignment are \c AlignTop, \c AlignBottom - and \c AlignVCenter. + The valid values for \c horizontalAlignment are \c Text.AlignLeft, \c Text.AlignRight and + \c Text.AlignHCenter. The valid values for \c verticalAlignment are \c Text.AlignTop, \c Text.AlignBottom + and \c Text.AlignVCenter. + + Note that for a single line of text, the size of the text is the area of the text. In this common case, + all alignments are equivalent. If you want the text to be, say, centered in it parent, then you will + need to either modify the Item::anchors, or set horizontalAlignment to Text.AlignHCenter and bind the width to + that of the parent. */ QDeclarativeText::HAlignment QDeclarativeText::hAlign() const { @@ -494,16 +499,16 @@ void QDeclarativeText::setVAlign(VAlignment align) wrap if an explicit width has been set. wrapMode can be one of: \list - \o NoWrap - no wrapping will be performed. - \o WordWrap - wrapping is done on word boundaries. If the text cannot be + \o Text.NoWrap - no wrapping will be performed. + \o Text.WordWrap - wrapping is done on word boundaries. If the text cannot be word-wrapped to the specified width it will be partially drawn outside of the item's bounds. If this is undesirable then enable clipping on the item (Item::clip). - \o WrapAnywhere - Text can be wrapped at any point on a line, even if it occurs in the middle of a word. - \o WrapAtWordBoundaryOrAnywhere - If possible, wrapping occurs at a word boundary; otherwise it + \o Text.WrapAnywhere - Text can be wrapped at any point on a line, even if it occurs in the middle of a word. + \o Text.WrapAtWordBoundaryOrAnywhere - If possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word. \endlist - The default is NoWrap. + The default is Text.NoWrap. */ QDeclarativeText::WrapMode QDeclarativeText::wrapMode() const { @@ -533,17 +538,17 @@ void QDeclarativeText::setWrapMode(WrapMode mode) Supported text formats are: \list - \o AutoText - \o PlainText - \o RichText - \o StyledText + \o Text.AutoText + \o Text.PlainText + \o Text.RichText + \o Text.StyledText \endlist - The default is AutoText. If the text format is AutoText the text element + The default is Text.AutoText. If the text format is Text.AutoText the text element will automatically determine whether the text should be treated as rich text. This determination is made using Qt::mightBeRichText(). - StyledText is an optimized format supporting some basic text + Text.StyledText is an optimized format supporting some basic text styling markup, in the style of html 3.2: \code @@ -554,7 +559,7 @@ void QDeclarativeText::setWrapMode(WrapMode mode) > < & \endcode - \c StyledText parser is strict, requiring tags to be correctly nested. + \c Text.StyledText parser is strict, requiring tags to be correctly nested. \table \row @@ -622,13 +627,13 @@ void QDeclarativeText::setTextFormat(TextFormat format) Eliding can be: \list - \o ElideNone - the default - \o ElideLeft - \o ElideMiddle - \o ElideRight + \o Text.ElideNone - the default + \o Text.ElideLeft + \o Text.ElideMiddle + \o Text.ElideRight \endlist - If the text is a multi-length string, and the mode is not \c ElideNone, + If the text is a multi-length string, and the mode is not \c Text.ElideNone, the first string that fits will be used, otherwise the last will be elided. Multi-length strings are ordered from longest to shortest, separated by the diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 762640c..d0ee2ee 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -138,11 +138,11 @@ QString QDeclarativeTextEdit::text() const The weight can be one of: \list - \o Light - \o Normal - the default - \o DemiBold - \o Bold - \o Black + \o Font.Light + \o Font.Normal - the default + \o Font.DemiBold + \o Font.Bold + \o Font.Black \endlist \qml @@ -215,11 +215,11 @@ QString QDeclarativeTextEdit::text() const Sets the capitalization for the text. \list - \o MixedCase - This is the normal text rendering option where no capitalization change is applied. - \o AllUppercase - This alters the text to be rendered in all uppercase type. - \o AllLowercase - This alters the text to be rendered in all lowercase type. - \o SmallCaps - This alters the text to be rendered in small-caps type. - \o Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character. + \o Font.MixedCase - This is the normal text rendering option where no capitalization change is applied. + \o Font.AllUppercase - This alters the text to be rendered in all uppercase type. + \o Font.AllLowercase - This alters the text to be rendered in all lowercase type. + \o Font.SmallCaps - This alters the text to be rendered in small-caps type. + \o Font.Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character. \endlist \qml @@ -255,13 +255,13 @@ void QDeclarativeTextEdit::setText(const QString &text) The way the text property should be displayed. \list - \o AutoText - \o PlainText - \o RichText - \o StyledText + \o TextEdit.AutoText + \o TextEdit.PlainText + \o TextEdit.RichText + \o TextEdit.StyledText \endlist - The default is AutoText. If the text format is AutoText the text edit + The default is TextEdit.AutoText. If the text format is TextEdit.AutoText the text edit will automatically determine whether the text should be treated as rich text. This determination is made using Qt::mightBeRichText(). @@ -428,9 +428,9 @@ void QDeclarativeTextEdit::setSelectedTextColor(const QColor &color) Sets the horizontal and vertical alignment of the text within the TextEdit items width and height. By default, the text is top-left aligned. - The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and - \c AlignHCenter. The valid values for \c verticalAlignment are \c AlignTop, \c AlignBottom - and \c AlignVCenter. + The valid values for \c horizontalAlignment are \c TextEdit.AlignLeft, \c TextEdit.AlignRight and + \c TextEdit.AlignHCenter. The valid values for \c verticalAlignment are \c TextEdit.AlignTop, \c TextEdit.AlignBottom + and \c TextEdit.AlignVCenter. */ QDeclarativeTextEdit::HAlignment QDeclarativeTextEdit::hAlign() const { @@ -473,14 +473,14 @@ void QDeclarativeTextEdit::setVAlign(QDeclarativeTextEdit::VAlignment alignment) The text will only wrap if an explicit width has been set. \list - \o NoWrap - no wrapping will be performed. - \o WordWrap - wrapping is done on word boundaries. - \o WrapAnywhere - Text can be wrapped at any point on a line, even if it occurs in the middle of a word. - \o WrapAtWordBoundaryOrAnywhere - If possible, wrapping occurs at a word boundary; otherwise it + \o TextEdit.NoWrap - no wrapping will be performed. + \o TextEdit.WordWrap - wrapping is done on word boundaries. + \o TextEdit.WrapAnywhere - Text can be wrapped at any point on a line, even if it occurs in the middle of a word. + \o TextEdit.WrapAtWordBoundaryOrAnywhere - If possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word. \endlist - The default is NoWrap. + The default is TextEdit.NoWrap. */ QDeclarativeTextEdit::WrapMode QDeclarativeTextEdit::wrapMode() const { diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 775450a..b04e36e 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -118,11 +118,11 @@ void QDeclarativeTextInput::setText(const QString &s) The weight can be one of: \list - \o Light - \o Normal - the default - \o DemiBold - \o Bold - \o Black + \o Font.Light + \o Font.Normal - the default + \o Font.DemiBold + \o Font.Bold + \o Font.Black \endlist \qml @@ -195,11 +195,11 @@ void QDeclarativeTextInput::setText(const QString &s) Sets the capitalization for the text. \list - \o MixedCase - This is the normal text rendering option where no capitalization change is applied. - \o AllUppercase - This alters the text to be rendered in all uppercase type. - \o AllLowercase - This alters the text to be rendered in all lowercase type. - \o SmallCaps - This alters the text to be rendered in small-caps type. - \o Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character. + \o Font.MixedCase - This is the normal text rendering option where no capitalization change is applied. + \o Font.AllUppercase - This alters the text to be rendered in all uppercase type. + \o Font.AllLowercase - This alters the text to be rendered in all lowercase type. + \o Font.SmallCaps - This alters the text to be rendered in small-caps type. + \o Font.Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character. \endlist \qml @@ -308,8 +308,8 @@ void QDeclarativeTextInput::setSelectedTextColor(const QColor &color) vertically. You can use anchors to align it however you want within another item. - The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and - \c AlignHCenter. + The valid values for \c horizontalAlignment are \c TextInput.AlignLeft, \c TextInput.AlignRight and + \c TextInput.AlignHCenter. */ QDeclarativeTextInput::HAlignment QDeclarativeTextInput::hAlign() const { @@ -600,9 +600,9 @@ void QDeclarativeTextInput::setAutoScroll(bool b) This property holds the notation of how a string can describe a number. The values for this property are DoubleValidator.StandardNotation or DoubleValidator.ScientificNotation. - If this property is set to ScientificNotation, the written number may have an exponent part(i.e. 1.5E-2). + If this property is set to DoubleValidator.ScientificNotation, the written number may have an exponent part(i.e. 1.5E-2). - By default, this property is set to ScientificNotation. + By default, this property is set to DoubleValidator.ScientificNotation. */ /*! diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 3ca0707..fb799dc 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -241,10 +241,10 @@ QDeclarativeComponent::~QDeclarativeComponent() \qmlproperty enumeration Component::status This property holds the status of component loading. It can be one of: \list - \o Null - no data is available for the component - \o Ready - the component has been loaded, and can be used to create instances. - \o Loading - the component is currently being loaded - \o Error - an error occurred while loading the component. + \o Component.Null - no data is available for the component + \o Component.Ready - the component has been loaded, and can be used to create instances. + \o Component.Loading - the component is currently being loaded + \o Component.Error - an error occurred while loading the component. Calling errorsString() will provide a human-readable description of any errors. \endlist */ diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 4059522..067565d 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -1320,27 +1320,27 @@ void QDeclarativeRotationAnimation::setTo(qreal t) /*! \qmlproperty enumeration RotationAnimation::direction The direction in which to rotate. - Possible values are Numerical, Clockwise, Counterclockwise, - or Shortest. + + Possible values are: \table \row - \o Numerical + \o RotationAnimation.Numerical \o Rotate by linearly interpolating between the two numbers. A rotation from 10 to 350 will rotate 340 degrees clockwise. \row - \o Clockwise + \o RotationAnimation.Clockwise \o Rotate clockwise between the two values \row - \o Counterclockwise + \o RotationAnimation.Counterclockwise \o Rotate counterclockwise between the two values \row - \o Shortest + \o RotationAnimation.Shortest \o Rotate in the direction that produces the shortest animation path. A rotation from 10 to 350 will rotate 20 degrees counterclockwise. \endtable - The default direction is Numerical. + The default direction is RotationAnimation.Numerical. */ QDeclarativeRotationAnimation::RotationDirection QDeclarativeRotationAnimation::direction() const { @@ -1754,189 +1754,189 @@ void QDeclarativePropertyAnimation::setTo(const QVariant &t) Linear. \qml - PropertyAnimation { properties: "y"; easing.type: "InOutElastic"; easing.amplitude: 2.0; easing.period: 1.5 } + PropertyAnimation { properties: "y"; easing.type: Easing.InOutElastic; easing.amplitude: 2.0; easing.period: 1.5 } \endqml Available types are: \table \row - \o \c Linear + \o \c Easing.Linear \o Easing curve for a linear (t) function: velocity is constant. \o \inlineimage qeasingcurve-linear.png \row - \o \c InQuad + \o \c Easing.InQuad \o Easing curve for a quadratic (t^2) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inquad.png \row - \o \c OutQuad + \o \c Easing.OutQuad \o Easing curve for a quadratic (t^2) function: decelerating to zero velocity. \o \inlineimage qeasingcurve-outquad.png \row - \o \c InOutQuad + \o \c Easing.InOutQuad \o Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutquad.png \row - \o \c OutInQuad + \o \c Easing.OutInQuad \o Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinquad.png \row - \o \c InCubic + \o \c Easing.InCubic \o Easing curve for a cubic (t^3) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-incubic.png \row - \o \c OutCubic + \o \c Easing.OutCubic \o Easing curve for a cubic (t^3) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outcubic.png \row - \o \c InOutCubic + \o \c Easing.InOutCubic \o Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutcubic.png \row - \o \c OutInCubic + \o \c Easing.OutInCubic \o Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outincubic.png \row - \o \c InQuart + \o \c Easing.InQuart \o Easing curve for a quartic (t^4) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inquart.png \row - \o \c OutQuart + \o \c Easing.OutQuart \o Easing curve for a cubic (t^4) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outquart.png \row - \o \c InOutQuart + \o \c Easing.InOutQuart \o Easing curve for a cubic (t^4) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutquart.png \row - \o \c OutInQuart + \o \c Easing.OutInQuart \o Easing curve for a cubic (t^4) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinquart.png \row - \o \c InQuint + \o \c Easing.InQuint \o Easing curve for a quintic (t^5) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inquint.png \row - \o \c OutQuint + \o \c Easing.OutQuint \o Easing curve for a cubic (t^5) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outquint.png \row - \o \c InOutQuint + \o \c Easing.InOutQuint \o Easing curve for a cubic (t^5) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutquint.png \row - \o \c OutInQuint + \o \c Easing.OutInQuint \o Easing curve for a cubic (t^5) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinquint.png \row - \o \c InSine + \o \c Easing.InSine \o Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-insine.png \row - \o \c OutSine + \o \c Easing.OutSine \o Easing curve for a sinusoidal (sin(t)) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outsine.png \row - \o \c InOutSine + \o \c Easing.InOutSine \o Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutsine.png \row - \o \c OutInSine + \o \c Easing.OutInSine \o Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinsine.png \row - \o \c InExpo + \o \c Easing.InExpo \o Easing curve for an exponential (2^t) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inexpo.png \row - \o \c OutExpo + \o \c Easing.OutExpo \o Easing curve for an exponential (2^t) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outexpo.png \row - \o \c InOutExpo + \o \c Easing.InOutExpo \o Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutexpo.png \row - \o \c OutInExpo + \o \c Easing.OutInExpo \o Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinexpo.png \row - \o \c InCirc + \o \c Easing.InCirc \o Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-incirc.png \row - \o \c OutCirc + \o \c Easing.OutCirc \o Easing curve for a circular (sqrt(1-t^2)) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outcirc.png \row - \o \c InOutCirc + \o \c Easing.InOutCirc \o Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutcirc.png \row - \o \c OutInCirc + \o \c Easing.OutInCirc \o Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outincirc.png \row - \o \c InElastic + \o \c Easing.InElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity. \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. \o \inlineimage qeasingcurve-inelastic.png \row - \o \c OutElastic + \o \c Easing.OutElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: decelerating from zero velocity. \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. \o \inlineimage qeasingcurve-outelastic.png \row - \o \c InOutElastic + \o \c Easing.InOutElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutelastic.png \row - \o \c OutInElastic + \o \c Easing.OutInElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinelastic.png \row - \o \c InBack + \o \c Easing.InBack \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. \o \inlineimage qeasingcurve-inback.png \row - \o \c OutBack + \o \c Easing.OutBack \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity. \o \inlineimage qeasingcurve-outback.png \row - \o \c InOutBack + \o \c Easing.InOutBack \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutback.png \row - \o \c OutInBack + \o \c Easing.OutInBack \o Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinback.png \row - \o \c InBounce + \o \c Easing.InBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inbounce.png \row - \o \c OutBounce + \o \c Easing.OutBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outbounce.png \row - \o \c InOutBounce + \o \c Easing.InOutBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutbounce.png \row - \o \c OutInBounce + \o \c Easing.OutInBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinbounce.png \endtable - easing.amplitude is not applicable for all curve types. It is only applicable for bounce and elastic curves (curves of type - QEasingCurve::InBounce, QEasingCurve::OutBounce, QEasingCurve::InOutBounce, QEasingCurve::OutInBounce, QEasingCurve::InElastic, - QEasingCurve::OutElastic, QEasingCurve::InOutElastic or QEasingCurve::OutInElastic). + easing.amplitude is only applicable for bounce and elastic curves (curves of type + Easing.InBounce, Easing.OutBounce, Easing.InOutBounce, Easing.OutInBounce, Easing.InElastic, + Easing.OutElastic, Easing.InOutElastic or Easing.OutInElastic). - easing.overshoot is not applicable for all curve types. It is only applicable if type is: QEasingCurve::InBack, QEasingCurve::OutBack, - QEasingCurve::InOutBack or QEasingCurve::OutInBack. + easing.overshoot is only applicable if type is: Easing.InBack, Easing.OutBack, + Easing.InOutBack or Easing.OutInBack. - easing.period is not applicable for all curve types. It is only applicable if type is: QEasingCurve::InElastic, QEasingCurve::OutElastic, - QEasingCurve::InOutElastic or QEasingCurve::OutInElastic. + easing.period is only applicable if type is: Easing.InElastic, Easing.OutElastic, + Easing.InOutElastic or Easing.OutInElastic. */ QEasingCurve QDeclarativePropertyAnimation::easing() const { @@ -2730,7 +2730,7 @@ void QDeclarativeAnchorAnimation::setDuration(int duration) Linear. \qml - AnchorAnimation { easing.type: "InOutQuad" } + AnchorAnimation { easing.type: Easing.InOutQuad } \endqml See the \l{PropertyAnimation::easing.type} documentation for information diff --git a/src/declarative/util/qdeclarativefontloader.cpp b/src/declarative/util/qdeclarativefontloader.cpp index f98ce8b..adfcd62 100644 --- a/src/declarative/util/qdeclarativefontloader.cpp +++ b/src/declarative/util/qdeclarativefontloader.cpp @@ -185,10 +185,10 @@ void QDeclarativeFontLoader::setName(const QString &name) This property holds the status of font loading. It can be one of: \list - \o Null - no font has been set - \o Ready - the font has been loaded - \o Loading - the font is currently being loaded - \o Error - an error occurred while loading the font + \o FontLoader.Null - no font has been set + \o FontLoader.Ready - the font has been loaded + \o FontLoader.Loading - the font is currently being loaded + \o FontLoader.Error - an error occurred while loading the font \endlist Note that a change in the status property does not cause anything to happen diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp index 19a00ee..bd48ef0 100644 --- a/src/declarative/util/qdeclarativesmoothedanimation.cpp +++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp @@ -388,10 +388,10 @@ void QDeclarativeSmoothedAnimation::transition(QDeclarativeStateActions &actions Sets how the SmoothedAnimation behaves if an animation direction is reversed. - If reversing mode is \c Eased, the animation will smoothly decelerate, and - then reverse direction. If the reversing mode is \c Immediate, the + If reversing mode is \c SmoothedAnimation.Eased, the animation will smoothly decelerate, and + then reverse direction. If the reversing mode is \c SmoothedAnimation.Immediate, the animation will immediately begin accelerating in the reverse direction, - begining with a velocity of 0. If the reversing mode is \c Sync, the + begining with a velocity of 0. If the reversing mode is \c SmoothedAnimation.Sync, the property is immediately set to the target value. */ QDeclarativeSmoothedAnimation::ReversingMode QDeclarativeSmoothedAnimation::reversingMode() const diff --git a/src/declarative/util/qdeclarativesmoothedfollow.cpp b/src/declarative/util/qdeclarativesmoothedfollow.cpp index 3ed9257..e919282 100644 --- a/src/declarative/util/qdeclarativesmoothedfollow.cpp +++ b/src/declarative/util/qdeclarativesmoothedfollow.cpp @@ -143,10 +143,10 @@ QDeclarativeSmoothedFollowPrivate::QDeclarativeSmoothedFollowPrivate() Sets how the SmoothedFollow behaves if an animation direction is reversed. - If reversing mode is \c Eased, the animation will smoothly decelerate, and - then reverse direction. If the reversing mode is \c Immediate, the + If reversing mode is \SmoothedFollow.c Eased, the animation will smoothly decelerate, and + then reverse direction. If the reversing mode is \c SmoothedFollow.Immediate, the animation will immediately begin accelerating in the reverse direction, - begining with a velocity of 0. If the reversing mode is \c Sync, the + begining with a velocity of 0. If the reversing mode is \c SmoothedFollow.Sync, the property is immediately set to the target value. */ QDeclarativeSmoothedFollow::ReversingMode QDeclarativeSmoothedFollow::reversingMode() const diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index bdebadf..ae3b5d7 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -675,10 +675,10 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati Specifies the model loading status, which can be one of the following: \list - \o Null - No XML data has been set for this model. - \o Ready - The XML data has been loaded into the model. - \o Loading - The model is in the process of reading and loading XML data. - \o Error - An error occurred while the model was loading. + \o XmlListModel.Null - No XML data has been set for this model. + \o XmlListModel.Ready - The XML data has been loaded into the model. + \o XmlListModel.Loading - The model is in the process of reading and loading XML data. + \o XmlListModel.Error - An error occurred while the model was loading. \endlist \sa progress -- cgit v0.12 From b1bf4b23fb34337ea1b5ebdd5aedaad48f5c9f4a Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 5 May 2010 15:13:35 +1000 Subject: Test for QList model with object properties changing. --- .../tst_qdeclarativevisualdatamodel.cpp | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp index 7de15a3..c238ef9 100644 --- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp +++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp @@ -44,6 +44,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -74,9 +78,50 @@ public: private slots: void rootIndex(); + void objectListModel(); private: QDeclarativeEngine engine; + template + T *findItem(QGraphicsObject *parent, const QString &objectName, int index); +}; + +class DataObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged) + +public: + DataObject(QObject *parent=0) : QObject(parent) {} + DataObject(const QString &name, const QString &color, QObject *parent=0) + : QObject(parent), m_name(name), m_color(color) { } + + + QString name() const { return m_name; } + void setName(const QString &name) { + if (name != m_name) { + m_name = name; + emit nameChanged(); + } + } + + QString color() const { return m_color; } + void setColor(const QString &color) { + if (color != m_color) { + m_color = color; + emit colorChanged(); + } + } + +signals: + void nameChanged(); + void colorChanged(); + +private: + QString m_name; + QString m_color; }; tst_qdeclarativevisualdatamodel::tst_qdeclarativevisualdatamodel() @@ -105,6 +150,60 @@ void tst_qdeclarativevisualdatamodel::rootIndex() delete obj; } +void tst_qdeclarativevisualdatamodel::objectListModel() +{ + QDeclarativeView view; + + QList dataList; + dataList.append(new DataObject("Item 1", "red")); + dataList.append(new DataObject("Item 2", "green")); + dataList.append(new DataObject("Item 3", "blue")); + dataList.append(new DataObject("Item 4", "yellow")); + + QDeclarativeContext *ctxt = view.rootContext(); + ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); + + view.setSource(QUrl::fromLocalFile(SRCDIR "/data/objectlist.qml")); + + QDeclarativeListView *listview = qobject_cast(view.rootObject()); + QVERIFY(listview != 0); + + QDeclarativeItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + QDeclarativeText *name = findItem(viewport, "name", 0); + QCOMPARE(name->text(), QString("Item 1")); + + dataList[0]->setProperty("name", QLatin1String("Changed")); + QCOMPARE(name->text(), QString("Changed")); +} + +template +T *tst_qdeclarativevisualdatamodel::findItem(QGraphicsObject *parent, const QString &objectName, int index) +{ + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->childItems().count() << "children"; + for (int i = 0; i < parent->childItems().count(); ++i) { + QDeclarativeItem *item = qobject_cast(parent->childItems().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { + if (index != -1) { + QDeclarativeExpression e(qmlContext(item), "index", item); + if (e.evaluate().toInt() == index) + return static_cast(item); + } else { + return static_cast(item); + } + } + item = findItem(item, objectName, index); + if (item) + return static_cast(item); + } + + return 0; +} QTEST_MAIN(tst_qdeclarativevisualdatamodel) -- cgit v0.12 From ba8ff70b5ac7b68be57a4b63e439fd5a37c4aafa Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 5 May 2010 15:24:53 +1000 Subject: Turn off smooth rendering for qDrawBorderPixmap() with transforms. On non-gl graphics systems smooth rendering of qDrawBorderPixmap() with a transform applied resulted in ugly artifacts. Better to draw without smooth and get a correct looking result, though with jaggy edges. Task-number: QTBUG-5687 Reviewed-by: Gunnar --- src/gui/painting/qdrawutil.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp index a62f06b..ef9b18c 100644 --- a/src/gui/painting/qdrawutil.cpp +++ b/src/gui/painting/qdrawutil.cpp @@ -1137,6 +1137,15 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin xTarget.resize(columns + 1); yTarget.resize(rows + 1); + bool oldAA = painter->testRenderHint(QPainter::Antialiasing); + bool oldSmooth = painter->testRenderHint(QPainter::SmoothPixmapTransform); + if (painter->paintEngine()->type() != QPaintEngine::OpenGL + && painter->paintEngine()->type() != QPaintEngine::OpenGL2 + && (oldSmooth || oldAA) && painter->combinedTransform().type() != QTransform::TxNone) { + painter->setRenderHint(QPainter::Antialiasing, false); + painter->setRenderHint(QPainter::SmoothPixmapTransform, false); + } + xTarget[0] = targetRect.left(); xTarget[1] = targetCenterLeft; xTarget[columns - 1] = targetCenterRight; @@ -1342,6 +1351,11 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin painter->drawPixmapFragments(opaqueData.data(), opaqueData.size(), pixmap, QPainter::OpaqueHint); if (translucentData.size()) painter->drawPixmapFragments(translucentData.data(), translucentData.size(), pixmap); + + if (oldAA) + painter->setRenderHint(QPainter::Antialiasing, true); + if (oldSmooth) + painter->setRenderHint(QPainter::SmoothPixmapTransform, true); } QT_END_NAMESPACE -- cgit v0.12 From 06c8e20cd7c04c5a11eee5b5a255099fa29bb3e4 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 5 May 2010 14:29:16 +1000 Subject: Fix qdoc errors --- doc/src/declarative/advtutorial.qdoc | 2 +- src/declarative/graphicsitems/qdeclarativeitem.cpp | 8 +------- src/declarative/graphicsitems/qdeclarativepainteditem.cpp | 2 +- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 4 ++-- src/declarative/qml/qdeclarativeengine.cpp | 2 +- src/declarative/qml/qdeclarativepropertyvaluesource.cpp | 3 +++ 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/doc/src/declarative/advtutorial.qdoc b/doc/src/declarative/advtutorial.qdoc index 7d2967e..8f95190 100644 --- a/doc/src/declarative/advtutorial.qdoc +++ b/doc/src/declarative/advtutorial.qdoc @@ -468,6 +468,6 @@ By following this tutorial you've seen how you can write a fully functional appl \endlist There is so much more to learn about QML that we haven't been able to cover in this tutorial. Check out all the -demos and examples and the \l {Declarative UI (QML)}{documentation} to find out all the things you can do with QML! +demos and examples and the \l {Declarative UI Using QML}{documentation} to find out all the things you can do with QML! */ diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index a0983cc..0395766 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1632,10 +1632,6 @@ void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeN specify it. */ -/*! - \internal -*/ - /*! \internal */ QDeclarativeListProperty QDeclarativeItemPrivate::data() { @@ -1646,7 +1642,7 @@ QDeclarativeListProperty QDeclarativeItemPrivate::data() \property QDeclarativeItem::childrenRect \brief The geometry of an item's children. - childrenRect provides an easy way to access the (collective) position and size of the item's children. + This property holds the (collective) position and size of the item's children. */ QRectF QDeclarativeItem::childrenRect() { @@ -2966,7 +2962,6 @@ void QDeclarativeItem::setFocus(bool focus) } /*! - \reimp \internal */ void QDeclarativeItem::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) @@ -2974,7 +2969,6 @@ void QDeclarativeItem::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidg } /*! - \reimp \internal */ bool QDeclarativeItem::event(QEvent *ev) diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp index 5dd7e5d..6430fae 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp +++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp @@ -231,7 +231,7 @@ void QDeclarativePaintedItem::setCacheFrozen(bool frozen) } /*! - \reimp + \internal */ void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index b04e36e..a1fa8c6 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -828,7 +828,7 @@ void QDeclarativeTextInput::moveCursor() } /*! - \qmlmethod int xToPosition(int x) + \qmlmethod int TextInput::xToPosition(int x) This function returns the character position at x pixels from the left of the textInput. Position 0 is before the @@ -1097,7 +1097,7 @@ QString QDeclarativeTextInput::displayText() const } /*! - \qmlmethod void moveCursorSelection(int position) + \qmlmethod void TextInput::moveCursorSelection(int position) Moves the cursor to \a position and updates the selection accordingly. (To only move the cursor, set the \l cursorPosition property.) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index dee5ec6..ac60758 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1550,7 +1550,7 @@ QStringList QDeclarativeEngine::importPathList() const } /*! - Sets the list of directories where the engine searches for + Sets \a paths as the list of directories where the engine searches for installed modules in a URL-based directory structure. By default, the list contains the paths specified in the \c QML_IMPORT_PATH environment diff --git a/src/declarative/qml/qdeclarativepropertyvaluesource.cpp b/src/declarative/qml/qdeclarativepropertyvaluesource.cpp index a0ed78f..039998f 100644 --- a/src/declarative/qml/qdeclarativepropertyvaluesource.cpp +++ b/src/declarative/qml/qdeclarativepropertyvaluesource.cpp @@ -60,6 +60,9 @@ QDeclarativePropertyValueSource::QDeclarativePropertyValueSource() { } +/*! + Destroys the value source. +*/ QDeclarativePropertyValueSource::~QDeclarativePropertyValueSource() { } -- cgit v0.12 From dc4f8e4b23a4b07efe1605c2ae479e219b456df9 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 5 May 2010 15:41:08 +1000 Subject: Docs - point to property types from tutorial and QML Basic Types page --- doc/src/declarative/basictypes.qdoc | 9 ++++++--- doc/src/declarative/tutorial.qdoc | 14 +++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/doc/src/declarative/basictypes.qdoc b/doc/src/declarative/basictypes.qdoc index 6901947..8db1c35 100644 --- a/doc/src/declarative/basictypes.qdoc +++ b/doc/src/declarative/basictypes.qdoc @@ -43,9 +43,12 @@ \page qdeclarativebasictypes.html \title QML Basic Types - QML uses a set of property types, which are primitive within QML. - These basic types are referenced throughout the documentation of the - QML elements. Almost all of them are exactly what you would expect. + QML has a set of primitive types, as listed below, that are used throughout + the \l {QML Elements}. + + The simpler types in this list can also be used for defining a new + \c property in a component. See \l{Extending types from QML} for the + list of types that can be used for custom properties. \annotatedlist qmlbasictypes */ diff --git a/doc/src/declarative/tutorial.qdoc b/doc/src/declarative/tutorial.qdoc index 4cfb999..75c0f851 100644 --- a/doc/src/declarative/tutorial.qdoc +++ b/doc/src/declarative/tutorial.qdoc @@ -57,10 +57,10 @@ The tutorial's source code is located in the $QTDIR/examples/declarative/tutoria Tutorial chapters: -\list -\o \l {QML Tutorial 1 - Basic Types} -\o \l {QML Tutorial 2 - QML Component} -\o \l {QML Tutorial 3 - States and Transitions} +\list 1 +\o \l {QML Tutorial 1 - Basic Types}{Basic Types} +\o \l {QML Tutorial 2 - QML Components}{QML Components} +\o \l {QML Tutorial 3 - States and Transitions}{States and Transitions} \endlist */ @@ -125,7 +125,7 @@ bin/qml $QTDIR/examples/declarative/tutorials/helloworld/tutorial1.qml /*! \page qml-tutorial2.html -\title QML Tutorial 2 - QML Component +\title QML Tutorial 2 - QML Components \contentspage QML Tutorial \previouspage QML Tutorial 1 - Basic Types \nextpage QML Tutorial 3 - States and Transitions @@ -137,7 +137,7 @@ This chapter adds a color picker to change the color of the text. Our color picker is made of six cells with different colors. To avoid writing the same code multiple times for each cell, we create a new \c Cell component. A component provides a way of defining a new type that we can re-use in other QML files. -A QML component is like a black-box and interacts with the outside world through properties, signals and slots and is generally +A QML component is like a black-box and interacts with the outside world through properties, signals and functions and is generally defined in its own QML file. (For more details, see \l {Defining new Components}). The component's filename must always start with a capital letter. @@ -158,7 +158,7 @@ An \l Item is the most basic visual element in QML and is often used as a contai We declare a \c cellColor property. This property is accessible from \e outside our component, this allows us to instantiate the cells with different colors. -This property is just an alias to an existing property - the color of the rectangle that compose the cell (see \l{intro-properties}{Properties}). +This property is just an alias to an existing property - the color of the rectangle that compose the cell (see \l{Adding new properties}). \snippet examples/declarative/tutorials/helloworld/Cell.qml 5 -- cgit v0.12 From f8af54e12bcb6e991315c53eca758c43653610fa Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 5 May 2010 15:54:33 +1000 Subject: little doc fix. --- src/declarative/util/qdeclarativesmoothedfollow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativesmoothedfollow.cpp b/src/declarative/util/qdeclarativesmoothedfollow.cpp index e919282..f70df9d 100644 --- a/src/declarative/util/qdeclarativesmoothedfollow.cpp +++ b/src/declarative/util/qdeclarativesmoothedfollow.cpp @@ -143,7 +143,7 @@ QDeclarativeSmoothedFollowPrivate::QDeclarativeSmoothedFollowPrivate() Sets how the SmoothedFollow behaves if an animation direction is reversed. - If reversing mode is \SmoothedFollow.c Eased, the animation will smoothly decelerate, and + If reversing mode is \c SmoothedFollow.Eased, the animation will smoothly decelerate, and then reverse direction. If the reversing mode is \c SmoothedFollow.Immediate, the animation will immediately begin accelerating in the reverse direction, begining with a velocity of 0. If the reversing mode is \c SmoothedFollow.Sync, the -- cgit v0.12 From 80c04413ba2c1a20a5d93d69df92ba908c26d81d Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 5 May 2010 16:03:16 +1000 Subject: Document delegate life cycle. Task-number: QTBUG-10353 --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 3 +++ src/declarative/graphicsitems/qdeclarativelistview.cpp | 3 +++ src/declarative/graphicsitems/qdeclarativepathview.cpp | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index f55c483..4c72482 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -908,6 +908,9 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m In this case ListModel is a handy way for us to test our UI. In practice the model would be implemented in C++, or perhaps via a SQL data source. + Delegates are instantiated as needed and may be destroyed at any time. + State should \e never be stored in a delegate. + \bold Note that views do not enable \e clip automatically. If the view is not clipped by another item or the screen, it will be necessary to set \e {clip: true} in order to have the out of view items clipped diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 589b8e2..3877fab 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1314,6 +1314,9 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m In this case ListModel is a handy way for us to test our UI. In practice the model would be implemented in C++, or perhaps via a SQL data source. + Delegates are instantiated as needed and may be destroyed at any time. + State should \e never be stored in a delegate. + \bold Note that views do not enable \e clip automatically. If the view is not clipped by another item or the screen, it will be necessary to set \e {clip: true} in order to have the out of view items clipped diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 9ae6f9d..5c3a3c0 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -308,12 +308,16 @@ void QDeclarativePathViewPrivate::regenerate() The model is typically provided by a QAbstractListModel "C++ model object", but can also be created directly in QML. - The items are laid out along a path defined by a \l Path and may be flicked to scroll. + The \l delegate is instantiated for each item on the \l path. + The items may be flicked to move them along the path. \snippet doc/src/snippets/declarative/pathview/pathview.qml 0 \image pathview.gif + Delegates are instantiated as needed and may be destroyed at any time. + State should \e never be stored in a delegate. + \bold Note that views do not enable \e clip automatically. If the view is not clipped by another item or the screen, it will be necessary to set \e {clip: true} in order to have the out of view items clipped -- cgit v0.12 From f5e3e21e95275a8cf31cddf2063dfa497e92872e Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 5 May 2010 16:22:51 +1000 Subject: Use enum rather than string for easing type. --- demos/declarative/calculator/calculator.qml | 4 +- demos/declarative/flickr/flickr.qml | 4 +- demos/declarative/flickr/mobile/GridDelegate.qml | 6 +- demos/declarative/flickr/mobile/ImageDetails.qml | 2 +- demos/declarative/flickr/mobile/TitleBar.qml | 2 +- demos/declarative/minehunt/MinehuntCore/Tile.qml | 2 +- .../photoviewer/PhotoViewerCore/AlbumDelegate.qml | 8 +- .../twitter/TwitterCore/HomeTitleBar.qml | 2 +- .../twitter/TwitterCore/MultiTitleBar.qml | 2 +- demos/declarative/twitter/TwitterCore/TitleBar.qml | 2 +- demos/declarative/twitter/twitter.qml | 2 +- .../content/RetractingWebBrowserHeader.qml | 2 +- demos/declarative/webbrowser/webbrowser.qml | 4 +- examples/declarative/animations/easing.qml | 104 +++++++++++---------- .../declarative/animations/property-animation.qml | 4 +- .../declarative/behaviors/behavior-example.qml | 4 +- .../border-image/content/MyBorderImage.qml | 20 +++- .../connections/connections-example.qml | 2 +- examples/declarative/focus/Core/ListViews.qml | 6 +- examples/declarative/focus/focus.qml | 4 +- examples/declarative/fonts/hello.qml | 2 +- examples/declarative/layouts/Button.qml | 42 ++++++--- examples/declarative/layouts/positioners.qml | 16 ++-- examples/declarative/parallax/qml/Smiley.qml | 4 +- examples/declarative/proxywidgets/proxywidgets.qml | 2 +- .../declarative/slideswitch/content/Switch.qml | 2 +- examples/declarative/states/transitions.qml | 4 +- .../declarative/tutorials/helloworld/tutorial3.qml | 2 +- examples/declarative/xmldata/yahoonews.qml | 2 +- .../graphicsitems/qdeclarativegridview.cpp | 2 +- .../graphicsitems/qdeclarativelistview.cpp | 2 +- .../graphicsitems/qdeclarativepositioners.cpp | 2 +- src/declarative/util/qdeclarativeanimation.cpp | 2 +- src/declarative/util/qdeclarativebehavior.cpp | 2 +- src/declarative/util/qdeclarativespringfollow.cpp | 2 +- 35 files changed, 154 insertions(+), 120 deletions(-) diff --git a/demos/declarative/calculator/calculator.qml b/demos/declarative/calculator/calculator.qml index 286a4d1..75f5735 100644 --- a/demos/declarative/calculator/calculator.qml +++ b/demos/declarative/calculator/calculator.qml @@ -98,8 +98,8 @@ Rectangle { transitions: Transition { SequentialAnimation { PropertyAction { target: rotateButton; property: "operation" } - NumberAnimation { properties: "rotation"; duration: 300; easing.type: "InOutQuint" } - NumberAnimation { properties: "x,y,width,height"; duration: 300; easing.type: "InOutQuint" } + NumberAnimation { properties: "rotation"; duration: 300; easing.type: Easing.InOutQuint } + NumberAnimation { properties: "x,y,width,height"; duration: 300; easing.type: Easing.InOutQuint } } } } diff --git a/demos/declarative/flickr/flickr.qml b/demos/declarative/flickr/flickr.qml index 8b73beb..29763d4 100644 --- a/demos/declarative/flickr/flickr.qml +++ b/demos/declarative/flickr/flickr.qml @@ -38,7 +38,7 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; duration: 500; easing.type: "InOutQuad" } + NumberAnimation { properties: "x"; duration: 500; easing.type: Easing.InOutQuad } } } @@ -76,7 +76,7 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; duration: 500; easing.type: "InOutQuad" } + NumberAnimation { properties: "x"; duration: 500; easing.type: Easing.InOutQuad } } } } diff --git a/demos/declarative/flickr/mobile/GridDelegate.qml b/demos/declarative/flickr/mobile/GridDelegate.qml index 5ab7b87..eccdc34 100644 --- a/demos/declarative/flickr/mobile/GridDelegate.qml +++ b/demos/declarative/flickr/mobile/GridDelegate.qml @@ -21,7 +21,7 @@ Item { anchors.centerIn: parent scale: 0.0 - Behavior on scale { NumberAnimation { easing.type: "InOutQuad"} } + Behavior on scale { NumberAnimation { easing.type: Easing.InOutQuad} } id: scaleMe Rectangle { height: 79; width: 79; id: blackRect; anchors.centerIn: parent; color: "black"; smooth: true } @@ -53,14 +53,14 @@ Transition { from: "Show"; to: "Details" ParentAnimation { - NumberAnimation { properties: "x,y"; duration: 500; easing.type: "InOutQuad" } + NumberAnimation { properties: "x,y"; duration: 500; easing.type: Easing.InOutQuad } } }, Transition { from: "Details"; to: "Show" SequentialAnimation { ParentAnimation { - NumberAnimation { properties: "x,y"; duration: 500; easing.type: "InOutQuad" } + NumberAnimation { properties: "x,y"; duration: 500; easing.type: Easing.InOutQuad } } PropertyAction { targets: wrapper; properties: "z" } } diff --git a/demos/declarative/flickr/mobile/ImageDetails.qml b/demos/declarative/flickr/mobile/ImageDetails.qml index 58b0b83..310c9df 100644 --- a/demos/declarative/flickr/mobile/ImageDetails.qml +++ b/demos/declarative/flickr/mobile/ImageDetails.qml @@ -114,7 +114,7 @@ Flipable { transitions: Transition { SequentialAnimation { PropertyAction { target: bigImage; property: "smooth"; value: false } - NumberAnimation { easing.type: "InOutQuad"; properties: "angle"; duration: 500 } + NumberAnimation { easing.type: Easing.InOutQuad; properties: "angle"; duration: 500 } PropertyAction { target: bigImage; property: "smooth"; value: !flickable.moving } } } diff --git a/demos/declarative/flickr/mobile/TitleBar.qml b/demos/declarative/flickr/mobile/TitleBar.qml index bb57429..025b897 100644 --- a/demos/declarative/flickr/mobile/TitleBar.qml +++ b/demos/declarative/flickr/mobile/TitleBar.qml @@ -81,6 +81,6 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; easing.type: "InOutQuad" } + NumberAnimation { properties: "x"; easing.type: Easing.InOutQuad } } } diff --git a/demos/declarative/minehunt/MinehuntCore/Tile.qml b/demos/declarative/minehunt/MinehuntCore/Tile.qml index f3620f4..98b2017 100644 --- a/demos/declarative/minehunt/MinehuntCore/Tile.qml +++ b/demos/declarative/minehunt/MinehuntCore/Tile.qml @@ -57,7 +57,7 @@ Flipable { PauseAnimation { duration: pauseDur } - RotationAnimation { easing.type: "InOutQuad" } + RotationAnimation { easing.type: Easing.InOutQuad } ScriptAction { script: if (modelData.hasMine && modelData.flipped) { expl.explode = true } } } } diff --git a/demos/declarative/photoviewer/PhotoViewerCore/AlbumDelegate.qml b/demos/declarative/photoviewer/PhotoViewerCore/AlbumDelegate.qml index d39b7bc..142735f 100644 --- a/demos/declarative/photoviewer/PhotoViewerCore/AlbumDelegate.qml +++ b/demos/declarative/photoviewer/PhotoViewerCore/AlbumDelegate.qml @@ -78,11 +78,11 @@ Component { ] GridView.onAdd: NumberAnimation { - target: albumWrapper; properties: "scale"; from: 0.0; to: 1.0; easing.type: "OutQuad" + target: albumWrapper; properties: "scale"; from: 0.0; to: 1.0; easing.type: Easing.OutQuad } GridView.onRemove: SequentialAnimation { PropertyAction { target: albumWrapper; property: "GridView.delayRemove"; value: true } - NumberAnimation { target: albumWrapper; property: "scale"; from: 1.0; to: 0.0; easing.type: "OutQuad" } + NumberAnimation { target: albumWrapper; property: "scale"; from: 1.0; to: 0.0; easing.type: Easing.OutQuad } PropertyAction { target: albumWrapper; property: "GridView.delayRemove"; value: false } } @@ -92,12 +92,12 @@ Component { SequentialAnimation { NumberAnimation { properties: 'opacity'; duration: 250 } PauseAnimation { duration: 350 } - NumberAnimation { target: backButton; properties: "y"; duration: 200; easing.type: "OutQuad" } + NumberAnimation { target: backButton; properties: "y"; duration: 200; easing.type: Easing.OutQuad } } }, Transition { from: 'inGrid'; to: '*' - NumberAnimation { properties: "y,opacity"; easing.type: "OutQuad"; duration: 300 } + NumberAnimation { properties: "y,opacity"; easing.type: Easing.OutQuad; duration: 300 } } ] } diff --git a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml index c1ae3e5..11aa74f 100644 --- a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml +++ b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml @@ -113,7 +113,7 @@ Item { transitions: [ Transition { from: "*"; to: "*" - NumberAnimation { properties: "x,y,width,height"; easing.type: "InOutQuad" } + NumberAnimation { properties: "x,y,width,height"; easing.type: Easing.InOutQuad } } ] } diff --git a/demos/declarative/twitter/TwitterCore/MultiTitleBar.qml b/demos/declarative/twitter/TwitterCore/MultiTitleBar.qml index 8c27e2b..445eda4 100644 --- a/demos/declarative/twitter/TwitterCore/MultiTitleBar.qml +++ b/demos/declarative/twitter/TwitterCore/MultiTitleBar.qml @@ -18,7 +18,7 @@ Item { } ] transitions: [ - Transition { NumberAnimation { properties: "x,y"; duration: 500; easing.type: "InOutQuad" } } + Transition { NumberAnimation { properties: "x,y"; duration: 500; easing.type: Easing.InOutQuad } } ] } diff --git a/demos/declarative/twitter/TwitterCore/TitleBar.qml b/demos/declarative/twitter/TwitterCore/TitleBar.qml index 87ceec5..5256de4 100644 --- a/demos/declarative/twitter/TwitterCore/TitleBar.qml +++ b/demos/declarative/twitter/TwitterCore/TitleBar.qml @@ -70,6 +70,6 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; easing.type: "InOutQuad" } + NumberAnimation { properties: "x"; easing.type: Easing.InOutQuad } } } diff --git a/demos/declarative/twitter/twitter.qml b/demos/declarative/twitter/twitter.qml index 0e3ec3e..f86388e 100644 --- a/demos/declarative/twitter/twitter.qml +++ b/demos/declarative/twitter/twitter.qml @@ -88,7 +88,7 @@ Item { } ] transitions: [ - Transition { NumberAnimation { properties: "x,y"; duration: 500; easing.type: "InOutQuad" } } + Transition { NumberAnimation { properties: "x,y"; duration: 500; easing.type: Easing.InOutQuad } } ] } } diff --git a/demos/declarative/webbrowser/content/RetractingWebBrowserHeader.qml b/demos/declarative/webbrowser/content/RetractingWebBrowserHeader.qml index f5bfadf..b02a5bf 100644 --- a/demos/declarative/webbrowser/content/RetractingWebBrowserHeader.qml +++ b/demos/declarative/webbrowser/content/RetractingWebBrowserHeader.qml @@ -105,7 +105,7 @@ Image { NumberAnimation { targets: header properties: "progressOff" - easing.type: "InOutQuad" + easing.type: Easing.InOutQuad duration: 300 } } diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index fbbe7b2..f1a6034 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -99,7 +99,7 @@ Item { Transition { NumberAnimation { properties: "opacity" - easing.type: "InOutQuad" + easing.type: Easing.InOutQuad duration: 300 } } @@ -155,7 +155,7 @@ Item { Transition { NumberAnimation { properties: "opacity" - easing.type: "InOutQuad" + easing.type: Easing.InOutQuad duration: 320 } } diff --git a/examples/declarative/animations/easing.qml b/examples/declarative/animations/easing.qml index b0f9669..939d43b 100644 --- a/examples/declarative/animations/easing.qml +++ b/examples/declarative/animations/easing.qml @@ -6,47 +6,47 @@ Rectangle { ListModel { id: easingTypes - ListElement { type: "Linear"; ballColor: "DarkRed" } - ListElement { type: "InQuad"; ballColor: "IndianRed" } - ListElement { type: "OutQuad"; ballColor: "Salmon" } - ListElement { type: "InOutQuad"; ballColor: "Tomato" } - ListElement { type: "OutInQuad"; ballColor: "DarkOrange" } - ListElement { type: "InCubic"; ballColor: "Gold" } - ListElement { type: "OutCubic"; ballColor: "Yellow" } - ListElement { type: "InOutCubic"; ballColor: "PeachPuff" } - ListElement { type: "OutInCubic"; ballColor: "Thistle" } - ListElement { type: "InQuart"; ballColor: "Orchid" } - ListElement { type: "OutQuart"; ballColor: "Purple" } - ListElement { type: "InOutQuart"; ballColor: "SlateBlue" } - ListElement { type: "OutInQuart"; ballColor: "Chartreuse" } - ListElement { type: "InQuint"; ballColor: "LimeGreen" } - ListElement { type: "OutQuint"; ballColor: "SeaGreen" } - ListElement { type: "InOutQuint"; ballColor: "DarkGreen" } - ListElement { type: "OutInQuint"; ballColor: "Olive" } - ListElement { type: "InSine"; ballColor: "DarkSeaGreen" } - ListElement { type: "OutSine"; ballColor: "Teal" } - ListElement { type: "InOutSine"; ballColor: "Turquoise" } - ListElement { type: "OutInSine"; ballColor: "SteelBlue" } - ListElement { type: "InExpo"; ballColor: "SkyBlue" } - ListElement { type: "OutExpo"; ballColor: "RoyalBlue" } - ListElement { type: "InOutExpo"; ballColor: "MediumBlue" } - ListElement { type: "OutInExpo"; ballColor: "MidnightBlue" } - ListElement { type: "InCirc"; ballColor: "CornSilk" } - ListElement { type: "OutCirc"; ballColor: "Bisque" } - ListElement { type: "InOutCirc"; ballColor: "RosyBrown" } - ListElement { type: "OutInCirc"; ballColor: "SandyBrown" } - ListElement { type: "InElastic"; ballColor: "DarkGoldenRod" } - ListElement { type: "OutElastic"; ballColor: "Chocolate" } - ListElement { type: "InOutElastic"; ballColor: "SaddleBrown" } - ListElement { type: "OutInElastic"; ballColor: "Brown" } - ListElement { type: "InBack"; ballColor: "Maroon" } - ListElement { type: "OutBack"; ballColor: "LavenderBlush" } - ListElement { type: "InOutBack"; ballColor: "MistyRose" } - ListElement { type: "OutInBack"; ballColor: "Gainsboro" } - ListElement { type: "OutBounce"; ballColor: "Silver" } - ListElement { type: "InBounce"; ballColor: "DimGray" } - ListElement { type: "InOutBounce"; ballColor: "SlateGray" } - ListElement { type: "OutInBounce"; ballColor: "DarkSlateGray" } + ListElement { name: "Easing.Linear"; type: Easing.Linear; ballColor: "DarkRed" } + ListElement { name: "Easing.InQuad"; type: Easing.InQuad; ballColor: "IndianRed" } + ListElement { name: "Easing.OutQuad"; type: Easing.OutQuad; ballColor: "Salmon" } + ListElement { name: "Easing.InOutQuad"; type: Easing.InOutQuad; ballColor: "Tomato" } + ListElement { name: "Easing.OutInQuad"; type: Easing.OutInQuad; ballColor: "DarkOrange" } + ListElement { name: "Easing.InCubic"; type: Easing.InCubic; ballColor: "Gold" } + ListElement { name: "Easing.OutCubic"; type: Easing.OutCubic; ballColor: "Yellow" } + ListElement { name: "Easing.InOutCubic"; type: Easing.InOutCubic; ballColor: "PeachPuff" } + ListElement { name: "Easing.OutInCubic"; type: Easing.OutInCubic; ballColor: "Thistle" } + ListElement { name: "Easing.InQuart"; type: Easing.InQuart; ballColor: "Orchid" } + ListElement { name: "Easing.OutQuart"; type: Easing.OutQuart; ballColor: "Purple" } + ListElement { name: "Easing.InOutQuart"; type: Easing.InOutQuart; ballColor: "SlateBlue" } + ListElement { name: "Easing.OutInQuart"; type: Easing.OutInQuart; ballColor: "Chartreuse" } + ListElement { name: "Easing.InQuint"; type: Easing.InQuint; ballColor: "LimeGreen" } + ListElement { name: "Easing.OutQuint"; type: Easing.OutQuint; ballColor: "SeaGreen" } + ListElement { name: "Easing.InOutQuint"; type: Easing.InOutQuint; ballColor: "DarkGreen" } + ListElement { name: "Easing.OutInQuint"; type: Easing.OutInQuint; ballColor: "Olive" } + ListElement { name: "Easing.InSine"; type: Easing.InSine; ballColor: "DarkSeaGreen" } + ListElement { name: "Easing.OutSine"; type: Easing.OutSine; ballColor: "Teal" } + ListElement { name: "Easing.InOutSine"; type: Easing.InOutSine; ballColor: "Turquoise" } + ListElement { name: "Easing.OutInSine"; type: Easing.OutInSine; ballColor: "SteelBlue" } + ListElement { name: "Easing.InExpo"; type: Easing.InExpo; ballColor: "SkyBlue" } + ListElement { name: "Easing.OutExpo"; type: Easing.OutExpo; ballColor: "RoyalBlue" } + ListElement { name: "Easing.InOutExpo"; type: Easing.InOutExpo; ballColor: "MediumBlue" } + ListElement { name: "Easing.OutInExpo"; type: Easing.OutInExpo; ballColor: "MidnightBlue" } + ListElement { name: "Easing.InCirc"; type: Easing.InCirc; ballColor: "CornSilk" } + ListElement { name: "Easing.OutCirc"; type: Easing.OutCirc; ballColor: "Bisque" } + ListElement { name: "Easing.InOutCirc"; type: Easing.InOutCirc; ballColor: "RosyBrown" } + ListElement { name: "Easing.OutInCirc"; type: Easing.OutInCirc; ballColor: "SandyBrown" } + ListElement { name: "Easing.InElastic"; type: Easing.InElastic; ballColor: "DarkGoldenRod" } + ListElement { name: "Easing.InElastic"; type: Easing.OutElastic; ballColor: "Chocolate" } + ListElement { name: "Easing.InOutElastic"; type: Easing.InOutElastic; ballColor: "SaddleBrown" } + ListElement { name: "Easing.OutInElastic"; type: Easing.OutInElastic; ballColor: "Brown" } + ListElement { name: "Easing.InBack"; type: Easing.InBack; ballColor: "Maroon" } + ListElement { name: "Easing.OutBack"; type: Easing.OutBack; ballColor: "LavenderBlush" } + ListElement { name: "Easing.InOutBack"; type: Easing.InOutBack; ballColor: "MistyRose" } + ListElement { name: "Easing.OutInBack"; type: Easing.OutInBack; ballColor: "Gainsboro" } + ListElement { name: "Easing.OutBounce"; type: Easing.OutBounce; ballColor: "Silver" } + ListElement { name: "Easing.InBounce"; type: Easing.InBounce; ballColor: "DimGray" } + ListElement { name: "Easing.InOutBounce"; type: Easing.InOutBounce; ballColor: "SlateGray" } + ListElement { name: "Easing.OutInBounce"; type: Easing.OutInBounce; ballColor: "DarkSlateGray" } } Component { @@ -54,19 +54,26 @@ Rectangle { Item { height: 42; width: window.width - Text { text: type; anchors.centerIn: parent; color: "White" } + + Text { text: name; anchors.centerIn: parent; color: "White" } + Rectangle { id: slot1; color: "#121212"; x: 30; height: 32; width: 32 - border.color: "#343434"; border.width: 1; radius: 8; anchors.verticalCenter: parent.verticalCenter + border.color: "#343434"; border.width: 1; radius: 8 + anchors.verticalCenter: parent.verticalCenter } + Rectangle { id: slot2; color: "#121212"; x: window.width - 62; height: 32; width: 32 - border.color: "#343434"; border.width: 1; radius: 8; anchors.verticalCenter: parent.verticalCenter + border.color: "#343434"; border.width: 1; radius: 8 + anchors.verticalCenter: parent.verticalCenter } + Rectangle { id: rect; x: 30; color: "#454545" border.color: "White"; border.width: 2 - height: 32; width: 32; radius: 8; anchors.verticalCenter: parent.verticalCenter + height: 32; width: 32; radius: 8 + anchors.verticalCenter: parent.verticalCenter MouseArea { onClicked: if (rect.state == '') rect.state = "right"; else rect.state = '' @@ -79,10 +86,8 @@ Rectangle { } transitions: Transition { - // ParallelAnimation { - NumberAnimation { properties: "x"; easing.type: type; duration: 1000 } - ColorAnimation { properties: "color"; easing.type: type; duration: 1000 } - // } + NumberAnimation { properties: "x"; easing.type: type; duration: 1000 } + ColorAnimation { properties: "color"; easing.type: type; duration: 1000 } } } } @@ -90,6 +95,7 @@ Rectangle { Flickable { anchors.fill: parent; contentHeight: layout.height + Column { id: layout anchors.left: parent.left; anchors.right: parent.right diff --git a/examples/declarative/animations/property-animation.qml b/examples/declarative/animations/property-animation.qml index 5afe8ef..6360511 100644 --- a/examples/declarative/animations/property-animation.qml +++ b/examples/declarative/animations/property-animation.qml @@ -48,13 +48,13 @@ Item { // Move from minHeight to maxHeight in 300ms, using the OutExpo easing function NumberAnimation { from: smiley.minHeight; to: smiley.maxHeight - easing.type: "OutExpo"; duration: 300 + easing.type: Easing.OutExpo; duration: 300 } // Then move back to minHeight in 1 second, using the OutBounce easing function NumberAnimation { from: smiley.maxHeight; to: smiley.minHeight - easing.type: "OutBounce"; duration: 1000 + easing.type: Easing.OutBounce; duration: 1000 } // Then pause for 500ms diff --git a/examples/declarative/behaviors/behavior-example.qml b/examples/declarative/behaviors/behavior-example.qml index b7bae6c..1f17b81 100644 --- a/examples/declarative/behaviors/behavior-example.qml +++ b/examples/declarative/behaviors/behavior-example.qml @@ -49,12 +49,12 @@ Rectangle { // Setting an 'elastic' behavior on the focusRect's x property. Behavior on x { - NumberAnimation { easing.type: "OutElastic"; easing.amplitude: 3.0; easing.period: 2.0; duration: 300 } + NumberAnimation { easing.type: Easing.OutElastic; easing.amplitude: 3.0; easing.period: 2.0; duration: 300 } } // Setting an 'elastic' behavior on the focusRect's y property. Behavior on y { - NumberAnimation { easing.type: "OutElastic"; easing.amplitude: 3.0; easing.period: 2.0; duration: 300 } + NumberAnimation { easing.type: Easing.OutElastic; easing.amplitude: 3.0; easing.period: 2.0; duration: 300 } } Text { diff --git a/examples/declarative/border-image/content/MyBorderImage.qml b/examples/declarative/border-image/content/MyBorderImage.qml index 2573a14..b47df7b 100644 --- a/examples/declarative/border-image/content/MyBorderImage.qml +++ b/examples/declarative/border-image/content/MyBorderImage.qml @@ -20,14 +20,26 @@ Item { SequentialAnimation on width { loops: Animation.Infinite - NumberAnimation { from: container.minWidth; to: container.maxWidth; duration: 2000; easing.type: "InOutQuad"} - NumberAnimation { from: container.maxWidth; to: container.minWidth; duration: 2000; easing.type: "InOutQuad" } + NumberAnimation { + from: container.minWidth; to: container.maxWidth + duration: 2000; easing.type: Easing.InOutQuad + } + NumberAnimation { + from: container.maxWidth; to: container.minWidth + duration: 2000; easing.type: Easing.InOutQuad + } } SequentialAnimation on height { loops: Animation.Infinite - NumberAnimation { from: container.minHeight; to: container.maxHeight; duration: 2000; easing.type: "InOutQuad"} - NumberAnimation { from: container.maxHeight; to: container.minHeight; duration: 2000; easing.type: "InOutQuad" } + NumberAnimation { + from: container.minHeight; to: container.maxHeight + duration: 2000; easing.type: Easing.InOutQuad + } + NumberAnimation { + from: container.maxHeight; to: container.minHeight + duration: 2000; easing.type: Easing.InOutQuad + } } border.top: container.margin diff --git a/examples/declarative/connections/connections-example.qml b/examples/declarative/connections/connections-example.qml index fbef968..1dd10ab 100644 --- a/examples/declarative/connections/connections-example.qml +++ b/examples/declarative/connections/connections-example.qml @@ -17,7 +17,7 @@ Rectangle { rotation: window.angle Behavior on rotation { - NumberAnimation { easing.type: "OutCubic"; duration: 300 } + NumberAnimation { easing.type: Easing.OutCubic; duration: 300 } } } diff --git a/examples/declarative/focus/Core/ListViews.qml b/examples/declarative/focus/Core/ListViews.qml index 089f821..32a5d4c 100644 --- a/examples/declarative/focus/Core/ListViews.qml +++ b/examples/declarative/focus/Core/ListViews.qml @@ -14,7 +14,7 @@ FocusScope { delegate: ListViewDelegate {} Behavior on y { - NumberAnimation { duration: 600; easing.type: "OutQuint" } + NumberAnimation { duration: 600; easing.type: Easing.OutQuint } } } @@ -26,7 +26,7 @@ FocusScope { delegate: ListViewDelegate {} Behavior on y { - NumberAnimation { duration: 600; easing.type: "OutQuint" } + NumberAnimation { duration: 600; easing.type: Easing.OutQuint } } } @@ -38,7 +38,7 @@ FocusScope { delegate: ListViewDelegate {} Behavior on y { - NumberAnimation { duration: 600; easing.type: "OutQuint" } + NumberAnimation { duration: 600; easing.type: Easing.OutQuint } } } diff --git a/examples/declarative/focus/focus.qml b/examples/declarative/focus/focus.qml index 22b0e50..8c992ae 100644 --- a/examples/declarative/focus/focus.qml +++ b/examples/declarative/focus/focus.qml @@ -38,7 +38,7 @@ Rectangle { } transitions: Transition { - NumberAnimation { properties: "y"; duration: 600; easing.type: "OutQuint" } + NumberAnimation { properties: "y"; duration: 600; easing.type: Easing.OutQuint } } } @@ -64,6 +64,6 @@ Rectangle { } transitions: Transition { - NumberAnimation { properties: "x,opacity"; duration: 600; easing.type: "OutQuint" } + NumberAnimation { properties: "x,opacity"; duration: 600; easing.type: Easing.OutQuint } } } diff --git a/examples/declarative/fonts/hello.qml b/examples/declarative/fonts/hello.qml index d4d0e4c..0d6f4cd 100644 --- a/examples/declarative/fonts/hello.qml +++ b/examples/declarative/fonts/hello.qml @@ -19,7 +19,7 @@ Rectangle { SequentialAnimation on font.letterSpacing { loops: Animation.Infinite; - NumberAnimation { from: 100; to: 300; easing.type: "InQuad"; duration: 3000 } + NumberAnimation { from: 100; to: 300; easing.type: Easing.InQuad; duration: 3000 } ScriptAction { script: { container.y = (screen.height / 4) + (Math.random() * screen.height / 2) diff --git a/examples/declarative/layouts/Button.qml b/examples/declarative/layouts/Button.qml index 0f08893..d03eeb5 100644 --- a/examples/declarative/layouts/Button.qml +++ b/examples/declarative/layouts/Button.qml @@ -1,22 +1,38 @@ import Qt 4.7 -Rectangle { border.color: "black"; color: "steelblue"; radius: 5; width: pix.width + textelement.width + 13; height: pix.height + 10; id: page +Rectangle { + id: page + property string text property string icon signal clicked - Image { id: pix; x: 5; y:5; source: parent.icon} - Text { id: textelement; text: page.text; color: "white"; x:pix.width+pix.x+3; anchors.verticalCenter: pix.verticalCenter;} - MouseArea{ id:mr; anchors.fill: parent; onClicked: {parent.focus = true; page.clicked()}} + border.color: "black"; color: "steelblue"; radius: 5 + width: pix.width + textelement.width + 13 + height: pix.height + 10 + + Image { id: pix; x: 5; y:5; source: parent.icon } + + Text { + id: textelement + text: page.text; color: "white" + x: pix.width + pix.x + 3 + anchors.verticalCenter: pix.verticalCenter + } + + MouseArea { + id: mr + anchors.fill: parent + onClicked: { parent.focus = true; page.clicked() } + } - states: - State{ name:"pressed"; when:mr.pressed - PropertyChanges {target:textelement; x: 5} - PropertyChanges {target:pix; x:textelement.x+textelement.width + 3} - } + states: State { + name: "pressed"; when: mr.pressed + PropertyChanges { target: textelement; x: 5 } + PropertyChanges { target: pix; x: textelement.x + textelement.width + 3 } + } - transitions: - Transition{ - NumberAnimation { properties:"x,left"; easing.type:"InOutQuad"; duration:200 } - } + transitions: Transition { + NumberAnimation { properties: "x,left"; easing.type: Easing.InOutQuad; duration: 200 } + } } diff --git a/examples/declarative/layouts/positioners.qml b/examples/declarative/layouts/positioners.qml index 3703b59..2cb0b8b 100644 --- a/examples/declarative/layouts/positioners.qml +++ b/examples/declarative/layouts/positioners.qml @@ -8,10 +8,10 @@ Rectangle { id: layout1 y: 0 move: Transition { - NumberAnimation { properties: "y"; easing.type: "OutBounce" } + NumberAnimation { properties: "y"; easing.type: Easing.OutBounce } } add: Transition { - NumberAnimation { properties: "y"; easing.type: "OutQuad" } + NumberAnimation { properties: "y"; easing.type: Easing.OutQuad } } Rectangle { color: "red"; width: 100; height: 50; border.color: "black"; radius: 15 } @@ -43,10 +43,10 @@ Rectangle { id: layout2 y: 300 move: Transition { - NumberAnimation { properties: "x"; easing.type: "OutBounce" } + NumberAnimation { properties: "x"; easing.type: Easing.OutBounce } } add: Transition { - NumberAnimation { properties: "x"; easing.type: "OutQuad" } + NumberAnimation { properties: "x"; easing.type: Easing.OutQuad } } Rectangle { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 } @@ -117,11 +117,11 @@ Rectangle { columns: 3 move: Transition { - NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } + NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce } } add: Transition { - NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } + NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce } } Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } @@ -167,11 +167,11 @@ Rectangle { x: 260; y: 250; width: 150 move: Transition { - NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } + NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce } } add: Transition { - NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } + NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce } } Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } diff --git a/examples/declarative/parallax/qml/Smiley.qml b/examples/declarative/parallax/qml/Smiley.qml index b1e1ae8..cfa4fed 100644 --- a/examples/declarative/parallax/qml/Smiley.qml +++ b/examples/declarative/parallax/qml/Smiley.qml @@ -30,13 +30,13 @@ Item { // Move from minHeight to maxHeight in 300ms, using the OutExpo easing function NumberAnimation { from: smiley.minHeight; to: smiley.maxHeight - easing.type: "OutExpo"; duration: 300 + easing.type: Easing.OutExpo; duration: 300 } // Then move back to minHeight in 1 second, using the OutBounce easing function NumberAnimation { from: smiley.maxHeight; to: smiley.minHeight - easing.type: "OutBounce"; duration: 1000 + easing.type: Easing.OutBounce; duration: 1000 } // Then pause for 500ms diff --git a/examples/declarative/proxywidgets/proxywidgets.qml b/examples/declarative/proxywidgets/proxywidgets.qml index 46dcf99..88de37f 100644 --- a/examples/declarative/proxywidgets/proxywidgets.qml +++ b/examples/declarative/proxywidgets/proxywidgets.qml @@ -63,7 +63,7 @@ Rectangle { transitions: Transition { ParallelAnimation { - NumberAnimation { properties: "x,y,rotation"; duration: 600; easing.type: "OutQuad" } + NumberAnimation { properties: "x,y,rotation"; duration: 600; easing.type: Easing.OutQuad } ColorAnimation { target: window; duration: 600 } } } diff --git a/examples/declarative/slideswitch/content/Switch.qml b/examples/declarative/slideswitch/content/Switch.qml index a8fa6ef..1aa7696 100644 --- a/examples/declarative/slideswitch/content/Switch.qml +++ b/examples/declarative/slideswitch/content/Switch.qml @@ -69,7 +69,7 @@ Item { //![7] transitions: Transition { - NumberAnimation { properties: "x"; easing.type: "InOutQuad"; duration: 200 } + NumberAnimation { properties: "x"; easing.type: Easing.InOutQuad; duration: 200 } } //![7] } diff --git a/examples/declarative/states/transitions.qml b/examples/declarative/states/transitions.qml index d1b1dd6..ccc7060 100644 --- a/examples/declarative/states/transitions.qml +++ b/examples/declarative/states/transitions.qml @@ -72,14 +72,14 @@ Rectangle { // with OutBounce easing function. Transition { from: "*"; to: "middleRight" - NumberAnimation { properties: "x,y"; easing.type: "OutBounce"; duration: 1000 } + NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce; duration: 1000 } }, // When transitioning to 'bottomLeft' move x,y over a duration of 2 seconds, // with InOutQuad easing function. Transition { from: "*"; to: "bottomLeft" - NumberAnimation { properties: "x,y"; easing.type: "InOutQuad"; duration: 2000 } + NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad; duration: 2000 } }, // For any other state changes move x,y linearly over duration of 200ms. diff --git a/examples/declarative/tutorials/helloworld/tutorial3.qml b/examples/declarative/tutorials/helloworld/tutorial3.qml index 041d9a9..0da762c 100644 --- a/examples/declarative/tutorials/helloworld/tutorial3.qml +++ b/examples/declarative/tutorials/helloworld/tutorial3.qml @@ -28,7 +28,7 @@ Rectangle { transitions: Transition { from: ""; to: "down"; reversible: true ParallelAnimation { - NumberAnimation { properties: "y,rotation"; duration: 500; easing.type: "InOutQuad" } + NumberAnimation { properties: "y,rotation"; duration: 500; easing.type: Easing.InOutQuad } ColorAnimation { duration: 500 } } } diff --git a/examples/declarative/xmldata/yahoonews.qml b/examples/declarative/xmldata/yahoonews.qml index 668778e..5bab463 100644 --- a/examples/declarative/xmldata/yahoonews.qml +++ b/examples/declarative/xmldata/yahoonews.qml @@ -65,7 +65,7 @@ Rectangle { transitions: Transition { from: "*"; to: "Details"; reversible: true SequentialAnimation { - NumberAnimation { duration: 200; properties: "height"; easing.type: "OutQuad" } + NumberAnimation { duration: 200; properties: "height"; easing.type: Easing.OutQuad } NumberAnimation { duration: 200; properties: "opacity" } } } diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 4c72482..9ae7279 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -964,7 +964,7 @@ QDeclarativeGridView::~QDeclarativeGridView() id: wrapper GridView.onRemove: SequentialAnimation { PropertyAction { target: wrapper; property: "GridView.delayRemove"; value: true } - NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: "InOutQuad" } + NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: Easing.InOutQuad } PropertyAction { target: wrapper; property: "GridView.delayRemove"; value: false } } } diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 3877fab..cef7e18 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1395,7 +1395,7 @@ QDeclarativeListView::~QDeclarativeListView() id: wrapper ListView.onRemove: SequentialAnimation { PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: true } - NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: "InOutQuad" } + NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: Easing.InOutQuad } PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: false } } } diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 206b09d..93bff3e 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -377,7 +377,7 @@ Column { move: Transition { NumberAnimation { properties: "y" - easing.type: "OutBounce" + easing.type: Easing.OutBounce } } } diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 9f95348..7f4d2e4 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -1615,7 +1615,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int Animate any objects that have changed their x or y properties in the target state using an InOutQuad easing curve: \qml - Transition { PropertyAnimation { properties: "x,y"; easing.type: "InOutQuad" } } + Transition { PropertyAnimation { properties: "x,y"; easing.type: Easing.InOutQuad } } \endqml \o In a Behavior diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index 90344ab..ba90007 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -82,7 +82,7 @@ public: y: 200 // initial value Behavior on y { NumberAnimation { - easing.type: "OutBounce" + easing.type: Easing.OutBounce easing.amplitude: 100 duration: 200 } diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringfollow.cpp index 70077f3..aae66ac 100644 --- a/src/declarative/util/qdeclarativespringfollow.cpp +++ b/src/declarative/util/qdeclarativespringfollow.cpp @@ -227,7 +227,7 @@ void QDeclarativeSpringFollowPrivate::stop() loops: Animation.Infinite NumberAnimation { to: 200 - easing.type: "OutBounce" + easing.type: Easing.OutBounce easing.amplitude: 100 duration: 2000 } -- cgit v0.12 From ab030e931e05a060b4f6fabf4235f05aeb0c252c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 5 May 2010 16:39:05 +1000 Subject: Fix cacheBuffer documentation. Task-number: QTBUG-10385 --- .../graphicsitems/qdeclarativegridview.cpp | 20 ++++++++++++++------ .../graphicsitems/qdeclarativelistview.cpp | 18 +++++++++++++----- src/declarative/util/qdeclarativeanimation.cpp | 2 +- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 4c72482..528cb22 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1405,12 +1405,20 @@ void QDeclarativeGridView::setWrapEnabled(bool wrap) } /*! - \qmlproperty int GridView::cacheBuffer - This property holds the number of off-screen pixels to cache. - - This property determines the number of pixels above the top of the view - and below the bottom of the view to cache. Setting this value can make - scrolling the view smoother at the expense of additional memory usage. + \qmlproperty int GridView::cacheBuffer + This property determines whether delegates are retained outside the + visible area of the view. + + If non-zero the view will keep as many delegates + instantiated as will fit within the buffer specified. For example, + if in a vertical view the delegate is 20 pixels high and \c cacheBuffer is + set to 40, then up to 2 delegates above and 2 delegates below the visible + area may be retained. + + Setting this value can make scrolling the list smoother at the expense + of additional memory usage. It is not a substitute for creating efficient + delegates; the fewer elements in a delegate, the faster a view may be + scrolled. */ int QDeclarativeGridView::cacheBuffer() const { diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 3877fab..75cf547 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1839,11 +1839,19 @@ void QDeclarativeListView::setWrapEnabled(bool wrap) /*! \qmlproperty int ListView::cacheBuffer - This property holds the number of off-screen pixels to cache. - - This property determines the number of pixels above the top of the list - and below the bottom of the list to cache. Setting this value can make - scrolling the list smoother at the expense of additional memory usage. + This property determines whether delegates are retained outside the + visible area of the view. + + If non-zero the view will keep as many delegates + instantiated as will fit within the buffer specified. For example, + if in a vertical view the delegate is 20 pixels high and \c cacheBuffer is + set to 40, then up to 2 delegates above and 2 delegates below the visible + area may be retained. + + Setting this value can make scrolling the list smoother at the expense + of additional memory usage. It is not a substitute for creating efficient + delegates; the fewer elements in a delegate, the faster a view may be + scrolled. */ int QDeclarativeListView::cacheBuffer() const { diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 9f95348..5b2954b 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -874,7 +874,7 @@ void QDeclarativePropertyActionPrivate::init() This property holds an explicit target object to animate. The exact effect of the \c target property depends on how the animation - is being used. Refer to the \l animation documentation for details. + is being used. Refer to the \l {QML Animation} documentation for details. */ QObject *QDeclarativePropertyAction::target() const -- cgit v0.12 From 238ed995be8f32e815ffb6883144d0547355a8eb Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 4 May 2010 14:14:46 +0200 Subject: Move Qt.widgets import to be an unsupported example Layout examples for QML are also cleaned up a bit. Layouts test removed, and LayoutItem test added, to clarify what we support. Reviewed-by: Michael Brasser --- examples/declarative/layouts/Button.qml | 22 -- examples/declarative/layouts/add.png | Bin 1577 -> 0 bytes examples/declarative/layouts/del.png | Bin 1661 -> 0 bytes .../layouts/graphicsLayouts/graphicslayouts.cpp | 366 +++++++++++++++++++++ .../layouts/graphicsLayouts/graphicslayouts.pro | 13 + .../layouts/graphicsLayouts/graphicslayouts.qml | 77 +++++ .../layouts/graphicsLayouts/graphicslayouts.qrc | 5 + .../layouts/graphicsLayouts/graphicslayouts_p.h | 303 +++++++++++++++++ .../declarative/layouts/graphicsLayouts/main.cpp | 60 ++++ .../declarative/layouts/layoutItem/layoutItem.pro | 13 + .../declarative/layouts/layoutItem/layoutItem.qml | 16 + .../declarative/layouts/layoutItem/layoutItem.qrc | 5 + examples/declarative/layouts/layoutItem/main.cpp | 73 ++++ examples/declarative/layouts/layouts.qml | 29 -- examples/declarative/layouts/layouts.qmlproject | 16 - examples/declarative/layouts/positioners.qml | 213 ------------ .../declarative/layouts/positioners/Button.qml | 22 ++ examples/declarative/layouts/positioners/add.png | Bin 0 -> 1577 bytes examples/declarative/layouts/positioners/del.png | Bin 0 -> 1661 bytes .../layouts/positioners/positioners.qml | 213 ++++++++++++ .../layouts/positioners/positioners.qmlproject | 18 + .../positioners/positioners.qmlproject.user | 41 +++ src/imports/imports.pro | 2 +- src/imports/widgets/graphicslayouts.cpp | 366 --------------------- src/imports/widgets/graphicslayouts_p.h | 303 ----------------- src/imports/widgets/qmldir | 1 - src/imports/widgets/widgets.cpp | 71 ---- src/imports/widgets/widgets.pro | 30 -- .../qdeclarativelayoutitem/data/layoutItem.qml | 9 + .../qdeclarativelayoutitem.pro | 8 + .../tst_qdeclarativelayoutitem.cpp | 115 +++++++ .../qdeclarativelayouts/data/layouts.qml | 31 -- .../qdeclarativelayouts/qdeclarativelayouts.pro | 10 - .../tst_qdeclarativelayouts.cpp | 147 --------- 34 files changed, 1358 insertions(+), 1240 deletions(-) delete mode 100644 examples/declarative/layouts/Button.qml delete mode 100644 examples/declarative/layouts/add.png delete mode 100644 examples/declarative/layouts/del.png create mode 100644 examples/declarative/layouts/graphicsLayouts/graphicslayouts.cpp create mode 100644 examples/declarative/layouts/graphicsLayouts/graphicslayouts.pro create mode 100644 examples/declarative/layouts/graphicsLayouts/graphicslayouts.qml create mode 100644 examples/declarative/layouts/graphicsLayouts/graphicslayouts.qrc create mode 100644 examples/declarative/layouts/graphicsLayouts/graphicslayouts_p.h create mode 100644 examples/declarative/layouts/graphicsLayouts/main.cpp create mode 100644 examples/declarative/layouts/layoutItem/layoutItem.pro create mode 100644 examples/declarative/layouts/layoutItem/layoutItem.qml create mode 100644 examples/declarative/layouts/layoutItem/layoutItem.qrc create mode 100644 examples/declarative/layouts/layoutItem/main.cpp delete mode 100644 examples/declarative/layouts/layouts.qml delete mode 100644 examples/declarative/layouts/layouts.qmlproject delete mode 100644 examples/declarative/layouts/positioners.qml create mode 100644 examples/declarative/layouts/positioners/Button.qml create mode 100644 examples/declarative/layouts/positioners/add.png create mode 100644 examples/declarative/layouts/positioners/del.png create mode 100644 examples/declarative/layouts/positioners/positioners.qml create mode 100644 examples/declarative/layouts/positioners/positioners.qmlproject create mode 100644 examples/declarative/layouts/positioners/positioners.qmlproject.user delete mode 100644 src/imports/widgets/graphicslayouts.cpp delete mode 100644 src/imports/widgets/graphicslayouts_p.h delete mode 100644 src/imports/widgets/qmldir delete mode 100644 src/imports/widgets/widgets.cpp delete mode 100644 src/imports/widgets/widgets.pro create mode 100644 tests/auto/declarative/qdeclarativelayoutitem/data/layoutItem.qml create mode 100644 tests/auto/declarative/qdeclarativelayoutitem/qdeclarativelayoutitem.pro create mode 100644 tests/auto/declarative/qdeclarativelayoutitem/tst_qdeclarativelayoutitem.cpp delete mode 100644 tests/auto/declarative/qdeclarativelayouts/data/layouts.qml delete mode 100644 tests/auto/declarative/qdeclarativelayouts/qdeclarativelayouts.pro delete mode 100644 tests/auto/declarative/qdeclarativelayouts/tst_qdeclarativelayouts.cpp diff --git a/examples/declarative/layouts/Button.qml b/examples/declarative/layouts/Button.qml deleted file mode 100644 index 0f08893..0000000 --- a/examples/declarative/layouts/Button.qml +++ /dev/null @@ -1,22 +0,0 @@ -import Qt 4.7 - -Rectangle { border.color: "black"; color: "steelblue"; radius: 5; width: pix.width + textelement.width + 13; height: pix.height + 10; id: page - property string text - property string icon - signal clicked - - Image { id: pix; x: 5; y:5; source: parent.icon} - Text { id: textelement; text: page.text; color: "white"; x:pix.width+pix.x+3; anchors.verticalCenter: pix.verticalCenter;} - MouseArea{ id:mr; anchors.fill: parent; onClicked: {parent.focus = true; page.clicked()}} - - states: - State{ name:"pressed"; when:mr.pressed - PropertyChanges {target:textelement; x: 5} - PropertyChanges {target:pix; x:textelement.x+textelement.width + 3} - } - - transitions: - Transition{ - NumberAnimation { properties:"x,left"; easing.type:"InOutQuad"; duration:200 } - } -} diff --git a/examples/declarative/layouts/add.png b/examples/declarative/layouts/add.png deleted file mode 100644 index f29d84b..0000000 Binary files a/examples/declarative/layouts/add.png and /dev/null differ diff --git a/examples/declarative/layouts/del.png b/examples/declarative/layouts/del.png deleted file mode 100644 index 1d753a3..0000000 Binary files a/examples/declarative/layouts/del.png and /dev/null differ diff --git a/examples/declarative/layouts/graphicsLayouts/graphicslayouts.cpp b/examples/declarative/layouts/graphicsLayouts/graphicslayouts.cpp new file mode 100644 index 0000000..25cf994 --- /dev/null +++ b/examples/declarative/layouts/graphicsLayouts/graphicslayouts.cpp @@ -0,0 +1,366 @@ +/**************************************************************************** +** +** 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 "graphicslayouts_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +LinearLayoutAttached::LinearLayoutAttached(QObject *parent) +: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter), _spacing(0) +{ +} + +void LinearLayoutAttached::setStretchFactor(int f) +{ + if (_stretch == f) + return; + + _stretch = f; + emit stretchChanged(reinterpret_cast(parent()), _stretch); +} + +void LinearLayoutAttached::setSpacing(int s) +{ + if (_spacing == s) + return; + + _spacing = s; + emit spacingChanged(reinterpret_cast(parent()), _spacing); +} + +void LinearLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (_alignment == a) + return; + + _alignment = a; + emit alignmentChanged(reinterpret_cast(parent()), _alignment); +} + +QGraphicsLinearLayoutStretchItemObject::QGraphicsLinearLayoutStretchItemObject(QObject *parent) + : QObject(parent) +{ +} + +QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ +Q_UNUSED(which); +Q_UNUSED(constraint); +return QSizeF(); +} + + +QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +QGraphicsLinearLayoutObject::~QGraphicsLinearLayoutObject() +{ +} + +void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item) +{ +insertItem(index, item); + +//connect attached properties +if (LinearLayoutAttached *obj = attachedProperties.value(item)) { + setStretchFactor(item, obj->stretchFactor()); + setAlignment(item, obj->alignment()); + updateSpacing(item, obj->spacing()); + QObject::connect(obj, SIGNAL(stretchChanged(QGraphicsLayoutItem*,int)), + this, SLOT(updateStretch(QGraphicsLayoutItem*,int))); + QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), + this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); + QObject::connect(obj, SIGNAL(spacingChanged(QGraphicsLayoutItem*,int)), + this, SLOT(updateSpacing(QGraphicsLayoutItem*,int))); + //### need to disconnect when widget is removed? +} +} + +//### is there a better way to do this? +void QGraphicsLinearLayoutObject::clearChildren() +{ +for (int i = 0; i < count(); ++i) + removeAt(i); +} + +qreal QGraphicsLinearLayoutObject::contentsMargin() const +{ + qreal a,b,c,d; + getContentsMargins(&a, &b, &c, &d); + if(a==b && a==c && a==d) + return a; + return -1; +} + +void QGraphicsLinearLayoutObject::setContentsMargin(qreal m) +{ + setContentsMargins(m,m,m,m); +} + +void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) +{ +QGraphicsLinearLayout::setStretchFactor(item, stretch); +} + +void QGraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing) +{ + for(int i=0; i < count(); i++){ + if(itemAt(i) == item){ //I do not see the reverse function, which is why we must loop over all items + QGraphicsLinearLayout::setItemSpacing(i, spacing); + return; + } + } +} + +void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ +QGraphicsLinearLayout::setAlignment(item, alignment); +} + +QHash QGraphicsLinearLayoutObject::attachedProperties; +LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) +{ +// ### This is not allowed - you must attach to any object +if (!qobject_cast(obj)) + return 0; +LinearLayoutAttached *rv = new LinearLayoutAttached(obj); +attachedProperties.insert(qobject_cast(obj), rv); +return rv; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////// +// QGraphicsGridLayout-related classes +////////////////////////////////////////////////////////////////////////////////////////////////////// +GridLayoutAttached::GridLayoutAttached(QObject *parent) +: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1), _rowstretch(-1), + _colstretch(-1), _rowspacing(-1), _colspacing(-1), _rowprefheight(-1), _rowmaxheight(-1), _rowminheight(-1), + _rowfixheight(-1), _colprefwidth(-1), _colmaxwidth(-1), _colminwidth(-1), _colfixwidth(-1) +{ +} + +void GridLayoutAttached::setRow(int r) +{ + if (_row == r) + return; + + _row = r; + //emit rowChanged(reinterpret_cast(parent()), _row); +} + +void GridLayoutAttached::setColumn(int c) +{ + if (_column == c) + return; + + _column = c; + //emit columnChanged(reinterpret_cast(parent()), _column); +} + +void GridLayoutAttached::setRowSpan(int rs) +{ + if (_rowspan == rs) + return; + + _rowspan = rs; + //emit rowSpanChanged(reinterpret_cast(parent()), _rowSpan); +} + +void GridLayoutAttached::setColumnSpan(int cs) +{ + if (_colspan == cs) + return; + + _colspan = cs; + //emit columnSpanChanged(reinterpret_cast(parent()), _columnSpan); +} + +void GridLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (_alignment == a) + return; + + _alignment = a; + emit alignmentChanged(reinterpret_cast(parent()), _alignment); +} + +void GridLayoutAttached::setRowStretchFactor(int f) +{ + _rowstretch = f; +} + +void GridLayoutAttached::setColumnStretchFactor(int f) +{ + _colstretch = f; +} + +void GridLayoutAttached::setRowSpacing(int s) +{ + _rowspacing = s; +} + +void GridLayoutAttached::setColumnSpacing(int s) +{ + _colspacing = s; +} + + +QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() +{ +} + +void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid) +{ +//use attached properties +if (QObject *obj = attachedProperties.value(qobject_cast(wid))) { + int row = static_cast(obj)->row(); + int column = static_cast(obj)->column(); + int rowSpan = static_cast(obj)->rowSpan(); + int columnSpan = static_cast(obj)->columnSpan(); + if (row == -1 || column == -1) { + qWarning() << "Must set row and column for an item in a grid layout"; + return; + } + addItem(wid, row, column, rowSpan, columnSpan); +} +} + +void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) +{ +//use attached properties +if (GridLayoutAttached *obj = attachedProperties.value(item)) { + int row = obj->row(); + int column = obj->column(); + int rowSpan = obj->rowSpan(); + int columnSpan = obj->columnSpan(); + Qt::Alignment alignment = obj->alignment(); + if (row == -1 || column == -1) { + qWarning() << "Must set row and column for an item in a grid layout"; + return; + } + if(obj->rowSpacing() != -1) + setRowSpacing(row, obj->rowSpacing()); + if(obj->columnSpacing() != -1) + setColumnSpacing(column, obj->columnSpacing()); + if(obj->rowStretchFactor() != -1) + setRowStretchFactor(row, obj->rowStretchFactor()); + if(obj->columnStretchFactor() != -1) + setColumnStretchFactor(column, obj->columnStretchFactor()); + if(obj->rowPreferredHeight() != -1) + setRowPreferredHeight(row, obj->rowPreferredHeight()); + if(obj->rowMaximumHeight() != -1) + setRowMaximumHeight(row, obj->rowMaximumHeight()); + if(obj->rowMinimumHeight() != -1) + setRowMinimumHeight(row, obj->rowMinimumHeight()); + if(obj->rowFixedHeight() != -1) + setRowFixedHeight(row, obj->rowFixedHeight()); + if(obj->columnPreferredWidth() != -1) + setColumnPreferredWidth(row, obj->columnPreferredWidth()); + if(obj->columnMaximumWidth() != -1) + setColumnMaximumWidth(row, obj->columnMaximumWidth()); + if(obj->columnMinimumWidth() != -1) + setColumnMinimumWidth(row, obj->columnMinimumWidth()); + if(obj->columnFixedWidth() != -1) + setColumnFixedWidth(row, obj->columnFixedWidth()); + addItem(item, row, column, rowSpan, columnSpan); + if (alignment != -1) + setAlignment(item,alignment); + QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), + this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); + //### need to disconnect when widget is removed? +} +} + +//### is there a better way to do this? +void QGraphicsGridLayoutObject::clearChildren() +{ +for (int i = 0; i < count(); ++i) + removeAt(i); +} + +qreal QGraphicsGridLayoutObject::spacing() const +{ +if (verticalSpacing() == horizontalSpacing()) + return verticalSpacing(); +return -1; //### +} + +qreal QGraphicsGridLayoutObject::contentsMargin() const +{ + qreal a,b,c,d; + getContentsMargins(&a, &b, &c, &d); + if(a==b && a==c && a==d) + return a; + return -1; +} + +void QGraphicsGridLayoutObject::setContentsMargin(qreal m) +{ + setContentsMargins(m,m,m,m); +} + + +void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ +QGraphicsGridLayout::setAlignment(item, alignment); +} + +QHash QGraphicsGridLayoutObject::attachedProperties; +GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) +{ +// ### This is not allowed - you must attach to any object +if (!qobject_cast(obj)) + return 0; +GridLayoutAttached *rv = new GridLayoutAttached(obj); +attachedProperties.insert(qobject_cast(obj), rv); +return rv; +} + +QT_END_NAMESPACE diff --git a/examples/declarative/layouts/graphicsLayouts/graphicslayouts.pro b/examples/declarative/layouts/graphicsLayouts/graphicslayouts.pro new file mode 100644 index 0000000..e5d91b2 --- /dev/null +++ b/examples/declarative/layouts/graphicsLayouts/graphicslayouts.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +TARGET = graphicslayouts +QT += declarative + +SOURCES += \ + graphicslayouts.cpp \ + main.cpp + +HEADERS += \ + graphicslayouts_p.h + +RESOURCES += \ + graphicslayouts.qrc diff --git a/examples/declarative/layouts/graphicsLayouts/graphicslayouts.qml b/examples/declarative/layouts/graphicsLayouts/graphicslayouts.qml new file mode 100644 index 0000000..fcd78d5 --- /dev/null +++ b/examples/declarative/layouts/graphicsLayouts/graphicslayouts.qml @@ -0,0 +1,77 @@ +import Qt 4.7 +import GraphicsLayouts 4.7 + +Item { + id: resizable + + width: 800 + height: 400 + + QGraphicsWidget { + size.width: parent.width/2 + size.height: parent.height + + layout: QGraphicsLinearLayout { + LayoutItem { + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { color: "yellow"; anchors.fill: parent } + } + LayoutItem { + minimumSize: "100x100" + maximumSize: "400x400" + preferredSize: "200x200" + Rectangle { color: "green"; anchors.fill: parent } + } + } + } + QGraphicsWidget { + x: parent.width/2 + size.width: parent.width/2 + size.height: parent.height + + layout: QGraphicsGridLayout { + LayoutItem { + QGraphicsGridLayout.row: 0 + QGraphicsGridLayout.column: 0 + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { color: "red"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 1 + QGraphicsGridLayout.column: 0 + minimumSize: "100x100" + maximumSize: "200x200" + preferredSize: "100x100" + Rectangle { color: "orange"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 2 + QGraphicsGridLayout.column: 0 + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "200x200" + Rectangle { color: "yellow"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 0 + QGraphicsGridLayout.column: 1 + minimumSize: "100x100" + maximumSize: "200x200" + preferredSize: "200x200" + Rectangle { color: "green"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 1 + QGraphicsGridLayout.column: 1 + minimumSize: "100x100" + maximumSize: "400x400" + preferredSize: "200x200" + Rectangle { color: "blue"; anchors.fill: parent } + } + } + } +} diff --git a/examples/declarative/layouts/graphicsLayouts/graphicslayouts.qrc b/examples/declarative/layouts/graphicsLayouts/graphicslayouts.qrc new file mode 100644 index 0000000..a199f8d --- /dev/null +++ b/examples/declarative/layouts/graphicsLayouts/graphicslayouts.qrc @@ -0,0 +1,5 @@ + + + graphicslayouts.qml + + diff --git a/examples/declarative/layouts/graphicsLayouts/graphicslayouts_p.h b/examples/declarative/layouts/graphicsLayouts/graphicslayouts_p.h new file mode 100644 index 0000000..ea9c614 --- /dev/null +++ b/examples/declarative/layouts/graphicsLayouts/graphicslayouts_p.h @@ -0,0 +1,303 @@ +/**************************************************************************** +** +** 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 GRAPHICSLAYOUTS_H +#define GRAPHICSLAYOUTS_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayoutItem) +public: + QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0); + + virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; +}; + +class LinearLayoutAttached; +class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty children READ children) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsLinearLayoutObject(QObject * = 0); + ~QGraphicsLinearLayoutObject(); + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } + + static LinearLayoutAttached *qmlAttachedProperties(QObject *); + + qreal contentsMargin() const; + void setContentsMargin(qreal); + +private Q_SLOTS: + void updateStretch(QGraphicsLayoutItem*,int); + void updateSpacing(QGraphicsLayoutItem*,int); + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class LinearLayoutAttached; + void clearChildren(); + void insertLayoutItem(int, QGraphicsLayoutItem *); + static QHash attachedProperties; + + static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { + static_cast(prop->object)->insertLayoutItem(-1, item); + } + + static void children_clear(QDeclarativeListProperty *prop) { + static_cast(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty *prop) { + return static_cast(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { + return static_cast(prop->object)->itemAt(index); + } +}; + +class GridLayoutAttached; +class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty children READ children) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) + Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) + Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsGridLayoutObject(QObject * = 0); + ~QGraphicsGridLayoutObject(); + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } + + qreal spacing() const; + qreal contentsMargin() const; + void setContentsMargin(qreal); + + static GridLayoutAttached *qmlAttachedProperties(QObject *); + +private Q_SLOTS: + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class GraphicsLayoutAttached; + void addWidget(QGraphicsWidget *); + void clearChildren(); + void addLayoutItem(QGraphicsLayoutItem *); + static QHash attachedProperties; + + static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { + static_cast(prop->object)->addLayoutItem(item); + } + + static void children_clear(QDeclarativeListProperty *prop) { + static_cast(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty *prop) { + return static_cast(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { + return static_cast(prop->object)->itemAt(index); + } +}; + +class LinearLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) + Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) +public: + LinearLayoutAttached(QObject *parent); + + int stretchFactor() const { return _stretch; } + void setStretchFactor(int f); + Qt::Alignment alignment() const { return _alignment; } + void setAlignment(Qt::Alignment a); + int spacing() const { return _spacing; } + void setSpacing(int s); + +Q_SIGNALS: + void stretchChanged(QGraphicsLayoutItem*,int); + void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); + void spacingChanged(QGraphicsLayoutItem*,int); + +private: + int _stretch; + Qt::Alignment _alignment; + int _spacing; +}; + +class GridLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int row READ row WRITE setRow) + Q_PROPERTY(int column READ column WRITE setColumn) + Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan) + Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) + Q_PROPERTY(int rowStretchFactor READ rowStretchFactor WRITE setRowStretchFactor) + Q_PROPERTY(int columnStretchFactor READ columnStretchFactor WRITE setColumnStretchFactor) + Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) + Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) + Q_PROPERTY(int rowPreferredHeight READ rowPreferredHeight WRITE setRowPreferredHeight) + Q_PROPERTY(int rowMinimumHeight READ rowMinimumHeight WRITE setRowMinimumHeight) + Q_PROPERTY(int rowMaximumHeight READ rowMaximumHeight WRITE setRowMaximumHeight) + Q_PROPERTY(int rowFixedHeight READ rowFixedHeight WRITE setRowFixedHeight) + Q_PROPERTY(int columnPreferredWidth READ columnPreferredWidth WRITE setColumnPreferredWidth) + Q_PROPERTY(int columnMaximumWidth READ columnMaximumWidth WRITE setColumnMaximumWidth) + Q_PROPERTY(int columnMinimumWidth READ columnMinimumWidth WRITE setColumnMinimumWidth) + Q_PROPERTY(int columnFixedWidth READ columnFixedWidth WRITE setColumnFixedWidth) + +public: + GridLayoutAttached(QObject *parent); + + int row() const { return _row; } + void setRow(int r); + + int column() const { return _column; } + void setColumn(int c); + + int rowSpan() const { return _rowspan; } + void setRowSpan(int rs); + + int columnSpan() const { return _colspan; } + void setColumnSpan(int cs); + + Qt::Alignment alignment() const { return _alignment; } + void setAlignment(Qt::Alignment a); + + int rowStretchFactor() const { return _rowstretch; } + void setRowStretchFactor(int f); + int columnStretchFactor() const { return _colstretch; } + void setColumnStretchFactor(int f); + + int rowSpacing() const { return _rowspacing; } + void setRowSpacing(int s); + int columnSpacing() const { return _colspacing; } + void setColumnSpacing(int s); + + int rowPreferredHeight() const { return _rowprefheight; } + void setRowPreferredHeight(int s) { _rowprefheight = s; } + + int rowMaximumHeight() const { return _rowmaxheight; } + void setRowMaximumHeight(int s) { _rowmaxheight = s; } + + int rowMinimumHeight() const { return _rowminheight; } + void setRowMinimumHeight(int s) { _rowminheight = s; } + + int rowFixedHeight() const { return _rowfixheight; } + void setRowFixedHeight(int s) { _rowfixheight = s; } + + int columnPreferredWidth() const { return _colprefwidth; } + void setColumnPreferredWidth(int s) { _colprefwidth = s; } + + int columnMaximumWidth() const { return _colmaxwidth; } + void setColumnMaximumWidth(int s) { _colmaxwidth = s; } + + int columnMinimumWidth() const { return _colminwidth; } + void setColumnMinimumWidth(int s) { _colminwidth = s; } + + int columnFixedWidth() const { return _colfixwidth; } + void setColumnFixedWidth(int s) { _colfixwidth = s; } + +Q_SIGNALS: + void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); + +private: + int _row; + int _column; + int _rowspan; + int _colspan; + Qt::Alignment _alignment; + int _rowstretch; + int _colstretch; + int _rowspacing; + int _colspacing; + int _rowprefheight; + int _rowmaxheight; + int _rowminheight; + int _rowfixheight; + int _colprefwidth; + int _colmaxwidth; + int _colminwidth; + int _colfixwidth; +}; + +QT_END_NAMESPACE + +QML_DECLARE_INTERFACE(QGraphicsLayoutItem) +QML_DECLARE_INTERFACE(QGraphicsLayout) +QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject) +QML_DECLARE_TYPE(QGraphicsLinearLayoutObject) +QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QGraphicsGridLayoutObject) +QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER + +#endif // GRAPHICSLAYOUTS_H diff --git a/examples/declarative/layouts/graphicsLayouts/main.cpp b/examples/declarative/layouts/graphicsLayouts/main.cpp new file mode 100644 index 0000000..89b69bf --- /dev/null +++ b/examples/declarative/layouts/graphicsLayouts/main.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins 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 "graphicslayouts_p.h" +#include + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + QDeclarativeView view; + qmlRegisterInterface("QGraphicsLayoutItem"); + qmlRegisterInterface("QGraphicsLayout"); + qmlRegisterType("GraphicsLayouts",4,7,"QGraphicsLinearLayoutStretchItem"); + qmlRegisterType("GraphicsLayouts",4,7,"QGraphicsLinearLayout"); + qmlRegisterType("GraphicsLayouts",4,7,"QGraphicsGridLayout"); + view.setSource(QUrl(":graphicslayouts.qml")); + view.show(); + return app.exec(); +}; + diff --git a/examples/declarative/layouts/layoutItem/layoutItem.pro b/examples/declarative/layouts/layoutItem/layoutItem.pro new file mode 100644 index 0000000..4a3fc73 --- /dev/null +++ b/examples/declarative/layouts/layoutItem/layoutItem.pro @@ -0,0 +1,13 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Tue May 4 13:36:26 2010 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp +RESOURCES += layoutItem.qrc diff --git a/examples/declarative/layouts/layoutItem/layoutItem.qml b/examples/declarative/layouts/layoutItem/layoutItem.qml new file mode 100644 index 0000000..9b9db22 --- /dev/null +++ b/examples/declarative/layouts/layoutItem/layoutItem.qml @@ -0,0 +1,16 @@ +import Qt 4.7 +import Qt.widgets 4.7 + +LayoutItem {//Sized by the layout + id: resizable + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { color: "yellow"; anchors.fill: parent } + Rectangle { + width: 100; height: 100; + anchors.top: parent.top; + anchors.right: parent.right; + color: "green"; + } +} diff --git a/examples/declarative/layouts/layoutItem/layoutItem.qrc b/examples/declarative/layouts/layoutItem/layoutItem.qrc new file mode 100644 index 0000000..deb0fba --- /dev/null +++ b/examples/declarative/layouts/layoutItem/layoutItem.qrc @@ -0,0 +1,5 @@ + + + layoutItem.qml + + diff --git a/examples/declarative/layouts/layoutItem/main.cpp b/examples/declarative/layouts/layoutItem/main.cpp new file mode 100644 index 0000000..a104251 --- /dev/null +++ b/examples/declarative/layouts/layoutItem/main.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +/* This example demonstrates using a LayoutItem to let QML snippets integrate + nicely with existing QGraphicsView applications designed with GraphicsLayouts +*/ +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + //Set up a graphics scene with a QGraphicsWidget and Layout + QGraphicsView view; + QGraphicsScene scene; + QGraphicsWidget *widget = new QGraphicsWidget(); + QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(); + widget->setLayout(layout); + scene.addItem(widget); + view.setScene(&scene); + //Add the QML snippet into the layout + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl(":layoutItem.qml")); + QGraphicsLayoutItem* obj = qobject_cast(c.create()); + layout->addItem(obj); + + widget->setGeometry(QRectF(0,0, 400,400)); + view.show(); + return app.exec(); +} diff --git a/examples/declarative/layouts/layouts.qml b/examples/declarative/layouts/layouts.qml deleted file mode 100644 index 391eab7..0000000 --- a/examples/declarative/layouts/layouts.qml +++ /dev/null @@ -1,29 +0,0 @@ -import Qt 4.7 -import Qt.widgets 4.7 - -Item { - id: resizable - - width: 400 - height: 400 - - QGraphicsWidget { - size.width: parent.width - size.height: parent.height - - layout: QGraphicsLinearLayout { - LayoutItem { - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "100x100" - Rectangle { color: "yellow"; anchors.fill: parent } - } - LayoutItem { - minimumSize: "100x100" - maximumSize: "400x400" - preferredSize: "200x200" - Rectangle { color: "green"; anchors.fill: parent } - } - } - } -} diff --git a/examples/declarative/layouts/layouts.qmlproject b/examples/declarative/layouts/layouts.qmlproject deleted file mode 100644 index d4909f8..0000000 --- a/examples/declarative/layouts/layouts.qmlproject +++ /dev/null @@ -1,16 +0,0 @@ -import QmlProject 1.0 - -Project { - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } - /* List of plugin directories passed to QML runtime */ - // importPaths: [ " ../exampleplugin " ] -} diff --git a/examples/declarative/layouts/positioners.qml b/examples/declarative/layouts/positioners.qml deleted file mode 100644 index 3703b59..0000000 --- a/examples/declarative/layouts/positioners.qml +++ /dev/null @@ -1,213 +0,0 @@ -import Qt 4.7 - -Rectangle { - id: page - width: 420; height: 420 - - Column { - id: layout1 - y: 0 - move: Transition { - NumberAnimation { properties: "y"; easing.type: "OutBounce" } - } - add: Transition { - NumberAnimation { properties: "y"; easing.type: "OutQuad" } - } - - Rectangle { color: "red"; width: 100; height: 50; border.color: "black"; radius: 15 } - - Rectangle { - id: blueV1 - width: 100; height: 50 - color: "lightsteelblue" - border.color: "black" - radius: 15 - Behavior on opacity { NumberAnimation {} } - } - - Rectangle { color: "green"; width: 100; height: 50; border.color: "black"; radius: 15 } - - Rectangle { - id: blueV2 - width: 100; height: 50 - color: "lightsteelblue" - border.color: "black" - radius: 15 - Behavior on opacity { NumberAnimation {} } - } - - Rectangle { color: "orange"; width: 100; height: 50; border.color: "black"; radius: 15 } - } - - Row { - id: layout2 - y: 300 - move: Transition { - NumberAnimation { properties: "x"; easing.type: "OutBounce" } - } - add: Transition { - NumberAnimation { properties: "x"; easing.type: "OutQuad" } - } - - Rectangle { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 } - - Rectangle { - id: blueH1 - width: 50; height: 100 - color: "lightsteelblue" - border.color: "black" - radius: 15 - Behavior on opacity { NumberAnimation {} } - } - - Rectangle { color: "green"; width: 50; height: 100; border.color: "black"; radius: 15 } - - Rectangle { - id: blueH2 - width: 50; height: 100 - color: "lightsteelblue" - border.color: "black" - radius: 15 - Behavior on opacity { NumberAnimation {} } - } - - Rectangle { color: "orange"; width: 50; height: 100; border.color: "black"; radius: 15 } - } - - Button { - x: 135; y: 90 - text: "Remove" - icon: "del.png" - - onClicked: { - blueH2.opacity = 0 - blueH1.opacity = 0 - blueV1.opacity = 0 - blueV2.opacity = 0 - blueG1.opacity = 0 - blueG2.opacity = 0 - blueG3.opacity = 0 - blueF1.opacity = 0 - blueF2.opacity = 0 - blueF3.opacity = 0 - } - } - - Button { - x: 145; y: 140 - text: "Add" - icon: "add.png" - - onClicked: { - blueH2.opacity = 1 - blueH1.opacity = 1 - blueV1.opacity = 1 - blueV2.opacity = 1 - blueG1.opacity = 1 - blueG2.opacity = 1 - blueG3.opacity = 1 - blueF1.opacity = 1 - blueF2.opacity = 1 - blueF3.opacity = 1 - } - } - - Grid { - x: 260; y: 0 - columns: 3 - - move: Transition { - NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } - } - - add: Transition { - NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } - } - - Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } - - Rectangle { - id: blueG1 - width: 50; height: 50 - color: "lightsteelblue" - border.color: "black" - radius: 15 - Behavior on opacity { NumberAnimation {} } - } - - Rectangle { color: "green"; width: 50; height: 50; border.color: "black"; radius: 15 } - - Rectangle { - id: blueG2 - width: 50; height: 50 - color: "lightsteelblue" - border.color: "black" - radius: 15 - Behavior on opacity { NumberAnimation {} } - } - - Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 } - - Rectangle { - id: blueG3 - width: 50; height: 50 - color: "lightsteelblue" - border.color: "black" - radius: 15 - Behavior on opacity { NumberAnimation {} } - } - - Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } - Rectangle { color: "green"; width: 50; height: 50; border.color: "black"; radius: 15 } - Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 } - } - - Flow { - id: layout4 - x: 260; y: 250; width: 150 - - move: Transition { - NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } - } - - add: Transition { - NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } - } - - Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } - - Rectangle { - id: blueF1 - width: 60; height: 50 - color: "lightsteelblue" - border.color: "black" - radius: 15 - Behavior on opacity { NumberAnimation {} } - } - - Rectangle { color: "green"; width: 30; height: 50; border.color: "black"; radius: 15 } - - Rectangle { - id: blueF2 - width: 60; height: 50 - color: "lightsteelblue" - border.color: "black" - radius: 15 - Behavior on opacity { NumberAnimation {} } - } - - Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 } - - Rectangle { - id: blueF3 - width: 40; height: 50 - color: "lightsteelblue" - border.color: "black" - radius: 15 - Behavior on opacity { NumberAnimation {} } - } - - Rectangle { color: "red"; width: 80; height: 50; border.color: "black"; radius: 15 } - } - -} diff --git a/examples/declarative/layouts/positioners/Button.qml b/examples/declarative/layouts/positioners/Button.qml new file mode 100644 index 0000000..0f08893 --- /dev/null +++ b/examples/declarative/layouts/positioners/Button.qml @@ -0,0 +1,22 @@ +import Qt 4.7 + +Rectangle { border.color: "black"; color: "steelblue"; radius: 5; width: pix.width + textelement.width + 13; height: pix.height + 10; id: page + property string text + property string icon + signal clicked + + Image { id: pix; x: 5; y:5; source: parent.icon} + Text { id: textelement; text: page.text; color: "white"; x:pix.width+pix.x+3; anchors.verticalCenter: pix.verticalCenter;} + MouseArea{ id:mr; anchors.fill: parent; onClicked: {parent.focus = true; page.clicked()}} + + states: + State{ name:"pressed"; when:mr.pressed + PropertyChanges {target:textelement; x: 5} + PropertyChanges {target:pix; x:textelement.x+textelement.width + 3} + } + + transitions: + Transition{ + NumberAnimation { properties:"x,left"; easing.type:"InOutQuad"; duration:200 } + } +} diff --git a/examples/declarative/layouts/positioners/add.png b/examples/declarative/layouts/positioners/add.png new file mode 100644 index 0000000..f29d84b Binary files /dev/null and b/examples/declarative/layouts/positioners/add.png differ diff --git a/examples/declarative/layouts/positioners/del.png b/examples/declarative/layouts/positioners/del.png new file mode 100644 index 0000000..1d753a3 Binary files /dev/null and b/examples/declarative/layouts/positioners/del.png differ diff --git a/examples/declarative/layouts/positioners/positioners.qml b/examples/declarative/layouts/positioners/positioners.qml new file mode 100644 index 0000000..3703b59 --- /dev/null +++ b/examples/declarative/layouts/positioners/positioners.qml @@ -0,0 +1,213 @@ +import Qt 4.7 + +Rectangle { + id: page + width: 420; height: 420 + + Column { + id: layout1 + y: 0 + move: Transition { + NumberAnimation { properties: "y"; easing.type: "OutBounce" } + } + add: Transition { + NumberAnimation { properties: "y"; easing.type: "OutQuad" } + } + + Rectangle { color: "red"; width: 100; height: 50; border.color: "black"; radius: 15 } + + Rectangle { + id: blueV1 + width: 100; height: 50 + color: "lightsteelblue" + border.color: "black" + radius: 15 + Behavior on opacity { NumberAnimation {} } + } + + Rectangle { color: "green"; width: 100; height: 50; border.color: "black"; radius: 15 } + + Rectangle { + id: blueV2 + width: 100; height: 50 + color: "lightsteelblue" + border.color: "black" + radius: 15 + Behavior on opacity { NumberAnimation {} } + } + + Rectangle { color: "orange"; width: 100; height: 50; border.color: "black"; radius: 15 } + } + + Row { + id: layout2 + y: 300 + move: Transition { + NumberAnimation { properties: "x"; easing.type: "OutBounce" } + } + add: Transition { + NumberAnimation { properties: "x"; easing.type: "OutQuad" } + } + + Rectangle { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 } + + Rectangle { + id: blueH1 + width: 50; height: 100 + color: "lightsteelblue" + border.color: "black" + radius: 15 + Behavior on opacity { NumberAnimation {} } + } + + Rectangle { color: "green"; width: 50; height: 100; border.color: "black"; radius: 15 } + + Rectangle { + id: blueH2 + width: 50; height: 100 + color: "lightsteelblue" + border.color: "black" + radius: 15 + Behavior on opacity { NumberAnimation {} } + } + + Rectangle { color: "orange"; width: 50; height: 100; border.color: "black"; radius: 15 } + } + + Button { + x: 135; y: 90 + text: "Remove" + icon: "del.png" + + onClicked: { + blueH2.opacity = 0 + blueH1.opacity = 0 + blueV1.opacity = 0 + blueV2.opacity = 0 + blueG1.opacity = 0 + blueG2.opacity = 0 + blueG3.opacity = 0 + blueF1.opacity = 0 + blueF2.opacity = 0 + blueF3.opacity = 0 + } + } + + Button { + x: 145; y: 140 + text: "Add" + icon: "add.png" + + onClicked: { + blueH2.opacity = 1 + blueH1.opacity = 1 + blueV1.opacity = 1 + blueV2.opacity = 1 + blueG1.opacity = 1 + blueG2.opacity = 1 + blueG3.opacity = 1 + blueF1.opacity = 1 + blueF2.opacity = 1 + blueF3.opacity = 1 + } + } + + Grid { + x: 260; y: 0 + columns: 3 + + move: Transition { + NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } + } + + add: Transition { + NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } + } + + Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } + + Rectangle { + id: blueG1 + width: 50; height: 50 + color: "lightsteelblue" + border.color: "black" + radius: 15 + Behavior on opacity { NumberAnimation {} } + } + + Rectangle { color: "green"; width: 50; height: 50; border.color: "black"; radius: 15 } + + Rectangle { + id: blueG2 + width: 50; height: 50 + color: "lightsteelblue" + border.color: "black" + radius: 15 + Behavior on opacity { NumberAnimation {} } + } + + Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 } + + Rectangle { + id: blueG3 + width: 50; height: 50 + color: "lightsteelblue" + border.color: "black" + radius: 15 + Behavior on opacity { NumberAnimation {} } + } + + Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } + Rectangle { color: "green"; width: 50; height: 50; border.color: "black"; radius: 15 } + Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 } + } + + Flow { + id: layout4 + x: 260; y: 250; width: 150 + + move: Transition { + NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } + } + + add: Transition { + NumberAnimation { properties: "x,y"; easing.type: "OutBounce" } + } + + Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } + + Rectangle { + id: blueF1 + width: 60; height: 50 + color: "lightsteelblue" + border.color: "black" + radius: 15 + Behavior on opacity { NumberAnimation {} } + } + + Rectangle { color: "green"; width: 30; height: 50; border.color: "black"; radius: 15 } + + Rectangle { + id: blueF2 + width: 60; height: 50 + color: "lightsteelblue" + border.color: "black" + radius: 15 + Behavior on opacity { NumberAnimation {} } + } + + Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 } + + Rectangle { + id: blueF3 + width: 40; height: 50 + color: "lightsteelblue" + border.color: "black" + radius: 15 + Behavior on opacity { NumberAnimation {} } + } + + Rectangle { color: "red"; width: 80; height: 50; border.color: "black"; radius: 15 } + } + +} diff --git a/examples/declarative/layouts/positioners/positioners.qmlproject b/examples/declarative/layouts/positioners/positioners.qmlproject new file mode 100644 index 0000000..e526217 --- /dev/null +++ b/examples/declarative/layouts/positioners/positioners.qmlproject @@ -0,0 +1,18 @@ +/* File generated by QtCreator */ + +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ " ../exampleplugin " ] +} diff --git a/examples/declarative/layouts/positioners/positioners.qmlproject.user b/examples/declarative/layouts/positioners/positioners.qmlproject.user new file mode 100644 index 0000000..593479d --- /dev/null +++ b/examples/declarative/layouts/positioners/positioners.qmlproject.user @@ -0,0 +1,41 @@ + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + UTF-8 + + + + ProjectExplorer.Project.Target.0 + + QML Runtime + QmlProjectManager.QmlTarget + -1 + 0 + 0 + + QML Runtime + QmlProjectManager.QmlRunConfiguration + 127.0.0.1 + 3768 + positioners.qml + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 4 + + diff --git a/src/imports/imports.pro b/src/imports/imports.pro index ecde0cc..1754908 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -SUBDIRS += widgets particles +SUBDIRS += particles contains(QT_CONFIG, webkit): SUBDIRS += webkit contains(QT_CONFIG, mediaservices): SUBDIRS += multimedia diff --git a/src/imports/widgets/graphicslayouts.cpp b/src/imports/widgets/graphicslayouts.cpp deleted file mode 100644 index 25cf994..0000000 --- a/src/imports/widgets/graphicslayouts.cpp +++ /dev/null @@ -1,366 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "graphicslayouts_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -LinearLayoutAttached::LinearLayoutAttached(QObject *parent) -: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter), _spacing(0) -{ -} - -void LinearLayoutAttached::setStretchFactor(int f) -{ - if (_stretch == f) - return; - - _stretch = f; - emit stretchChanged(reinterpret_cast(parent()), _stretch); -} - -void LinearLayoutAttached::setSpacing(int s) -{ - if (_spacing == s) - return; - - _spacing = s; - emit spacingChanged(reinterpret_cast(parent()), _spacing); -} - -void LinearLayoutAttached::setAlignment(Qt::Alignment a) -{ - if (_alignment == a) - return; - - _alignment = a; - emit alignmentChanged(reinterpret_cast(parent()), _alignment); -} - -QGraphicsLinearLayoutStretchItemObject::QGraphicsLinearLayoutStretchItemObject(QObject *parent) - : QObject(parent) -{ -} - -QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const -{ -Q_UNUSED(which); -Q_UNUSED(constraint); -return QSizeF(); -} - - -QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent) -: QObject(parent) -{ -} - -QGraphicsLinearLayoutObject::~QGraphicsLinearLayoutObject() -{ -} - -void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item) -{ -insertItem(index, item); - -//connect attached properties -if (LinearLayoutAttached *obj = attachedProperties.value(item)) { - setStretchFactor(item, obj->stretchFactor()); - setAlignment(item, obj->alignment()); - updateSpacing(item, obj->spacing()); - QObject::connect(obj, SIGNAL(stretchChanged(QGraphicsLayoutItem*,int)), - this, SLOT(updateStretch(QGraphicsLayoutItem*,int))); - QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), - this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); - QObject::connect(obj, SIGNAL(spacingChanged(QGraphicsLayoutItem*,int)), - this, SLOT(updateSpacing(QGraphicsLayoutItem*,int))); - //### need to disconnect when widget is removed? -} -} - -//### is there a better way to do this? -void QGraphicsLinearLayoutObject::clearChildren() -{ -for (int i = 0; i < count(); ++i) - removeAt(i); -} - -qreal QGraphicsLinearLayoutObject::contentsMargin() const -{ - qreal a,b,c,d; - getContentsMargins(&a, &b, &c, &d); - if(a==b && a==c && a==d) - return a; - return -1; -} - -void QGraphicsLinearLayoutObject::setContentsMargin(qreal m) -{ - setContentsMargins(m,m,m,m); -} - -void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) -{ -QGraphicsLinearLayout::setStretchFactor(item, stretch); -} - -void QGraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing) -{ - for(int i=0; i < count(); i++){ - if(itemAt(i) == item){ //I do not see the reverse function, which is why we must loop over all items - QGraphicsLinearLayout::setItemSpacing(i, spacing); - return; - } - } -} - -void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) -{ -QGraphicsLinearLayout::setAlignment(item, alignment); -} - -QHash QGraphicsLinearLayoutObject::attachedProperties; -LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) -{ -// ### This is not allowed - you must attach to any object -if (!qobject_cast(obj)) - return 0; -LinearLayoutAttached *rv = new LinearLayoutAttached(obj); -attachedProperties.insert(qobject_cast(obj), rv); -return rv; -} - -////////////////////////////////////////////////////////////////////////////////////////////////////// -// QGraphicsGridLayout-related classes -////////////////////////////////////////////////////////////////////////////////////////////////////// -GridLayoutAttached::GridLayoutAttached(QObject *parent) -: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1), _rowstretch(-1), - _colstretch(-1), _rowspacing(-1), _colspacing(-1), _rowprefheight(-1), _rowmaxheight(-1), _rowminheight(-1), - _rowfixheight(-1), _colprefwidth(-1), _colmaxwidth(-1), _colminwidth(-1), _colfixwidth(-1) -{ -} - -void GridLayoutAttached::setRow(int r) -{ - if (_row == r) - return; - - _row = r; - //emit rowChanged(reinterpret_cast(parent()), _row); -} - -void GridLayoutAttached::setColumn(int c) -{ - if (_column == c) - return; - - _column = c; - //emit columnChanged(reinterpret_cast(parent()), _column); -} - -void GridLayoutAttached::setRowSpan(int rs) -{ - if (_rowspan == rs) - return; - - _rowspan = rs; - //emit rowSpanChanged(reinterpret_cast(parent()), _rowSpan); -} - -void GridLayoutAttached::setColumnSpan(int cs) -{ - if (_colspan == cs) - return; - - _colspan = cs; - //emit columnSpanChanged(reinterpret_cast(parent()), _columnSpan); -} - -void GridLayoutAttached::setAlignment(Qt::Alignment a) -{ - if (_alignment == a) - return; - - _alignment = a; - emit alignmentChanged(reinterpret_cast(parent()), _alignment); -} - -void GridLayoutAttached::setRowStretchFactor(int f) -{ - _rowstretch = f; -} - -void GridLayoutAttached::setColumnStretchFactor(int f) -{ - _colstretch = f; -} - -void GridLayoutAttached::setRowSpacing(int s) -{ - _rowspacing = s; -} - -void GridLayoutAttached::setColumnSpacing(int s) -{ - _colspacing = s; -} - - -QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) -: QObject(parent) -{ -} - -QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() -{ -} - -void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid) -{ -//use attached properties -if (QObject *obj = attachedProperties.value(qobject_cast(wid))) { - int row = static_cast(obj)->row(); - int column = static_cast(obj)->column(); - int rowSpan = static_cast(obj)->rowSpan(); - int columnSpan = static_cast(obj)->columnSpan(); - if (row == -1 || column == -1) { - qWarning() << "Must set row and column for an item in a grid layout"; - return; - } - addItem(wid, row, column, rowSpan, columnSpan); -} -} - -void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) -{ -//use attached properties -if (GridLayoutAttached *obj = attachedProperties.value(item)) { - int row = obj->row(); - int column = obj->column(); - int rowSpan = obj->rowSpan(); - int columnSpan = obj->columnSpan(); - Qt::Alignment alignment = obj->alignment(); - if (row == -1 || column == -1) { - qWarning() << "Must set row and column for an item in a grid layout"; - return; - } - if(obj->rowSpacing() != -1) - setRowSpacing(row, obj->rowSpacing()); - if(obj->columnSpacing() != -1) - setColumnSpacing(column, obj->columnSpacing()); - if(obj->rowStretchFactor() != -1) - setRowStretchFactor(row, obj->rowStretchFactor()); - if(obj->columnStretchFactor() != -1) - setColumnStretchFactor(column, obj->columnStretchFactor()); - if(obj->rowPreferredHeight() != -1) - setRowPreferredHeight(row, obj->rowPreferredHeight()); - if(obj->rowMaximumHeight() != -1) - setRowMaximumHeight(row, obj->rowMaximumHeight()); - if(obj->rowMinimumHeight() != -1) - setRowMinimumHeight(row, obj->rowMinimumHeight()); - if(obj->rowFixedHeight() != -1) - setRowFixedHeight(row, obj->rowFixedHeight()); - if(obj->columnPreferredWidth() != -1) - setColumnPreferredWidth(row, obj->columnPreferredWidth()); - if(obj->columnMaximumWidth() != -1) - setColumnMaximumWidth(row, obj->columnMaximumWidth()); - if(obj->columnMinimumWidth() != -1) - setColumnMinimumWidth(row, obj->columnMinimumWidth()); - if(obj->columnFixedWidth() != -1) - setColumnFixedWidth(row, obj->columnFixedWidth()); - addItem(item, row, column, rowSpan, columnSpan); - if (alignment != -1) - setAlignment(item,alignment); - QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), - this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); - //### need to disconnect when widget is removed? -} -} - -//### is there a better way to do this? -void QGraphicsGridLayoutObject::clearChildren() -{ -for (int i = 0; i < count(); ++i) - removeAt(i); -} - -qreal QGraphicsGridLayoutObject::spacing() const -{ -if (verticalSpacing() == horizontalSpacing()) - return verticalSpacing(); -return -1; //### -} - -qreal QGraphicsGridLayoutObject::contentsMargin() const -{ - qreal a,b,c,d; - getContentsMargins(&a, &b, &c, &d); - if(a==b && a==c && a==d) - return a; - return -1; -} - -void QGraphicsGridLayoutObject::setContentsMargin(qreal m) -{ - setContentsMargins(m,m,m,m); -} - - -void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) -{ -QGraphicsGridLayout::setAlignment(item, alignment); -} - -QHash QGraphicsGridLayoutObject::attachedProperties; -GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) -{ -// ### This is not allowed - you must attach to any object -if (!qobject_cast(obj)) - return 0; -GridLayoutAttached *rv = new GridLayoutAttached(obj); -attachedProperties.insert(qobject_cast(obj), rv); -return rv; -} - -QT_END_NAMESPACE diff --git a/src/imports/widgets/graphicslayouts_p.h b/src/imports/widgets/graphicslayouts_p.h deleted file mode 100644 index ea9c614..0000000 --- a/src/imports/widgets/graphicslayouts_p.h +++ /dev/null @@ -1,303 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef GRAPHICSLAYOUTS_H -#define GRAPHICSLAYOUTS_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayoutItem) -public: - QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0); - - virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; -}; - -class LinearLayoutAttached; -class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - - Q_PROPERTY(QDeclarativeListProperty children READ children) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsLinearLayoutObject(QObject * = 0); - ~QGraphicsLinearLayoutObject(); - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } - - static LinearLayoutAttached *qmlAttachedProperties(QObject *); - - qreal contentsMargin() const; - void setContentsMargin(qreal); - -private Q_SLOTS: - void updateStretch(QGraphicsLayoutItem*,int); - void updateSpacing(QGraphicsLayoutItem*,int); - void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); - -private: - friend class LinearLayoutAttached; - void clearChildren(); - void insertLayoutItem(int, QGraphicsLayoutItem *); - static QHash attachedProperties; - - static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { - static_cast(prop->object)->insertLayoutItem(-1, item); - } - - static void children_clear(QDeclarativeListProperty *prop) { - static_cast(prop->object)->clearChildren(); - } - - static int children_count(QDeclarativeListProperty *prop) { - return static_cast(prop->object)->count(); - } - - static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { - return static_cast(prop->object)->itemAt(index); - } -}; - -class GridLayoutAttached; -class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - - Q_PROPERTY(QDeclarativeListProperty children READ children) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) - Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) - Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsGridLayoutObject(QObject * = 0); - ~QGraphicsGridLayoutObject(); - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } - - qreal spacing() const; - qreal contentsMargin() const; - void setContentsMargin(qreal); - - static GridLayoutAttached *qmlAttachedProperties(QObject *); - -private Q_SLOTS: - void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); - -private: - friend class GraphicsLayoutAttached; - void addWidget(QGraphicsWidget *); - void clearChildren(); - void addLayoutItem(QGraphicsLayoutItem *); - static QHash attachedProperties; - - static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { - static_cast(prop->object)->addLayoutItem(item); - } - - static void children_clear(QDeclarativeListProperty *prop) { - static_cast(prop->object)->clearChildren(); - } - - static int children_count(QDeclarativeListProperty *prop) { - return static_cast(prop->object)->count(); - } - - static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { - return static_cast(prop->object)->itemAt(index); - } -}; - -class LinearLayoutAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged) - Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) - Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) -public: - LinearLayoutAttached(QObject *parent); - - int stretchFactor() const { return _stretch; } - void setStretchFactor(int f); - Qt::Alignment alignment() const { return _alignment; } - void setAlignment(Qt::Alignment a); - int spacing() const { return _spacing; } - void setSpacing(int s); - -Q_SIGNALS: - void stretchChanged(QGraphicsLayoutItem*,int); - void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); - void spacingChanged(QGraphicsLayoutItem*,int); - -private: - int _stretch; - Qt::Alignment _alignment; - int _spacing; -}; - -class GridLayoutAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int row READ row WRITE setRow) - Q_PROPERTY(int column READ column WRITE setColumn) - Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan) - Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan) - Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) - Q_PROPERTY(int rowStretchFactor READ rowStretchFactor WRITE setRowStretchFactor) - Q_PROPERTY(int columnStretchFactor READ columnStretchFactor WRITE setColumnStretchFactor) - Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) - Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) - Q_PROPERTY(int rowPreferredHeight READ rowPreferredHeight WRITE setRowPreferredHeight) - Q_PROPERTY(int rowMinimumHeight READ rowMinimumHeight WRITE setRowMinimumHeight) - Q_PROPERTY(int rowMaximumHeight READ rowMaximumHeight WRITE setRowMaximumHeight) - Q_PROPERTY(int rowFixedHeight READ rowFixedHeight WRITE setRowFixedHeight) - Q_PROPERTY(int columnPreferredWidth READ columnPreferredWidth WRITE setColumnPreferredWidth) - Q_PROPERTY(int columnMaximumWidth READ columnMaximumWidth WRITE setColumnMaximumWidth) - Q_PROPERTY(int columnMinimumWidth READ columnMinimumWidth WRITE setColumnMinimumWidth) - Q_PROPERTY(int columnFixedWidth READ columnFixedWidth WRITE setColumnFixedWidth) - -public: - GridLayoutAttached(QObject *parent); - - int row() const { return _row; } - void setRow(int r); - - int column() const { return _column; } - void setColumn(int c); - - int rowSpan() const { return _rowspan; } - void setRowSpan(int rs); - - int columnSpan() const { return _colspan; } - void setColumnSpan(int cs); - - Qt::Alignment alignment() const { return _alignment; } - void setAlignment(Qt::Alignment a); - - int rowStretchFactor() const { return _rowstretch; } - void setRowStretchFactor(int f); - int columnStretchFactor() const { return _colstretch; } - void setColumnStretchFactor(int f); - - int rowSpacing() const { return _rowspacing; } - void setRowSpacing(int s); - int columnSpacing() const { return _colspacing; } - void setColumnSpacing(int s); - - int rowPreferredHeight() const { return _rowprefheight; } - void setRowPreferredHeight(int s) { _rowprefheight = s; } - - int rowMaximumHeight() const { return _rowmaxheight; } - void setRowMaximumHeight(int s) { _rowmaxheight = s; } - - int rowMinimumHeight() const { return _rowminheight; } - void setRowMinimumHeight(int s) { _rowminheight = s; } - - int rowFixedHeight() const { return _rowfixheight; } - void setRowFixedHeight(int s) { _rowfixheight = s; } - - int columnPreferredWidth() const { return _colprefwidth; } - void setColumnPreferredWidth(int s) { _colprefwidth = s; } - - int columnMaximumWidth() const { return _colmaxwidth; } - void setColumnMaximumWidth(int s) { _colmaxwidth = s; } - - int columnMinimumWidth() const { return _colminwidth; } - void setColumnMinimumWidth(int s) { _colminwidth = s; } - - int columnFixedWidth() const { return _colfixwidth; } - void setColumnFixedWidth(int s) { _colfixwidth = s; } - -Q_SIGNALS: - void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); - -private: - int _row; - int _column; - int _rowspan; - int _colspan; - Qt::Alignment _alignment; - int _rowstretch; - int _colstretch; - int _rowspacing; - int _colspacing; - int _rowprefheight; - int _rowmaxheight; - int _rowminheight; - int _rowfixheight; - int _colprefwidth; - int _colmaxwidth; - int _colminwidth; - int _colfixwidth; -}; - -QT_END_NAMESPACE - -QML_DECLARE_INTERFACE(QGraphicsLayoutItem) -QML_DECLARE_INTERFACE(QGraphicsLayout) -QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject) -QML_DECLARE_TYPE(QGraphicsLinearLayoutObject) -QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QGraphicsGridLayoutObject) -QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif // GRAPHICSLAYOUTS_H diff --git a/src/imports/widgets/qmldir b/src/imports/widgets/qmldir deleted file mode 100644 index 6f19878..0000000 --- a/src/imports/widgets/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin widgets diff --git a/src/imports/widgets/widgets.cpp b/src/imports/widgets/widgets.cpp deleted file mode 100644 index 20de1fe..0000000 --- a/src/imports/widgets/widgets.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins 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 "graphicslayouts_p.h" -#include -QT_BEGIN_NAMESPACE - -class QWidgetsQmlModule : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - virtual void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.widgets")); - - qmlRegisterInterface("QGraphicsLayoutItem"); - qmlRegisterInterface("QGraphicsLayout"); - qmlRegisterType(uri,4,7,"QGraphicsLinearLayoutStretchItem"); - qmlRegisterType(uri,4,7,"QGraphicsLinearLayout"); - qmlRegisterType(uri,4,7,"QGraphicsGridLayout"); - } -}; - -QT_END_NAMESPACE - -#include "widgets.moc" - -Q_EXPORT_PLUGIN2(qtwidgetsqmlmodule, QT_PREPEND_NAMESPACE(QWidgetsQmlModule)); - diff --git a/src/imports/widgets/widgets.pro b/src/imports/widgets/widgets.pro deleted file mode 100644 index 234ff1e..0000000 --- a/src/imports/widgets/widgets.pro +++ /dev/null @@ -1,30 +0,0 @@ -TARGET = widgets -TARGETPATH = Qt/widgets -include(../qimportbase.pri) - -QT += declarative - -SOURCES += \ - graphicslayouts.cpp \ - widgets.cpp - -HEADERS += \ - graphicslayouts_p.h - -QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/$$TARGETPATH -target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH - -qmldir.files += $$PWD/qmldir -qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH - -symbian:{ - load(data_caging_paths) - include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) - - importFiles.sources = widgets.dll qmldir - importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH - - DEPLOYMENT = importFiles -} - -INSTALLS += target qmldir diff --git a/tests/auto/declarative/qdeclarativelayoutitem/data/layoutItem.qml b/tests/auto/declarative/qdeclarativelayoutitem/data/layoutItem.qml new file mode 100644 index 0000000..ee881a2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelayoutitem/data/layoutItem.qml @@ -0,0 +1,9 @@ +import Qt 4.7 + +LayoutItem {//Sized by the layout + id: resizable + objectName: "resizable" + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "200x200" +} diff --git a/tests/auto/declarative/qdeclarativelayoutitem/qdeclarativelayoutitem.pro b/tests/auto/declarative/qdeclarativelayoutitem/qdeclarativelayoutitem.pro new file mode 100644 index 0000000..eeb784d --- /dev/null +++ b/tests/auto/declarative/qdeclarativelayoutitem/qdeclarativelayoutitem.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qdeclarativelayoutitem.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qdeclarativelayoutitem/tst_qdeclarativelayoutitem.cpp b/tests/auto/declarative/qdeclarativelayoutitem/tst_qdeclarativelayoutitem.cpp new file mode 100644 index 0000000..2207635 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelayoutitem/tst_qdeclarativelayoutitem.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../../shared/util.h" + +class tst_qdeclarativelayoutitem : public QObject +{ + Q_OBJECT +public: + tst_qdeclarativelayoutitem(); + +private slots: + void test_resizing(); +}; + +tst_qdeclarativelayoutitem::tst_qdeclarativelayoutitem() +{ +} + +void tst_qdeclarativelayoutitem::test_resizing() +{ + //Create Layout (must be done in C++) + QGraphicsView view; + QGraphicsScene scene; + QGraphicsWidget *widget = new QGraphicsWidget(); + QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(); + widget->setLayout(layout); + scene.addItem(widget); + view.setScene(&scene); + //Add the QML snippet into the layout + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl(SRCDIR "/data/layoutItem.qml")); + QDeclarativeLayoutItem* obj = static_cast(c.create()); + layout->addItem(obj); + layout->setContentsMargins(0,0,0,0); + widget->setContentsMargins(0,0,0,0); + view.show(); + + QVERIFY(obj!= 0); + + widget->setGeometry(QRectF(0,0, 400,400)); + QCOMPARE(obj->width(), 300.0); + QCOMPARE(obj->height(), 300.0); + + widget->setGeometry(QRectF(0,0, 300,300)); + QCOMPARE(obj->width(), 300.0); + QCOMPARE(obj->height(), 300.0); + + widget->setGeometry(QRectF(0,0, 200,200)); + QCOMPARE(obj->width(), 200.0); + QCOMPARE(obj->height(), 200.0); + + widget->setGeometry(QRectF(0,0, 100,100)); + QCOMPARE(obj->width(), 100.0); + QCOMPARE(obj->height(), 100.0); + + widget->setGeometry(QRectF(0,0, 40,40)); + QCOMPARE(obj->width(), 100.0); + QCOMPARE(obj->height(), 100.0); + + widget->setGeometry(QRectF(0,0, 412,112)); + QCOMPARE(obj->width(), 300.0); + QCOMPARE(obj->height(), 112.0); +} + + +QTEST_MAIN(tst_qdeclarativelayoutitem) + +#include "tst_qdeclarativelayoutitem.moc" diff --git a/tests/auto/declarative/qdeclarativelayouts/data/layouts.qml b/tests/auto/declarative/qdeclarativelayouts/data/layouts.qml deleted file mode 100644 index 0538738..0000000 --- a/tests/auto/declarative/qdeclarativelayouts/data/layouts.qml +++ /dev/null @@ -1,31 +0,0 @@ -import Qt 4.7 -import Qt.widgets 4.7 - -Item { - id: resizable - width:300 - height:300 - QGraphicsWidget { - x : resizable.x - y : resizable.y - width : resizable.width - height : resizable.height - layout: QGraphicsLinearLayout { - spacing: 0 - LayoutItem { - objectName: "left" - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "100x100" - Rectangle { objectName: "yellowRect"; color: "yellow"; anchors.fill: parent } - } - LayoutItem { - objectName: "right" - minimumSize: "100x100" - maximumSize: "400x400" - preferredSize: "200x200" - Rectangle { objectName: "greenRect"; color: "green"; anchors.fill: parent } - } - } - } -} diff --git a/tests/auto/declarative/qdeclarativelayouts/qdeclarativelayouts.pro b/tests/auto/declarative/qdeclarativelayouts/qdeclarativelayouts.pro deleted file mode 100644 index a2065f4..0000000 --- a/tests/auto/declarative/qdeclarativelayouts/qdeclarativelayouts.pro +++ /dev/null @@ -1,10 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -SOURCES += tst_qdeclarativelayouts.cpp -macx:CONFIG -= app_bundle - -# Define SRCDIR equal to test's source directory -DEFINES += SRCDIR=\\\"$$PWD\\\" - -CONFIG += parallel_test - diff --git a/tests/auto/declarative/qdeclarativelayouts/tst_qdeclarativelayouts.cpp b/tests/auto/declarative/qdeclarativelayouts/tst_qdeclarativelayouts.cpp deleted file mode 100644 index 412c3b7..0000000 --- a/tests/auto/declarative/qdeclarativelayouts/tst_qdeclarativelayouts.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include - -class tst_QDeclarativeLayouts : public QObject -{ - Q_OBJECT -public: - tst_QDeclarativeLayouts(); - -private slots: - void test_qml();//GraphicsLayout set up in Qml - void test_cpp();//GraphicsLayout set up in C++ - -private: - QDeclarativeView *createView(const QString &filename); -}; - -tst_QDeclarativeLayouts::tst_QDeclarativeLayouts() -{ -} - -void tst_QDeclarativeLayouts::test_qml() -{ - QDeclarativeView *canvas = createView(SRCDIR "/data/layouts.qml"); - - qApp->processEvents(); - QDeclarativeLayoutItem *left = static_cast(canvas->rootObject()->findChild("left")); - QVERIFY(left != 0); - - QDeclarativeLayoutItem *right = static_cast(canvas->rootObject()->findChild("right")); - QVERIFY(right != 0); - - qreal l = QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin); - qreal r = QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin); - qreal t = QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin); - qreal b = QApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin); - QVERIFY2(l == r && r == t && t == b, "Test assumes equal margins."); - qreal gvMargin = l; - - QDeclarativeItem *rootItem = qobject_cast(canvas->rootObject()); - QVERIFY(rootItem != 0); - - //Preferred Size - rootItem->setWidth(300 + 2*gvMargin); - rootItem->setHeight(300 + 2*gvMargin); - - QCOMPARE(left->x(), gvMargin); - QCOMPARE(left->y(), gvMargin); - QCOMPARE(left->width(), 100.0); - QCOMPARE(left->height(), 300.0); - - QCOMPARE(right->x(), 100.0 + gvMargin); - QCOMPARE(right->y(), 0.0 + gvMargin); - QCOMPARE(right->width(), 200.0); - QCOMPARE(right->height(), 300.0); - - //Minimum Size - rootItem->setWidth(10+2*gvMargin); - rootItem->setHeight(10+2*gvMargin); - - QCOMPARE(left->x(), gvMargin); - QCOMPARE(left->width(), 100.0); - QCOMPARE(left->height(), 100.0); - - QCOMPARE(right->x(), 100.0 + gvMargin); - QCOMPARE(right->width(), 100.0); - QCOMPARE(right->height(), 100.0); - - //Between preferred and Maximum Size - /*Note that if set to maximum size (or above) GraphicsLinearLayout behavior - is to shrink them down to preferred size. So the exact maximum size can't - be used*/ - rootItem->setWidth(670 + 2*gvMargin); - rootItem->setHeight(300 + 2*gvMargin); - - QCOMPARE(left->x(), gvMargin); - QCOMPARE(left->width(), 270.0); - QCOMPARE(left->height(), 300.0); - - QCOMPARE(right->x(), 270.0 + gvMargin); - QCOMPARE(right->width(), 400.0); - QCOMPARE(right->height(), 300.0); - - delete canvas; -} - -void tst_QDeclarativeLayouts::test_cpp() -{ - //TODO: This test! -} - -QDeclarativeView *tst_QDeclarativeLayouts::createView(const QString &filename) -{ - QDeclarativeView *canvas = new QDeclarativeView(0); - canvas->setSource(QUrl::fromLocalFile(filename)); - - return canvas; -} - - -QTEST_MAIN(tst_QDeclarativeLayouts) - -#include "tst_qdeclarativelayouts.moc" -- cgit v0.12 From 39e992988f21553df7e839f36ced75ca5bf8588c Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 5 May 2010 18:06:20 +1000 Subject: Fix i18n example. Add french translation to photoviewer demo. --- .../photoviewer/PhotoViewerCore/AlbumDelegate.qml | 2 +- demos/declarative/photoviewer/i18n/base.ts | 30 +++++++++++++++++++++ demos/declarative/photoviewer/i18n/qml_fr.qm | Bin 0 -> 268 bytes demos/declarative/photoviewer/i18n/qml_fr.ts | 30 +++++++++++++++++++++ demos/declarative/photoviewer/photoviewer.qml | 6 ++--- examples/declarative/i18n/i18n.qml | 30 ++++++++++++--------- 6 files changed, 81 insertions(+), 17 deletions(-) create mode 100644 demos/declarative/photoviewer/i18n/base.ts create mode 100644 demos/declarative/photoviewer/i18n/qml_fr.qm create mode 100644 demos/declarative/photoviewer/i18n/qml_fr.ts diff --git a/demos/declarative/photoviewer/PhotoViewerCore/AlbumDelegate.qml b/demos/declarative/photoviewer/PhotoViewerCore/AlbumDelegate.qml index 142735f..71d3cdc 100644 --- a/demos/declarative/photoviewer/PhotoViewerCore/AlbumDelegate.qml +++ b/demos/declarative/photoviewer/PhotoViewerCore/AlbumDelegate.qml @@ -56,7 +56,7 @@ Component { Tag { anchors { horizontalCenter: parent.horizontalCenter; bottom: parent.bottom; bottomMargin: 10 } - frontLabel: tag; backLabel: "Delete"; flipped: mainWindow.editMode + frontLabel: tag; backLabel: qsTr("Remove"); flipped: mainWindow.editMode onTagChanged: rssModel.tags = tag onBackClicked: if (mainWindow.editMode) photosModel.remove(index); } diff --git a/demos/declarative/photoviewer/i18n/base.ts b/demos/declarative/photoviewer/i18n/base.ts new file mode 100644 index 0000000..1accfd2 --- /dev/null +++ b/demos/declarative/photoviewer/i18n/base.ts @@ -0,0 +1,30 @@ + + + + + AlbumDelegate + + + Remove + + + + + photoviewer + + + Add + + + + + Edit + + + + + Back + + + + diff --git a/demos/declarative/photoviewer/i18n/qml_fr.qm b/demos/declarative/photoviewer/i18n/qml_fr.qm new file mode 100644 index 0000000..c24fcbc Binary files /dev/null and b/demos/declarative/photoviewer/i18n/qml_fr.qm differ diff --git a/demos/declarative/photoviewer/i18n/qml_fr.ts b/demos/declarative/photoviewer/i18n/qml_fr.ts new file mode 100644 index 0000000..9f892db --- /dev/null +++ b/demos/declarative/photoviewer/i18n/qml_fr.ts @@ -0,0 +1,30 @@ + + + + + AlbumDelegate + + + Remove + Supprimer + + + + photoviewer + + + Add + Ajouter + + + + Edit + Éditer + + + + Back + Retour + + + diff --git a/demos/declarative/photoviewer/photoviewer.qml b/demos/declarative/photoviewer/photoviewer.qml index 4094294..e384f46 100644 --- a/demos/declarative/photoviewer/photoviewer.qml +++ b/demos/declarative/photoviewer/photoviewer.qml @@ -27,7 +27,7 @@ Rectangle { Column { spacing: 20; anchors { bottom: parent.bottom; right: parent.right; rightMargin: 20; bottomMargin: 20 } Button { - id: newButton; label: "New"; rotation: 3 + id: newButton; label: qsTr("Add"); rotation: 3 anchors.horizontalCenter: parent.horizontalCenter onClicked: { mainWindow.editMode = false @@ -36,7 +36,7 @@ Rectangle { } } Button { - id: deleteButton; label: "Delete"; rotation: -2; + id: deleteButton; label: qsTr("Edit"); rotation: -2; onClicked: mainWindow.editMode = !mainWindow.editMode anchors.horizontalCenter: parent.horizontalCenter } @@ -49,7 +49,7 @@ Rectangle { ListView { anchors.fill: parent; model: albumVisualModel.parts.browser; interactive: false } - Button { id: backButton; label: "Back"; rotation: 3; x: parent.width - backButton.width - 6; y: -backButton.height - 8 } + Button { id: backButton; label: qsTr("Back"); rotation: 3; x: parent.width - backButton.width - 6; y: -backButton.height - 8 } Rectangle { id: photosShade; color: 'black'; width: parent.width; height: parent.height; opacity: 0; visible: opacity != 0.0 } diff --git a/examples/declarative/i18n/i18n.qml b/examples/declarative/i18n/i18n.qml index 3b1279a..c3030b2 100644 --- a/examples/declarative/i18n/i18n.qml +++ b/examples/declarative/i18n/i18n.qml @@ -6,8 +6,9 @@ import Qt 4.7 // // The files are created/updated by running: // -// lupdate i18n.qml -ts i18n/*.ts +// lupdate i18n.qml -ts i18n/base.ts // +// Translations for new languages are created by copying i18n/base.ts to i18n/qml_.ts // The .ts files can then be edited with Linguist: // // linguist i18n/qml_fr.ts @@ -16,18 +17,21 @@ import Qt 4.7 // // lrelease i18n/*.ts // -// Translations for new languages are created by copying i18n/base.ts to i18n/qml_.ts -// and editing the result with Linguist. -// -Column { - Text { - text: "If a translation is available for the system language (eg. Franch) then the string below will translated (eg. 'Bonjour'). Otherwise is will show 'Hello'." - width: 200 - wrapMode: Text.WordWrap - } - Text { - text: qsTr("Hello") - font.pointSize: 25 +Rectangle { + width: 640; height: 480 + + Column { + anchors.fill: parent; spacing: 20 + + Text { + text: "If a translation is available for the system language (eg. French) then the string below will translated (eg. 'Bonjour'). Otherwise is will show 'Hello'." + width: parent.width; wrapMode: Text.WordWrap + } + + Text { + text: qsTr("Hello") + font.pointSize: 25; anchors.horizontalCenter: parent.horizontalCenter + } } } -- cgit v0.12 From d340dc6e4b3f1f4f8737d0d1d34e76ae68e007d6 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 23 Apr 2010 17:22:16 +0200 Subject: Add a switch to the menu to hide/show the runtime warnings Reviewed-by: mae --- tools/qml/loggerwidget.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++-- tools/qml/loggerwidget.h | 32 +++++++++++- tools/qml/main.cpp | 33 +++++++++---- tools/qml/qmlruntime.cpp | 44 ++++++++++++++++- tools/qml/qmlruntime.h | 10 ++++ 5 files changed, 222 insertions(+), 17 deletions(-) diff --git a/tools/qml/loggerwidget.cpp b/tools/qml/loggerwidget.cpp index 9eca4a6..3ae2b5e 100644 --- a/tools/qml/loggerwidget.cpp +++ b/tools/qml/loggerwidget.cpp @@ -42,29 +42,141 @@ #include "loggerwidget.h" #include #include +#include +#include +#include QT_BEGIN_NAMESPACE LoggerWidget::LoggerWidget(QWidget *parent) : QPlainTextEdit(parent), - m_keepClosed(false) + m_visibilityOrigin(SettingsOrigin) { setAttribute(Qt::WA_QuitOnClose, false); - setWindowTitle(tr("Logger")); + setWindowTitle(tr("Warnings")); + + readSettings(); + setupPreferencesMenu(); } void LoggerWidget::append(const QString &msg) { appendPlainText(msg); - if (!m_keepClosed && !isVisible()) + if (!isVisible() && (defaultVisibility() == AutoShowWarnings)) setVisible(true); } +LoggerWidget::Visibility LoggerWidget::defaultVisibility() const +{ + return m_visibility; +} + +void LoggerWidget::setDefaultVisibility(LoggerWidget::Visibility visibility) +{ + if (m_visibility == visibility) + return; + + m_visibility = visibility; + m_visibilityOrigin = CommandLineOrigin; + + m_preferencesMenu->setEnabled(m_visibilityOrigin == SettingsOrigin); +} + +QMenu *LoggerWidget::preferencesMenu() +{ + return m_preferencesMenu; +} + +QAction *LoggerWidget::showAction() +{ + return m_showWidgetAction; +} + +void LoggerWidget::readSettings() +{ + QSettings settings; + QString warningsPreferences = settings.value("warnings", "hide").toString(); + if (warningsPreferences == "show") { + m_visibility = ShowWarnings; + } else if (warningsPreferences == "hide") { + m_visibility = HideWarnings; + } else { + m_visibility = AutoShowWarnings; + } +} + +void LoggerWidget::saveSettings() +{ + if (m_visibilityOrigin != SettingsOrigin) + return; + + QString value = "autoShow"; + if (defaultVisibility() == ShowWarnings) { + value = "show"; + } else if (defaultVisibility() == HideWarnings) { + value = "hide"; + } + + QSettings settings; + settings.setValue("warnings", value); +} + +void LoggerWidget::warningsPreferenceChanged(QAction *action) +{ + Visibility newSetting = static_cast(action->data().toInt()); + m_visibility = newSetting; + saveSettings(); +} + +void LoggerWidget::showEvent(QShowEvent *event) +{ + QWidget::showEvent(event); + emit opened(); +} + void LoggerWidget::closeEvent(QCloseEvent *event) { - m_keepClosed = true; QWidget::closeEvent(event); + emit closed(); +} + +void LoggerWidget::setupPreferencesMenu() +{ + m_preferencesMenu = new QMenu(tr("Warnings")); + QActionGroup *warnings = new QActionGroup(m_preferencesMenu); + warnings->setExclusive(true); + + connect(warnings, SIGNAL(triggered(QAction*)), this, SLOT(warningsPreferenceChanged(QAction*))); + + QAction *showWarningsPreference = new QAction(tr("Show by default"), m_preferencesMenu); + showWarningsPreference->setCheckable(true); + showWarningsPreference->setData(LoggerWidget::ShowWarnings); + warnings->addAction(showWarningsPreference); + m_preferencesMenu->addAction(showWarningsPreference); + + QAction *hideWarningsPreference = new QAction(tr("Hide by default"), m_preferencesMenu); + hideWarningsPreference->setCheckable(true); + hideWarningsPreference->setData(LoggerWidget::HideWarnings); + warnings->addAction(hideWarningsPreference); + m_preferencesMenu->addAction(hideWarningsPreference); + + QAction *autoWarningsPreference = new QAction(tr("Show for first warning"), m_preferencesMenu); + autoWarningsPreference->setCheckable(true); + autoWarningsPreference->setData(LoggerWidget::AutoShowWarnings); + warnings->addAction(autoWarningsPreference); + m_preferencesMenu->addAction(autoWarningsPreference); + + switch (defaultVisibility()) { + case LoggerWidget::ShowWarnings: + showWarningsPreference->setChecked(true); + break; + case LoggerWidget::HideWarnings: + hideWarningsPreference->setChecked(true); + break; + default: + autoWarningsPreference->setChecked(true); + } } QT_END_NAMESPACE diff --git a/tools/qml/loggerwidget.h b/tools/qml/loggerwidget.h index 5c4a701..b68ecc5 100644 --- a/tools/qml/loggerwidget.h +++ b/tools/qml/loggerwidget.h @@ -50,14 +50,44 @@ class LoggerWidget : public QPlainTextEdit { Q_OBJECT public: LoggerWidget(QWidget *parent=0); + + enum Visibility { ShowWarnings, HideWarnings, AutoShowWarnings }; + + Visibility defaultVisibility() const; + void setDefaultVisibility(Visibility visibility); + + QMenu *preferencesMenu(); + QAction *showAction(); + public slots: void append(const QString &msg); + +private slots: + void warningsPreferenceChanged(QAction *action); + void readSettings(); + void saveSettings(); + protected: + void showEvent(QShowEvent *event); void closeEvent(QCloseEvent *event); + +signals: + void opened(); + void closed(); + private: - bool m_keepClosed; + void setupPreferencesMenu(); + + QMenu *m_preferencesMenu; + QAction *m_showWidgetAction; + + enum ConfigOrigin { CommandLineOrigin, SettingsOrigin }; + ConfigOrigin m_visibilityOrigin; + Visibility m_visibility; }; +Q_DECLARE_METATYPE(LoggerWidget::Visibility); + QT_END_NAMESPACE #endif // LOGGERWIDGET_H diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index f2c0530..78f0c87 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(" -warnings ................................ show warnings in a separate log window"); + qWarning(" -warnings [show|hide]..................... show warnings in a separate log window"); qWarning(" -recordfile ..................... set video recording file"); qWarning(" - ImageMagick 'convert' for GIF)"); qWarning(" - png file for raw frames"); @@ -168,6 +168,8 @@ void scriptOptsUsage() exit(1); } +enum WarningsConfig { ShowWarnings, HideWarnings, DefaultWarnings }; + int main(int argc, char ** argv) { #if defined (Q_OS_SYMBIAN) @@ -230,7 +232,7 @@ int main(int argc, char ** argv) bool maximized = false; bool useNativeFileBrowser = true; - bool showLogWidget = false; + WarningsConfig warningsConfig = DefaultWarnings; bool sizeToView = true; #if defined(Q_OS_SYMBIAN) @@ -292,7 +294,15 @@ int main(int argc, char ** argv) } else if (arg == "-qmlbrowser") { useNativeFileBrowser = false; } else if (arg == "-warnings") { - showLogWidget = true; + if (lastArg) usage(); + QString warningsStr = QString(argv[++i]); + if (warningsStr == QLatin1String("show")) { + warningsConfig = ShowWarnings; + } else if (warningsStr == QLatin1String("hide")) { + warningsConfig = HideWarnings; + } else { + usage(); + } } else if (arg == "-I" || arg == "-L") { if (arg == "-L") qWarning("-L option provided for compatibility only, use -I instead"); @@ -341,13 +351,6 @@ int main(int argc, char ** argv) if (stayOnTop) wflags |= Qt::WindowStaysOnTopHint; -#if !defined(Q_OS_SYMBIAN) - LoggerWidget loggerWidget(0); - if (showLogWidget) { - logger = &loggerWidget; - } -#endif - QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags); if (!scriptopts.isEmpty()) { QStringList options = @@ -390,6 +393,16 @@ int main(int argc, char ** argv) usage(); } +#if !defined(Q_OS_SYMBIAN) + logger = viewer->warningsWidget(); + if (warningsConfig == ShowWarnings) { + logger.data()->setDefaultVisibility(LoggerWidget::ShowWarnings); + logger.data()->show(); + } else if (warningsConfig == HideWarnings){ + logger.data()->setDefaultVisibility(LoggerWidget::HideWarnings); + } +#endif + foreach (QString lib, imports) viewer->addLibraryPath(lib); diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index da31284..1229df2 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -462,10 +462,13 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) #else : QWidget(parent, flags) #endif + , loggerWindow(new LoggerWidget()) , frame_stream(0), scaleSkin(true), mb(0) , portraitOrientation(0), landscapeOrientation(0) - , m_scriptOptions(0), tester(0), useQmlFileBrowser(true) - , translator(0) + , showWarningsWindow(0) + , m_scriptOptions(0) + , tester(0) + , useQmlFileBrowser(true) { QDeclarativeViewer::registerTypes(); setWindowTitle(tr("Qt Qml Runtime")); @@ -506,6 +509,9 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) QObject::connect(canvas, SIGNAL(statusChanged(QDeclarativeView::Status)), this, SLOT(statusChanged())); QObject::connect(canvas->engine(), SIGNAL(quit()), QCoreApplication::instance (), SLOT(quit())); + QObject::connect(warningsWidget(), SIGNAL(opened()), this, SLOT(warningsWidgetOpened())); + QObject::connect(warningsWidget(), SIGNAL(closed()), this, SLOT(warningsWidgetClosed())); + if (!(flags & Qt::FramelessWindowHint)) { createMenu(menuBar(),0); setPortrait(); @@ -565,6 +571,11 @@ QDeclarativeView *QDeclarativeViewer::view() const return canvas; } +LoggerWidget *QDeclarativeViewer::warningsWidget() const +{ + return loggerWindow; +} + void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) { QObject *parent = flatmenu ? (QObject*)flatmenu : (QObject*)menu; @@ -616,6 +627,15 @@ void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool))); debugMenu->addAction(slowAction); + showWarningsWindow = new QAction(tr("Show Warnings"), parent); + showWarningsWindow->setCheckable((true)); + showWarningsWindow->setChecked(loggerWindow->isVisible()); + connect(showWarningsWindow, SIGNAL(triggered(bool)), this, SLOT(showWarnings(bool))); + +#if !defined(Q_OS_SYMBIAN) + debugMenu->addAction(showWarningsWindow); +#endif + if (flatmenu) flatmenu->addSeparator(); QMenu *skinMenu = flatmenu ? flatmenu->addMenu(tr("&Skin")) : menu->addMenu(tr("&Skin")); @@ -672,6 +692,8 @@ void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) #if !defined(Q_OS_SYMBIAN) if (!flatmenu) settingsMenu->addAction(recordOptions); + + settingsMenu->addMenu(loggerWindow->preferencesMenu()); #else QAction *fullscreenAction = new QAction(tr("Full Screen"), parent); fullscreenAction->setCheckable(true); @@ -679,7 +701,10 @@ void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) settingsMenu->addAction(fullscreenAction); #endif + if (flatmenu) flatmenu->addSeparator(); + QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties")); + QActionGroup *orientation = new QActionGroup(parent); QAction *toggleOrientation = new QAction(tr("&Toggle Orientation"), parent); @@ -758,6 +783,21 @@ void QDeclarativeViewer::toggleFullScreen() showFullScreen(); } +void QDeclarativeViewer::showWarnings(bool show) +{ + loggerWindow->setVisible(show); +} + +void QDeclarativeViewer::warningsWidgetOpened() +{ + showWarningsWindow->setChecked(true); +} + +void QDeclarativeViewer::warningsWidgetClosed() +{ + showWarningsWindow->setChecked(false); +} + void QDeclarativeViewer::setScaleSkin() { if (scaleSkin) diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 0b23303..655feea 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -48,6 +48,8 @@ #include #include +#include "loggerwidget.h" + QT_BEGIN_NAMESPACE class QDeclarativeView; @@ -108,6 +110,7 @@ public: QMenuBar *menuBar() const; QDeclarativeView *view() const; + LoggerWidget *warningsWidget() const; public slots: void sceneResized(QSize size); @@ -145,10 +148,15 @@ private slots: void startNetwork(); void toggleFullScreen(); + void showWarnings(bool show); + void warningsWidgetOpened(); + void warningsWidgetClosed(); + private: QString getVideoFileName(); int menuBarHeight() const; + LoggerWidget *loggerWindow; PreviewDeviceSkin *skin; QSize skinscreensize; QDeclarativeView *canvas; @@ -183,6 +191,8 @@ private: QAction *portraitOrientation; QAction *landscapeOrientation; + QAction *showWarningsWindow; + QString m_script; ScriptOptions m_scriptOptions; QDeclarativeTester *tester; -- cgit v0.12 From 0a8379d9f01118d7ff0121e6ecbbc0307e1e7f63 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 6 May 2010 04:54:19 +1000 Subject: Make component.createObject require a parent argument For graphical objects (the common case) a common mistake is to not parent a dynamically created item. Since you almost always want to add a parent, and it's hard for a beginner to diagnose this problem, a parent is now a required argument and dealt with by the createObject function. Task-number: QTBUG-10110 --- demos/declarative/samegame/SamegameCore/samegame.js | 3 +-- demos/declarative/snake/content/snake.js | 6 ++---- doc/src/declarative/dynamicobjects.qdoc | 4 +++- doc/src/declarative/globalobject.qdoc | 5 ++++- doc/src/snippets/declarative/componentCreation.js | 8 ++------ doc/src/snippets/declarative/dynamicObjects.qml | 3 +-- examples/declarative/dynamic/qml/itemCreation.js | 3 +-- .../tutorials/samegame/samegame2/samegame.js | 3 +-- .../tutorials/samegame/samegame3/samegame.js | 3 +-- .../tutorials/samegame/samegame4/content/samegame.js | 3 +-- src/declarative/qml/qdeclarativecomponent.cpp | 20 +++++++++++++++++++- src/declarative/qml/qdeclarativecomponent.h | 2 +- .../qdeclarativeecmascript/data/dynamicCreation.qml | 4 ++-- 13 files changed, 39 insertions(+), 28 deletions(-) diff --git a/demos/declarative/samegame/SamegameCore/samegame.js b/demos/declarative/samegame/SamegameCore/samegame.js index cc0a70d..f9c6184 100755 --- a/demos/declarative/samegame/SamegameCore/samegame.js +++ b/demos/declarative/samegame/SamegameCore/samegame.js @@ -176,14 +176,13 @@ function createBlock(column,row){ // 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.status == Component.Ready){ - var dynamicObject = component.createObject(); + var dynamicObject = component.createObject(gameCanvas); if(dynamicObject == null){ console.log("error creating block"); console.log(component.errorsString()); return false; } dynamicObject.type = Math.floor(Math.random() * 3); - dynamicObject.parent = gameCanvas; dynamicObject.x = column*gameCanvas.blockSize; dynamicObject.targetX = column*gameCanvas.blockSize; dynamicObject.targetY = row*gameCanvas.blockSize; diff --git a/demos/declarative/snake/content/snake.js b/demos/declarative/snake/content/snake.js index 102bd87..f5c231e 100644 --- a/demos/declarative/snake/content/snake.js +++ b/demos/declarative/snake/content/snake.js @@ -59,8 +59,7 @@ function startNewGame() console.log("Still loading linkComponent"); continue;//TODO: Better error handling? } - var link = linkComponent.createObject(); - link.parent = playfield; + var link = linkComponent.createObject(playfield); link.z = numRows * numColumns + 1 - i; link.type = i == 0 ? 2 : 0; link.spawned = false; @@ -300,8 +299,7 @@ function createCookie(value) { console.log("Still loading cookieComponent"); return;//TODO: Better error handling? } - cookie = cookieComponent.createObject(); - cookie.parent = head.parent; + cookie = cookieComponent.createObject(head.parent); cookie.value = value; cookie.row = row; cookie.column = column; diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc index dc0277d..2688ee5 100644 --- a/doc/src/declarative/dynamicobjects.qdoc +++ b/doc/src/declarative/dynamicobjects.qdoc @@ -69,7 +69,9 @@ 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 \l {Component::createObject()}{createObject()} method to create an instance of -the component. +the component. This function takes exactly one argument, which is the parent for the new item. Since graphical items will +not appear on the scene without a parent, it is recommended that you set the parent this way. However, if you wish to set +the parent later you can safely pass null to this function. Here is an example. Here is a \c Sprite.qml, which defines a simple QML component: diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 7c27ae4..bc9830a 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -258,7 +258,10 @@ 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 error that occurred. Note that createObject() takes exactly one argument, which is set +to the parent of the created object. Graphical objects without a parent will not appear +on the scene, but if you do not wish to parent the item at this point you can safely pass +in null. 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. diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js index be928f0..f6fb379 100644 --- a/doc/src/snippets/declarative/componentCreation.js +++ b/doc/src/snippets/declarative/componentCreation.js @@ -4,11 +4,10 @@ var sprite; function finishCreation() { if (component.status == Component.Ready) { - sprite = component.createObject(); + sprite = component.createObject(appWindow); if (sprite == null) { // Error Handling } else { - sprite.parent = appWindow; sprite.x = 100; sprite.y = 100; // ... @@ -32,13 +31,12 @@ else //![2] component = Qt.createComponent("Sprite.qml"); -sprite = component.createObject(); +sprite = component.createObject(appWindow); if (sprite == null) { // Error Handling console.log("Error loading component:", component.errorsString()); } else { - sprite.parent = appWindow; sprite.x = 100; sprite.y = 100; // ... @@ -47,5 +45,3 @@ if (sprite == null) { } -createSpriteObjects(); - diff --git a/doc/src/snippets/declarative/dynamicObjects.qml b/doc/src/snippets/declarative/dynamicObjects.qml index dd55d78..6a8c927 100644 --- a/doc/src/snippets/declarative/dynamicObjects.qml +++ b/doc/src/snippets/declarative/dynamicObjects.qml @@ -21,8 +21,7 @@ Rectangle { } function createRectangle() { - var object = rectComponent.createObject(); - object.parent = rootItem; + var object = rectComponent.createObject(rootItem); } Component.onCompleted: createRectangle() diff --git a/examples/declarative/dynamic/qml/itemCreation.js b/examples/declarative/dynamic/qml/itemCreation.js index 3c1b975..08f5320 100644 --- a/examples/declarative/dynamic/qml/itemCreation.js +++ b/examples/declarative/dynamic/qml/itemCreation.js @@ -42,8 +42,7 @@ function loadComponent() { function createItem() { if (itemComponent.status == Component.Ready && draggedItem == null) { - draggedItem = itemComponent.createObject(); - draggedItem.parent = window; + draggedItem = itemComponent.createObject(window); draggedItem.image = itemButton.image; draggedItem.x = xOffset; draggedItem.y = yOffset; diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js index bcfb5b6..0dbe6a6 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js @@ -41,13 +41,12 @@ function createBlock(column, row) { // 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(); + var dynamicObject = component.createObject(background); if (dynamicObject == null) { console.log("error creating block"); console.log(component.errorsString()); return false; } - dynamicObject.parent = background; dynamicObject.x = column * blockSize; dynamicObject.y = row * blockSize; dynamicObject.width = blockSize; diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.js b/examples/declarative/tutorials/samegame/samegame3/samegame.js index 4256aee..e5ba6e0 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.js @@ -38,14 +38,13 @@ function createBlock(column, row) { // 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(); + var dynamicObject = component.createObject(gameCanvas); if (dynamicObject == null) { console.log("error creating block"); console.log(component.errorsString()); return false; } dynamicObject.type = Math.floor(Math.random() * 3); - dynamicObject.parent = gameCanvas; dynamicObject.x = column * gameCanvas.blockSize; dynamicObject.y = row * gameCanvas.blockSize; dynamicObject.width = gameCanvas.blockSize; diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js index 961cd66..159c9a7 100755 --- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js @@ -49,14 +49,13 @@ function createBlock(column, row) { // 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(); + var dynamicObject = component.createObject(gameCanvas); if (dynamicObject == null) { console.log("error creating block"); console.log(component.errorsString()); return false; } dynamicObject.type = Math.floor(Math.random() * 3); - dynamicObject.parent = gameCanvas; dynamicObject.x = column * gameCanvas.blockSize; dynamicObject.targetX = column * gameCanvas.blockSize; dynamicObject.targetY = row * gameCanvas.blockSize; diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 3ca0707..e7b9c9e 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -59,6 +59,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -557,8 +558,11 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q /*! \internal A version of create which returns a scriptObject, for use in script + + Sets graphics object parent because forgetting to do this is a frequent + and serious problem. */ -QScriptValue QDeclarativeComponent::createObject() +QScriptValue QDeclarativeComponent::createObject(QObject* parent) { Q_D(QDeclarativeComponent); QDeclarativeContext* ctxt = creationContext(); @@ -567,6 +571,20 @@ QScriptValue QDeclarativeComponent::createObject() QObject* ret = create(ctxt); if (!ret) return QScriptValue(QScriptValue::NullValue); + + QGraphicsObject* gobj = qobject_cast(ret); + bool needParent = (gobj != 0); + if(parent){ + ret->setParent(parent); + QGraphicsObject* gparent = qobject_cast(parent); + if(gparent){ + gobj->setParentItem(gparent); + needParent = false; + } + } + if(needParent) + qWarning("QDeclarativeComponent: Created graphical object was not placed in the graphics scene."); + QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(d->engine); QDeclarativeData::get(ret, true)->setImplicitDestructible(); return priv->objectClass->newQObject(ret, QMetaType::QObjectStar); diff --git a/src/declarative/qml/qdeclarativecomponent.h b/src/declarative/qml/qdeclarativecomponent.h index b078174..688e233 100644 --- a/src/declarative/qml/qdeclarativecomponent.h +++ b/src/declarative/qml/qdeclarativecomponent.h @@ -109,7 +109,7 @@ Q_SIGNALS: protected: QDeclarativeComponent(QDeclarativeComponentPrivate &dd, QObject* parent); - Q_INVOKABLE QScriptValue createObject(); + Q_INVOKABLE QScriptValue createObject(QObject* parent); private: QDeclarativeComponent(QDeclarativeEngine *, QDeclarativeCompiledData *, int, int, QObject *parent); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/dynamicCreation.qml b/tests/auto/declarative/qdeclarativeecmascript/data/dynamicCreation.qml index 3047e9b..7b132e1 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/dynamicCreation.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/dynamicCreation.qml @@ -11,7 +11,7 @@ MyQmlObject{ function createTwo() { var component = Qt.createComponent('dynamicCreation.helper.qml'); - obj.objectProperty = component.createObject(); + obj.objectProperty = component.createObject(obj); } function createThree() @@ -22,6 +22,6 @@ MyQmlObject{ function dontCrash() { var component = Qt.createComponent('file-doesnt-exist.qml'); - obj.objectProperty = component.createObject(); + obj.objectProperty = component.createObject(obj); } } -- cgit v0.12 From 053fcebb7ef1b3899b656d511437a8139ee012b7 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 6 May 2010 08:45:13 +1000 Subject: Initialize variable and crash less. --- tools/qml/qmlruntime.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 1229df2..fe0f67c 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -469,6 +469,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) , m_scriptOptions(0) , tester(0) , useQmlFileBrowser(true) + , translator(0) { QDeclarativeViewer::registerTypes(); setWindowTitle(tr("Qt Qml Runtime")); -- cgit v0.12 From 2df493e9f0660be7d9b5ba691883e13fa12cde72 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 6 May 2010 09:18:36 +1000 Subject: Fix compile in namespace. --- tools/qml/loggerwidget.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/qml/loggerwidget.h b/tools/qml/loggerwidget.h index b68ecc5..fd20c41 100644 --- a/tools/qml/loggerwidget.h +++ b/tools/qml/loggerwidget.h @@ -86,8 +86,8 @@ private: Visibility m_visibility; }; -Q_DECLARE_METATYPE(LoggerWidget::Visibility); - QT_END_NAMESPACE +Q_DECLARE_METATYPE(LoggerWidget::Visibility) + #endif // LOGGERWIDGET_H -- cgit v0.12 From 8e023477777982d3aeb53d26ed61f7e8c1eb753c Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 6 May 2010 09:34:51 +1000 Subject: Another initialization fix. Unleak. --- tools/qml/main.cpp | 2 +- tools/qml/qmlruntime.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 78f0c87..fb687ac 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -54,7 +54,7 @@ QT_USE_NAMESPACE -QtMsgHandler systemMsgOutput; +QtMsgHandler systemMsgOutput = 0; #if defined (Q_OS_SYMBIAN) #include diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index fe0f67c..d49b0f1 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -543,6 +543,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) QDeclarativeViewer::~QDeclarativeViewer() { + delete loggerWindow; canvas->engine()->setNetworkAccessManagerFactory(0); delete namFactory; } -- cgit v0.12 From 2df39e548264617b8e10fae32bdafbfe2edcd895 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 6 May 2010 09:39:31 +1000 Subject: Fix some compiler warnings. --- src/declarative/qml/qdeclarativeengine.cpp | 46 +++++++++++++++--------------- src/declarative/qml/qdeclarativeinfo.cpp | 3 +- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 6ddd01e..cc6c5fe 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -962,7 +962,7 @@ QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QS Q_ASSERT(context); if(ctxt->argumentCount() != 1) { - return ctxt->throwError("Qt.createComponent(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.createComponent(): Invalid arguments")); }else{ QString arg = ctxt->argument(0).toString(); if (arg.isEmpty()) @@ -982,7 +982,7 @@ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QS QDeclarativeEngine* activeEngine = activeEnginePriv->q_func(); if(ctxt->argumentCount() < 2 || ctxt->argumentCount() > 3) - return ctxt->throwError("Qt.createQmlObject(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.createQmlObject(): Invalid arguments")); QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt); Q_ASSERT(context); @@ -1002,7 +1002,7 @@ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QS QObject *parentArg = activeEnginePriv->objectClass->toQObject(ctxt->argument(1)); if(!parentArg) - return ctxt->throwError("Qt.createQmlObject(): Missing parent object"); + return ctxt->throwError(QLatin1String("Qt.createQmlObject(): Missing parent object")); QDeclarativeComponent component(activeEngine); component.setData(qml.toUtf8(), url); @@ -1027,7 +1027,7 @@ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QS } if (!component.isReady()) - return ctxt->throwError("Qt.createQmlObject(): Component is not ready"); + return ctxt->throwError(QLatin1String("Qt.createQmlObject(): Component is not ready")); QObject *obj = component.beginCreate(context->asQDeclarativeContext()); if(obj) @@ -1076,7 +1076,7 @@ QScriptValue QDeclarativeEnginePrivate::isQtObject(QScriptContext *ctxt, QScript QScriptValue QDeclarativeEnginePrivate::vector(QScriptContext *ctxt, QScriptEngine *engine) { if(ctxt->argumentCount() != 3) - return ctxt->throwError("Qt.vector(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.vector(): Invalid arguments")); qsreal x = ctxt->argument(0).toNumber(); qsreal y = ctxt->argument(1).toNumber(); qsreal z = ctxt->argument(2).toNumber(); @@ -1087,7 +1087,7 @@ QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptE { int argCount = ctxt->argumentCount(); if(argCount == 0 || argCount > 2) - return ctxt->throwError("Qt.formatDate(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.formatDate(): Invalid arguments")); QDate date = ctxt->argument(0).toDateTime().date(); Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate; @@ -1098,7 +1098,7 @@ QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptE } else if (ctxt->argument(1).isNumber()) { enumFormat = Qt::DateFormat(ctxt->argument(1).toUInt32()); } else { - return ctxt->throwError("Qt.formatDate(): Invalid date format"); + return ctxt->throwError(QLatin1String("Qt.formatDate(): Invalid date format")); } } return engine->newVariant(qVariantFromValue(date.toString(enumFormat))); @@ -1108,7 +1108,7 @@ QScriptValue QDeclarativeEnginePrivate::formatTime(QScriptContext*ctxt, QScriptE { int argCount = ctxt->argumentCount(); if(argCount == 0 || argCount > 2) - return ctxt->throwError("Qt.formatTime(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.formatTime(): Invalid arguments")); QTime date = ctxt->argument(0).toDateTime().time(); Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate; @@ -1119,7 +1119,7 @@ QScriptValue QDeclarativeEnginePrivate::formatTime(QScriptContext*ctxt, QScriptE } else if (ctxt->argument(1).isNumber()) { enumFormat = Qt::DateFormat(ctxt->argument(1).toUInt32()); } else { - return ctxt->throwError("Qt.formatTime(): Invalid time format"); + return ctxt->throwError(QLatin1String("Qt.formatTime(): Invalid time format")); } } return engine->newVariant(qVariantFromValue(date.toString(enumFormat))); @@ -1129,7 +1129,7 @@ QScriptValue QDeclarativeEnginePrivate::formatDateTime(QScriptContext*ctxt, QScr { int argCount = ctxt->argumentCount(); if(argCount == 0 || argCount > 2) - return ctxt->throwError("Qt.formatDateTime(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid arguments")); QDateTime date = ctxt->argument(0).toDateTime(); Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate; @@ -1140,7 +1140,7 @@ QScriptValue QDeclarativeEnginePrivate::formatDateTime(QScriptContext*ctxt, QScr } else if (ctxt->argument(1).isNumber()) { enumFormat = Qt::DateFormat(ctxt->argument(1).toUInt32()); } else { - return ctxt->throwError("Qt.formatDateTime(): Invalid datetime format"); + return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid datetime format")); } } return engine->newVariant(qVariantFromValue(date.toString(enumFormat))); @@ -1150,7 +1150,7 @@ QScriptValue QDeclarativeEnginePrivate::rgba(QScriptContext *ctxt, QScriptEngine { int argCount = ctxt->argumentCount(); if(argCount < 3 || argCount > 4) - return ctxt->throwError("Qt.rgba(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.rgba(): Invalid arguments")); qsreal r = ctxt->argument(0).toNumber(); qsreal g = ctxt->argument(1).toNumber(); qsreal b = ctxt->argument(2).toNumber(); @@ -1172,7 +1172,7 @@ QScriptValue QDeclarativeEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine { int argCount = ctxt->argumentCount(); if(argCount < 3 || argCount > 4) - return ctxt->throwError("Qt.hsla(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.hsla(): Invalid arguments")); qsreal h = ctxt->argument(0).toNumber(); qsreal s = ctxt->argument(1).toNumber(); qsreal l = ctxt->argument(2).toNumber(); @@ -1193,7 +1193,7 @@ QScriptValue QDeclarativeEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine QScriptValue QDeclarativeEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine *engine) { if(ctxt->argumentCount() != 4) - return ctxt->throwError("Qt.rect(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.rect(): Invalid arguments")); qsreal x = ctxt->argument(0).toNumber(); qsreal y = ctxt->argument(1).toNumber(); @@ -1209,7 +1209,7 @@ QScriptValue QDeclarativeEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine) { if(ctxt->argumentCount() != 2) - return ctxt->throwError("Qt.point(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.point(): Invalid arguments")); qsreal x = ctxt->argument(0).toNumber(); qsreal y = ctxt->argument(1).toNumber(); return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QPointF(x, y))); @@ -1218,7 +1218,7 @@ QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngin QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine) { if(ctxt->argumentCount() != 2) - return ctxt->throwError("Qt.size(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.size(): Invalid arguments")); qsreal w = ctxt->argument(0).toNumber(); qsreal h = ctxt->argument(1).toNumber(); return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QSizeF(w, h))); @@ -1227,7 +1227,7 @@ QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine QScriptValue QDeclarativeEnginePrivate::lighter(QScriptContext *ctxt, QScriptEngine *engine) { if(ctxt->argumentCount() != 1 && ctxt->argumentCount() != 2) - return ctxt->throwError("Qt.lighter(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.lighter(): Invalid arguments")); QVariant v = ctxt->argument(0).toVariant(); QColor color; if (v.userType() == QVariant::Color) @@ -1249,7 +1249,7 @@ QScriptValue QDeclarativeEnginePrivate::lighter(QScriptContext *ctxt, QScriptEng QScriptValue QDeclarativeEnginePrivate::darker(QScriptContext *ctxt, QScriptEngine *engine) { if(ctxt->argumentCount() != 1 && ctxt->argumentCount() != 2) - return ctxt->throwError("Qt.darker(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.darker(): Invalid arguments")); QVariant v = ctxt->argument(0).toVariant(); QColor color; if (v.userType() == QVariant::Color) @@ -1282,7 +1282,7 @@ QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QSc QScriptValue QDeclarativeEnginePrivate::fontFamilies(QScriptContext *ctxt, QScriptEngine *e) { if(ctxt->argumentCount() != 0) - return ctxt->throwError("Qt.fontFamilies(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.fontFamilies(): Invalid arguments")); QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(e); QFontDatabase database; @@ -1292,7 +1292,7 @@ QScriptValue QDeclarativeEnginePrivate::fontFamilies(QScriptContext *ctxt, QScri QScriptValue QDeclarativeEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *) { if (ctxt->argumentCount() != 1) - return ctxt->throwError("Qt.md5(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.md5(): Invalid arguments")); QByteArray data = ctxt->argument(0).toString().toUtf8(); QByteArray result = QCryptographicHash::hash(data, QCryptographicHash::Md5); @@ -1303,7 +1303,7 @@ QScriptValue QDeclarativeEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine QScriptValue QDeclarativeEnginePrivate::btoa(QScriptContext *ctxt, QScriptEngine *) { if (ctxt->argumentCount() != 1) - return ctxt->throwError("Qt.btoa(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.btoa(): Invalid arguments")); QByteArray data = ctxt->argument(0).toString().toUtf8(); @@ -1313,7 +1313,7 @@ QScriptValue QDeclarativeEnginePrivate::btoa(QScriptContext *ctxt, QScriptEngine QScriptValue QDeclarativeEnginePrivate::atob(QScriptContext *ctxt, QScriptEngine *) { if (ctxt->argumentCount() != 1) - return ctxt->throwError("Qt.atob(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.atob(): Invalid arguments")); QByteArray data = ctxt->argument(0).toString().toUtf8(); @@ -1414,7 +1414,7 @@ QScriptValue QDeclarativeEnginePrivate::quit(QScriptContext * /*ctxt*/, QScriptE QScriptValue QDeclarativeEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine) { if(ctxt->argumentCount() != 2) - return ctxt->throwError("Qt.tint(): Invalid arguments"); + return ctxt->throwError(QLatin1String("Qt.tint(): Invalid arguments")); //get color QVariant v = ctxt->argument(0).toVariant(); QColor color; diff --git a/src/declarative/qml/qdeclarativeinfo.cpp b/src/declarative/qml/qdeclarativeinfo.cpp index ffed14e..c980a2a 100644 --- a/src/declarative/qml/qdeclarativeinfo.cpp +++ b/src/declarative/qml/qdeclarativeinfo.cpp @@ -78,8 +78,9 @@ QT_BEGIN_NAMESPACE \endcode */ -struct QDeclarativeInfoPrivate +class QDeclarativeInfoPrivate { +public: QDeclarativeInfoPrivate() : ref (1), object(0) {} int ref; -- cgit v0.12 From ac0b3eec9fbf25fb72d5368fa7ba31b58bb7ed30 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 6 May 2010 09:46:49 +1000 Subject: Doc: more clarification of cacheBuffer --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 3 +++ src/declarative/graphicsitems/qdeclarativelistview.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index ef6d3df..869826c 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1415,6 +1415,9 @@ void QDeclarativeGridView::setWrapEnabled(bool wrap) set to 40, then up to 2 delegates above and 2 delegates below the visible area may be retained. + Note that cacheBuffer is not a pixel buffer - it only maintains additional + instantiated delegates. + Setting this value can make scrolling the list smoother at the expense of additional memory usage. It is not a substitute for creating efficient delegates; the fewer elements in a delegate, the faster a view may be diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 8485071..0811278 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1848,6 +1848,9 @@ void QDeclarativeListView::setWrapEnabled(bool wrap) set to 40, then up to 2 delegates above and 2 delegates below the visible area may be retained. + Note that cacheBuffer is not a pixel buffer - it only maintains additional + instantiated delegates. + Setting this value can make scrolling the list smoother at the expense of additional memory usage. It is not a substitute for creating efficient delegates; the fewer elements in a delegate, the faster a view may be -- cgit v0.12 From c13db7e74887b648960161b5f4fa04ed8dfd3e64 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 6 May 2010 10:16:25 +1000 Subject: doc fixes --- doc/src/declarative/animation.qdoc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc index 88aca1b..6e98949 100644 --- a/doc/src/declarative/animation.qdoc +++ b/doc/src/declarative/animation.qdoc @@ -73,9 +73,9 @@ Rectangle { y: 0 SequentialAnimation on y { loops: Animation.Infinite - NumberAnimation { to: 200-img.height; easing.type: "OutBounce"; duration: 2000 } + NumberAnimation { to: 200-img.height; easing.type: Easing.OutBounce; duration: 2000 } PauseAnimation { duration: 1000 } - NumberAnimation { to: 0; easing.type: "OutQuad"; duration: 1000 } + NumberAnimation { to: 0; easing.type: Easing.OutQuad; duration: 1000 } } } } @@ -136,7 +136,7 @@ transitions: [ Transition { NumberAnimation { properties: "x,y" - easing.type: "OutBounce" + easing.type: Easing.OutBounce duration: 200 } } @@ -157,7 +157,7 @@ Transition { SequentialAnimation { NumberAnimation { duration: 1000 - easing.type: "OutBounce" + easing.type: Easing.OutBounce // animate myItem's x and y if they have changed in the state target: myItem properties: "x,y" @@ -199,7 +199,7 @@ Transition { ParallelAnimation { NumberAnimation { duration: 1000 - easing.type: "OutBounce" + easing.type: Easing.OutBounce targets: box1 properties: "x,y" } @@ -227,7 +227,7 @@ Rectangle { id: redRect color: "red" width: 100; height: 100 - Behavior on x { NumberAnimation { duration: 300; easing.type: "InOutQuad" } } + Behavior on x { NumberAnimation { duration: 300; easing.type: Easing.InOutQuad } } } \endqml -- cgit v0.12 From d6da01355fb436a04932131373579938dc4b7d8d Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 6 May 2010 10:49:57 +1000 Subject: Compile --- tests/auto/declarative/declarative.pro | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 9b3b3d0..b8e33cf 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -29,7 +29,6 @@ SUBDIRS += \ qdeclarativeitem \ # Cover qdeclarativelistview \ # Cover qdeclarativeloader \ # Cover - qdeclarativelayouts \ # Cover qdeclarativemousearea \ # Cover qdeclarativeparticles \ # Cover qdeclarativepathview \ # Cover -- cgit v0.12 From c628213c5b64b50e914d173d207f4fe64629d5e2 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 6 May 2010 10:50:04 +1000 Subject: Add QML_XHR_DUMP option --- src/declarative/qml/qdeclarativexmlhttprequest.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp index b7e1832..94205fe 100644 --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp @@ -46,6 +46,7 @@ #include "private/qdeclarativerefcount_p.h" #include "private/qdeclarativeengine_p.h" #include "private/qdeclarativeexpression_p.h" +#include "qdeclarativeglobal_p.h" #include #include @@ -94,6 +95,8 @@ QT_BEGIN_NAMESPACE +DEFINE_BOOL_CONFIG_OPTION(xhrDump, QML_XHR_DUMP); + class DocumentImpl; class NodeImpl { @@ -1131,6 +1134,14 @@ void QDeclarativeXMLHttpRequest::requestFromUrl(const QUrl &url) } } + if (xhrDump()) { + qWarning().nospace() << "XMLHttpRequest: " << qPrintable(m_method) << " " << qPrintable(url.toString()); + if (!m_data.isEmpty()) { + qWarning().nospace() << " " + << qPrintable(QString::fromUtf8(m_data)); + } + } + if (m_method == QLatin1String("GET")) m_network = networkAccessManager()->get(request); else if (m_method == QLatin1String("HEAD")) @@ -1264,6 +1275,16 @@ void QDeclarativeXMLHttpRequest::finished() if (cbv.isError()) printError(cbv); } m_responseEntityBody.append(m_network->readAll()); + + if (xhrDump()) { + qWarning().nospace() << "XMLHttpRequest: RESPONSE " << qPrintable(m_url.toString()); + if (!m_responseEntityBody.isEmpty()) { + qWarning().nospace() << " " + << qPrintable(QString::fromUtf8(m_responseEntityBody)); + } + } + + m_data.clear(); destroyNetwork(); if (m_state < Loading) { -- cgit v0.12 From 1eb430a1f1ddb3d88ec44294606b365e119b2e01 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 6 May 2010 10:55:13 +1000 Subject: Fix autotest --- tests/auto/declarative/examples/tst_examples.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index 058fda1..4f10a98 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -87,6 +87,7 @@ tst_examples::tst_examples() excludedDirs << "examples/declarative/gestures"; excludedDirs << "examples/declarative/imageprovider"; + excludedDirs << "examples/declarative/layouts/graphicsLayouts"; excludedDirs << "demos/declarative/minehunt"; excludedDirs << "doc/src/snippets/declarative/graphicswidgets"; -- cgit v0.12 From 4b0c60c6246fb7aacea3d74787a9e5a0cc507edd Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 6 May 2010 11:00:51 +1000 Subject: Add missing test file. --- .../qdeclarativevisualdatamodel/data/objectlist.qml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativevisualdatamodel/data/objectlist.qml diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/data/objectlist.qml b/tests/auto/declarative/qdeclarativevisualdatamodel/data/objectlist.qml new file mode 100644 index 0000000..f5198c9 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevisualdatamodel/data/objectlist.qml @@ -0,0 +1,16 @@ +import Qt 4.7 + +ListView { + width: 100 + height: 100 + anchors.fill: parent + model: myModel + delegate: Component { + Rectangle { + height: 25 + width: 100 + color: model.modelData.color + Text { objectName: "name"; text: name } + } + } +} -- cgit v0.12 From c16cc8c4d03cb062c5164295cad75509ec31feaf Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 6 May 2010 11:16:45 +1000 Subject: Use enum for drag.axis in doc and examples. --- demos/declarative/flickr/common/Slider.qml | 2 +- doc/src/snippets/declarative/drag.qml | 2 +- examples/declarative/dial/dial-example.qml | 2 +- examples/declarative/mousearea/mouse.qml | 2 +- examples/declarative/slideswitch/content/Switch.qml | 2 +- examples/declarative/velocity/Day.qml | 2 +- src/declarative/graphicsitems/qdeclarativemousearea.cpp | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/demos/declarative/flickr/common/Slider.qml b/demos/declarative/flickr/common/Slider.qml index 4da370e..76f6303 100644 --- a/demos/declarative/flickr/common/Slider.qml +++ b/demos/declarative/flickr/common/Slider.qml @@ -29,7 +29,7 @@ Item { MouseArea { anchors.fill: parent; drag.target: parent - drag.axis: "XAxis"; drag.minimumX: 2; drag.maximumX: slider.xMax+2 + drag.axis: Drag.XAxis; drag.minimumX: 2; drag.maximumX: slider.xMax+2 onPositionChanged: { value = (maximum - minimum) * (handle.x-2) / slider.xMax + minimum; } } } diff --git a/doc/src/snippets/declarative/drag.qml b/doc/src/snippets/declarative/drag.qml index 9465efb..79469e3 100644 --- a/doc/src/snippets/declarative/drag.qml +++ b/doc/src/snippets/declarative/drag.qml @@ -9,7 +9,7 @@ Rectangle { MouseArea { anchors.fill: parent drag.target: pic - drag.axis: "XAxis" + drag.axis: Drag.XAxis drag.minimumX: 0 drag.maximumX: blurtest.width-pic.width } diff --git a/examples/declarative/dial/dial-example.qml b/examples/declarative/dial/dial-example.qml index fd899a5..2e102b0 100644 --- a/examples/declarative/dial/dial-example.qml +++ b/examples/declarative/dial/dial-example.qml @@ -37,7 +37,7 @@ Rectangle { MouseArea { anchors.fill: parent - drag.target: parent; drag.axis: "XAxis"; drag.minimumX: 2; drag.maximumX: container.width - 32 + drag.target: parent; drag.axis: Drag.XAxis; drag.minimumX: 2; drag.maximumX: container.width - 32 } } } diff --git a/examples/declarative/mousearea/mouse.qml b/examples/declarative/mousearea/mouse.qml index 67302a8..06134b7 100644 --- a/examples/declarative/mousearea/mouse.qml +++ b/examples/declarative/mousearea/mouse.qml @@ -33,7 +33,7 @@ Rectangle { MouseArea { anchors.fill: parent drag.target: parent - drag.axis: "XAxis" + drag.axis: Drag.XAxis drag.minimumX: 0 drag.maximumX: 150 diff --git a/examples/declarative/slideswitch/content/Switch.qml b/examples/declarative/slideswitch/content/Switch.qml index 1aa7696..526a171 100644 --- a/examples/declarative/slideswitch/content/Switch.qml +++ b/examples/declarative/slideswitch/content/Switch.qml @@ -45,7 +45,7 @@ Item { MouseArea { anchors.fill: parent - drag.target: knob; drag.axis: "XAxis"; drag.minimumX: 1; drag.maximumX: 78 + drag.target: knob; drag.axis: Drag.XAxis; drag.minimumX: 1; drag.maximumX: 78 onClicked: toggle() onReleased: dorelease() } diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 433295b..350c1c4 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -61,7 +61,7 @@ Component { id: mouse anchors.fill: parent drag.target: stickyPage - drag.axis: "XandYAxis" + drag.axis: Drag.XandYAxis drag.minimumY: 0 drag.maximumY: page.height - 80 drag.minimumX: 100 diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index d178107..c5a995e 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -746,7 +746,7 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag() /*! \qmlproperty Item MouseArea::drag.target \qmlproperty bool MouseArea::drag.active - \qmlproperty Axis MouseArea::drag.axis + \qmlproperty enumeration MouseArea::drag.axis \qmlproperty real MouseArea::drag.minimumX \qmlproperty real MouseArea::drag.maximumX \qmlproperty real MouseArea::drag.minimumY @@ -757,7 +757,7 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag() \list \i \c target specifies the item to drag. \i \c active specifies if the target item is being currently dragged. - \i \c axis specifies whether dragging can be done horizontally (XAxis), vertically (YAxis), or both (XandYAxis) + \i \c axis specifies whether dragging can be done horizontally (Drag.XAxis), vertically (Drag.YAxis), or both (Drag.XandYAxis) \i the minimum and maximum properties limit how far the target can be dragged along the corresponding axes. \endlist -- cgit v0.12 From 3e4116ff5337d41466904b2e381dfa74267264a8 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 6 May 2010 12:42:36 +1000 Subject: Cleanup --- examples/declarative/animations/color-animation.qml | 5 ++--- examples/declarative/animations/property-animation.qml | 1 - examples/declarative/connections/connections-example.qml | 1 - examples/declarative/dynamic/qml/PerspectiveItem.qml | 3 +-- examples/declarative/listview/dynamic.qml | 16 +++++++--------- examples/declarative/parallax/qml/ParallaxView.qml | 15 +++++++-------- examples/declarative/parallax/qml/Smiley.qml | 3 +-- 7 files changed, 18 insertions(+), 26 deletions(-) diff --git a/examples/declarative/animations/color-animation.qml b/examples/declarative/animations/color-animation.qml index 3616a31..61737e9 100644 --- a/examples/declarative/animations/color-animation.qml +++ b/examples/declarative/animations/color-animation.qml @@ -31,15 +31,14 @@ Item { // the sun, moon, and stars Item { width: parent.width; height: 2 * parent.height - transformOrigin: Item.Center NumberAnimation on rotation { from: 0; to: 360; duration: 10000; loops: Animation.Infinite } Image { source: "images/sun.png"; y: 10; anchors.horizontalCenter: parent.horizontalCenter - transformOrigin: Item.Center; rotation: -3 * parent.rotation + rotation: -3 * parent.rotation } Image { source: "images/moon.png"; y: parent.height - 74; anchors.horizontalCenter: parent.horizontalCenter - transformOrigin: Item.Center; rotation: -parent.rotation + rotation: -parent.rotation } Particles { x: 0; y: parent.height/2; width: parent.width; height: parent.height/2 diff --git a/examples/declarative/animations/property-animation.qml b/examples/declarative/animations/property-animation.qml index 6360511..87ac8ec 100644 --- a/examples/declarative/animations/property-animation.qml +++ b/examples/declarative/animations/property-animation.qml @@ -26,7 +26,6 @@ Item { Image { anchors.horizontalCenter: parent.horizontalCenter source: "images/shadow.png"; y: smiley.minHeight + 58 - transformOrigin: Item.Center // The scale property depends on the y position of the smiley face. scale: smiley.y * 0.5 / (smiley.minHeight - smiley.maxHeight) diff --git a/examples/declarative/connections/connections-example.qml b/examples/declarative/connections/connections-example.qml index 1dd10ab..e65a280 100644 --- a/examples/declarative/connections/connections-example.qml +++ b/examples/declarative/connections/connections-example.qml @@ -13,7 +13,6 @@ Rectangle { id: image source: "content/bg1.jpg" anchors.centerIn: parent - transformOrigin: Item.Center rotation: window.angle Behavior on rotation { diff --git a/examples/declarative/dynamic/qml/PerspectiveItem.qml b/examples/declarative/dynamic/qml/PerspectiveItem.qml index 3cbe64a..6d763c3 100644 --- a/examples/declarative/dynamic/qml/PerspectiveItem.qml +++ b/examples/declarative/dynamic/qml/PerspectiveItem.qml @@ -4,13 +4,12 @@ Image { id: tree property bool created: false property double scaleFactor: Math.max((y+height-250)*0.01, 0.3) - property double scaledBottom: y + (height+height*scaleFactor)/2 + property double scaledBottom: y + (height+height*scaleFactor)/2 property bool onLand: scaledBottom > window.height/2 property string image //Needed for compatibility with GenericItem opacity: onLand ? 1 : 0.25 onCreatedChanged: if (created && !onLand) { tree.destroy() } else { z = scaledBottom } scale: scaleFactor - transformOrigin: "Center" source: image; smooth: true onYChanged: z = scaledBottom } diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index 236a9c5..952f6a7 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -56,7 +56,7 @@ Rectangle { Item { width: container.width; height: 55 - + Column { id: moveButtons x: 5; width: childrenRect.width; anchors.verticalCenter: parent.verticalCenter @@ -84,7 +84,7 @@ Rectangle { spacing: 5 Repeater { model: attributes - Component { + Component { Text { text: description; color: "White" } } } @@ -95,13 +95,12 @@ Rectangle { id: itemButtons anchors { right: removeButton.left; rightMargin: 35; verticalCenter: parent.verticalCenter } - width: childrenRect.width + width: childrenRect.width spacing: 10 Image { source: "content/pics/list-add.png" scale: clickUp.isPressed ? 0.9 : 1 - transformOrigin: Item.Center ClickAutoRepeating { id: clickUp @@ -115,9 +114,8 @@ Rectangle { Image { source: "content/pics/list-remove.png" scale: clickDown.isPressed ? 0.9 : 1 - transformOrigin: Item.Center - ClickAutoRepeating { + ClickAutoRepeating { id: clickDown anchors.fill: parent onClicked: fruitModel.setProperty(index, "cost", Math.max(0,cost-0.25)) @@ -158,7 +156,7 @@ Rectangle { } transitions: Transition { NumberAnimation { properties: "opacity"; duration: 400 } - } + } } Row { @@ -198,10 +196,10 @@ Rectangle { } } - Image { + Image { source: "content/pics/archive-remove.png" - MouseArea { + MouseArea { anchors.fill: parent onClicked: fruitModel.clear() } diff --git a/examples/declarative/parallax/qml/ParallaxView.qml b/examples/declarative/parallax/qml/ParallaxView.qml index 4b38d45..e869a21 100644 --- a/examples/declarative/parallax/qml/ParallaxView.qml +++ b/examples/declarative/parallax/qml/ParallaxView.qml @@ -18,9 +18,9 @@ Item { id: list currentIndex: root.currentIndex - onCurrentIndexChanged: root.currentIndex = currentIndex + onCurrentIndexChanged: root.currentIndex = currentIndex - orientation: "Horizontal" + orientation: Qt.Horizontal boundsBehavior: Flickable.DragOverBounds anchors.fill: parent model: VisualItemModel { id: visualModel } @@ -45,10 +45,10 @@ Item { anchors.horizontalCenter: parent.horizontalCenter width: Math.min(count * 50, parent.width - 20) interactive: width == parent.width - 20 - orientation: "Horizontal" + orientation: Qt.Horizontal - delegate: Item { - width: 50; height: 50 + delegate: Item { + width: 50; height: 50 id: delegateRoot Image { @@ -56,7 +56,6 @@ Item { source: modelData.icon smooth: true scale: 0.8 - transformOrigin: "Center" } MouseArea { @@ -64,10 +63,10 @@ Item { onClicked: { root.currentIndex = index } } - states: State { + states: State { name: "Selected" when: delegateRoot.ListView.isCurrentItem == true - PropertyChanges { + PropertyChanges { target: image scale: 1 y: -5 diff --git a/examples/declarative/parallax/qml/Smiley.qml b/examples/declarative/parallax/qml/Smiley.qml index cfa4fed..662addc 100644 --- a/examples/declarative/parallax/qml/Smiley.qml +++ b/examples/declarative/parallax/qml/Smiley.qml @@ -8,7 +8,6 @@ Item { Image { anchors.horizontalCenter: parent.horizontalCenter source: "../pics/shadow.png"; y: smiley.minHeight + 58 - transformOrigin: Item.Center // The scale property depends on the y position of the smiley face. scale: smiley.y * 0.5 / (smiley.minHeight - smiley.maxHeight) @@ -32,7 +31,7 @@ Item { from: smiley.minHeight; to: smiley.maxHeight easing.type: Easing.OutExpo; duration: 300 } - + // Then move back to minHeight in 1 second, using the OutBounce easing function NumberAnimation { from: smiley.maxHeight; to: smiley.minHeight -- cgit v0.12 From e909d9a200c7a75dc23542f4603ce86fdc135bab Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 6 May 2010 13:11:48 +1000 Subject: Cleanup --- demos/declarative/snake/snake.qml | 6 +++--- demos/declarative/webbrowser/content/FlickableWebView.qml | 6 +++--- doc/src/declarative/elements.qdoc | 1 + examples/declarative/fonts/fonts.qml | 6 +++--- examples/declarative/listview/sections.qml | 2 +- examples/declarative/webview/alerts.qml | 2 +- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/demos/declarative/snake/snake.qml b/demos/declarative/snake/snake.qml index 47bced4..bc4a974 100644 --- a/demos/declarative/snake/snake.qml +++ b/demos/declarative/snake/snake.qml @@ -60,7 +60,7 @@ Rectangle { Image { id: title source: "content/pics/snake.jpg" - fillMode: "PreserveAspectCrop" + fillMode: Image.PreserveAspectCrop anchors.fill: parent anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter @@ -69,7 +69,7 @@ Rectangle { Text { color: "white" font.pointSize: 24 - horizontalAlignment: "AlignHCenter" + horizontalAlignment: Text.AlignHCenter text: "Last Score:\t" + lastScore + "\nHighscore:\t" + highScores.topScore; anchors.horizontalCenter: parent.horizontalCenter anchors.bottom: parent.bottom @@ -78,7 +78,7 @@ Rectangle { } source: "content/pics/background.png" - fillMode: "PreserveAspectCrop" + fillMode: Image.PreserveAspectCrop anchors.left: parent.left anchors.right: parent.right diff --git a/demos/declarative/webbrowser/content/FlickableWebView.qml b/demos/declarative/webbrowser/content/FlickableWebView.qml index 46f45e0..50ea97d 100644 --- a/demos/declarative/webbrowser/content/FlickableWebView.qml +++ b/demos/declarative/webbrowser/content/FlickableWebView.qml @@ -105,14 +105,14 @@ Flickable { property: "scale" from: 1 to: 0 // set before calling - easing.type: "Linear" + easing.type: Easing.Linear duration: 200 } NumberAnimation { id: flickVX target: flickable property: "contentX" - easing.type: "Linear" + easing.type: Easing.Linear duration: 200 from: 0 // set before calling to: 0 // set before calling @@ -121,7 +121,7 @@ Flickable { id: flickVY target: flickable property: "contentY" - easing.type: "Linear" + easing.type: Easing.Linear duration: 200 from: 0 // set before calling to: 0 // set before calling diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 79fe909..1dbc51b 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -142,6 +142,7 @@ The following table lists the QML elements provided by the \l {QtDeclarative}{Qt \o \l Loader \o \l Repeater \o \l SystemPalette +\o \l FontLoader \o \l LayoutItem \endlist diff --git a/examples/declarative/fonts/fonts.qml b/examples/declarative/fonts/fonts.qml index ae31b03..f3eac48 100644 --- a/examples/declarative/fonts/fonts.qml +++ b/examples/declarative/fonts/fonts.qml @@ -51,9 +51,9 @@ Rectangle { } Text { text: { - if (webFont.status == 1) myText - else if (webFont.status == 2) "Loading..." - else if (webFont.status == 3) "Error loading font" + if (webFont.status == FontLoader.Ready) myText + else if (webFont.status == FontLoader.Loading) "Loading..." + else if (webFont.status == FontLoader.Error) "Error loading font" } color: "lightsteelblue" width: parent.width diff --git a/examples/declarative/listview/sections.qml b/examples/declarative/listview/sections.qml index 0a81f63..21f9f03 100644 --- a/examples/declarative/listview/sections.qml +++ b/examples/declarative/listview/sections.qml @@ -61,7 +61,7 @@ Rectangle { height: 20 Text { x: 2; height: parent.height - verticalAlignment: 'AlignVCenter' + verticalAlignment: Text.AlignVCenter text: section font.bold: true } diff --git a/examples/declarative/webview/alerts.qml b/examples/declarative/webview/alerts.qml index 6a5a0d2..7684c3e 100644 --- a/examples/declarative/webview/alerts.qml +++ b/examples/declarative/webview/alerts.qml @@ -52,7 +52,7 @@ WebView { font.pixelSize: 20 width: webView.width*0.75 wrapMode: Text.WordWrap - horizontalAlignment: "AlignHCenter" + horizontalAlignment: Text.AlignHCenter } } } -- cgit v0.12 From 2dfa4fbcdc901b8cdd8df0087ecf5e3fa2523603 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 6 May 2010 14:14:36 +1000 Subject: More cleanup --- demos/declarative/flickr/mobile/GridDelegate.qml | 2 +- demos/declarative/flickr/mobile/ImageDetails.qml | 12 ++++++++---- demos/declarative/twitter/TwitterCore/FatDelegate.qml | 2 +- demos/declarative/twitter/TwitterCore/HomeTitleBar.qml | 2 +- examples/declarative/listview/dynamic.qml | 2 +- examples/declarative/listview/itemlist.qml | 4 ++-- examples/declarative/listview/listview-example.qml | 4 ++-- examples/declarative/scrollbar/ScrollBar.qml | 16 ++++++++-------- examples/declarative/scrollbar/display.qml | 4 ++-- 9 files changed, 26 insertions(+), 22 deletions(-) diff --git a/demos/declarative/flickr/mobile/GridDelegate.qml b/demos/declarative/flickr/mobile/GridDelegate.qml index eccdc34..df608bc 100644 --- a/demos/declarative/flickr/mobile/GridDelegate.qml +++ b/demos/declarative/flickr/mobile/GridDelegate.qml @@ -38,7 +38,7 @@ states: [ State { - name: "Show"; when: thumb.status == 1 + name: "Show"; when: thumb.status == Image.Ready PropertyChanges { target: scaleMe; scale: 1 } }, State { diff --git a/demos/declarative/flickr/mobile/ImageDetails.qml b/demos/declarative/flickr/mobile/ImageDetails.qml index 310c9df..caf1571 100644 --- a/demos/declarative/flickr/mobile/ImageDetails.qml +++ b/demos/declarative/flickr/mobile/ImageDetails.qml @@ -54,7 +54,11 @@ Flipable { Rectangle { anchors.fill: parent; color: "black"; opacity: 0.4 } - Common.Progress { anchors.centerIn: parent; width: 200; height: 18; progress: bigImage.progress; visible: bigImage.status!=1 } + Common.Progress { + anchors.centerIn: parent; width: 200; height: 18 + progress: bigImage.progress; visible: bigImage.status != Image.Ready + } + Flickable { id: flickable; anchors.fill: parent; clip: true contentWidth: imageContainer.width; contentHeight: imageContainer.height @@ -69,7 +73,7 @@ Flipable { anchors.centerIn: parent; smooth: !flickable.moving onStatusChanged : { // Default scale shows the entire image. - if (status == 1 && width != 0) { + if (status == Image.Ready && width != 0) { slider.minimum = Math.min(flickable.width / width, flickable.height / height); prevScale = Math.min(slider.minimum, 1); slider.value = prevScale; @@ -81,12 +85,12 @@ Flipable { Text { text: "Image Unavailable" - visible: bigImage.status == 'Error' + visible: bigImage.status == Image.Error anchors.centerIn: parent; color: "white"; font.bold: true } Common.Slider { - id: slider; visible: { bigImage.status == 1 && maximum > minimum } + id: slider; visible: { bigImage.status == Image.Ready && maximum > minimum } anchors { bottom: parent.bottom; bottomMargin: 65 left: parent.left; leftMargin: 25 diff --git a/demos/declarative/twitter/TwitterCore/FatDelegate.qml b/demos/declarative/twitter/TwitterCore/FatDelegate.qml index 62ee11a..72e5ecc 100644 --- a/demos/declarative/twitter/TwitterCore/FatDelegate.qml +++ b/demos/declarative/twitter/TwitterCore/FatDelegate.qml @@ -27,7 +27,7 @@ Component { id: whiteRect; x: 6; width: 50; height: 50; color: "white"; smooth: true anchors.verticalCenter: parent.verticalCenter - Loading { x: 1; y: 1; width: 48; height: 48; visible: realImage.status != 1 } + Loading { x: 1; y: 1; width: 48; height: 48; visible: realImage.status != Image.Ready } Image { id: realImage; source: userImage; x: 1; y: 1; width:48; height:48 } } Text { id:txt; y:4; x: 56 diff --git a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml index 11aa74f..26ad1a9 100644 --- a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml +++ b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml @@ -37,7 +37,7 @@ Item { UserModel { user: rssModel.authName; id: userModel } Component { id: imgDelegate; Item { - Loading { width:48; height:48; visible: realImage.status != 1 } + Loading { width:48; height:48; visible: realImage.status != Image.Ready } Image { source: image; width:48; height:48; id: realImage } } } diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index 952f6a7..9b05ad5 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -145,7 +145,7 @@ Rectangle { width: 8; height: view.height; anchors.right: view.right opacity: 0 - orientation: "Vertical" + orientation: Qt.Vertical position: view.visibleArea.yPosition pageSize: view.visibleArea.heightRatio diff --git a/examples/declarative/listview/itemlist.qml b/examples/declarative/listview/itemlist.qml index e387f28..b73b3a3 100644 --- a/examples/declarative/listview/itemlist.qml +++ b/examples/declarative/listview/itemlist.qml @@ -33,7 +33,7 @@ Rectangle { anchors { fill: parent; bottomMargin: 30 } model: itemModel preferredHighlightBegin: 0; preferredHighlightEnd: 0 - highlightRangeMode: "StrictlyEnforceRange" + highlightRangeMode: ListView.StrictlyEnforceRange orientation: ListView.Horizontal snapMode: ListView.SnapOneItem; flickDeceleration: 2000 } @@ -55,7 +55,7 @@ Rectangle { radius: 3 color: view.currentIndex == index ? "blue" : "white" - MouseArea { + MouseArea { width: 20; height: 20 anchors.centerIn: parent onClicked: view.currentIndex = index diff --git a/examples/declarative/listview/listview-example.qml b/examples/declarative/listview/listview-example.qml index 6feedf6..2e8cdda 100644 --- a/examples/declarative/listview/listview-example.qml +++ b/examples/declarative/listview/listview-example.qml @@ -75,7 +75,7 @@ Rectangle { highlight: petHighlight currentIndex: list1.currentIndex preferredHighlightBegin: 80; preferredHighlightEnd: 220 - highlightRangeMode: "ApplyRange" + highlightRangeMode: ListView.ApplyRange } ListView { @@ -87,7 +87,7 @@ Rectangle { highlight: Rectangle { color: "lightsteelblue" } currentIndex: list1.currentIndex preferredHighlightBegin: 125; preferredHighlightEnd: 125 - highlightRangeMode: "StrictlyEnforceRange" + highlightRangeMode: ListView.StrictlyEnforceRange flickDeceleration: 1000 } } diff --git a/examples/declarative/scrollbar/ScrollBar.qml b/examples/declarative/scrollbar/ScrollBar.qml index 5433156..c628a20 100644 --- a/examples/declarative/scrollbar/ScrollBar.qml +++ b/examples/declarative/scrollbar/ScrollBar.qml @@ -7,26 +7,26 @@ Item { // position and pageSize are in the range 0.0 - 1.0. They are relative to the // height of the page, i.e. a pageSize of 0.5 means that you can see 50% // of the height of the view. - // orientation can be either 'Vertical' or 'Horizontal' + // orientation can be either Qt.Vertical or Qt.Horizontal property real position property real pageSize - property variant orientation : "Vertical" + property variant orientation : Qt.Vertical // A light, semi-transparent background Rectangle { id: background anchors.fill: parent - radius: orientation == 'Vertical' ? (width/2 - 1) : (height/2 - 1) + radius: orientation == Qt.Vertical ? (width/2 - 1) : (height/2 - 1) color: "white" opacity: 0.3 } // Size the bar to the required size, depending upon the orientation. Rectangle { - x: orientation == 'Vertical' ? 1 : (scrollBar.position * (scrollBar.width-2) + 1) - y: orientation == 'Vertical' ? (scrollBar.position * (scrollBar.height-2) + 1) : 1 - width: orientation == 'Vertical' ? (parent.width-2) : (scrollBar.pageSize * (scrollBar.width-2)) - height: orientation == 'Vertical' ? (scrollBar.pageSize * (scrollBar.height-2)) : (parent.height-2) - radius: orientation == 'Vertical' ? (width/2 - 1) : (height/2 - 1) + x: orientation == Qt.Vertical ? 1 : (scrollBar.position * (scrollBar.width-2) + 1) + y: orientation == Qt.Vertical ? (scrollBar.position * (scrollBar.height-2) + 1) : 1 + width: orientation == Qt.Vertical ? (parent.width-2) : (scrollBar.pageSize * (scrollBar.width-2)) + height: orientation == Qt.Vertical ? (scrollBar.pageSize * (scrollBar.height-2)) : (parent.height-2) + radius: orientation == Qt.Vertical ? (width/2 - 1) : (height/2 - 1) color: "black" opacity: 0.7 } diff --git a/examples/declarative/scrollbar/display.qml b/examples/declarative/scrollbar/display.qml index cb1da16..b8a5e36 100644 --- a/examples/declarative/scrollbar/display.qml +++ b/examples/declarative/scrollbar/display.qml @@ -37,7 +37,7 @@ Rectangle { width: 12; height: view.height-12 anchors.right: view.right opacity: 0 - orientation: "Vertical" + orientation: Qt.Vertical position: view.visibleArea.yPosition pageSize: view.visibleArea.heightRatio } @@ -47,7 +47,7 @@ Rectangle { width: view.width-12; height: 12 anchors.bottom: view.bottom opacity: 0 - orientation: "Horizontal" + orientation: Qt.Horizontal position: view.visibleArea.xPosition pageSize: view.visibleArea.widthRatio } -- cgit v0.12 From f95a53ec1f88f819424aa3e894f91c1b875fd749 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 6 May 2010 14:29:27 +1000 Subject: Make sure to call base class implementation. --- src/declarative/graphicsitems/qdeclarativepainteditem.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp index 6430fae..ce9b69f 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp +++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp @@ -210,6 +210,7 @@ void QDeclarativePaintedItem::geometryChanged(const QRectF &newGeometry, if (newGeometry.width() != oldGeometry.width() || newGeometry.height() != oldGeometry.height()) clearCache(); + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); } QVariant QDeclarativePaintedItem::itemChange(GraphicsItemChange change, -- cgit v0.12 From 3323eb86586240d8ddcde985d052478809a6bffb Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 6 May 2010 15:01:36 +1000 Subject: TextInput echoMode doc. --- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index a1fa8c6..9ae4e1a 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -706,14 +706,15 @@ bool QDeclarativeTextInput::hasAcceptableInput() const } /*! - \qmlproperty TextInput.EchoMode TextInput::echoMode + \qmlproperty enumeration TextInput::echoMode Specifies how the text should be displayed in the TextInput. - The default is Normal, which displays the text as it is. Other values - are Password, which displays asterixes instead of characters, NoEcho, - which displays nothing, and PasswordEchoOnEdit, which displays all but the - current character as asterixes. - + \list + \o TextInput.Normal - Displays the text as it is. (Default) + \o TextInput.Password - Displays asterixes instead of characters. + \o TextInput.NoEcho - Displays nothing. + \o TextInput.PasswordEchoOnEdit - Displays all but the current character as asterixes. + \endlist */ QDeclarativeTextInput::EchoMode QDeclarativeTextInput::echoMode() const { @@ -1084,7 +1085,7 @@ void QDeclarativeTextInput::setPasswordCharacter(const QString &str) \qmlproperty string TextInput::displayText 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 -- cgit v0.12 From d0a56df355cebc60176c3f449c1aee7bafd5562b Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 6 May 2010 15:52:38 +1000 Subject: qdoc fixes --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 4 ++-- src/declarative/graphicsitems/qdeclarativeitem.cpp | 2 +- src/declarative/graphicsitems/qdeclarativelistview.cpp | 4 ++-- src/declarative/graphicsitems/qdeclarativepathview.cpp | 4 ++-- src/declarative/graphicsitems/qdeclarativetextedit.cpp | 2 +- .../graphicsitems/qdeclarativevisualitemmodel.cpp | 2 +- src/declarative/util/qdeclarativeanimation.cpp | 12 ++++++------ 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 869826c..0094213 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1054,7 +1054,7 @@ void QDeclarativeGridView::setModel(const QVariant &model) } /*! - \qmlproperty component GridView::delegate + \qmlproperty Component GridView::delegate The delegate provides a template defining each item instantiated by the view. The index is exposed as an accessible \c index property. Properties of the @@ -1172,7 +1172,7 @@ int QDeclarativeGridView::count() const } /*! - \qmlproperty component GridView::highlight + \qmlproperty Component GridView::highlight This property holds the component to use as the highlight. An instance of the highlight component will be created for each view. diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 0395766..9433ba0 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -720,7 +720,7 @@ void QDeclarativeKeyNavigationAttached::keyReleased(QKeyEvent *event) */ /*! - \qmlproperty List Keys::forwardTo + \qmlproperty list Keys::forwardTo This property provides a way to forward key presses, key releases, and keyboard input coming from input methods to other items. This can be useful when you want diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 0811278..cff345e 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1488,7 +1488,7 @@ void QDeclarativeListView::setModel(const QVariant &model) } /*! - \qmlproperty component ListView::delegate + \qmlproperty Component ListView::delegate The delegate provides a template defining each item instantiated by the view. The index is exposed as an accessible \c index property. Properties of the @@ -1608,7 +1608,7 @@ int QDeclarativeListView::count() const } /*! - \qmlproperty component ListView::highlight + \qmlproperty Component ListView::highlight This property holds the component to use as the highlight. An instance of the highlight component will be created for each list. diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 5c3a3c0..040fc98 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -561,7 +561,7 @@ void QDeclarativePathViewPrivate::setOffset(qreal o) } /*! - \qmlproperty component PathView::highlight + \qmlproperty Component PathView::highlight This property holds the component to use as the highlight. An instance of the highlight component will be created for each view. @@ -790,7 +790,7 @@ void QDeclarativePathView::setInteractive(bool interactive) } /*! - \qmlproperty component PathView::delegate + \qmlproperty Component PathView::delegate The delegate provides a template defining each item instantiated by the view. The index is exposed as an accessible \c index property. Properties of the diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index d0ee2ee..d095dbe 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -728,7 +728,7 @@ void QDeclarativeTextEdit::setPersistentSelection(bool on) } /* - \qmlproperty number TextEdit::textMargin + \qmlproperty real TextEdit::textMargin The margin, in pixels, around the text in the TextEdit. */ diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index f01d4c2..306443b 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -759,7 +759,7 @@ void QDeclarativeVisualDataModel::setModel(const QVariant &model) } /*! - \qmlproperty component VisualDataModel::delegate + \qmlproperty Component VisualDataModel::delegate The delegate provides a template defining each item instantiated by a view. The index is exposed as an accessible \c index property. Properties of the diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 206621b..0f7c946 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -755,7 +755,7 @@ void QDeclarativeScriptAction::setScript(const QDeclarativeScriptString &script) } /*! - \qmlproperty QString ScriptAction::scriptName + \qmlproperty string ScriptAction::scriptName This property holds the the name of the StateChangeScript to run. This property is only valid when ScriptAction is used as part of a transition. @@ -791,7 +791,7 @@ void QDeclarativeScriptActionPrivate::execute() if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) expr.setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); expr.evaluate(); - if (expr.hasError()) + if (expr.hasError()) qmlInfo(q) << expr.error(); } } @@ -844,7 +844,7 @@ QAbstractAnimation *QDeclarativeScriptAction::qtAnimation() The PropertyAction is immediate - the target property is not animated to the selected value in any way. - + \sa QtDeclarative */ /*! @@ -2347,7 +2347,7 @@ QDeclarativeParentAnimation::~QDeclarativeParentAnimation() } /*! - \qmlproperty item ParentAnimation::target + \qmlproperty Item ParentAnimation::target The item to reparent. When used in a transition, if no target is specified all @@ -2370,7 +2370,7 @@ void QDeclarativeParentAnimation::setTarget(QDeclarativeItem *target) } /*! - \qmlproperty item ParentAnimation::newParent + \qmlproperty Item ParentAnimation::newParent The new parent to animate to. If not set, then the parent defined in the end state of the transition. @@ -2392,7 +2392,7 @@ void QDeclarativeParentAnimation::setNewParent(QDeclarativeItem *newParent) } /*! - \qmlproperty item ParentAnimation::via + \qmlproperty Item ParentAnimation::via The item to reparent via. This provides a way to do an unclipped animation when both the old parent and new parent are clipped -- cgit v0.12 From bf965a3b74a10636a63f72d72ad41e169a9851e3 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 6 May 2010 16:16:08 +1000 Subject: Avoid warnings as delegates with bindings to parent are created and destroyed. Task-number: QTBUG-10359 --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 4 +++- src/declarative/graphicsitems/qdeclarativelistview.cpp | 4 +++- .../graphicsitems/qdeclarativevisualitemmodel.cpp | 8 ++++++++ src/declarative/qml/qdeclarativecontext.cpp | 17 +++++++++++------ src/declarative/qml/qdeclarativecontext_p.h | 1 + src/declarative/qml/qdeclarativeengine.cpp | 4 +++- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 869826c..75b9d3c 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -378,9 +378,11 @@ FxGridItem *QDeclarativeGridViewPrivate::createItem(int modelIndex) if (model->completePending()) { // complete listItem->item->setZValue(1); + listItem->item->setParentItem(q->viewport()); model->completeItem(); + } else { + listItem->item->setParentItem(q->viewport()); } - listItem->item->setParentItem(q->viewport()); unrequestedItems.remove(listItem->item); } requestedIndex = -1; diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 0811278..064a33f 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -573,9 +573,11 @@ FxListItem *QDeclarativeListViewPrivate::createItem(int modelIndex) if (model->completePending()) { // complete listItem->item->setZValue(1); + listItem->item->setParentItem(q->viewport()); model->completeItem(); + } else { + listItem->item->setParentItem(q->viewport()); } - listItem->item->setParentItem(q->viewport()); QDeclarativeItemPrivate *itemPrivate = static_cast(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); if (sectionCriteria && sectionCriteria->delegate()) { diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index f01d4c2..c6a6b81 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -44,6 +44,7 @@ #include "qdeclarativeitem.h" #include +#include #include #include #include @@ -963,6 +964,13 @@ QDeclarativeVisualDataModel::ReleaseFlags QDeclarativeVisualDataModel::release(Q } if (d->m_cache.releaseItem(obj)) { + // Remove any bindings to avoid warnings due to parent change. + QObjectPrivate *p = QObjectPrivate::get(obj); + Q_ASSERT(p->declarativeData); + QDeclarativeData *d = static_cast(p->declarativeData); + if (d->ownContext && d->context) + d->context->clearExpressions(); + if (inPackage) { emit destroyingPackage(qobject_cast(obj)); } else { diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index ae4223e..b61b8cb 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -528,13 +528,8 @@ void QDeclarativeContextData::invalidate() parent = 0; } -void QDeclarativeContextData::destroy() +void QDeclarativeContextData::clearExpressions() { - if (linkedContext) - linkedContext->destroy(); - - if (engine) invalidate(); - QDeclarativeAbstractExpression *expression = expressions; while (expression) { QDeclarativeAbstractExpression *nextExpression = expression->m_nextExpression; @@ -546,6 +541,16 @@ void QDeclarativeContextData::destroy() expression = nextExpression; } expressions = 0; +} + +void QDeclarativeContextData::destroy() +{ + if (linkedContext) + linkedContext->destroy(); + + if (engine) invalidate(); + + clearExpressions(); while (contextObjects) { QDeclarativeData *co = contextObjects; diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h index c7fb099..6b6cd0a 100644 --- a/src/declarative/qml/qdeclarativecontext_p.h +++ b/src/declarative/qml/qdeclarativecontext_p.h @@ -113,6 +113,7 @@ class QDeclarativeContextData public: QDeclarativeContextData(); QDeclarativeContextData(QDeclarativeContext *); + void clearExpressions(); void destroy(); void invalidate(); diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index cc6c5fe..9f5cafe 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -329,8 +329,10 @@ void QDeclarativePrivate::qdeclarativeelement_destructor(QObject *o) QObjectPrivate *p = QObjectPrivate::get(o); Q_ASSERT(p->declarativeData); QDeclarativeData *d = static_cast(p->declarativeData); - if (d->ownContext) + if (d->ownContext && d->context) { d->context->destroy(); + d->context = 0; + } } void QDeclarativeData::destroyed(QAbstractDeclarativeData *d, QObject *o) -- cgit v0.12 From d1ab59da5de38ce0df0e6b9961fc5bf6580e5607 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 6 May 2010 17:04:55 +1000 Subject: qdoc fixes. --- doc/src/declarative/elements.qdoc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 1dbc51b..574a187 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -120,11 +120,22 @@ The following table lists the QML elements provided by the \l {QtDeclarative}{Qt \list \o \l Item \o \l Rectangle + \list + \o \l Gradient + \list + \o \l GradientStop + \endlist + \endlist \o \l Image \o \l BorderImage \o \l AnimatedImage \o \l Text \o \l TextInput + \list + \o \l IntValidator + \o \l DoubleValidator + \o \l RegExpValidator + \endlist \o \l TextEdit \endlist -- cgit v0.12 From a0ff96a8fd1cbf1206afd12e0062949fa035f64f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 6 May 2010 17:42:53 +1000 Subject: Call QDeclarativeItem::geometryChanged() base implementation --- src/declarative/graphicsitems/qdeclarativepainteditem.cpp | 2 ++ .../qdeclarativetextedit/data/geometrySignals.qml | 12 ++++++++++++ .../qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 13 ++++++++++++- .../qdeclarativetextinput/data/geometrySignals.qml | 12 ++++++++++++ .../qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 11 +++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/geometrySignals.qml create mode 100644 tests/auto/declarative/qdeclarativetextinput/data/geometrySignals.qml diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp index 6430fae..c4f0b86 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp +++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp @@ -210,6 +210,8 @@ void QDeclarativePaintedItem::geometryChanged(const QRectF &newGeometry, if (newGeometry.width() != oldGeometry.width() || newGeometry.height() != oldGeometry.height()) clearCache(); + + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); } QVariant QDeclarativePaintedItem::itemChange(GraphicsItemChange change, diff --git a/tests/auto/declarative/qdeclarativetextedit/data/geometrySignals.qml b/tests/auto/declarative/qdeclarativetextedit/data/geometrySignals.qml new file mode 100644 index 0000000..b39ba5b --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/geometrySignals.qml @@ -0,0 +1,12 @@ +import Qt 4.7 + +Item { + width: 400; height: 500; + property int bindingWidth: text.width + property int bindingHeight: text.height + + TextInput { + id: text + anchors.fill: parent + } +} diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 3307b7c..8cc0e3f 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -84,7 +84,7 @@ private slots: void navigation(); void readOnly(); void sendRequestSoftwareInputPanelEvent(); - + void geometrySignals(); private: void simulateKey(QDeclarativeView *, int key); QDeclarativeView *createView(const QString &filename); @@ -808,6 +808,17 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QApplication::processEvents(); QCOMPARE(ic.softwareInputPanelEventReceived, true); } + +void tst_qdeclarativetextedit::geometrySignals() +{ + QDeclarativeComponent component(&engine, SRCDIR "/data/geometrySignals.qml"); + QObject *o = component.create(); + QVERIFY(o); + QCOMPARE(o->property("bindingWidth").toInt(), 400); + QCOMPARE(o->property("bindingHeight").toInt(), 500); + delete o; +} + QTEST_MAIN(tst_qdeclarativetextedit) #include "tst_qdeclarativetextedit.moc" diff --git a/tests/auto/declarative/qdeclarativetextinput/data/geometrySignals.qml b/tests/auto/declarative/qdeclarativetextinput/data/geometrySignals.qml new file mode 100644 index 0000000..a9b50fe --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextinput/data/geometrySignals.qml @@ -0,0 +1,12 @@ +import Qt 4.7 + +Item { + width: 400; height: 500; + property int bindingWidth: text.width + property int bindingHeight: text.height + + TextEdit { + id: text + anchors.fill: parent + } +} diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 83ebe6c..0065ccf 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -76,6 +76,7 @@ private slots: void focusOutClearSelection(); void echoMode(); + void geometrySignals(); private: void simulateKey(QDeclarativeView *, int key); QDeclarativeView *createView(const QString &filename); @@ -805,6 +806,16 @@ void tst_qdeclarativetextinput::focusOutClearSelection() QTRY_COMPARE(input.selectedText(), QLatin1String("")); } +void tst_qdeclarativetextinput::geometrySignals() +{ + QDeclarativeComponent component(&engine, SRCDIR "/data/geometrySignals.qml"); + QObject *o = component.create(); + QVERIFY(o); + QCOMPARE(o->property("bindingWidth").toInt(), 400); + QCOMPARE(o->property("bindingHeight").toInt(), 500); + delete o; +} + QTEST_MAIN(tst_qdeclarativetextinput) #include "tst_qdeclarativetextinput.moc" -- cgit v0.12 From 9439d7475e7ba558a5b455a8f2b7f90adf26db79 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 7 May 2010 09:14:54 +1000 Subject: Avoid repeated create/destroy at top list boundary with sub-pixel movement. --- src/declarative/graphicsitems/qdeclarativelistview.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 328f319..416e0a8 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -650,7 +650,7 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) FxListItem *item = 0; int pos = itemEnd + 1; while (modelIndex < model->count() && pos <= fillTo) { - //qDebug() << "refill: append item" << modelIndex << "pos" << pos; +// qDebug() << "refill: append item" << modelIndex << "pos" << pos; if (!(item = createItem(modelIndex))) break; item->setPosition(pos); @@ -661,8 +661,8 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) if (doBuffer) // never buffer more than one item per frame break; } - while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos > fillFrom) { - //qDebug() << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos; + while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos-1 >= fillFrom) { +// qDebug() << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos; if (!(item = createItem(visibleIndex-1))) break; --visibleIndex; @@ -678,7 +678,7 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) while (visibleItems.count() > 1 && (item = visibleItems.first()) && item->endPosition() < bufferFrom) { if (item->attached->delayRemove()) break; - //qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endPosition(); +// qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endPosition(); if (item->index != -1) visibleIndex++; visibleItems.removeFirst(); @@ -688,7 +688,7 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->position() > bufferTo) { if (item->attached->delayRemove()) break; - //qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1; +// qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1 << item->position(); visibleItems.removeLast(); releaseItem(item); changed = true; -- cgit v0.12 From 65d04843759d14f15f559c78df94626568bc0cb8 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 7 May 2010 10:16:28 +1000 Subject: Compile with opengl enabled. --- src/multimedia/mediaservices/mediaservices.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/multimedia/mediaservices/mediaservices.pro b/src/multimedia/mediaservices/mediaservices.pro index d5b0e4c..8a065f4 100644 --- a/src/multimedia/mediaservices/mediaservices.pro +++ b/src/multimedia/mediaservices/mediaservices.pro @@ -2,6 +2,8 @@ TARGET = QtMediaServices QPRO_PWD = $$PWD QT = core gui multimedia +contains(QT_CONFIG, opengl): QT += opengl + DEFINES += QT_BUILD_MEDIASERVICES_LIB QT_NO_USING_NAMESPACE unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtMultimedia -- cgit v0.12 From 7c945e152c9abd0478bed5a4d251012944d93b44 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 5 May 2010 14:57:53 +1000 Subject: Resize qmlruntime window to new dimensions when orientation changes Task-number: Reviewed-by: Warwick Allison --- src/declarative/util/qdeclarativeview.cpp | 16 ++- tests/auto/declarative/declarative.pro | 1 + .../qdeclarativeview/tst_qdeclarativeview.cpp | 4 +- .../qdeclarativeviewer/data/orientation.qml | 10 ++ .../qdeclarativeviewer/qdeclarativeviewer.pro | 11 +++ .../qdeclarativeviewer/tst_qdeclarativeviewer.cpp | 108 +++++++++++++++++++++ tools/qml/qmlruntime.cpp | 19 +++- tools/qml/qmlruntime.h | 5 +- 8 files changed, 156 insertions(+), 18 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeviewer/data/orientation.qml create mode 100644 tests/auto/declarative/qdeclarativeviewer/qdeclarativeviewer.pro create mode 100644 tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index 62d913c..833e284 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -484,10 +484,7 @@ QSize QDeclarativeViewPrivate::rootObjectSize() QSize rootObjectSize(0,0); int widthCandidate = -1; int heightCandidate = -1; - if (declarativeItemRoot) { - widthCandidate = declarativeItemRoot->width(); - heightCandidate = declarativeItemRoot->height(); - } else if (root) { + if (root) { QSizeF size = root->boundingRect().size(); widthCandidate = size.width(); heightCandidate = size.height(); @@ -614,16 +611,15 @@ bool QDeclarativeView::eventFilter(QObject *watched, QEvent *e) /*! \internal - Preferred size follows the root object in - resize mode SizeViewToRootObject and - the view in resize mode SizeRootObjectToView. + Preferred size follows the root object geometry. */ QSize QDeclarativeView::sizeHint() const { - if (d->resizeMode == SizeRootObjectToView) { + QSize rootObjectSize = d->rootObjectSize(); + if (rootObjectSize.isEmpty()) { return size(); - } else { // d->resizeMode == SizeViewToRootObject - return d->rootObjectSize(); + } else { + return rootObjectSize; } } diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index b8e33cf..05c4c26 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -64,6 +64,7 @@ SUBDIRS += \ qdeclarativestyledtext \ # Cover qdeclarativesqldatabase \ # Cover qdeclarativevisualdatamodel \ # Cover + qdeclarativeviewer \ # Cover qmlvisual # Cover contains(QT_CONFIG, webkit) { diff --git a/tests/auto/declarative/qdeclarativeview/tst_qdeclarativeview.cpp b/tests/auto/declarative/qdeclarativeview/tst_qdeclarativeview.cpp index 1ed51c1..dd2f46e 100644 --- a/tests/auto/declarative/qdeclarativeview/tst_qdeclarativeview.cpp +++ b/tests/auto/declarative/qdeclarativeview/tst_qdeclarativeview.cpp @@ -147,7 +147,7 @@ void tst_QDeclarativeView::resizemodedeclarativeitem() declarativeItem->setHeight(80); QCOMPARE(canvas->width(), 80); QCOMPARE(canvas->height(), 100); - QCOMPARE(canvas->size(), canvas->sizeHint()); + QCOMPARE(QSize(declarativeItem->width(), declarativeItem->height()), canvas->sizeHint()); QCOMPARE(sceneResizedSpy2.count(), 2); // size update from view @@ -230,7 +230,7 @@ void tst_QDeclarativeView::resizemodegraphicswidget() canvas->setResizeMode(QDeclarativeView::SizeRootObjectToView); graphicsWidget->resize(QSizeF(60,80)); QCOMPARE(canvas->size(), QSize(80,100)); - QCOMPARE(canvas->size(), canvas->sizeHint()); + QCOMPARE(QSize(graphicsWidget->size().width(), graphicsWidget->size().height()), canvas->sizeHint()); QCOMPARE(sceneResizedSpy2.count(), 2); // size update from view diff --git a/tests/auto/declarative/qdeclarativeviewer/data/orientation.qml b/tests/auto/declarative/qdeclarativeviewer/data/orientation.qml new file mode 100644 index 0000000..687fac6 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeviewer/data/orientation.qml @@ -0,0 +1,10 @@ +import Qt 4.7 +Rectangle { + color: "black" + width: (runtime.orientation == Orientation.Landscape) ? 300 : 200 + height: (runtime.orientation == Orientation.Landscape) ? 200 : 300 + Text { + text: runtime.orientation == Orientation.Landscape ? "Landscape" : "Portrait" + color: "white" + } +} \ No newline at end of file diff --git a/tests/auto/declarative/qdeclarativeviewer/qdeclarativeviewer.pro b/tests/auto/declarative/qdeclarativeviewer/qdeclarativeviewer.pro new file mode 100644 index 0000000..dc10f5b --- /dev/null +++ b/tests/auto/declarative/qdeclarativeviewer/qdeclarativeviewer.pro @@ -0,0 +1,11 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +include(../../../../tools/qml/qml.pri) + +SOURCES += tst_qdeclarativeviewer.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" + +CONFIG += parallel_test diff --git a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp new file mode 100644 index 0000000..9429dc9 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include "qmlruntime.h" + +class tst_QDeclarativeViewer : public QObject + +{ + Q_OBJECT +public: + tst_QDeclarativeViewer(); + +private slots: + void orientation(); + +private: + QDeclarativeEngine engine; +}; + +tst_QDeclarativeViewer::tst_QDeclarativeViewer() +{ +} + +void tst_QDeclarativeViewer::orientation() +{ + QWidget window; + QDeclarativeViewer *viewer = new QDeclarativeViewer(&window); + QVERIFY(viewer); + viewer->open(SRCDIR "/data/orientation.qml"); + QVERIFY(viewer->view()); + QVERIFY(viewer->menuBar()); + QDeclarativeItem* rootItem = qobject_cast(viewer->view()->rootObject()); + QVERIFY(rootItem); + window.show(); + + QCOMPARE(rootItem->width(), 200.0); + QCOMPARE(rootItem->height(), 300.0); + QCOMPARE(viewer->view()->size(), QSize(200, 300)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); + QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), viewer->sizeHint()); + + viewer->toggleOrientation(); + qApp->processEvents(); + + QCOMPARE(rootItem->width(), 300.0); + QCOMPARE(rootItem->height(), 200.0); + QCOMPARE(viewer->view()->size(), QSize(300, 200)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(300, 200)); + QCOMPARE(viewer->size(), QSize(300, 200+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), viewer->sizeHint()); + + viewer->toggleOrientation(); + qApp->processEvents(); + + QCOMPARE(rootItem->width(), 200.0); + QCOMPARE(rootItem->height(), 300.0); + QCOMPARE(viewer->view()->size(), QSize(200, 300)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); + QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), viewer->sizeHint()); +} + +QTEST_MAIN(tst_QDeclarativeViewer) + +#include "tst_qdeclarativeviewer.moc" diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index d49b0f1..06fa004 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -535,6 +535,8 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) connect(&autoStartTimer, SIGNAL(triggered()), this, SLOT(autoStartRecording())); connect(&autoStopTimer, SIGNAL(triggered()), this, SLOT(autoStopRecording())); connect(&recordTimer, SIGNAL(triggered()), this, SLOT(recordFrame())); + connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()), + this, SLOT(orientationChanged()), Qt::QueuedConnection); autoStartTimer.setRunning(false); autoStopTimer.setRunning(false); recordTimer.setRunning(false); @@ -968,10 +970,8 @@ void QDeclarativeViewer::statusChanged() if (canvas->status() == QDeclarativeView::Ready) { initialSize = canvas->sizeHint(); if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { - QSize newWindowSize = initialSize; - newWindowSize.setHeight(newWindowSize.height()+menuBarHeight()); updateSizeHints(); - resize(newWindowSize); + resize(QSize(initialSize.width(), initialSize.height()+menuBarHeight())); } } } @@ -1425,6 +1425,19 @@ void QDeclarativeViewer::recordFrame() } } +void QDeclarativeViewer::orientationChanged() +{ + if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { + if (canvas->rootObject()) { + QSizeF rootObjectSize = canvas->rootObject()->boundingRect().size(); + QSize newSize(rootObjectSize.width(), rootObjectSize.height()+menuBarHeight()); + if (size() != newSize) { + resize(newSize); + } + } + } +} + void QDeclarativeViewer::setDeviceKeys(bool on) { devicemode = on; diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 655feea..9551090 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -125,6 +125,7 @@ public slots: void showProxySettings (); void proxySettingsChanged (); void setScaleView(); + void toggleOrientation(); void statusChanged(); void setSlowMode(bool); void launch(const QString &); @@ -132,7 +133,6 @@ public slots: protected: virtual void keyPressEvent(QKeyEvent *); virtual bool event(QEvent *); - void createMenu(QMenuBar *menu, QMenu *flatmenu); private slots: @@ -144,9 +144,9 @@ private slots: void setScaleSkin(); void setPortrait(); void setLandscape(); - void toggleOrientation(); void startNetwork(); void toggleFullScreen(); + void orientationChanged(); void showWarnings(bool show); void warningsWidgetOpened(); @@ -199,7 +199,6 @@ private: QNetworkReply *wgtreply; QString wgtdir; - NetworkAccessManagerFactory *namFactory; bool useQmlFileBrowser; -- cgit v0.12 From d7ef9666e2a3c8d06c5f32b7f47f602b177a74f6 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Thu, 6 May 2010 15:48:34 +1000 Subject: Avoid emitting release when the mouse is ungrabbed Added an onCanceled signal to mouse area, which is triggered when the mouse area rejects the event (propagates to the nearest mouse area beneath) or some other element steals the mouse grab (flickable, for example). Task-number: QTBUG-10162 Reviewed-by: Michael Brasser --- .../graphicsitems/qdeclarativemousearea.cpp | 19 ++++++++-- .../graphicsitems/qdeclarativemousearea_p.h | 1 + .../tst_qdeclarativemousearea.cpp | 44 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index c5a995e..74f2338 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -288,6 +288,17 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() */ /*! + \qmlsignal MouseArea::onCanceled() + + This handler is called when the mouse events are canceled, either because the event was not accepted or + another element stole the mouse event handling. This signal is for advanced users, it's useful in case there + is more than one mouse areas handling input, or when there is a mouse area inside a flickable. In the latter + case, if you do some logic on pressed and then start dragging, the flickable will steal the mouse handling + from the mouse area. In these cases, to reset the logic when there is no mouse handling anymore, you should + use onCanceled, in addition to onReleased. +*/ + +/*! \internal \class QDeclarativeMouseArea \brief The QDeclarativeMouseArea class provides a simple mouse handling abstraction for use within Qml. @@ -562,10 +573,12 @@ bool QDeclarativeMouseArea::sceneEvent(QEvent *event) // state d->pressed = false; setKeepMouseGrab(false); - QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, false); - emit released(&me); + emit canceled(); emit pressedChanged(); - setHovered(false); + if (d->hovered) { + d->hovered = false; + emit hoveredChanged(); + } } } return rv; diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h index e3f523b..df77ac6 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h +++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h @@ -163,6 +163,7 @@ Q_SIGNALS: void doubleClicked(QDeclarativeMouseEvent *mouse); void entered(); void exited(); + void canceled(); protected: void setHovered(bool); diff --git a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp index eb4aa12..96e6b8c 100644 --- a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp +++ b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp @@ -56,6 +56,8 @@ private slots: void updateMouseAreaPosOnClick(); void updateMouseAreaPosOnResize(); void noOnClickedWithPressAndHold(); + void onMousePressRejected(); + private: QDeclarativeView *createView(); }; @@ -330,6 +332,48 @@ void tst_QDeclarativeMouseArea::noOnClickedWithPressAndHold() QVERIFY(canvas->rootObject()->property("held").toBool()); } +void tst_QDeclarativeMouseArea::onMousePressRejected() +{ + QDeclarativeView *canvas = createView(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/rejectEvent.qml")); + canvas->show(); + canvas->setFocus(); + QVERIFY(canvas->rootObject() != 0); + + QVERIFY(!canvas->rootObject()->property("mr1_pressed").toBool()); + QVERIFY(!canvas->rootObject()->property("mr1_released").toBool()); + QVERIFY(!canvas->rootObject()->property("mr1_canceled").toBool()); + QVERIFY(!canvas->rootObject()->property("mr2_pressed").toBool()); + QVERIFY(!canvas->rootObject()->property("mr2_released").toBool()); + QVERIFY(!canvas->rootObject()->property("mr2_canceled").toBool()); + + QGraphicsScene *scene = canvas->scene(); + QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); + pressEvent.setScenePos(QPointF(100, 100)); + pressEvent.setButton(Qt::LeftButton); + pressEvent.setButtons(Qt::LeftButton); + QApplication::sendEvent(scene, &pressEvent); + + QVERIFY(canvas->rootObject()->property("mr1_pressed").toBool()); + QVERIFY(!canvas->rootObject()->property("mr1_released").toBool()); + QVERIFY(!canvas->rootObject()->property("mr1_canceled").toBool()); + QVERIFY(canvas->rootObject()->property("mr2_pressed").toBool()); + QVERIFY(!canvas->rootObject()->property("mr2_released").toBool()); + QVERIFY(canvas->rootObject()->property("mr2_canceled").toBool()); + + QTest::qWait(200); + + QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); + releaseEvent.setScenePos(QPointF(100, 100)); + releaseEvent.setButton(Qt::LeftButton); + releaseEvent.setButtons(Qt::LeftButton); + QApplication::sendEvent(scene, &releaseEvent); + + QVERIFY(canvas->rootObject()->property("mr1_released").toBool()); + QVERIFY(!canvas->rootObject()->property("mr1_canceled").toBool()); + QVERIFY(!canvas->rootObject()->property("mr2_released").toBool()); +} + QTEST_MAIN(tst_QDeclarativeMouseArea) #include "tst_qdeclarativemousearea.moc" -- cgit v0.12 From 705a6ee8f08b1c0b360f1438301ce049e96ed450 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Thu, 6 May 2010 16:06:43 +1000 Subject: Fix autotest bug in MouseArea Reviewed-by: Martin Jones --- .../declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp index 96e6b8c..ff3bf45 100644 --- a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp +++ b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp @@ -322,7 +322,7 @@ void tst_QDeclarativeMouseArea::noOnClickedWithPressAndHold() QTest::qWait(1000); - QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMousePress); + QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); releaseEvent.setScenePos(QPointF(100, 100)); releaseEvent.setButton(Qt::LeftButton); releaseEvent.setButtons(Qt::LeftButton); -- cgit v0.12 From abd2c025d088064c31fd1b0e9c5ea29996e51bbe Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Fri, 7 May 2010 10:57:56 +1000 Subject: Update mouse area qmlvisual test to follow change QTBUG-10162 Reviewed-by: Michael Brasser --- .../qmlvisual/qdeclarativemousearea/mousearea-flickable.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/mousearea-flickable.qml b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/mousearea-flickable.qml index a0b787f..e223f5e 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/mousearea-flickable.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/mousearea-flickable.qml @@ -25,7 +25,7 @@ Rectangle { MouseArea { anchors.fill: parent onPressed: blue.color = "lightsteelblue" - onReleased: blue.color = "steelblue" + onCanceled: blue.color = "steelblue" } } Rectangle { @@ -36,7 +36,7 @@ Rectangle { MouseArea { anchors.fill: parent onEntered: { red.color = "darkred"; tooltip.opacity = 1 } - onExited: { red.color = "red"; tooltip.opacity = 0 } + onCanceled: { red.color = "red"; tooltip.opacity = 0 } } Rectangle { id: tooltip -- cgit v0.12 From 62a65081a37ed9a51b0d39d1e740345d77f7bec0 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 7 May 2010 12:10:33 +1000 Subject: Clean up example code, add white background behind text --- examples/declarative/dynamic/dynamic.qml | 193 +++++++++++---------- examples/declarative/dynamic/qml/Button.qml | 36 ++-- examples/declarative/dynamic/qml/GenericItem.qml | 13 -- examples/declarative/dynamic/qml/PaletteItem.qml | 16 +- .../declarative/dynamic/qml/PerspectiveItem.qml | 29 ++-- examples/declarative/dynamic/qml/Sun.qml | 32 +++- examples/declarative/dynamic/qml/itemCreation.js | 58 +++---- 7 files changed, 206 insertions(+), 171 deletions(-) delete mode 100644 examples/declarative/dynamic/qml/GenericItem.qml diff --git a/examples/declarative/dynamic/dynamic.qml b/examples/declarative/dynamic/dynamic.qml index 0e6e197..52c7c1e 100644 --- a/examples/declarative/dynamic/dynamic.qml +++ b/examples/declarative/dynamic/dynamic.qml @@ -4,44 +4,49 @@ import "qml" Item { id: window + + property int activeSuns: 0 + //This is a desktop-sized example width: 1024; height: 512 - property int activeSuns: 0 - //This is the message that pops up when there's an error - Rectangle{ + //This is the message box that pops up when there's an error + Rectangle { id: dialog + opacity: 0 anchors.centerIn: parent - width: dialogText.width + 6 - height: dialogText.height + 6 + width: dialogText.width + 6; height: dialogText.height + 6 border.color: 'black' color: 'lightsteelblue' z: 65535 //Arbitrary number chosen to be above all the items, including the scaled perspective ones. + function show(str){ dialogText.text = str; dialogAnim.start(); } - Text{ + + Text { id: dialogText - x:3 - y:3 + x: 3; y: 3 font.pixelSize: 14 } - SequentialAnimation{ + + SequentialAnimation { id: dialogAnim - NumberAnimation{target: dialog; property:"opacity"; to: 1; duration: 1000} - PauseAnimation{duration: 5000} - NumberAnimation{target: dialog; property:"opacity"; to: 0; duration: 1000} + NumberAnimation { target: dialog; property:"opacity"; to: 1; duration: 1000 } + PauseAnimation { duration: 5000 } + NumberAnimation { target: dialog; property:"opacity"; to: 0; duration: 1000 } } } // sky - Rectangle { id: sky + Rectangle { + id: sky anchors { left: parent.left; top: parent.top; right: toolbox.right; bottom: parent.verticalCenter } gradient: Gradient { - GradientStop { id: stopA; position: 0.0; color: "#0E1533" } - GradientStop { id: stopB; position: 1.0; color: "#437284" } + GradientStop { id: gradientStopA; position: 0.0; color: "#0E1533" } + GradientStop { id: gradientStopB; position: 1.0; color: "#437284" } } } @@ -49,109 +54,123 @@ Item { Particles { id: stars x: 0; y: 0; width: parent.width; height: parent.height / 2 - source: "images/star.png"; angleDeviation: 360; velocity: 0 - velocityDeviation: 0; count: parent.width / 10; fadeInDuration: 2800 + source: "images/star.png" + angleDeviation: 360 + velocity: 0; velocityDeviation: 0 + count: parent.width / 10 + fadeInDuration: 2800 opacity: 1 } - // ground, which has a z such that the sun can set behind it + // ground Rectangle { id: ground - z: 2 - anchors { left: parent.left; top: parent.verticalCenter; right: toolbox.right; bottom: parent.bottom } + z: 2 // just above the sun so that the sun can set behind it + anchors { left: parent.left; top: parent.verticalCenter; right: toolbox.left; bottom: parent.bottom } gradient: Gradient { GradientStop { position: 0.0; color: "ForestGreen" } GradientStop { position: 1.0; color: "DarkGreen" } } } - //Day state, for when you place a sun - states: State { - name: "Day"; when: window.activeSuns > 0 - PropertyChanges { target: stopA; color: "DeepSkyBlue"} - PropertyChanges { target: stopB; color: "SkyBlue"} - PropertyChanges { target: stars; opacity: 0 } - } - - transitions: Transition { - PropertyAnimation { duration: 3000 } - ColorAnimation { duration: 3000 } - } - SystemPalette { id: activePalette } - // toolbox + // right-hand panel Rectangle { id: toolbox - z: 3 //Above ground - color: activePalette.window; + width: 480 - anchors { right: parent.right; top:parent.top; bottom: parent.bottom } - Rectangle { //Not a child of any positioner - border.color: "black"; - width: toolRow.width + 4 - height: toolRow.height + 4 - x: toolboxPositioner.x + toolRow.x - 2 - y: toolboxPositioner.y + toolRow.y - 2 - } + color: activePalette.window + anchors { right: parent.right; top: parent.top; bottom: parent.bottom } + Column { - id: toolboxPositioner anchors.centerIn: parent spacing: 8 + Text { text: "Drag an item into the scene." } - Row { - id: toolRow - spacing: 8; - PaletteItem { - anchors.verticalCenter: parent.verticalCenter - file: "Sun.qml"; - image: "../images/sun.png" - } - PaletteItem { - file: "GenericItem.qml" - image: "../images/moon.png" - } - PaletteItem { - anchors.verticalCenter: parent.verticalCenter - file: "PerspectiveItem.qml" - image: "../images/tree_s.png" - } - PaletteItem { - anchors.verticalCenter: parent.verticalCenter - file: "PerspectiveItem.qml" - image: "../images/rabbit_brown.png" - } - PaletteItem { - anchors.verticalCenter: parent.verticalCenter - file: "PerspectiveItem.qml" - image: "../images/rabbit_bw.png" + + Rectangle { + width: childrenRect.width + 10; height: childrenRect.height + 10 + border.color: "black" + + Row { + anchors.centerIn: parent + spacing: 8 + + PaletteItem { + anchors.verticalCenter: parent.verticalCenter + componentFile: "Sun.qml" + image: "../images/sun.png" + } + PaletteItem { + anchors.verticalCenter: parent.verticalCenter + componentFile: "GenericSceneItem.qml" + image: "../images/moon.png" + } + PaletteItem { + anchors.verticalCenter: parent.verticalCenter + componentFile: "PerspectiveItem.qml" + image: "../images/tree_s.png" + } + PaletteItem { + anchors.verticalCenter: parent.verticalCenter + componentFile: "PerspectiveItem.qml" + image: "../images/rabbit_brown.png" + } + PaletteItem { + anchors.verticalCenter: parent.verticalCenter + componentFile: "PerspectiveItem.qml" + image: "../images/rabbit_bw.png" + } } } + Text { text: "Active Suns: " + activeSuns } - Rectangle { width: 440; height: 1; color: "black" } - Text { text: "Arbitrary QML: " } - TextEdit { - id: qmlText - width: 460 - height: 220 - readOnly: false - focusOnPress: true - font.pixelSize: 14 - - text: "import Qt 4.7\nImage {\n id: smile;\n x: 500*Math.random();\n y: 200*Math.random(); \n source: 'images/face-smile.png';\n NumberAnimation on opacity { \n to: 0; duration: 1500;\n }\n Component.onCompleted: smile.destroy(1500);\n}" + + Rectangle { width: parent.width; height: 1; color: "black" } + + Text { text: "Arbitrary QML:" } + + Rectangle { + width: 460; height: 240 + + TextEdit { + id: qmlText + anchors.fill: parent; anchors.margins: 5 + readOnly: false + focusOnPress: true + font.pixelSize: 14 + + text: "import Qt 4.7\nImage {\n id: smile\n x: 500 * Math.random()\n y: 200 * Math.random() \n source: 'images/face-smile.png'\n\n NumberAnimation on opacity { \n to: 0; duration: 1500\n }\n\n Component.onCompleted: smile.destroy(1500);\n}" + } } + Button { text: "Create" - function makeCustom() { - try{ + onClicked: { + try { Qt.createQmlObject(qmlText.text, window, 'CustomObject'); - }catch(err){ - dialog.show('Error on line ' + err.qmlErrors[0].lineNumber + '\n' + err.qmlErrors[0].message ); + } catch(err) { + dialog.show('Error on line ' + err.qmlErrors[0].lineNumber + '\n' + err.qmlErrors[0].message); } } - onClicked: makeCustom(); } } } + //Day state, for when a sun is added to the scene + states: State { + name: "Day" + when: window.activeSuns > 0 + + PropertyChanges { target: gradientStopA; color: "DeepSkyBlue" } + PropertyChanges { target: gradientStopB; color: "SkyBlue" } + PropertyChanges { target: stars; opacity: 0 } + } + + transitions: Transition { + PropertyAnimation { duration: 3000 } + ColorAnimation { duration: 3000 } + } + } diff --git a/examples/declarative/dynamic/qml/Button.qml b/examples/declarative/dynamic/qml/Button.qml index 53588bb..963a850 100644 --- a/examples/declarative/dynamic/qml/Button.qml +++ b/examples/declarative/dynamic/qml/Button.qml @@ -6,19 +6,35 @@ Rectangle { property variant text signal clicked - SystemPalette { id: activePalette } - height: text.height + 10 - width: text.width + 20 + height: text.height + 10; width: text.width + 20 border.width: 1 - radius: 4; smooth: true + radius: 4 + smooth: true + gradient: Gradient { - GradientStop { position: 0.0; - color: if(!mr.pressed){activePalette.light;}else{activePalette.button;} + GradientStop { + position: 0.0 + color: !mouseArea.pressed ? activePalette.light : activePalette.button } - GradientStop { position: 1.0; - color: if(!mr.pressed){activePalette.button;}else{activePalette.dark;} + GradientStop { + position: 1.0 + color: !mouseArea.pressed ? activePalette.button : activePalette.dark } } - MouseArea { id:mr; anchors.fill: parent; onClicked: container.clicked() } - Text { id: text; anchors.centerIn:parent; font.pointSize: 10; text: parent.text; color: activePalette.buttonText } + + SystemPalette { id: activePalette } + + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: container.clicked() + } + + Text { + id: text + anchors.centerIn:parent + font.pointSize: 10 + text: parent.text + color: activePalette.buttonText + } } diff --git a/examples/declarative/dynamic/qml/GenericItem.qml b/examples/declarative/dynamic/qml/GenericItem.qml deleted file mode 100644 index faac06d..0000000 --- a/examples/declarative/dynamic/qml/GenericItem.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt 4.7 - -Item{ - property bool created: false - property string image - width: imageItem.width - height: imageItem.height - z: 2 - Image{ - id: imageItem - source: image; - } -} diff --git a/examples/declarative/dynamic/qml/PaletteItem.qml b/examples/declarative/dynamic/qml/PaletteItem.qml index e8f2ed4..dcb5cc3 100644 --- a/examples/declarative/dynamic/qml/PaletteItem.qml +++ b/examples/declarative/dynamic/qml/PaletteItem.qml @@ -1,13 +1,19 @@ import Qt 4.7 import "itemCreation.js" as Code -GenericItem { - id: itemButton - property string file +Image { + id: paletteItem + + property string componentFile + property string image + + source: image + MouseArea { - anchors.fill: parent; + anchors.fill: parent + onPressed: Code.startDrag(mouse); - onPositionChanged: Code.moveDrag(mouse); + onPositionChanged: Code.continueDrag(mouse); onReleased: Code.endDrag(mouse); } } diff --git a/examples/declarative/dynamic/qml/PerspectiveItem.qml b/examples/declarative/dynamic/qml/PerspectiveItem.qml index 3cbe64a..c04d3dc 100644 --- a/examples/declarative/dynamic/qml/PerspectiveItem.qml +++ b/examples/declarative/dynamic/qml/PerspectiveItem.qml @@ -1,16 +1,25 @@ import Qt 4.7 Image { - id: tree + id: rootItem + property bool created: false - property double scaleFactor: Math.max((y+height-250)*0.01, 0.3) - property double scaledBottom: y + (height+height*scaleFactor)/2 - property bool onLand: scaledBottom > window.height/2 - property string image //Needed for compatibility with GenericItem + property string image + + property double scaledBottom: y + (height + height*scale) / 2 + property bool onLand: scaledBottom > window.height / 2 + + source: image opacity: onLand ? 1 : 0.25 - onCreatedChanged: if (created && !onLand) { tree.destroy() } else { z = scaledBottom } - scale: scaleFactor - transformOrigin: "Center" - source: image; smooth: true - onYChanged: z = scaledBottom + scale: Math.max((y + height - 250) * 0.01, 0.3) + smooth: true + + onCreatedChanged: { + if (created && !onLand) + rootItem.destroy(); + else + z = scaledBottom; + } + + onYChanged: z = scaledBottom; } diff --git a/examples/declarative/dynamic/qml/Sun.qml b/examples/declarative/dynamic/qml/Sun.qml index 3627964..43dcb9a 100644 --- a/examples/declarative/dynamic/qml/Sun.qml +++ b/examples/declarative/dynamic/qml/Sun.qml @@ -2,23 +2,37 @@ import Qt 4.7 Image { id: sun + property bool created: false property string image: "../images/sun.png" - onCreatedChanged: if(created){window.activeSuns++;}else{window.activeSuns--;} - source: image; - z: 1 + source: image - //x and y get set when instantiated - //head offscreen + // once item is created, start moving offscreen NumberAnimation on y { - to: window.height / 2; + to: window.height / 2 running: created - onRunningChanged: if (running) duration = (window.height - sun.y) * 10; else state = "OffScreen"; + onRunningChanged: { + if (running) + duration = (window.height - sun.y) * 10; + else + state = "OffScreen" + } } states: State { - name: "OffScreen"; - StateChangeScript { script: { sun.created = false; sun.destroy() } } + name: "OffScreen" + StateChangeScript { + script: { sun.created = false; sun.destroy() } + } + } + + onCreatedChanged: { + if (created) { + sun.z = 1; // above the sky but below the ground layer + window.activeSuns++; + } else { + window.activeSuns--; + } } } diff --git a/examples/declarative/dynamic/qml/itemCreation.js b/examples/declarative/dynamic/qml/itemCreation.js index 3c1b975..92d345d 100644 --- a/examples/declarative/dynamic/qml/itemCreation.js +++ b/examples/declarative/dynamic/qml/itemCreation.js @@ -1,54 +1,39 @@ var itemComponent = null; var draggedItem = null; var startingMouse; -var startingZ; -//Until QT-2385 is resolved we need to convert to scene coordinates manually -var xOffset; -var yOffset; -function setSceneOffset() -{ - xOffset = 0; - yOffset = 0; - var p = itemButton; - while(p != window){ - xOffset += p.x; - yOffset += p.y; - p = p.parent; - } -} +var posnInWindow; function startDrag(mouse) { - setSceneOffset(); + posnInWindow = paletteItem.mapToItem(null, 0, 0); startingMouse = { x: mouse.x, y: mouse.y } loadComponent(); } -//Creation is split into two functions due to an asyncronous wait while +//Creation is split into two functions due to an asynchronous wait while //possible external files are loaded. function loadComponent() { - if (itemComponent != null) //Already loaded the component + if (itemComponent != null) { // component has been previously loaded createItem(); + return; + } - itemComponent = Qt.createComponent(itemButton.file); - //console.log(itemButton.file) - if(itemComponent.status == Component.Loading){ - component.statusChanged.connect(finishCreation); - }else{//Depending on the content, it can be ready or error immediately + itemComponent = Qt.createComponent(paletteItem.componentFile); + if (itemComponent.status == Component.Loading) //Depending on the content, it can be ready or error immediately + component.statusChanged.connect(createItem); + else createItem(); - } } function createItem() { if (itemComponent.status == Component.Ready && draggedItem == null) { draggedItem = itemComponent.createObject(); draggedItem.parent = window; - draggedItem.image = itemButton.image; - draggedItem.x = xOffset; - draggedItem.y = yOffset; - startingZ = draggedItem.z; - draggedItem.z = 4;//On top + draggedItem.image = paletteItem.image; + draggedItem.x = posnInWindow.x; + draggedItem.y = posnInWindow.y; + draggedItem.z = 3; // make sure created item is above the ground layer } else if (itemComponent.status == Component.Error) { draggedItem = null; console.log("error creating component"); @@ -56,25 +41,24 @@ function createItem() { } } -function moveDrag(mouse) +function continueDrag(mouse) { - if(draggedItem == null) + if (draggedItem == null) return; - draggedItem.x = mouse.x + xOffset - startingMouse.x; - draggedItem.y = mouse.y + yOffset - startingMouse.y; + draggedItem.x = mouse.x + posnInWindow.x - startingMouse.x; + draggedItem.y = mouse.y + posnInWindow.y - startingMouse.y; } function endDrag(mouse) { - if(draggedItem == null) + if (draggedItem == null) return; - if(draggedItem.x + draggedItem.width > toolbox.x){ //Don't drop it in the toolbox + if (draggedItem.x + draggedItem.width > toolbox.x) { //Don't drop it in the toolbox draggedItem.destroy(); draggedItem = null; - }else{ - draggedItem.z = startingZ; + } else { draggedItem.created = true; draggedItem = null; } -- cgit v0.12 From 4600f2053802ad41550a84573bdcbe4b50fb5a67 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 7 May 2010 13:29:34 +1000 Subject: Doc fix Task-number: QTBUG-10458 --- src/declarative/util/qdeclarativelistmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index 3810256..0985a6b 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -591,7 +591,7 @@ void QDeclarativeListModel::set(int index, const QScriptValue& valuemap) Changes the \a property of the item at \a index in the list model to \a value. \code - fruitModel.set(3, "cost", 5.95) + fruitModel.setProperty(3, "cost", 5.95) \endcode The \a index must be an element in the list. -- cgit v0.12 From 17837067e9dbda02669487bdd64419c38e8a2ebd Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Fri, 7 May 2010 14:17:27 +1000 Subject: Add missing qml file to qdeclarativemousearea --- .../qdeclarativemousearea/data/rejectEvent.qml | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativemousearea/data/rejectEvent.qml diff --git a/tests/auto/declarative/qdeclarativemousearea/data/rejectEvent.qml b/tests/auto/declarative/qdeclarativemousearea/data/rejectEvent.qml new file mode 100644 index 0000000..fecfadf --- /dev/null +++ b/tests/auto/declarative/qdeclarativemousearea/data/rejectEvent.qml @@ -0,0 +1,28 @@ +import Qt 4.7 + +Rectangle { + id: root + color: "#ffffff" + width: 320; height: 240 + property bool mr1_pressed: false + property bool mr1_released: false + property bool mr1_canceled: false + property bool mr2_pressed: false + property bool mr2_released: false + property bool mr2_canceled: false + + MouseArea { + id: mouseRegion1 + anchors.fill: parent + onPressed: {console.log("press111"); root.mr1_pressed = true} + onReleased: {console.log("release111"); root.mr1_released = true} + onCanceled: {console.log("ungrab1111"); root.mr1_canceled = true} + } + MouseArea { + id: mouseRegion2 + width: 120; height: 120 + onPressed: {console.log("press222"); root.mr2_pressed = true; mouse.accepted = false} + onReleased: {console.log("release2222"); root.mr2_released = true} + onCanceled: {console.log("ungrab2222"); root.mr2_canceled = true} + } +} -- cgit v0.12 From 60a06af7200217aa16c8c130a1ed0afce31812ed Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 7 May 2010 14:23:56 +1000 Subject: Fix autotests (remove import Qt.widgets) --- .../auto/declarative/qdeclarativeanchors/data/anchorsqgraphicswidget.qml | 1 - tests/auto/declarative/qdeclarativeloader/data/GraphicsWidget250x250.qml | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeanchors/data/anchorsqgraphicswidget.qml b/tests/auto/declarative/qdeclarativeanchors/data/anchorsqgraphicswidget.qml index 91973a3..d430c2c 100644 --- a/tests/auto/declarative/qdeclarativeanchors/data/anchorsqgraphicswidget.qml +++ b/tests/auto/declarative/qdeclarativeanchors/data/anchorsqgraphicswidget.qml @@ -1,5 +1,4 @@ import Qt 4.7 -import Qt.widgets 4.7 Rectangle { color: "white" diff --git a/tests/auto/declarative/qdeclarativeloader/data/GraphicsWidget250x250.qml b/tests/auto/declarative/qdeclarativeloader/data/GraphicsWidget250x250.qml index 9bb0b37..3b851c1 100644 --- a/tests/auto/declarative/qdeclarativeloader/data/GraphicsWidget250x250.qml +++ b/tests/auto/declarative/qdeclarativeloader/data/GraphicsWidget250x250.qml @@ -1,5 +1,4 @@ import Qt 4.7 -import Qt.widgets 4.6 QGraphicsWidget { size: "250x250" -- cgit v0.12 From 32c2d17680a04fced714aa103b40d7de24d9eb26 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 7 May 2010 14:41:00 +1000 Subject: Fix autotests --- src/imports/imports.pro | 2 +- tests/auto/declarative/declarative.pro | 1 - tests/auto/declarative/examples/tst_examples.cpp | 23 +++---- .../graphicswidgets/data/graphicswidgets.qml | 52 --------------- .../graphicswidgets/graphicswidgets.pro | 10 --- .../graphicswidgets/tst_graphicswidgets.cpp | 74 ---------------------- 6 files changed, 9 insertions(+), 153 deletions(-) delete mode 100644 tests/auto/declarative/graphicswidgets/data/graphicswidgets.qml delete mode 100644 tests/auto/declarative/graphicswidgets/graphicswidgets.pro delete mode 100644 tests/auto/declarative/graphicswidgets/tst_graphicswidgets.cpp diff --git a/src/imports/imports.pro b/src/imports/imports.pro index 1754908..a9d600e 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -SUBDIRS += particles +SUBDIRS += particles gestures contains(QT_CONFIG, webkit): SUBDIRS += webkit contains(QT_CONFIG, mediaservices): SUBDIRS += multimedia diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 05c4c26..a9b069c 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -1,7 +1,6 @@ TEMPLATE = subdirs SUBDIRS += \ examples \ - graphicswidgets \ # Cover parserstress \ # Cover qmetaobjectbuilder \ # Cover qdeclarativeanimations \ # Cover diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index 4f10a98..3759cb5 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -80,16 +80,6 @@ tst_examples::tst_examples() // Add directories you want excluded here - excludedDirs << "examples/declarative/extending"; - excludedDirs << "examples/declarative/tutorials/extending"; - excludedDirs << "examples/declarative/plugins"; - excludedDirs << "examples/declarative/proxywidgets"; - excludedDirs << "examples/declarative/gestures"; - - excludedDirs << "examples/declarative/imageprovider"; - excludedDirs << "examples/declarative/layouts/graphicsLayouts"; - excludedDirs << "demos/declarative/minehunt"; - excludedDirs << "doc/src/snippets/declarative/graphicswidgets"; #ifdef QT_NO_WEBKIT @@ -160,11 +150,14 @@ QStringList tst_examples::findQmlFiles(const QDir &d) QStringList rv; - QStringList files = d.entryList(QStringList() << QLatin1String("*.qml"), - QDir::Files); - foreach (const QString &file, files) { - if (file.at(0).isLower()) { - rv << d.absoluteFilePath(file); + QStringList cppfiles = d.entryList(QStringList() << QLatin1String("*.cpp"), QDir::Files); + if (cppfiles.isEmpty()) { + QStringList files = d.entryList(QStringList() << QLatin1String("*.qml"), + QDir::Files); + foreach (const QString &file, files) { + if (file.at(0).isLower()) { + rv << d.absoluteFilePath(file); + } } } diff --git a/tests/auto/declarative/graphicswidgets/data/graphicswidgets.qml b/tests/auto/declarative/graphicswidgets/data/graphicswidgets.qml deleted file mode 100644 index d6cf4de..0000000 --- a/tests/auto/declarative/graphicswidgets/data/graphicswidgets.qml +++ /dev/null @@ -1,52 +0,0 @@ -import Qt 4.7 -import Qt.widgets 4.7 - -QGraphicsWidget { - geometry: "20,0,600x400" - layout: QGraphicsLinearLayout { - orientation: Qt.Horizontal - QGraphicsWidget { - layout: QGraphicsLinearLayout { - spacing: 10; orientation: Qt.Vertical - LayoutItem { - QGraphicsLinearLayout.stretchFactor: 1 - QGraphicsLinearLayout.spacing: 1 - objectName: "left" - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "100x100" - Rectangle { objectName: "yellowRect"; color: "yellow"; anchors.fill: parent } - } - LayoutItem { - QGraphicsLinearLayout.stretchFactor: 10 - QGraphicsLinearLayout.spacing: 10 - objectName: "left" - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "100x100" - Rectangle { objectName: "yellowRect"; color: "blue"; anchors.fill: parent } - } - } - } - QGraphicsWidget { - layout: QGraphicsLinearLayout { - spacing: 10; orientation: Qt.Horizontal; contentsMargin: 10 - LayoutItem { - objectName: "left" - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "100x100" - Rectangle { objectName: "yellowRect"; color: "red"; anchors.fill: parent } - } - LayoutItem { - objectName: "left" - minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "100x100" - Rectangle { objectName: "yellowRect"; color: "green"; anchors.fill: parent } - } - } - } - } -} - diff --git a/tests/auto/declarative/graphicswidgets/graphicswidgets.pro b/tests/auto/declarative/graphicswidgets/graphicswidgets.pro deleted file mode 100644 index b77b430..0000000 --- a/tests/auto/declarative/graphicswidgets/graphicswidgets.pro +++ /dev/null @@ -1,10 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative gui -macx:CONFIG -= app_bundle - -SOURCES += tst_graphicswidgets.cpp - -# Define SRCDIR equal to test's source directory -DEFINES += SRCDIR=\\\"$$PWD\\\" - -CONFIG += parallel_test diff --git a/tests/auto/declarative/graphicswidgets/tst_graphicswidgets.cpp b/tests/auto/declarative/graphicswidgets/tst_graphicswidgets.cpp deleted file mode 100644 index f1a71d5..0000000 --- a/tests/auto/declarative/graphicswidgets/tst_graphicswidgets.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include - -class tst_graphicswidgets : public QObject - -{ - Q_OBJECT -public: - tst_graphicswidgets(); - -private slots: - void widgets(); -}; - -tst_graphicswidgets::tst_graphicswidgets() -{ -} - -void tst_graphicswidgets::widgets() -{ - QDeclarativeEngine engine; - QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/graphicswidgets.qml")); - QGraphicsWidget *obj = qobject_cast(c.create()); - - QVERIFY(obj != 0); - delete obj; -} - -QTEST_MAIN(tst_graphicswidgets) - -#include "tst_graphicswidgets.moc" -- cgit v0.12 From bdfa2d47fa1a6abee6e966f82fadf7a3d97bab0b Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 7 May 2010 15:48:58 +1000 Subject: Doc --- src/imports/webkit/qdeclarativewebview.cpp | 33 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/imports/webkit/qdeclarativewebview.cpp b/src/imports/webkit/qdeclarativewebview.cpp index 5db812c..9571470 100644 --- a/src/imports/webkit/qdeclarativewebview.cpp +++ b/src/imports/webkit/qdeclarativewebview.cpp @@ -437,24 +437,39 @@ void QDeclarativeWebView::paintPage(const QRect& r) /*! \qmlproperty list WebView::javaScriptWindowObjects - This property is a list of object that are available from within - the webview's JavaScript context. + A list of QML objects to expose to the web page. - The \a object will be inserted as a child of the frame's window - object, under the name given by the attached property \c WebView.windowObjectName. + Each object will be added as a property of the web frame's window object. The + property name is controlled by the value of \c WebView.windowObjectName + attached property. + + Exposing QML objects to a web page allows JavaScript executing in the web + page itself to communicate with QML, by reading and writing properties and + by calling methods of the exposed QML objects. + + This example shows how to call into a QML method using a window object. \qml WebView { - javaScriptWindowObjects: Object { - WebView.windowObjectName: "coordinates" + javaScriptWindowObjects: QtObject { + WebView.windowObjectName: "qml" + + function qmlCall() { + console.log("This call is in QML!"); + } } + + html: "" } \endqml - Properties of the object will be exposed as JavaScript properties and slots as - JavaScript methods. + The output of the example will be: + \code + This is in WebKit! + This call is in QML! + \endcode - If Javascript is not enabled for this page, then this property does nothing. + If Javascript is not enabled for the page, then this property does nothing. */ QDeclarativeListProperty QDeclarativeWebView::javaScriptWindowObjects() { -- cgit v0.12 From 4976130171033abdd8323a19229dcbfc5b008cfe Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 7 May 2010 16:15:37 +1000 Subject: Avoid many unnecessary allocations, so so that paint engines attached to pixmaps do not consume excessive amounts of memory, and so can still be reasonably kept cached with the pixmap. Saves 8K for every pixmaps drawn to on raster paint engine. Saves about 2K for other graphicssystems. Task-number: QTBUG-10215 Reviewed-by: Gunnar --- src/gui/painting/qdatabuffer_p.h | 19 +++++++-- src/gui/painting/qoutlinemapper.cpp | 3 +- src/gui/painting/qoutlinemapper_p.h | 11 ++++- src/gui/painting/qpaintengine_raster.cpp | 47 ++++++++++++---------- src/gui/painting/qpaintengine_raster_p.h | 6 ++- src/gui/painting/qpaintengineex.cpp | 3 +- src/gui/painting/qpathclipper.cpp | 23 +++++++---- src/gui/painting/qpathclipper_p.h | 7 +++- src/gui/painting/qpolygonclipper_p.h | 3 +- src/gui/painting/qrasterizer.cpp | 8 +++- src/gui/painting/qstroker.cpp | 2 +- src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h | 4 +- .../gl2paintengineex/qpaintengineex_opengl2_p.h | 1 + .../gl2paintengineex/qtriangulatingstroker.cpp | 5 ++- .../gl2paintengineex/qtriangulatingstroker_p.h | 1 + src/opengl/gl2paintengineex/qtriangulator.cpp | 12 +++--- src/opengl/qpaintengine_opengl.cpp | 3 ++ 17 files changed, 107 insertions(+), 51 deletions(-) diff --git a/src/gui/painting/qdatabuffer_p.h b/src/gui/painting/qdatabuffer_p.h index bc5f1ef..8f8544f 100644 --- a/src/gui/painting/qdatabuffer_p.h +++ b/src/gui/painting/qdatabuffer_p.h @@ -60,16 +60,20 @@ QT_BEGIN_NAMESPACE template class QDataBuffer { public: - QDataBuffer(int res = 64) + QDataBuffer(int res) { capacity = res; - buffer = (Type*) qMalloc(capacity * sizeof(Type)); + if (res) + buffer = (Type*) qMalloc(capacity * sizeof(Type)); + else + buffer = 0; siz = 0; } ~QDataBuffer() { - qFree(buffer); + if (buffer) + qFree(buffer); } inline void reset() { siz = 0; } @@ -104,6 +108,8 @@ public: inline void reserve(int size) { if (size > capacity) { + if (capacity == 0) + capacity = 1; while (capacity < size) capacity *= 2; buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); @@ -112,7 +118,12 @@ public: inline void shrink(int size) { capacity = size; - buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); + if (size) + buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); + else { + qFree(buffer); + buffer = 0; + } } inline void swap(QDataBuffer &other) { diff --git a/src/gui/painting/qoutlinemapper.cpp b/src/gui/painting/qoutlinemapper.cpp index ad0c2eb..1b01960 100644 --- a/src/gui/painting/qoutlinemapper.cpp +++ b/src/gui/painting/qoutlinemapper.cpp @@ -154,7 +154,8 @@ QT_FT_Outline *QOutlineMapper::convertPath(const QVectorPath &path) // ### We can kill this copying and just use the buffer straight... m_elements.resize(count); - memcpy(m_elements.data(), path.points(), count* sizeof(QPointF)); + if (count) + memcpy(m_elements.data(), path.points(), count* sizeof(QPointF)); m_element_types.resize(0); } diff --git a/src/gui/painting/qoutlinemapper_p.h b/src/gui/painting/qoutlinemapper_p.h index d0ce1a9..39b7593 100644 --- a/src/gui/painting/qoutlinemapper_p.h +++ b/src/gui/painting/qoutlinemapper_p.h @@ -87,8 +87,15 @@ const int QT_RASTER_COORD_LIMIT = 32767; class QOutlineMapper { public: - QOutlineMapper() - : m_round_coords(false) + QOutlineMapper() : + m_element_types(0), + m_elements(0), + m_elements_dev(0), + m_points(0), + m_tags(0), + m_contours(0), + m_polygon_dev(0), + m_round_coords(false) { } diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 9148ac2..483bc0c 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -336,17 +336,6 @@ void QRasterPaintEngine::init() d->hdc = 0; #endif - d->rasterPoolSize = 8192; - d->rasterPoolBase = -#if defined(Q_WS_WIN64) - // We make use of setjmp and longjmp in qgrayraster.c which requires - // 16-byte alignment, hence we hardcode this requirement here.. - (unsigned char *) _aligned_malloc(d->rasterPoolSize, sizeof(void*) * 2); -#else - (unsigned char *) malloc(d->rasterPoolSize); -#endif - Q_CHECK_PTR(d->rasterPoolBase); - // The antialiasing raster. d->grayRaster.reset(new QT_FT_Raster); Q_CHECK_PTR(d->grayRaster.data()); @@ -354,8 +343,6 @@ void QRasterPaintEngine::init() QT_THROW(std::bad_alloc()); // an error creating the raster is caused by a bad malloc - qt_ft_grays_raster.raster_reset(*d->grayRaster.data(), d->rasterPoolBase, d->rasterPoolSize); - d->rasterizer.reset(new QRasterizer); d->rasterBuffer.reset(new QRasterBuffer()); d->outlineMapper.reset(new QOutlineMapper); @@ -437,12 +424,6 @@ QRasterPaintEngine::~QRasterPaintEngine() { Q_D(QRasterPaintEngine); -#if defined(Q_WS_WIN64) - _aligned_free(d->rasterPoolBase); -#else - free(d->rasterPoolBase); -#endif - qt_ft_grays_raster.raster_done(*d->grayRaster.data()); } @@ -4090,6 +4071,22 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, return; } + const int rasterPoolInitialSize = 8192; + int rasterPoolSize = rasterPoolInitialSize; + unsigned char *rasterPoolBase; +#if defined(Q_WS_WIN64) + rasterPoolBase = + // We make use of setjmp and longjmp in qgrayraster.c which requires + // 16-byte alignment, hence we hardcode this requirement here.. + (unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2); +#else + unsigned char rasterPoolOnStack[rasterPoolInitialSize]; + rasterPoolBase = rasterPoolOnStack; +#endif + Q_CHECK_PTR(rasterPoolBase); + + qt_ft_grays_raster.raster_reset(*grayRaster.data(), rasterPoolBase, rasterPoolSize); + void *data = userData; QT_FT_BBox clip_box = { deviceRect.x(), @@ -4122,13 +4119,14 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, int new_size = rasterPoolSize * 2; if (new_size > 1024 * 1024) { qWarning("QPainter: Rasterization of primitive failed"); - return; + break; } #if defined(Q_WS_WIN64) _aligned_free(rasterPoolBase); #else - free(rasterPoolBase); + if (rasterPoolBase != rasterPoolOnStack) // initially on the stack + free(rasterPoolBase); #endif rasterPoolSize = new_size; @@ -4149,6 +4147,13 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, done = true; } } + +#if defined(Q_WS_WIN64) + _aligned_free(rasterPoolBase); +#else + if (rasterPoolBase != rasterPoolOnStack) // initially on the stack + free(rasterPoolBase); +#endif } void QRasterPaintEnginePrivate::recalculateFastImages() diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h index 55eb82e..0a0b0b2 100644 --- a/src/gui/painting/qpaintengine_raster_p.h +++ b/src/gui/painting/qpaintengine_raster_p.h @@ -300,6 +300,10 @@ QRasterPaintEnginePrivate : public QPaintEngineExPrivate { Q_DECLARE_PUBLIC(QRasterPaintEngine) public: + QRasterPaintEnginePrivate() : QPaintEngineExPrivate(), + cachedLines(0) + { + } void rasterizeLine_dashed(QLineF line, qreal width, int *dashIndex, qreal *dashOffset, bool *inDash); @@ -354,8 +358,6 @@ public: QScopedPointer dashStroker; QScopedPointer grayRaster; - unsigned long rasterPoolSize; - unsigned char *rasterPoolBase; QDataBuffer cachedLines; QSpanData image_filler; diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp index a78cafb..fda937e 100644 --- a/src/gui/painting/qpaintengineex.cpp +++ b/src/gui/painting/qpaintengineex.cpp @@ -149,6 +149,7 @@ QDebug Q_GUI_EXPORT &operator<<(QDebug &s, const QVectorPath &path) struct StrokeHandler { + StrokeHandler(int reserve) : pts(reserve), types(reserve) {} QDataBuffer pts; QDataBuffer types; }; @@ -394,7 +395,7 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) return; if (!d->strokeHandler) { - d->strokeHandler = new StrokeHandler; + d->strokeHandler = new StrokeHandler(path.elementCount()+4); d->stroker.setMoveToHook(qpaintengineex_moveTo); d->stroker.setLineToHook(qpaintengineex_lineTo); d->stroker.setCubicToHook(qpaintengineex_cubicTo); diff --git a/src/gui/painting/qpathclipper.cpp b/src/gui/painting/qpathclipper.cpp index c910024..78553c9 100644 --- a/src/gui/painting/qpathclipper.cpp +++ b/src/gui/painting/qpathclipper.cpp @@ -278,7 +278,8 @@ private: }; SegmentTree::SegmentTree(QPathSegments &segments) - : m_segments(segments) + : m_segments(segments), + m_intersections(0) { m_bounds.x1 = qt_inf(); m_bounds.y1 = qt_inf(); @@ -806,7 +807,7 @@ void QWingedEdge::intersectAndAdd() for (int i = 0; i < m_segments.points(); ++i) addVertex(m_segments.pointAt(i)); - QDataBuffer intersections; + QDataBuffer intersections(m_segments.segments()); for (int i = 0; i < m_segments.segments(); ++i) { intersections.reset(); @@ -857,11 +858,17 @@ void QWingedEdge::intersectAndAdd() } } -QWingedEdge::QWingedEdge() +QWingedEdge::QWingedEdge() : + m_edges(0), + m_vertices(0), + m_segments(0) { } -QWingedEdge::QWingedEdge(const QPainterPath &subject, const QPainterPath &clip) +QWingedEdge::QWingedEdge(const QPainterPath &subject, const QPainterPath &clip) : + m_edges(subject.length()), + m_vertices(subject.length()), + m_segments(subject.length()) { m_segments.setPath(subject); m_segments.addPath(clip); @@ -1414,9 +1421,9 @@ bool QPathClipper::intersect() else if (clipIsRect) return subjectPath.intersects(r2); - QPathSegments a; + QPathSegments a(subjectPath.length()); a.setPath(subjectPath); - QPathSegments b; + QPathSegments b(clipPath.length()); b.setPath(clipPath); QIntersectionFinder finder; @@ -1459,9 +1466,9 @@ bool QPathClipper::contains() if (clipIsRect) return subjectPath.contains(r2); - QPathSegments a; + QPathSegments a(subjectPath.length()); a.setPath(subjectPath); - QPathSegments b; + QPathSegments b(clipPath.length()); b.setPath(clipPath); QIntersectionFinder finder; diff --git a/src/gui/painting/qpathclipper_p.h b/src/gui/painting/qpathclipper_p.h index 7962400..fab618d 100644 --- a/src/gui/painting/qpathclipper_p.h +++ b/src/gui/painting/qpathclipper_p.h @@ -199,7 +199,7 @@ public: }; - QPathSegments(); + QPathSegments(int reserve); void setPath(const QPainterPath &path); void addPath(const QPainterPath &path); @@ -345,7 +345,10 @@ inline QPathVertex::operator QPointF() const return QPointF(x, y); } -inline QPathSegments::QPathSegments() +inline QPathSegments::QPathSegments(int reserve) : + m_points(reserve), + m_segments(reserve), + m_intersections(reserve) { } diff --git a/src/gui/painting/qpolygonclipper_p.h b/src/gui/painting/qpolygonclipper_p.h index 1b4cbb3..cdaac1c 100644 --- a/src/gui/painting/qpolygonclipper_p.h +++ b/src/gui/painting/qpolygonclipper_p.h @@ -62,7 +62,8 @@ QT_BEGIN_NAMESPACE template class QPolygonClipper { public: - QPolygonClipper() + QPolygonClipper() : + buffer1(0), buffer2(0) { x1 = y1 = x2 = y2 = 0; } diff --git a/src/gui/painting/qrasterizer.cpp b/src/gui/painting/qrasterizer.cpp index 51d01c9..f8f8afb 100644 --- a/src/gui/painting/qrasterizer.cpp +++ b/src/gui/painting/qrasterizer.cpp @@ -198,9 +198,11 @@ public: }; QScanConverter::QScanConverter() - : m_alloc(0) + : m_lines(0) + , m_alloc(0) , m_size(0) , m_intersections(0) + , m_active(0) { } @@ -310,6 +312,10 @@ struct QBoolToType template void qScanConvert(QScanConverter &d, T allVertical) { + if (!d.m_lines.size()) { + d.m_active.reset(); + return; + } qSort(d.m_lines.data(), d.m_lines.data() + d.m_lines.size(), QT_PREPEND_NAMESPACE(topOrder)); int line = 0; for (int y = d.m_lines.first().top; y <= d.m_bottom; ++y) { diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp index e43544c..9b8e099 100644 --- a/src/gui/painting/qstroker.cpp +++ b/src/gui/painting/qstroker.cpp @@ -187,7 +187,7 @@ static inline qreal adapted_angle_on_x(const QLineF &line) } QStrokerOps::QStrokerOps() - : m_customData(0), m_moveTo(0), m_lineTo(0), m_cubicTo(0) + : m_elements(0), m_customData(0), m_moveTo(0), m_lineTo(0), m_cubicTo(0) { } diff --git a/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h b/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h index adc69ee..46029b9 100644 --- a/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h +++ b/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h @@ -100,8 +100,10 @@ class QGL2PEXVertexArray { public: QGL2PEXVertexArray() : + vertexArray(0), vertexArrayStops(0), maxX(-2e10), maxY(-2e10), minX(2e10), minY(2e10), - boundingRectDirty(true) {} + boundingRectDirty(true) + { } inline void addRect(const QRectF &rect) { diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h index 6ba0c42..0a046dc 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h @@ -177,6 +177,7 @@ public: ctx(0), useSystemClip(true), elementIndicesVBOId(0), + opacityArray(0), snapToPixelGrid(false), addOffset(false), nativePaintingActive(false), diff --git a/src/opengl/gl2paintengineex/qtriangulatingstroker.cpp b/src/opengl/gl2paintengineex/qtriangulatingstroker.cpp index f677ce1..9bc099d 100644 --- a/src/opengl/gl2paintengineex/qtriangulatingstroker.cpp +++ b/src/opengl/gl2paintengineex/qtriangulatingstroker.cpp @@ -481,7 +481,8 @@ static void qdashprocessor_cubicTo(qreal, qreal, qreal, qreal, qreal, qreal, voi } QDashedStrokeProcessor::QDashedStrokeProcessor() - : m_dash_stroker(0), m_inv_scale(1) + : m_points(0), m_types(0), + m_dash_stroker(0), m_inv_scale(1) { m_dash_stroker.setMoveToHook(qdashprocessor_moveTo); m_dash_stroker.setLineToHook(qdashprocessor_lineTo); @@ -499,6 +500,8 @@ void QDashedStrokeProcessor::process(const QVectorPath &path, const QPen &pen, c m_points.reset(); m_types.reset(); + m_points.reserve(path.elementCount()); + m_types.reserve(path.elementCount()); qreal width = qpen_widthf(pen); if (width == 0) diff --git a/src/opengl/gl2paintengineex/qtriangulatingstroker_p.h b/src/opengl/gl2paintengineex/qtriangulatingstroker_p.h index 956d7cc..ab27ed6 100644 --- a/src/opengl/gl2paintengineex/qtriangulatingstroker_p.h +++ b/src/opengl/gl2paintengineex/qtriangulatingstroker_p.h @@ -54,6 +54,7 @@ QT_BEGIN_NAMESPACE class QTriangulatingStroker { public: + QTriangulatingStroker() : m_vertices(0) {} void process(const QVectorPath &path, const QPen &pen, const QRectF &clip); inline int vertexCount() const { return m_vertices.size(); } diff --git a/src/opengl/gl2paintengineex/qtriangulator.cpp b/src/opengl/gl2paintengineex/qtriangulator.cpp index ce917ff..df7cbc2 100644 --- a/src/opengl/gl2paintengineex/qtriangulator.cpp +++ b/src/opengl/gl2paintengineex/qtriangulator.cpp @@ -510,6 +510,7 @@ template class QMaxHeap { public: + QMaxHeap() : m_data(0) {} inline int size() const {return m_data.size();} inline bool empty() const {return m_data.isEmpty();} inline bool isEmpty() const {return m_data.isEmpty();} @@ -1299,7 +1300,8 @@ public: class ComplexToSimple { public: - inline ComplexToSimple(QTriangulator *parent) : m_parent(parent) { } + inline ComplexToSimple(QTriangulator *parent) : m_parent(parent), + m_edges(0), m_events(0), m_splits(0) { } void decompose(); private: struct Edge @@ -1412,7 +1414,7 @@ public: class SimpleToMonotone { public: - inline SimpleToMonotone(QTriangulator *parent) : m_parent(parent) { } + inline SimpleToMonotone(QTriangulator *parent) : m_parent(parent), m_edges(0), m_upperVertex(0) { } void decompose(); private: enum VertexType {MergeVertex, EndVertex, RegularVertex, StartVertex, SplitVertex}; @@ -1486,7 +1488,7 @@ public: int m_length; }; - inline QTriangulator() { } + inline QTriangulator() : m_vertices(0) { } // Call this only once. void initialize(const qreal *polygon, int count, uint hint, const QTransform &matrix); @@ -2709,7 +2711,7 @@ void QTriangulator::SimpleToMonotone::monotoneDecomposition() return; Q_ASSERT(!m_edgeList.root); - QDataBuffer > diagonals; + QDataBuffer > diagonals(m_upperVertex.size()); int i = 0; for (int index = 1; index < m_edges.size(); ++index) { @@ -2853,7 +2855,7 @@ bool QTriangulator::SimpleToMonotone::CompareVertices::operator () (int i, int j void QTriangulator::MonotoneToTriangles::decompose() { QVector result; - QDataBuffer stack; + QDataBuffer stack(m_parent->m_indices.size()); m_first = 0; // Require at least three more indices. while (m_first + 3 <= m_parent->m_indices.size()) { diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index 306fd8b..d2b0d4f 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -668,6 +668,7 @@ public: , last_created_state(0) , shader_ctx(0) , grad_palette(0) + , tess_points(0) , drawable_texture(0) , ref_cleaner(this) {} @@ -1950,6 +1951,8 @@ void QOpenGLPaintEnginePrivate::pathToVertexArrays(const QPainterPath &path) void QOpenGLPaintEnginePrivate::drawVertexArrays() { + if (tess_points_stops.count() == 0) + return; glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_DOUBLE, 0, tess_points.data()); int previous_stop = 0; -- cgit v0.12 From 346aa62e0ca4d02c32cae227165db004d2f15214 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 10 May 2010 10:32:59 +1000 Subject: Avoid changing header dependencies. (should fix compile on Symbian) --- src/gui/painting/qpaintengine_raster.cpp | 5 +++++ src/gui/painting/qpaintengine_raster_p.h | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 483bc0c..6f395f6 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -251,6 +251,11 @@ static void qt_debug_path(const QPainterPath &path) } #endif +QRasterPaintEnginePrivate::QRasterPaintEnginePrivate() : + QPaintEngineExPrivate(), + cachedLines(0) +{ +} /*! diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h index 0a0b0b2..1016f8d 100644 --- a/src/gui/painting/qpaintengine_raster_p.h +++ b/src/gui/painting/qpaintengine_raster_p.h @@ -300,10 +300,7 @@ QRasterPaintEnginePrivate : public QPaintEngineExPrivate { Q_DECLARE_PUBLIC(QRasterPaintEngine) public: - QRasterPaintEnginePrivate() : QPaintEngineExPrivate(), - cachedLines(0) - { - } + QRasterPaintEnginePrivate(); void rasterizeLine_dashed(QLineF line, qreal width, int *dashIndex, qreal *dashOffset, bool *inDash); -- cgit v0.12 From 1ca5742e83b650750d45d03882e8109c61c1f392 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 10 May 2010 10:54:32 +1000 Subject: There is no Qt.widgets Task-number: QTBUG-10469 --- examples/declarative/layouts/layoutItem/layoutItem.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/declarative/layouts/layoutItem/layoutItem.qml b/examples/declarative/layouts/layoutItem/layoutItem.qml index 9b9db22..460c564 100644 --- a/examples/declarative/layouts/layoutItem/layoutItem.qml +++ b/examples/declarative/layouts/layoutItem/layoutItem.qml @@ -1,5 +1,4 @@ import Qt 4.7 -import Qt.widgets 4.7 LayoutItem {//Sized by the layout id: resizable -- cgit v0.12 From b524e356424fe386eae56f65600077ce52ca6f92 Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Mon, 10 May 2010 03:43:12 +0200 Subject: Optimize QGW constructor. Mostly by avoiding sending useless QVariant at construction time. itemChange is virtual, the user implementation will never be called. Worst case the QGW one. Reviewed-by:janarve --- src/gui/graphicsview/qgraphicsitem.cpp | 7 ++++--- src/gui/graphicsview/qgraphicswidget.cpp | 3 --- src/gui/graphicsview/qgraphicswidget_p.cpp | 9 ++++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index ba674dd..b2bdc5c 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1090,6 +1090,10 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const Q if (newParent == parent) return; + if (isWidget) + static_cast(this)->fixFocusChainBeforeReparenting((newParent && + newParent->isWidget()) ? static_cast(newParent) : 0, + scene); if (scene) { // Deliver the change to the index if (scene->d_func()->indexMethod != QGraphicsScene::NoIndex) @@ -1796,9 +1800,6 @@ static void _q_qgraphicsItemSetFlag(QGraphicsItem *item, QGraphicsItem::Graphics */ void QGraphicsItem::setFlags(GraphicsItemFlags flags) { - if (isWindow()) - flags |= ItemIsPanel; - // Notify change and check for adjustment. if (quint32(d_ptr->flags) == quint32(flags)) return; diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index b264447..478c0c3 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -1105,9 +1105,6 @@ QVariant QGraphicsWidget::itemChange(GraphicsItemChange change, const QVariant & } break; case ItemParentChange: { - QGraphicsItem *parent = qVariantValue(value); - d->fixFocusChainBeforeReparenting((parent && parent->isWidget()) ? static_cast(parent) : 0, scene()); - // Deliver ParentAboutToChange. QEvent event(QEvent::ParentAboutToChange); QApplication::sendEvent(this, &event); diff --git a/src/gui/graphicsview/qgraphicswidget_p.cpp b/src/gui/graphicsview/qgraphicswidget_p.cpp index 6e397b6..50b315a 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.cpp +++ b/src/gui/graphicsview/qgraphicswidget_p.cpp @@ -71,14 +71,17 @@ void QGraphicsWidgetPrivate::init(QGraphicsItem *parentItem, Qt::WindowFlags wFl adjustWindowFlags(&wFlags); windowFlags = wFlags; - q->setParentItem(parentItem); + if (parentItem) + setParentItemHelper(parentItem, 0, 0); + q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType)); q->setGraphicsItem(q); resolveLayoutDirection(); q->unsetWindowFrameMargins(); - q->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption); - q->setFlag(QGraphicsItem::ItemSendsGeometryChanges); + flags |= QGraphicsItem::ItemUsesExtendedStyleOption | QGraphicsItem::ItemSendsGeometryChanges; + if (windowFlags & Qt::Window) + flags |= QGraphicsItem::ItemIsPanel; } qreal QGraphicsWidgetPrivate::titleBarHeight(const QStyleOptionTitleBar &options) const -- cgit v0.12 From 6ab242e23832f0ab10ef26a3b7b505cf086ddf43 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 10 May 2010 12:04:18 +1000 Subject: Prevent handling of Up/Down on Mac OS X, for consistency with other platforms. Task-number: QTBUG-10438 --- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 9 +++++++-- .../qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 9ae4e1a..604f508 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -62,6 +62,9 @@ QT_BEGIN_NAMESPACE Input constraints include setting a QValidator, an input mask, or a maximum input length. + + On Mac OS X, the Up/Down key bindings for Home/End are explicitly disabled. + If you want such bindings (on any platform), you will need to construct them in QML. */ QDeclarativeTextInput::QDeclarativeTextInput(QDeclarativeItem* parent) : QDeclarativePaintedItem(*(new QDeclarativeTextInputPrivate), parent) @@ -860,10 +863,12 @@ void QDeclarativeTextInputPrivate::focusChanged(bool hasFocus) void QDeclarativeTextInput::keyPressEvent(QKeyEvent* ev) { Q_D(QDeclarativeTextInput); - if(((d->control->cursor() == 0 && ev->key() == Qt::Key_Left) + if (((ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down) && ev->modifiers() == Qt::NoModifier) // Don't allow MacOSX up/down support, and we don't allow a completer. + || (((d->control->cursor() == 0 && ev->key() == Qt::Key_Left) || (d->control->cursor() == d->control->text().length() && ev->key() == Qt::Key_Right)) - && (d->lastSelectionStart == d->lastSelectionEnd)){ + && (d->lastSelectionStart == d->lastSelectionEnd))) + { //ignore when moving off the end //unless there is a selection, because then moving will do something (deselect) ev->ignore(); diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 0065ccf..c00390d 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -576,6 +576,14 @@ void tst_qdeclarativetextinput::navigation() simulateKey(canvas, Qt::Key_Left); QVERIFY(input->hasFocus() == true); + // Up and Down should NOT do Home/End, even on Mac OS X (QTBUG-10438). + input->setCursorPosition(2); + QCOMPARE(input->cursorPosition(),2); + simulateKey(canvas, Qt::Key_Up); + QCOMPARE(input->cursorPosition(),2); + simulateKey(canvas, Qt::Key_Down); + QCOMPARE(input->cursorPosition(),2); + delete canvas; } -- cgit v0.12 From c4d8435f80ef72fa419591a666b4e989ccb2c173 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Mon, 10 May 2010 12:19:16 +1000 Subject: Remove debug messages from mousearea autotest file --- .../declarative/qdeclarativemousearea/data/rejectEvent.qml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/auto/declarative/qdeclarativemousearea/data/rejectEvent.qml b/tests/auto/declarative/qdeclarativemousearea/data/rejectEvent.qml index fecfadf..c01e938 100644 --- a/tests/auto/declarative/qdeclarativemousearea/data/rejectEvent.qml +++ b/tests/auto/declarative/qdeclarativemousearea/data/rejectEvent.qml @@ -14,15 +14,15 @@ Rectangle { MouseArea { id: mouseRegion1 anchors.fill: parent - onPressed: {console.log("press111"); root.mr1_pressed = true} - onReleased: {console.log("release111"); root.mr1_released = true} - onCanceled: {console.log("ungrab1111"); root.mr1_canceled = true} + onPressed: { root.mr1_pressed = true } + onReleased: { root.mr1_released = true } + onCanceled: { root.mr1_canceled = true } } MouseArea { id: mouseRegion2 width: 120; height: 120 - onPressed: {console.log("press222"); root.mr2_pressed = true; mouse.accepted = false} - onReleased: {console.log("release2222"); root.mr2_released = true} - onCanceled: {console.log("ungrab2222"); root.mr2_canceled = true} + onPressed: { root.mr2_pressed = true; mouse.accepted = false } + onReleased: { root.mr2_released = true } + onCanceled: { root.mr2_canceled = true } } } -- cgit v0.12 From b1b8d79cecb40e94ddaf91c0e319209849d27f9e Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Mon, 10 May 2010 12:29:13 +1000 Subject: Fixes doc of mouse area's onEntered Task-number: QTBUG-9227 --- src/declarative/graphicsitems/qdeclarativemousearea.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index 74f2338..1947c00 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -197,8 +197,8 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() This handler is called when the mouse enters the mouse area. By default the onEntered handler is only called while a button is - pressed. Setting hoverEnabled to true enables handling of - onExited when no mouse button is pressed. + pressed. Setting hoverEnabled to true enables handling of + onEntered when no mouse button is pressed. \sa hoverEnabled */ @@ -209,7 +209,7 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() This handler is called when the mouse exists the mouse area. By default the onExited handler is only called while a button is - pressed. Setting hoverEnabled to true enables handling of + pressed. Setting hoverEnabled to true enables handling of onExited when no mouse button is pressed. \sa hoverEnabled -- cgit v0.12 From 9fabb4624a3b1209bc7fb5a4edd919c62df20233 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 10 May 2010 12:56:43 +1000 Subject: Add some test asserts --- src/declarative/util/qdeclarativepropertychanges.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp index c7e3bc5..6e88259 100644 --- a/src/declarative/util/qdeclarativepropertychanges.cpp +++ b/src/declarative/util/qdeclarativepropertychanges.cpp @@ -163,11 +163,13 @@ public: virtual void execute(Reason) { ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, expression); + Q_ASSERT(expression != ownedExpression); } virtual bool isReversable() { return true; } virtual void reverse(Reason) { ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, reverseExpression); + Q_ASSERT(reverseExpression != ownedExpression); } virtual void saveOriginals() { @@ -177,6 +179,7 @@ public: virtual void rewind() { ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, rewindExpression); + Q_ASSERT(rewindExpression != ownedExpression); } virtual void saveCurrentValues() { rewindExpression = QDeclarativePropertyPrivate::signalExpression(property); -- cgit v0.12 From 5280485f2b614c7b0417e37f91b959b689835b42 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Mon, 10 May 2010 16:25:01 +1000 Subject: Removed multimedia effects from tvtennis declarative example The multimedia elements are not part of 4.7 anymore. Reviewed-by: Martin Jones --- examples/declarative/tvtennis/click.wav | Bin 3056 -> 0 bytes examples/declarative/tvtennis/paddle.wav | Bin 5320 -> 0 bytes examples/declarative/tvtennis/tvtennis.qml | 8 -------- 3 files changed, 8 deletions(-) delete mode 100644 examples/declarative/tvtennis/click.wav delete mode 100644 examples/declarative/tvtennis/paddle.wav diff --git a/examples/declarative/tvtennis/click.wav b/examples/declarative/tvtennis/click.wav deleted file mode 100644 index 26c46f8..0000000 Binary files a/examples/declarative/tvtennis/click.wav and /dev/null differ diff --git a/examples/declarative/tvtennis/paddle.wav b/examples/declarative/tvtennis/paddle.wav deleted file mode 100644 index 604e0e5..0000000 Binary files a/examples/declarative/tvtennis/paddle.wav and /dev/null differ diff --git a/examples/declarative/tvtennis/tvtennis.qml b/examples/declarative/tvtennis/tvtennis.qml index 354a16f..c90d9c5 100644 --- a/examples/declarative/tvtennis/tvtennis.qml +++ b/examples/declarative/tvtennis/tvtennis.qml @@ -1,5 +1,4 @@ import Qt 4.7 -import Qt.multimedia 4.7 Rectangle { id: page @@ -17,17 +16,12 @@ Rectangle { x: 20; width: 20; height: 20; z: 1 color: "Lime" - SoundEffect { id: paddle; source: "paddle.wav" } - SoundEffect { id: wall; source: "click.wav" } - // Move the ball to the right and back to the left repeatedly SequentialAnimation on x { loops: Animation.Infinite NumberAnimation { to: page.width - 40; duration: 2000 } - ScriptAction { script: paddle.play() } PropertyAction { target: ball; property: "direction"; value: "left" } NumberAnimation { to: 20; duration: 2000 } - ScriptAction { script: paddle.play() } PropertyAction { target: ball; property: "direction"; value: "right" } } @@ -37,10 +31,8 @@ Rectangle { // Detect the ball hitting the top or bottom of the view and bounce it onYChanged: { if (y <= 0) { - wall.play(); targetY = page.height - 20; } else if (y >= page.height - 20) { - wall.play(); targetY = 0; } } -- cgit v0.12 From da8d6c23ceaeb1f266c9c499e98c9fedb1d1e20d Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 11 May 2010 08:13:33 +1000 Subject: Error message on QWS appears to have changed. --- .../declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp b/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp index dc9c2b2..d68b3e3 100644 --- a/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp +++ b/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp @@ -123,7 +123,7 @@ 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()); + QTest::ignoreMessage(QtDebugMsg, QString("FT_New_Face failed with index 0 : 2 ").toLatin1()); #endif QDeclarativeComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); -- cgit v0.12 From cd70183a86f3586eb34c15f11af03746f28f4acc Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 11 May 2010 08:57:17 +1000 Subject: Remove unnecesary check for debug output. --- .../declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp b/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp index d68b3e3..36908d9 100644 --- a/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp +++ b/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp @@ -122,9 +122,6 @@ 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 : 2 ").toLatin1()); -#endif QDeclarativeComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QDeclarativeFontLoader *fontObject = qobject_cast(component.create()); -- cgit v0.12 From 129940723d9145a4380f7e44c06cbaa88ee4053b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 11 May 2010 11:07:23 +1000 Subject: Correct ownership of signal handlers in state changes. When a state uses override, we may apply the same replacesignalhandler on top of itself. Make sure we update ownership accordingly. Task-number: QTBUG-10523 --- .../util/qdeclarativepropertychanges.cpp | 35 +++++++++++++++++----- .../data/signalOverrideCrash2.qml | 24 +++++++++++++++ .../qdeclarativestates/tst_qdeclarativestates.cpp | 16 ++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativestates/data/signalOverrideCrash2.qml diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp index 6e88259..94780c4 100644 --- a/src/declarative/util/qdeclarativepropertychanges.cpp +++ b/src/declarative/util/qdeclarativepropertychanges.cpp @@ -161,15 +161,22 @@ public: QDeclarativeExpression *rewindExpression; QDeclarativeGuard ownedExpression; + virtual bool changesBindings() { return true; } + virtual void clearBindings() { + ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, 0); + } + virtual void execute(Reason) { - ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, expression); - Q_ASSERT(expression != ownedExpression); + QDeclarativePropertyPrivate::setSignalExpression(property, expression); + if (ownedExpression == expression) + ownedExpression = 0; } virtual bool isReversable() { return true; } virtual void reverse(Reason) { - ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, reverseExpression); - Q_ASSERT(reverseExpression != ownedExpression); + QDeclarativePropertyPrivate::setSignalExpression(property, reverseExpression); + if (ownedExpression == reverseExpression) + ownedExpression = 0; } virtual void saveOriginals() { @@ -177,12 +184,26 @@ public: reverseExpression = rewindExpression; } + virtual void copyOriginals(QDeclarativeActionEvent *other) + { + QDeclarativeReplaceSignalHandler *rsh = static_cast(other); + saveCurrentValues(); + if (rsh == this) + return; + reverseExpression = rsh->reverseExpression; + if (rsh->ownedExpression == reverseExpression) { + ownedExpression = rsh->ownedExpression; + rsh->ownedExpression = 0; + } + } + virtual void rewind() { - ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, rewindExpression); - Q_ASSERT(rewindExpression != ownedExpression); + QDeclarativePropertyPrivate::setSignalExpression(property, rewindExpression); + if (ownedExpression == rewindExpression) + ownedExpression = 0; } virtual void saveCurrentValues() { - rewindExpression = QDeclarativePropertyPrivate::signalExpression(property); + rewindExpression = QDeclarativePropertyPrivate::signalExpression(property); } virtual bool override(QDeclarativeActionEvent*other) { diff --git a/tests/auto/declarative/qdeclarativestates/data/signalOverrideCrash2.qml b/tests/auto/declarative/qdeclarativestates/data/signalOverrideCrash2.qml new file mode 100644 index 0000000..2215ee4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativestates/data/signalOverrideCrash2.qml @@ -0,0 +1,24 @@ +import Qt 4.7 + +Rectangle { + id: myRect + width: 400 + height: 400 + + states: [ + State { + name: "state1" + PropertyChanges { + target: myRect + onHeightChanged: console.log("Hello World") + color: "green" + } + }, + State { + name: "state2"; extend: "state1" + PropertyChanges { + target: myRect + color: "red" + } + }] +} diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 13992ad..ea074a4 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -87,6 +87,7 @@ private slots: void basicBinding(); void signalOverride(); void signalOverrideCrash(); + void signalOverrideCrash2(); void parentChange(); void parentChangeErrors(); void anchorChanges(); @@ -449,6 +450,21 @@ void tst_qdeclarativestates::signalOverrideCrash() rect->doSomething(); } +void tst_qdeclarativestates::signalOverrideCrash2() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/signalOverrideCrash2.qml"); + QDeclarativeRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QDeclarativeItemPrivate::get(rect)->setState("state1"); + QDeclarativeItemPrivate::get(rect)->setState("state2"); + QDeclarativeItemPrivate::get(rect)->setState("state1"); + + delete rect; +} + void tst_qdeclarativestates::parentChange() { QDeclarativeEngine engine; -- cgit v0.12 From aa40b01fcda22e654790aaf93a6b14f947cdea72 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 11 May 2010 13:09:49 +1000 Subject: Round ideal width up to prevent incorrect word wrapping on Mac OS X QTBUG-10539 --- src/declarative/graphicsitems/qdeclarativetextedit.cpp | 4 +++- .../declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index d095dbe..6d86e58 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -46,6 +46,8 @@ #include #include +#include + #include #include #include @@ -1107,7 +1109,7 @@ void QDeclarativeTextEdit::updateSize() setBaselineOffset(fm.ascent() + yoff + d->textMargin); //### need to comfirm cost of always setting these - int newWidth = (int)d->document->idealWidth(); + int newWidth = qCeil(d->document->idealWidth()); d->document->setTextWidth(newWidth); // ### QTextDoc> Alignment will not work unless textWidth is set. Does Text need this line as well? int cursorWidth = 1; if(d->cursor) diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 8cc0e3f..b92024f 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -202,7 +202,7 @@ void tst_qdeclarativetextedit::width() QFont f; QFontMetricsF fm(f); qreal metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); - metricWidth = floor(metricWidth); + metricWidth = ceil(metricWidth); QString componentStr = "import Qt 4.7\nTextEdit { text: \"" + standard.at(i) + "\" }"; QDeclarativeComponent texteditComponent(&engine); @@ -219,7 +219,7 @@ void tst_qdeclarativetextedit::width() document.setHtml(richText.at(i)); document.setDocumentMargin(0); - int documentWidth = document.idealWidth(); + int documentWidth = ceil(document.idealWidth()); QString componentStr = "import Qt 4.7\nTextEdit { text: \"" + richText.at(i) + "\" }"; QDeclarativeComponent texteditComponent(&engine); -- cgit v0.12 From 367798c3cfaac56d82b29a90061d621e2b5854a5 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 11 May 2010 14:08:17 +1000 Subject: Correct Flipable back item based on parent, not scene transform Flipable transformation consists of two parts: 1. Detecting that the back face is visible 2. Transforming the back item as though "it were on the front" These are two steps. The first should be done in scene coordinates, and the second relative to the Flipable parent. QTBUG-10532 --- src/declarative/graphicsitems/qdeclarativeflipable.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflipable.cpp b/src/declarative/graphicsitems/qdeclarativeflipable.cpp index e2fc809..d926119 100644 --- a/src/declarative/graphicsitems/qdeclarativeflipable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflipable.cpp @@ -190,12 +190,15 @@ void QDeclarativeFlipablePrivate::updateSceneTransformFromParent() QPointF p2(1, 0); QPointF p3(1, 1); - p1 = sceneTransform.map(p1); - p2 = sceneTransform.map(p2); - p3 = sceneTransform.map(p3); - - qreal cross = (p1.x() - p2.x()) * (p3.y() - p2.y()) - - (p1.y() - p2.y()) * (p3.x() - p2.x()); + QPointF scenep1 = sceneTransform.map(p1); + QPointF scenep2 = sceneTransform.map(p2); + QPointF scenep3 = sceneTransform.map(p3); + p1 = q->mapToParent(p1); + p2 = q->mapToParent(p2); + p3 = q->mapToParent(p3); + + qreal cross = (scenep1.x() - scenep2.x()) * (scenep3.y() - scenep2.y()) - + (scenep1.y() - scenep2.y()) * (scenep3.x() - scenep2.x()); wantBackYFlipped = p1.x() >= p2.x(); wantBackXFlipped = p2.y() >= p3.y(); -- cgit v0.12
default