** 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.
+** 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
+** 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.
-**
-**
+** 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.
**
**
**
{
public:
QDeclarativeFolderListModelPrivate()
- : sortField(QDeclarativeFolderListModel::Name), sortReversed(false), count(0) {
+ : sortField(QDeclarativeFolderListModel::Name), sortReversed(false), count(0), showDirs(true), showDots(false), showOnlyReadable(false), insideRefresh(false) {
nameFilters << QLatin1String("*");
}
QDeclarativeFolderListModel::SortField sortField;
bool sortReversed;
int count;
+ bool showDirs;
+ bool showDots;
+ bool showOnlyReadable;
+ bool insideRefresh;
};
/*!
{
if (folder == d->folder)
return;
- QModelIndex index = d->model.index(folder.toLocalFile());
- if ((index.isValid() && d->model.isDir(index)) || folder.toLocalFile().isEmpty()) {
+ QModelIndex index = d->model.index(folder.toLocalFile()); // This can modify the filtering rules.
+ if ((index.isValid() && d->model.isDir(index)) || folder.toLocalFile().isEmpty()) {
d->folder = folder;
- QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(this, "resetFiltering", Qt::QueuedConnection); // resetFiltering will invoke refresh().
emit folderChanged();
}
}
+void QDeclarativeFolderListModel::resetFiltering()
+{
+ // 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().
+}
+
/*!
\qmlproperty url FolderListModel::parentFolder
QString localFile = d->folder.toLocalFile();
if (!localFile.isEmpty()) {
QDir dir(localFile);
-#if defined(Q_OS_SYMBIAN) || defined(Q_OS_WIN)
+#if defined(Q_OS_WIN)
if (dir.isRoot())
dir.setPath("");
else
void QDeclarativeFolderListModel::refresh()
{
+ if (d->insideRefresh)
+ return;
+ d->insideRefresh = true;
+
d->folderIndex = QModelIndex();
if (d->count) {
emit beginRemoveRows(QModelIndex(), 0, d->count-1);
d->count = 0;
emit endRemoveRows();
}
+
d->folderIndex = d->model.index(d->folder.toLocalFile());
int newcount = d->model.rowCount(d->folderIndex);
if (newcount) {
d->count = newcount;
emit endInsertRows();
}
+
+ d->insideRefresh = false; // finished refreshing.
}
void QDeclarativeFolderListModel::inserted(const QModelIndex &index, int start, int end)
{
if (!(d->model.filter() & QDir::AllDirs) == !on)
return;
- if (on)
+ if (on) {
+ d->showDirs = true;
d->model.setFilter(d->model.filter() | QDir::AllDirs | QDir::Drives);
- else
+ } else {
+ d->showDirs = false;
d->model.setFilter(d->model.filter() & ~(QDir::AllDirs | QDir::Drives));
+ }
}
/*!
{
if (!(d->model.filter() & QDir::NoDotAndDotDot) == on)
return;
- if (on)
+ if (on) {
+ d->showDots = true;
d->model.setFilter(d->model.filter() & ~QDir::NoDotAndDotDot);
- else
+ } else {
+ d->showDots = false;
d->model.setFilter(d->model.filter() | QDir::NoDotAndDotDot);
+ }
}
/*!
{
if (!(d->model.filter() & QDir::Readable) == !on)
return;
- if (on)
+ if (on) {
+ d->showOnlyReadable = true;
d->model.setFilter(d->model.filter() | QDir::Readable);
- else
+ } else {
+ d->showOnlyReadable = false;
d->model.setFilter(d->model.filter() & ~QDir::Readable);
+ }
}
//![code]