source: trunk/src/gui/dialogs/qfilesystemmodel.h@ 642

Last change on this file since 642 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 6.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QFILESYSTEMMODEL_H
43#define QFILESYSTEMMODEL_H
44
45#include <QtCore/qabstractitemmodel.h>
46#include <QtCore/qpair.h>
47#include <QtCore/qdir.h>
48#include <QtGui/qicon.h>
49#include <QtCore/qdiriterator.h>
50
51QT_BEGIN_HEADER
52
53QT_BEGIN_NAMESPACE
54
55QT_MODULE(Gui)
56
57#ifndef QT_NO_FILESYSTEMMODEL
58
59class ExtendedInformation;
60class QFileSystemModelPrivate;
61class QFileIconProvider;
62
63class Q_GUI_EXPORT QFileSystemModel : public QAbstractItemModel
64{
65 Q_OBJECT
66 Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks)
67 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
68 Q_PROPERTY(bool nameFilterDisables READ nameFilterDisables WRITE setNameFilterDisables)
69
70Q_SIGNALS:
71 void rootPathChanged(const QString &newPath);
72 void fileRenamed(const QString &path, const QString &oldName, const QString &newName);
73
74public:
75 enum Roles {
76 FileIconRole = Qt::DecorationRole,
77 FilePathRole = Qt::UserRole + 1,
78 FileNameRole = Qt::UserRole + 2,
79 FilePermissions = Qt::UserRole + 3
80 };
81
82 explicit QFileSystemModel(QObject *parent = 0);
83 ~QFileSystemModel();
84
85 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
86 QModelIndex index(const QString &path, int column = 0) const;
87 QModelIndex parent(const QModelIndex &child) const;
88 bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
89 bool canFetchMore(const QModelIndex &parent) const;
90 void fetchMore(const QModelIndex &parent);
91
92 int rowCount(const QModelIndex &parent = QModelIndex()) const;
93 int columnCount(const QModelIndex &parent = QModelIndex()) const;
94
95 QVariant myComputer(int role = Qt::DisplayRole) const;
96 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
97 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
98
99 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
100
101 Qt::ItemFlags flags(const QModelIndex &index) const;
102
103 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
104
105 QStringList mimeTypes() const;
106 QMimeData *mimeData(const QModelIndexList &indexes) const;
107 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
108 int row, int column, const QModelIndex &parent);
109 Qt::DropActions supportedDropActions() const;
110
111 // QFileSystemModel specific API
112 QModelIndex setRootPath(const QString &path);
113 QString rootPath() const;
114 QDir rootDirectory() const;
115
116 void setIconProvider(QFileIconProvider *provider);
117 QFileIconProvider *iconProvider() const;
118
119 void setFilter(QDir::Filters filters);
120 QDir::Filters filter() const;
121
122 void setResolveSymlinks(bool enable);
123 bool resolveSymlinks() const;
124
125 void setReadOnly(bool enable);
126 bool isReadOnly() const;
127
128 void setNameFilterDisables(bool enable);
129 bool nameFilterDisables() const;
130
131 void setNameFilters(const QStringList &filters);
132 QStringList nameFilters() const;
133
134 QString filePath(const QModelIndex &index) const;
135 bool isDir(const QModelIndex &index) const;
136 qint64 size(const QModelIndex &index) const;
137 QString type(const QModelIndex &index) const;
138 QDateTime lastModified(const QModelIndex &index) const;
139
140 QModelIndex mkdir(const QModelIndex &parent, const QString &name);
141 inline bool rmdir(const QModelIndex &index) const;
142 inline QString fileName(const QModelIndex &index) const;
143 inline QIcon fileIcon(const QModelIndex &index) const;
144 QFile::Permissions permissions(const QModelIndex &index) const;
145 inline QFileInfo fileInfo(const QModelIndex &index) const;
146 bool remove(const QModelIndex &index) const;
147
148protected:
149 QFileSystemModel(QFileSystemModelPrivate &, QObject *parent = 0);
150 void timerEvent(QTimerEvent *event);
151 bool event(QEvent *event);
152
153private:
154 Q_DECLARE_PRIVATE(QFileSystemModel)
155 Q_DISABLE_COPY(QFileSystemModel)
156
157 Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QStringList &list))
158 Q_PRIVATE_SLOT(d_func(), void _q_performDelayedSort())
159 Q_PRIVATE_SLOT(d_func(), void _q_fileSystemChanged(const QString &path, const QList<QPair<QString, QFileInfo> > &))
160 Q_PRIVATE_SLOT(d_func(), void _q_resolvedName(const QString &fileName, const QString &resolvedName))
161
162 friend class QFileDialogPrivate;
163};
164
165inline bool QFileSystemModel::rmdir(const QModelIndex &aindex) const
166{ QDir dir; return dir.rmdir(filePath(aindex)); }
167inline QString QFileSystemModel::fileName(const QModelIndex &aindex) const
168{ return aindex.data(Qt::DisplayRole).toString(); }
169inline QIcon QFileSystemModel::fileIcon(const QModelIndex &aindex) const
170{ return qvariant_cast<QIcon>(aindex.data(Qt::DecorationRole)); }
171inline QFileInfo QFileSystemModel::fileInfo(const QModelIndex &aindex) const
172{ return QFileInfo(filePath(aindex)); }
173
174#endif // QT_NO_FILESYSTEMMODEL
175
176QT_END_NAMESPACE
177
178QT_END_HEADER
179
180#endif // QFILESYSTEMMODEL_H
181
Note: See TracBrowser for help on using the repository browser.