qdirmodel.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 QDIRMODEL_H
00043 #define QDIRMODEL_H
00044 
00045 #include <QtCore/qabstractitemmodel.h>
00046 #include <QtCore/qdir.h>
00047 #include <QtGui/qfileiconprovider.h>
00048 
00049 QT_BEGIN_HEADER
00050 
00051 QT_BEGIN_NAMESPACE
00052 
00053 QT_MODULE(Gui)
00054 
00055 #ifndef QT_NO_DIRMODEL
00056 
00057 class QDirModelPrivate;
00058 
00059 class Q_GUI_EXPORT QDirModel : public QAbstractItemModel
00060 {
00061     Q_OBJECT
00062     Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks)
00063     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
00064     Q_PROPERTY(bool lazyChildCount READ lazyChildCount WRITE setLazyChildCount)
00065 
00066 public:
00067     enum Roles {
00068         FileIconRole = Qt::DecorationRole,
00069         FilePathRole = Qt::UserRole + 1,
00070         FileNameRole
00071     };
00072 
00073     QDirModel(const QStringList &nameFilters, QDir::Filters filters,
00074               QDir::SortFlags sort, QObject *parent = 0);
00075     explicit QDirModel(QObject *parent = 0);
00076     ~QDirModel();
00077 
00078     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
00079     QModelIndex parent(const QModelIndex &child) const;
00080 
00081     int rowCount(const QModelIndex &parent = QModelIndex()) const;
00082     int columnCount(const QModelIndex &parent = QModelIndex()) const;
00083 
00084     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00085     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00086 
00087     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00088 
00089     bool hasChildren(const QModelIndex &index = QModelIndex()) const;
00090     Qt::ItemFlags flags(const QModelIndex &index) const;
00091 
00092     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
00093 
00094     QStringList mimeTypes() const;
00095     QMimeData *mimeData(const QModelIndexList &indexes) const;
00096     bool dropMimeData(const QMimeData *data, Qt::DropAction action,
00097                       int row, int column, const QModelIndex &parent);
00098     Qt::DropActions supportedDropActions() const;
00099 
00100     // QDirModel specific API
00101 
00102     void setIconProvider(QFileIconProvider *provider);
00103     QFileIconProvider *iconProvider() const;
00104 
00105     void setNameFilters(const QStringList &filters);
00106     QStringList nameFilters() const;
00107 
00108     void setFilter(QDir::Filters filters);
00109     QDir::Filters filter() const;
00110 
00111     void setSorting(QDir::SortFlags sort);
00112     QDir::SortFlags sorting() const;
00113 
00114     void setResolveSymlinks(bool enable);
00115     bool resolveSymlinks() const;
00116 
00117     void setReadOnly(bool enable);
00118     bool isReadOnly() const;
00119 
00120     void setLazyChildCount(bool enable);
00121     bool lazyChildCount() const;
00122 
00123     QModelIndex index(const QString &path, int column = 0) const;
00124 
00125     bool isDir(const QModelIndex &index) const;
00126     QModelIndex mkdir(const QModelIndex &parent, const QString &name);
00127     bool rmdir(const QModelIndex &index);
00128     bool remove(const QModelIndex &index);
00129 
00130     QString filePath(const QModelIndex &index) const;
00131     QString fileName(const QModelIndex &index) const;
00132     QIcon fileIcon(const QModelIndex &index) const;
00133     QFileInfo fileInfo(const QModelIndex &index) const;
00134 
00135 #ifdef Q_NO_USING_KEYWORD
00136     inline QObject *parent() const { return QObject::parent(); }
00137 #else
00138     using QObject::parent;
00139 #endif
00140 
00141 public Q_SLOTS:
00142     void refresh(const QModelIndex &parent = QModelIndex());
00143 
00144 protected:
00145     QDirModel(QDirModelPrivate &, QObject *parent = 0);
00146     friend class QFileDialogPrivate;
00147 
00148 private:
00149     Q_DECLARE_PRIVATE(QDirModel)
00150     Q_DISABLE_COPY(QDirModel)
00151     Q_PRIVATE_SLOT(d_func(), void _q_refresh())
00152 };
00153 
00154 #endif // QT_NO_DIRMODEL
00155 
00156 QT_END_NAMESPACE
00157 
00158 QT_END_HEADER
00159 
00160 #endif // QDIRMODEL_H