qfilesystemmodel.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QFILESYSTEMMODEL_H
00043 #define QFILESYSTEMMODEL_H
00044 
00045 #include <QtCore/qabstractitemmodel.h>
00046 #include <QtCore/qpair.h>
00047 #include <QtCore/qdir.h>
00048 #include <QtGui/qicon.h>
00049 #include <QtCore/qdiriterator.h>
00050 
00051 QT_BEGIN_HEADER
00052 
00053 QT_BEGIN_NAMESPACE
00054 
00055 QT_MODULE(Gui)
00056 
00057 #ifndef QT_NO_FILESYSTEMMODEL
00058 
00059 class ExtendedInformation;
00060 class QFileSystemModelPrivate;
00061 class QFileIconProvider;
00062 
00063 class Q_GUI_EXPORT QFileSystemModel : public QAbstractItemModel
00064 {
00065     Q_OBJECT
00066     Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks)
00067     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
00068     Q_PROPERTY(bool nameFilterDisables READ nameFilterDisables WRITE setNameFilterDisables)
00069 
00070 Q_SIGNALS:
00071     void rootPathChanged(const QString &newPath);
00072     void fileRenamed(const QString &path, const QString &oldName, const QString &newName);
00073     void directoryLoaded(const QString &path);
00074 
00075 public:
00076     enum Roles {
00077         FileIconRole = Qt::DecorationRole,
00078         FilePathRole = Qt::UserRole + 1,
00079         FileNameRole = Qt::UserRole + 2,
00080         FilePermissions = Qt::UserRole + 3
00081     };
00082 
00083     explicit QFileSystemModel(QObject *parent = 0);
00084     ~QFileSystemModel();
00085 
00086     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
00087     QModelIndex index(const QString &path, int column = 0) const;
00088     QModelIndex parent(const QModelIndex &child) const;
00089     bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
00090     bool canFetchMore(const QModelIndex &parent) const;
00091     void fetchMore(const QModelIndex &parent);
00092 
00093     int rowCount(const QModelIndex &parent = QModelIndex()) const;
00094     int columnCount(const QModelIndex &parent = QModelIndex()) const;
00095 
00096     QVariant myComputer(int role = Qt::DisplayRole) const;
00097     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00098     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00099 
00100     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00101 
00102     Qt::ItemFlags flags(const QModelIndex &index) const;
00103 
00104     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
00105 
00106     QStringList mimeTypes() const;
00107     QMimeData *mimeData(const QModelIndexList &indexes) const;
00108     bool dropMimeData(const QMimeData *data, Qt::DropAction action,
00109                       int row, int column, const QModelIndex &parent);
00110     Qt::DropActions supportedDropActions() const;
00111 
00112     // QFileSystemModel specific API
00113     QModelIndex setRootPath(const QString &path);
00114     QString rootPath() const;
00115     QDir rootDirectory() const;
00116 
00117     void setIconProvider(QFileIconProvider *provider);
00118     QFileIconProvider *iconProvider() const;
00119 
00120     void setFilter(QDir::Filters filters);
00121     QDir::Filters filter() const;
00122 
00123     void setResolveSymlinks(bool enable);
00124     bool resolveSymlinks() const;
00125 
00126     void setReadOnly(bool enable);
00127     bool isReadOnly() const;
00128 
00129     void setNameFilterDisables(bool enable);
00130     bool nameFilterDisables() const;
00131 
00132     void setNameFilters(const QStringList &filters);
00133     QStringList nameFilters() const;
00134 
00135     QString filePath(const QModelIndex &index) const;
00136     bool isDir(const QModelIndex &index) const;
00137     qint64 size(const QModelIndex &index) const;
00138     QString type(const QModelIndex &index) const;
00139     QDateTime lastModified(const QModelIndex &index) const;
00140 
00141     QModelIndex mkdir(const QModelIndex &parent, const QString &name);
00142     inline bool rmdir(const QModelIndex &index) const;
00143     inline QString fileName(const QModelIndex &index) const;
00144     inline QIcon fileIcon(const QModelIndex &index) const;
00145     QFile::Permissions permissions(const QModelIndex &index) const;
00146     inline QFileInfo fileInfo(const QModelIndex &index) const;
00147     bool remove(const QModelIndex &index) const;
00148 
00149 protected:
00150     QFileSystemModel(QFileSystemModelPrivate &, QObject *parent = 0);
00151     void timerEvent(QTimerEvent *event);
00152     bool event(QEvent *event);
00153 
00154 private:
00155     Q_DECLARE_PRIVATE(QFileSystemModel)
00156     Q_DISABLE_COPY(QFileSystemModel)
00157 
00158     Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QStringList &list))
00159     Q_PRIVATE_SLOT(d_func(), void _q_performDelayedSort())
00160     Q_PRIVATE_SLOT(d_func(), void _q_fileSystemChanged(const QString &path, const QList<QPair<QString, QFileInfo> > &))
00161     Q_PRIVATE_SLOT(d_func(), void _q_resolvedName(const QString &fileName, const QString &resolvedName))
00162 
00163     friend class QFileDialogPrivate;
00164 };
00165 
00166 inline bool QFileSystemModel::rmdir(const QModelIndex &aindex) const
00167 { QDir dir; return dir.rmdir(filePath(aindex)); }
00168 inline QString QFileSystemModel::fileName(const QModelIndex &aindex) const
00169 { return aindex.data(Qt::DisplayRole).toString(); }
00170 inline QIcon QFileSystemModel::fileIcon(const QModelIndex &aindex) const
00171 { return qvariant_cast<QIcon>(aindex.data(Qt::DecorationRole)); }
00172 inline QFileInfo QFileSystemModel::fileInfo(const QModelIndex &aindex) const
00173 { return QFileInfo(filePath(aindex)); }
00174 
00175 #endif // QT_NO_FILESYSTEMMODEL
00176 
00177 QT_END_NAMESPACE
00178 
00179 QT_END_HEADER
00180 
00181 #endif // QFILESYSTEMMODEL_H
00182