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