From 3e86171f03ff295c0c77ade7ef49e8c395063bd8 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 16 Oct 2009 09:41:37 +1000 Subject: spel --- doc/src/declarative/network.qdoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/declarative/network.qdoc b/doc/src/declarative/network.qdoc index da4495f..e88dfdc 100644 --- a/doc/src/declarative/network.qdoc +++ b/doc/src/declarative/network.qdoc @@ -47,7 +47,7 @@ QML supports network transparency by using URLs (rather than file names) for all references from a QML document to other content. Since a \i relative URL is the same as a relative file, development of QML on regular file systems remains simple. -\section1 Accessing Network Reesources from QML +\section1 Accessing Network Resources from QML Whenever an object has a property of type URL (QUrl), assigning a string to that property will actually assign an absolute URL - by resolving the string against @@ -105,7 +105,7 @@ The \c import statement only works network transparently if it has an "as" claus All network access from QML is managed by a QNetworkAccessManager set on the QmlEngine which executes the QML. By default, this is an unmodified Qt QNetworkAccessManager. You may set a different manager using QmlEngine::setNetworkAccessManager() as appropriate for the policies of your application. -For eample, the \l qmlviewer tool sets a new QNetworkAccessManager which +For example, the \l qmlviewer tool sets a new QNetworkAccessManager which trusts HTTP Expiry headers to avoid network cache checks, allows HTTP Pipelining, adds a persistent HTTP CookieJar, a simple disk cache, and supports proxy settings. -- cgit v0.12 From 768c642574cc6ee1748c165ab60d027830a45d43 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 16 Oct 2009 11:28:30 +1000 Subject: doc --- src/declarative/qml/qmlcontext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 43a4741..31d4e1f 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -469,7 +469,7 @@ QUrl QmlContext::resolvedUrl(const QUrl &src) } /*! - Explicitly sets the url resolveUrl() will use for relative references to \a baseUrl. + Explicitly sets the url resolvedUrl() will use for relative references to \a baseUrl. Calling this function will override the url of the containing component used by default. -- cgit v0.12 From cf822676f9198b532b324b82855ecb6cae7c6968 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 16 Oct 2009 12:32:10 +1000 Subject: Improve FolderListModel a little File -> Url Support the useful filters --- examples/declarative/loader/Browser.qml | 2 +- src/declarative/extra/qmlfolderlistmodel.cpp | 104 +++++++++++++++++++++++---- src/declarative/extra/qmlfolderlistmodel.h | 18 +++-- 3 files changed, 107 insertions(+), 17 deletions(-) diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml index 9eedd4e..3e61de0 100644 --- a/examples/declarative/loader/Browser.qml +++ b/examples/declarative/loader/Browser.qml @@ -9,7 +9,7 @@ Rectangle { FolderListModel { id: folders nameFilters: [ "*.qml" ] - folder: "E:" + folder: "file:///E:/" // Documents on your S60 phone (or Windows E: drive) } SystemPalette { id: palette; colorGroup: Qt.Active } diff --git a/src/declarative/extra/qmlfolderlistmodel.cpp b/src/declarative/extra/qmlfolderlistmodel.cpp index 4a7c2f1..0e5c275 100644 --- a/src/declarative/extra/qmlfolderlistmodel.cpp +++ b/src/declarative/extra/qmlfolderlistmodel.cpp @@ -43,6 +43,7 @@ #include #include #include "qmlfolderlistmodel.h" +#include QT_BEGIN_NAMESPACE @@ -51,7 +52,6 @@ class QmlFolderListModelPrivate : public QObjectPrivate public: QmlFolderListModelPrivate() : sortField(QmlFolderListModel::Name), sortReversed(false), count(0) { - folder = QDir::currentPath(); nameFilters << QLatin1String("*"); } @@ -82,7 +82,7 @@ public: } QDirModel model; - QString folder; + QUrl folder; QStringList nameFilters; QModelIndex folderIndex; QmlFolderListModel::SortField sortField; @@ -116,7 +116,7 @@ QmlFolderListModel::QmlFolderListModel(QObject *parent) : QListModelInterface(*(new QmlFolderListModelPrivate), parent) { Q_D(QmlFolderListModel); - d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives); + 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)) @@ -139,7 +139,7 @@ QHash QmlFolderListModel::data(int index, const QList &roles) QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex); if (modelIndex.isValid()) { folderData[QDirModel::FileNameRole] = d->model.data(modelIndex, QDirModel::FileNameRole); - folderData[QDirModel::FilePathRole] = d->model.data(modelIndex, QDirModel::FilePathRole); + folderData[QDirModel::FilePathRole] = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString()); } return folderData; @@ -175,19 +175,21 @@ QString QmlFolderListModel::toString(int role) const \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). */ -QString QmlFolderListModel::folder() const +QUrl QmlFolderListModel::folder() const { Q_D(const QmlFolderListModel); return d->folder; } -void QmlFolderListModel::setFolder(const QString &folder) +void QmlFolderListModel::setFolder(const QUrl &folder) { Q_D(QmlFolderListModel); if (folder == d->folder) return; - QModelIndex index = d->model.index(folder); + QModelIndex index = d->model.index(folder.toLocalFile()); if (index.isValid() && d->model.isDir(index)) { d->folder = folder; QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); @@ -195,13 +197,15 @@ void QmlFolderListModel::setFolder(const QString &folder) } } -QString QmlFolderListModel::parentFolder() const +QUrl QmlFolderListModel::parentFolder() const { Q_D(const QmlFolderListModel); - int pos = d->folder.lastIndexOf('/'); + int pos = d->folder.path().lastIndexOf(QLatin1Char('/')); if (pos == -1) - return QString(); - return d->folder.left(pos); + return QUrl(); + QUrl r = d->folder; + r.setPath(d->folder.path().left(pos)); + return r; } /*! @@ -234,6 +238,9 @@ void QmlFolderListModel::setNameFilters(const QStringList &filters) void QmlFolderListModel::componentComplete() { Q_D(QmlFolderListModel); + 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); } @@ -294,7 +301,7 @@ void QmlFolderListModel::refresh() d->count = 0; emit itemsRemoved(0, tmpCount); } - d->folderIndex = d->model.index(d->folder); + d->folderIndex = d->model.index(d->folder.toLocalFile()); d->count = d->model.rowCount(d->folderIndex); if (d->count) { emit itemsInserted(0, d->count); @@ -327,6 +334,79 @@ void QmlFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex 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 QmlFolderListModel::showDirs() const +{ + Q_D(const QmlFolderListModel); + return d->model.filter() & QDir::AllDirs; +} + +void QmlFolderListModel::setShowDirs(bool on) +{ + Q_D(QmlFolderListModel); + 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 QmlFolderListModel::showDotAndDotDot() const +{ + Q_D(const QmlFolderListModel); + return !(d->model.filter() & QDir::NoDotAndDotDot); +} + +void QmlFolderListModel::setShowDotAndDotDot(bool on) +{ + Q_D(QmlFolderListModel); + 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 QmlFolderListModel::showOnlyReadable() const +{ + Q_D(const QmlFolderListModel); + return d->model.filter() & QDir::Readable; +} + +void QmlFolderListModel::setShowOnlyReadable(bool on) +{ + Q_D(QmlFolderListModel); + 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); +} + + QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FolderListModel,QmlFolderListModel) QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlfolderlistmodel.h b/src/declarative/extra/qmlfolderlistmodel.h index 6bb1c4b..cee44e8 100644 --- a/src/declarative/extra/qmlfolderlistmodel.h +++ b/src/declarative/extra/qmlfolderlistmodel.h @@ -60,11 +60,14 @@ class Q_DECLARATIVE_EXPORT QmlFolderListModel : public QListModelInterface, publ Q_OBJECT Q_INTERFACES(QmlParserStatus) - Q_PROPERTY(QString folder READ folder WRITE setFolder NOTIFY folderChanged) + Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged) Q_PROPERTY(QString 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: QmlFolderListModel(QObject *parent = 0); @@ -75,10 +78,10 @@ public: virtual QList roles() const; virtual QString toString(int role) const; - QString folder() const; - void setFolder(const QString &folder); + QUrl folder() const; + void setFolder(const QUrl &folder); - QString parentFolder() const; + QUrl parentFolder() const; QStringList nameFilters() const; void setNameFilters(const QStringList &filters); @@ -95,6 +98,13 @@ public: 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(); -- cgit v0.12