diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-13 06:53:18 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-13 06:53:18 (GMT) |
commit | ed5cbe3cc5d57360c205d22deb8bb77063227b8f (patch) | |
tree | 508cf4323e9fe9cf4e3a82de114d7cc10fcfa42c | |
parent | 00b802ca9b2b09bc0357bc4b8f213657e24b02f8 (diff) | |
parent | 7544b0ddf02c5302eed430452efc5da311d8b1c7 (diff) | |
download | Qt-ed5cbe3cc5d57360c205d22deb8bb77063227b8f.zip Qt-ed5cbe3cc5d57360c205d22deb8bb77063227b8f.tar.gz Qt-ed5cbe3cc5d57360c205d22deb8bb77063227b8f.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
-rw-r--r-- | doc/src/declarative/qtbinding.qdoc | 2 | ||||
-rw-r--r-- | examples/declarative/layouts/layouts.qml | 10 | ||||
-rw-r--r-- | examples/declarative/listview/dynamic.qml | 15 | ||||
-rw-r--r-- | examples/declarative/listview/highlight.qml | 1 | ||||
-rw-r--r-- | examples/declarative/listview/listview-example.qml | 16 | ||||
-rw-r--r-- | examples/declarative/progressbar/content/ProgressBar.qml | 8 | ||||
-rw-r--r-- | examples/declarative/searchbox/SearchBox.qml | 6 | ||||
-rw-r--r-- | examples/declarative/states/states.qml | 50 | ||||
-rw-r--r-- | examples/declarative/states/transitions.qml | 69 | ||||
-rw-r--r-- | examples/declarative/tic-tac-toe/content/Button.qml | 8 | ||||
-rw-r--r-- | examples/declarative/tic-tac-toe/tic-tac-toe.qml | 10 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 15 | ||||
-rw-r--r-- | tests/auto/declarative/examples/tst_examples.cpp | 34 |
13 files changed, 138 insertions, 106 deletions
diff --git a/doc/src/declarative/qtbinding.qdoc b/doc/src/declarative/qtbinding.qdoc index 181c504..fa0d13c 100644 --- a/doc/src/declarative/qtbinding.qdoc +++ b/doc/src/declarative/qtbinding.qdoc @@ -74,7 +74,7 @@ an example of loading a QML document, and creating an object from it. \code QDeclarativeEngine *engine = new QDeclarativeEngine(parent); -QDeclarativeComponent component(engine, QUrl("main.qml")); +QDeclarativeComponent component(engine, QUrl::fromLocalFile("main.qml")); QObject *myObject = component.create(); \endcode diff --git a/examples/declarative/layouts/layouts.qml b/examples/declarative/layouts/layouts.qml index 81f9aed..391eab7 100644 --- a/examples/declarative/layouts/layouts.qml +++ b/examples/declarative/layouts/layouts.qml @@ -1,15 +1,15 @@ import Qt 4.7 -import Qt.widgets 4.6 +import Qt.widgets 4.7 Item { id: resizable - width:400 - height:400 + width: 400 + height: 400 QGraphicsWidget { - size.width:parent.width - size.height:parent.height + size.width: parent.width + size.height: parent.height layout: QGraphicsLinearLayout { LayoutItem { diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index efd0e10..236a9c5 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -3,6 +3,7 @@ import "content" import "../scrollbar" Rectangle { + id: container width: 640; height: 480 color: "#343434" @@ -54,7 +55,7 @@ Rectangle { id: fruitDelegate Item { - width: parent.width; height: 55 + width: container.width; height: 55 Column { id: moveButtons @@ -174,9 +175,9 @@ Rectangle { anchors.fill: parent onClicked: { fruitModel.append({ - "name":"Pizza Margarita", - "cost":5.95, - "attributes":[{"description": "Cheese"},{"description": "Tomato"}] + "name": "Pizza Margarita", + "cost": 5.95, + "attributes": [{"description": "Cheese"},{"description": "Tomato"}] }) } } @@ -189,9 +190,9 @@ Rectangle { anchors.fill: parent; onClicked: { fruitModel.insert(0, { - "name":"Pizza Supreme", - "cost":9.95, - "attributes":[{"description": "Cheese"},{"description": "Tomato"},{"description": "The Works"}] + "name": "Pizza Supreme", + "cost": 9.95, + "attributes": [{"description": "Cheese"},{"description": "Tomato"},{"description": "The Works"}] }) } } diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index 2f7f2ca..50ba2f7 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -43,6 +43,7 @@ Rectangle { SpringFollow on y { to: list1.currentItem.y; spring: 3; damping: 0.1 } } } + ListView { id: list1 width: 200; height: parent.height diff --git a/examples/declarative/listview/listview-example.qml b/examples/declarative/listview/listview-example.qml index 9409356..6feedf6 100644 --- a/examples/declarative/listview/listview-example.qml +++ b/examples/declarative/listview/listview-example.qml @@ -58,25 +58,33 @@ Rectangle { ListView { id: list1 width: 200; height: parent.height - model: MyPetsModel; delegate: petDelegate + model: MyPetsModel + delegate: petDelegate + highlight: petHighlight currentIndex: list3.currentIndex focus: true } + ListView { id: list2 x: 200; width: 200; height: parent.height - model: MyPetsModel; delegate: petDelegate + model: MyPetsModel + delegate: petDelegate + highlight: petHighlight currentIndex: list1.currentIndex preferredHighlightBegin: 80; preferredHighlightEnd: 220 highlightRangeMode: "ApplyRange" } + ListView { id: list3 x: 400; width: 200; height: parent.height - model: MyPetsModel; delegate: petDelegate - highlight: petHighlight + model: MyPetsModel + delegate: petDelegate + + highlight: Rectangle { color: "lightsteelblue" } currentIndex: list1.currentIndex preferredHighlightBegin: 125; preferredHighlightEnd: 125 highlightRangeMode: "StrictlyEnforceRange" diff --git a/examples/declarative/progressbar/content/ProgressBar.qml b/examples/declarative/progressbar/content/ProgressBar.qml index 6f13335..bc36df5 100644 --- a/examples/declarative/progressbar/content/ProgressBar.qml +++ b/examples/declarative/progressbar/content/ProgressBar.qml @@ -6,8 +6,8 @@ Item { property int minimum: 0 property int maximum: 100 property int value: 0 - property alias color: g1.color - property alias secondColor: g2.color + property alias color: gradient1.color + property alias secondColor: gradient2.color width: 250; height: 23 clip: true @@ -29,8 +29,8 @@ Item { anchors { left: parent.left; top: parent.top; bottom: parent.bottom; leftMargin: 3; topMargin: 3; bottomMargin: 3 } radius: 1 gradient: Gradient { - GradientStop { id: g1; position: 0.0 } - GradientStop { id: g2; position: 1.0 } + GradientStop { id: gradient1; position: 0.0 } + GradientStop { id: gradient2; position: 1.0 } } } diff --git a/examples/declarative/searchbox/SearchBox.qml b/examples/declarative/searchbox/SearchBox.qml index adeddd1..aae7ee9 100644 --- a/examples/declarative/searchbox/SearchBox.qml +++ b/examples/declarative/searchbox/SearchBox.qml @@ -21,7 +21,9 @@ FocusScope { id: typeSomething anchors.fill: parent; anchors.leftMargin: 8 verticalAlignment: Text.AlignVCenter - text: "Type something..."; color: "gray"; font.italic: true + text: "Type something..." + color: "gray" + font.italic: true } MouseArea { anchors.fill: parent; onClicked: focusScope.focus = true } @@ -29,7 +31,7 @@ FocusScope { TextInput { id: textInput anchors { left: parent.left; leftMargin: 8; verticalCenter: parent.verticalCenter } - focus: if (1) true + focus: true } Image { diff --git a/examples/declarative/states/states.qml b/examples/declarative/states/states.qml index f8c1dd5..4429e78 100644 --- a/examples/declarative/states/states.qml +++ b/examples/declarative/states/states.qml @@ -5,53 +5,57 @@ Rectangle { width: 640; height: 480 color: "#343434" - // A target region. Clicking in here sets the state to the default state + Image { + id: userIcon + x: topLeftRect.x; y: topLeftRect.y + source: "user.png" + } + Rectangle { - id: initialPosition + id: topLeftRect + anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } width: 64; height: 64 - radius: 6 - color: "Transparent"; border.color: "Gray" + color: "Transparent"; border.color: "Gray"; radius: 6 + // Clicking in here sets the state to the default state, returning the image to + // its initial position MouseArea { anchors.fill: parent; onClicked: page.state = '' } } - // Another target region. Clicking in here sets the state to 'Position1' Rectangle { - id: position1 + id: middleRightRect + anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } width: 64; height: 64 - radius: 6 - color: "Transparent"; border.color: "Gray" + color: "Transparent"; border.color: "Gray"; radius: 6 - MouseArea { anchors.fill: parent; onClicked: page.state = 'Position1' } + // Clicking in here sets the state to 'middleRight' + MouseArea { anchors.fill: parent; onClicked: page.state = 'middleRight' } } - // Another target region. Clicking in here sets the state to 'Position2' Rectangle { - id: position2 + id: bottomLeftRect + anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } width: 64; height: 64 - radius: 6 - color: "Transparent"; border.color: "Gray" + color: "Transparent"; border.color: "Gray"; radius: 6 - MouseArea { anchors.fill: parent; onClicked: page.state = 'Position2' } + // Clicking in here sets the state to 'bottomLeft' + MouseArea { anchors.fill: parent; onClicked: page.state = 'bottomLeft' } } - // The image which will be moved when my state changes - Image { id: user; source: "user.png"; x: initialPosition.x; y: initialPosition.y } - states: [ - // In state 'Position1', change the 'user' item position to rect2's position. + // In state 'middleRight', move the image to middleRightRect State { - name: "Position1" - PropertyChanges { target: user; x: position1.x; y: position1.y } + name: "middleRight" + PropertyChanges { target: userIcon; x: middleRightRect.x; y: middleRightRect.y } }, - // In state 'Position2', change the 'user' item position to rect3's position. + // In state 'bottomLeft', move the image to bottomLeftRect State { - name: "Position2" - PropertyChanges { target: user; x: position2.x; y: position2.y } + name: "bottomLeft" + PropertyChanges { target: userIcon; x: bottomLeftRect.x; y: bottomLeftRect.y } } ] } diff --git a/examples/declarative/states/transitions.qml b/examples/declarative/states/transitions.qml index b475333..d1b1dd6 100644 --- a/examples/declarative/states/transitions.qml +++ b/examples/declarative/states/transitions.qml @@ -1,74 +1,87 @@ import Qt 4.7 +/* + This is exactly the same as states.qml, except that we have appended + a set of transitions to apply animations when the item changes + between each state. +*/ + Rectangle { id: page width: 640; height: 480 color: "#343434" - // A target region. Clicking in here sets the state to the default state + Image { + id: userIcon + x: topLeftRect.x; y: topLeftRect.y + source: "user.png" + } + Rectangle { - id: initialPosition + id: topLeftRect + anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } width: 64; height: 64 - radius: 6 - color: "Transparent"; border.color: "Gray" + color: "Transparent"; border.color: "Gray"; radius: 6 + // Clicking in here sets the state to the default state, returning the image to + // its initial position MouseArea { anchors.fill: parent; onClicked: page.state = '' } } - // Another target region. Clicking in here sets the state to 'Position1' Rectangle { - id: position1 + id: middleRightRect + anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } width: 64; height: 64 - radius: 6 - color: "Transparent"; border.color: "Gray" + color: "Transparent"; border.color: "Gray"; radius: 6 - MouseArea { anchors.fill: parent; onClicked: page.state = 'Position1' } + // Clicking in here sets the state to 'middleRight' + MouseArea { anchors.fill: parent; onClicked: page.state = 'middleRight' } } - // Another target region. Clicking in here sets the state to 'Position2' Rectangle { - id: position2 + id: bottomLeftRect + anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } width: 64; height: 64 - radius: 6 - color: "Transparent"; border.color: "Gray" + color: "Transparent"; border.color: "Gray"; radius: 6 - MouseArea { anchors.fill: parent; onClicked: page.state = 'Position2' } + // Clicking in here sets the state to 'bottomLeft' + MouseArea { anchors.fill: parent; onClicked: page.state = 'bottomLeft' } } - // The image which will be moved when my state changes - Image { id: user; source: "user.png"; x: initialPosition.x; y: initialPosition.y } - states: [ - // In state 'Position1', change the 'user' item position to rect2's position. + // In state 'middleRight', move the image to middleRightRect State { - name: "Position1" - PropertyChanges { target: user; x: position1.x; y: position1.y } + name: "middleRight" + PropertyChanges { target: userIcon; x: middleRightRect.x; y: middleRightRect.y } }, - // In state 'Position2', change the 'user' item position to rect3's position. + // In state 'bottomLeft', move the image to bottomLeftRect State { - name: "Position2" - PropertyChanges { target: user; x: position2.x; y: position2.y } + name: "bottomLeft" + PropertyChanges { target: userIcon; x: bottomLeftRect.x; y: bottomLeftRect.y } } ] - // transitions define how the properties change. + // Transitions define how the properties change when the item moves between each state transitions: [ - // When transitioning to 'Position1' move x,y over a duration of 1 second, + + // When transitioning to 'middleRight' move x,y over a duration of 1 second, // with OutBounce easing function. Transition { - from: "*"; to: "Position1" + from: "*"; to: "middleRight" NumberAnimation { properties: "x,y"; easing.type: "OutBounce"; duration: 1000 } }, - // When transitioning to 'Position2' move x,y over a duration of 2 seconds, + + // When transitioning to 'bottomLeft' move x,y over a duration of 2 seconds, // with InOutQuad easing function. Transition { - from: "*"; to: "Position2" + from: "*"; to: "bottomLeft" NumberAnimation { properties: "x,y"; easing.type: "InOutQuad"; duration: 2000 } }, + // For any other state changes move x,y linearly over duration of 200ms. Transition { NumberAnimation { properties: "x,y"; duration: 200 } diff --git a/examples/declarative/tic-tac-toe/content/Button.qml b/examples/declarative/tic-tac-toe/content/Button.qml index 56e5ecd..ecf18cd 100644 --- a/examples/declarative/tic-tac-toe/content/Button.qml +++ b/examples/declarative/tic-tac-toe/content/Button.qml @@ -9,7 +9,7 @@ Rectangle { property string darkCol: "darkgray" property string lightCol: "white" - width: txtItem.width + 20; height: txtItem.height + 6 + width: buttonLabel.width + 20; height: buttonLabel.height + 6 border { width: 1; color: Qt.darker(mainCol) } radius: 8; color: mainCol @@ -28,12 +28,10 @@ Rectangle { MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { - id: txtItem + id: buttonLabel anchors.centerIn: container text: container.text; - color: "blue" - style: Text.Outline; styleColor: "white" - font.pixelSize: 14; font.bold: true + font.pixelSize: 14 } } diff --git a/examples/declarative/tic-tac-toe/tic-tac-toe.qml b/examples/declarative/tic-tac-toe/tic-tac-toe.qml index 62bb56f..dd13052 100644 --- a/examples/declarative/tic-tac-toe/tic-tac-toe.qml +++ b/examples/declarative/tic-tac-toe/tic-tac-toe.qml @@ -5,8 +5,8 @@ import "content/tic-tac-toe.js" as Logic Item { id: game - property bool show: false; - property real difficulty: 1.0; //chance it will actually think + property bool show: false + property real difficulty: 1.0 //chance it will actually think width: 440 height: 480 @@ -50,17 +50,17 @@ Item { Button { text: "Hard" - onClicked: game.difficulty=1.0; + onClicked: game.difficulty = 1.0; down: game.difficulty == 1.0 } Button { text: "Moderate" - onClicked: game.difficulty=0.8; + onClicked: game.difficulty = 0.8; down: game.difficulty == 0.8 } Button { text: "Easy" - onClicked: game.difficulty=0.2; + onClicked: game.difficulty = 0.2; down: game.difficulty == 0.2 } } diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 15348ed..dc325ce 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -1127,20 +1127,21 @@ void QDeclarativeVisualDataModel::_q_itemsChanged(int index, int count, const QList<int> &roles) { Q_D(QDeclarativeVisualDataModel); - // XXX - highly inefficient - for (int ii = index; ii < index + count; ++ii) { - - if (QObject *item = d->m_cache.item(ii)) { - QDeclarativeVisualDataModelData *data = d->data(item); + for (QHash<int,QDeclarativeVisualDataModelPrivate::ObjectRef>::ConstIterator iter = d->m_cache.begin(); + iter != d->m_cache.end(); ++iter) { + const int idx = iter.key(); + if (idx >= index && idx < index+count) { + QDeclarativeVisualDataModelPrivate::ObjectRef objRef = *iter; + QDeclarativeVisualDataModelData *data = d->data(objRef.obj); for (int roleIdx = 0; roleIdx < roles.count(); ++roleIdx) { int role = roles.at(roleIdx); int propId = data->propForRole(role); if (propId != -1) { if (d->m_listModelInterface) { - data->setValue(propId, d->m_listModelInterface->data(ii, QList<int>() << role).value(role)); + data->setValue(propId, d->m_listModelInterface->data(idx, QList<int>() << role).value(role)); } else if (d->m_abstractItemModel) { - QModelIndex index = d->m_abstractItemModel->index(ii, 0, d->m_root); + QModelIndex index = d->m_abstractItemModel->index(idx, 0, d->m_root); data->setValue(propId, d->m_abstractItemModel->data(index, role)); } } diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index ae74fc0..3e5c0ae 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -110,19 +110,19 @@ void tst_examples::namingConvention(const QDir &d) return; } - QStringList files = d.entryList(QStringList() << QLatin1String("*.qml"), + QStringList files = d.entryList(QStringList() << QLatin1String("*.qml"), QDir::Files); bool seenQml = !files.isEmpty(); bool seenLowercase = false; foreach (const QString &file, files) { - if (file.at(0).isLower()) + if (file.at(0).isLower()) seenLowercase = true; } if (!seenQml) { - QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot | + QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks); foreach (const QString &dir, dirs) { QDir sub = d; @@ -153,7 +153,7 @@ QStringList tst_examples::findQmlFiles(const QDir &d) QStringList rv; - QStringList files = d.entryList(QStringList() << QLatin1String("*.qml"), + QStringList files = d.entryList(QStringList() << QLatin1String("*.qml"), QDir::Files); foreach (const QString &file, files) { if (file.at(0).isLower()) { @@ -161,7 +161,7 @@ QStringList tst_examples::findQmlFiles(const QDir &d) } } - QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot | + QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks); foreach (const QString &dir, dirs) { QDir sub = d; @@ -175,26 +175,30 @@ QStringList tst_examples::findQmlFiles(const QDir &d) /* -This test runs all the examples in the declarative UI source tree and ensures +This test runs all the examples in the declarative UI source tree and ensures that they start and exit cleanly. Examples are any .qml files under the examples/ or demos/ directory that start -with a lower case letter. +with a lower case letter. */ #ifndef CONCURRENT void tst_examples::examples_data() { QTest::addColumn<QString>("file"); - QString examples = QLibraryInfo::location(QLibraryInfo::ExamplesPath); - QString demos = QLibraryInfo::location(QLibraryInfo::DemosPath); + QString examples = QLatin1String(SRCDIR) + "/../../../../demos/declarative/"; + QString demos = QLatin1String(SRCDIR) + "/../../../../examples/declarative/"; QString snippets = QLatin1String(SRCDIR) + "/../../../../doc/src/snippets/"; + qWarning() << examples << demos << snippets; + QStringList files; files << findQmlFiles(QDir(examples)); files << findQmlFiles(QDir(demos)); files << findQmlFiles(QDir(snippets)); + qWarning() << files; + foreach (const QString &file, files) QTest::newRow(file.toLatin1().constData()) << file; } @@ -223,7 +227,7 @@ void Example::run() QFileInfo testdata(script+".qml"); QStringList arguments; arguments << "-script" << (testdata.exists() ? script : QLatin1String(SRCDIR "/data/dummytest")) - << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure" + << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure" << file; #ifdef Q_WS_QWS arguments << "-qws"; @@ -238,7 +242,7 @@ void Example::run() if (p.exitStatus() != QProcess::NormalExit || p.exitCode() != 0) qWarning() << p.readAllStandardOutput() << p.readAllStandardError(); - + if (p.exitStatus() != QProcess::NormalExit || p.exitCode() != 0) { result = Fail; @@ -255,8 +259,8 @@ void tst_examples::examples() #ifdef CONCURRENT QThreadPool::globalInstance()->setMaxThreadCount(5); - QString examples = QLibraryInfo::location(QLibraryInfo::ExamplesPath); - QString demos = QLibraryInfo::location(QLibraryInfo::DemosPath); + QString examples = QLatin1String(SRCDIR) + "/../../../../demos/declarative/"; + QString demos = QLatin1String(SRCDIR) + "/../../../../examples/declarative/"; QString snippets = QLatin1String(SRCDIR) + "/../../../../doc/src/snippets/"; QStringList files; @@ -283,7 +287,7 @@ void tst_examples::examples() sync.waitForFinished(); - for (int ii = 0; ii < tests.count(); ++ii) + for (int ii = 0; ii < tests.count(); ++ii) QVERIFY(tests.at(ii).result == Example::Pass); #else @@ -296,7 +300,7 @@ void tst_examples::examples() QFileInfo testdata(script+".qml"); QStringList arguments; arguments << "-script" << (testdata.exists() ? script : QLatin1String(SRCDIR "/data/dummytest")) - << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure" + << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure" << file; #ifdef Q_WS_QWS arguments << "-qws"; |