From 749407354ebfaaf87f9b10e6bc6e394c04f7c4f0 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 18 May 2010 09:38:26 +1000 Subject: Fix to work with file: URLs (eg. from qml -qmlbrowser) --- tools/qml/qmlruntime.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 9700090..490fa34 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -906,6 +906,7 @@ bool QDeclarativeViewer::open(const QString& file_or_url) QString fileName = url.toLocalFile(); if (!fileName.isEmpty()) { + fi.setFile(fileName); if (fi.exists()) { if (fi.suffix().toLower() != QLatin1String("qml")) { qWarning() << "qml cannot open non-QML file" << fileName; -- cgit v0.12 From 0bdfdd4d2c5cc0298faa974b83dcd623da989452 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 18 May 2010 09:39:06 +1000 Subject: doc models from plugins --- doc/src/declarative/extending.qdoc | 5 ++++- doc/src/declarative/qdeclarativemodels.qdoc | 23 ++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc index 5b695f7..574b0b2 100644 --- a/doc/src/declarative/extending.qdoc +++ b/doc/src/declarative/extending.qdoc @@ -61,8 +61,11 @@ QML for their own independent use. The QML snippet shown above instantiates one \c Person instance and sets the \c name and \c shoeSize properties on it. Everything in QML ultimately comes down to either instantiating an object instance, or assigning a property a value. + QML relies heavily on Qt's meta object system and can only instantiate classes -that derive from QObject. +that derive from QObject. For visual element types, this will usually mean a subclass +of QDeclarativeItem; for models used with the view elements, a subclass of QAbstractItemModel; +and for abitrary objects with properties, a direct subclass of QObject. The QML engine has no intrinsic knowledge of any class types. Instead the programmer must register the C++ types with their corresponding QML names. diff --git a/doc/src/declarative/qdeclarativemodels.qdoc b/doc/src/declarative/qdeclarativemodels.qdoc index 788d417..109d390 100644 --- a/doc/src/declarative/qdeclarativemodels.qdoc +++ b/doc/src/declarative/qdeclarativemodels.qdoc @@ -99,7 +99,8 @@ There are a number of QML elements that operate using data models: \endlist QML supports several types of data model, which may be provided by QML -or C++ (via QDeclarativeContext::setContextProperty(), for example). +or C++ (via QDeclarativeContext::setContextProperty() or as plugin types, +for example). \section1 QML Data Models @@ -210,8 +211,13 @@ will be positioned by the view. \section1 C++ Data Models +Models defined in C++ can be made available to QML either from a C++ application or from a +\l{QDeclarativeExtensionPlugin}{QML C++ plugin}. + \section2 QAbstractItemModel +A model can be defined by subclassing QAbstractItemModel. + QAbstractItemModel provides the roles set via the QAbstractItemModel::setRoleNames() method. The default role names set by Qt are: @@ -227,7 +233,18 @@ The default role names set by Qt are: \o decoration \endtable -QAbstractItemModel presents a heirachy of tables. Views currently provided by QML +The model could be made available to QML either directly: + +\code +QDeclarativeContext *ctxt = view.rootContext(); +MyModel *model = new MyModel; // subclass of QAbstractItemModel +ctxt->setContextProperty("myModel", model); +\endcode + +or by registering the subclass as a new QML type in +a \l{QDeclarativeExtensionPlugin}{QML C++ plugin}. + +QAbstractItemModel presents a heirachy of tables, but views currently provided by QML can only display list data. In order to display child lists of a heirachical model the VisualDataModel element provides several properties and functions for use @@ -242,7 +259,7 @@ with models of type QAbstractItemModel: \section2 QStringList -QStringList provides the contents of the list via the \e modelData role: +A model may be a simple QStringList, which provides the contents of the list via the \e modelData role: \table \row -- cgit v0.12 From e971948611b4790f0b3a05a29d8e7ab2e72e95f4 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 18 May 2010 09:46:09 +1000 Subject: Move stuff from QML viewer to plugins. --- src/imports/dirmodel/dirmodel.pro | 26 ++ src/imports/dirmodel/plugin.cpp | 65 ++++ .../dirmodel/qdeclarativefolderlistmodel.cpp | 413 ++++++++++++++++++++ src/imports/dirmodel/qdeclarativefolderlistmodel.h | 122 ++++++ src/imports/dirmodel/qmldir | 1 + src/imports/imports.pro | 2 +- tools/qml/content/Browser.qml | 1 + tools/qml/main.cpp | 2 - tools/qml/qdeclarativefolderlistmodel.cpp | 423 --------------------- tools/qml/qdeclarativefolderlistmodel.h | 128 ------- tools/qml/qml.pri | 2 - 11 files changed, 629 insertions(+), 556 deletions(-) create mode 100644 src/imports/dirmodel/dirmodel.pro create mode 100644 src/imports/dirmodel/plugin.cpp create mode 100644 src/imports/dirmodel/qdeclarativefolderlistmodel.cpp create mode 100644 src/imports/dirmodel/qdeclarativefolderlistmodel.h create mode 100644 src/imports/dirmodel/qmldir delete mode 100644 tools/qml/qdeclarativefolderlistmodel.cpp delete mode 100644 tools/qml/qdeclarativefolderlistmodel.h diff --git a/src/imports/dirmodel/dirmodel.pro b/src/imports/dirmodel/dirmodel.pro new file mode 100644 index 0000000..03f3a1a --- /dev/null +++ b/src/imports/dirmodel/dirmodel.pro @@ -0,0 +1,26 @@ +TARGET = qmlviewerplugin +TARGETPATH = Qt/labs/folderlistmodel +include(../qimportbase.pri) + +QT += declarative script + +SOURCES += qdeclarativefolderlistmodel.cpp plugin.cpp +HEADERS += qdeclarativefolderlistmodel.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 = qmlviewerplugin.dll qmldir + importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH + + DEPLOYMENT = importFiles +} + +INSTALLS += target qmldir diff --git a/src/imports/dirmodel/plugin.cpp b/src/imports/dirmodel/plugin.cpp new file mode 100644 index 0000000..61bf354 --- /dev/null +++ b/src/imports/dirmodel/plugin.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 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 "qdeclarativefolderlistmodel.h" + +QT_BEGIN_NAMESPACE + +class QmlViewerPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.folderlistmodel")); + qmlRegisterType(uri,1,0,"FolderListModel"); + } +}; + +QT_END_NAMESPACE + +#include "plugin.moc" + +Q_EXPORT_PLUGIN2(qmlviewerplugin, QT_PREPEND_NAMESPACE(QmlViewerPlugin)); + diff --git a/src/imports/dirmodel/qdeclarativefolderlistmodel.cpp b/src/imports/dirmodel/qdeclarativefolderlistmodel.cpp new file mode 100644 index 0000000..11f9733 --- /dev/null +++ b/src/imports/dirmodel/qdeclarativefolderlistmodel.cpp @@ -0,0 +1,413 @@ +/**************************************************************************** +** +** 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 "qdeclarativefolderlistmodel.h" +#include +#include +#include + +class QDeclarativeFolderListModelPrivate +{ +public: + QDeclarativeFolderListModelPrivate() + : sortField(QDeclarativeFolderListModel::Name), sortReversed(false), count(0) { + nameFilters << QLatin1String("*"); + } + + void updateSorting() { + QDir::SortFlags flags = 0; + switch(sortField) { + case QDeclarativeFolderListModel::Unsorted: + flags |= QDir::Unsorted; + break; + case QDeclarativeFolderListModel::Name: + flags |= QDir::Name; + break; + case QDeclarativeFolderListModel::Time: + flags |= QDir::Time; + break; + case QDeclarativeFolderListModel::Size: + flags |= QDir::Size; + break; + case QDeclarativeFolderListModel::Type: + flags |= QDir::Type; + break; + } + + if (sortReversed) + flags |= QDir::Reversed; + + model.setSorting(flags); + } + + QDirModel model; + QUrl folder; + QStringList nameFilters; + QModelIndex folderIndex; + QDeclarativeFolderListModel::SortField sortField; + bool sortReversed; + int count; +}; + +/*! + \qmlclass FolderListModel + \brief The FolderListModel provides a model of the contents of a folder in a filesystem. + + FolderListModel provides access to the local filesystem. The \e folder property + specifies the folder to list. + + Qt uses "/" as a universal directory separator in the same way that "/" is + used as a path separator in URLs. If you always use "/" as a directory + separator, Qt will translate your paths to conform to the underlying + operating system. + + The roles available are: + \list + \o fileName + \o filePath + \endlist + + Additionally a file entry can be differentiated from a folder entry + via the \l isFolder() method. +*/ + +QDeclarativeFolderListModel::QDeclarativeFolderListModel(QObject *parent) + : QListModelInterface(parent) +{ + d = new QDeclarativeFolderListModelPrivate; + d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives | QDir::NoDotAndDotDot); + connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int)) + , this, SLOT(inserted(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(rowsRemoved(const QModelIndex&,int,int)) + , this, SLOT(removed(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) + , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); + connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh())); + connect(&d->model, SIGNAL(layoutChanged()), this, SLOT(refresh())); +} + +QDeclarativeFolderListModel::~QDeclarativeFolderListModel() +{ + delete d; +} + +QHash QDeclarativeFolderListModel::data(int index, const QList &roles) const +{ + Q_UNUSED(roles); + QHash folderData; + QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); + if (modelIndex.isValid()) { + folderData[QDirModel::FileNameRole] = d->model.data(modelIndex, QDirModel::FileNameRole); + folderData[QDirModel::FilePathRole] = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); + } + + return folderData; +} + +QVariant QDeclarativeFolderListModel::data(int index, int role) const +{ + QVariant rv; + QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); + if (modelIndex.isValid()) { + if (role == QDirModel::FileNameRole) + rv = d->model.data(modelIndex, QDirModel::FileNameRole); + else if (role == QDirModel::FilePathRole) + rv = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); + } + + return rv; +} + +int QDeclarativeFolderListModel::count() const +{ + return d->count; +} + +QList QDeclarativeFolderListModel::roles() const +{ + QList r; + r << QDirModel::FileNameRole; + r << QDirModel::FilePathRole; + return r; +} + +QString QDeclarativeFolderListModel::toString(int role) const +{ + switch (role) { + case QDirModel::FileNameRole: + return QLatin1String("fileName"); + case QDirModel::FilePathRole: + return QLatin1String("filePath"); + } + + return QString(); +} + +/*! + \qmlproperty string FolderListModel::folder + + The \a folder property holds the folder the model is currently providing. + + It is a URL, but must be a file: or qrc: URL (or relative to such a URL). +*/ +QUrl QDeclarativeFolderListModel::folder() const +{ + return d->folder; +} + +void QDeclarativeFolderListModel::setFolder(const QUrl &folder) +{ + if (folder == d->folder) + return; + QModelIndex index = d->model.index(folder.toLocalFile()); + if (index.isValid() && d->model.isDir(index)) { + d->folder = folder; + QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); + emit folderChanged(); + } +} + +QUrl QDeclarativeFolderListModel::parentFolder() const +{ + QUrl r; + QString localFile = d->folder.toLocalFile(); + if (!localFile.isEmpty()) { + QDir dir(localFile); +#if defined(Q_OS_SYMBIAN) + if (dir.isRoot()) + dir.setPath(""); + else +#endif + dir.cdUp(); + r = d->folder; + r.setPath(dir.path()); + } else { + int pos = d->folder.path().lastIndexOf(QLatin1Char('/')); + if (pos == -1) + return QUrl(); + r = d->folder; + r.setPath(d->folder.path().left(pos)); + } + return r; +} + +/*! + \qmlproperty list FolderListModel::nameFilters + + The \a nameFilters property contains a list of filename filters. + The filters may include the ? and * wildcards. + + The example below filters on PNG and JPEG files: + + \code + FolderListModel { + nameFilters: [ "*.png", "*.jpg" ] + } + \endcode +*/ +QStringList QDeclarativeFolderListModel::nameFilters() const +{ + return d->nameFilters; +} + +void QDeclarativeFolderListModel::setNameFilters(const QStringList &filters) +{ + d->nameFilters = filters; + d->model.setNameFilters(d->nameFilters); +} + +void QDeclarativeFolderListModel::classBegin() +{ +} + +void QDeclarativeFolderListModel::componentComplete() +{ + if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile())) + setFolder(QUrl(QLatin1String("file://")+QDir::currentPath())); + + if (!d->folderIndex.isValid()) + QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); +} + +QDeclarativeFolderListModel::SortField QDeclarativeFolderListModel::sortField() const +{ + return d->sortField; +} + +void QDeclarativeFolderListModel::setSortField(SortField field) +{ + if (field != d->sortField) { + d->sortField = field; + d->updateSorting(); + } +} + +bool QDeclarativeFolderListModel::sortReversed() const +{ + return d->sortReversed; +} + +void QDeclarativeFolderListModel::setSortReversed(bool rev) +{ + if (rev != d->sortReversed) { + d->sortReversed = rev; + d->updateSorting(); + } +} + +/*! + \qmlmethod bool FolderListModel::isFolder(int index) + + Returns true if the entry \a index is a folder; otherwise + returns false. +*/ +bool QDeclarativeFolderListModel::isFolder(int index) const +{ + if (index != -1) { + QModelIndex idx = d->model.index(index, 0, d->folderIndex); + if (idx.isValid()) + return d->model.isDir(idx); + } + return false; +} + +void QDeclarativeFolderListModel::refresh() +{ + d->folderIndex = QModelIndex(); + if (d->count) { + int tmpCount = d->count; + d->count = 0; + emit itemsRemoved(0, tmpCount); + } + d->folderIndex = d->model.index(d->folder.toLocalFile()); + d->count = d->model.rowCount(d->folderIndex); + if (d->count) { + emit itemsInserted(0, d->count); + } +} + +void QDeclarativeFolderListModel::inserted(const QModelIndex &index, int start, int end) +{ + if (index == d->folderIndex) { + d->count = d->model.rowCount(d->folderIndex); + emit itemsInserted(start, end - start + 1); + } +} + +void QDeclarativeFolderListModel::removed(const QModelIndex &index, int start, int end) +{ + if (index == d->folderIndex) { + d->count = d->model.rowCount(d->folderIndex); + emit itemsRemoved(start, end - start + 1); + } +} + +void QDeclarativeFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) +{ + if (start.parent() == d->folderIndex) + emit itemsChanged(start.row(), end.row() - start.row() + 1, roles()); +} + +/*! + \qmlproperty bool FolderListModel::showDirs + + If true (the default), directories are included in the model. + + Note that the nameFilters are ignored for directories. +*/ +bool QDeclarativeFolderListModel::showDirs() const +{ + return d->model.filter() & QDir::AllDirs; +} + +void QDeclarativeFolderListModel::setShowDirs(bool on) +{ + if (!(d->model.filter() & QDir::AllDirs) == !on) + return; + if (on) + d->model.setFilter(d->model.filter() | QDir::AllDirs | QDir::Drives); + else + d->model.setFilter(d->model.filter() & ~(QDir::AllDirs | QDir::Drives)); +} + +/*! + \qmlproperty bool FolderListModel::showDotAndDotDot + + If true, the "." and ".." directories are included in the model. + + The default is false. +*/ +bool QDeclarativeFolderListModel::showDotAndDotDot() const +{ + return !(d->model.filter() & QDir::NoDotAndDotDot); +} + +void QDeclarativeFolderListModel::setShowDotAndDotDot(bool on) +{ + if (!(d->model.filter() & QDir::NoDotAndDotDot) == on) + return; + if (on) + d->model.setFilter(d->model.filter() & ~QDir::NoDotAndDotDot); + else + d->model.setFilter(d->model.filter() | QDir::NoDotAndDotDot); +} + +/*! + \qmlproperty bool FolderListModel::showOnlyReadable + + If true, only readable files and directories are shown. + + The default is false. +*/ +bool QDeclarativeFolderListModel::showOnlyReadable() const +{ + return d->model.filter() & QDir::Readable; +} + +void QDeclarativeFolderListModel::setShowOnlyReadable(bool on) +{ + if (!(d->model.filter() & QDir::Readable) == !on) + return; + if (on) + d->model.setFilter(d->model.filter() | QDir::Readable); + else + d->model.setFilter(d->model.filter() & ~QDir::Readable); +} diff --git a/src/imports/dirmodel/qdeclarativefolderlistmodel.h b/src/imports/dirmodel/qdeclarativefolderlistmodel.h new file mode 100644 index 0000000..0ca935c --- /dev/null +++ b/src/imports/dirmodel/qdeclarativefolderlistmodel.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEFOLDERLISTMODEL_H +#define QDECLARATIVEFOLDERLISTMODEL_H + +#include +#include +#include +#include + +class QDeclarativeContext; +class QModelIndex; + +class QDeclarativeFolderListModelPrivate; +class QDeclarativeFolderListModel : public QListModelInterface, public QDeclarativeParserStatus +{ + Q_OBJECT + Q_INTERFACES(QDeclarativeParserStatus) + + Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged) + Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged) + Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) + Q_PROPERTY(SortField sortField READ sortField WRITE setSortField) + Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed) + Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs) + Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) + Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) + +public: + QDeclarativeFolderListModel(QObject *parent = 0); + ~QDeclarativeFolderListModel(); + + virtual QHash data(int index, const QList &roles = (QList())) const; + virtual QVariant data(int index, int role) const; + virtual int count() const; + virtual QList roles() const; + virtual QString toString(int role) const; + + QUrl folder() const; + void setFolder(const QUrl &folder); + + QUrl parentFolder() const; + + QStringList nameFilters() const; + void setNameFilters(const QStringList &filters); + + virtual void classBegin(); + virtual void componentComplete(); + + Q_INVOKABLE bool isFolder(int index) const; + + enum SortField { Unsorted, Name, Time, Size, Type }; + SortField sortField() const; + void setSortField(SortField field); + Q_ENUMS(SortField) + + bool sortReversed() const; + void setSortReversed(bool rev); + + bool showDirs() const; + void setShowDirs(bool); + bool showDotAndDotDot() const; + void setShowDotAndDotDot(bool); + bool showOnlyReadable() const; + void setShowOnlyReadable(bool); + +Q_SIGNALS: + void folderChanged(); + +private Q_SLOTS: + void refresh(); + void inserted(const QModelIndex &index, int start, int end); + void removed(const QModelIndex &index, int start, int end); + void dataChanged(const QModelIndex &start, const QModelIndex &end); + +private: + Q_DISABLE_COPY(QDeclarativeFolderListModel) + QDeclarativeFolderListModelPrivate *d; +}; + +QML_DECLARE_TYPE(QDeclarativeFolderListModel) + +#endif // QDECLARATIVEFOLDERLISTMODEL_H diff --git a/src/imports/dirmodel/qmldir b/src/imports/dirmodel/qmldir new file mode 100644 index 0000000..0be644f --- /dev/null +++ b/src/imports/dirmodel/qmldir @@ -0,0 +1 @@ +plugin qmlviewerplugin diff --git a/src/imports/imports.pro b/src/imports/imports.pro index a9d600e..df43b76 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -SUBDIRS += particles gestures +SUBDIRS += dirmodel particles gestures contains(QT_CONFIG, webkit): SUBDIRS += webkit contains(QT_CONFIG, mediaservices): SUBDIRS += multimedia diff --git a/tools/qml/content/Browser.qml b/tools/qml/content/Browser.qml index c3a2cc0..fe7ad9c 100644 --- a/tools/qml/content/Browser.qml +++ b/tools/qml/content/Browser.qml @@ -1,4 +1,5 @@ import Qt 4.7 +import Qt.labs.folderlistmodel 1.0 Rectangle { id: root diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 380f5cc..0b3f2f0 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -50,7 +50,6 @@ #include #include #include "qdeclarativetester.h" -#include "qdeclarativefolderlistmodel.h" QT_USE_NAMESPACE @@ -203,7 +202,6 @@ int main(int argc, char ** argv) QDeclarativeViewer::registerTypes(); QDeclarativeTester::registerTypes(); - QDeclarativeFolderListModel::registerTypes(); bool frameless = false; QString fileName; diff --git a/tools/qml/qdeclarativefolderlistmodel.cpp b/tools/qml/qdeclarativefolderlistmodel.cpp deleted file mode 100644 index 7ac25d6..0000000 --- a/tools/qml/qdeclarativefolderlistmodel.cpp +++ /dev/null @@ -1,423 +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 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 "qdeclarativefolderlistmodel.h" -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QDeclarativeFolderListModelPrivate -{ -public: - QDeclarativeFolderListModelPrivate() - : sortField(QDeclarativeFolderListModel::Name), sortReversed(false), count(0) { - nameFilters << QLatin1String("*"); - } - - void updateSorting() { - QDir::SortFlags flags = 0; - switch(sortField) { - case QDeclarativeFolderListModel::Unsorted: - flags |= QDir::Unsorted; - break; - case QDeclarativeFolderListModel::Name: - flags |= QDir::Name; - break; - case QDeclarativeFolderListModel::Time: - flags |= QDir::Time; - break; - case QDeclarativeFolderListModel::Size: - flags |= QDir::Size; - break; - case QDeclarativeFolderListModel::Type: - flags |= QDir::Type; - break; - } - - if (sortReversed) - flags |= QDir::Reversed; - - model.setSorting(flags); - } - - QDirModel model; - QUrl folder; - QStringList nameFilters; - QModelIndex folderIndex; - QDeclarativeFolderListModel::SortField sortField; - bool sortReversed; - int count; -}; - -/*! - \qmlclass FolderListModel - \brief The FolderListModel provides a model of the contents of a folder in a filesystem. - - FolderListModel provides access to the local filesystem. The \e folder property - specifies the folder to list. - - Qt uses "/" as a universal directory separator in the same way that "/" is - used as a path separator in URLs. If you always use "/" as a directory - separator, Qt will translate your paths to conform to the underlying - operating system. - - The roles available are: - \list - \o fileName - \o filePath - \endlist - - Additionally a file entry can be differentiated from a folder entry - via the \l isFolder() method. -*/ - -QDeclarativeFolderListModel::QDeclarativeFolderListModel(QObject *parent) - : QListModelInterface(parent) -{ - d = new QDeclarativeFolderListModelPrivate; - d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives | QDir::NoDotAndDotDot); - connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int)) - , this, SLOT(inserted(const QModelIndex&,int,int))); - connect(&d->model, SIGNAL(rowsRemoved(const QModelIndex&,int,int)) - , this, SLOT(removed(const QModelIndex&,int,int))); - connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) - , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); - connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh())); - connect(&d->model, SIGNAL(layoutChanged()), this, SLOT(refresh())); -} - -QDeclarativeFolderListModel::~QDeclarativeFolderListModel() -{ - delete d; -} - -QHash QDeclarativeFolderListModel::data(int index, const QList &roles) const -{ - Q_UNUSED(roles); - QHash folderData; - QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); - if (modelIndex.isValid()) { - folderData[QDirModel::FileNameRole] = d->model.data(modelIndex, QDirModel::FileNameRole); - folderData[QDirModel::FilePathRole] = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); - } - - return folderData; -} - -QVariant QDeclarativeFolderListModel::data(int index, int role) const -{ - QVariant rv; - QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); - if (modelIndex.isValid()) { - if (role == QDirModel::FileNameRole) - rv = d->model.data(modelIndex, QDirModel::FileNameRole); - else if (role == QDirModel::FilePathRole) - rv = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); - } - - return rv; -} - -int QDeclarativeFolderListModel::count() const -{ - return d->count; -} - -QList QDeclarativeFolderListModel::roles() const -{ - QList r; - r << QDirModel::FileNameRole; - r << QDirModel::FilePathRole; - return r; -} - -QString QDeclarativeFolderListModel::toString(int role) const -{ - switch (role) { - case QDirModel::FileNameRole: - return QLatin1String("fileName"); - case QDirModel::FilePathRole: - return QLatin1String("filePath"); - } - - return QString(); -} - -/*! - \qmlproperty string FolderListModel::folder - - The \a folder property holds the folder the model is currently providing. - - It is a URL, but must be a file: or qrc: URL (or relative to such a URL). -*/ -QUrl QDeclarativeFolderListModel::folder() const -{ - return d->folder; -} - -void QDeclarativeFolderListModel::setFolder(const QUrl &folder) -{ - if (folder == d->folder) - return; - QModelIndex index = d->model.index(folder.toLocalFile()); - if (index.isValid() && d->model.isDir(index)) { - d->folder = folder; - QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); - emit folderChanged(); - } -} - -QUrl QDeclarativeFolderListModel::parentFolder() const -{ - QUrl r; - QString localFile = d->folder.toLocalFile(); - if (!localFile.isEmpty()) { - QDir dir(localFile); -#if defined(Q_OS_SYMBIAN) - if (dir.isRoot()) - dir.setPath(""); - else -#endif - dir.cdUp(); - r = d->folder; - r.setPath(dir.path()); - } else { - int pos = d->folder.path().lastIndexOf(QLatin1Char('/')); - if (pos == -1) - return QUrl(); - r = d->folder; - r.setPath(d->folder.path().left(pos)); - } - return r; -} - -/*! - \qmlproperty list FolderListModel::nameFilters - - The \a nameFilters property contains a list of filename filters. - The filters may include the ? and * wildcards. - - The example below filters on PNG and JPEG files: - - \code - FolderListModel { - nameFilters: [ "*.png", "*.jpg" ] - } - \endcode -*/ -QStringList QDeclarativeFolderListModel::nameFilters() const -{ - return d->nameFilters; -} - -void QDeclarativeFolderListModel::setNameFilters(const QStringList &filters) -{ - d->nameFilters = filters; - d->model.setNameFilters(d->nameFilters); -} - -void QDeclarativeFolderListModel::classBegin() -{ -} - -void QDeclarativeFolderListModel::componentComplete() -{ - if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile())) - setFolder(QUrl(QLatin1String("file://")+QDir::currentPath())); - - if (!d->folderIndex.isValid()) - QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); -} - -QDeclarativeFolderListModel::SortField QDeclarativeFolderListModel::sortField() const -{ - return d->sortField; -} - -void QDeclarativeFolderListModel::setSortField(SortField field) -{ - if (field != d->sortField) { - d->sortField = field; - d->updateSorting(); - } -} - -bool QDeclarativeFolderListModel::sortReversed() const -{ - return d->sortReversed; -} - -void QDeclarativeFolderListModel::setSortReversed(bool rev) -{ - if (rev != d->sortReversed) { - d->sortReversed = rev; - d->updateSorting(); - } -} - -/*! - \qmlmethod bool FolderListModel::isFolder(int index) - - Returns true if the entry \a index is a folder; otherwise - returns false. -*/ -bool QDeclarativeFolderListModel::isFolder(int index) const -{ - if (index != -1) { - QModelIndex idx = d->model.index(index, 0, d->folderIndex); - if (idx.isValid()) - return d->model.isDir(idx); - } - return false; -} - -void QDeclarativeFolderListModel::refresh() -{ - d->folderIndex = QModelIndex(); - if (d->count) { - int tmpCount = d->count; - d->count = 0; - emit itemsRemoved(0, tmpCount); - } - d->folderIndex = d->model.index(d->folder.toLocalFile()); - d->count = d->model.rowCount(d->folderIndex); - if (d->count) { - emit itemsInserted(0, d->count); - } -} - -void QDeclarativeFolderListModel::inserted(const QModelIndex &index, int start, int end) -{ - if (index == d->folderIndex) { - d->count = d->model.rowCount(d->folderIndex); - emit itemsInserted(start, end - start + 1); - } -} - -void QDeclarativeFolderListModel::removed(const QModelIndex &index, int start, int end) -{ - if (index == d->folderIndex) { - d->count = d->model.rowCount(d->folderIndex); - emit itemsRemoved(start, end - start + 1); - } -} - -void QDeclarativeFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) -{ - if (start.parent() == d->folderIndex) - emit itemsChanged(start.row(), end.row() - start.row() + 1, roles()); -} - -/*! - \qmlproperty bool FolderListModel::showDirs - - If true (the default), directories are included in the model. - - Note that the nameFilters are ignored for directories. -*/ -bool QDeclarativeFolderListModel::showDirs() const -{ - return d->model.filter() & QDir::AllDirs; -} - -void QDeclarativeFolderListModel::setShowDirs(bool on) -{ - if (!(d->model.filter() & QDir::AllDirs) == !on) - return; - if (on) - d->model.setFilter(d->model.filter() | QDir::AllDirs | QDir::Drives); - else - d->model.setFilter(d->model.filter() & ~(QDir::AllDirs | QDir::Drives)); -} - -/*! - \qmlproperty bool FolderListModel::showDotAndDotDot - - If true, the "." and ".." directories are included in the model. - - The default is false. -*/ -bool QDeclarativeFolderListModel::showDotAndDotDot() const -{ - return !(d->model.filter() & QDir::NoDotAndDotDot); -} - -void QDeclarativeFolderListModel::setShowDotAndDotDot(bool on) -{ - if (!(d->model.filter() & QDir::NoDotAndDotDot) == on) - return; - if (on) - d->model.setFilter(d->model.filter() & ~QDir::NoDotAndDotDot); - else - d->model.setFilter(d->model.filter() | QDir::NoDotAndDotDot); -} - -/*! - \qmlproperty bool FolderListModel::showOnlyReadable - - If true, only readable files and directories are shown. - - The default is false. -*/ -bool QDeclarativeFolderListModel::showOnlyReadable() const -{ - return d->model.filter() & QDir::Readable; -} - -void QDeclarativeFolderListModel::setShowOnlyReadable(bool on) -{ - if (!(d->model.filter() & QDir::Readable) == !on) - return; - if (on) - d->model.setFilter(d->model.filter() | QDir::Readable); - else - d->model.setFilter(d->model.filter() & ~QDir::Readable); -} - -void QDeclarativeFolderListModel::registerTypes() -{ - qmlRegisterType("Qt",4,7,"FolderListModel"); -} - -QT_END_NAMESPACE - diff --git a/tools/qml/qdeclarativefolderlistmodel.h b/tools/qml/qdeclarativefolderlistmodel.h deleted file mode 100644 index 1ecc784..0000000 --- a/tools/qml/qdeclarativefolderlistmodel.h +++ /dev/null @@ -1,128 +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 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$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEFOLDERLISTMODEL_H -#define QDECLARATIVEFOLDERLISTMODEL_H - -#include -#include -#include -#include "../../src/declarative/3rdparty/qlistmodelinterface_p.h" - -QT_BEGIN_NAMESPACE - -class QDeclarativeContext; -class QModelIndex; - -class QDeclarativeFolderListModelPrivate; -class QDeclarativeFolderListModel : public QListModelInterface, public QDeclarativeParserStatus -{ - Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) - - Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged) - Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged) - Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) - Q_PROPERTY(SortField sortField READ sortField WRITE setSortField) - Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed) - Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs) - Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) - Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) - -public: - QDeclarativeFolderListModel(QObject *parent = 0); - ~QDeclarativeFolderListModel(); - - static void registerTypes(); - - virtual QHash data(int index, const QList &roles = (QList())) const; - virtual QVariant data(int index, int role) const; - virtual int count() const; - virtual QList roles() const; - virtual QString toString(int role) const; - - QUrl folder() const; - void setFolder(const QUrl &folder); - - QUrl parentFolder() const; - - QStringList nameFilters() const; - void setNameFilters(const QStringList &filters); - - virtual void classBegin(); - virtual void componentComplete(); - - Q_INVOKABLE bool isFolder(int index) const; - - enum SortField { Unsorted, Name, Time, Size, Type }; - SortField sortField() const; - void setSortField(SortField field); - Q_ENUMS(SortField) - - bool sortReversed() const; - void setSortReversed(bool rev); - - bool showDirs() const; - void setShowDirs(bool); - bool showDotAndDotDot() const; - void setShowDotAndDotDot(bool); - bool showOnlyReadable() const; - void setShowOnlyReadable(bool); - -Q_SIGNALS: - void folderChanged(); - -private Q_SLOTS: - void refresh(); - void inserted(const QModelIndex &index, int start, int end); - void removed(const QModelIndex &index, int start, int end); - void dataChanged(const QModelIndex &start, const QModelIndex &end); - -private: - Q_DISABLE_COPY(QDeclarativeFolderListModel) - QDeclarativeFolderListModelPrivate *d; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeFolderListModel) - -#endif // QDECLARATIVEFOLDERLISTMODEL_H diff --git a/tools/qml/qml.pri b/tools/qml/qml.pri index a2058c7..5e3e74b 100644 --- a/tools/qml/qml.pri +++ b/tools/qml/qml.pri @@ -10,12 +10,10 @@ HEADERS += $$PWD/qmlruntime.h \ $$PWD/proxysettings.h \ $$PWD/qdeclarativetester.h \ $$PWD/deviceorientation.h \ - $$PWD/qdeclarativefolderlistmodel.h \ $$PWD/loggerwidget.h SOURCES += $$PWD/qmlruntime.cpp \ $$PWD/proxysettings.cpp \ $$PWD/qdeclarativetester.cpp \ - $$PWD/qdeclarativefolderlistmodel.cpp \ $$PWD/loggerwidget.cpp RESOURCES = $$PWD/qmlruntime.qrc -- cgit v0.12 From 4530e4c8cf1ddb1ac92fc04fa5d25b0b78308534 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 18 May 2010 09:06:47 +1000 Subject: Set raster + gl viewport as the default for OS X. This setup seems to work around most rendering bugs and timing issues. Task-number: QTBUG-10544 --- tools/qml/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 380f5cc..0ddce72 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -181,7 +181,7 @@ int main(int argc, char ** argv) atexit(showWarnings); #endif -#if defined (Q_WS_X11) +#if defined (Q_WS_X11) || defined (Q_WS_MAC) //### default to using raster graphics backend for now bool gsSpecified = false; for (int i = 0; i < argc; ++i) { @@ -236,6 +236,10 @@ int main(int argc, char ** argv) useNativeFileBrowser = false; #endif +#if defined(Q_WS_MAC) + useGL = true; +#endif + for (int i = 1; i < argc; ++i) { bool lastArg = (i == argc - 1); QString arg = argv[i]; -- cgit v0.12 From 273024e58d90bb9b3a5da0161f884f1af22d75df Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 18 May 2010 10:43:25 +1000 Subject: Use QDeclarativeScriptString for ParentChange. So that scope resolution is correct, e.g. "width: parent.width-10;" in a ParentChange works correctly. Task-number: QTBUG-10675 --- src/declarative/qml/qdeclarativecompiler.cpp | 2 +- .../util/qdeclarativestateoperations.cpp | 192 ++-- .../util/qdeclarativestateoperations_p.h | 36 +- .../qdeclarativelanguage/data/scriptString.3.qml | 5 + .../qdeclarativelanguage/data/scriptString.4.qml | 5 + .../qdeclarativelanguage/data/scriptString.5.qml | 5 + .../tst_qdeclarativelanguage.cpp | 53 +- .../parentAnimation2/data/parentAnimation2.0.png | Bin 0 -> 2046 bytes .../parentAnimation2/data/parentAnimation2.1.png | Bin 0 -> 2059 bytes .../parentAnimation2/data/parentAnimation2.2.png | Bin 0 -> 2052 bytes .../parentAnimation2/data/parentAnimation2.3.png | Bin 0 -> 2011 bytes .../parentAnimation2/data/parentAnimation2.qml | 1023 ++++++++++++++++++++ .../parentAnimation2/parentAnimation2.qml | 64 ++ tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp | 1 + 14 files changed, 1301 insertions(+), 85 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/scriptString.3.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/scriptString.4.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/scriptString.5.qml create mode 100644 tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.0.png create mode 100644 tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.1.png create mode 100644 tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.2.png create mode 100644 tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.3.png create mode 100644 tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.qml create mode 100644 tests/auto/declarative/qmlvisual/animation/parentAnimation2/parentAnimation2.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index a43b9ac..19c12ff 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1893,7 +1893,7 @@ bool QDeclarativeCompiler::buildScriptStringProperty(QDeclarativeParser::Propert if (prop->values.count() > 1) COMPILE_EXCEPTION(prop->values.at(1), tr( "Cannot assign multiple values to a script property")); - if (prop->values.at(0)->object || !prop->values.at(0)->value.isScript()) + if (prop->values.at(0)->object) COMPILE_EXCEPTION(prop->values.at(0), tr( "Invalid property assignment: script expected")); obj->addScriptStringProperty(prop, ctxt.stack); diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 0326f6d..efef52d 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -75,12 +75,12 @@ public: QDeclarativeItem *rewindParent; QDeclarativeItem *rewindStackBefore; - QDeclarativeNullableValue x; - QDeclarativeNullableValue y; - QDeclarativeNullableValue width; - QDeclarativeNullableValue height; - QDeclarativeNullableValue scale; - QDeclarativeNullableValue rotation; + QDeclarativeNullableValue xString; + QDeclarativeNullableValue yString; + QDeclarativeNullableValue widthString; + QDeclarativeNullableValue heightString; + QDeclarativeNullableValue scaleString; + QDeclarativeNullableValue rotationString; void doChange(QDeclarativeItem *targetParent, QDeclarativeItem *stackBefore = 0); }; @@ -196,112 +196,112 @@ QDeclarativeParentChange::~QDeclarativeParentChange() These properties hold the new position, size, scale, and rotation for the item in this state. */ -qreal QDeclarativeParentChange::x() const +QDeclarativeScriptString QDeclarativeParentChange::x() const { Q_D(const QDeclarativeParentChange); - return d->x.isNull ? qreal(0.) : d->x.value; + return d->xString.value; } -void QDeclarativeParentChange::setX(qreal x) +void QDeclarativeParentChange::setX(QDeclarativeScriptString x) { Q_D(QDeclarativeParentChange); - d->x = x; + d->xString = x; } bool QDeclarativeParentChange::xIsSet() const { Q_D(const QDeclarativeParentChange); - return d->x.isValid(); + return d->xString.isValid(); } -qreal QDeclarativeParentChange::y() const +QDeclarativeScriptString QDeclarativeParentChange::y() const { Q_D(const QDeclarativeParentChange); - return d->y.isNull ? qreal(0.) : d->y.value; + return d->yString.value; } -void QDeclarativeParentChange::setY(qreal y) +void QDeclarativeParentChange::setY(QDeclarativeScriptString y) { Q_D(QDeclarativeParentChange); - d->y = y; + d->yString = y; } bool QDeclarativeParentChange::yIsSet() const { Q_D(const QDeclarativeParentChange); - return d->y.isValid(); + return d->yString.isValid(); } -qreal QDeclarativeParentChange::width() const +QDeclarativeScriptString QDeclarativeParentChange::width() const { Q_D(const QDeclarativeParentChange); - return d->width.isNull ? qreal(0.) : d->width.value; + return d->widthString.value; } -void QDeclarativeParentChange::setWidth(qreal width) +void QDeclarativeParentChange::setWidth(QDeclarativeScriptString width) { Q_D(QDeclarativeParentChange); - d->width = width; + d->widthString = width; } bool QDeclarativeParentChange::widthIsSet() const { Q_D(const QDeclarativeParentChange); - return d->width.isValid(); + return d->widthString.isValid(); } -qreal QDeclarativeParentChange::height() const +QDeclarativeScriptString QDeclarativeParentChange::height() const { Q_D(const QDeclarativeParentChange); - return d->height.isNull ? qreal(0.) : d->height.value; + return d->heightString.value; } -void QDeclarativeParentChange::setHeight(qreal height) +void QDeclarativeParentChange::setHeight(QDeclarativeScriptString height) { Q_D(QDeclarativeParentChange); - d->height = height; + d->heightString = height; } bool QDeclarativeParentChange::heightIsSet() const { Q_D(const QDeclarativeParentChange); - return d->height.isValid(); + return d->heightString.isValid(); } -qreal QDeclarativeParentChange::scale() const +QDeclarativeScriptString QDeclarativeParentChange::scale() const { Q_D(const QDeclarativeParentChange); - return d->scale.isNull ? qreal(1.) : d->scale.value; + return d->scaleString.value; } -void QDeclarativeParentChange::setScale(qreal scale) +void QDeclarativeParentChange::setScale(QDeclarativeScriptString scale) { Q_D(QDeclarativeParentChange); - d->scale = scale; + d->scaleString = scale; } bool QDeclarativeParentChange::scaleIsSet() const { Q_D(const QDeclarativeParentChange); - return d->scale.isValid(); + return d->scaleString.isValid(); } -qreal QDeclarativeParentChange::rotation() const +QDeclarativeScriptString QDeclarativeParentChange::rotation() const { Q_D(const QDeclarativeParentChange); - return d->rotation.isNull ? qreal(0.) : d->rotation.value; + return d->rotationString.value; } -void QDeclarativeParentChange::setRotation(qreal rotation) +void QDeclarativeParentChange::setRotation(QDeclarativeScriptString rotation) { Q_D(QDeclarativeParentChange); - d->rotation = rotation; + d->rotationString = rotation; } bool QDeclarativeParentChange::rotationIsSet() const { Q_D(const QDeclarativeParentChange); - return d->rotation.isValid(); + return d->rotationString.isValid(); } QDeclarativeItem *QDeclarativeParentChange::originalParent() const @@ -356,34 +356,118 @@ QDeclarativeStateOperation::ActionList QDeclarativeParentChange::actions() a.event = this; actions << a; - if (d->x.isValid()) { - QDeclarativeAction xa(d->target, QLatin1String("x"), x()); - actions << xa; + if (d->xString.isValid()) { + bool ok = false; + QString script = d->xString.value.script(); + qreal x = script.toFloat(&ok); + if (ok) { + QDeclarativeAction xa(d->target, QLatin1String("x"), x); + actions << xa; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("x"))); + QDeclarativeAction xa; + xa.property = newBinding->property(); + xa.toBinding = newBinding; + xa.fromValue = xa.property.read(); + xa.deletableToBinding = true; + actions << xa; + } } - if (d->y.isValid()) { - QDeclarativeAction ya(d->target, QLatin1String("y"), y()); - actions << ya; + if (d->yString.isValid()) { + bool ok = false; + QString script = d->yString.value.script(); + qreal y = script.toFloat(&ok); + if (ok) { + QDeclarativeAction ya(d->target, QLatin1String("y"), y); + actions << ya; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("y"))); + QDeclarativeAction ya; + ya.property = newBinding->property(); + ya.toBinding = newBinding; + ya.fromValue = ya.property.read(); + ya.deletableToBinding = true; + actions << ya; + } } - if (d->scale.isValid()) { - QDeclarativeAction sa(d->target, QLatin1String("scale"), scale()); - actions << sa; + if (d->scaleString.isValid()) { + bool ok = false; + QString script = d->scaleString.value.script(); + qreal scale = script.toFloat(&ok); + if (ok) { + QDeclarativeAction sa(d->target, QLatin1String("scale"), scale); + actions << sa; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("scale"))); + QDeclarativeAction sa; + sa.property = newBinding->property(); + sa.toBinding = newBinding; + sa.fromValue = sa.property.read(); + sa.deletableToBinding = true; + actions << sa; + } } - if (d->rotation.isValid()) { - QDeclarativeAction ra(d->target, QLatin1String("rotation"), rotation()); - actions << ra; + if (d->rotationString.isValid()) { + bool ok = false; + QString script = d->rotationString.value.script(); + qreal rotation = script.toFloat(&ok); + if (ok) { + QDeclarativeAction ra(d->target, QLatin1String("rotation"), rotation); + actions << ra; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("rotation"))); + QDeclarativeAction ra; + ra.property = newBinding->property(); + ra.toBinding = newBinding; + ra.fromValue = ra.property.read(); + ra.deletableToBinding = true; + actions << ra; + } } - if (d->width.isValid()) { - QDeclarativeAction wa(d->target, QLatin1String("width"), width()); - actions << wa; + if (d->widthString.isValid()) { + bool ok = false; + QString script = d->widthString.value.script(); + qreal width = script.toFloat(&ok); + if (ok) { + QDeclarativeAction wa(d->target, QLatin1String("width"), width); + actions << wa; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("width"))); + QDeclarativeAction wa; + wa.property = newBinding->property(); + wa.toBinding = newBinding; + wa.fromValue = wa.property.read(); + wa.deletableToBinding = true; + actions << wa; + } } - if (d->height.isValid()) { - QDeclarativeAction ha(d->target, QLatin1String("height"), height()); - actions << ha; + if (d->heightString.isValid()) { + bool ok = false; + QString script = d->heightString.value.script(); + qreal height = script.toFloat(&ok); + if (ok) { + QDeclarativeAction ha(d->target, QLatin1String("height"), height); + actions << ha; + } else { + QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); + newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("height"))); + QDeclarativeAction ha; + ha.property = newBinding->property(); + ha.toBinding = newBinding; + ha.fromValue = ha.property.read(); + ha.deletableToBinding = true; + actions << ha; + } } return actions; diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h index 21a86f5..05ad052 100644 --- a/src/declarative/util/qdeclarativestateoperations_p.h +++ b/src/declarative/util/qdeclarativestateoperations_p.h @@ -62,12 +62,12 @@ class Q_DECLARATIVE_EXPORT QDeclarativeParentChange : public QDeclarativeStateOp Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject) Q_PROPERTY(QDeclarativeItem *parent READ parent WRITE setParent) - Q_PROPERTY(qreal x READ x WRITE setX) - Q_PROPERTY(qreal y READ y WRITE setY) - Q_PROPERTY(qreal width READ width WRITE setWidth) - Q_PROPERTY(qreal height READ height WRITE setHeight) - Q_PROPERTY(qreal scale READ scale WRITE setScale) - Q_PROPERTY(qreal rotation READ rotation WRITE setRotation) + Q_PROPERTY(QDeclarativeScriptString x READ x WRITE setX) + Q_PROPERTY(QDeclarativeScriptString y READ y WRITE setY) + Q_PROPERTY(QDeclarativeScriptString width READ width WRITE setWidth) + Q_PROPERTY(QDeclarativeScriptString height READ height WRITE setHeight) + Q_PROPERTY(QDeclarativeScriptString scale READ scale WRITE setScale) + Q_PROPERTY(QDeclarativeScriptString rotation READ rotation WRITE setRotation) public: QDeclarativeParentChange(QObject *parent=0); ~QDeclarativeParentChange(); @@ -80,28 +80,28 @@ public: QDeclarativeItem *originalParent() const; - qreal x() const; - void setX(qreal x); + QDeclarativeScriptString x() const; + void setX(QDeclarativeScriptString x); bool xIsSet() const; - qreal y() const; - void setY(qreal y); + QDeclarativeScriptString y() const; + void setY(QDeclarativeScriptString y); bool yIsSet() const; - qreal width() const; - void setWidth(qreal width); + QDeclarativeScriptString width() const; + void setWidth(QDeclarativeScriptString width); bool widthIsSet() const; - qreal height() const; - void setHeight(qreal height); + QDeclarativeScriptString height() const; + void setHeight(QDeclarativeScriptString height); bool heightIsSet() const; - qreal scale() const; - void setScale(qreal scale); + QDeclarativeScriptString scale() const; + void setScale(QDeclarativeScriptString scale); bool scaleIsSet() const; - qreal rotation() const; - void setRotation(qreal rotation); + QDeclarativeScriptString rotation() const; + void setRotation(QDeclarativeScriptString rotation); bool rotationIsSet() const; virtual ActionList actions(); diff --git a/tests/auto/declarative/qdeclarativelanguage/data/scriptString.3.qml b/tests/auto/declarative/qdeclarativelanguage/data/scriptString.3.qml new file mode 100644 index 0000000..0de3667 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/scriptString.3.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + scriptProperty: "hello world" +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/scriptString.4.qml b/tests/auto/declarative/qdeclarativelanguage/data/scriptString.4.qml new file mode 100644 index 0000000..0cd82ff --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/scriptString.4.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + scriptProperty: 12.345 +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/scriptString.5.qml b/tests/auto/declarative/qdeclarativelanguage/data/scriptString.5.qml new file mode 100644 index 0000000..3e2f9a4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/scriptString.5.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + scriptProperty: true +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 6b070f5..4434e46 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -1105,19 +1105,48 @@ void tst_qdeclarativelanguage::onDestruction() // Check that assignments to QDeclarativeScriptString properties work void tst_qdeclarativelanguage::scriptString() { - QDeclarativeComponent component(&engine, TEST_FILE("scriptString.qml")); - VERIFY_ERRORS(0); + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptString.qml")); + VERIFY_ERRORS(0); - MyTypeObject *object = qobject_cast(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->scriptProperty().script(), QString("foo + bar")); - QCOMPARE(object->scriptProperty().scopeObject(), qobject_cast(object)); - QCOMPARE(object->scriptProperty().context(), qmlContext(object)); - - QVERIFY(object->grouped() != 0); - QCOMPARE(object->grouped()->script().script(), QString("console.log(1921)")); - QCOMPARE(object->grouped()->script().scopeObject(), qobject_cast(object)); - QCOMPARE(object->grouped()->script().context(), qmlContext(object)); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->scriptProperty().script(), QString("foo + bar")); + QCOMPARE(object->scriptProperty().scopeObject(), qobject_cast(object)); + QCOMPARE(object->scriptProperty().context(), qmlContext(object)); + + QVERIFY(object->grouped() != 0); + QCOMPARE(object->grouped()->script().script(), QString("console.log(1921)")); + QCOMPARE(object->grouped()->script().scopeObject(), qobject_cast(object)); + QCOMPARE(object->grouped()->script().context(), qmlContext(object)); + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptString3.qml")); + VERIFY_ERRORS(0); + + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->scriptProperty().script(), QString("\"hello world\"")); + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptString4.qml")); + VERIFY_ERRORS(0); + + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->scriptProperty().script(), QString("12.345")); + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptString5.qml")); + VERIFY_ERRORS(0); + + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->scriptProperty().script(), QString("true")); + } } // Check that default property assignments are correctly spliced into explicit diff --git a/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.0.png b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.0.png new file mode 100644 index 0000000..135911c Binary files /dev/null and b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.0.png differ diff --git a/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.1.png b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.1.png new file mode 100644 index 0000000..0d71292 Binary files /dev/null and b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.1.png differ diff --git a/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.2.png b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.2.png new file mode 100644 index 0000000..920d992 Binary files /dev/null and b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.2.png differ diff --git a/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.3.png b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.3.png new file mode 100644 index 0000000..1c4d89e Binary files /dev/null and b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.3.png differ diff --git a/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.qml b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.qml new file mode 100644 index 0000000..9e1b923 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/data/parentAnimation2.qml @@ -0,0 +1,1023 @@ +import Qt.VisualTest 4.7 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 32 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 48 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 64 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 80 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 96 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 112 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 128 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 144 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 160 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 176 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 192 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 208 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 224 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 240 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 256 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 272 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 288 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 304 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 320 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 336 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 352 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 368 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 384 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 400 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 416 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 432 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 448 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 464 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 480 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 496 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 512 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 528 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 544 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 560 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 576 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 592 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 608 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 624 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 640 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 656 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 672 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 688 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 704 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 350; y: 182 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 720 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 736 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 752 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 768 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 784 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 800 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 350; y: 182 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 816 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 832 + hash: "9b524b546d250d239ea99dd3319f3d6a" + } + Frame { + msec: 848 + hash: "593300f166c2fd3c325cb35114ca595b" + } + Frame { + msec: 864 + hash: "4451e76e111c99faa77b5fff9a2642fa" + } + Frame { + msec: 880 + hash: "0b4a5675afba935e17eba19e29b709ee" + } + Frame { + msec: 896 + hash: "8682866f0234eebf25aca27a7737c777" + } + Frame { + msec: 912 + hash: "5b3b70dd366bb4c1b5e7d56ce50e59a6" + } + Frame { + msec: 928 + hash: "897394982c93ebcbea68c25cec6d47d3" + } + Frame { + msec: 944 + hash: "23c3c0383a517d33767adeebc53bfa3a" + } + Frame { + msec: 960 + image: "parentAnimation2.0.png" + } + Frame { + msec: 976 + hash: "95b4fe1e5eeffe1673e199308e8ce76c" + } + Frame { + msec: 992 + hash: "dbb9a5aa9f569b97711aa2c1f5ebda47" + } + Frame { + msec: 1008 + hash: "0a5a73409b019e650ea860e1a8e27328" + } + Frame { + msec: 1024 + hash: "496bd0d053522bcf71d506b497ede0d5" + } + Frame { + msec: 1040 + hash: "97a32b4a6c99ffe842c35e903bd23d79" + } + Frame { + msec: 1056 + hash: "496dfbbb0c0c28e108adf4c25341ef11" + } + Frame { + msec: 1072 + hash: "aa2e5eb88b1498f0d36897be2a36b0ff" + } + Frame { + msec: 1088 + hash: "0c6f7b54264ab36cfd5145fb7b30432f" + } + Frame { + msec: 1104 + hash: "797fc3ea1db51f12d900b4e0e4998065" + } + Frame { + msec: 1120 + hash: "2b076b8bc1ec1e2f21a4d7a77c94cfeb" + } + Frame { + msec: 1136 + hash: "8d5888ca1cfba19cea569bd38bada417" + } + Frame { + msec: 1152 + hash: "15ae94de5aa106eaa18d0faefa5d61f5" + } + Frame { + msec: 1168 + hash: "96e90d74d5a7788d5a6da6cfdb92b185" + } + Frame { + msec: 1184 + hash: "5698a5e9e628209fc28644198eac65da" + } + Frame { + msec: 1200 + hash: "074ac8f08de8f22c241e23ad8b89b0f0" + } + Frame { + msec: 1216 + hash: "a49fdf41e9ee1e5d764262d4585af2ff" + } + Frame { + msec: 1232 + hash: "accc9b6573a676a40fcf0129085f6fce" + } + Frame { + msec: 1248 + hash: "1cc956d55f0c382c2f74dcc05a05494f" + } + Frame { + msec: 1264 + hash: "38ff3121566b2c719f47d027fcef8b8e" + } + Frame { + msec: 1280 + hash: "4de97b3361a16ca1710f2e75d5c9de6f" + } + Frame { + msec: 1296 + hash: "dbd1455105630bb8f262140e79ceda1b" + } + Frame { + msec: 1312 + hash: "bcdac4ab71a29b78bfa756b56b8d8414" + } + Frame { + msec: 1328 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1344 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1360 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1376 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1392 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1408 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1424 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1440 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1456 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1472 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1488 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1504 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1520 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1536 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1552 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1568 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1584 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1600 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1616 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1632 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1648 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1664 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1680 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1696 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1712 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 415; y: 121 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1728 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1744 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1760 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1776 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1792 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1808 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1824 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 415; y: 121 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1840 + hash: "f02f73a85532c1dd403d64c50c7e73ca" + } + Frame { + msec: 1856 + hash: "b59fbcfb7db77cf30ea4ff039a9163ae" + } + Frame { + msec: 1872 + hash: "432a76f0663bfd35f6bbeb3fbeb91799" + } + Frame { + msec: 1888 + hash: "098e18005d3a2ff9095587954c92339c" + } + Frame { + msec: 1904 + hash: "069100bf4ec523a9e9d5bf557ffc51d1" + } + Frame { + msec: 1920 + image: "parentAnimation2.1.png" + } + Frame { + msec: 1936 + hash: "60ed700e49bf2c51aba9b44400b56294" + } + Frame { + msec: 1952 + hash: "79aa15dc74668d963f36f28524f4d091" + } + Frame { + msec: 1968 + hash: "6838cb2d728259adc8d91a4a69e35adf" + } + Frame { + msec: 1984 + hash: "3f73c720ce5f1e65fb8537a9beb66d26" + } + Frame { + msec: 2000 + hash: "95d990ccd3e45e780d875aae1f4654f8" + } + Frame { + msec: 2016 + hash: "5389a121571f61e73903305860e60016" + } + Frame { + msec: 2032 + hash: "66f0018b6f35c1c18b28f4959eef96a8" + } + Frame { + msec: 2048 + hash: "c0fa0560a9a5a0f773394c4fd98c9fa3" + } + Frame { + msec: 2064 + hash: "e2d665ae0ac3007520003bb4a24ca708" + } + Frame { + msec: 2080 + hash: "ab6e6976e4214c725f71a4f0ba6d3f68" + } + Frame { + msec: 2096 + hash: "642f48f731f896d0d4b66956485b615b" + } + Frame { + msec: 2112 + hash: "cdc36222978e4361dd3ddc2cba78328d" + } + Frame { + msec: 2128 + hash: "22fe869d83d9d290c4d1702e7553c7aa" + } + Frame { + msec: 2144 + hash: "3cf2b6a4fd5c73c24717a1ce901cfb19" + } + Frame { + msec: 2160 + hash: "ea7ecad2a9b7e6ca9a9d1c9c46e0f6dc" + } + Frame { + msec: 2176 + hash: "3a7e7e2145b40732ef4e18218a959536" + } + Frame { + msec: 2192 + hash: "1386046373ab246ae533aba206ffe502" + } + Frame { + msec: 2208 + hash: "2183072e2117c2bc660767bc67e6c355" + } + Frame { + msec: 2224 + hash: "659c6fedf573d19727f9852a9034e4fe" + } + Frame { + msec: 2240 + hash: "5be4e8fa87593aeb4d59768a61441c37" + } + Frame { + msec: 2256 + hash: "2030b883508d07735b20726d218fd751" + } + Frame { + msec: 2272 + hash: "fd70334fa8a1ff80369cce6aa69255c4" + } + Frame { + msec: 2288 + hash: "be666aafc8a3d2de9ffaff54d9ac15d1" + } + Frame { + msec: 2304 + hash: "3370f2246f679068e40cdb48c92decad" + } + Frame { + msec: 2320 + hash: "f0b4565fd441c071112bdc8225861f76" + } + Frame { + msec: 2336 + hash: "61babd82afc20a3023c2fe483a2e73cb" + } + Frame { + msec: 2352 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2368 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2384 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2400 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2416 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2432 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2448 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2464 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2480 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2496 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2512 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2528 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2544 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2560 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2576 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2592 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2608 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2624 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2640 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2656 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2672 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2688 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2704 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2720 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2736 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2752 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2768 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 207; y: 255 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 2784 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2800 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2816 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2832 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2848 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2864 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2880 + image: "parentAnimation2.2.png" + } + Frame { + msec: 2896 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 207; y: 255 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 2912 + hash: "acab4a79f22ebc8a45759ae282e8f3db" + } + Frame { + msec: 2928 + hash: "608af88c841d6058c3304cc134de0187" + } + Frame { + msec: 2944 + hash: "96a727d6ff02c7baf85865fda9d871bd" + } + Frame { + msec: 2960 + hash: "22cacf109e40b457041d6c2862c4f97f" + } + Frame { + msec: 2976 + hash: "ea2a53381eef8ac75fce23c518f1e261" + } + Frame { + msec: 2992 + hash: "a719237e74e9c40b46cc1f27cca5e286" + } + Frame { + msec: 3008 + hash: "804ef3519ba9852afb0bd4ef793e0006" + } + Frame { + msec: 3024 + hash: "4abc5026f0de1165717bd14630c9d9f6" + } + Frame { + msec: 3040 + hash: "1e4dd04698691932725076073a0bd2e7" + } + Frame { + msec: 3056 + hash: "12aae9dcfd9597ce600588b19bdf5a7d" + } + Frame { + msec: 3072 + hash: "9176b69f7df68d860b7d7aecc2496f09" + } + Frame { + msec: 3088 + hash: "9cba95a510685ab6367ba87246f6c922" + } + Frame { + msec: 3104 + hash: "33ef448b9485fafb7a2af319f9f6e816" + } + Frame { + msec: 3120 + hash: "791760db748e46aceb9f469c33b7bf2f" + } + Frame { + msec: 3136 + hash: "201a00feef1bb445f2fd0ba8ef9467a1" + } + Frame { + msec: 3152 + hash: "6e8962c3cb522f5a45b093f1780d2dae" + } + Frame { + msec: 3168 + hash: "d75cb08203a4f2c05b4dfdca2196e3db" + } + Frame { + msec: 3184 + hash: "0417d681c9b64e2cc252ab6fcf20148b" + } + Frame { + msec: 3200 + hash: "85993e5a91a86cedb8c88819b035b6bb" + } + Frame { + msec: 3216 + hash: "d7a0db647e641df9625b8eb5078a8ec3" + } + Frame { + msec: 3232 + hash: "fa29824ed3fd3d4e0d8036079be6bcf8" + } + Frame { + msec: 3248 + hash: "4fc84a3ae74bb6ab7b0b846c8747eb54" + } + Frame { + msec: 3264 + hash: "a172921ffe15077382db8e8915fb340b" + } + Frame { + msec: 3280 + hash: "480ee71d2407d729814a2e19d4320c59" + } + Frame { + msec: 3296 + hash: "b8cf02a1ad96d5c3354f2b658085ed28" + } + Frame { + msec: 3312 + hash: "80fc0f57f58250f63a77b1988a9e1d2e" + } + Frame { + msec: 3328 + hash: "bc283b5d7c5b88ef447be5992a77b6a9" + } + Frame { + msec: 3344 + hash: "89c86df88dc1a3188d52c1f75b80ccf1" + } + Frame { + msec: 3360 + hash: "84148139d89b45949561321bd6f6c835" + } + Frame { + msec: 3376 + hash: "9118d6933b3f77e0b5b8da2d630152e8" + } + Frame { + msec: 3392 + hash: "2b5f746225053778fb07a606ff113e64" + } + Frame { + msec: 3408 + hash: "0a1ed1bea6ed674826d0a2c3146a1c31" + } + Frame { + msec: 3424 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3440 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3456 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3472 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3488 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3504 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3520 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3536 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3552 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3568 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3584 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3600 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3616 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3632 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3648 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Key { + type: 6 + key: 16777249 + modifiers: 67108864 + text: "" + autorep: false + count: 1 + } + Frame { + msec: 3664 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3680 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3696 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3712 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3728 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3744 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3760 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3776 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3792 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3808 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3824 + hash: "b3bfd7a06d3e246f4256ab5a267360b0" + } + Frame { + msec: 3840 + image: "parentAnimation2.3.png" + } +} diff --git a/tests/auto/declarative/qmlvisual/animation/parentAnimation2/parentAnimation2.qml b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/parentAnimation2.qml new file mode 100644 index 0000000..dfab108 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/animation/parentAnimation2/parentAnimation2.qml @@ -0,0 +1,64 @@ +import Qt 4.7 + +/* +Blue rect fills (with 10px margin) screen, then red, then green, then screen again. +*/ + +Rectangle { + id: whiteRect + width: 640; height: 480; + + Rectangle { + id: redRect + x: 400; y: 50 + width: 100; height: 100 + color: "red" + } + + Rectangle { + id: greenRect + x: 100; y: 150 + width: 200; height: 300 + color: "green" + } + + Rectangle { + id: blueRect + x: 5; y: 5 + width: parent.width-10 + height: parent.height-10 + color: "lightblue" + + //Text { text: "Click me!"; anchors.centerIn: parent } + + MouseArea { + anchors.fill: parent + onClicked: { + switch(blueRect.state) { + case "": blueRect.state = "inRed"; break; + case "inRed": blueRect.state = "inGreen"; break; + case "inGreen": blueRect.state = ""; break; + } + } + } + + states: [ + State { + name: "inRed" + ParentChange { target: blueRect; parent: redRect; x: 5; y: 5; width: parent.width-10; height: parent.height-10 } + PropertyChanges { target: redRect; z: 1 } + }, + State { + name: "inGreen" + ParentChange { target: blueRect; parent: greenRect; x: 5; y: 5; width: parent.width-10; height: parent.height-10 } + PropertyChanges { target: greenRect; z: 1 } + } + ] + + transitions: Transition { + ParentAnimation { target: blueRect; //via: whiteRect; + NumberAnimation { properties: "x, y, width, height"; duration: 500 } + } + } + } +} diff --git a/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp b/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp index 4aad29b..f105692 100644 --- a/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp +++ b/tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp @@ -105,6 +105,7 @@ void tst_qmlvisual::visual_data() files << QT_TEST_SOURCE_DIR "/qdeclarativeborderimage/animated.qml"; files << QT_TEST_SOURCE_DIR "/qdeclarativeflipable/test-flipable.qml"; files << QT_TEST_SOURCE_DIR "/qdeclarativepositioners/usingRepeater.qml"; + files << QT_TEST_SOURCE_DIR "/animation/parentAnimation2/parentAnimation2.qml"; //these are tests we think are stable and useful enough to be run by the CI system files << QT_TEST_SOURCE_DIR "/animation/bindinganimation/bindinganimation.qml"; -- cgit v0.12 From 4fa070d69c84de373eeed79aea569d408757cd52 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 18 May 2010 11:37:20 +1000 Subject: Port from QListModelInterface to QAbstractListModel. --- .../dirmodel/qdeclarativefolderlistmodel.cpp | 76 +++++++++------------- src/imports/dirmodel/qdeclarativefolderlistmodel.h | 19 ++++-- 2 files changed, 44 insertions(+), 51 deletions(-) diff --git a/src/imports/dirmodel/qdeclarativefolderlistmodel.cpp b/src/imports/dirmodel/qdeclarativefolderlistmodel.cpp index 11f9733..50ef4ae 100644 --- a/src/imports/dirmodel/qdeclarativefolderlistmodel.cpp +++ b/src/imports/dirmodel/qdeclarativefolderlistmodel.cpp @@ -110,8 +110,13 @@ public: */ QDeclarativeFolderListModel::QDeclarativeFolderListModel(QObject *parent) - : QListModelInterface(parent) + : QAbstractListModel(parent) { + QHash roles; + roles[FileNameRole] = "fileName"; + roles[FilePathRole] = "filePath"; + setRoleNames(roles); + d = new QDeclarativeFolderListModelPrivate; d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives | QDir::NoDotAndDotDot); connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int)) @@ -129,56 +134,35 @@ QDeclarativeFolderListModel::~QDeclarativeFolderListModel() delete d; } -QHash QDeclarativeFolderListModel::data(int index, const QList &roles) const -{ - Q_UNUSED(roles); - QHash folderData; - QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); - if (modelIndex.isValid()) { - folderData[QDirModel::FileNameRole] = d->model.data(modelIndex, QDirModel::FileNameRole); - folderData[QDirModel::FilePathRole] = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); - } - - return folderData; -} - -QVariant QDeclarativeFolderListModel::data(int index, int role) const +QVariant QDeclarativeFolderListModel::data(const QModelIndex &index, int role) const { QVariant rv; - QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); + QModelIndex modelIndex = d->model.index(index.row(), 0, d->folderIndex); if (modelIndex.isValid()) { - if (role == QDirModel::FileNameRole) - rv = d->model.data(modelIndex, QDirModel::FileNameRole); - else if (role == QDirModel::FilePathRole) + if (role == FileNameRole) + rv = d->model.data(modelIndex, QDirModel::FileNameRole).toString(); + else if (role == FilePathRole) rv = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); } - return rv; } -int QDeclarativeFolderListModel::count() const +QString QDeclarativeFolderListModel::fileName(int index) const { - return d->count; + QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); + return d->model.data(modelIndex, QDirModel::FileNameRole).toString(); } -QList QDeclarativeFolderListModel::roles() const +QUrl QDeclarativeFolderListModel::filePath(int index) const { - QList r; - r << QDirModel::FileNameRole; - r << QDirModel::FilePathRole; - return r; + QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); + return QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); } -QString QDeclarativeFolderListModel::toString(int role) const +int QDeclarativeFolderListModel::rowCount(const QModelIndex &parent) const { - switch (role) { - case QDirModel::FileNameRole: - return QLatin1String("fileName"); - case QDirModel::FilePathRole: - return QLatin1String("filePath"); - } - - return QString(); + Q_UNUSED(parent); + return d->count; } /*! @@ -313,37 +297,41 @@ void QDeclarativeFolderListModel::refresh() { d->folderIndex = QModelIndex(); if (d->count) { - int tmpCount = d->count; + emit beginRemoveRows(QModelIndex(), 0, d->count); d->count = 0; - emit itemsRemoved(0, tmpCount); + emit endRemoveRows(); } d->folderIndex = d->model.index(d->folder.toLocalFile()); - d->count = d->model.rowCount(d->folderIndex); - if (d->count) { - emit itemsInserted(0, d->count); + int newcount = d->model.rowCount(d->folderIndex); + if (newcount) { + emit beginInsertRows(QModelIndex(), 0, newcount-1); + d->count = newcount; + emit endInsertRows(); } } void QDeclarativeFolderListModel::inserted(const QModelIndex &index, int start, int end) { if (index == d->folderIndex) { + emit beginInsertRows(QModelIndex(), start, end); d->count = d->model.rowCount(d->folderIndex); - emit itemsInserted(start, end - start + 1); + emit endInsertRows(); } } void QDeclarativeFolderListModel::removed(const QModelIndex &index, int start, int end) { if (index == d->folderIndex) { + emit beginRemoveRows(QModelIndex(), start, end); d->count = d->model.rowCount(d->folderIndex); - emit itemsRemoved(start, end - start + 1); + emit endRemoveRows(); } } void QDeclarativeFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) { if (start.parent() == d->folderIndex) - emit itemsChanged(start.row(), end.row() - start.row() + 1, roles()); + emit dataChanged(index(start.row(),0), index(end.row(),0)); } /*! diff --git a/src/imports/dirmodel/qdeclarativefolderlistmodel.h b/src/imports/dirmodel/qdeclarativefolderlistmodel.h index 0ca935c..86a7588 100644 --- a/src/imports/dirmodel/qdeclarativefolderlistmodel.h +++ b/src/imports/dirmodel/qdeclarativefolderlistmodel.h @@ -45,13 +45,13 @@ #include #include #include -#include +#include class QDeclarativeContext; class QModelIndex; class QDeclarativeFolderListModelPrivate; -class QDeclarativeFolderListModel : public QListModelInterface, public QDeclarativeParserStatus +class QDeclarativeFolderListModel : public QAbstractListModel, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) @@ -64,16 +64,21 @@ class QDeclarativeFolderListModel : public QListModelInterface, public QDeclarat Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs) Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) + Q_PROPERTY(int count READ count) public: QDeclarativeFolderListModel(QObject *parent = 0); ~QDeclarativeFolderListModel(); - virtual QHash data(int index, const QList &roles = (QList())) const; - virtual QVariant data(int index, int role) const; - virtual int count() const; - virtual QList roles() const; - virtual QString toString(int role) const; + enum Roles { FileNameRole = Qt::UserRole+1, FilePathRole = Qt::UserRole+2 }; + + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + + int count() const { return rowCount(QModelIndex()); } + + Q_INVOKABLE QString fileName(int index) const; + Q_INVOKABLE QUrl filePath(int index) const; QUrl folder() const; void setFolder(const QUrl &folder); -- cgit v0.12 From 8806c8c9ba7151247a5f7769f654ec8c3b485df1 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 18 May 2010 11:48:14 +1000 Subject: Photoviewer example fixes. --- .../photoviewer/PhotoViewerCore/Button.qml | 4 +-- .../photoviewer/PhotoViewerCore/EditableButton.qml | 40 ++++++++-------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/demos/declarative/photoviewer/PhotoViewerCore/Button.qml b/demos/declarative/photoviewer/PhotoViewerCore/Button.qml index c681064..5be096a 100644 --- a/demos/declarative/photoviewer/PhotoViewerCore/Button.qml +++ b/demos/declarative/photoviewer/PhotoViewerCore/Button.qml @@ -4,7 +4,7 @@ Item { id: container property alias label: labelText.text - property color tint: "#FFFFFFFF" + property string tint: "" signal clicked width: labelText.width + 70 ; height: labelText.height + 18 @@ -19,7 +19,7 @@ Item { Rectangle { anchors.fill: container; color: container.tint; visible: container.tint != "" - opacity: 0.1; smooth: true + opacity: 0.25; smooth: true } Text { id: labelText; font.pixelSize: 15; anchors.centerIn: parent; smooth: true } diff --git a/demos/declarative/photoviewer/PhotoViewerCore/EditableButton.qml b/demos/declarative/photoviewer/PhotoViewerCore/EditableButton.qml index ccfda02..15ffe56 100644 --- a/demos/declarative/photoviewer/PhotoViewerCore/EditableButton.qml +++ b/demos/declarative/photoviewer/PhotoViewerCore/EditableButton.qml @@ -4,11 +4,10 @@ Item { id: container property string label - property color tint: "#FFFFFFFF" signal clicked signal labelChanged(string label) - width: labelText.width + 70 ; height: labelText.height + 18 + width: textInput.width + 70 ; height: textInput.height + 18 BorderImage { anchors { fill: container; leftMargin: -6; topMargin: -6; rightMargin: -8; bottomMargin: -8 } @@ -18,36 +17,25 @@ Item { Image { anchors.fill: parent; source: "images/cardboard.png"; smooth: true } - Rectangle { - anchors.fill: container; color: container.tint; visible: container.tint != "" - opacity: 0.1; smooth: true - } - - Text { id: labelText; text: label; font.pixelSize: 15; anchors.centerIn: parent; smooth: true } - TextInput { - id: textInput; text: label; font.pixelSize: 15; anchors.centerIn: parent; smooth: true; visible: false - Keys.onReturnPressed: container.labelChanged(textInput.text) + id: textInput; text: label; font.pixelSize: 15; anchors.centerIn: parent; smooth: true + Keys.onReturnPressed: { + container.labelChanged(textInput.text) + container.focus = true + } Keys.onEscapePressed: { - textInput.text = labelText.text - container.state = '' + textInput.text = container.label + container.focus = true } } - MouseArea { - anchors { fill: parent; leftMargin: -20; topMargin: -20; rightMargin: -20; bottomMargin: -20 } - onClicked: container.state = "editMode" - } - - states: State { - name: "editMode" - PropertyChanges { target: container; width: textInput.width + 70; height: textInput.height + 17 } - PropertyChanges { target: textInput; visible: true; focus: true } - PropertyChanges { target: labelText; visible: false } + Rectangle { + anchors.fill: container; border.color: "steelblue"; border.width: 4 + color: "transparent"; visible: textInput.focus; smooth: true } - onLabelChanged: { - labelText.text = label - container.state = '' + MouseArea { + anchors { fill: parent; leftMargin: -20; topMargin: -20; rightMargin: -20; bottomMargin: -20 } + onClicked: textInput.forceFocus() } } -- cgit v0.12 From 1ba3a79e05e96e7a7d38f25cf05d691c4f590559 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 18 May 2010 11:57:29 +1000 Subject: Don't disable SmoothPixmapTransform in qDrawBorderPixmap() Reverts part of ba8ff70b5ac7b68be57a4b63e439fd5a37c4aafa Drawing is far too ugly without SmoothPixmapTransform. Some glitches remain after this change, but they are due to a bug: QTBUG-10524 Task-number: QTBUG-5687 Reviewed-by: Aaron Kennedy --- src/gui/painting/qdrawutil.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp index ef9b18c..3ce95ef 100644 --- a/src/gui/painting/qdrawutil.cpp +++ b/src/gui/painting/qdrawutil.cpp @@ -1138,12 +1138,10 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin 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) { + && oldAA && painter->combinedTransform().type() != QTransform::TxNone) { painter->setRenderHint(QPainter::Antialiasing, false); - painter->setRenderHint(QPainter::SmoothPixmapTransform, false); } xTarget[0] = targetRect.left(); @@ -1354,8 +1352,6 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin if (oldAA) painter->setRenderHint(QPainter::Antialiasing, true); - if (oldSmooth) - painter->setRenderHint(QPainter::SmoothPixmapTransform, true); } QT_END_NAMESPACE -- cgit v0.12 From f784d8f70d864c89c778ce3c0951d51260857523 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 18 May 2010 12:26:56 +1000 Subject: Round correctly in binding optimizer QTBUG-9538 --- src/declarative/qml/qdeclarativecompiledbindings.cpp | 2 +- .../qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index f55d330..7ddc735 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -1200,7 +1200,7 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, const Register &input = registers[instr->unaryop.src]; Register &output = registers[instr->unaryop.output]; if (input.isUndefined()) output.setUndefined(); - else output.setint(int(input.getqreal())); + else output.setint(qRound(input.getqreal())); } break; diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 64e5b3f..0710e15 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -2083,10 +2083,9 @@ void tst_qdeclarativeecmascript::compiled() QCOMPARE(object->property("test15").toBool(), false); QCOMPARE(object->property("test16").toBool(), true); - QCOMPARE(object->property("test17").toInt(), 4); + QCOMPARE(object->property("test17").toInt(), 5); QCOMPARE(object->property("test18").toReal(), qreal(176)); - QEXPECT_FAIL("", "QTBUG-9538", Continue); - QCOMPARE(object->property("test19").toInt(), 6); + QCOMPARE(object->property("test19").toInt(), 7); QCOMPARE(object->property("test20").toReal(), qreal(6.7)); QCOMPARE(object->property("test21").toString(), QLatin1String("6.7")); QCOMPARE(object->property("test22").toString(), QLatin1String("!")); -- cgit v0.12 From 54c6a0101ba2bf3910126c53738e337712e5bb9a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 18 May 2010 11:42:46 +1000 Subject: Add parent parameter to QDeclarativeExpression constructor. Also rearrange the parameter order to be more clear. --- src/declarative/QmlChanges.txt | 5 +++++ .../graphicsitems/qdeclarativevisualitemmodel.cpp | 6 +++--- src/declarative/qml/qdeclarativebinding.cpp | 4 ++-- src/declarative/qml/qdeclarativeboundsignal.cpp | 2 +- src/declarative/qml/qdeclarativeenginedebug.cpp | 2 +- src/declarative/qml/qdeclarativeexpression.cpp | 18 ++++++++++-------- src/declarative/qml/qdeclarativeexpression.h | 6 +++--- src/declarative/qml/qdeclarativevme.cpp | 2 +- src/declarative/qml/qdeclarativewatcher.cpp | 2 +- src/declarative/util/qdeclarativeanimation.cpp | 2 +- src/declarative/util/qdeclarativeconnections.cpp | 2 +- src/declarative/util/qdeclarativepropertychanges.cpp | 4 ++-- src/declarative/util/qdeclarativestateoperations.cpp | 2 +- src/imports/gestures/qdeclarativegesturearea.cpp | 2 +- .../qdeclarativecontext/tst_qdeclarativecontext.cpp | 2 +- .../declarative/qdeclarativeecmascript/testtypes.h | 2 +- .../qdeclarativeimage/tst_qdeclarativeimage.cpp | 2 +- .../tst_qdeclarativelistmodel.cpp | 4 ++-- .../qdeclarativelistview/tst_qdeclarativelistview.cpp | 2 +- .../qdeclarativepathview/tst_qdeclarativepathview.cpp | 2 +- .../tst_qdeclarativevisualdatamodel.cpp | 2 +- 21 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index ec8f508..b1f4f1b 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -18,6 +18,11 @@ C++ API QDeclarativeExpression::value() has been renamed to QDeclarativeExpression::evaluate() +The QDeclarativeExpression constructor has changed from + QDeclarativeExpression(context, expression, scope) +to + QDeclarativeExpression(context, scope, expression, parent = 0) + QML Launcher ------------ The standalone executable has been renamed to qml launcher. Runtime warnings diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 0e4217e..7abd0a2 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -204,7 +204,7 @@ QVariant QDeclarativeVisualItemModel::evaluate(int index, const QString &express QDeclarativeContext *ccontext = qmlContext(this); QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); ctxt->setContextObject(d->children.at(index)); - QDeclarativeExpression e(ctxt, expression, objectContext); + QDeclarativeExpression e(ctxt, objectContext, expression); QVariant value = e.evaluate(); delete ctxt; return value; @@ -1176,7 +1176,7 @@ QVariant QDeclarativeVisualDataModel::evaluate(int index, const QString &express if (nobj) { QDeclarativeItem *item = qobject_cast(nobj); if (item) { - QDeclarativeExpression e(qmlContext(item), expression, objectContext); + QDeclarativeExpression e(qmlContext(item), objectContext, expression); value = e.evaluate(); } } else { @@ -1185,7 +1185,7 @@ QVariant QDeclarativeVisualDataModel::evaluate(int index, const QString &express QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this); ctxt->setContextObject(data); - QDeclarativeExpression e(ctxt, expression, objectContext); + QDeclarativeExpression e(ctxt, objectContext, expression); value = e.evaluate(); delete data; delete ctxt; diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index 2e905b9..8230941 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -88,7 +88,7 @@ QDeclarativeBinding::QDeclarativeBinding(void *data, QDeclarativeRefCount *rc, Q QDeclarativeBinding::QDeclarativeBinding(const QString &str, QObject *obj, QDeclarativeContext *ctxt, QObject *parent) -: QDeclarativeExpression(QDeclarativeContextData::get(ctxt), str, obj, *new QDeclarativeBindingPrivate) +: QDeclarativeExpression(QDeclarativeContextData::get(ctxt), obj, str, *new QDeclarativeBindingPrivate) { setParent(parent); setNotifyOnValueChanged(true); @@ -96,7 +96,7 @@ QDeclarativeBinding::QDeclarativeBinding(const QString &str, QObject *obj, QDecl QDeclarativeBinding::QDeclarativeBinding(const QString &str, QObject *obj, QDeclarativeContextData *ctxt, QObject *parent) -: QDeclarativeExpression(ctxt, str, obj, *new QDeclarativeBindingPrivate) +: QDeclarativeExpression(ctxt, obj, str, *new QDeclarativeBindingPrivate) { setParent(parent); setNotifyOnValueChanged(true); diff --git a/src/declarative/qml/qdeclarativeboundsignal.cpp b/src/declarative/qml/qdeclarativeboundsignal.cpp index 89f1256..8769122 100644 --- a/src/declarative/qml/qdeclarativeboundsignal.cpp +++ b/src/declarative/qml/qdeclarativeboundsignal.cpp @@ -119,7 +119,7 @@ QDeclarativeBoundSignal::QDeclarativeBoundSignal(QDeclarativeContext *ctxt, cons QDeclarative_setParent_noEvent(this, parent); QMetaObject::connect(scope, m_signal.methodIndex(), this, evaluateIdx); - m_expression = new QDeclarativeExpression(ctxt, val, scope); + m_expression = new QDeclarativeExpression(ctxt, scope, val); } QDeclarativeBoundSignal::~QDeclarativeBoundSignal() diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 69e42f8..7ae0050 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -414,7 +414,7 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message) QDeclarativeContext *context = qmlContext(object); QVariant result; if (object && context) { - QDeclarativeExpression exprObj(context, expr, object); + QDeclarativeExpression exprObj(context, object, expr); bool undefined = false; QVariant value = exprObj.evaluate(&undefined); if (undefined) diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index 5ceb918..b1aecfa 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -241,15 +241,17 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, vo } /*! - Create a QDeclarativeExpression object. + Create a QDeclarativeExpression object that is a child of \a parent. The \a expression JavaScript will be executed in the \a ctxt QDeclarativeContext. If specified, the \a scope object's properties will also be in scope during the expression's execution. */ -QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContext *ctxt, const QString &expression, - QObject *scope) -: QObject(*new QDeclarativeExpressionPrivate, 0) +QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContext *ctxt, + QObject *scope, + const QString &expression, + QObject *parent) +: QObject(*new QDeclarativeExpressionPrivate, parent) { Q_D(QDeclarativeExpression); d->init(QDeclarativeContextData::get(ctxt), expression, scope); @@ -258,8 +260,8 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContext *ctxt, const /*! \internal */ -QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, const QString &expression, - QObject *scope) +QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, QObject *scope, + const QString &expression) : QObject(*new QDeclarativeExpressionPrivate, 0) { Q_D(QDeclarativeExpression); @@ -267,8 +269,8 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, co } /*! \internal */ -QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, const QString &expression, - QObject *scope, QDeclarativeExpressionPrivate &dd) +QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, QObject *scope, + const QString &expression, QDeclarativeExpressionPrivate &dd) : QObject(dd, 0) { Q_D(QDeclarativeExpression); diff --git a/src/declarative/qml/qdeclarativeexpression.h b/src/declarative/qml/qdeclarativeexpression.h index 6c72e4d..a8c86da 100644 --- a/src/declarative/qml/qdeclarativeexpression.h +++ b/src/declarative/qml/qdeclarativeexpression.h @@ -64,7 +64,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeExpression : public QObject Q_OBJECT public: QDeclarativeExpression(); - QDeclarativeExpression(QDeclarativeContext *, const QString &, QObject *); + QDeclarativeExpression(QDeclarativeContext *, QObject *, const QString &, QObject * = 0); virtual ~QDeclarativeExpression(); QDeclarativeEngine *engine() const; @@ -92,13 +92,13 @@ Q_SIGNALS: void valueChanged(); protected: - QDeclarativeExpression(QDeclarativeContextData *, const QString &, QObject *, + QDeclarativeExpression(QDeclarativeContextData *, QObject *, const QString &, QDeclarativeExpressionPrivate &dd); QDeclarativeExpression(QDeclarativeContextData *, void *, QDeclarativeRefCount *rc, QObject *me, const QString &, int, QDeclarativeExpressionPrivate &dd); private: - QDeclarativeExpression(QDeclarativeContextData *, const QString &, QObject *); + QDeclarativeExpression(QDeclarativeContextData *, QObject *, const QString &); Q_DISABLE_COPY(QDeclarativeExpression) Q_DECLARE_PRIVATE(QDeclarativeExpression) diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index 8ba79a6..3247f85 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -627,7 +627,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, QDeclarativeBoundSignal *bs = new QDeclarativeBoundSignal(target, signal, target); QDeclarativeExpression *expr = - new QDeclarativeExpression(ctxt, primitives.at(instr.storeSignal.value), context); + new QDeclarativeExpression(ctxt, context, primitives.at(instr.storeSignal.value)); expr->setSourceLocation(comp->name, instr.line); bs->setExpression(expr); } diff --git a/src/declarative/qml/qdeclarativewatcher.cpp b/src/declarative/qml/qdeclarativewatcher.cpp index 842b3c4..da1419f 100644 --- a/src/declarative/qml/qdeclarativewatcher.cpp +++ b/src/declarative/qml/qdeclarativewatcher.cpp @@ -153,7 +153,7 @@ bool QDeclarativeWatcher::addWatch(int id, quint32 objectId, const QString &expr QObject *object = QDeclarativeDebugService::objectForId(objectId); QDeclarativeContext *context = qmlContext(object); if (context) { - QDeclarativeExpression *exprObj = new QDeclarativeExpression(context, expr, object); + QDeclarativeExpression *exprObj = new QDeclarativeExpression(context, object, expr); exprObj->setNotifyOnValueChanged(true); QDeclarativeWatchProxy *proxy = new QDeclarativeWatchProxy(id, exprObj, objectId, this); exprObj->setParent(proxy); diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 67440b6..3017e22 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -786,7 +786,7 @@ void QDeclarativeScriptActionPrivate::execute() const QString &str = scriptStr.script(); if (!str.isEmpty()) { - QDeclarativeExpression expr(scriptStr.context(), str, scriptStr.scopeObject()); + QDeclarativeExpression expr(scriptStr.context(), scriptStr.scopeObject(), str); QDeclarativeData *ddata = QDeclarativeData::get(q); if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) expr.setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); diff --git a/src/declarative/util/qdeclarativeconnections.cpp b/src/declarative/util/qdeclarativeconnections.cpp index ffa160f..808d196 100644 --- a/src/declarative/util/qdeclarativeconnections.cpp +++ b/src/declarative/util/qdeclarativeconnections.cpp @@ -262,7 +262,7 @@ void QDeclarativeConnections::connectSignals() if (prop.isValid() && (prop.type() & QDeclarativeProperty::SignalProperty)) { QDeclarativeBoundSignal *signal = new QDeclarativeBoundSignal(target(), prop.method(), this); - signal->setExpression(new QDeclarativeExpression(qmlContext(this), script, 0)); + signal->setExpression(new QDeclarativeExpression(qmlContext(this), 0, script)); d->boundsignals += signal; } else { if (!d->ignoreUnknownSignals) diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp index 12fef36..d99de7a 100644 --- a/src/declarative/util/qdeclarativepropertychanges.cpp +++ b/src/declarative/util/qdeclarativepropertychanges.cpp @@ -321,7 +321,7 @@ 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); + QDeclarativeExpression *expression = new QDeclarativeExpression(qmlContext(q), object, data.toString()); QDeclarativeData *ddata = QDeclarativeData::get(q); if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) expression->setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); @@ -330,7 +330,7 @@ void QDeclarativePropertyChangesPrivate::decode() handler->expression = expression; signalReplacements << handler; } else if (isScript) { - QDeclarativeExpression *expression = new QDeclarativeExpression(qmlContext(q), data.toString(), object); + QDeclarativeExpression *expression = new QDeclarativeExpression(qmlContext(q), object, data.toString()); QDeclarativeData *ddata = QDeclarativeData::get(q); if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) expression->setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index efef52d..b11c0c2 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -659,7 +659,7 @@ void QDeclarativeStateChangeScript::execute(Reason) Q_D(QDeclarativeStateChangeScript); const QString &script = d->script.script(); if (!script.isEmpty()) { - QDeclarativeExpression expr(d->script.context(), script, d->script.scopeObject()); + QDeclarativeExpression expr(d->script.context(), d->script.scopeObject(), script); QDeclarativeData *ddata = QDeclarativeData::get(this); if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) expr.setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); diff --git a/src/imports/gestures/qdeclarativegesturearea.cpp b/src/imports/gestures/qdeclarativegesturearea.cpp index 19afe0c..1b0aeeb 100644 --- a/src/imports/gestures/qdeclarativegesturearea.cpp +++ b/src/imports/gestures/qdeclarativegesturearea.cpp @@ -226,7 +226,7 @@ void QDeclarativeGestureArea::connectSignals() ds >> gesturetype; QString script; ds >> script; - QDeclarativeExpression *exp = new QDeclarativeExpression(qmlContext(this), script, 0); + QDeclarativeExpression *exp = new QDeclarativeExpression(qmlContext(this), 0, script); d->bindings.insert(Qt::GestureType(gesturetype),exp); grabGesture(Qt::GestureType(gesturetype)); } diff --git a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp index 851460f..7f0e6c0 100644 --- a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp +++ b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp @@ -398,7 +398,7 @@ void tst_qdeclarativecontext::destruction() QObject obj; QDeclarativeEngine::setContextForObject(&obj, ctxt); - QDeclarativeExpression expr(ctxt, "a", 0); + QDeclarativeExpression expr(ctxt, 0, "a"); QCOMPARE(ctxt, QDeclarativeEngine::contextForObject(&obj)); QCOMPARE(ctxt, expr.context()); diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h index 1381d57..7bb8a8e 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h @@ -190,7 +190,7 @@ class MyExpression : public QDeclarativeExpression Q_OBJECT public: MyExpression(QDeclarativeContext *ctxt, const QString &expr) - : QDeclarativeExpression(ctxt, expr, 0), changed(false) + : QDeclarativeExpression(ctxt, 0, expr), changed(false) { QObject::connect(this, SIGNAL(valueChanged()), this, SLOT(expressionValueChanged())); setNotifyOnValueChanged(true); diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp index e0143a6..720702a 100644 --- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp @@ -400,7 +400,7 @@ T *tst_qdeclarativeimage::findItem(QGraphicsObject *parent, const QString &objec //qDebug() << "try" << item; if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { if (index != -1) { - QDeclarativeExpression e(qmlContext(item), "index", item); + QDeclarativeExpression e(qmlContext(item), item, "index"); if (e.evaluate().toInt() == index) return static_cast(item); } else { diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index 26a12f0..be4ffe8 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -275,7 +275,7 @@ void tst_qdeclarativelistmodel::dynamic() QDeclarativeListModel model; QDeclarativeEngine::setContextForObject(&model,engine.rootContext()); engine.rootContext()->setContextObject(&model); - QDeclarativeExpression e(engine.rootContext(), script, &model); + QDeclarativeExpression e(engine.rootContext(), &model, script); if (!warning.isEmpty()) QTest::ignoreMessage(QtWarningMsg, warning.toLatin1()); @@ -332,7 +332,7 @@ void tst_qdeclarativelistmodel::dynamic_worker() Q_ARG(QVariant, operations.mid(0, operations.length()-1)))); waitForWorker(item); - QDeclarativeExpression e(eng.rootContext(), operations.last().toString(), &model); + QDeclarativeExpression e(eng.rootContext(), &model, operations.last().toString()); if (QByteArray(QTest::currentDataTag()).startsWith("nested")) QVERIFY(e.evaluate().toInt() != result); else diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index ec2afae..fde2e43 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -1550,7 +1550,7 @@ T *tst_QDeclarativeListView::findItem(QGraphicsObject *parent, const QString &ob //qDebug() << "try" << item; if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { if (index != -1) { - QDeclarativeExpression e(qmlContext(item), "index", item); + QDeclarativeExpression e(qmlContext(item), item, "index"); if (e.evaluate().toInt() == index) return static_cast(item); } else { diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index 0e16f66..f32a6c7 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -760,7 +760,7 @@ T *tst_QDeclarativePathView::findItem(QGraphicsObject *parent, const QString &ob //qDebug() << "try" << item; if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { if (index != -1) { - QDeclarativeExpression e(qmlContext(item), "index", item); + QDeclarativeExpression e(qmlContext(item), item, "index"); if (e.evaluate().toInt() == index) return static_cast(item); } else { diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp index c238ef9..8f3fb16 100644 --- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp +++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp @@ -190,7 +190,7 @@ T *tst_qdeclarativevisualdatamodel::findItem(QGraphicsObject *parent, const QStr //qDebug() << "try" << item; if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { if (index != -1) { - QDeclarativeExpression e(qmlContext(item), "index", item); + QDeclarativeExpression e(qmlContext(item), item, "index"); if (e.evaluate().toInt() == index) return static_cast(item); } else { -- cgit v0.12 From 07fc1c3a97689f1f72e4e9b6d7d1bad1a391a9a7 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 18 May 2010 12:28:26 +1000 Subject: Rename files; fix test. --- .../auto/declarative/qdeclarativelanguage/data/scriptString.3.qml | 5 ----- .../auto/declarative/qdeclarativelanguage/data/scriptString.4.qml | 5 ----- .../auto/declarative/qdeclarativelanguage/data/scriptString.5.qml | 5 ----- tests/auto/declarative/qdeclarativelanguage/data/scriptString2.qml | 5 +++++ tests/auto/declarative/qdeclarativelanguage/data/scriptString3.qml | 5 +++++ tests/auto/declarative/qdeclarativelanguage/data/scriptString4.qml | 5 +++++ .../declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 7 ++++--- 7 files changed, 19 insertions(+), 18 deletions(-) delete mode 100644 tests/auto/declarative/qdeclarativelanguage/data/scriptString.3.qml delete mode 100644 tests/auto/declarative/qdeclarativelanguage/data/scriptString.4.qml delete mode 100644 tests/auto/declarative/qdeclarativelanguage/data/scriptString.5.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/scriptString2.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/scriptString3.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/scriptString4.qml diff --git a/tests/auto/declarative/qdeclarativelanguage/data/scriptString.3.qml b/tests/auto/declarative/qdeclarativelanguage/data/scriptString.3.qml deleted file mode 100644 index 0de3667..0000000 --- a/tests/auto/declarative/qdeclarativelanguage/data/scriptString.3.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Test 1.0 - -MyTypeObject { - scriptProperty: "hello world" -} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/scriptString.4.qml b/tests/auto/declarative/qdeclarativelanguage/data/scriptString.4.qml deleted file mode 100644 index 0cd82ff..0000000 --- a/tests/auto/declarative/qdeclarativelanguage/data/scriptString.4.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Test 1.0 - -MyTypeObject { - scriptProperty: 12.345 -} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/scriptString.5.qml b/tests/auto/declarative/qdeclarativelanguage/data/scriptString.5.qml deleted file mode 100644 index 3e2f9a4..0000000 --- a/tests/auto/declarative/qdeclarativelanguage/data/scriptString.5.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Test 1.0 - -MyTypeObject { - scriptProperty: true -} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/scriptString2.qml b/tests/auto/declarative/qdeclarativelanguage/data/scriptString2.qml new file mode 100644 index 0000000..0de3667 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/scriptString2.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + scriptProperty: "hello world" +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/scriptString3.qml b/tests/auto/declarative/qdeclarativelanguage/data/scriptString3.qml new file mode 100644 index 0000000..0cd82ff --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/scriptString3.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + scriptProperty: 12.345 +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/scriptString4.qml b/tests/auto/declarative/qdeclarativelanguage/data/scriptString4.qml new file mode 100644 index 0000000..3e2f9a4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/scriptString4.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + scriptProperty: true +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 4434e46..b72c75f 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -1122,16 +1122,17 @@ void tst_qdeclarativelanguage::scriptString() } { - QDeclarativeComponent component(&engine, TEST_FILE("scriptString3.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("scriptString2.qml")); VERIFY_ERRORS(0); MyTypeObject *object = qobject_cast(component.create()); QVERIFY(object != 0); + QEXPECT_FAIL("", "Variant.asScript() returns incorrect value for string (bug pending)", Continue); QCOMPARE(object->scriptProperty().script(), QString("\"hello world\"")); } { - QDeclarativeComponent component(&engine, TEST_FILE("scriptString4.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("scriptString3.qml")); VERIFY_ERRORS(0); MyTypeObject *object = qobject_cast(component.create()); @@ -1140,7 +1141,7 @@ void tst_qdeclarativelanguage::scriptString() } { - QDeclarativeComponent component(&engine, TEST_FILE("scriptString5.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("scriptString4.qml")); VERIFY_ERRORS(0); MyTypeObject *object = qobject_cast(component.create()); -- cgit v0.12 From c68c518d0e4823beaab7d3adf20044bc03446b46 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 18 May 2010 12:50:44 +1000 Subject: Sometimes you own QNetworkReply, sometimes you don't. God bless QNetworkAccessManager --- src/declarative/qml/qdeclarativexmlhttprequest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp index 80510f8..acd1f51 100644 --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp @@ -995,7 +995,7 @@ private: int m_status; QString m_statusText; QNetworkRequest m_request; - QNetworkReply *m_network; + QDeclarativeGuard m_network; void destroyNetwork(); QNetworkAccessManager *m_nam; -- cgit v0.12 From e6dcb15ca670ac9a01ac7c4c96a7de2959f98498 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 18 May 2010 13:09:22 +1000 Subject: Fix naming. --- src/imports/dirmodel/dirmodel.pro | 26 -- src/imports/dirmodel/plugin.cpp | 65 ---- .../dirmodel/qdeclarativefolderlistmodel.cpp | 401 --------------------- src/imports/dirmodel/qdeclarativefolderlistmodel.h | 127 ------- src/imports/dirmodel/qmldir | 1 - src/imports/folderlistmodel/folderlistmodel.pro | 26 ++ src/imports/folderlistmodel/plugin.cpp | 65 ++++ .../qdeclarativefolderlistmodel.cpp | 389 ++++++++++++++++++++ .../folderlistmodel/qdeclarativefolderlistmodel.h | 124 +++++++ src/imports/folderlistmodel/qmldir | 1 + src/imports/imports.pro | 2 +- 11 files changed, 606 insertions(+), 621 deletions(-) delete mode 100644 src/imports/dirmodel/dirmodel.pro delete mode 100644 src/imports/dirmodel/plugin.cpp delete mode 100644 src/imports/dirmodel/qdeclarativefolderlistmodel.cpp delete mode 100644 src/imports/dirmodel/qdeclarativefolderlistmodel.h delete mode 100644 src/imports/dirmodel/qmldir create mode 100644 src/imports/folderlistmodel/folderlistmodel.pro create mode 100644 src/imports/folderlistmodel/plugin.cpp create mode 100644 src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp create mode 100644 src/imports/folderlistmodel/qdeclarativefolderlistmodel.h create mode 100644 src/imports/folderlistmodel/qmldir diff --git a/src/imports/dirmodel/dirmodel.pro b/src/imports/dirmodel/dirmodel.pro deleted file mode 100644 index 03f3a1a..0000000 --- a/src/imports/dirmodel/dirmodel.pro +++ /dev/null @@ -1,26 +0,0 @@ -TARGET = qmlviewerplugin -TARGETPATH = Qt/labs/folderlistmodel -include(../qimportbase.pri) - -QT += declarative script - -SOURCES += qdeclarativefolderlistmodel.cpp plugin.cpp -HEADERS += qdeclarativefolderlistmodel.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 = qmlviewerplugin.dll qmldir - importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH - - DEPLOYMENT = importFiles -} - -INSTALLS += target qmldir diff --git a/src/imports/dirmodel/plugin.cpp b/src/imports/dirmodel/plugin.cpp deleted file mode 100644 index 61bf354..0000000 --- a/src/imports/dirmodel/plugin.cpp +++ /dev/null @@ -1,65 +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 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 "qdeclarativefolderlistmodel.h" - -QT_BEGIN_NAMESPACE - -class QmlViewerPlugin : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - virtual void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.folderlistmodel")); - qmlRegisterType(uri,1,0,"FolderListModel"); - } -}; - -QT_END_NAMESPACE - -#include "plugin.moc" - -Q_EXPORT_PLUGIN2(qmlviewerplugin, QT_PREPEND_NAMESPACE(QmlViewerPlugin)); - diff --git a/src/imports/dirmodel/qdeclarativefolderlistmodel.cpp b/src/imports/dirmodel/qdeclarativefolderlistmodel.cpp deleted file mode 100644 index 50ef4ae..0000000 --- a/src/imports/dirmodel/qdeclarativefolderlistmodel.cpp +++ /dev/null @@ -1,401 +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 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 "qdeclarativefolderlistmodel.h" -#include -#include -#include - -class QDeclarativeFolderListModelPrivate -{ -public: - QDeclarativeFolderListModelPrivate() - : sortField(QDeclarativeFolderListModel::Name), sortReversed(false), count(0) { - nameFilters << QLatin1String("*"); - } - - void updateSorting() { - QDir::SortFlags flags = 0; - switch(sortField) { - case QDeclarativeFolderListModel::Unsorted: - flags |= QDir::Unsorted; - break; - case QDeclarativeFolderListModel::Name: - flags |= QDir::Name; - break; - case QDeclarativeFolderListModel::Time: - flags |= QDir::Time; - break; - case QDeclarativeFolderListModel::Size: - flags |= QDir::Size; - break; - case QDeclarativeFolderListModel::Type: - flags |= QDir::Type; - break; - } - - if (sortReversed) - flags |= QDir::Reversed; - - model.setSorting(flags); - } - - QDirModel model; - QUrl folder; - QStringList nameFilters; - QModelIndex folderIndex; - QDeclarativeFolderListModel::SortField sortField; - bool sortReversed; - int count; -}; - -/*! - \qmlclass FolderListModel - \brief The FolderListModel provides a model of the contents of a folder in a filesystem. - - FolderListModel provides access to the local filesystem. The \e folder property - specifies the folder to list. - - Qt uses "/" as a universal directory separator in the same way that "/" is - used as a path separator in URLs. If you always use "/" as a directory - separator, Qt will translate your paths to conform to the underlying - operating system. - - The roles available are: - \list - \o fileName - \o filePath - \endlist - - Additionally a file entry can be differentiated from a folder entry - via the \l isFolder() method. -*/ - -QDeclarativeFolderListModel::QDeclarativeFolderListModel(QObject *parent) - : QAbstractListModel(parent) -{ - QHash roles; - roles[FileNameRole] = "fileName"; - roles[FilePathRole] = "filePath"; - setRoleNames(roles); - - d = new QDeclarativeFolderListModelPrivate; - d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives | QDir::NoDotAndDotDot); - connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int)) - , this, SLOT(inserted(const QModelIndex&,int,int))); - connect(&d->model, SIGNAL(rowsRemoved(const QModelIndex&,int,int)) - , this, SLOT(removed(const QModelIndex&,int,int))); - connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) - , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); - connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh())); - connect(&d->model, SIGNAL(layoutChanged()), this, SLOT(refresh())); -} - -QDeclarativeFolderListModel::~QDeclarativeFolderListModel() -{ - delete d; -} - -QVariant QDeclarativeFolderListModel::data(const QModelIndex &index, int role) const -{ - QVariant rv; - QModelIndex modelIndex = d->model.index(index.row(), 0, d->folderIndex); - if (modelIndex.isValid()) { - if (role == FileNameRole) - rv = d->model.data(modelIndex, QDirModel::FileNameRole).toString(); - else if (role == FilePathRole) - rv = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); - } - return rv; -} - -QString QDeclarativeFolderListModel::fileName(int index) const -{ - QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); - return d->model.data(modelIndex, QDirModel::FileNameRole).toString(); -} - -QUrl QDeclarativeFolderListModel::filePath(int index) const -{ - QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); - return QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); -} - -int QDeclarativeFolderListModel::rowCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent); - return d->count; -} - -/*! - \qmlproperty string FolderListModel::folder - - The \a folder property holds the folder the model is currently providing. - - It is a URL, but must be a file: or qrc: URL (or relative to such a URL). -*/ -QUrl QDeclarativeFolderListModel::folder() const -{ - return d->folder; -} - -void QDeclarativeFolderListModel::setFolder(const QUrl &folder) -{ - if (folder == d->folder) - return; - QModelIndex index = d->model.index(folder.toLocalFile()); - if (index.isValid() && d->model.isDir(index)) { - d->folder = folder; - QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); - emit folderChanged(); - } -} - -QUrl QDeclarativeFolderListModel::parentFolder() const -{ - QUrl r; - QString localFile = d->folder.toLocalFile(); - if (!localFile.isEmpty()) { - QDir dir(localFile); -#if defined(Q_OS_SYMBIAN) - if (dir.isRoot()) - dir.setPath(""); - else -#endif - dir.cdUp(); - r = d->folder; - r.setPath(dir.path()); - } else { - int pos = d->folder.path().lastIndexOf(QLatin1Char('/')); - if (pos == -1) - return QUrl(); - r = d->folder; - r.setPath(d->folder.path().left(pos)); - } - return r; -} - -/*! - \qmlproperty list FolderListModel::nameFilters - - The \a nameFilters property contains a list of filename filters. - The filters may include the ? and * wildcards. - - The example below filters on PNG and JPEG files: - - \code - FolderListModel { - nameFilters: [ "*.png", "*.jpg" ] - } - \endcode -*/ -QStringList QDeclarativeFolderListModel::nameFilters() const -{ - return d->nameFilters; -} - -void QDeclarativeFolderListModel::setNameFilters(const QStringList &filters) -{ - d->nameFilters = filters; - d->model.setNameFilters(d->nameFilters); -} - -void QDeclarativeFolderListModel::classBegin() -{ -} - -void QDeclarativeFolderListModel::componentComplete() -{ - if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile())) - setFolder(QUrl(QLatin1String("file://")+QDir::currentPath())); - - if (!d->folderIndex.isValid()) - QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); -} - -QDeclarativeFolderListModel::SortField QDeclarativeFolderListModel::sortField() const -{ - return d->sortField; -} - -void QDeclarativeFolderListModel::setSortField(SortField field) -{ - if (field != d->sortField) { - d->sortField = field; - d->updateSorting(); - } -} - -bool QDeclarativeFolderListModel::sortReversed() const -{ - return d->sortReversed; -} - -void QDeclarativeFolderListModel::setSortReversed(bool rev) -{ - if (rev != d->sortReversed) { - d->sortReversed = rev; - d->updateSorting(); - } -} - -/*! - \qmlmethod bool FolderListModel::isFolder(int index) - - Returns true if the entry \a index is a folder; otherwise - returns false. -*/ -bool QDeclarativeFolderListModel::isFolder(int index) const -{ - if (index != -1) { - QModelIndex idx = d->model.index(index, 0, d->folderIndex); - if (idx.isValid()) - return d->model.isDir(idx); - } - return false; -} - -void QDeclarativeFolderListModel::refresh() -{ - d->folderIndex = QModelIndex(); - if (d->count) { - emit beginRemoveRows(QModelIndex(), 0, d->count); - d->count = 0; - emit endRemoveRows(); - } - d->folderIndex = d->model.index(d->folder.toLocalFile()); - int newcount = d->model.rowCount(d->folderIndex); - if (newcount) { - emit beginInsertRows(QModelIndex(), 0, newcount-1); - d->count = newcount; - emit endInsertRows(); - } -} - -void QDeclarativeFolderListModel::inserted(const QModelIndex &index, int start, int end) -{ - if (index == d->folderIndex) { - emit beginInsertRows(QModelIndex(), start, end); - d->count = d->model.rowCount(d->folderIndex); - emit endInsertRows(); - } -} - -void QDeclarativeFolderListModel::removed(const QModelIndex &index, int start, int end) -{ - if (index == d->folderIndex) { - emit beginRemoveRows(QModelIndex(), start, end); - d->count = d->model.rowCount(d->folderIndex); - emit endRemoveRows(); - } -} - -void QDeclarativeFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) -{ - if (start.parent() == d->folderIndex) - emit dataChanged(index(start.row(),0), index(end.row(),0)); -} - -/*! - \qmlproperty bool FolderListModel::showDirs - - If true (the default), directories are included in the model. - - Note that the nameFilters are ignored for directories. -*/ -bool QDeclarativeFolderListModel::showDirs() const -{ - return d->model.filter() & QDir::AllDirs; -} - -void QDeclarativeFolderListModel::setShowDirs(bool on) -{ - if (!(d->model.filter() & QDir::AllDirs) == !on) - return; - if (on) - d->model.setFilter(d->model.filter() | QDir::AllDirs | QDir::Drives); - else - d->model.setFilter(d->model.filter() & ~(QDir::AllDirs | QDir::Drives)); -} - -/*! - \qmlproperty bool FolderListModel::showDotAndDotDot - - If true, the "." and ".." directories are included in the model. - - The default is false. -*/ -bool QDeclarativeFolderListModel::showDotAndDotDot() const -{ - return !(d->model.filter() & QDir::NoDotAndDotDot); -} - -void QDeclarativeFolderListModel::setShowDotAndDotDot(bool on) -{ - if (!(d->model.filter() & QDir::NoDotAndDotDot) == on) - return; - if (on) - d->model.setFilter(d->model.filter() & ~QDir::NoDotAndDotDot); - else - d->model.setFilter(d->model.filter() | QDir::NoDotAndDotDot); -} - -/*! - \qmlproperty bool FolderListModel::showOnlyReadable - - If true, only readable files and directories are shown. - - The default is false. -*/ -bool QDeclarativeFolderListModel::showOnlyReadable() const -{ - return d->model.filter() & QDir::Readable; -} - -void QDeclarativeFolderListModel::setShowOnlyReadable(bool on) -{ - if (!(d->model.filter() & QDir::Readable) == !on) - return; - if (on) - d->model.setFilter(d->model.filter() | QDir::Readable); - else - d->model.setFilter(d->model.filter() & ~QDir::Readable); -} diff --git a/src/imports/dirmodel/qdeclarativefolderlistmodel.h b/src/imports/dirmodel/qdeclarativefolderlistmodel.h deleted file mode 100644 index 86a7588..0000000 --- a/src/imports/dirmodel/qdeclarativefolderlistmodel.h +++ /dev/null @@ -1,127 +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 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$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEFOLDERLISTMODEL_H -#define QDECLARATIVEFOLDERLISTMODEL_H - -#include -#include -#include -#include - -class QDeclarativeContext; -class QModelIndex; - -class QDeclarativeFolderListModelPrivate; -class QDeclarativeFolderListModel : public QAbstractListModel, public QDeclarativeParserStatus -{ - Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) - - Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged) - Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged) - Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) - Q_PROPERTY(SortField sortField READ sortField WRITE setSortField) - Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed) - Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs) - Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) - Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) - Q_PROPERTY(int count READ count) - -public: - QDeclarativeFolderListModel(QObject *parent = 0); - ~QDeclarativeFolderListModel(); - - enum Roles { FileNameRole = Qt::UserRole+1, FilePathRole = Qt::UserRole+2 }; - - int rowCount(const QModelIndex &parent) const; - QVariant data(const QModelIndex &index, int role) const; - - int count() const { return rowCount(QModelIndex()); } - - Q_INVOKABLE QString fileName(int index) const; - Q_INVOKABLE QUrl filePath(int index) const; - - QUrl folder() const; - void setFolder(const QUrl &folder); - - QUrl parentFolder() const; - - QStringList nameFilters() const; - void setNameFilters(const QStringList &filters); - - virtual void classBegin(); - virtual void componentComplete(); - - Q_INVOKABLE bool isFolder(int index) const; - - enum SortField { Unsorted, Name, Time, Size, Type }; - SortField sortField() const; - void setSortField(SortField field); - Q_ENUMS(SortField) - - bool sortReversed() const; - void setSortReversed(bool rev); - - bool showDirs() const; - void setShowDirs(bool); - bool showDotAndDotDot() const; - void setShowDotAndDotDot(bool); - bool showOnlyReadable() const; - void setShowOnlyReadable(bool); - -Q_SIGNALS: - void folderChanged(); - -private Q_SLOTS: - void refresh(); - void inserted(const QModelIndex &index, int start, int end); - void removed(const QModelIndex &index, int start, int end); - void dataChanged(const QModelIndex &start, const QModelIndex &end); - -private: - Q_DISABLE_COPY(QDeclarativeFolderListModel) - QDeclarativeFolderListModelPrivate *d; -}; - -QML_DECLARE_TYPE(QDeclarativeFolderListModel) - -#endif // QDECLARATIVEFOLDERLISTMODEL_H diff --git a/src/imports/dirmodel/qmldir b/src/imports/dirmodel/qmldir deleted file mode 100644 index 0be644f..0000000 --- a/src/imports/dirmodel/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin qmlviewerplugin diff --git a/src/imports/folderlistmodel/folderlistmodel.pro b/src/imports/folderlistmodel/folderlistmodel.pro new file mode 100644 index 0000000..781dfc2 --- /dev/null +++ b/src/imports/folderlistmodel/folderlistmodel.pro @@ -0,0 +1,26 @@ +TARGET = qmlfolderlistmodelplugin +TARGETPATH = Qt/labs/folderlistmodel +include(../qimportbase.pri) + +QT += declarative script + +SOURCES += qdeclarativefolderlistmodel.cpp plugin.cpp +HEADERS += qdeclarativefolderlistmodel.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 = qmlfolderlistmodelplugin.dll qmldir + importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH + + DEPLOYMENT = importFiles +} + +INSTALLS += target qmldir diff --git a/src/imports/folderlistmodel/plugin.cpp b/src/imports/folderlistmodel/plugin.cpp new file mode 100644 index 0000000..b94efb0 --- /dev/null +++ b/src/imports/folderlistmodel/plugin.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 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 "qdeclarativefolderlistmodel.h" + +QT_BEGIN_NAMESPACE + +class QmlFolderListModelPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.folderlistmodel")); + qmlRegisterType(uri,1,0,"FolderListModel"); + } +}; + +QT_END_NAMESPACE + +#include "plugin.moc" + +Q_EXPORT_PLUGIN2(qmlfolderlistmodelplugin, QT_PREPEND_NAMESPACE(QmlFolderListModelPlugin)); + diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp new file mode 100644 index 0000000..a16f0c6 --- /dev/null +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp @@ -0,0 +1,389 @@ +/**************************************************************************** +** +** 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 "qdeclarativefolderlistmodel.h" +#include +#include +#include + +class QDeclarativeFolderListModelPrivate +{ +public: + QDeclarativeFolderListModelPrivate() + : sortField(QDeclarativeFolderListModel::Name), sortReversed(false), count(0) { + nameFilters << QLatin1String("*"); + } + + void updateSorting() { + QDir::SortFlags flags = 0; + switch(sortField) { + case QDeclarativeFolderListModel::Unsorted: + flags |= QDir::Unsorted; + break; + case QDeclarativeFolderListModel::Name: + flags |= QDir::Name; + break; + case QDeclarativeFolderListModel::Time: + flags |= QDir::Time; + break; + case QDeclarativeFolderListModel::Size: + flags |= QDir::Size; + break; + case QDeclarativeFolderListModel::Type: + flags |= QDir::Type; + break; + } + + if (sortReversed) + flags |= QDir::Reversed; + + model.setSorting(flags); + } + + QDirModel model; + QUrl folder; + QStringList nameFilters; + QModelIndex folderIndex; + QDeclarativeFolderListModel::SortField sortField; + bool sortReversed; + int count; +}; + +/*! + \qmlclass FolderListModel + \brief The FolderListModel provides a model of the contents of a folder in a filesystem. + + FolderListModel provides access to the local filesystem. The \e folder property + specifies the folder to list. + + Qt uses "/" as a universal directory separator in the same way that "/" is + used as a path separator in URLs. If you always use "/" as a directory + separator, Qt will translate your paths to conform to the underlying + operating system. + + The roles available are: + \list + \o fileName + \o filePath + \endlist + + Additionally a file entry can be differentiated from a folder entry + via the \l isFolder() method. +*/ + +QDeclarativeFolderListModel::QDeclarativeFolderListModel(QObject *parent) + : QAbstractListModel(parent) +{ + QHash roles; + roles[FileNameRole] = "fileName"; + roles[FilePathRole] = "filePath"; + setRoleNames(roles); + + d = new QDeclarativeFolderListModelPrivate; + d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives | QDir::NoDotAndDotDot); + connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int)) + , this, SLOT(inserted(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(rowsRemoved(const QModelIndex&,int,int)) + , this, SLOT(removed(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) + , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); + connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh())); + connect(&d->model, SIGNAL(layoutChanged()), this, SLOT(refresh())); +} + +QDeclarativeFolderListModel::~QDeclarativeFolderListModel() +{ + delete d; +} + +QVariant QDeclarativeFolderListModel::data(const QModelIndex &index, int role) const +{ + QVariant rv; + QModelIndex modelIndex = d->model.index(index.row(), 0, d->folderIndex); + if (modelIndex.isValid()) { + if (role == FileNameRole) + rv = d->model.data(modelIndex, QDirModel::FileNameRole).toString(); + else if (role == FilePathRole) + rv = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); + } + return rv; +} + +int QDeclarativeFolderListModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return d->count; +} + +/*! + \qmlproperty string FolderListModel::folder + + The \a folder property holds the folder the model is currently providing. + + It is a URL, but must be a file: or qrc: URL (or relative to such a URL). +*/ +QUrl QDeclarativeFolderListModel::folder() const +{ + return d->folder; +} + +void QDeclarativeFolderListModel::setFolder(const QUrl &folder) +{ + if (folder == d->folder) + return; + QModelIndex index = d->model.index(folder.toLocalFile()); + if (index.isValid() && d->model.isDir(index)) { + d->folder = folder; + QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); + emit folderChanged(); + } +} + +QUrl QDeclarativeFolderListModel::parentFolder() const +{ + QUrl r; + QString localFile = d->folder.toLocalFile(); + if (!localFile.isEmpty()) { + QDir dir(localFile); +#if defined(Q_OS_SYMBIAN) + if (dir.isRoot()) + dir.setPath(""); + else +#endif + dir.cdUp(); + r = d->folder; + r.setPath(dir.path()); + } else { + int pos = d->folder.path().lastIndexOf(QLatin1Char('/')); + if (pos == -1) + return QUrl(); + r = d->folder; + r.setPath(d->folder.path().left(pos)); + } + return r; +} + +/*! + \qmlproperty list FolderListModel::nameFilters + + The \a nameFilters property contains a list of filename filters. + The filters may include the ? and * wildcards. + + The example below filters on PNG and JPEG files: + + \code + FolderListModel { + nameFilters: [ "*.png", "*.jpg" ] + } + \endcode +*/ +QStringList QDeclarativeFolderListModel::nameFilters() const +{ + return d->nameFilters; +} + +void QDeclarativeFolderListModel::setNameFilters(const QStringList &filters) +{ + d->nameFilters = filters; + d->model.setNameFilters(d->nameFilters); +} + +void QDeclarativeFolderListModel::classBegin() +{ +} + +void QDeclarativeFolderListModel::componentComplete() +{ + if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile())) + setFolder(QUrl(QLatin1String("file://")+QDir::currentPath())); + + if (!d->folderIndex.isValid()) + QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); +} + +QDeclarativeFolderListModel::SortField QDeclarativeFolderListModel::sortField() const +{ + return d->sortField; +} + +void QDeclarativeFolderListModel::setSortField(SortField field) +{ + if (field != d->sortField) { + d->sortField = field; + d->updateSorting(); + } +} + +bool QDeclarativeFolderListModel::sortReversed() const +{ + return d->sortReversed; +} + +void QDeclarativeFolderListModel::setSortReversed(bool rev) +{ + if (rev != d->sortReversed) { + d->sortReversed = rev; + d->updateSorting(); + } +} + +/*! + \qmlmethod bool FolderListModel::isFolder(int index) + + Returns true if the entry \a index is a folder; otherwise + returns false. +*/ +bool QDeclarativeFolderListModel::isFolder(int index) const +{ + if (index != -1) { + QModelIndex idx = d->model.index(index, 0, d->folderIndex); + if (idx.isValid()) + return d->model.isDir(idx); + } + return false; +} + +void QDeclarativeFolderListModel::refresh() +{ + d->folderIndex = QModelIndex(); + if (d->count) { + emit beginRemoveRows(QModelIndex(), 0, d->count); + d->count = 0; + emit endRemoveRows(); + } + d->folderIndex = d->model.index(d->folder.toLocalFile()); + int newcount = d->model.rowCount(d->folderIndex); + if (newcount) { + emit beginInsertRows(QModelIndex(), 0, newcount-1); + d->count = newcount; + emit endInsertRows(); + } +} + +void QDeclarativeFolderListModel::inserted(const QModelIndex &index, int start, int end) +{ + if (index == d->folderIndex) { + emit beginInsertRows(QModelIndex(), start, end); + d->count = d->model.rowCount(d->folderIndex); + emit endInsertRows(); + } +} + +void QDeclarativeFolderListModel::removed(const QModelIndex &index, int start, int end) +{ + if (index == d->folderIndex) { + emit beginRemoveRows(QModelIndex(), start, end); + d->count = d->model.rowCount(d->folderIndex); + emit endRemoveRows(); + } +} + +void QDeclarativeFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) +{ + if (start.parent() == d->folderIndex) + emit dataChanged(index(start.row(),0), index(end.row(),0)); +} + +/*! + \qmlproperty bool FolderListModel::showDirs + + If true (the default), directories are included in the model. + + Note that the nameFilters are ignored for directories. +*/ +bool QDeclarativeFolderListModel::showDirs() const +{ + return d->model.filter() & QDir::AllDirs; +} + +void QDeclarativeFolderListModel::setShowDirs(bool on) +{ + if (!(d->model.filter() & QDir::AllDirs) == !on) + return; + if (on) + d->model.setFilter(d->model.filter() | QDir::AllDirs | QDir::Drives); + else + d->model.setFilter(d->model.filter() & ~(QDir::AllDirs | QDir::Drives)); +} + +/*! + \qmlproperty bool FolderListModel::showDotAndDotDot + + If true, the "." and ".." directories are included in the model. + + The default is false. +*/ +bool QDeclarativeFolderListModel::showDotAndDotDot() const +{ + return !(d->model.filter() & QDir::NoDotAndDotDot); +} + +void QDeclarativeFolderListModel::setShowDotAndDotDot(bool on) +{ + if (!(d->model.filter() & QDir::NoDotAndDotDot) == on) + return; + if (on) + d->model.setFilter(d->model.filter() & ~QDir::NoDotAndDotDot); + else + d->model.setFilter(d->model.filter() | QDir::NoDotAndDotDot); +} + +/*! + \qmlproperty bool FolderListModel::showOnlyReadable + + If true, only readable files and directories are shown. + + The default is false. +*/ +bool QDeclarativeFolderListModel::showOnlyReadable() const +{ + return d->model.filter() & QDir::Readable; +} + +void QDeclarativeFolderListModel::setShowOnlyReadable(bool on) +{ + if (!(d->model.filter() & QDir::Readable) == !on) + return; + if (on) + d->model.setFilter(d->model.filter() | QDir::Readable); + else + d->model.setFilter(d->model.filter() & ~QDir::Readable); +} diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h new file mode 100644 index 0000000..e610a14 --- /dev/null +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEFOLDERLISTMODEL_H +#define QDECLARATIVEFOLDERLISTMODEL_H + +#include +#include +#include +#include + +class QDeclarativeContext; +class QModelIndex; + +class QDeclarativeFolderListModelPrivate; +class QDeclarativeFolderListModel : public QAbstractListModel, public QDeclarativeParserStatus +{ + Q_OBJECT + Q_INTERFACES(QDeclarativeParserStatus) + + Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged) + Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged) + Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) + Q_PROPERTY(SortField sortField READ sortField WRITE setSortField) + Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed) + Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs) + Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) + Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) + Q_PROPERTY(int count READ count) + +public: + QDeclarativeFolderListModel(QObject *parent = 0); + ~QDeclarativeFolderListModel(); + + enum Roles { FileNameRole = Qt::UserRole+1, FilePathRole = Qt::UserRole+2 }; + + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + + int count() const { return rowCount(QModelIndex()); } + + QUrl folder() const; + void setFolder(const QUrl &folder); + + QUrl parentFolder() const; + + QStringList nameFilters() const; + void setNameFilters(const QStringList &filters); + + virtual void classBegin(); + virtual void componentComplete(); + + Q_INVOKABLE bool isFolder(int index) const; + + enum SortField { Unsorted, Name, Time, Size, Type }; + SortField sortField() const; + void setSortField(SortField field); + Q_ENUMS(SortField) + + bool sortReversed() const; + void setSortReversed(bool rev); + + bool showDirs() const; + void setShowDirs(bool); + bool showDotAndDotDot() const; + void setShowDotAndDotDot(bool); + bool showOnlyReadable() const; + void setShowOnlyReadable(bool); + +Q_SIGNALS: + void folderChanged(); + +private Q_SLOTS: + void refresh(); + void inserted(const QModelIndex &index, int start, int end); + void removed(const QModelIndex &index, int start, int end); + void dataChanged(const QModelIndex &start, const QModelIndex &end); + +private: + Q_DISABLE_COPY(QDeclarativeFolderListModel) + QDeclarativeFolderListModelPrivate *d; +}; + +QML_DECLARE_TYPE(QDeclarativeFolderListModel) + +#endif // QDECLARATIVEFOLDERLISTMODEL_H diff --git a/src/imports/folderlistmodel/qmldir b/src/imports/folderlistmodel/qmldir new file mode 100644 index 0000000..6e115bb --- /dev/null +++ b/src/imports/folderlistmodel/qmldir @@ -0,0 +1 @@ +plugin qmlfolderlistmodelplugin diff --git a/src/imports/imports.pro b/src/imports/imports.pro index df43b76..e937742 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -SUBDIRS += dirmodel particles gestures +SUBDIRS += folderlistmodel particles gestures contains(QT_CONFIG, webkit): SUBDIRS += webkit contains(QT_CONFIG, mediaservices): SUBDIRS += multimedia -- cgit v0.12 From 300a259e13906e8dde204e3f33dab88ea80f8302 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 18 May 2010 13:10:33 +1000 Subject: Test Qt.labs.folderlistmodel plugin --- .../qdeclarativefolderlistmodel/data/basic.qml | 5 + .../qdeclarativefolderlistmodel/data/dummy.qml | 1 + .../qdeclarativefolderlistmodel.pro | 17 ++++ .../tst_qdeclarativefolderlistmodel.cpp | 113 +++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativefolderlistmodel/data/basic.qml create mode 100644 tests/auto/declarative/qdeclarativefolderlistmodel/data/dummy.qml create mode 100644 tests/auto/declarative/qdeclarativefolderlistmodel/qdeclarativefolderlistmodel.pro create mode 100644 tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp diff --git a/tests/auto/declarative/qdeclarativefolderlistmodel/data/basic.qml b/tests/auto/declarative/qdeclarativefolderlistmodel/data/basic.qml new file mode 100644 index 0000000..2c4977d --- /dev/null +++ b/tests/auto/declarative/qdeclarativefolderlistmodel/data/basic.qml @@ -0,0 +1,5 @@ +import Qt.labs.folderlistmodel 1.0 + +FolderListModel { + nameFilters: [ "*.qml" ] +} diff --git a/tests/auto/declarative/qdeclarativefolderlistmodel/data/dummy.qml b/tests/auto/declarative/qdeclarativefolderlistmodel/data/dummy.qml new file mode 100644 index 0000000..609638b --- /dev/null +++ b/tests/auto/declarative/qdeclarativefolderlistmodel/data/dummy.qml @@ -0,0 +1 @@ +// This file is not used, it is just content for QDirModel diff --git a/tests/auto/declarative/qdeclarativefolderlistmodel/qdeclarativefolderlistmodel.pro b/tests/auto/declarative/qdeclarativefolderlistmodel/qdeclarativefolderlistmodel.pro new file mode 100644 index 0000000..487d0e1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativefolderlistmodel/qdeclarativefolderlistmodel.pro @@ -0,0 +1,17 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += tst_qdeclarativefolderlistmodel.cpp + +# Define SRCDIR equal to test's source directory +symbian: { + DEFINES += SRCDIR=\".\" + importFiles.sources = data + importFiles.path = + DEPLOYMENT = importFiles +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} + +CONFIG += parallel_test diff --git a/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp b/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp new file mode 100644 index 0000000..8a8bfe7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativefolderlistmodel/tst_qdeclarativefolderlistmodel.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 "../../../shared/util.h" +#include +#include +#include +#include +#include +#include + +// From qdeclarastivefolderlistmodel.h +const int FileNameRole = Qt::UserRole+1; +const int FilePathRole = Qt::UserRole+2; +enum SortField { Unsorted, Name, Time, Size, Type }; + +class tst_qdeclarativefolderlistmodel : public QObject +{ + Q_OBJECT +public: + tst_qdeclarativefolderlistmodel() {} + +private slots: + void basicProperties(); + +private: + void checkNoErrors(const QDeclarativeComponent& component); + QDeclarativeEngine engine; +}; + +void tst_qdeclarativefolderlistmodel::checkNoErrors(const QDeclarativeComponent& component) +{ + // Wait until the component is ready + QTRY_VERIFY(component.isReady() || component.isError()); + + if (component.isError()) { + QList errors = component.errors(); + for (int ii = 0; ii < errors.count(); ++ii) { + const QDeclarativeError &error = errors.at(ii); + QByteArray errorStr = QByteArray::number(error.line()) + ":" + + QByteArray::number(error.column()) + ":" + + error.description().toUtf8(); + qWarning() << errorStr; + } + } + QVERIFY(!component.isError()); +} + +void tst_qdeclarativefolderlistmodel::basicProperties() +{ + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/basic.qml")); + checkNoErrors(component); + + QAbstractListModel *flm = qobject_cast(component.create()); + QVERIFY(flm != 0); + + + flm->setProperty("folder",QUrl::fromLocalFile(SRCDIR "/data")); + QTRY_COMPARE(flm->property("count").toInt(),2); // wait for refresh + QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile(SRCDIR "/data")); + QCOMPARE(flm->property("parentFolder").toUrl(), QUrl::fromLocalFile(SRCDIR)); + QCOMPARE(flm->property("sortField").toInt(), int(Name)); + QCOMPARE(flm->property("nameFilters").toStringList(), QStringList() << "*.qml"); + QCOMPARE(flm->property("sortReversed").toBool(), false); + QCOMPARE(flm->property("showDirs").toBool(), true); + QCOMPARE(flm->property("showDotAndDotDot").toBool(), false); + QCOMPARE(flm->property("showOnlyReadable").toBool(), false); + QCOMPARE(flm->data(flm->index(0),FileNameRole).toString(), QLatin1String("basic.qml")); + QCOMPARE(flm->data(flm->index(1),FileNameRole).toString(), QLatin1String("dummy.qml")); +} + +QTEST_MAIN(tst_qdeclarativefolderlistmodel) + +#include "tst_qdeclarativefolderlistmodel.moc" -- cgit v0.12 From 92b783a4ab9687baaf55d732965fe21aa69146a4 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 18 May 2010 13:23:46 +1000 Subject: git ignore stuff --- .gitignore | 1 + tests/.gitignore | 6 ++++++ tests/auto/declarative/.gitignore | 5 ----- 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 tests/.gitignore delete mode 100644 tests/auto/declarative/.gitignore diff --git a/.gitignore b/.gitignore index 5707371..fd7b495 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ bin/lrelease* bin/lupdate* bin/lconvert* bin/moc* +bin/makeqpf* bin/pixeltool* bin/qmake* bin/qdoc3* diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..b203473 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,6 @@ +QObject.log +tst_* +!tst_*.* +tst_*.log +tst_*.debug +tst_*~ diff --git a/tests/auto/declarative/.gitignore b/tests/auto/declarative/.gitignore deleted file mode 100644 index 57608cf..0000000 --- a/tests/auto/declarative/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -tst_* -!tst_*.* -tst_*.log -tst_*.debug -tst_*~ -- cgit v0.12 From 690ad58e03fb064e90e2e66e96419d82d9ee343d Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 18 May 2010 14:46:49 +1000 Subject: Documentation --- demos/declarative/rssnews/rssnews.qmlproject | 16 +++++++++ doc/src/declarative/examples.qdoc | 4 +-- doc/src/examples/qml-examples.qdoc | 7 +--- doc/src/examples/qml-rssnews.qdoc | 49 +++++++++++++++++++++++++++ doc/src/images/qml-rssnews-example.png | Bin 0 -> 143314 bytes 5 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 demos/declarative/rssnews/rssnews.qmlproject create mode 100644 doc/src/examples/qml-rssnews.qdoc create mode 100644 doc/src/images/qml-rssnews-example.png diff --git a/demos/declarative/rssnews/rssnews.qmlproject b/demos/declarative/rssnews/rssnews.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/demos/declarative/rssnews/rssnews.qmlproject @@ -0,0 +1,16 @@ +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/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc index cdc308a..a65614e 100644 --- a/doc/src/declarative/examples.qdoc +++ b/doc/src/declarative/examples.qdoc @@ -122,7 +122,6 @@ For example, from your build directory, run: \section2 XML \list -\o \l{declarative/xml/xmldata}{XML data} \o \l{declarative/xml/xmlhttprequest}{XmlHttpRequest} \endlist @@ -161,9 +160,10 @@ For example, from your build directory, run: \list \o \l{demos/declarative/calculator}{Calculator} +\o \l{demos/declarative/flickr}{Flickr Mobile} \o \l{demos/declarative/minehunt}{Minehunt} \o \l{demos/declarative/photoviewer}{Photo Viewer} -\o \l{demos/declarative/flickr}{Flickr Mobile} +\o \l{demos/declarative/rssnews}{RSS News Reader} \o \l{demos/declarative/samegame}{Same Game} \o \l{demos/declarative/snake}{Snake} \endlist diff --git a/doc/src/examples/qml-examples.qdoc b/doc/src/examples/qml-examples.qdoc index 22113ee..cad713e 100644 --- a/doc/src/examples/qml-examples.qdoc +++ b/doc/src/examples/qml-examples.qdoc @@ -175,7 +175,7 @@ */ /*! - \title Threaded ListModel + \title Threaded ListModel \example declarative/threading/threadedlistmodel */ @@ -268,11 +268,6 @@ */ /*! - \title XML Data - \example declarative/xml/xmldata -*/ - -/*! \title XMLHttpRequest \example declarative/xml/xmlhttprequest */ diff --git a/doc/src/examples/qml-rssnews.qdoc b/doc/src/examples/qml-rssnews.qdoc new file mode 100644 index 0000000..0e7bdef --- /dev/null +++ b/doc/src/examples/qml-rssnews.qdoc @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +/*! + \title RSS News + \example demos/declarative/rssnews + + This demo shows how to write a RSS news reader in QML. + + \image qml-rssnews-example.png +*/ diff --git a/doc/src/images/qml-rssnews-example.png b/doc/src/images/qml-rssnews-example.png new file mode 100644 index 0000000..948ef4d Binary files /dev/null and b/doc/src/images/qml-rssnews-example.png differ -- cgit v0.12 From 3d1a6596c6a381b71718af22eb8a861830ec7b6b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 18 May 2010 14:51:58 +1000 Subject: Make sure strings are escaped when returned via asScript. Makes 273024e58d90bb9b3a5da0161f884f1af22d75df more correct. --- src/declarative/qml/qdeclarativecompiler.cpp | 46 +++++++++++----------- src/declarative/qml/qdeclarativeparser.cpp | 45 +++++++++++++++++++++ src/declarative/qml/qdeclarativeparser_p.h | 4 +- .../qdeclarativelanguage/data/emptySignal.qml | 2 +- .../qdeclarativelanguage/data/scriptString2.qml | 2 +- .../tst_qdeclarativelanguage.cpp | 6 +-- 6 files changed, 75 insertions(+), 30 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 19c12ff..d880844 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -180,7 +180,7 @@ bool QDeclarativeCompiler::isSignalPropertyName(const QByteArray &name) bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop, QDeclarativeParser::Value *v) { - QString string = v->value.asScript(); + QString string = v->value.asString(); if (!prop.isWritable()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name()))); @@ -207,31 +207,31 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop, break; case QVariant::UInt: { - bool ok; - string.toUInt(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: unsigned int expected")); + bool ok = v->value.isNumber(); + if (ok) { + double n = v->value.asNumber(); + if (double(uint(n)) != n) + ok = false; + } + if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: unsigned int expected")); } break; case QVariant::Int: { - bool ok; - string.toInt(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: int expected")); + bool ok = v->value.isNumber(); + if (ok) { + double n = v->value.asNumber(); + if (double(int(n)) != n) + ok = false; + } + if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: int expected")); } break; case QMetaType::Float: - { - bool ok; - string.toFloat(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: float expected")); - } + if (!v->value.isNumber()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: float expected")); break; case QVariant::Double: - { - bool ok; - string.toDouble(&ok); - if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: double expected")); - } + if (!v->value.isNumber()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: double expected")); break; case QVariant::Color: { @@ -319,7 +319,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop, void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop, QDeclarativeParser::Value *v) { - QString string = v->value.asScript(); + QString string = v->value.asString(); QDeclarativeInstruction instr; instr.line = v->location.start.line; @@ -382,28 +382,28 @@ void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop, { instr.type = QDeclarativeInstruction::StoreInteger; instr.storeInteger.propertyIndex = prop.propertyIndex(); - instr.storeInteger.value = string.toUInt(); + instr.storeInteger.value = uint(v->value.asNumber()); } break; case QVariant::Int: { instr.type = QDeclarativeInstruction::StoreInteger; instr.storeInteger.propertyIndex = prop.propertyIndex(); - instr.storeInteger.value = string.toInt(); + instr.storeInteger.value = int(v->value.asNumber()); } break; case QMetaType::Float: { instr.type = QDeclarativeInstruction::StoreFloat; instr.storeFloat.propertyIndex = prop.propertyIndex(); - instr.storeFloat.value = string.toFloat(); + instr.storeFloat.value = float(v->value.asNumber()); } break; case QVariant::Double: { instr.type = QDeclarativeInstruction::StoreDouble; instr.storeDouble.propertyIndex = prop.propertyIndex(); - instr.storeDouble.value = string.toDouble(); + instr.storeDouble.value = v->value.asNumber(); } break; case QVariant::Color: @@ -1187,7 +1187,7 @@ bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj, if (idProp) { if (idProp->value || idProp->values.count() > 1 || idProp->values.at(0)->object) COMPILE_EXCEPTION(idProp, tr("Invalid component id specification")); - COMPILE_CHECK(checkValidId(idProp->values.first(), idProp->values.first()->primitive())); + COMPILE_CHECK(checkValidId(idProp->values.first(), idProp->values.first()->primitive())) QString idVal = idProp->values.first()->primitive(); diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp index b38bd76..8d00ef8 100644 --- a/src/declarative/qml/qdeclarativeparser.cpp +++ b/src/declarative/qml/qdeclarativeparser.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include QT_BEGIN_NAMESPACE @@ -310,6 +311,49 @@ double QDeclarativeParser::Variant::asNumber() const return d; } +//reverse of Lexer::singleEscape() +QString escapedString(const QString &string) +{ + QString tmp = QLatin1String("\""); + for (int i = 0; i < string.length(); ++i) { + const QChar &c = string.at(i); + switch(c.unicode()) { + case 0x08: + tmp += QLatin1String("\\b"); + break; + case 0x09: + tmp += QLatin1String("\\t"); + break; + case 0x0A: + tmp += QLatin1String("\\n"); + break; + case 0x0B: + tmp += QLatin1String("\\v"); + break; + case 0x0C: + tmp += QLatin1String("\\f"); + break; + case 0x0D: + tmp += QLatin1String("\\r"); + break; + case 0x22: + tmp += QLatin1String("\\\""); + break; + case 0x27: + tmp += QLatin1String("\\\'"); + break; + case 0x5C: + tmp += QLatin1String("\\\\"); + break; + default: + tmp += c; + break; + } + } + tmp += QLatin1Char('\"'); + return tmp; +} + QString QDeclarativeParser::Variant::asScript() const { switch(type()) { @@ -324,6 +368,7 @@ QString QDeclarativeParser::Variant::asScript() const else return s; case String: + return escapedString(s); case Script: return s; } diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h index 25777f5..d192f3a 100644 --- a/src/declarative/qml/qdeclarativeparser_p.h +++ b/src/declarative/qml/qdeclarativeparser_p.h @@ -307,8 +307,8 @@ namespace QDeclarativeParser }; Type type; - // ### Temporary - QString primitive() const { return value.asScript(); } + // ### Temporary (for id only) + QString primitive() const { return value.isString() ? value.asString() : value.asScript(); } // Primitive value Variant value; diff --git a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.qml b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.qml index 4c5a122..ba3545e 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.qml +++ b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.qml @@ -1,6 +1,6 @@ import Test 1.0 MyQmlObject { - onBasicSignal: " " + onBasicSignal: " " } diff --git a/tests/auto/declarative/qdeclarativelanguage/data/scriptString2.qml b/tests/auto/declarative/qdeclarativelanguage/data/scriptString2.qml index 0de3667..c42da2b 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/scriptString2.qml +++ b/tests/auto/declarative/qdeclarativelanguage/data/scriptString2.qml @@ -1,5 +1,5 @@ import Test 1.0 MyTypeObject { - scriptProperty: "hello world" + scriptProperty: "hello\n\"world\"" } diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index b72c75f..cb2764f 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -351,7 +351,8 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("invalidAttachedProperty.12") << "invalidAttachedProperty.12.qml" << "invalidAttachedProperty.12.errors.txt" << false; QTest::newRow("invalidAttachedProperty.13") << "invalidAttachedProperty.13.qml" << "invalidAttachedProperty.13.errors.txt" << false; - QTest::newRow("emptySignal") << "emptySignal.qml" << "emptySignal.errors.txt" << false; + //### this is no longer considered empty (and should produce a different error: QTBUG-10764) + //QTest::newRow("emptySignal") << "emptySignal.qml" << "emptySignal.errors.txt" << false; QTest::newRow("emptySignal.2") << "emptySignal.2.qml" << "emptySignal.2.errors.txt" << false; QTest::newRow("nestedErrors") << "nestedErrors.qml" << "nestedErrors.errors.txt" << false; @@ -1127,8 +1128,7 @@ void tst_qdeclarativelanguage::scriptString() MyTypeObject *object = qobject_cast(component.create()); QVERIFY(object != 0); - QEXPECT_FAIL("", "Variant.asScript() returns incorrect value for string (bug pending)", Continue); - QCOMPARE(object->scriptProperty().script(), QString("\"hello world\"")); + QCOMPARE(object->scriptProperty().script(), QString("\"hello\\n\\\"world\\\"\"")); } { -- cgit v0.12 From 9a111f72362b39be9b10d5d365faa21dfebf770e Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 18 May 2010 15:40:53 +1000 Subject: Prevent assignment of values (string, number, bool) to signal handlers. Task-number: QTBUG-10764 Reviewed-by: Aaron Kennedy --- src/declarative/qml/qdeclarativecompiler.cpp | 3 +++ .../qdeclarativelanguage/data/assignValueToSignal.errors.txt | 1 + .../declarative/qdeclarativelanguage/data/assignValueToSignal.qml | 6 ++++++ .../declarative/qdeclarativelanguage/data/emptySignal.2.errors.txt | 1 - tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.qml | 7 ------- .../declarative/qdeclarativelanguage/data/emptySignal.errors.txt | 2 +- tests/auto/declarative/qdeclarativelanguage/data/emptySignal.qml | 3 ++- .../declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 5 ++--- 8 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/assignValueToSignal.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/assignValueToSignal.qml delete mode 100644 tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.errors.txt delete mode 100644 tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index d880844..b5bf972 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1316,6 +1316,9 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl } else { prop->values.at(0)->type = Value::SignalExpression; + if (!prop->values.at(0)->value.isScript()) + COMPILE_EXCEPTION(prop, tr("Cannot assign a value to a signal (expecting a script to be run)")); + QString script = prop->values.at(0)->value.asScript().trimmed(); if (script.isEmpty()) COMPILE_EXCEPTION(prop, tr("Empty signal assignment")); diff --git a/tests/auto/declarative/qdeclarativelanguage/data/assignValueToSignal.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/assignValueToSignal.errors.txt new file mode 100644 index 0000000..eb1430a --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/assignValueToSignal.errors.txt @@ -0,0 +1 @@ +4:5:Cannot assign a value to a signal (expecting a script to be run) diff --git a/tests/auto/declarative/qdeclarativelanguage/data/assignValueToSignal.qml b/tests/auto/declarative/qdeclarativelanguage/data/assignValueToSignal.qml new file mode 100644 index 0000000..6fa1259 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/assignValueToSignal.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyQmlObject { + onBasicSignal: "hello world" +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.errors.txt deleted file mode 100644 index 8b20434..0000000 --- a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.errors.txt +++ /dev/null @@ -1 +0,0 @@ -4:5:Incorrectly specified signal assignment diff --git a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.qml b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.qml deleted file mode 100644 index c84fea3..0000000 --- a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.2.qml +++ /dev/null @@ -1,7 +0,0 @@ -import Test 1.0 - -MyQmlObject { - onBasicSignal { - } -} - diff --git a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.errors.txt index 353bbf5..8b20434 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.errors.txt @@ -1 +1 @@ -4:5:Empty signal assignment +4:5:Incorrectly specified signal assignment diff --git a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.qml b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.qml index ba3545e..c84fea3 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.qml +++ b/tests/auto/declarative/qdeclarativelanguage/data/emptySignal.qml @@ -1,6 +1,7 @@ import Test 1.0 MyQmlObject { - onBasicSignal: " " + onBasicSignal { + } } diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index cb2764f..200f016 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -351,9 +351,8 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("invalidAttachedProperty.12") << "invalidAttachedProperty.12.qml" << "invalidAttachedProperty.12.errors.txt" << false; QTest::newRow("invalidAttachedProperty.13") << "invalidAttachedProperty.13.qml" << "invalidAttachedProperty.13.errors.txt" << false; - //### this is no longer considered empty (and should produce a different error: QTBUG-10764) - //QTest::newRow("emptySignal") << "emptySignal.qml" << "emptySignal.errors.txt" << false; - QTest::newRow("emptySignal.2") << "emptySignal.2.qml" << "emptySignal.2.errors.txt" << false; + QTest::newRow("assignValueToSignal") << "assignValueToSignal.qml" << "assignValueToSignal.errors.txt" << false; + QTest::newRow("emptySignal") << "emptySignal.qml" << "emptySignal.errors.txt" << false; QTest::newRow("nestedErrors") << "nestedErrors.qml" << "nestedErrors.errors.txt" << false; QTest::newRow("defaultGrouped") << "defaultGrouped.qml" << "defaultGrouped.errors.txt" << false; -- cgit v0.12 From 11ccb46495c18cc2a12ad599a9e985b0e3cd7b95 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 18 May 2010 10:26:03 +1000 Subject: Improve docs for Qt.quit() --- doc/src/declarative/globalobject.qdoc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 2a83e30..c29a796 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -219,8 +219,9 @@ Binary to ASCII - this function returns a base64 encoding of \c data. ASCII to binary - this function returns a base64 decoding of \c data. \section3 Qt.quit() -This function causes the QML engine to emit the quit signal, which in -\l {Qt Declarative UI Runtime}{qml} causes the runtime to quit. +This function causes the QDeclarativeEngine::quit() signal to be emitted. +Within the \l {Qt Declarative UI Runtime}{qml} application this causes the +launcher application to exit. \section3 Qt.resolvedUrl(url) This function returns \c url resolved relative to the URL of the -- cgit v0.12 From 711a9a8294d354c1a745b0f6a550672403b7e6fd Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 18 May 2010 15:07:46 +1000 Subject: doc fix --- src/declarative/qml/qdeclarativeworkerscript.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp index 4b687a9..8182998 100644 --- a/src/declarative/qml/qdeclarativeworkerscript.cpp +++ b/src/declarative/qml/qdeclarativeworkerscript.cpp @@ -527,7 +527,7 @@ void QDeclarativeWorkerScriptEngine::run() \snippet doc/src/snippets/declarative/workerscript.qml 0 The above worker script specifies a javascript file, "script.js", that handles - the operations to be performed in the new thread: + the operations to be performed in the new thread. Here is \c script.js: \qml WorkerScript.onMessage = function(message) { @@ -538,7 +538,7 @@ void QDeclarativeWorkerScriptEngine::run() When the user clicks anywhere within the rectangle, \c sendMessage() is called, triggering the \tt WorkerScript.onMessage() handler in - \tt source.js. This in turn sends a reply message that is then received + \tt script.js. This in turn sends a reply message that is then received by the \tt onMessage() handler of \tt myWorker. */ QDeclarativeWorkerScript::QDeclarativeWorkerScript(QObject *parent) -- cgit v0.12 From ffccebed9af217cc5bf2f3e4eba00df754eb7ac9 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 18 May 2010 16:09:53 +1000 Subject: Make Qt.include() work for js files that have '.pragma library' --- src/declarative/qml/qdeclarativeinclude.cpp | 3 +++ .../qdeclarativeecmascript/data/include_pragma.qml | 11 +++++++++++ .../qdeclarativeecmascript/data/include_pragma_inner.js | 5 +++++ .../qdeclarativeecmascript/data/include_pragma_outer.js | 6 ++++++ .../qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 11 +++++++++++ 5 files changed, 36 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/include_pragma.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_inner.js create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_outer.js diff --git a/src/declarative/qml/qdeclarativeinclude.cpp b/src/declarative/qml/qdeclarativeinclude.cpp index 619264a..e37b68b 100644 --- a/src/declarative/qml/qdeclarativeinclude.cpp +++ b/src/declarative/qml/qdeclarativeinclude.cpp @@ -140,6 +140,7 @@ void QDeclarativeInclude::finished() scriptContext->pushScope(m_scope[1]); scriptContext->setActivationObject(m_scope[1]); + QDeclarativeScriptParser::extractPragmas(code); m_scriptEngine->evaluate(code, urlString, 1); @@ -230,6 +231,7 @@ QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *e QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -5); scriptContext->pushScope(scope); scriptContext->setActivationObject(scope); + QDeclarativeScriptParser::extractPragmas(code); engine->evaluate(code, urlString, 1); @@ -291,6 +293,7 @@ QScriptValue QDeclarativeInclude::worker_include(QScriptContext *ctxt, QScriptEn QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -4); scriptContext->pushScope(scope); scriptContext->setActivationObject(scope); + QDeclarativeScriptParser::extractPragmas(code); engine->evaluate(code, urlString, 1); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma.qml b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma.qml new file mode 100644 index 0000000..67b8cfd --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma.qml @@ -0,0 +1,11 @@ +import Qt 4.7 +import "include_pragma_outer.js" as Script + +Item { + property int test1 + + Component.onCompleted: { + test1 = Script.callFunction() + } +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_inner.js b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_inner.js new file mode 100644 index 0000000..a0380a2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_inner.js @@ -0,0 +1,5 @@ +.pragma library + +function getValue() { + return 100; +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_outer.js b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_outer.js new file mode 100644 index 0000000..d87bafc --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/include_pragma_outer.js @@ -0,0 +1,6 @@ +Qt.include("include_pragma_inner.js") + +function callFunction() { + return getValue(); +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 0710e15..9a88237 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -2424,6 +2424,17 @@ void tst_qdeclarativeecmascript::include() delete o; } + // Including file with ".pragma library" + { + QDeclarativeComponent component(&engine, TEST_FILE("include_pragma.qml")); + qDebug() << "errors:" << component.errorsString(); + QObject *o = component.create(); + QVERIFY(o != 0); + QCOMPARE(o->property("test1").toInt(), 100); + + delete o; + } + // Remote - success { TestHTTPServer server(8111); -- cgit v0.12 From 633a5cf6d8197105d6392dbf56bf0f29f9c84da1 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Tue, 18 May 2010 16:26:20 +1000 Subject: Regression fix for Loader anchors not working Task-number: QTBUG-10766 Reviewed-by: Yann Bodson --- .../graphicsitems/qdeclarativeloader.cpp | 1 + .../qdeclarativeloader/data/AnchoredLoader.qml | 14 ++++++++++++++ .../qdeclarativeloader/tst_qdeclarativeloader.cpp | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeloader/data/AnchoredLoader.qml diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index cbdfd87..94983c4 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -366,6 +366,7 @@ QDeclarativeLoader::Status QDeclarativeLoader::status() const void QDeclarativeLoader::componentComplete() { + QDeclarativeItem::componentComplete(); if (status() == Ready) emit loaded(); } diff --git a/tests/auto/declarative/qdeclarativeloader/data/AnchoredLoader.qml b/tests/auto/declarative/qdeclarativeloader/data/AnchoredLoader.qml new file mode 100644 index 0000000..5d02dae --- /dev/null +++ b/tests/auto/declarative/qdeclarativeloader/data/AnchoredLoader.qml @@ -0,0 +1,14 @@ +import Qt 4.7 + +Rectangle { + width: 300 + height: 200 + color: "blue" + Loader { + objectName: "loader" + anchors.fill: parent + sourceComponent: Component { + Rectangle { color: "red"; objectName: "sourceElement" } + } + } +} diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp index 59580ea..11cc61b 100644 --- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp +++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp @@ -78,6 +78,7 @@ private slots: void clear(); void urlToComponent(); void componentToUrl(); + void anchoredLoader(); void sizeLoaderToItem(); void sizeItemToLoader(); void noResize(); @@ -266,6 +267,27 @@ void tst_QDeclarativeLoader::componentToUrl() delete item; } +void tst_QDeclarativeLoader::anchoredLoader() +{ + QDeclarativeComponent component(&engine, TEST_FILE("/AnchoredLoader.qml")); + QDeclarativeItem *rootItem = qobject_cast(component.create()); + QVERIFY(rootItem != 0); + QDeclarativeItem *loader = rootItem->findChild("loader"); + QDeclarativeItem *sourceElement = rootItem->findChild("sourceElement"); + + QVERIFY(loader != 0); + QVERIFY(sourceElement != 0); + + QCOMPARE(rootItem->width(), 300.0); + QCOMPARE(rootItem->height(), 200.0); + + QCOMPARE(loader->width(), 300.0); + QCOMPARE(loader->height(), 200.0); + + QCOMPARE(sourceElement->width(), 300.0); + QCOMPARE(sourceElement->height(), 200.0); +} + void tst_QDeclarativeLoader::sizeLoaderToItem() { QDeclarativeComponent component(&engine, TEST_FILE("/SizeToItem.qml")); -- cgit v0.12 From f4492bf01baae353ff63da18a9a602fb3a8058e4 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 18 May 2010 17:43:20 +1000 Subject: Rename some examples: proxyviewer -> networkaccessmanagerfactory, proxywidgets -> qwidgets, dynamic -> dynamicscene, velocity -> corkboards --- doc/src/declarative/examples.qdoc | 8 +- doc/src/examples/qml-examples.qdoc | 24 +-- .../declarative/cppextensions/cppextensions.pro | 4 +- .../networkaccessmanagerfactory/main.cpp | 109 +++++++++++++ .../networkaccessmanagerfactory.pro | 9 ++ .../networkaccessmanagerfactory.qrc | 5 + .../networkaccessmanagerfactory/view.qml | 7 + .../declarative/cppextensions/proxyviewer/main.cpp | 109 ------------- .../cppextensions/proxyviewer/proxyviewer.pro | 9 -- .../cppextensions/proxyviewer/proxyviewer.qrc | 5 - .../declarative/cppextensions/proxyviewer/view.qml | 7 - .../cppextensions/proxywidgets/ProxyWidgets/qmldir | 1 - .../declarative/cppextensions/proxywidgets/README | 4 - .../cppextensions/proxywidgets/proxywidgets.cpp | 97 ------------ .../cppextensions/proxywidgets/proxywidgets.pro | 21 --- .../cppextensions/proxywidgets/proxywidgets.qml | 70 -------- .../proxywidgets/proxywidgets.qmlproject | 16 -- .../cppextensions/qwidgets/QWidgets/qmldir | 1 + examples/declarative/cppextensions/qwidgets/README | 6 + .../cppextensions/qwidgets/qwidgets.cpp | 97 ++++++++++++ .../cppextensions/qwidgets/qwidgets.pro | 21 +++ .../cppextensions/qwidgets/qwidgets.qml | 70 ++++++++ .../cppextensions/qwidgets/qwidgets.qmlproject | 16 ++ examples/declarative/toys/corkboards/Day.qml | 101 ++++++++++++ examples/declarative/toys/corkboards/cork.jpg | Bin 0 -> 149337 bytes .../declarative/toys/corkboards/corkboards.qml | 75 +++++++++ .../toys/corkboards/corkboards.qmlproject | 16 ++ .../declarative/toys/corkboards/note-yellow.png | Bin 0 -> 54559 bytes examples/declarative/toys/corkboards/tack.png | Bin 0 -> 7282 bytes examples/declarative/toys/dynamic/dynamic.qml | 176 --------------------- .../declarative/toys/dynamic/dynamic.qmlproject | 16 -- examples/declarative/toys/dynamic/images/NOTE | 1 - .../declarative/toys/dynamic/images/face-smile.png | Bin 15408 -> 0 bytes examples/declarative/toys/dynamic/images/moon.png | Bin 1757 -> 0 bytes .../toys/dynamic/images/rabbit_brown.png | Bin 1245 -> 0 bytes .../declarative/toys/dynamic/images/rabbit_bw.png | Bin 1759 -> 0 bytes examples/declarative/toys/dynamic/images/star.png | Bin 349 -> 0 bytes examples/declarative/toys/dynamic/images/sun.png | Bin 8153 -> 0 bytes .../declarative/toys/dynamic/images/tree_s.png | Bin 3406 -> 0 bytes examples/declarative/toys/dynamic/qml/Button.qml | 40 ----- .../declarative/toys/dynamic/qml/PaletteItem.qml | 19 --- .../toys/dynamic/qml/PerspectiveItem.qml | 25 --- examples/declarative/toys/dynamic/qml/Sun.qml | 38 ----- .../declarative/toys/dynamic/qml/itemCreation.js | 65 -------- .../declarative/toys/dynamicscene/dynamicscene.qml | 176 +++++++++++++++++++++ .../toys/dynamicscene/dynamicscene.qmlproject | 16 ++ examples/declarative/toys/dynamicscene/images/NOTE | 1 + .../toys/dynamicscene/images/face-smile.png | Bin 0 -> 15408 bytes .../declarative/toys/dynamicscene/images/moon.png | Bin 0 -> 1757 bytes .../toys/dynamicscene/images/rabbit_brown.png | Bin 0 -> 1245 bytes .../toys/dynamicscene/images/rabbit_bw.png | Bin 0 -> 1759 bytes .../declarative/toys/dynamicscene/images/star.png | Bin 0 -> 349 bytes .../declarative/toys/dynamicscene/images/sun.png | Bin 0 -> 8153 bytes .../toys/dynamicscene/images/tree_s.png | Bin 0 -> 3406 bytes .../declarative/toys/dynamicscene/qml/Button.qml | 40 +++++ .../toys/dynamicscene/qml/PaletteItem.qml | 19 +++ .../toys/dynamicscene/qml/PerspectiveItem.qml | 25 +++ examples/declarative/toys/dynamicscene/qml/Sun.qml | 38 +++++ .../toys/dynamicscene/qml/itemCreation.js | 65 ++++++++ examples/declarative/toys/velocity/Day.qml | 101 ------------ examples/declarative/toys/velocity/cork.jpg | Bin 149337 -> 0 bytes examples/declarative/toys/velocity/note-yellow.png | Bin 54559 -> 0 bytes examples/declarative/toys/velocity/tack.png | Bin 7282 -> 0 bytes examples/declarative/toys/velocity/velocity.qml | 75 --------- .../declarative/toys/velocity/velocity.qmlproject | 16 -- 65 files changed, 931 insertions(+), 929 deletions(-) create mode 100644 examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp create mode 100644 examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.pro create mode 100644 examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.qrc create mode 100644 examples/declarative/cppextensions/networkaccessmanagerfactory/view.qml delete mode 100644 examples/declarative/cppextensions/proxyviewer/main.cpp delete mode 100644 examples/declarative/cppextensions/proxyviewer/proxyviewer.pro delete mode 100644 examples/declarative/cppextensions/proxyviewer/proxyviewer.qrc delete mode 100644 examples/declarative/cppextensions/proxyviewer/view.qml delete mode 100644 examples/declarative/cppextensions/proxywidgets/ProxyWidgets/qmldir delete mode 100644 examples/declarative/cppextensions/proxywidgets/README delete mode 100644 examples/declarative/cppextensions/proxywidgets/proxywidgets.cpp delete mode 100644 examples/declarative/cppextensions/proxywidgets/proxywidgets.pro delete mode 100644 examples/declarative/cppextensions/proxywidgets/proxywidgets.qml delete mode 100644 examples/declarative/cppextensions/proxywidgets/proxywidgets.qmlproject create mode 100644 examples/declarative/cppextensions/qwidgets/QWidgets/qmldir create mode 100644 examples/declarative/cppextensions/qwidgets/README create mode 100644 examples/declarative/cppextensions/qwidgets/qwidgets.cpp create mode 100644 examples/declarative/cppextensions/qwidgets/qwidgets.pro create mode 100644 examples/declarative/cppextensions/qwidgets/qwidgets.qml create mode 100644 examples/declarative/cppextensions/qwidgets/qwidgets.qmlproject create mode 100644 examples/declarative/toys/corkboards/Day.qml create mode 100644 examples/declarative/toys/corkboards/cork.jpg create mode 100644 examples/declarative/toys/corkboards/corkboards.qml create mode 100644 examples/declarative/toys/corkboards/corkboards.qmlproject create mode 100644 examples/declarative/toys/corkboards/note-yellow.png create mode 100644 examples/declarative/toys/corkboards/tack.png delete mode 100644 examples/declarative/toys/dynamic/dynamic.qml delete mode 100644 examples/declarative/toys/dynamic/dynamic.qmlproject delete mode 100644 examples/declarative/toys/dynamic/images/NOTE delete mode 100644 examples/declarative/toys/dynamic/images/face-smile.png delete mode 100644 examples/declarative/toys/dynamic/images/moon.png delete mode 100644 examples/declarative/toys/dynamic/images/rabbit_brown.png delete mode 100644 examples/declarative/toys/dynamic/images/rabbit_bw.png delete mode 100644 examples/declarative/toys/dynamic/images/star.png delete mode 100644 examples/declarative/toys/dynamic/images/sun.png delete mode 100644 examples/declarative/toys/dynamic/images/tree_s.png delete mode 100644 examples/declarative/toys/dynamic/qml/Button.qml delete mode 100644 examples/declarative/toys/dynamic/qml/PaletteItem.qml delete mode 100644 examples/declarative/toys/dynamic/qml/PerspectiveItem.qml delete mode 100644 examples/declarative/toys/dynamic/qml/Sun.qml delete mode 100644 examples/declarative/toys/dynamic/qml/itemCreation.js create mode 100644 examples/declarative/toys/dynamicscene/dynamicscene.qml create mode 100644 examples/declarative/toys/dynamicscene/dynamicscene.qmlproject create mode 100644 examples/declarative/toys/dynamicscene/images/NOTE create mode 100644 examples/declarative/toys/dynamicscene/images/face-smile.png create mode 100644 examples/declarative/toys/dynamicscene/images/moon.png create mode 100644 examples/declarative/toys/dynamicscene/images/rabbit_brown.png create mode 100644 examples/declarative/toys/dynamicscene/images/rabbit_bw.png create mode 100644 examples/declarative/toys/dynamicscene/images/star.png create mode 100644 examples/declarative/toys/dynamicscene/images/sun.png create mode 100644 examples/declarative/toys/dynamicscene/images/tree_s.png create mode 100644 examples/declarative/toys/dynamicscene/qml/Button.qml create mode 100644 examples/declarative/toys/dynamicscene/qml/PaletteItem.qml create mode 100644 examples/declarative/toys/dynamicscene/qml/PerspectiveItem.qml create mode 100644 examples/declarative/toys/dynamicscene/qml/Sun.qml create mode 100644 examples/declarative/toys/dynamicscene/qml/itemCreation.js delete mode 100644 examples/declarative/toys/velocity/Day.qml delete mode 100644 examples/declarative/toys/velocity/cork.jpg delete mode 100644 examples/declarative/toys/velocity/note-yellow.png delete mode 100644 examples/declarative/toys/velocity/tack.png delete mode 100644 examples/declarative/toys/velocity/velocity.qml delete mode 100644 examples/declarative/toys/velocity/velocity.qmlproject diff --git a/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc index a65614e..4ad57f2 100644 --- a/doc/src/declarative/examples.qdoc +++ b/doc/src/declarative/examples.qdoc @@ -139,20 +139,20 @@ For example, from your build directory, run: \list \o \l{declarative/cppextensions/referenceexamples}{Reference examples} (discussed in \l {Extending QML in C++}) \o \l{declarative/cppextensions/plugins}{Plugins} -\o \l{declarative/cppextensions/proxywidgets}{QtWidgets} \o \l{declarative/cppextensions/qgraphicslayouts}{QGraphicsLayouts} +\o \l{declarative/cppextensions/qwidgets}{QWidgets} \o \l{declarative/cppextensions/imageprovider}{Image provider} -\o \l{declarative/cppextensions/proxyviewer}{Network access manager factory} +\o \l{declarative/cppextensions/networkaccessmanagerfactory}{Network access manager factory} \endlist \section2 Toys \list \o \l{declarative/toys/clocks}{Clocks} +\o \l{declarative/toys/corkboards}{Corkboards} \o \l{declarative/toys/dial}{Dial} -\o \l{declarative/toys/dynamic}{Dynamic} +\o \l{declarative/toys/dynamicscene}{Dynamic Scene} \o \l{declarative/toys/tic-tac-toe}{Tic Tac Toe} \o \l{declarative/toys/tvtennis}{TV Tennis} -\o \l{declarative/toys/velocity}{Velocity} \endlist diff --git a/doc/src/examples/qml-examples.qdoc b/doc/src/examples/qml-examples.qdoc index cad713e..2973d8c 100644 --- a/doc/src/examples/qml-examples.qdoc +++ b/doc/src/examples/qml-examples.qdoc @@ -88,13 +88,13 @@ */ /*! - \title QtWidgets - \example declarative/cppextensions/proxywidgets + \title QGraphicsLayouts + \example declarative/cppextensions/qgraphicslayouts */ /*! - \title QGraphicsLayouts - \example declarative/cppextensions/qgraphicslayouts + \title QWidgets + \example declarative/cppextensions/qwidgets */ /*! @@ -104,7 +104,7 @@ /*! \title Network access manager - \example declarative/cppextensions/proxyviewer + \example declarative/cppextensions/networkaccessmanagerfactory */ /*! @@ -192,6 +192,11 @@ */ /*! + \title Corkboards + \example declarative/toys/corkboards +*/ + +/*! \title Dial \example declarative/toys/dial @@ -199,8 +204,8 @@ */ /*! - \title Dynamic - \example declarative/toys/dynamic + \title Dynamic Scene + \example declarative/toys/dynamicscene This example shows how to create dynamic objects QML. */ @@ -216,11 +221,6 @@ */ /*! - \title Velocity - \example declarative/toys/velocity -*/ - -/*! \title Gestures \example declarative/touchinteraction/gestures */ diff --git a/examples/declarative/cppextensions/cppextensions.pro b/examples/declarative/cppextensions/cppextensions.pro index caa6092..33762fe 100644 --- a/examples/declarative/cppextensions/cppextensions.pro +++ b/examples/declarative/cppextensions/cppextensions.pro @@ -3,8 +3,8 @@ TEMPLATE = subdirs SUBDIRS += \ imageprovider \ plugins \ - proxyviewer \ - proxywidgets \ + networkaccessmanagerfactory \ + qwidgets \ qgraphicslayouts \ referenceexamples diff --git a/examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp b/examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp new file mode 100644 index 0000000..4ecbb5c --- /dev/null +++ b/examples/declarative/cppextensions/networkaccessmanagerfactory/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: + networkaccessmanagerfactory [-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: networkaccessmanagerfactory [-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/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.pro b/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.pro new file mode 100644 index 0000000..74d8db3 --- /dev/null +++ b/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = networkaccessmanagerfactory +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative network + +# Input +SOURCES += main.cpp +RESOURCES += networkaccessmanagerfactory.qrc diff --git a/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.qrc b/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.qrc new file mode 100644 index 0000000..17e9301 --- /dev/null +++ b/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.qrc @@ -0,0 +1,5 @@ + + + view.qml + + diff --git a/examples/declarative/cppextensions/networkaccessmanagerfactory/view.qml b/examples/declarative/cppextensions/networkaccessmanagerfactory/view.qml new file mode 100644 index 0000000..7f1bdef --- /dev/null +++ b/examples/declarative/cppextensions/networkaccessmanagerfactory/view.qml @@ -0,0 +1,7 @@ +import Qt 4.7 + +Image { + width: 100 + height: 100 + source: "http://qt.nokia.com/logo.png" +} diff --git a/examples/declarative/cppextensions/proxyviewer/main.cpp b/examples/declarative/cppextensions/proxyviewer/main.cpp deleted file mode 100644 index b82d2c9..0000000 --- a/examples/declarative/cppextensions/proxyviewer/main.cpp +++ /dev/null @@ -1,109 +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 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/cppextensions/proxyviewer/proxyviewer.pro b/examples/declarative/cppextensions/proxyviewer/proxyviewer.pro deleted file mode 100644 index b6bfa7f..0000000 --- a/examples/declarative/cppextensions/proxyviewer/proxyviewer.pro +++ /dev/null @@ -1,9 +0,0 @@ -TEMPLATE = app -TARGET = proxyviewer -DEPENDPATH += . -INCLUDEPATH += . -QT += declarative network - -# Input -SOURCES += main.cpp -RESOURCES += proxyviewer.qrc diff --git a/examples/declarative/cppextensions/proxyviewer/proxyviewer.qrc b/examples/declarative/cppextensions/proxyviewer/proxyviewer.qrc deleted file mode 100644 index 17e9301..0000000 --- a/examples/declarative/cppextensions/proxyviewer/proxyviewer.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - view.qml - - diff --git a/examples/declarative/cppextensions/proxyviewer/view.qml b/examples/declarative/cppextensions/proxyviewer/view.qml deleted file mode 100644 index 7f1bdef..0000000 --- a/examples/declarative/cppextensions/proxyviewer/view.qml +++ /dev/null @@ -1,7 +0,0 @@ -import Qt 4.7 - -Image { - width: 100 - height: 100 - source: "http://qt.nokia.com/logo.png" -} diff --git a/examples/declarative/cppextensions/proxywidgets/ProxyWidgets/qmldir b/examples/declarative/cppextensions/proxywidgets/ProxyWidgets/qmldir deleted file mode 100644 index e55267c..0000000 --- a/examples/declarative/cppextensions/proxywidgets/ProxyWidgets/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin proxywidgetsplugin diff --git a/examples/declarative/cppextensions/proxywidgets/README b/examples/declarative/cppextensions/proxywidgets/README deleted file mode 100644 index f50fa22..0000000 --- a/examples/declarative/cppextensions/proxywidgets/README +++ /dev/null @@ -1,4 +0,0 @@ -To run: - - make install - qml proxywidgets.qml diff --git a/examples/declarative/cppextensions/proxywidgets/proxywidgets.cpp b/examples/declarative/cppextensions/proxywidgets/proxywidgets.cpp deleted file mode 100644 index 067eb2c..0000000 --- a/examples/declarative/cppextensions/proxywidgets/proxywidgets.cpp +++ /dev/null @@ -1,97 +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 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 - -class MyPushButton : public QGraphicsProxyWidget -{ - Q_OBJECT - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - -public: - MyPushButton(QGraphicsItem* parent = 0) - : QGraphicsProxyWidget(parent) - { - widget = new QPushButton("MyPushButton"); - widget->setAttribute(Qt::WA_NoSystemBackground); - setWidget(widget); - - QObject::connect(widget, SIGNAL(clicked(bool)), this, SIGNAL(clicked(bool))); - } - - QString text() const - { - return widget->text(); - } - - void setText(const QString& text) - { - if (text != widget->text()) { - widget->setText(text); - emit textChanged(); - } - } - -Q_SIGNALS: - void clicked(bool); - void textChanged(); - -private: - QPushButton *widget; -}; - -class ProxyWidgetsPlugin : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - void registerTypes(const char *uri) - { - qmlRegisterType(uri, 1, 0, "MyPushButton"); - } -}; - -#include "proxywidgets.moc" - -Q_EXPORT_PLUGIN2(proxywidgetsplugin, ProxyWidgetsPlugin); diff --git a/examples/declarative/cppextensions/proxywidgets/proxywidgets.pro b/examples/declarative/cppextensions/proxywidgets/proxywidgets.pro deleted file mode 100644 index cb07d80..0000000 --- a/examples/declarative/cppextensions/proxywidgets/proxywidgets.pro +++ /dev/null @@ -1,21 +0,0 @@ -TEMPLATE = lib -DESTDIR = ProxyWidgets -TARGET = proxywidgetsplugin -CONFIG += qt plugin -QT += declarative - -SOURCES += proxywidgets.cpp - -sources.files += proxywidgets.pro proxywidgets.cpp proxywidgets.qml - -sources.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins - -target.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins - -INSTALLS += sources target - -symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) - -symbian:{ - TARGET.EPOCALLOWDLLDATA = 1 -} \ No newline at end of file diff --git a/examples/declarative/cppextensions/proxywidgets/proxywidgets.qml b/examples/declarative/cppextensions/proxywidgets/proxywidgets.qml deleted file mode 100644 index 88de37f..0000000 --- a/examples/declarative/cppextensions/proxywidgets/proxywidgets.qml +++ /dev/null @@ -1,70 +0,0 @@ -import Qt 4.7 -import "ProxyWidgets" 1.0 - -Rectangle { - id: window - - property int margin: 30 - - width: 640; height: 480 - color: palette.window - - SystemPalette { id: palette } - - MyPushButton { - id: button1 - x: margin; y: margin - text: "Right" - transformOriginPoint: Qt.point(width / 2, height / 2) - - onClicked: window.state = "right" - } - - MyPushButton { - id: button2 - x: margin; y: margin + 30 - text: "Bottom" - transformOriginPoint: Qt.point(width / 2, height / 2) - - onClicked: window.state = "bottom" - } - - MyPushButton { - id: button3 - x: margin; y: margin + 60 - text: "Quit" - transformOriginPoint: Qt.point(width / 2, height / 2) - - onClicked: Qt.quit() - } - - states: [ - State { - name: "right" - PropertyChanges { target: button1; x: window.width - width - margin; text: "Left"; onClicked: window.state = "" } - PropertyChanges { target: button2; x: window.width - width - margin } - PropertyChanges { target: button3; x: window.width - width - margin } - PropertyChanges { target: window; color: Qt.darker(palette.window) } - }, - State { - name: "bottom" - PropertyChanges { target: button1; y: window.height - height - margin; rotation: 180 } - PropertyChanges { - target: button2 - x: button1.x + button1.width + 10; y: window.height - height - margin - rotation: 180 - text: "Top" - onClicked: window.state = "" - } - PropertyChanges { target: button3; x: button2.x + button2.width + 10; y: window.height - height - margin; rotation: 180 } - PropertyChanges { target: window; color: Qt.lighter(palette.window) } - } - ] - - transitions: Transition { - ParallelAnimation { - NumberAnimation { properties: "x,y,rotation"; duration: 600; easing.type: Easing.OutQuad } - ColorAnimation { target: window; duration: 600 } - } - } -} diff --git a/examples/declarative/cppextensions/proxywidgets/proxywidgets.qmlproject b/examples/declarative/cppextensions/proxywidgets/proxywidgets.qmlproject deleted file mode 100644 index d4909f8..0000000 --- a/examples/declarative/cppextensions/proxywidgets/proxywidgets.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/cppextensions/qwidgets/QWidgets/qmldir b/examples/declarative/cppextensions/qwidgets/QWidgets/qmldir new file mode 100644 index 0000000..e55267c --- /dev/null +++ b/examples/declarative/cppextensions/qwidgets/QWidgets/qmldir @@ -0,0 +1 @@ +plugin proxywidgetsplugin diff --git a/examples/declarative/cppextensions/qwidgets/README b/examples/declarative/cppextensions/qwidgets/README new file mode 100644 index 0000000..e2f1b2b --- /dev/null +++ b/examples/declarative/cppextensions/qwidgets/README @@ -0,0 +1,6 @@ +This example shows how to embed QWidget-based objects into QML. + +To run: + + make install + qml qwidgets.qml diff --git a/examples/declarative/cppextensions/qwidgets/qwidgets.cpp b/examples/declarative/cppextensions/qwidgets/qwidgets.cpp new file mode 100644 index 0000000..228f9f1 --- /dev/null +++ b/examples/declarative/cppextensions/qwidgets/qwidgets.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** 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 + +class MyPushButton : public QGraphicsProxyWidget +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + +public: + MyPushButton(QGraphicsItem* parent = 0) + : QGraphicsProxyWidget(parent) + { + widget = new QPushButton("MyPushButton"); + widget->setAttribute(Qt::WA_NoSystemBackground); + setWidget(widget); + + QObject::connect(widget, SIGNAL(clicked(bool)), this, SIGNAL(clicked(bool))); + } + + QString text() const + { + return widget->text(); + } + + void setText(const QString& text) + { + if (text != widget->text()) { + widget->setText(text); + emit textChanged(); + } + } + +Q_SIGNALS: + void clicked(bool); + void textChanged(); + +private: + QPushButton *widget; +}; + +class QWidgetsPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + void registerTypes(const char *uri) + { + qmlRegisterType(uri, 1, 0, "MyPushButton"); + } +}; + +#include "qwidgets.moc" + +Q_EXPORT_PLUGIN2(qwidgetsplugin, QWidgetsPlugin); diff --git a/examples/declarative/cppextensions/qwidgets/qwidgets.pro b/examples/declarative/cppextensions/qwidgets/qwidgets.pro new file mode 100644 index 0000000..37f313d --- /dev/null +++ b/examples/declarative/cppextensions/qwidgets/qwidgets.pro @@ -0,0 +1,21 @@ +TEMPLATE = lib +DESTDIR = QWidgets +TARGET = qwidgetsplugin +CONFIG += qt plugin +QT += declarative + +SOURCES += qwidgets.cpp + +sources.files += qwidgets.pro qwidgets.cpp qwidgets.qml + +sources.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins + +target.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins + +INSTALLS += sources target + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + +symbian:{ + TARGET.EPOCALLOWDLLDATA = 1 +} diff --git a/examples/declarative/cppextensions/qwidgets/qwidgets.qml b/examples/declarative/cppextensions/qwidgets/qwidgets.qml new file mode 100644 index 0000000..47f9573 --- /dev/null +++ b/examples/declarative/cppextensions/qwidgets/qwidgets.qml @@ -0,0 +1,70 @@ +import Qt 4.7 +import "QWidgets" 1.0 + +Rectangle { + id: window + + property int margin: 30 + + width: 640; height: 480 + color: palette.window + + SystemPalette { id: palette } + + MyPushButton { + id: button1 + x: margin; y: margin + text: "Right" + transformOriginPoint: Qt.point(width / 2, height / 2) + + onClicked: window.state = "right" + } + + MyPushButton { + id: button2 + x: margin; y: margin + 30 + text: "Bottom" + transformOriginPoint: Qt.point(width / 2, height / 2) + + onClicked: window.state = "bottom" + } + + MyPushButton { + id: button3 + x: margin; y: margin + 60 + text: "Quit" + transformOriginPoint: Qt.point(width / 2, height / 2) + + onClicked: Qt.quit() + } + + states: [ + State { + name: "right" + PropertyChanges { target: button1; x: window.width - width - margin; text: "Left"; onClicked: window.state = "" } + PropertyChanges { target: button2; x: window.width - width - margin } + PropertyChanges { target: button3; x: window.width - width - margin } + PropertyChanges { target: window; color: Qt.darker(palette.window) } + }, + State { + name: "bottom" + PropertyChanges { target: button1; y: window.height - height - margin; rotation: 180 } + PropertyChanges { + target: button2 + x: button1.x + button1.width + 10; y: window.height - height - margin + rotation: 180 + text: "Top" + onClicked: window.state = "" + } + PropertyChanges { target: button3; x: button2.x + button2.width + 10; y: window.height - height - margin; rotation: 180 } + PropertyChanges { target: window; color: Qt.lighter(palette.window) } + } + ] + + transitions: Transition { + ParallelAnimation { + NumberAnimation { properties: "x,y,rotation"; duration: 600; easing.type: Easing.OutQuad } + ColorAnimation { target: window; duration: 600 } + } + } +} diff --git a/examples/declarative/cppextensions/qwidgets/qwidgets.qmlproject b/examples/declarative/cppextensions/qwidgets/qwidgets.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/qwidgets/qwidgets.qmlproject @@ -0,0 +1,16 @@ +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/toys/corkboards/Day.qml b/examples/declarative/toys/corkboards/Day.qml new file mode 100644 index 0000000..350c1c4 --- /dev/null +++ b/examples/declarative/toys/corkboards/Day.qml @@ -0,0 +1,101 @@ +import Qt 4.7 + +Component { + Item { + property variant stickies + + id: page + width: 840; height: 480 + + Image { source: "cork.jpg" } + + Text { + text: name; x: 15; y: 8; height: 40; width: 370 + font.pixelSize: 18; font.bold: true; color: "white" + style: Text.Outline; styleColor: "black" + } + + Repeater { + model: notes + Item { + id: stickyPage + + property int randomX: Math.random() * 500 + 100 + property int randomY: Math.random() * 200 + 50 + + x: randomX; y: randomY + + SpringFollow on rotation { + to: -flickable.horizontalVelocity / 100 + spring: 2.0; damping: 0.15 + } + + Item { + id: sticky + scale: 0.7 + + Image { + id: stickyImage + x: 8 + -width * 0.6 / 2; y: -20 + source: "note-yellow.png" + scale: 0.6; transformOrigin: Item.TopLeft + smooth: true + } + + TextEdit { + id: myText + x: -104; y: 36; width: 215; height: 200 + smooth: true + font.pixelSize: 24 + readOnly: false + rotation: -8 + text: noteText + } + + Item { + x: stickyImage.x; y: -20 + width: stickyImage.width * stickyImage.scale + height: stickyImage.height * stickyImage.scale + + MouseArea { + id: mouse + anchors.fill: parent + drag.target: stickyPage + drag.axis: Drag.XandYAxis + drag.minimumY: 0 + drag.maximumY: page.height - 80 + drag.minimumX: 100 + drag.maximumX: page.width - 140 + onClicked: { myText.focus = true } + } + } + } + + Image { + x: -width / 2; y: -height * 0.5 / 2 + source: "tack.png" + scale: 0.7; transformOrigin: Item.TopLeft + } + + states: State { + name: "pressed" + when: mouse.pressed + PropertyChanges { target: sticky; rotation: 8; scale: 1 } + PropertyChanges { target: page; z: 8 } + } + + transitions: Transition { + NumberAnimation { properties: "rotation,scale"; duration: 200 } + } + } + } + } +} + + + + + + + + diff --git a/examples/declarative/toys/corkboards/cork.jpg b/examples/declarative/toys/corkboards/cork.jpg new file mode 100644 index 0000000..160bc00 Binary files /dev/null and b/examples/declarative/toys/corkboards/cork.jpg differ diff --git a/examples/declarative/toys/corkboards/corkboards.qml b/examples/declarative/toys/corkboards/corkboards.qml new file mode 100644 index 0000000..871bafc --- /dev/null +++ b/examples/declarative/toys/corkboards/corkboards.qml @@ -0,0 +1,75 @@ +import Qt 4.7 + +Rectangle { + width: 800; height: 480 + color: "#464646" + + ListModel { + id: list + + ListElement { + name: "Sunday" + notes: [ + ListElement { noteText: "Lunch" }, + ListElement { noteText: "Birthday Party" } + ] + } + + ListElement { + name: "Monday" + notes: [ + ListElement { noteText: "Pickup kids from\nschool\n4.30pm" }, + ListElement { noteText: "Checkout Qt" }, ListElement { noteText: "Read email" } + ] + } + + ListElement { + name: "Tuesday" + notes: [ + ListElement { noteText: "Walk dog" }, + ListElement { noteText: "Buy newspaper" } + ] + } + + ListElement { + name: "Wednesday" + notes: [ ListElement { noteText: "Cook dinner" } ] + } + + ListElement { + name: "Thursday" + notes: [ + ListElement { noteText: "Meeting\n5.30pm" }, + ListElement { noteText: "Weed garden" } + ] + } + + ListElement { + name: "Friday" + notes: [ + ListElement { noteText: "More work" }, + ListElement { noteText: "Grocery shopping" } + ] + } + + ListElement { + name: "Saturday" + notes: [ + ListElement { noteText: "Drink" }, + ListElement { noteText: "Download Qt\nPlay with QML" } + ] + } + } + + ListView { + id: flickable + + anchors.fill: parent + focus: true + highlightRangeMode: ListView.StrictlyEnforceRange + orientation: ListView.Horizontal + snapMode: ListView.SnapOneItem + model: list + delegate: Day { } + } +} diff --git a/examples/declarative/toys/corkboards/corkboards.qmlproject b/examples/declarative/toys/corkboards/corkboards.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/toys/corkboards/corkboards.qmlproject @@ -0,0 +1,16 @@ +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/toys/corkboards/note-yellow.png b/examples/declarative/toys/corkboards/note-yellow.png new file mode 100644 index 0000000..8ddecc8 Binary files /dev/null and b/examples/declarative/toys/corkboards/note-yellow.png differ diff --git a/examples/declarative/toys/corkboards/tack.png b/examples/declarative/toys/corkboards/tack.png new file mode 100644 index 0000000..cef2d1c Binary files /dev/null and b/examples/declarative/toys/corkboards/tack.png differ diff --git a/examples/declarative/toys/dynamic/dynamic.qml b/examples/declarative/toys/dynamic/dynamic.qml deleted file mode 100644 index 52c7c1e..0000000 --- a/examples/declarative/toys/dynamic/dynamic.qml +++ /dev/null @@ -1,176 +0,0 @@ -import Qt 4.7 -import Qt.labs.particles 1.0 -import "qml" - -Item { - id: window - - property int activeSuns: 0 - - //This is a desktop-sized example - width: 1024; height: 512 - - //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 - 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 { - id: dialogText - x: 3; y: 3 - font.pixelSize: 14 - } - - SequentialAnimation { - id: dialogAnim - 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 - anchors { left: parent.left; top: parent.top; right: toolbox.right; bottom: parent.verticalCenter } - gradient: Gradient { - GradientStop { id: gradientStopA; position: 0.0; color: "#0E1533" } - GradientStop { id: gradientStopB; position: 1.0; color: "#437284" } - } - } - - // stars (when there's no sun) - 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 - opacity: 1 - } - - // ground - Rectangle { - id: ground - 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" } - } - } - - SystemPalette { id: activePalette } - - // right-hand panel - Rectangle { - id: toolbox - - width: 480 - color: activePalette.window - anchors { right: parent.right; top: parent.top; bottom: parent.bottom } - - Column { - anchors.centerIn: parent - spacing: 8 - - Text { text: "Drag an item into the scene." } - - 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: 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" - onClicked: { - try { - Qt.createQmlObject(qmlText.text, window, 'CustomObject'); - } catch(err) { - dialog.show('Error on line ' + err.qmlErrors[0].lineNumber + '\n' + err.qmlErrors[0].message); - } - } - } - } - } - - //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/toys/dynamic/dynamic.qmlproject b/examples/declarative/toys/dynamic/dynamic.qmlproject deleted file mode 100644 index d4909f8..0000000 --- a/examples/declarative/toys/dynamic/dynamic.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/toys/dynamic/images/NOTE b/examples/declarative/toys/dynamic/images/NOTE deleted file mode 100644 index fcd87f9..0000000 --- a/examples/declarative/toys/dynamic/images/NOTE +++ /dev/null @@ -1 +0,0 @@ -Images (except star.png) are from the KDE project. diff --git a/examples/declarative/toys/dynamic/images/face-smile.png b/examples/declarative/toys/dynamic/images/face-smile.png deleted file mode 100644 index 3d66d72..0000000 Binary files a/examples/declarative/toys/dynamic/images/face-smile.png and /dev/null differ diff --git a/examples/declarative/toys/dynamic/images/moon.png b/examples/declarative/toys/dynamic/images/moon.png deleted file mode 100644 index 1c0d606..0000000 Binary files a/examples/declarative/toys/dynamic/images/moon.png and /dev/null differ diff --git a/examples/declarative/toys/dynamic/images/rabbit_brown.png b/examples/declarative/toys/dynamic/images/rabbit_brown.png deleted file mode 100644 index ebfdeed..0000000 Binary files a/examples/declarative/toys/dynamic/images/rabbit_brown.png and /dev/null differ diff --git a/examples/declarative/toys/dynamic/images/rabbit_bw.png b/examples/declarative/toys/dynamic/images/rabbit_bw.png deleted file mode 100644 index 7bff9b9..0000000 Binary files a/examples/declarative/toys/dynamic/images/rabbit_bw.png and /dev/null differ diff --git a/examples/declarative/toys/dynamic/images/star.png b/examples/declarative/toys/dynamic/images/star.png deleted file mode 100644 index 27ef924..0000000 Binary files a/examples/declarative/toys/dynamic/images/star.png and /dev/null differ diff --git a/examples/declarative/toys/dynamic/images/sun.png b/examples/declarative/toys/dynamic/images/sun.png deleted file mode 100644 index 7713ca5..0000000 Binary files a/examples/declarative/toys/dynamic/images/sun.png and /dev/null differ diff --git a/examples/declarative/toys/dynamic/images/tree_s.png b/examples/declarative/toys/dynamic/images/tree_s.png deleted file mode 100644 index 6eac35a..0000000 Binary files a/examples/declarative/toys/dynamic/images/tree_s.png and /dev/null differ diff --git a/examples/declarative/toys/dynamic/qml/Button.qml b/examples/declarative/toys/dynamic/qml/Button.qml deleted file mode 100644 index 963a850..0000000 --- a/examples/declarative/toys/dynamic/qml/Button.qml +++ /dev/null @@ -1,40 +0,0 @@ -import Qt 4.7 - -Rectangle { - id: container - - property variant text - signal clicked - - height: text.height + 10; width: text.width + 20 - border.width: 1 - radius: 4 - smooth: true - - gradient: Gradient { - GradientStop { - position: 0.0 - color: !mouseArea.pressed ? activePalette.light : activePalette.button - } - GradientStop { - position: 1.0 - color: !mouseArea.pressed ? activePalette.button : activePalette.dark - } - } - - 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/toys/dynamic/qml/PaletteItem.qml b/examples/declarative/toys/dynamic/qml/PaletteItem.qml deleted file mode 100644 index dcb5cc3..0000000 --- a/examples/declarative/toys/dynamic/qml/PaletteItem.qml +++ /dev/null @@ -1,19 +0,0 @@ -import Qt 4.7 -import "itemCreation.js" as Code - -Image { - id: paletteItem - - property string componentFile - property string image - - source: image - - MouseArea { - anchors.fill: parent - - onPressed: Code.startDrag(mouse); - onPositionChanged: Code.continueDrag(mouse); - onReleased: Code.endDrag(mouse); - } -} diff --git a/examples/declarative/toys/dynamic/qml/PerspectiveItem.qml b/examples/declarative/toys/dynamic/qml/PerspectiveItem.qml deleted file mode 100644 index c04d3dc..0000000 --- a/examples/declarative/toys/dynamic/qml/PerspectiveItem.qml +++ /dev/null @@ -1,25 +0,0 @@ -import Qt 4.7 - -Image { - id: rootItem - - property bool created: false - 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 - 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/toys/dynamic/qml/Sun.qml b/examples/declarative/toys/dynamic/qml/Sun.qml deleted file mode 100644 index 43dcb9a..0000000 --- a/examples/declarative/toys/dynamic/qml/Sun.qml +++ /dev/null @@ -1,38 +0,0 @@ -import Qt 4.7 - -Image { - id: sun - - property bool created: false - property string image: "../images/sun.png" - - source: image - - // once item is created, start moving offscreen - NumberAnimation on y { - to: window.height / 2 - running: created - onRunningChanged: { - if (running) - duration = (window.height - sun.y) * 10; - else - state = "OffScreen" - } - } - - states: State { - 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/toys/dynamic/qml/itemCreation.js b/examples/declarative/toys/dynamic/qml/itemCreation.js deleted file mode 100644 index 59750f3..0000000 --- a/examples/declarative/toys/dynamic/qml/itemCreation.js +++ /dev/null @@ -1,65 +0,0 @@ -var itemComponent = null; -var draggedItem = null; -var startingMouse; -var posnInWindow; - -function startDrag(mouse) -{ - posnInWindow = paletteItem.mapToItem(null, 0, 0); - startingMouse = { x: mouse.x, y: mouse.y } - loadComponent(); -} - -//Creation is split into two functions due to an asynchronous wait while -//possible external files are loaded. - -function loadComponent() { - if (itemComponent != null) { // component has been previously loaded - createItem(); - return; - } - - 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(window); - 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"); - console.log(component.errorsString()); - } -} - -function continueDrag(mouse) -{ - if (draggedItem == null) - return; - - draggedItem.x = mouse.x + posnInWindow.x - startingMouse.x; - draggedItem.y = mouse.y + posnInWindow.y - startingMouse.y; -} - -function endDrag(mouse) -{ - if (draggedItem == null) - return; - - if (draggedItem.x + draggedItem.width > toolbox.x) { //Don't drop it in the toolbox - draggedItem.destroy(); - draggedItem = null; - } else { - draggedItem.created = true; - draggedItem = null; - } -} - diff --git a/examples/declarative/toys/dynamicscene/dynamicscene.qml b/examples/declarative/toys/dynamicscene/dynamicscene.qml new file mode 100644 index 0000000..52c7c1e --- /dev/null +++ b/examples/declarative/toys/dynamicscene/dynamicscene.qml @@ -0,0 +1,176 @@ +import Qt 4.7 +import Qt.labs.particles 1.0 +import "qml" + +Item { + id: window + + property int activeSuns: 0 + + //This is a desktop-sized example + width: 1024; height: 512 + + //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 + 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 { + id: dialogText + x: 3; y: 3 + font.pixelSize: 14 + } + + SequentialAnimation { + id: dialogAnim + 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 + anchors { left: parent.left; top: parent.top; right: toolbox.right; bottom: parent.verticalCenter } + gradient: Gradient { + GradientStop { id: gradientStopA; position: 0.0; color: "#0E1533" } + GradientStop { id: gradientStopB; position: 1.0; color: "#437284" } + } + } + + // stars (when there's no sun) + 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 + opacity: 1 + } + + // ground + Rectangle { + id: ground + 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" } + } + } + + SystemPalette { id: activePalette } + + // right-hand panel + Rectangle { + id: toolbox + + width: 480 + color: activePalette.window + anchors { right: parent.right; top: parent.top; bottom: parent.bottom } + + Column { + anchors.centerIn: parent + spacing: 8 + + Text { text: "Drag an item into the scene." } + + 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: 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" + onClicked: { + try { + Qt.createQmlObject(qmlText.text, window, 'CustomObject'); + } catch(err) { + dialog.show('Error on line ' + err.qmlErrors[0].lineNumber + '\n' + err.qmlErrors[0].message); + } + } + } + } + } + + //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/toys/dynamicscene/dynamicscene.qmlproject b/examples/declarative/toys/dynamicscene/dynamicscene.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/toys/dynamicscene/dynamicscene.qmlproject @@ -0,0 +1,16 @@ +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/toys/dynamicscene/images/NOTE b/examples/declarative/toys/dynamicscene/images/NOTE new file mode 100644 index 0000000..fcd87f9 --- /dev/null +++ b/examples/declarative/toys/dynamicscene/images/NOTE @@ -0,0 +1 @@ +Images (except star.png) are from the KDE project. diff --git a/examples/declarative/toys/dynamicscene/images/face-smile.png b/examples/declarative/toys/dynamicscene/images/face-smile.png new file mode 100644 index 0000000..3d66d72 Binary files /dev/null and b/examples/declarative/toys/dynamicscene/images/face-smile.png differ diff --git a/examples/declarative/toys/dynamicscene/images/moon.png b/examples/declarative/toys/dynamicscene/images/moon.png new file mode 100644 index 0000000..1c0d606 Binary files /dev/null and b/examples/declarative/toys/dynamicscene/images/moon.png differ diff --git a/examples/declarative/toys/dynamicscene/images/rabbit_brown.png b/examples/declarative/toys/dynamicscene/images/rabbit_brown.png new file mode 100644 index 0000000..ebfdeed Binary files /dev/null and b/examples/declarative/toys/dynamicscene/images/rabbit_brown.png differ diff --git a/examples/declarative/toys/dynamicscene/images/rabbit_bw.png b/examples/declarative/toys/dynamicscene/images/rabbit_bw.png new file mode 100644 index 0000000..7bff9b9 Binary files /dev/null and b/examples/declarative/toys/dynamicscene/images/rabbit_bw.png differ diff --git a/examples/declarative/toys/dynamicscene/images/star.png b/examples/declarative/toys/dynamicscene/images/star.png new file mode 100644 index 0000000..27ef924 Binary files /dev/null and b/examples/declarative/toys/dynamicscene/images/star.png differ diff --git a/examples/declarative/toys/dynamicscene/images/sun.png b/examples/declarative/toys/dynamicscene/images/sun.png new file mode 100644 index 0000000..7713ca5 Binary files /dev/null and b/examples/declarative/toys/dynamicscene/images/sun.png differ diff --git a/examples/declarative/toys/dynamicscene/images/tree_s.png b/examples/declarative/toys/dynamicscene/images/tree_s.png new file mode 100644 index 0000000..6eac35a Binary files /dev/null and b/examples/declarative/toys/dynamicscene/images/tree_s.png differ diff --git a/examples/declarative/toys/dynamicscene/qml/Button.qml b/examples/declarative/toys/dynamicscene/qml/Button.qml new file mode 100644 index 0000000..963a850 --- /dev/null +++ b/examples/declarative/toys/dynamicscene/qml/Button.qml @@ -0,0 +1,40 @@ +import Qt 4.7 + +Rectangle { + id: container + + property variant text + signal clicked + + height: text.height + 10; width: text.width + 20 + border.width: 1 + radius: 4 + smooth: true + + gradient: Gradient { + GradientStop { + position: 0.0 + color: !mouseArea.pressed ? activePalette.light : activePalette.button + } + GradientStop { + position: 1.0 + color: !mouseArea.pressed ? activePalette.button : activePalette.dark + } + } + + 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/toys/dynamicscene/qml/PaletteItem.qml b/examples/declarative/toys/dynamicscene/qml/PaletteItem.qml new file mode 100644 index 0000000..dcb5cc3 --- /dev/null +++ b/examples/declarative/toys/dynamicscene/qml/PaletteItem.qml @@ -0,0 +1,19 @@ +import Qt 4.7 +import "itemCreation.js" as Code + +Image { + id: paletteItem + + property string componentFile + property string image + + source: image + + MouseArea { + anchors.fill: parent + + onPressed: Code.startDrag(mouse); + onPositionChanged: Code.continueDrag(mouse); + onReleased: Code.endDrag(mouse); + } +} diff --git a/examples/declarative/toys/dynamicscene/qml/PerspectiveItem.qml b/examples/declarative/toys/dynamicscene/qml/PerspectiveItem.qml new file mode 100644 index 0000000..c04d3dc --- /dev/null +++ b/examples/declarative/toys/dynamicscene/qml/PerspectiveItem.qml @@ -0,0 +1,25 @@ +import Qt 4.7 + +Image { + id: rootItem + + property bool created: false + 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 + 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/toys/dynamicscene/qml/Sun.qml b/examples/declarative/toys/dynamicscene/qml/Sun.qml new file mode 100644 index 0000000..43dcb9a --- /dev/null +++ b/examples/declarative/toys/dynamicscene/qml/Sun.qml @@ -0,0 +1,38 @@ +import Qt 4.7 + +Image { + id: sun + + property bool created: false + property string image: "../images/sun.png" + + source: image + + // once item is created, start moving offscreen + NumberAnimation on y { + to: window.height / 2 + running: created + onRunningChanged: { + if (running) + duration = (window.height - sun.y) * 10; + else + state = "OffScreen" + } + } + + states: State { + 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/toys/dynamicscene/qml/itemCreation.js b/examples/declarative/toys/dynamicscene/qml/itemCreation.js new file mode 100644 index 0000000..59750f3 --- /dev/null +++ b/examples/declarative/toys/dynamicscene/qml/itemCreation.js @@ -0,0 +1,65 @@ +var itemComponent = null; +var draggedItem = null; +var startingMouse; +var posnInWindow; + +function startDrag(mouse) +{ + posnInWindow = paletteItem.mapToItem(null, 0, 0); + startingMouse = { x: mouse.x, y: mouse.y } + loadComponent(); +} + +//Creation is split into two functions due to an asynchronous wait while +//possible external files are loaded. + +function loadComponent() { + if (itemComponent != null) { // component has been previously loaded + createItem(); + return; + } + + 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(window); + 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"); + console.log(component.errorsString()); + } +} + +function continueDrag(mouse) +{ + if (draggedItem == null) + return; + + draggedItem.x = mouse.x + posnInWindow.x - startingMouse.x; + draggedItem.y = mouse.y + posnInWindow.y - startingMouse.y; +} + +function endDrag(mouse) +{ + if (draggedItem == null) + return; + + if (draggedItem.x + draggedItem.width > toolbox.x) { //Don't drop it in the toolbox + draggedItem.destroy(); + draggedItem = null; + } else { + draggedItem.created = true; + draggedItem = null; + } +} + diff --git a/examples/declarative/toys/velocity/Day.qml b/examples/declarative/toys/velocity/Day.qml deleted file mode 100644 index 350c1c4..0000000 --- a/examples/declarative/toys/velocity/Day.qml +++ /dev/null @@ -1,101 +0,0 @@ -import Qt 4.7 - -Component { - Item { - property variant stickies - - id: page - width: 840; height: 480 - - Image { source: "cork.jpg" } - - Text { - text: name; x: 15; y: 8; height: 40; width: 370 - font.pixelSize: 18; font.bold: true; color: "white" - style: Text.Outline; styleColor: "black" - } - - Repeater { - model: notes - Item { - id: stickyPage - - property int randomX: Math.random() * 500 + 100 - property int randomY: Math.random() * 200 + 50 - - x: randomX; y: randomY - - SpringFollow on rotation { - to: -flickable.horizontalVelocity / 100 - spring: 2.0; damping: 0.15 - } - - Item { - id: sticky - scale: 0.7 - - Image { - id: stickyImage - x: 8 + -width * 0.6 / 2; y: -20 - source: "note-yellow.png" - scale: 0.6; transformOrigin: Item.TopLeft - smooth: true - } - - TextEdit { - id: myText - x: -104; y: 36; width: 215; height: 200 - smooth: true - font.pixelSize: 24 - readOnly: false - rotation: -8 - text: noteText - } - - Item { - x: stickyImage.x; y: -20 - width: stickyImage.width * stickyImage.scale - height: stickyImage.height * stickyImage.scale - - MouseArea { - id: mouse - anchors.fill: parent - drag.target: stickyPage - drag.axis: Drag.XandYAxis - drag.minimumY: 0 - drag.maximumY: page.height - 80 - drag.minimumX: 100 - drag.maximumX: page.width - 140 - onClicked: { myText.focus = true } - } - } - } - - Image { - x: -width / 2; y: -height * 0.5 / 2 - source: "tack.png" - scale: 0.7; transformOrigin: Item.TopLeft - } - - states: State { - name: "pressed" - when: mouse.pressed - PropertyChanges { target: sticky; rotation: 8; scale: 1 } - PropertyChanges { target: page; z: 8 } - } - - transitions: Transition { - NumberAnimation { properties: "rotation,scale"; duration: 200 } - } - } - } - } -} - - - - - - - - diff --git a/examples/declarative/toys/velocity/cork.jpg b/examples/declarative/toys/velocity/cork.jpg deleted file mode 100644 index 160bc00..0000000 Binary files a/examples/declarative/toys/velocity/cork.jpg and /dev/null differ diff --git a/examples/declarative/toys/velocity/note-yellow.png b/examples/declarative/toys/velocity/note-yellow.png deleted file mode 100644 index 8ddecc8..0000000 Binary files a/examples/declarative/toys/velocity/note-yellow.png and /dev/null differ diff --git a/examples/declarative/toys/velocity/tack.png b/examples/declarative/toys/velocity/tack.png deleted file mode 100644 index cef2d1c..0000000 Binary files a/examples/declarative/toys/velocity/tack.png and /dev/null differ diff --git a/examples/declarative/toys/velocity/velocity.qml b/examples/declarative/toys/velocity/velocity.qml deleted file mode 100644 index 871bafc..0000000 --- a/examples/declarative/toys/velocity/velocity.qml +++ /dev/null @@ -1,75 +0,0 @@ -import Qt 4.7 - -Rectangle { - width: 800; height: 480 - color: "#464646" - - ListModel { - id: list - - ListElement { - name: "Sunday" - notes: [ - ListElement { noteText: "Lunch" }, - ListElement { noteText: "Birthday Party" } - ] - } - - ListElement { - name: "Monday" - notes: [ - ListElement { noteText: "Pickup kids from\nschool\n4.30pm" }, - ListElement { noteText: "Checkout Qt" }, ListElement { noteText: "Read email" } - ] - } - - ListElement { - name: "Tuesday" - notes: [ - ListElement { noteText: "Walk dog" }, - ListElement { noteText: "Buy newspaper" } - ] - } - - ListElement { - name: "Wednesday" - notes: [ ListElement { noteText: "Cook dinner" } ] - } - - ListElement { - name: "Thursday" - notes: [ - ListElement { noteText: "Meeting\n5.30pm" }, - ListElement { noteText: "Weed garden" } - ] - } - - ListElement { - name: "Friday" - notes: [ - ListElement { noteText: "More work" }, - ListElement { noteText: "Grocery shopping" } - ] - } - - ListElement { - name: "Saturday" - notes: [ - ListElement { noteText: "Drink" }, - ListElement { noteText: "Download Qt\nPlay with QML" } - ] - } - } - - ListView { - id: flickable - - anchors.fill: parent - focus: true - highlightRangeMode: ListView.StrictlyEnforceRange - orientation: ListView.Horizontal - snapMode: ListView.SnapOneItem - model: list - delegate: Day { } - } -} diff --git a/examples/declarative/toys/velocity/velocity.qmlproject b/examples/declarative/toys/velocity/velocity.qmlproject deleted file mode 100644 index d4909f8..0000000 --- a/examples/declarative/toys/velocity/velocity.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 " ] -} -- cgit v0.12 From 69479992d8b4af73481df12e6f052269ae88ccc1 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 18 May 2010 12:24:20 +0200 Subject: Renaming "Qml Launcher" back to "QML Viewer" Change the official name of the qml executable back to "Qt QML Viewer" - the original name before it got renamed to "QML Runtime" and then "QML Launcher". Also, the new Mac OS X bundle name is "QMLViewer" (without a space to ease command line use). --- doc/src/declarative/qmlruntime.qdoc | 22 +++++++++++----------- doc/src/snippets/declarative/gridview/gridview.qml | 2 +- .../snippets/declarative/listview/highlight.qml | 2 +- doc/src/snippets/declarative/listview/listview.qml | 2 +- src/declarative/QmlChanges.txt | 4 ++-- tools/qdoc3/test/macros.qdocconf | 2 +- tools/qml/content/Browser.qml | 6 +++--- tools/qml/main.cpp | 14 +++++++------- tools/qml/qml.pro | 2 +- tools/qml/qmlruntime.cpp | 12 ++++++------ 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/doc/src/declarative/qmlruntime.qdoc b/doc/src/declarative/qmlruntime.qdoc index b105df4..a03b9c2 100644 --- a/doc/src/declarative/qmlruntime.qdoc +++ b/doc/src/declarative/qmlruntime.qdoc @@ -42,17 +42,17 @@ /*! \page qmlruntime.html \title Qt Declarative UI Runtime - \keyword qml runtime + \keyword QML Viewer (qml) \ingroup qttools This page documents the \e{Declarative UI Runtime} for the Qt GUI - toolkit, and the \QQL which can be used to run apps - written for the runtime. The \QQL reads a declarative + toolkit, and the \QQV which can be used to run apps + written for the runtime. The \QQV reads a declarative user interface definition (\c .qml) file and displays the user interface it describes. QML is a runtime, as you can run plain QML files which pull in their required modules. To run apps with the QML runtime, you can either start the runtime - from your own application (using a QDeclarativeView) or with the simple \QQL. + from your own application (using a QDeclarativeView) or with the simple \QQV. The launcher can be installed in a production environment, assuming that it is not already present in the system. It is generally packaged alongside Qt. @@ -61,16 +61,16 @@ \list \o Write your own Qt application including a QDeclarative view and deploy it the same as any other Qt application (not discussed further on this page), or - \o Write a main QML file for your application, and run your application using the included \QQL. + \o Write a main QML file for your application, and run your application using the included \QQV. \endlist - To run an application with the \QQL, pass the filename as an argument: + To run an application with the \QQV, pass the filename as an argument: \code qml myQmlFile.qml \endcode - Deploying a QML application via the \QQL allows for QML only deployments, but can also + Deploying a QML application via the \QQV allows for QML only deployments, but can also include custom C++ modules just as easily. Below is an example of how you might structure a complex application deployed via the QML runtime, it is a listing of the files that would be included in the deployment package. @@ -92,8 +92,8 @@ as the appropriate module file is chosen based on platform naming conventions. The C++ modules must contain a QDeclarativeExtentionPlugin subclass. - The application would be executed either with your own application, the command 'qml MyApp.qml' or by - opening the file if your system has the \QQL registered as the handler for QML files. The MyApp.qml file would have access + The application would be executed either with your own application, the command 'qml MyApp.qml' or by + opening the file if your system has the \QQV registered as the handler for QML files. The MyApp.qml file would have access to all of the deployed types using the import statements such as the following: \code @@ -101,8 +101,8 @@ import "OtherModule" 1.0 as Other \endcode - \section1 Qt QML Launcher functionality - The \QQL implements some additional functionality to help it supporting + \section1 Qt QML Viewer functionality + The \QQV implements some additional functionality to help it supporting myriad applications. If you implement your own application, you may also wish to reimplement some or all of this functionality. However, much of this functionality is intended to aid the prototyping of QML applications and may not be necessary for a deployed application. diff --git a/doc/src/snippets/declarative/gridview/gridview.qml b/doc/src/snippets/declarative/gridview/gridview.qml index cf345aa..1d3df97 100644 --- a/doc/src/snippets/declarative/gridview/gridview.qml +++ b/doc/src/snippets/declarative/gridview/gridview.qml @@ -4,7 +4,7 @@ import Qt 4.7 Rectangle { width: 240; height: 180; color: "white" // ContactModel model is defined in dummydata/ContactModel.qml - // The launcher automatically loads files in dummydata/* to assist + // The viewer automatically loads files in dummydata/* to assist // development without a real data source. // Define a delegate component. A component will be diff --git a/doc/src/snippets/declarative/listview/highlight.qml b/doc/src/snippets/declarative/listview/highlight.qml index 1282f8d..794b3f2 100644 --- a/doc/src/snippets/declarative/listview/highlight.qml +++ b/doc/src/snippets/declarative/listview/highlight.qml @@ -4,7 +4,7 @@ Rectangle { width: 180; height: 200; color: "white" // ContactModel model is defined in dummydata/ContactModel.qml - // The launcher automatically loads files in dummydata/* to assist + // The viewer automatically loads files in dummydata/* to assist // development without a real data source. // Define a delegate component. A component will be diff --git a/doc/src/snippets/declarative/listview/listview.qml b/doc/src/snippets/declarative/listview/listview.qml index 44f0540..61bf126 100644 --- a/doc/src/snippets/declarative/listview/listview.qml +++ b/doc/src/snippets/declarative/listview/listview.qml @@ -5,7 +5,7 @@ Rectangle { width: 180; height: 200; color: "white" // ContactModel model is defined in dummydata/ContactModel.qml - // The launcher automatically loads files in dummydata/* to assist + // The viewer automatically loads files in dummydata/* to assist // development without a real data source. // Define a delegate component. A component will be diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index b1f4f1b..c121a2d 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -23,9 +23,9 @@ The QDeclarativeExpression constructor has changed from to QDeclarativeExpression(context, scope, expression, parent = 0) -QML Launcher +QML Viewer ------------ -The standalone executable has been renamed to qml launcher. Runtime warnings +The standalone qml executable has been renamed back to Qml Viewer. Runtime warnings can be now accessed via the menu (Debugging->Show Warnings). ============================================================================= diff --git a/tools/qdoc3/test/macros.qdocconf b/tools/qdoc3/test/macros.qdocconf index e7a1dbc..510a8b3 100644 --- a/tools/qdoc3/test/macros.qdocconf +++ b/tools/qdoc3/test/macros.qdocconf @@ -18,7 +18,7 @@ macro.ouml.HTML = "ö" macro.QA = "\\e{Qt Assistant}" macro.QD = "\\e{Qt Designer}" macro.QL = "\\e{Qt Linguist}" -macro.QQL = "\\e{Qt QML Launcher}" +macro.QQV = "\\e{Qt QML Viewer}" macro.param = "\\e" macro.raisedaster.HTML = "*" macro.rarrow.HTML = "→" diff --git a/tools/qml/content/Browser.qml b/tools/qml/content/Browser.qml index fe7ad9c..7238203 100644 --- a/tools/qml/content/Browser.qml +++ b/tools/qml/content/Browser.qml @@ -13,12 +13,12 @@ Rectangle { FolderListModel { id: folders1 nameFilters: [ "*.qml" ] - folder: qmlLauncherFolder + folder: qmlViewerFolder } FolderListModel { id: folders2 nameFilters: [ "*.qml" ] - folder: qmlLauncherFolder + folder: qmlViewerFolder } SystemPalette { id: palette } @@ -63,7 +63,7 @@ Rectangle { if (folders.isFolder(index)) { down(filePath); } else { - qmlLauncher.launch(filePath); + qmlViewer.launch(filePath); } } width: root.width diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 18e2531..22fc5ca 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -85,7 +85,7 @@ QString warnings; void showWarnings() { if (!warnings.isEmpty()) { - QMessageBox::warning(0, QApplication::tr("Qt QML Launcher"), warnings); + QMessageBox::warning(0, QApplication::tr("Qt QML Viewer"), warnings); } } @@ -117,7 +117,7 @@ void usage() qWarning(" -frameless ............................... run with no window frame"); qWarning(" -maximized................................ run maximized"); qWarning(" -fullscreen............................... run fullscreen"); - qWarning(" -stayontop................................ keep launcher window on top"); + qWarning(" -stayontop................................ keep viewer window on top"); 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"); @@ -156,9 +156,9 @@ void scriptOptsUsage() qWarning(" testerror ................................ test 'error' property of root item on playback"); qWarning(" snapshot ................................. file being recorded is static,"); qWarning(" only one frame will be recorded or tested"); - qWarning(" exitoncomplete ........................... cleanly exit the launcher on script completion"); - qWarning(" exitonfailure ............................ immediately exit the launcher on script failure"); - qWarning(" saveonexit ............................... save recording on launcher exit"); + qWarning(" exitoncomplete ........................... cleanly exit the viewer on script completion"); + qWarning(" exitonfailure ............................ immediately exit the viewer on script failure"); + qWarning(" saveonexit ............................... save recording on viewer exit"); qWarning(" "); qWarning(" One of record, play or both must be specified."); exit(1); @@ -196,7 +196,7 @@ int main(int argc, char ** argv) #endif QApplication app(argc, argv); - app.setApplicationName("QtQmlLauncher"); + app.setApplicationName("QtQmlViewer"); app.setOrganizationName("Nokia"); app.setOrganizationDomain("nokia.com"); @@ -277,7 +277,7 @@ int main(int argc, char ** argv) if (lastArg) usage(); app.setStartDragDistance(QString(argv[++i]).toInt()); } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) { - qWarning("Qt QML Launcher version %s", QT_VERSION_STR); + qWarning("Qt QML Viewer version %s", QT_VERSION_STR); exit(0); } else if (arg == "-translation") { if (lastArg) usage(); diff --git a/tools/qml/qml.pro b/tools/qml/qml.pro index 6129639..886f0d9 100644 --- a/tools/qml/qml.pro +++ b/tools/qml/qml.pro @@ -37,6 +37,6 @@ symbian { } mac { QMAKE_INFO_PLIST=Info_mac.plist - TARGET="QML Launcher" + TARGET=QMLViewer ICON=qml.icns } diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 490fa34..8df250f 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -350,7 +350,7 @@ QNetworkAccessManager *NetworkAccessManagerFactory::create(QObject *parent) setupProxy(manager); if (cacheSize > 0) { QNetworkDiskCache *cache = new QNetworkDiskCache; - cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-launcher-network-cache")); + cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-viewer-network-cache")); cache->setMaximumCacheSize(cacheSize); manager->setCache(cache); } else { @@ -388,7 +388,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) , translator(0) { QDeclarativeViewer::registerTypes(); - setWindowTitle(tr("Qt QML Launcher")); + setWindowTitle(tr("Qt QML Viewer")); devicemode = false; canvas = 0; @@ -887,7 +887,7 @@ bool QDeclarativeViewer::open(const QString& file_or_url) url = QUrl::fromLocalFile(fi.absoluteFilePath()); else url = QUrl(file_or_url); - setWindowTitle(tr("%1 - Qt QML Launcher").arg(file_or_url)); + setWindowTitle(tr("%1 - Qt QML Viewer").arg(file_or_url)); if (!m_script.isEmpty()) tester = new QDeclarativeTester(m_script, m_scriptOptions, canvas); @@ -895,11 +895,11 @@ bool QDeclarativeViewer::open(const QString& file_or_url) delete canvas->rootObject(); canvas->engine()->clearComponentCache(); QDeclarativeContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("qmlLauncher", this); + ctxt->setContextProperty("qmlViewer", this); #ifdef Q_OS_SYMBIAN - ctxt->setContextProperty("qmlLauncherFolder", "E:\\"); // Documents on your S60 phone + ctxt->setContextProperty("qmlViewerFolder", "E:\\"); // Documents on your S60 phone #else - ctxt->setContextProperty("qmlLauncherFolder", QDir::currentPath()); + ctxt->setContextProperty("qmlViewerFolder", QDir::currentPath()); #endif ctxt->setContextProperty("runtime", Runtime::instance()); -- cgit v0.12 From 2108142dcd0a2dbb639443b594eb2c1c24e480cc Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 19 May 2010 10:16:36 +1000 Subject: Fix folderlistmodel with qt namespace --- src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp | 4 ++++ src/imports/folderlistmodel/qdeclarativefolderlistmodel.h | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp index a16f0c6..2ff7412 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp @@ -44,6 +44,8 @@ #include #include +QT_BEGIN_NAMESPACE + class QDeclarativeFolderListModelPrivate { public: @@ -387,3 +389,5 @@ void QDeclarativeFolderListModel::setShowOnlyReadable(bool on) else d->model.setFilter(d->model.filter() & ~QDir::Readable); } + +QT_END_NAMESPACE diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h index e610a14..dbde4c0 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h @@ -47,6 +47,12 @@ #include #include +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + class QDeclarativeContext; class QModelIndex; @@ -119,6 +125,10 @@ private: QDeclarativeFolderListModelPrivate *d; }; +QT_END_NAMESPACE + QML_DECLARE_TYPE(QDeclarativeFolderListModel) +QT_END_HEADER + #endif // QDECLARATIVEFOLDERLISTMODEL_H -- cgit v0.12 From 4ff78b296644d0b05c95497b8cca4eee6c04e7ae Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 19 May 2010 11:06:25 +1000 Subject: Add missing .qmlproject files --- .../networkaccessmanagerfactory.qmlproject | 16 ++++++++++++++++ .../graphicsLayouts/graphicsLayouts.qmlproject | 16 ++++++++++++++++ .../qgraphicslayouts/layoutItem/layoutItem.qmlproject | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.qmlproject create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject create mode 100644 examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qmlproject diff --git a/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.qmlproject b/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.qmlproject @@ -0,0 +1,16 @@ +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/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject @@ -0,0 +1,16 @@ +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/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qmlproject b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qmlproject @@ -0,0 +1,16 @@ +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 " ] +} -- cgit v0.12 From e007505d8f35c1194caf80ffc4f1e46561ff7be3 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 19 May 2010 11:10:11 +1000 Subject: When changing Loader source, remove old item from scene immediately. This ensures focus is restored to the correct item. Task-number: QTBUG-10787 --- src/declarative/graphicsitems/qdeclarativeloader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index 94983c4..4995baf 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -81,8 +81,12 @@ void QDeclarativeLoaderPrivate::clear() // We can't delete immediately because our item may have triggered // the Loader to load a different item. - item->setVisible(false); - item->setParentItem(0); + if (item->scene()) { + item->scene()->removeItem(item); + } else { + item->setParentItem(0); + item->setVisible(false); + } item->deleteLater(); item = 0; } -- cgit v0.12 From 71114e0c0af7418f61c0bf5d9ec881619946e128 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 19 May 2010 11:15:30 +1000 Subject: Remove image example (covered in class docs) --- doc/src/declarative/examples.qdoc | 1 - doc/src/examples/qml-examples.qdoc | 7 ------ .../declarative/imageelements/image/face_fit.qml | 26 ------------------- .../imageelements/image/face_fit_animated.qml | 28 --------------------- .../imageelements/image/image.qmlproject | 16 ------------ .../declarative/imageelements/image/pics/face.png | Bin 15408 -> 0 bytes .../imageelements/image/scale_and_crop.qml | 21 ---------------- .../imageelements/image/scale_and_crop_simple.qml | 20 --------------- .../imageelements/image/scale_and_sidecrop.qml | 22 ---------------- .../imageelements/image/scale_to_fit.qml | 22 ---------------- .../imageelements/image/scale_to_fit_simple.qml | 20 --------------- 11 files changed, 183 deletions(-) delete mode 100644 examples/declarative/imageelements/image/face_fit.qml delete mode 100644 examples/declarative/imageelements/image/face_fit_animated.qml delete mode 100644 examples/declarative/imageelements/image/image.qmlproject delete mode 100644 examples/declarative/imageelements/image/pics/face.png delete mode 100644 examples/declarative/imageelements/image/scale_and_crop.qml delete mode 100644 examples/declarative/imageelements/image/scale_and_crop_simple.qml delete mode 100644 examples/declarative/imageelements/image/scale_and_sidecrop.qml delete mode 100644 examples/declarative/imageelements/image/scale_to_fit.qml delete mode 100644 examples/declarative/imageelements/image/scale_to_fit_simple.qml diff --git a/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc index 4ad57f2..bc02646 100644 --- a/doc/src/declarative/examples.qdoc +++ b/doc/src/declarative/examples.qdoc @@ -82,7 +82,6 @@ For example, from your build directory, run: \section2 Image Elements \list \o \l{declarative/imageelements/borderimage}{BorderImage} -\o \l{declarative/imageelements/image}{Image} \endlist \section2 \l{declarative/positioners}{Positioners} diff --git a/doc/src/examples/qml-examples.qdoc b/doc/src/examples/qml-examples.qdoc index 2973d8c..7a0fcca 100644 --- a/doc/src/examples/qml-examples.qdoc +++ b/doc/src/examples/qml-examples.qdoc @@ -71,13 +71,6 @@ */ /*! - \title Image - \example declarative/imageelements/image - - This example shows uses of the \l Image element in QML. -*/ - -/*! \title Reference examples \example declarative/cppextensions/referenceexamples */ diff --git a/examples/declarative/imageelements/image/face_fit.qml b/examples/declarative/imageelements/image/face_fit.qml deleted file mode 100644 index 52cd4c2..0000000 --- a/examples/declarative/imageelements/image/face_fit.qml +++ /dev/null @@ -1,26 +0,0 @@ -import Qt 4.7 - -// Here, we implement a hybrid of the "scale to fit" and "scale and crop" -// behaviours which will crop up to 25% from *one* dimension if necessary -// to fully scale the other. This is a realistic algorithm, for example -// when the edges of the image contain less vital information than the -// center - such as a face. -// -Rectangle { - // default size: whole image, unscaled - width: face.width - height: face.height - color: "gray" - clip: true - - Image { - id: face - smooth: true - anchors.centerIn: parent - source: "pics/face.png" - x: (parent.width-width*scale)/2 - y: (parent.height-height*scale)/2 - scale: Math.max(Math.min(parent.width/width*1.333,parent.height/height), - Math.min(parent.width/width,parent.height/height*1.333)) - } -} diff --git a/examples/declarative/imageelements/image/face_fit_animated.qml b/examples/declarative/imageelements/image/face_fit_animated.qml deleted file mode 100644 index 63fc9c6..0000000 --- a/examples/declarative/imageelements/image/face_fit_animated.qml +++ /dev/null @@ -1,28 +0,0 @@ -import Qt 4.7 - -// Here, we extend the "face_fit" example with animation to show how truly -// diverse and usage-specific behaviours are made possible by NOT putting a -// hard-coded aspect ratio feature into the Image primitive. -// -Rectangle { - // default size: whole image, unscaled - width: face.width - height: face.height - color: "gray" - clip: true - - Image { - id: face - smooth: true - anchors.centerIn: parent - source: "pics/face.png" - x: (parent.width-width*scale)/2 - y: (parent.height-height*scale)/2 - SpringFollow on scale { - to: Math.max(Math.min(face.parent.width/face.width*1.333,face.parent.height/face.height), - Math.min(face.parent.width/face.width,face.parent.height/face.height*1.333)) - spring: 1 - damping: 0.05 - } - } -} diff --git a/examples/declarative/imageelements/image/image.qmlproject b/examples/declarative/imageelements/image/image.qmlproject deleted file mode 100644 index d4909f8..0000000 --- a/examples/declarative/imageelements/image/image.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/imageelements/image/pics/face.png b/examples/declarative/imageelements/image/pics/face.png deleted file mode 100644 index 3d66d72..0000000 Binary files a/examples/declarative/imageelements/image/pics/face.png and /dev/null differ diff --git a/examples/declarative/imageelements/image/scale_and_crop.qml b/examples/declarative/imageelements/image/scale_and_crop.qml deleted file mode 100644 index a438104..0000000 --- a/examples/declarative/imageelements/image/scale_and_crop.qml +++ /dev/null @@ -1,21 +0,0 @@ -import Qt 4.7 - -// Here, we implement "Scale and Crop" behaviour. -// -Rectangle { - // default size: whole image, unscaled - width: face.width - height: face.height - color: "gray" - clip: true - - Image { - id: face - smooth: true - anchors.centerIn: parent - source: "pics/face.png" - x: (parent.width-width*scale)/2 - y: (parent.height-height*scale)/2 - scale: Math.max(parent.width/width,parent.height/height) - } -} diff --git a/examples/declarative/imageelements/image/scale_and_crop_simple.qml b/examples/declarative/imageelements/image/scale_and_crop_simple.qml deleted file mode 100644 index 1160ec5..0000000 --- a/examples/declarative/imageelements/image/scale_and_crop_simple.qml +++ /dev/null @@ -1,20 +0,0 @@ -import Qt 4.7 - -// Here, we implement "Scale to Fit" behaviour, using the -// fillMode property. -// -Rectangle { - // default size: whole image, unscaled - width: face.width - height: face.height - color: "gray" - clip: true - - Image { - id: face - smooth: true - source: "pics/face.png" - fillMode: Image.PreserveAspectCrop - anchors.fill: parent - } -} diff --git a/examples/declarative/imageelements/image/scale_and_sidecrop.qml b/examples/declarative/imageelements/image/scale_and_sidecrop.qml deleted file mode 100644 index 5593ab8..0000000 --- a/examples/declarative/imageelements/image/scale_and_sidecrop.qml +++ /dev/null @@ -1,22 +0,0 @@ -import Qt 4.7 - -// Here, we implement a variant of "Scale and Crop" behaviour, where we -// crop the sides if necessary to fully fit vertically, but not the reverse. -// -Rectangle { - // default size: whole image, unscaled - width: face.width - height: face.height - color: "gray" - clip: true - - Image { - id: face - smooth: true - anchors.centerIn: parent - source: "pics/face.png" - x: (parent.width-width*scale)/2 - y: (parent.height-height*scale)/2 - scale: parent.height/height - } -} diff --git a/examples/declarative/imageelements/image/scale_to_fit.qml b/examples/declarative/imageelements/image/scale_to_fit.qml deleted file mode 100644 index 724a36e..0000000 --- a/examples/declarative/imageelements/image/scale_to_fit.qml +++ /dev/null @@ -1,22 +0,0 @@ -import Qt 4.7 - -// Here, we implement "Scale to Fit" behaviour "manually", rather -// than using the preserveAspect property. -// -Rectangle { - // default size: whole image, unscaled - width: face.width - height: face.height - color: "gray" - clip: true - - Image { - id: face - smooth: true - anchors.centerIn: parent - source: "pics/face.png" - x: (parent.width-width*scale)/2 - y: (parent.height-height*scale)/2 - scale: Math.min(parent.width/width,parent.height/height) - } -} diff --git a/examples/declarative/imageelements/image/scale_to_fit_simple.qml b/examples/declarative/imageelements/image/scale_to_fit_simple.qml deleted file mode 100644 index 0e960b4..0000000 --- a/examples/declarative/imageelements/image/scale_to_fit_simple.qml +++ /dev/null @@ -1,20 +0,0 @@ -import Qt 4.7 - -// Here, we implement "Scale to Fit" behaviour, using the -// fillMode property. -// -Rectangle { - // default size: whole image, unscaled - width: face.width - height: face.height - color: "gray" - clip: true - - Image { - id: face - smooth: true - source: "pics/face.png" - fillMode: Image.PreserveAspectFit - anchors.fill: parent - } -} -- cgit v0.12 From 5f3e8f33083be7bd7b858c8880f52a99952e0b75 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 19 May 2010 12:36:06 +1000 Subject: doc --- doc/src/declarative/examples.qdoc | 6 + doc/src/examples/qml-folderlistmodel.qdoc | 142 +++++++++++++++++++++ doc/src/images/declarative-folderlistmodel.png | Bin 0 -> 17764 bytes doc/src/snippets/declarative/folderlistmodel.qml | 17 +++ src/imports/folderlistmodel/plugin.cpp | 4 + .../qdeclarativefolderlistmodel.cpp | 9 ++ .../folderlistmodel/qdeclarativefolderlistmodel.h | 31 ++++- 7 files changed, 204 insertions(+), 5 deletions(-) create mode 100644 doc/src/examples/qml-folderlistmodel.qdoc create mode 100644 doc/src/images/declarative-folderlistmodel.png create mode 100644 doc/src/snippets/declarative/folderlistmodel.qml diff --git a/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc index cdc308a..94f27e9 100644 --- a/doc/src/declarative/examples.qdoc +++ b/doc/src/declarative/examples.qdoc @@ -168,5 +168,11 @@ For example, from your build directory, run: \o \l{demos/declarative/snake}{Snake} \endlist +\section1 Labs + +\list +\o \l{src/imports/folderlistmodel}{Folder List Model} - a C++ model plugin +\endlist + */ diff --git a/doc/src/examples/qml-folderlistmodel.qdoc b/doc/src/examples/qml-folderlistmodel.qdoc new file mode 100644 index 0000000..6e5f493 --- /dev/null +++ b/doc/src/examples/qml-folderlistmodel.qdoc @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +/*! + +\title FolderListModel - a C++ model plugin +\example src/imports/folderlistmodel + +This plugin shows how to make a C++ model available to QML. It presents +a simple file list for a single folder (directory) and allows the presented +folder to be changed. + +\image declarative-folderlistmodel.png The FolderListModel used to choose a QML file + +We do not explain the model implementation in detail, but rather focus on the mechanics of +making the model available to QML. + +\section1 Usage from QML + +The type we are creating can be used from QML like this: + +\snippet doc/src/snippets/declarative/folderlistmodel.qml 0 + +\section1 Defining the Model + +We are subclassing QAbstractListModel which will allow us to give data to QML and +send notifications when the data changes: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h class begin + +As you see, we also inherit the QDeclarativeParserStatus interface, so that we +can delay initial processing until we have all properties set (via componentComplete() below). + +The first thing to do when devising a new type for QML is to define the properties +you want the type to have: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h class props + +The purposes of each of these should be pretty obvious - in QML we will set the folder +to display (a file: URL), and the kinds of files we want to show in the view of the model. + +Next are the constructor, destructor, and standard QAbstractListModel subclassing requirements: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h abslistmodel + +The data() function is where we provide model values. The rowCount() function +is also a standard part of the QAbstractListModel interface, but we also want to provide +a simpler count property: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h count + +Then we have the functions for the remaining properties which we defined above: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h prop funcs + +Imperative actions upon the model are made available to QML via a Q_INVOKABLE tag on +a normal member function. The isFolder(index) function says whether the value at \e index +is a folder: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h isfolder + +Then we have the QDeclarativeParserStatus interface: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h parserstatus + +Then the NOTIFY function for the folders property. The implementation will emit this +when the folder property is changed. + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h notifier + +The class ends with some implementation details: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h class end + +Lastly, the boilerplare to declare the type for QML use: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h qml decl + +To make this class available to QML, we only need to make a simple subclass of QDeclarativeExtensionPlugin: + +\snippet src/imports/folderlistmodel/plugin.cpp class decl + +and then use the standard Qt plugin export macro: + +\snippet src/imports/folderlistmodel/plugin.cpp plugin export decl + +Finally, in order for QML to connect the "import" statement to our plugin, we list it in the qmldir file: + +\l{src/imports/folderlistmodel/qmldir} + +This qmldir file and the compiled plugin will be installed in \c $QTDIR/imports/Qt/labs/folderlistmodel/ where +the QML engine will find it (since \c $QTDIR/imports is the value of QLibraryInf::libraryPath()). + +\section1 Implementing the Model + +We'll not discuss the model implementation in detail, as it is not specific to QML - any Qt C++ model +can be interfaced to QML. +This implementation is basically just takes the krufty old QDirModel, +which is a tree with lots of detailed roles and re-presents it as a simpler list model where +each item is just a fileName and a filePath (as a file: URL rather than a plain file, since QML +works with URLs for all content). + +\l{src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp} +*/ diff --git a/doc/src/images/declarative-folderlistmodel.png b/doc/src/images/declarative-folderlistmodel.png new file mode 100644 index 0000000..a469f96 Binary files /dev/null and b/doc/src/images/declarative-folderlistmodel.png differ diff --git a/doc/src/snippets/declarative/folderlistmodel.qml b/doc/src/snippets/declarative/folderlistmodel.qml new file mode 100644 index 0000000..e90f9fd --- /dev/null +++ b/doc/src/snippets/declarative/folderlistmodel.qml @@ -0,0 +1,17 @@ +//![0] +import Qt 4.7 +import Qt.labs.folderlistmodel 1.0 + +ListView { + FolderListModel { + id: foldermodel + nameFilters: ["*.qml"] + } + Component { + id: filedelegate + Text { text: fileName } + } + model: foldermodel + delegate: filedelegate +} +//![0] diff --git a/src/imports/folderlistmodel/plugin.cpp b/src/imports/folderlistmodel/plugin.cpp index b94efb0..d4569f7 100644 --- a/src/imports/folderlistmodel/plugin.cpp +++ b/src/imports/folderlistmodel/plugin.cpp @@ -46,6 +46,7 @@ QT_BEGIN_NAMESPACE +//![class decl] class QmlFolderListModelPlugin : public QDeclarativeExtensionPlugin { Q_OBJECT @@ -56,10 +57,13 @@ public: qmlRegisterType(uri,1,0,"FolderListModel"); } }; +//![class decl] QT_END_NAMESPACE #include "plugin.moc" +//![plugin export decl] Q_EXPORT_PLUGIN2(qmlfolderlistmodelplugin, QT_PREPEND_NAMESPACE(QmlFolderListModelPlugin)); +//![plugin export decl] diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp index a16f0c6..0a75edf 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +//![code] #include "qdeclarativefolderlistmodel.h" #include #include @@ -99,6 +100,12 @@ public: separator, Qt will translate your paths to conform to the underlying operating system. + This type is made available by importing the \c Qt.labs.folderlistmodel module. + \e {Elements in the Qt.labs module are not guaranteed to remain compatible + in future versions.} + + \bold{import Qt.labs.folderlistmodel 1.0} + The roles available are: \list \o fileName @@ -387,3 +394,5 @@ void QDeclarativeFolderListModel::setShowOnlyReadable(bool on) else d->model.setFilter(d->model.filter() & ~QDir::Readable); } + +//![code] diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h index e610a14..87141c5 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h @@ -51,11 +51,15 @@ class QDeclarativeContext; class QModelIndex; class QDeclarativeFolderListModelPrivate; + +//![class begin] class QDeclarativeFolderListModel : public QAbstractListModel, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) +//![class begin] +//![class props] Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged) Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged) Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) @@ -65,7 +69,9 @@ class QDeclarativeFolderListModel : public QAbstractListModel, public QDeclarati Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) Q_PROPERTY(int count READ count) +//![class props] +//![abslistmodel] public: QDeclarativeFolderListModel(QObject *parent = 0); ~QDeclarativeFolderListModel(); @@ -74,9 +80,13 @@ public: int rowCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; +//![abslistmodel] +//![count] int count() const { return rowCount(QModelIndex()); } +//![count] +//![prop funcs] QUrl folder() const; void setFolder(const QUrl &folder); @@ -85,11 +95,6 @@ public: QStringList nameFilters() const; void setNameFilters(const QStringList &filters); - virtual void classBegin(); - virtual void componentComplete(); - - Q_INVOKABLE bool isFolder(int index) const; - enum SortField { Unsorted, Name, Time, Size, Type }; SortField sortField() const; void setSortField(SortField field); @@ -104,10 +109,23 @@ public: void setShowDotAndDotDot(bool); bool showOnlyReadable() const; void setShowOnlyReadable(bool); +//![prop funcs] + +//![isfolder] + Q_INVOKABLE bool isFolder(int index) const; +//![isfolder] + +//![parserstatus] + virtual void classBegin(); + virtual void componentComplete(); +//![parserstatus] +//![notifier] Q_SIGNALS: void folderChanged(); +//![notifier] +//![class end] private Q_SLOTS: void refresh(); void inserted(const QModelIndex &index, int start, int end); @@ -118,7 +136,10 @@ private: Q_DISABLE_COPY(QDeclarativeFolderListModel) QDeclarativeFolderListModelPrivate *d; }; +//![class end] +//![qml decl] QML_DECLARE_TYPE(QDeclarativeFolderListModel) +//![qml decl] #endif // QDECLARATIVEFOLDERLISTMODEL_H -- cgit v0.12 From cd707a865625c7ee0ec836d2a1bdcda847ab0517 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 19 May 2010 12:41:50 +1000 Subject: doc --- doc/src/examples/qml-folderlistmodel.qdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/src/examples/qml-folderlistmodel.qdoc b/doc/src/examples/qml-folderlistmodel.qdoc index 6e5f493..b820528 100644 --- a/doc/src/examples/qml-folderlistmodel.qdoc +++ b/doc/src/examples/qml-folderlistmodel.qdoc @@ -114,6 +114,8 @@ Lastly, the boilerplare to declare the type for QML use: \snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h qml decl +\section1 Connecting the Model to QML + To make this class available to QML, we only need to make a simple subclass of QDeclarativeExtensionPlugin: \snippet src/imports/folderlistmodel/plugin.cpp class decl -- cgit v0.12 From 36c51fe5229580ddaef7b7feb23822ecb775bffc Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 19 May 2010 12:54:59 +1000 Subject: Bug moved. --- .../qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 831e318..4173a44 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -238,7 +238,7 @@ void tst_qdeclarativexmllistmodel::roleErrors() QCOMPARE(data.value(Qt::UserRole+1), QVariant()); QCOMPARE(data.value(Qt::UserRole+2), QVariant()); - QEXPECT_FAIL("", "QT-2456", Continue); + QEXPECT_FAIL("", "QTBUG-10797", Continue); QCOMPARE(data.value(Qt::UserRole+3), QVariant()); delete model; -- cgit v0.12 From 90faa4aafc32adcf8fc3415fa0aa36d765b51087 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 19 May 2010 13:17:00 +1000 Subject: Introduce a threaded interpreter for QML binding bytecode Reviewed-by: Roberto Raggi --- .../qml/qdeclarativecompiledbindings.cpp | 389 ++++++++++++--------- 1 file changed, 233 insertions(+), 156 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index 7ddc735..ad05e80 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -64,6 +64,73 @@ DEFINE_BOOL_CONFIG_OPTION(bindingsDump, QML_BINDINGS_DUMP); Q_GLOBAL_STATIC(QDeclarativeFastProperties, fastProperties); +#ifdef __GNUC__ +# define QML_THREADED_INTERPRETER +#endif + +#define FOR_EACH_QML_INSTR(F) \ + F(Noop) /* Nop */ \ + F(BindingId) /* id */ \ + F(Subscribe) /* subscribe */ \ + F(SubscribeId) /* subscribe */ \ + F(FetchAndSubscribe) /* fetchAndSubscribe */ \ + F(LoadId) /* load */ \ + F(LoadScope) /* load */ \ + F(LoadRoot) /* load */ \ + F(LoadAttached) /* attached */ \ + F(ConvertIntToReal) /* unaryop */ \ + F(ConvertRealToInt) /* unaryop */ \ + F(Real) /* real_value */ \ + F(Int) /* int_value */ \ + F(Bool) /* bool_value */ \ + F(String) /* string_value */ \ + F(AddReal) /* binaryop */ \ + F(AddInt) /* binaryop */ \ + F(AddString) /* binaryop */ \ + F(MinusReal) /* binaryop */ \ + F(MinusInt) /* binaryop */ \ + F(CompareReal) /* binaryop */ \ + F(CompareString) /* binaryop */ \ + F(NotCompareReal) /* binaryop */ \ + F(NotCompareString) /* binaryop */ \ + F(GreaterThanReal) /* binaryop */ \ + F(MaxReal) /* binaryop */ \ + F(MinReal) /* binaryop */ \ + F(NewString) /* construct */ \ + F(NewUrl) /* construct */ \ + F(CleanupUrl) /* cleanup */ \ + F(CleanupString) /* cleanup */ \ + F(Copy) /* copy */ \ + F(Fetch) /* fetch */ \ + F(Store) /* store */ \ + F(Skip) /* skip */ \ + F(Done) /* done */ \ + /* Speculative property resolution */ \ + F(InitString) /* initstring */ \ + F(FindGeneric) /* find */ \ + F(FindGenericTerminal) /* find */ \ + F(FindProperty) /* find */ \ + F(FindPropertyTerminal) /* find */ \ + F(CleanupGeneric) /* cleanup */ \ + F(ConvertGenericToReal) /* unaryop */ \ + F(ConvertGenericToBool) /* unaryop */ \ + F(ConvertGenericToString) /* unaryop */ \ + F(ConvertGenericToUrl) /* unaryop */ + +#define QML_INSTR_ENUM(I) I, +#define QML_INSTR_ADDR(I) &&op_##I, + +#ifdef QML_THREADED_INTERPRETER +# define QML_BEGIN_INSTR(I) op_##I: +# define QML_END_INSTR(I) ++instr; goto *instr->common.code; +# define QML_INSTR_HEADER void *code; +#else +# define QML_BEGIN_INSTR(I) case Instr::I: +# define QML_END_INSTR(I) break; +# define QML_INSTR_HEADER +#endif + + using namespace QDeclarativeJS; namespace { @@ -328,101 +395,45 @@ namespace { // This structure is exactly 8-bytes in size struct Instr { enum { - Noop, - BindingId, // id - - Subscribe, // subscribe - SubscribeId, // subscribe - - FetchAndSubscribe, // fetchAndSubscribe - - LoadId, // load - LoadScope, // load - LoadRoot, // load - LoadAttached, // attached - - ConvertIntToReal, // unaryop - ConvertRealToInt, // unaryop - - Real, // real_value - Int, // int_value - Bool, // bool_value - String, // string_value - - AddReal, // binaryop - AddInt, // binaryop - AddString, // binaryop - - MinusReal, // binaryop - MinusInt, // binaryop - - CompareReal, // binaryop - CompareString, // binaryop - - NotCompareReal, // binaryop - NotCompareString, // binaryop - - GreaterThanReal, // binaryop - MaxReal, // binaryop - MinReal, // binaryop - - NewString, // construct - NewUrl, // construct - - CleanupUrl, // cleanup - CleanupString, // cleanup - - Copy, // copy - Fetch, // fetch - Store, // store - - Skip, // skip - - Done, - - // Speculative property resolution - InitString, // initstring - FindGeneric, // find - FindGenericTerminal, // find - FindProperty, // find - FindPropertyTerminal, // find - CleanupGeneric, // cleanup - ConvertGenericToReal, // unaryop - ConvertGenericToBool, // unaryop - ConvertGenericToString, // unaryop - ConvertGenericToUrl, // unaryop + FOR_EACH_QML_INSTR(QML_INSTR_ENUM) }; union { struct { + QML_INSTR_HEADER quint8 type; quint8 packing[7]; } common; struct { + QML_INSTR_HEADER quint8 type; quint8 packing; quint16 column; quint32 line; } id; struct { + QML_INSTR_HEADER quint8 type; quint8 packing[3]; quint16 subscriptions; quint16 identifiers; } init; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint16 offset; quint32 index; } subscribe; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; quint32 index; } load; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 reg; @@ -430,6 +441,7 @@ struct Instr { quint32 index; } attached; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 reg; @@ -437,6 +449,7 @@ struct Instr { quint32 index; } store; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 objectReg; @@ -445,6 +458,7 @@ struct Instr { quint16 function; } fetchAndSubscribe; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 objectReg; @@ -452,41 +466,48 @@ struct Instr { quint32 index; } fetch; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; qint8 src; quint8 packing[5]; } copy; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[6]; } construct; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; float value; } real_value; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; int value; } int_value; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; bool value; quint8 packing[5]; } bool_value; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint16 length; quint32 offset; } string_value; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 src1; @@ -494,18 +515,21 @@ struct Instr { quint8 packing[4]; } binaryop; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 src; quint8 packing[5]; } unaryop; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; quint32 count; } skip; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; qint8 src; @@ -514,11 +538,13 @@ struct Instr { quint16 subscribeIndex; } find; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[6]; } cleanup; struct { + QML_INSTR_HEADER quint8 type; quint8 packing[1]; quint16 offset; @@ -535,7 +561,7 @@ struct Program { quint16 subscriptions; quint16 identifiers; quint16 instructionCount; - quint16 dummy; + quint16 compiled; const char *data() const { return ((const char *)this) + sizeof(Program); } const Instr *instructions() const { return (const Instr *)(data() + dataLength); } @@ -1097,35 +1123,57 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, instr += instrIndex; const char *data = program->data(); +#ifdef QML_THREADED_INTERPRETER + static void *decode_instr[] = { + FOR_EACH_QML_INSTR(QML_INSTR_ADDR) + }; + + if (!program->compiled) { + program->compiled = true; + const Instr *inop = program->instructions(); + for (int i = 0; i < program->instructionCount; ++i) { + Instr *op = (Instr *) inop++; + op->common.code = decode_instr[op->common.type]; + } + } + + goto *instr->common.code; +#else // return; + #ifdef COMPILEDBINDINGS_DEBUG qWarning().nospace() << "Begin binding run"; #endif while (instr) { + switch (instr->common.type) { + #ifdef COMPILEDBINDINGS_DEBUG dumpInstruction(instr); #endif - switch (instr->common.type) { - case Instr::Noop: - case Instr::BindingId: - break; +#endif - case Instr::SubscribeId: + QML_BEGIN_INSTR(Noop) + QML_END_INSTR(Noop) + + QML_BEGIN_INSTR(BindingId) + QML_END_INSTR(BindingId) + + QML_BEGIN_INSTR(SubscribeId) subscribeId(context, instr->subscribe.index, instr->subscribe.offset); - break; + QML_END_INSTR(SubscribeId) - case Instr::Subscribe: + QML_BEGIN_INSTR(Subscribe) { QObject *o = 0; const Register &object = registers[instr->subscribe.reg]; if (!object.isUndefined()) o = object.getQObject(); subscribe(o, instr->subscribe.index, instr->subscribe.offset); } - break; + QML_END_INSTR(Subscribe) - case Instr::FetchAndSubscribe: + QML_BEGIN_INSTR(FetchAndSubscribe) { const Register &input = registers[instr->fetchAndSubscribe.objectReg]; Register &output = registers[instr->fetchAndSubscribe.output]; @@ -1149,21 +1197,21 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, fastProperties()->accessor(instr->fetchAndSubscribe.function)(object, output.typeDataPtr(), sub); } } - break; + QML_END_INSTR(FetchAndSubscribe) - case Instr::LoadId: + QML_BEGIN_INSTR(LoadId) registers[instr->load.reg].setQObject(context->idValues[instr->load.index].data()); - break; + QML_END_INSTR(LoadId) - case Instr::LoadScope: + QML_BEGIN_INSTR(LoadScope) registers[instr->load.reg].setQObject(scope); - break; + QML_END_INSTR(LoadScope) - case Instr::LoadRoot: + QML_BEGIN_INSTR(LoadRoot) registers[instr->load.reg].setQObject(context->contextObject); - break; + QML_END_INSTR(LoadRoot) - case Instr::LoadAttached: + QML_BEGIN_INSTR(LoadAttached) { const Register &input = registers[instr->attached.reg]; Register &output = registers[instr->attached.output]; @@ -1184,48 +1232,48 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.setQObject(attached); } } - break; + QML_END_INSTR(LoadAttached) - case Instr::ConvertIntToReal: + QML_BEGIN_INSTR(ConvertIntToReal) { const Register &input = registers[instr->unaryop.src]; Register &output = registers[instr->unaryop.output]; if (input.isUndefined()) output.setUndefined(); else output.setqreal(qreal(input.getint())); } - break; + QML_END_INSTR(ConvertIntToReal) - case Instr::ConvertRealToInt: + QML_BEGIN_INSTR(ConvertRealToInt) { const Register &input = registers[instr->unaryop.src]; Register &output = registers[instr->unaryop.output]; if (input.isUndefined()) output.setUndefined(); else output.setint(qRound(input.getqreal())); } - break; + QML_END_INSTR(ConvertRealToInt) - case Instr::Real: + QML_BEGIN_INSTR(Real) registers[instr->real_value.reg].setqreal(instr->real_value.value); - break; + QML_END_INSTR(Real) - case Instr::Int: + QML_BEGIN_INSTR(Int) registers[instr->int_value.reg].setint(instr->int_value.value); - break; + QML_END_INSTR(Int) - case Instr::Bool: + QML_BEGIN_INSTR(Bool) registers[instr->bool_value.reg].setbool(instr->bool_value.value); - break; + QML_END_INSTR(Bool) - case Instr::String: + QML_BEGIN_INSTR(String) { Register &output = registers[instr->string_value.reg]; new (output.getstringptr()) QString((QChar *)(data + instr->string_value.offset), instr->string_value.length); output.settype(QMetaType::QString); } - break; + QML_END_INSTR(String) - case Instr::AddReal: + QML_BEGIN_INSTR(AddReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1233,9 +1281,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(lhs.getqreal() + rhs.getqreal()); } - break; + QML_END_INSTR(AddReal) - case Instr::AddInt: + QML_BEGIN_INSTR(AddInt) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1243,9 +1291,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setint(lhs.getint() + rhs.getint()); } - break; + QML_END_INSTR(AddInt) - case Instr::AddString: + QML_BEGIN_INSTR(AddString) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1265,9 +1313,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.settype(QMetaType::QString); } } - break; + QML_END_INSTR(AddString) - case Instr::MinusReal: + QML_BEGIN_INSTR(MinusReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1275,9 +1323,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(lhs.getqreal() - rhs.getqreal()); } - break; + QML_END_INSTR(MinusReal) - case Instr::MinusInt: + QML_BEGIN_INSTR(MinusInt) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1285,9 +1333,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setint(lhs.getint() - rhs.getint()); } - break; + QML_END_INSTR(MinusInt) - case Instr::CompareReal: + QML_BEGIN_INSTR(CompareReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1295,9 +1343,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() == rhs.isUndefined()); else output.setbool(lhs.getqreal() == rhs.getqreal()); } - break; + QML_END_INSTR(CompareReal) - case Instr::CompareString: + QML_BEGIN_INSTR(CompareString) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1305,9 +1353,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() == rhs.isUndefined()); else output.setbool(*lhs.getstringptr() == *rhs.getstringptr()); } - break; + QML_END_INSTR(CompareString) - case Instr::NotCompareReal: + QML_BEGIN_INSTR(NotCompareReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1315,9 +1363,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() != rhs.isUndefined()); else output.setbool(lhs.getqreal() != rhs.getqreal()); } - break; + QML_END_INSTR(NotCompareReal) - case Instr::NotCompareString: + QML_BEGIN_INSTR(NotCompareString) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1325,9 +1373,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() != rhs.isUndefined()); else output.setbool(*lhs.getstringptr() != *rhs.getstringptr()); } - break; + QML_END_INSTR(NotCompareString) - case Instr::GreaterThanReal: + QML_BEGIN_INSTR(GreaterThanReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1335,9 +1383,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(false); else output.setbool(lhs.getqreal() > rhs.getqreal()); } - break; + QML_END_INSTR(GreaterThanReal) - case Instr::MaxReal: + QML_BEGIN_INSTR(MaxReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1345,9 +1393,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(qMax(lhs.getqreal(), rhs.getqreal())); } - break; + QML_END_INSTR(MaxReal) - case Instr::MinReal: + QML_BEGIN_INSTR(MinReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1355,33 +1403,33 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(qMin(lhs.getqreal(), rhs.getqreal())); } - break; + QML_END_INSTR(MinReal) - case Instr::NewString: + QML_BEGIN_INSTR(NewString) { Register &output = registers[instr->construct.reg]; new (output.getstringptr()) QString; output.settype(QMetaType::QString); } - break; + QML_END_INSTR(NewString) - case Instr::NewUrl: + QML_BEGIN_INSTR(NewUrl) { Register &output = registers[instr->construct.reg]; new (output.geturlptr()) QUrl; output.settype(QMetaType::QUrl); } - break; + QML_END_INSTR(NewUrl) - case Instr::CleanupString: + QML_BEGIN_INSTR(CleanupString) registers[instr->cleanup.reg].getstringptr()->~QString(); - break; + QML_END_INSTR(CleanupString) - case Instr::CleanupUrl: + QML_BEGIN_INSTR(CleanupUrl) registers[instr->cleanup.reg].geturlptr()->~QUrl(); - break; + QML_END_INSTR(CleanupUrl) - case Instr::Fetch: + QML_BEGIN_INSTR(Fetch) { const Register &input = registers[instr->fetch.objectReg]; Register &output = registers[instr->fetch.output]; @@ -1399,9 +1447,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, QMetaObject::metacall(object, QMetaObject::ReadProperty, instr->fetch.index, argv); } } - break; + QML_END_INSTR(Fetch) - case Instr::Store: + QML_BEGIN_INSTR(Store) { Register &data = registers[instr->store.reg]; if (data.isUndefined()) { @@ -1415,21 +1463,22 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, QMetaObject::metacall(output, QMetaObject::WriteProperty, instr->store.index, argv); } - break; + QML_END_INSTR(Store) - case Instr::Copy: + QML_BEGIN_INSTR(Copy) registers[instr->copy.reg] = registers[instr->copy.src]; - break; + QML_END_INSTR(Copy) - case Instr::Skip: + QML_BEGIN_INSTR(Skip) if (instr->skip.reg == -1 || !registers[instr->skip.reg].getbool()) instr += instr->skip.count; - break; + QML_END_INSTR(Skip) - case Instr::Done: + QML_BEGIN_INSTR(Done) return; + QML_END_INSTR(Done) - case Instr::InitString: + QML_BEGIN_INSTR(InitString) if (!identifiers[instr->initstring.offset].identifier) { quint32 len = *(quint32 *)(data + instr->initstring.dataIdx); QChar *strdata = (QChar *)(data + instr->initstring.dataIdx + sizeof(quint32)); @@ -1438,10 +1487,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, identifiers[instr->initstring.offset] = engine->objectClass->createPersistentIdentifier(str); } - break; + QML_END_INSTR(InitString) - case Instr::FindGenericTerminal: - case Instr::FindGeneric: + QML_BEGIN_INSTR(FindGenericTerminal) // We start the search in the parent context, as we know that the // name is not present in the current context or it would have been // found during the static compile @@ -1449,10 +1497,19 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, context->parent, identifiers[instr->find.name].identifier, instr->common.type == Instr::FindGenericTerminal); - break; + QML_END_INSTR(FindGenericTerminal) - case Instr::FindPropertyTerminal: - case Instr::FindProperty: + QML_BEGIN_INSTR(FindGeneric) + // We start the search in the parent context, as we know that the + // name is not present in the current context or it would have been + // found during the static compile + findgeneric(registers + instr->find.reg, instr->find.subscribeIndex, + context->parent, + identifiers[instr->find.name].identifier, + instr->common.type == Instr::FindGenericTerminal); + QML_END_INSTR(FindGeneric) + + QML_BEGIN_INSTR(FindPropertyTerminal) { const Register &object = registers[instr->find.src]; if (object.isUndefined()) { @@ -1465,9 +1522,24 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, instr->find.subscribeIndex, identifiers[instr->find.name].identifier, instr->common.type == Instr::FindPropertyTerminal); } - break; + QML_END_INSTR(FindPropertyTerminal) - case Instr::CleanupGeneric: + QML_BEGIN_INSTR(FindProperty) + { + const Register &object = registers[instr->find.src]; + if (object.isUndefined()) { + throwException(instr->find.exceptionId, error, program, context); + return; + } + + findproperty(object.getQObject(), registers + instr->find.reg, + QDeclarativeEnginePrivate::get(context->engine), + instr->find.subscribeIndex, identifiers[instr->find.name].identifier, + instr->common.type == Instr::FindPropertyTerminal); + } + QML_END_INSTR(FindProperty) + + QML_BEGIN_INSTR(CleanupGeneric) { int type = registers[instr->cleanup.reg].gettype(); if (type == qMetaTypeId()) { @@ -1478,9 +1550,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, registers[instr->cleanup.reg].geturlptr()->~QUrl(); } } - break; + QML_END_INSTR(CleanupGeneric) - case Instr::ConvertGenericToReal: + QML_BEGIN_INSTR(ConvertGenericToReal) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1488,9 +1560,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.setqreal(toReal(&input, input.gettype(), &ok)); if (!ok) output.setUndefined(); } - break; + QML_END_INSTR(ConvertGenericToReal) - case Instr::ConvertGenericToBool: + QML_BEGIN_INSTR(ConvertGenericToBool) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1498,9 +1570,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.setbool(toBool(&input, input.gettype(), &ok)); if (!ok) output.setUndefined(); } - break; + QML_END_INSTR(ConvertGenericToBool) - case Instr::ConvertGenericToString: + QML_BEGIN_INSTR(ConvertGenericToString) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1509,9 +1581,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (ok) { new (output.getstringptr()) QString(str); output.settype(QMetaType::QString); } else { output.setUndefined(); } } - break; + QML_END_INSTR(ConvertGenericToString) - case Instr::ConvertGenericToUrl: + QML_BEGIN_INSTR(ConvertGenericToUrl) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1520,15 +1592,19 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (ok) { new (output.geturlptr()) QUrl(url); output.settype(QMetaType::QUrl); } else { output.setUndefined(); } } - break; + QML_END_INSTR(ConvertGenericToUrl) +#ifdef QML_THREADED_INTERPRETER + // nothing to do +#else default: qFatal("EEK"); break; - } + } // switch - instr++; - } + ++instr; + } // while +#endif } void QDeclarativeBindingCompiler::dump(const QByteArray &programData) @@ -2781,6 +2857,7 @@ QByteArray QDeclarativeBindingCompiler::program() const prog.subscriptions = d->committed.subscriptionIds.count(); prog.identifiers = d->committed.registeredStrings.count(); prog.instructionCount = bytecode.count(); + prog.compiled = false; int size = sizeof(Program) + bytecode.count() * sizeof(Instr); size += prog.dataLength; -- cgit v0.12 From 14ecb79de540af894e779fcc11937c82ffda8cc8 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 19 May 2010 14:29:24 +1000 Subject: Don't crash if the target parent is destroyed. Task-number: QTBUG-10755 --- src/declarative/util/qdeclarativestateoperations.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index b11c0c2..80ae5f5 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -69,7 +69,7 @@ public: rewindParent(0), rewindStackBefore(0) {} QDeclarativeItem *target; - QDeclarativeItem *parent; + QDeclarativeGuard parent; QDeclarativeGuard origParent; QDeclarativeGuard origStackBefore; QDeclarativeItem *rewindParent; -- cgit v0.12 From 399bb3dbeacc1d055191c200bbbc2ab262a8eb9b Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 19 May 2010 08:23:52 +0200 Subject: Rename qml executable to qmlviewer Revert the name of the 'qml' executable back to qmlviewer (QMLViewer on mac). --- doc/src/declarative/qmlruntime.qdoc | 8 ++++---- tools/qml/main.cpp | 4 ++-- tools/qml/qml.pro | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/doc/src/declarative/qmlruntime.qdoc b/doc/src/declarative/qmlruntime.qdoc index a03b9c2..cef5e63 100644 --- a/doc/src/declarative/qmlruntime.qdoc +++ b/doc/src/declarative/qmlruntime.qdoc @@ -42,7 +42,7 @@ /*! \page qmlruntime.html \title Qt Declarative UI Runtime - \keyword QML Viewer (qml) + \keyword QML Viewer \ingroup qttools This page documents the \e{Declarative UI Runtime} for the Qt GUI @@ -67,7 +67,7 @@ To run an application with the \QQV, pass the filename as an argument: \code - qml myQmlFile.qml + qmlviewer myQmlFile.qml \endcode Deploying a QML application via the \QQV allows for QML only deployments, but can also @@ -92,7 +92,7 @@ as the appropriate module file is chosen based on platform naming conventions. The C++ modules must contain a QDeclarativeExtentionPlugin subclass. - The application would be executed either with your own application, the command 'qml MyApp.qml' or by + The application would be executed either with your own application, the command 'qmlviewer MyApp.qml' or by opening the file if your system has the \QQV registered as the handler for QML files. The MyApp.qml file would have access to all of the deployed types using the import statements such as the following: @@ -109,7 +109,7 @@ \section2 Options - When run with the \c -help option, \c qml shows available options. + When run with the \c -help option, \c qmlviewer shows available options. \section2 Translations diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 22fc5ca..0cce1cc 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -110,7 +110,7 @@ void myMessageOutput(QtMsgType type, const char *msg) void usage() { - qWarning("Usage: qml [options] "); + qWarning("Usage: qmlviewer [options] "); qWarning(" "); qWarning(" options:"); qWarning(" -v, -version ............................. display version"); @@ -148,7 +148,7 @@ void usage() void scriptOptsUsage() { - qWarning("Usage: qml -scriptopts