summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/declarative/network.qdoc4
-rw-r--r--examples/declarative/loader/Browser.qml2
-rw-r--r--src/declarative/extra/qmlfolderlistmodel.cpp104
-rw-r--r--src/declarative/extra/qmlfolderlistmodel.h18
-rw-r--r--src/declarative/fx/qfxmouseregion.cpp1
-rw-r--r--src/declarative/qml/qmlcontext.cpp2
6 files changed, 111 insertions, 20 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.
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 <QDirModel>
#include <qdebug.h>
#include "qmlfolderlistmodel.h"
+#include <QtDeclarative/qmlcontext.h>
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<int,QVariant> QmlFolderListModel::data(int index, const QList<int> &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<int> 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();
diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp
index d3c776f..4b31fd4 100644
--- a/src/declarative/fx/qfxmouseregion.cpp
+++ b/src/declarative/fx/qfxmouseregion.cpp
@@ -440,6 +440,7 @@ void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
// If we don't accept hover, we need to reset containsMouse.
if (!acceptHoverEvents())
setHovered(false);
+ setKeepMouseGrab(false);
}
}
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.