2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-01-05 04:29:18 +00:00
|
|
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2012-01-20 04:04:27 +00:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the examples of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-05-24 11:43:28 +00:00
|
|
|
** 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.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-05-24 11:43:28 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 11:43:28 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
2012-01-24 03:37:23 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
//![code]
|
2012-02-16 04:43:03 +00:00
|
|
|
#include "qquickfolderlistmodel.h"
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QDirModel>
|
|
|
|
#include <QDebug>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <qqmlcontext.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef QT_NO_DIRMODEL
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class QQuickFolderListModelPrivate
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickFolderListModelPrivate()
|
|
|
|
: sortField(QQuickFolderListModel::Name), sortReversed(false), count(0), showDirs(true), showDots(false), showOnlyReadable(false), insideRefresh(false) {
|
2011-04-27 10:05:43 +00:00
|
|
|
nameFilters << QLatin1String("*");
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateSorting() {
|
|
|
|
QDir::SortFlags flags = 0;
|
|
|
|
switch(sortField) {
|
2012-02-16 04:43:03 +00:00
|
|
|
case QQuickFolderListModel::Unsorted:
|
2011-04-27 10:05:43 +00:00
|
|
|
flags |= QDir::Unsorted;
|
|
|
|
break;
|
2012-02-16 04:43:03 +00:00
|
|
|
case QQuickFolderListModel::Name:
|
2011-04-27 10:05:43 +00:00
|
|
|
flags |= QDir::Name;
|
|
|
|
break;
|
2012-02-16 04:43:03 +00:00
|
|
|
case QQuickFolderListModel::Time:
|
2011-04-27 10:05:43 +00:00
|
|
|
flags |= QDir::Time;
|
|
|
|
break;
|
2012-02-16 04:43:03 +00:00
|
|
|
case QQuickFolderListModel::Size:
|
2011-04-27 10:05:43 +00:00
|
|
|
flags |= QDir::Size;
|
|
|
|
break;
|
2012-02-16 04:43:03 +00:00
|
|
|
case QQuickFolderListModel::Type:
|
2011-04-27 10:05:43 +00:00
|
|
|
flags |= QDir::Type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sortReversed)
|
|
|
|
flags |= QDir::Reversed;
|
|
|
|
|
|
|
|
model.setSorting(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDirModel model;
|
|
|
|
QUrl folder;
|
|
|
|
QStringList nameFilters;
|
|
|
|
QModelIndex folderIndex;
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickFolderListModel::SortField sortField;
|
2011-04-27 10:05:43 +00:00
|
|
|
bool sortReversed;
|
|
|
|
int count;
|
2011-05-23 05:38:53 +00:00
|
|
|
bool showDirs;
|
|
|
|
bool showDots;
|
|
|
|
bool showOnlyReadable;
|
|
|
|
bool insideRefresh;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
2012-02-16 04:43:03 +00:00
|
|
|
\qmlclass FolderListModel QQuickFolderListModel
|
2011-04-27 10:05:43 +00:00
|
|
|
\ingroup qml-working-with-data
|
|
|
|
\brief The FolderListModel provides a model of the contents of a file system folder.
|
|
|
|
|
|
|
|
FolderListModel provides access to information about the contents of a folder
|
|
|
|
in the local file system, exposing a list of files to views and other data components.
|
|
|
|
|
|
|
|
\note This type is made available by importing the \c Qt.labs.folderlistmodel module.
|
|
|
|
\e{Elements in the Qt.labs module are not guaranteed to remain compatible
|
|
|
|
in future versions.}
|
|
|
|
|
|
|
|
\bold{import Qt.labs.folderlistmodel 1.0}
|
|
|
|
|
|
|
|
The \l folder property specifies the folder to access. Information about the
|
|
|
|
files and directories in the folder is supplied via the model's interface.
|
|
|
|
Components access names and paths via the following roles:
|
|
|
|
|
|
|
|
\list
|
|
|
|
\o fileName
|
|
|
|
\o filePath
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
Additionally a file entry can be differentiated from a folder entry via the
|
|
|
|
isFolder() method.
|
|
|
|
|
|
|
|
\section1 Filtering
|
|
|
|
|
|
|
|
Various properties can be set to filter the number of files and directories
|
|
|
|
exposed by the model.
|
|
|
|
|
|
|
|
The \l nameFilters property can be set to contain a list of wildcard filters
|
|
|
|
that are applied to names of files and directories, causing only those that
|
|
|
|
match the filters to be exposed.
|
|
|
|
|
|
|
|
Directories can be included or excluded using the \l showDirs property, and
|
|
|
|
navigation directories can also be excluded by setting the \l showDotAndDotDot
|
|
|
|
property to false.
|
|
|
|
|
|
|
|
It is sometimes useful to limit the files and directories exposed to those
|
|
|
|
that the user can access. The \l showOnlyReadable property can be set to
|
|
|
|
enable this feature.
|
|
|
|
|
|
|
|
\section1 Example Usage
|
|
|
|
|
|
|
|
The following example shows a FolderListModel being used to provide a list
|
|
|
|
of QML files in a \l ListView:
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
\snippet doc/src/snippets/qml/folderlistmodel.qml 0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\section1 Path Separators
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
\sa {QML Data Models}
|
|
|
|
*/
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickFolderListModel::QQuickFolderListModel(QObject *parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
: QAbstractListModel(parent)
|
|
|
|
{
|
|
|
|
QHash<int, QByteArray> roles;
|
|
|
|
roles[FileNameRole] = "fileName";
|
|
|
|
roles[FilePathRole] = "filePath";
|
|
|
|
setRoleNames(roles);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
d = new QQuickFolderListModelPrivate;
|
2011-04-27 10:05:43 +00:00
|
|
|
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(handleDataChanged(const QModelIndex&,const QModelIndex&)));
|
|
|
|
connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh()));
|
|
|
|
connect(&d->model, SIGNAL(layoutChanged()), this, SLOT(refresh()));
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickFolderListModel::~QQuickFolderListModel()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QVariant QQuickFolderListModel::data(const QModelIndex &index, int role) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\qmlproperty int FolderListModel::count
|
|
|
|
|
|
|
|
Returns the number of items in the current folder that match the
|
|
|
|
filter criteria.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
int QQuickFolderListModel::rowCount(const QModelIndex &parent) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
return d->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\qmlproperty string FolderListModel::folder
|
|
|
|
|
|
|
|
The \a folder property holds a URL for the folder that the model is
|
|
|
|
currently providing.
|
|
|
|
|
|
|
|
The value is a URL expressed as a string, and must be a \c file: or \c qrc:
|
|
|
|
URL, or a relative URL.
|
|
|
|
|
|
|
|
By default, the value is an invalid URL.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QUrl QQuickFolderListModel::folder() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
return d->folder;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::setFolder(const QUrl &folder)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (folder == d->folder)
|
|
|
|
return;
|
|
|
|
|
2011-05-23 05:38:53 +00:00
|
|
|
QModelIndex index = d->model.index(folder.toLocalFile()); // This can modify the filtering rules.
|
|
|
|
if ((index.isValid() && d->model.isDir(index)) || folder.toLocalFile().isEmpty()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
d->folder = folder;
|
2011-05-23 05:38:53 +00:00
|
|
|
QMetaObject::invokeMethod(this, "resetFiltering", Qt::QueuedConnection); // resetFiltering will invoke refresh().
|
2011-04-27 10:05:43 +00:00
|
|
|
emit folderChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::resetFiltering()
|
2011-05-23 05:38:53 +00:00
|
|
|
{
|
|
|
|
// ensure that we reset the filtering rules, because the QDirModel::index()
|
|
|
|
// function isn't quite as const as it claims to be.
|
|
|
|
QDir::Filters filt = d->model.filter();
|
|
|
|
|
|
|
|
if (d->showDirs)
|
|
|
|
filt |= (QDir::AllDirs | QDir::Drives);
|
|
|
|
else
|
|
|
|
filt &= ~(QDir::AllDirs | QDir::Drives);
|
|
|
|
|
|
|
|
if (d->showDots)
|
|
|
|
filt &= ~QDir::NoDotAndDotDot;
|
|
|
|
else
|
|
|
|
filt |= QDir::NoDotAndDotDot;
|
|
|
|
|
|
|
|
if (d->showOnlyReadable)
|
|
|
|
filt |= QDir::Readable;
|
|
|
|
else
|
|
|
|
filt &= ~QDir::Readable;
|
|
|
|
|
|
|
|
d->model.setFilter(filt); // this causes a refresh().
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
|
|
|
\qmlproperty url FolderListModel::parentFolder
|
|
|
|
|
|
|
|
Returns the URL of the parent of of the current \l folder.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QUrl QQuickFolderListModel::parentFolder() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QString localFile = d->folder.toLocalFile();
|
|
|
|
if (!localFile.isEmpty()) {
|
|
|
|
QDir dir(localFile);
|
2011-10-19 05:04:15 +00:00
|
|
|
#if defined(Q_OS_WIN)
|
2011-04-27 10:05:43 +00:00
|
|
|
if (dir.isRoot())
|
|
|
|
dir.setPath("");
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
dir.cdUp();
|
|
|
|
localFile = dir.path();
|
|
|
|
} else {
|
|
|
|
int pos = d->folder.path().lastIndexOf(QLatin1Char('/'));
|
|
|
|
if (pos == -1)
|
|
|
|
return QUrl();
|
|
|
|
localFile = d->folder.path().left(pos);
|
|
|
|
}
|
|
|
|
return QUrl::fromLocalFile(localFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\qmlproperty list<string> FolderListModel::nameFilters
|
|
|
|
|
|
|
|
The \a nameFilters property contains a list of file name filters.
|
|
|
|
The filters may include the ? and * wildcards.
|
|
|
|
|
|
|
|
The example below filters on PNG and JPEG files:
|
|
|
|
|
|
|
|
\qml
|
|
|
|
FolderListModel {
|
|
|
|
nameFilters: [ "*.png", "*.jpg" ]
|
|
|
|
}
|
|
|
|
\endqml
|
|
|
|
|
|
|
|
\note Directories are not excluded by filters.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QStringList QQuickFolderListModel::nameFilters() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
return d->nameFilters;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::setNameFilters(const QStringList &filters)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
d->nameFilters = filters;
|
|
|
|
d->model.setNameFilters(d->nameFilters);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::classBegin()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::componentComplete()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (!d->folder.isValid() || d->folder.toLocalFile().isEmpty() || !QDir().exists(d->folder.toLocalFile()))
|
|
|
|
setFolder(QUrl(QLatin1String("file://")+QDir::currentPath()));
|
|
|
|
|
|
|
|
if (!d->folderIndex.isValid())
|
|
|
|
QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\qmlproperty enumeration FolderListModel::sortField
|
|
|
|
|
|
|
|
The \a sortField property contains field to use for sorting. sortField
|
|
|
|
may be one of:
|
|
|
|
\list
|
|
|
|
\o Unsorted - no sorting is applied. The order is system default.
|
|
|
|
\o Name - sort by filename
|
|
|
|
\o Time - sort by time modified
|
|
|
|
\o Size - sort by file size
|
|
|
|
\o Type - sort by file type (extension)
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
\sa sortReversed
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickFolderListModel::SortField QQuickFolderListModel::sortField() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
return d->sortField;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::setSortField(SortField field)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (field != d->sortField) {
|
|
|
|
d->sortField = field;
|
|
|
|
d->updateSorting();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\qmlproperty bool FolderListModel::sortReversed
|
|
|
|
|
|
|
|
If set to true, reverses the sort order. The default is false.
|
|
|
|
|
|
|
|
\sa sortField
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQuickFolderListModel::sortReversed() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
return d->sortReversed;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::setSortReversed(bool rev)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQuickFolderListModel::isFolder(int index) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (index != -1) {
|
|
|
|
QModelIndex idx = d->model.index(index, 0, d->folderIndex);
|
|
|
|
if (idx.isValid())
|
|
|
|
return d->model.isDir(idx);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::refresh()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-05-23 05:38:53 +00:00
|
|
|
if (d->insideRefresh)
|
|
|
|
return;
|
|
|
|
d->insideRefresh = true;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
d->folderIndex = QModelIndex();
|
|
|
|
if (d->count) {
|
|
|
|
emit beginRemoveRows(QModelIndex(), 0, d->count-1);
|
|
|
|
d->count = 0;
|
|
|
|
emit endRemoveRows();
|
|
|
|
}
|
2011-05-23 05:38:53 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
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();
|
|
|
|
}
|
2011-05-23 05:38:53 +00:00
|
|
|
|
|
|
|
d->insideRefresh = false; // finished refreshing.
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::inserted(const QModelIndex &index, int start, int end)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (index == d->folderIndex) {
|
|
|
|
emit beginInsertRows(QModelIndex(), start, end);
|
|
|
|
d->count = d->model.rowCount(d->folderIndex);
|
|
|
|
emit endInsertRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::removed(const QModelIndex &index, int start, int end)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (index == d->folderIndex) {
|
|
|
|
emit beginRemoveRows(QModelIndex(), start, end);
|
|
|
|
d->count = d->model.rowCount(d->folderIndex);
|
|
|
|
emit endRemoveRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::handleDataChanged(const QModelIndex &start, const QModelIndex &end)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (start.parent() == d->folderIndex)
|
|
|
|
emit dataChanged(index(start.row(),0), index(end.row(),0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\qmlproperty bool FolderListModel::showDirs
|
|
|
|
|
|
|
|
If true, directories are included in the model; otherwise only files
|
|
|
|
are included.
|
|
|
|
|
|
|
|
By default, this property is true.
|
|
|
|
|
|
|
|
Note that the nameFilters are not applied to directories.
|
|
|
|
|
|
|
|
\sa showDotAndDotDot
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQuickFolderListModel::showDirs() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
return d->model.filter() & QDir::AllDirs;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::setShowDirs(bool on)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (!(d->model.filter() & QDir::AllDirs) == !on)
|
|
|
|
return;
|
2011-05-23 05:38:53 +00:00
|
|
|
if (on) {
|
|
|
|
d->showDirs = true;
|
2011-04-27 10:05:43 +00:00
|
|
|
d->model.setFilter(d->model.filter() | QDir::AllDirs | QDir::Drives);
|
2011-05-23 05:38:53 +00:00
|
|
|
} else {
|
|
|
|
d->showDirs = false;
|
2011-04-27 10:05:43 +00:00
|
|
|
d->model.setFilter(d->model.filter() & ~(QDir::AllDirs | QDir::Drives));
|
2011-05-23 05:38:53 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\qmlproperty bool FolderListModel::showDotAndDotDot
|
|
|
|
|
|
|
|
If true, the "." and ".." directories are included in the model; otherwise
|
|
|
|
they are excluded.
|
|
|
|
|
|
|
|
By default, this property is false.
|
|
|
|
|
|
|
|
\sa showDirs
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQuickFolderListModel::showDotAndDotDot() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
return !(d->model.filter() & QDir::NoDotAndDotDot);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::setShowDotAndDotDot(bool on)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (!(d->model.filter() & QDir::NoDotAndDotDot) == on)
|
|
|
|
return;
|
2011-05-23 05:38:53 +00:00
|
|
|
if (on) {
|
|
|
|
d->showDots = true;
|
2011-04-27 10:05:43 +00:00
|
|
|
d->model.setFilter(d->model.filter() & ~QDir::NoDotAndDotDot);
|
2011-05-23 05:38:53 +00:00
|
|
|
} else {
|
|
|
|
d->showDots = false;
|
2011-04-27 10:05:43 +00:00
|
|
|
d->model.setFilter(d->model.filter() | QDir::NoDotAndDotDot);
|
2011-05-23 05:38:53 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\qmlproperty bool FolderListModel::showOnlyReadable
|
|
|
|
|
|
|
|
If true, only readable files and directories are shown; otherwise all files
|
|
|
|
and directories are shown.
|
|
|
|
|
|
|
|
By default, this property is false.
|
|
|
|
|
|
|
|
\sa showDirs
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQuickFolderListModel::showOnlyReadable() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
return d->model.filter() & QDir::Readable;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickFolderListModel::setShowOnlyReadable(bool on)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (!(d->model.filter() & QDir::Readable) == !on)
|
|
|
|
return;
|
2011-05-23 05:38:53 +00:00
|
|
|
if (on) {
|
|
|
|
d->showOnlyReadable = true;
|
2011-04-27 10:05:43 +00:00
|
|
|
d->model.setFilter(d->model.filter() | QDir::Readable);
|
2011-05-23 05:38:53 +00:00
|
|
|
} else {
|
|
|
|
d->showOnlyReadable = false;
|
2011-04-27 10:05:43 +00:00
|
|
|
d->model.setFilter(d->model.filter() & ~QDir::Readable);
|
2011-05-23 05:38:53 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//![code]
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
#endif // QT_NO_DIRMODEL
|