From d7a1e01e9970bef56f647873bb2a3496893b775a Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 14 Jul 2010 15:02:33 +1000 Subject: Distinguish Qt Quick, Qt Declarative and QML on the landing page Task-number: QTBUG-11916 --- doc/src/declarative/declarativeui.qdoc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/src/declarative/declarativeui.qdoc b/doc/src/declarative/declarativeui.qdoc index cd27c40..217e372 100644 --- a/doc/src/declarative/declarativeui.qdoc +++ b/doc/src/declarative/declarativeui.qdoc @@ -37,7 +37,9 @@ custom user interfaces from a rich set of \l {QML Elements}{QML elements}. Qt Quick helps programmers and designers collaborate to build the fluid user interfaces that are becoming common in portable consumer devices, such as mobile phones, media players, set-top boxes -and netbooks. +and netbooks. Qt Quick consists of the QtDeclarative C++ module, QML, and +the integration of both of these into the Qt Creator IDE. Using the QtDeclarative +C++ module, you can load and interact with QML files from your Qt application. QML is an extension to \l {http://www.ecma-international.org/publications/standards/Ecma-262.htm} @@ -58,7 +60,7 @@ complete internet-enabled applications like a \l Qt Quick builds on \l {QML for Qt programmers}{Qt's existing strengths}. QML can be be used to incrementally extend an existing application or to build completely new applications. QML is fully \l -{Extending QML in C++}{extensible from C++}. +{Extending QML in C++}{extensible from C++} through the QtDeclarative Module. \section1 Getting Started -- cgit v0.12 From 2ba0dfd82a3d82e98a70aeda3b142e0a870eeb0d Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 14 Jul 2010 15:03:35 +1000 Subject: Finish QML for Qt Programmers section I don't think I kept the same style as the rest of the section, so this may need to be refactored a little. But it's not incomplete anymore, content-wise. Task-number: QTBUG-11918 --- doc/src/declarative/qtprogrammers.qdoc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/src/declarative/qtprogrammers.qdoc b/doc/src/declarative/qtprogrammers.qdoc index ae54d58..68d56bf 100644 --- a/doc/src/declarative/qtprogrammers.qdoc +++ b/doc/src/declarative/qtprogrammers.qdoc @@ -27,8 +27,6 @@ /*! - INCOMPLETE - \page qtprogrammers.html \target qtprogrammers \title QML for Qt programmers @@ -146,4 +144,14 @@ transition from an arbitrary Text item, or characters within a Text item, so you item would need to be sufficiently flexible to allow such animation. \section1 QML Items Compared With QGraphicsWidgets + +The main difference between QML items and QGraphicsWidgets is how they are intended to be used. The technical implementation details are much the same, but in practice they are different because QML items are made for declarative and compositional use, and QGraphicsWidgets are made for imperative and more integrated use. Both QML items and QGraphicsWidgets inherit from QGraphicsObject, and can co-exist. The differences are in the layouting system and the interfacing with other components. Note that, as QGraphicsWidgets tend more to be all-in-one packages, the equivalent of a QGraphicsWidget may be many QML items composed across several QML files, but it can still be loaded and used as a single QGraphicsObject from C++. + +QGraphicsWidgets are usually designed to be laid out with QGraphicsLayouts. QML does not use QGraphicsLayouts, as the Qt layouts do not mix well with animated and fluid UIs, so the geometry interface is one of the main differences. When writing QML elements, you allow the designers to place their bounding rectangle using absolute geometry, bindings or anchors (all setup for you when you inherit QDeclarativeItem) and you do not use layouts or size hints. If size hints are appropriate, then place them in the QML documentation so that the designers know how to use the item best, but still have complete control over the look and feel. + +The other main difference is that QGraphicsWidgets tend to follow the widget model, in that they are a self-contained bundle of UI and logic. In contrast, QML primitives are usually a single purpose item that does not fulfill a use case on its own, but is composed into the equivalent of the widget inside the QML file. So when writing QML Items, try to avoid doing UI logic or composing visual elements inside the items. Try instead to write more general purpose primitives, so that the look and feel (which involves the UI logic) can be written in QML. + +Both differences are caused by the different method of interaction. QGraphicsWidget is a QGraphicsObject subclass which makes fluid UI development from C++ easier, and QDeclarativeItem is a QGraphicsObject subclass which makes fluid UI development from QML easier. The difference therefore is primarily one of the interface exposed, and the design of the items that come with it (the Declarative primitives for QML and the nothing for QGraphicsWidget, because you need to write your own UI logic into the subclass). + +If you wish to use both QML and C++ to write the UI, for example to ease the transition period, it is recommended to use QDeclarativeItem subclasses (although you can use QGraphicsWidgets as well). To allow for easier use from C++ make the root item of each C++ component a LayoutItem, and load individual 'widgets' of QML (possibly comprised of multiple files, and containing a self-contained bundle of UI and logic) into your scene to replace individual QGraphicsWidgets one at a time. */ -- cgit v0.12 From 2d4876330e292253a9133b0197e573097ecfa5bb Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 14 Jul 2010 15:05:02 +1000 Subject: Clean up particle motion documentation Task-number: QTBUG-11917 --- src/imports/particles/qdeclarativeparticles.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/imports/particles/qdeclarativeparticles.cpp b/src/imports/particles/qdeclarativeparticles.cpp index e95dfc7..8fe8a9f 100644 --- a/src/imports/particles/qdeclarativeparticles.cpp +++ b/src/imports/particles/qdeclarativeparticles.cpp @@ -158,6 +158,11 @@ void QDeclarativeParticleMotion::destroy(QDeclarativeParticle &particle) \brief The ParticleMotionLinear object moves particles linearly. \sa Particles + + This is the default motion, and moves the particles according to the + properties specified in the Particles element. + + It has no further properties. */ /*! @@ -178,6 +183,13 @@ void QDeclarativeParticleMotionLinear::advance(QDeclarativeParticle &p, int inte \since 4.7 \brief The ParticleMotionGravity object moves particles towards a point. + This motion attracts the particles to the specified point with the specified acceleration. + To mimic earth gravity, set yattractor to -6360000 and acceleration to 9.8. + + The defaults are all 0, not earth gravity, and so no motion will occur without setting + at least the acceleration property. + + \sa Particles */ @@ -186,6 +198,7 @@ void QDeclarativeParticleMotionLinear::advance(QDeclarativeParticle &p, int inte \class QDeclarativeParticleMotionGravity \ingroup group_effects \brief The QDeclarativeParticleMotionGravity class moves the particles towards a point. + */ /*! @@ -305,14 +318,14 @@ Rectangle { */ /*! - \qmlproperty real QDeclarativeParticleMotionWander::xvariance - \qmlproperty real QDeclarativeParticleMotionWander::yvariance + \qmlproperty real ParticleMotionWander::xvariance + \qmlproperty real ParticleMotionWander::yvariance These properties set the amount to wander in the x and y directions. */ /*! - \qmlproperty real QDeclarativeParticleMotionWander::pace + \qmlproperty real ParticleMotionWander::pace This property holds how quickly the paricles will move from side to side. */ -- cgit v0.12 From 9adc85fdfa0af2b6948408932188ee1b79247fa6 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 14 Jul 2010 15:32:32 +1000 Subject: Position GridView and ListView footer correctly when model cleared. Task-number: QTBUG-12167 --- .../graphicsitems/qdeclarativegridview.cpp | 5 ++- .../graphicsitems/qdeclarativelistview.cpp | 7 ++-- .../qdeclarativegridview/data/footer.qml | 32 +++++++++++++++++ .../tst_qdeclarativegridview.cpp | 41 ++++++++++++++++++++++ .../qdeclarativelistview/data/footer.qml | 30 ++++++++++++++++ .../tst_qdeclarativelistview.cpp | 32 +++++++++++++++++ 6 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativegridview/data/footer.qml create mode 100644 tests/auto/declarative/qdeclarativelistview/data/footer.qml diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index dce6f0e..14a4f08 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -2438,8 +2438,11 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count) if (removedVisible && d->visibleItems.isEmpty()) { d->timeline.clear(); d->setPosition(0); - if (d->itemCount == 0) + if (d->itemCount == 0) { + d->updateHeader(); + d->updateFooter(); update(); + } } emit countChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index cd26472..110c970 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1077,7 +1077,7 @@ void QDeclarativeListViewPrivate::updateFooter() } if (footer) { if (visibleItems.count()) { - qreal endPos = endPosition(); + qreal endPos = endPosition() + 1; if (lastVisibleIndex() == model->count()-1) { footer->setPosition(endPos); } else { @@ -2893,8 +2893,11 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count) d->visiblePos = d->header ? d->header->size() : 0; d->timeline.clear(); d->setPosition(0); - if (d->itemCount == 0) + if (d->itemCount == 0) { + d->updateHeader(); + d->updateFooter(); update(); + } } emit countChanged(); diff --git a/tests/auto/declarative/qdeclarativegridview/data/footer.qml b/tests/auto/declarative/qdeclarativegridview/data/footer.qml new file mode 100644 index 0000000..170b2b5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativegridview/data/footer.qml @@ -0,0 +1,32 @@ +import Qt 4.7 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + width: 80 + height: 60 + border.color: "blue" + Text { + text: index + } + color: GridView.isCurrentItem ? "lightsteelblue" : "white" + } + } + GridView { + id: grid + objectName: "grid" + width: 240 + height: 320 + cellWidth: 80 + cellHeight: 60 + model: testModel + delegate: myDelegate + footer: Text { objectName: "footer"; text: "Footer"; height: 30 } + } +} diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index a67c56f..1a28b71 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -81,6 +81,7 @@ private slots: void enforceRange(); void QTBUG_8456(); void manualHighlight(); + void footer(); private: QDeclarativeView *createView(); @@ -147,6 +148,14 @@ public: emit dataChanged(index(idx,0), index(idx,0)); } + void clear() { + int count = list.count(); + emit beginRemoveRows(QModelIndex(), 0, count-1); + list.clear(); + emit endRemoveRows(); + } + + private: QList > list; }; @@ -1162,6 +1171,38 @@ void tst_QDeclarativeGridView::manualHighlight() QTRY_COMPARE(gridview->highlightItem()->x(), gridview->currentItem()->x()); } +void tst_QDeclarativeGridView::footer() +{ + QDeclarativeView *canvas = createView(); + + TestModel model; + for (int i = 0; i < 7; i++) + model.addItem("Item" + QString::number(i), ""); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/footer.qml")); + qApp->processEvents(); + + QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); + QTRY_VERIFY(gridview != 0); + + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QDeclarativeText *footer = findItem(contentItem, "footer"); + QVERIFY(footer); + + QCOMPARE(footer->y(), 180.0); + + model.removeItem(2); + QTRY_COMPARE(footer->y(), 120.0); + + model.clear(); + QTRY_COMPARE(footer->y(), 0.0); +} + QDeclarativeView *tst_QDeclarativeGridView::createView() { diff --git a/tests/auto/declarative/qdeclarativelistview/data/footer.qml b/tests/auto/declarative/qdeclarativelistview/data/footer.qml new file mode 100644 index 0000000..11cbe16 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistview/data/footer.qml @@ -0,0 +1,30 @@ +import Qt 4.7 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + height: 20 + width: 240 + Text { + text: index + } + color: ListView.isCurrentItem ? "lightsteelblue" : "white" + } + } + ListView { + id: list + objectName: "list" + focus: true + width: 240 + height: 320 + model: testModel + delegate: myDelegate + footer: Text { objectName: "footer"; text: "Footer"; height: 30 } + } +} diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index e13bd94..9c24e03 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -97,6 +97,7 @@ private slots: void QTBUG_9791(); void manualHighlight(); void QTBUG_11105(); + void footer(); private: template void items(); @@ -1558,6 +1559,37 @@ void tst_QDeclarativeListView::QTBUG_11105() delete canvas; } +void tst_QDeclarativeListView::footer() +{ + QDeclarativeView *canvas = createView(); + + TestModel model; + for (int i = 0; i < 3; i++) + model.addItem("Item" + QString::number(i), ""); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/footer.qml")); + qApp->processEvents(); + + QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); + QTRY_VERIFY(listview != 0); + + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QDeclarativeText *footer = findItem(contentItem, "footer"); + QVERIFY(footer); + QCOMPARE(footer->y(), 60.0); + + model.removeItem(1); + QTRY_COMPARE(footer->y(), 40.0); + + model.clear(); + QTRY_COMPARE(footer->y(), 0.0); +} + void tst_QDeclarativeListView::qListModelInterface_items() { items(); -- cgit v0.12