summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-10-21 01:37:56 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-10-21 01:37:56 (GMT)
commitc2aa20e6eda3654022976db2b1abbf23f9abbcfb (patch)
tree8f7d8b737dc3f5bf02c435d27d5849b505c3b253 /src
parentbb10e8d5570865b6fb1c4c7460600f92ea9f9844 (diff)
downloadQt-c2aa20e6eda3654022976db2b1abbf23f9abbcfb.zip
Qt-c2aa20e6eda3654022976db2b1abbf23f9abbcfb.tar.gz
Qt-c2aa20e6eda3654022976db2b1abbf23f9abbcfb.tar.bz2
Move QmlFolderListModel to the loader example.
Diffstat (limited to 'src')
-rw-r--r--src/declarative/extra/extra.pri2
-rw-r--r--src/declarative/extra/qmlfolderlistmodel.cpp413
-rw-r--r--src/declarative/extra/qmlfolderlistmodel.h128
3 files changed, 0 insertions, 543 deletions
diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri
index 6730550..726f099 100644
--- a/src/declarative/extra/extra.pri
+++ b/src/declarative/extra/extra.pri
@@ -3,7 +3,6 @@ SOURCES += \
extra/qmlnumberformatter.cpp \
extra/qmldatetimeformatter.cpp \
extra/qfxintegermodel.cpp \
- extra/qmlfolderlistmodel.cpp \
extra/qfxanimatedimageitem.cpp \
extra/qfxparticles.cpp \
extra/qmlbehavior.cpp \
@@ -15,7 +14,6 @@ HEADERS += \
extra/qmlnumberformatter.h \
extra/qmldatetimeformatter.h \
extra/qfxintegermodel.h \
- extra/qmlfolderlistmodel.h \
extra/qfxanimatedimageitem.h \
extra/qfxanimatedimageitem_p.h \
extra/qfxparticles.h \
diff --git a/src/declarative/extra/qmlfolderlistmodel.cpp b/src/declarative/extra/qmlfolderlistmodel.cpp
deleted file mode 100644
index 0e5c275..0000000
--- a/src/declarative/extra/qmlfolderlistmodel.cpp
+++ /dev/null
@@ -1,413 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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 either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** 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.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "private/qobject_p.h"
-#include <QDirModel>
-#include <qdebug.h>
-#include "qmlfolderlistmodel.h"
-#include <QtDeclarative/qmlcontext.h>
-
-QT_BEGIN_NAMESPACE
-
-class QmlFolderListModelPrivate : public QObjectPrivate
-{
-public:
- QmlFolderListModelPrivate()
- : sortField(QmlFolderListModel::Name), sortReversed(false), count(0) {
- nameFilters << QLatin1String("*");
- }
-
- void updateSorting() {
- QDir::SortFlags flags = 0;
- switch(sortField) {
- case QmlFolderListModel::Unsorted:
- flags |= QDir::Unsorted;
- break;
- case QmlFolderListModel::Name:
- flags |= QDir::Name;
- break;
- case QmlFolderListModel::Time:
- flags |= QDir::Time;
- break;
- case QmlFolderListModel::Size:
- flags |= QDir::Size;
- break;
- case QmlFolderListModel::Type:
- flags |= QDir::Type;
- break;
- }
-
- if (sortReversed)
- flags |= QDir::Reversed;
-
- model.setSorting(flags);
- }
-
- QDirModel model;
- QUrl folder;
- QStringList nameFilters;
- QModelIndex folderIndex;
- QmlFolderListModel::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.
-*/
-
-QmlFolderListModel::QmlFolderListModel(QObject *parent)
- : QListModelInterface(*(new QmlFolderListModelPrivate), parent)
-{
- Q_D(QmlFolderListModel);
- 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()));
-}
-
-QmlFolderListModel::~QmlFolderListModel()
-{
-}
-
-QHash<int,QVariant> QmlFolderListModel::data(int index, const QList<int> &roles) const
-{
- Q_UNUSED(roles);
- Q_D(const QmlFolderListModel);
- QHash<int,QVariant> 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;
-}
-
-int QmlFolderListModel::count() const
-{
- Q_D(const QmlFolderListModel);
- return d->count;
-}
-
-QList<int> QmlFolderListModel::roles() const
-{
- QList<int> r;
- r << QDirModel::FileNameRole;
- r << QDirModel::FilePathRole;
- return r;
-}
-
-QString QmlFolderListModel::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 QmlFolderListModel::folder() const
-{
- Q_D(const QmlFolderListModel);
- return d->folder;
-}
-
-void QmlFolderListModel::setFolder(const QUrl &folder)
-{
- Q_D(QmlFolderListModel);
- 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 QmlFolderListModel::parentFolder() const
-{
- Q_D(const QmlFolderListModel);
- int pos = d->folder.path().lastIndexOf(QLatin1Char('/'));
- if (pos == -1)
- return QUrl();
- QUrl r = d->folder;
- r.setPath(d->folder.path().left(pos));
- return r;
-}
-
-/*!
- \qmlproperty list<string> 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 QmlFolderListModel::nameFilters() const
-{
- Q_D(const QmlFolderListModel);
- return d->nameFilters;
-}
-
-void QmlFolderListModel::setNameFilters(const QStringList &filters)
-{
- Q_D(QmlFolderListModel);
- d->nameFilters = filters;
- d->model.setNameFilters(d->nameFilters);
-}
-
-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);
-}
-
-QmlFolderListModel::SortField QmlFolderListModel::sortField() const
-{
- Q_D(const QmlFolderListModel);
- return d->sortField;
-}
-
-void QmlFolderListModel::setSortField(SortField field)
-{
- Q_D(QmlFolderListModel);
- if (field != d->sortField) {
- d->sortField = field;
- d->updateSorting();
- }
-}
-
-bool QmlFolderListModel::sortReversed() const
-{
- Q_D(const QmlFolderListModel);
- return d->sortReversed;
-}
-
-void QmlFolderListModel::setSortReversed(bool rev)
-{
- Q_D(QmlFolderListModel);
- 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 QmlFolderListModel::isFolder(int index) const
-{
- Q_D(const QmlFolderListModel);
- if (index != -1) {
- QModelIndex idx = d->model.index(index, 0, d->folderIndex);
- if (idx.isValid())
- return d->model.isDir(idx);
- }
- return false;
-}
-
-void QmlFolderListModel::refresh()
-{
- Q_D(QmlFolderListModel);
- 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 QmlFolderListModel::inserted(const QModelIndex &index, int start, int end)
-{
- Q_D(QmlFolderListModel);
- if (index == d->folderIndex) {
- d->count = d->model.rowCount(d->folderIndex);
- emit itemsInserted(start, end - start + 1);
- }
-}
-
-void QmlFolderListModel::removed(const QModelIndex &index, int start, int end)
-{
- Q_D(QmlFolderListModel);
- if (index == d->folderIndex) {
- d->count = d->model.rowCount(d->folderIndex);
- emit itemsRemoved(start, end - start + 1);
- }
-}
-
-void QmlFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end)
-{
- Q_D(QmlFolderListModel);
- qDebug() << "data changed";
- 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 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
deleted file mode 100644
index 66e600b..0000000
--- a/src/declarative/extra/qmlfolderlistmodel.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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 either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** 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.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMLFOLDERLISTMODEL_H
-#define QMLFOLDERLISTMODEL_H
-
-#include <QtDeclarative/qml.h>
-#include <QtDeclarative/QListModelInterface>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class QmlContext;
-class QModelIndex;
-
-class QmlFolderListModelPrivate;
-class Q_DECLARATIVE_EXPORT QmlFolderListModel : public QListModelInterface, public QmlParserStatus
-{
- Q_OBJECT
- Q_INTERFACES(QmlParserStatus)
-
- 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:
- QmlFolderListModel(QObject *parent = 0);
- ~QmlFolderListModel();
-
- virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const;
- virtual int count() const;
- virtual QList<int> 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 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_DECLARE_PRIVATE(QmlFolderListModel)
- Q_DISABLE_COPY(QmlFolderListModel)
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QmlFolderListModel)
-
-QT_END_HEADER
-
-#endif // QMLFOLDERLISTMODEL_H