From 31feeb0aa28f89d66c4af874d8e556141bb6c1f4 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 11 Nov 2009 13:44:35 +1000 Subject: Make QmlPropertyMap public --- src/declarative/util/qmlpropertymap.cpp | 2 +- src/declarative/util/qmlpropertymap.h | 90 +++++++++++++++++++++++++++++++++ src/declarative/util/qmlpropertymap_p.h | 90 --------------------------------- src/declarative/util/util.pri | 2 +- 4 files changed, 92 insertions(+), 92 deletions(-) create mode 100644 src/declarative/util/qmlpropertymap.h delete mode 100644 src/declarative/util/qmlpropertymap_p.h diff --git a/src/declarative/util/qmlpropertymap.cpp b/src/declarative/util/qmlpropertymap.cpp index 8abf09f..c0e3340 100644 --- a/src/declarative/util/qmlpropertymap.cpp +++ b/src/declarative/util/qmlpropertymap.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlpropertymap_p.h" +#include "qmlpropertymap.h" #include #include diff --git a/src/declarative/util/qmlpropertymap.h b/src/declarative/util/qmlpropertymap.h new file mode 100644 index 0000000..bb397fe --- /dev/null +++ b/src/declarative/util/qmlpropertymap.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 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 QMLPROPERTYMAP_H +#define QMLPROPERTYMAP_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlPropertyMapPrivate; +class Q_DECLARATIVE_EXPORT QmlPropertyMap : public QObject +{ + Q_OBJECT +public: + QmlPropertyMap(QObject *parent = 0); + virtual ~QmlPropertyMap(); + + QVariant value(const QString &key) const; + void insert(const QString &key, const QVariant &value); + void clear(const QString &key); + + Q_INVOKABLE QStringList keys() const; + + int count() const; + int size() const; + bool isEmpty() const; + bool contains(const QString &key) const; + + QVariant &operator[](const QString &key); + const QVariant operator[](const QString &key) const; + +Q_SIGNALS: + void valueChanged(const QString &key); + +private: + Q_DECLARE_PRIVATE(QmlPropertyMap) + Q_DISABLE_COPY(QmlPropertyMap) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/declarative/util/qmlpropertymap_p.h b/src/declarative/util/qmlpropertymap_p.h deleted file mode 100644 index bb397fe..0000000 --- a/src/declarative/util/qmlpropertymap_p.h +++ /dev/null @@ -1,90 +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 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 QMLPROPERTYMAP_H -#define QMLPROPERTYMAP_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlPropertyMapPrivate; -class Q_DECLARATIVE_EXPORT QmlPropertyMap : public QObject -{ - Q_OBJECT -public: - QmlPropertyMap(QObject *parent = 0); - virtual ~QmlPropertyMap(); - - QVariant value(const QString &key) const; - void insert(const QString &key, const QVariant &value); - void clear(const QString &key); - - Q_INVOKABLE QStringList keys() const; - - int count() const; - int size() const; - bool isEmpty() const; - bool contains(const QString &key) const; - - QVariant &operator[](const QString &key); - const QVariant operator[](const QString &key) const; - -Q_SIGNALS: - void valueChanged(const QString &key); - -private: - Q_DECLARE_PRIVATE(QmlPropertyMap) - Q_DISABLE_COPY(QmlPropertyMap) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index f955ef6..e043cca 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -48,5 +48,5 @@ HEADERS += \ util/qmltimeline_p_p.h \ util/qmltimer_p.h \ util/qmlbind_p.h \ - util/qmlpropertymap_p.h \ + util/qmlpropertymap.h \ util/qmlpixmapcache_p.h -- cgit v0.12 From 6ac7ce79b6041a7c35d08cb28f775dead9701c4b Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 11 Nov 2009 17:40:55 +1000 Subject: Update SameGame tutorial to discuss offline storage Also removed the \target and got the navigation set up properly. Task-number: QT-2375 --- doc/src/declarative/advtutorial.qdoc | 8 +++---- doc/src/declarative/advtutorial1.qdoc | 5 ++--- doc/src/declarative/advtutorial2.qdoc | 4 ++-- doc/src/declarative/advtutorial3.qdoc | 4 ++-- doc/src/declarative/advtutorial4.qdoc | 25 +++++++++++++++------- .../samegame/samegame4/content/samegame.js | 4 +++- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/doc/src/declarative/advtutorial.qdoc b/doc/src/declarative/advtutorial.qdoc index 21eab92..c796633 100644 --- a/doc/src/declarative/advtutorial.qdoc +++ b/doc/src/declarative/advtutorial.qdoc @@ -53,10 +53,10 @@ The results of the individual steps are in the $QTDIR/examples/declarative/tutor Tutorial chapters: \list -\o \l {advtutorial1}{Advanced Tutorial 1 - Basic Game Screen and Block} -\o \l {advtutorial2}{Advanced Tutorial 2 - Dynamically create the Blocks} -\o \l {advtutorial3}{Advanced Tutorial 3 - Implement the Game Logic} -\o \l {advtutorial4}{Advanced Tutorial 4 - Finishing Touches} +\o \l {Advanced Tutorial 1 - Creating the Game Canvas and Blocks} +\o \l {Advanced Tutorial 2 - Populating the Game Canvas} +\o \l {Advanced Tutorial 3 - Implementing the Game Logic} +\o \l {Advanced Tutorial 4 - Finishing Touches} \endlist */ diff --git a/doc/src/declarative/advtutorial1.qdoc b/doc/src/declarative/advtutorial1.qdoc index 1d47615..66fa607 100644 --- a/doc/src/declarative/advtutorial1.qdoc +++ b/doc/src/declarative/advtutorial1.qdoc @@ -42,8 +42,7 @@ /*! \page advtutorial1.html \example declarative/tutorials/samegame/samegame1 -\target advtutorial1 -\title Advanced Tutorial 1 - Creating the Game canvas and block +\title Advanced Tutorial 1 - Creating the Game Canvas and Blocks The first step is to create the items in your application. In Same Game we have a main game screen and the blocks that populate it. @@ -79,6 +78,6 @@ You should be familiar with all that goes on in these files so far. This is a very basic start and doesn't move at all - next we will populate the game canvas with some blocks. -[\l {advtutorial.html}{Advanced Tutorial}] [Next: \l {advtutorial2}{Advanced Tutorial 2}] +[\l {advtutorial.html}{Advanced Tutorial}] [Next: \l {Advanced Tutorial 2 - Populating the Game Canvas}] */ diff --git a/doc/src/declarative/advtutorial2.qdoc b/doc/src/declarative/advtutorial2.qdoc index 0265446..abfdbc6 100644 --- a/doc/src/declarative/advtutorial2.qdoc +++ b/doc/src/declarative/advtutorial2.qdoc @@ -41,7 +41,7 @@ /*! \page advtutorial2.html -\target advtutorial2 +\example declarative/tutorials/samegame/samegame2 \title Advanced Tutorial 2 - Populating the Game Canvas Now that we've written some basic elements, let's start writing the game. The @@ -103,6 +103,6 @@ by adding a script element to it. With those two changes, and the script file, you are now dynamically creating a field of blocks you can play with. They don't do anything now though; the next chapter will add the game mechanics. -[Previous: \l {advtutorial1}{Advanced Tutorial 1}] [\l {advtutorial.html}{Advanced Tutorial}] [Next: \l {advtutorial3}{Advanced Tutorial 3}] +[Previous: \l {Advanced Tutorial 1 - Creating the Game canvas and block}] [\l {advtutorial.html}{Advanced Tutorial}] [Next: \l {Advanced Tutorial 3 - Implementing the Game Logic}] */ diff --git a/doc/src/declarative/advtutorial3.qdoc b/doc/src/declarative/advtutorial3.qdoc index ea504aa..0d236e4 100644 --- a/doc/src/declarative/advtutorial3.qdoc +++ b/doc/src/declarative/advtutorial3.qdoc @@ -41,7 +41,7 @@ /*! \page advtutorial3.html -\target advtutorial3 +\example declarative/tutorials/samegame/samegame3 \title Advanced Tutorial 3 - Implementing the Game Logic To the \c initBoard function we added clearing the board beforehand, so that clicking new game won't leave the previous game @@ -111,7 +111,7 @@ The game works, but it's a little boring right now. Where's the smooth animated If you were a QML expert you could have written these in for the first iteration, but in this tutorial they've been saved until the next chapter - where your application becomes alive! -[Previous: \l {advtutorial2}{Advanced Tutorial 2}] [\l {advtutorial.html}{Advanced Tutorial}] [Next: \l {advtutorial4}{Advanced Tutorial 4}] +[Previous: \l {Advanced Tutorial 2 - Populating the Game Canvas}] [\l {advtutorial.html}{Advanced Tutorial}] [Next: \l {Advanced Tutorial 4 - Finishing Touches}] */ diff --git a/doc/src/declarative/advtutorial4.qdoc b/doc/src/declarative/advtutorial4.qdoc index 5f8c0e9..f4724d8 100644 --- a/doc/src/declarative/advtutorial4.qdoc +++ b/doc/src/declarative/advtutorial4.qdoc @@ -41,7 +41,7 @@ /*! \page advtutorial4.html -\target advtutorial4 +\example declarative/tutorials/samegame/samegame4 \title Advanced Tutorial 4 - Finishing Touches Now we're going to do two things to liven the game up. Animate the blocks and add a web-based high score system. @@ -118,17 +118,26 @@ player's actions. The end result is shown below: \image declarative-adv-tutorial4.gif +\section2 Offline High Scores +Another extension we might want for the game is some way of storing and retrieving high scores. This tutorial contains both online and offline high score storage. + +For better high score data, we want the name and time of the player. The time is obtained in the script fairly simply, but we +have to ask the player for their name. We thus re-use the dialog QML file to pop up a dialog asking for the player's name (and +if they exit this dialog without entering it they have a way to opt out of posting their high score). When the dialog is closed we store the name and high score, using the code below. + +\snippet declarative/tutorials/samegame/samegame4/content/samegame.js 2 + +For offline storage, we use the HTML 5 offline storage javascript API to maintain a persistant SQL database unique to this application. This first line in this function calls the function for the web-based high scores, described later, if it has been setup. Next we create an offline storage database for the high scores using openDatabase and prepare the data and SQL query that we want to use to save it. The offline storage API uses SQL queries for data manipulation and retrival, and in the db.transaction call we use three SQL queries to initialize the database (if necessary), and then add to and retrieve high scores. To use the returned data, we turn it into a string with one line per row returned, and show a dialog containing that string. For a more detailed explanation of the offline storage API in QML, consult the global object documentation. + +This is one way of storing and displaying high scores locally, but not the only way. A more complex alternative would have been to create a high score dialog component, and pass the results to it for processing and display (instead of resusing the Dialog). This would allow a more themable dialog that could present the high scores better. If your QML is the UI for a C++ application, you could also have passed the score to a C++ function to store it locally in a variety of ways, including a simple format without SQL. + \section2 Web-based High Scores -Another extension we might want for the game is some way of storing and retrieving high scores. In this tutorial we'll show you -how to integrate a web enabled high score storage into your QML application. The implementation we've done is very +You've seen how to store high scores locally, but it is also easy to integrate a web enabled high score storage into your QML application. This tutorial also shows you how to communicate the high scores to a web server. The implementation we've done is very simple - the high score data is posted to a php script running on a server somewhere, and that server then stores it and displays it to visitors. You could request an XML or QML file from that same server, which contained and displayed the scores, -but that's beyond the scope of this tutorial. +but that's beyond the scope of this tutorial. The php script we've used is available in the examples directory. -For better high score data, we want the name and time of the player. The time is obtained in the script fairly simply, but we -have to ask the player for their name. We thus re-use the dialog QML file to pop up a dialog asking for the player's name (and -if they exit this dialog without entering it they have a way to opt out of posting their high score). When the dialog is closed, if the player entered their name we can send the data to the web service in the following snippet out of the script file: \snippet declarative/tutorials/samegame/samegame4/content/samegame.js 1 @@ -145,5 +154,5 @@ By following this tutorial you've now ben shown how to write a fully functional written in a script file and with both many fluid animations and being web-enabled. Congratulations, you should now be skilled enough to write your own QML applications. -[Previous: \l {advtutorial3}{Advanced Tutorial 3}] [\l {advtutorial.html}{Advanced Tutorial}] +[Previous: \l {Advanced Tutorial 3 - Implementing the Game Logic}] [\l {advtutorial.html}{Advanced Tutorial}] */ diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js index 58de55f..d5778fe 100755 --- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js @@ -5,7 +5,7 @@ var maxY = 15; var maxIndex = maxX*maxY; var board = new Array(maxIndex); var tileSrc = "content/BoomBlock.qml"; -var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php"; +//var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php"; var scoresURL = ""; var timer; var component = createComponent(tileSrc); @@ -206,6 +206,7 @@ function createBlock(xIdx,yIdx){ return true; } +//![2] function saveHighScore(name) { if(scoresURL!="") sendHighScore(name); @@ -241,6 +242,7 @@ function saveHighScore(name) { } ); } +//![2] //![1] function sendHighScore(name) { -- cgit v0.12 From edd306f681d3c53d00c0a99c68775615cc0a2d5e Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 11 Nov 2009 12:56:47 +1000 Subject: Fix minehunt demo --- demos/declarative/minehunt/main.cpp | 1 + demos/declarative/minehunt/minehunt | Bin 0 -> 302213 bytes demos/declarative/minehunt/minehunt.qml | 5 +++-- demos/declarative/minehunt/test.qml | 13 +++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100755 demos/declarative/minehunt/minehunt create mode 100644 demos/declarative/minehunt/test.qml diff --git a/demos/declarative/minehunt/main.cpp b/demos/declarative/minehunt/main.cpp index 5e67cc1..895648f 100644 --- a/demos/declarative/minehunt/main.cpp +++ b/demos/declarative/minehunt/main.cpp @@ -174,6 +174,7 @@ MyWidget::MyWidget(int width, int height, QWidget *parent, Qt::WindowFlags flags QmlContext *ctxt = canvas->rootContext(); ctxt->addDefaultObject(this); + ctxt->setContextProperty("tiles", QVariant::fromValue*>(&_tiles));//QTBUG-5675 canvas->execute(); } diff --git a/demos/declarative/minehunt/minehunt b/demos/declarative/minehunt/minehunt new file mode 100755 index 0000000..94584a9 Binary files /dev/null and b/demos/declarative/minehunt/minehunt differ diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index 596e82d..ff00d83 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -107,8 +107,8 @@ Item { onPressed: { field.clickx = flipable.parent.x; field.clicky = flipable.parent.y; - row = Math.floor(index/9); - col = index - (Math.floor(index/9) * 9); + var row = Math.floor(index/9); + var col = index - (Math.floor(index/9) * 9); if (mouse.button==undefined || mouse.button==Qt.RightButton) { flag(row,col); } else { @@ -131,6 +131,7 @@ Item { anchors.verticalCenter: parent.verticalCenter } Repeater { + id: repeater model: tiles x: 1 y: 1 diff --git a/demos/declarative/minehunt/test.qml b/demos/declarative/minehunt/test.qml new file mode 100644 index 0000000..11ed182 --- /dev/null +++ b/demos/declarative/minehunt/test.qml @@ -0,0 +1,13 @@ +import Qt 4.6 + + Image { + source: "pics/front.png" + width: 40 + height: 40 + Image { + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + source: "pics/flag.png" + opacity: 1 + } + } -- cgit v0.12 From d1d900561a9a51bd44707546e691b013341e221c Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 11 Nov 2009 17:47:21 +1000 Subject: Extend repeater test ObjectList doesn't pass yet. Unsure if it should be passing, or if we should rectify the docs. --- tests/auto/declarative/repeater/data/intmodel.qml | 17 ++++++++++ tests/auto/declarative/repeater/data/objlist.qml | 21 +++++++++++++ tests/auto/declarative/repeater/tst_repeater.cpp | 38 +++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 tests/auto/declarative/repeater/data/intmodel.qml create mode 100644 tests/auto/declarative/repeater/data/objlist.qml diff --git a/tests/auto/declarative/repeater/data/intmodel.qml b/tests/auto/declarative/repeater/data/intmodel.qml new file mode 100644 index 0000000..a779079 --- /dev/null +++ b/tests/auto/declarative/repeater/data/intmodel.qml @@ -0,0 +1,17 @@ +import Qt 4.6 + +Rectangle { + id: container + objectName: "container" + width: 240 + height: 320 + color: "white" + Repeater { + id: repeater + objectName: "repeater" + model: testData + Component { + Item{} + } + } +} diff --git a/tests/auto/declarative/repeater/data/objlist.qml b/tests/auto/declarative/repeater/data/objlist.qml new file mode 100644 index 0000000..ecc6d02 --- /dev/null +++ b/tests/auto/declarative/repeater/data/objlist.qml @@ -0,0 +1,21 @@ +import Qt 4.6 + +Rectangle { + id: container + objectName: "container" + width: 240 + height: 320 + color: "white" + Repeater { + id: repeater + objectName: "repeater" + model: testData + property int errors: 0 + property int instantiated: 0 + Component { + Item{ + Component.onCompleted: {if(index!=modelData.idx) repeater.errors += 1; repeater.instantiated++} + } + } + } +} diff --git a/tests/auto/declarative/repeater/tst_repeater.cpp b/tests/auto/declarative/repeater/tst_repeater.cpp index dc0f1be..e002ee1 100644 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ b/tests/auto/declarative/repeater/tst_repeater.cpp @@ -52,6 +52,8 @@ public: tst_QmlGraphicsRepeater(); private slots: + void numberModel(); + void objectList(); void stringList(); private: @@ -64,6 +66,42 @@ tst_QmlGraphicsRepeater::tst_QmlGraphicsRepeater() { } +void tst_QmlGraphicsRepeater::numberModel() +{ + QmlView *canvas = createView(SRCDIR "/data/intmodel.qml"); + canvas->execute(); + qApp->processEvents(); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testData", 5); + + QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QVERIFY(repeater != 0); + QCOMPARE(repeater->parentItem()->childItems().count(), 5+1); +} + +void tst_QmlGraphicsRepeater::objectList() +{ + QmlView *canvas = createView(SRCDIR "/data/objlist.qml"); + + QObjectList* data = new QObjectList; + for(int i=0; i<100; i++){ + *data << new QObject(); + data->back()->setProperty("idx", i); + } + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testData", QVariant::fromValue(data)); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QVERIFY(repeater != 0); + QCOMPARE(repeater->property("errors").toInt(), 0);//If this fails either they are out of order or can't find the object's data + QCOMPARE(repeater->property("instantiated").toInt(), 100); +} + /* The Repeater element creates children at its own position in its parent's stacking order. In this test we insert a repeater between two other Text -- cgit v0.12