Qt 4.8
qfiledialog.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QFILEDIALOG_H
43 #define QFILEDIALOG_H
44 
45 #include <QtCore/qdir.h>
46 #include <QtCore/qstring.h>
47 #include <QtGui/qdialog.h>
48 
50 
52 
53 QT_MODULE(Gui)
54 
55 #ifndef QT_NO_FILEDIALOG
56 
57 class QModelIndex;
58 class QItemSelection;
59 struct QFileDialogArgs;
60 class QFileIconProvider;
61 class QFileDialogPrivate;
64 class QUrl;
65 
67 {
68  Q_OBJECT
70  Q_FLAGS(Options)
71  ViewMode viewMode;
72  FileMode fileMode;
73  AcceptMode acceptMode;
74  bool readOnly;
75  bool resolveSymlinks;
76  bool confirmOverwrite;
77  QString defaultSuffix;
78  bool nameFilterDetailsVisible;
79  Options options;
80 
81 public:
82  enum ViewMode { Detail, List };
83  enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
84  enum AcceptMode { AcceptOpen, AcceptSave };
85  enum DialogLabel { LookIn, FileName, FileType, Accept, Reject };
86 
87  // ### Rename to FileDialogOption and FileDialogOptions for Qt 5.0
88  enum Option
89  {
90  ShowDirsOnly = 0x00000001,
91  DontResolveSymlinks = 0x00000002,
92  DontConfirmOverwrite = 0x00000004,
93  DontUseSheet = 0x00000008,
94  DontUseNativeDialog = 0x00000010,
95  ReadOnly = 0x00000020,
96  HideNameFilterDetails = 0x00000040,
97  DontUseCustomDirectoryIcons = 0x00000080
98  };
99  Q_DECLARE_FLAGS(Options, Option)
100 
101  QFileDialog(QWidget *parent, Qt::WindowFlags f);
102  explicit QFileDialog(QWidget *parent = 0,
103  const QString &caption = QString(),
104  const QString &directory = QString(),
105  const QString &filter = QString());
106  ~QFileDialog();
107 
108  void setDirectory(const QString &directory);
109  inline void setDirectory(const QDir &directory);
110  QDir directory() const;
111 
112  void selectFile(const QString &filename);
113  QStringList selectedFiles() const;
114 
115 #ifdef QT_DEPRECATED
116  QT_DEPRECATED void setFilter(const QString &filter);
117  QT_DEPRECATED void setFilters(const QStringList &filters);
119  QT_DEPRECATED void selectFilter(const QString &filter);
120  QT_DEPRECATED QString selectedFilter() const;
121 #endif
122  void setNameFilterDetailsVisible(bool enabled);
123  bool isNameFilterDetailsVisible() const;
124 
125  void setNameFilter(const QString &filter);
126  void setNameFilters(const QStringList &filters);
127  QStringList nameFilters() const;
128  void selectNameFilter(const QString &filter);
129  QString selectedNameFilter() const;
130 
131  QDir::Filters filter() const;
132  void setFilter(QDir::Filters filters);
133 
134  void setViewMode(ViewMode mode);
135  ViewMode viewMode() const;
136 
137  void setFileMode(FileMode mode);
138  FileMode fileMode() const;
139 
140  void setAcceptMode(AcceptMode mode);
141  AcceptMode acceptMode() const;
142 
143  void setReadOnly(bool enabled);
144  bool isReadOnly() const;
145 
146  void setResolveSymlinks(bool enabled);
147  bool resolveSymlinks() const;
148 
149  void setSidebarUrls(const QList<QUrl> &urls);
150  QList<QUrl> sidebarUrls() const;
151 
152  QByteArray saveState() const;
153  bool restoreState(const QByteArray &state);
154 
155  void setConfirmOverwrite(bool enabled);
156  bool confirmOverwrite() const;
157 
158  void setDefaultSuffix(const QString &suffix);
159  QString defaultSuffix() const;
160 
161  void setHistory(const QStringList &paths);
162  QStringList history() const;
163 
164  void setItemDelegate(QAbstractItemDelegate *delegate);
165  QAbstractItemDelegate *itemDelegate() const;
166 
167  void setIconProvider(QFileIconProvider *provider);
168  QFileIconProvider *iconProvider() const;
169 
170  void setLabelText(DialogLabel label, const QString &text);
171  QString labelText(DialogLabel label) const;
172 
173 #ifndef QT_NO_PROXYMODEL
174  void setProxyModel(QAbstractProxyModel *model);
175  QAbstractProxyModel *proxyModel() const;
176 #endif
177 
178  void setOption(Option option, bool on = true);
179  bool testOption(Option option) const;
180  void setOptions(Options options);
181  Options options() const;
182 
183 #ifdef Q_NO_USING_KEYWORD
184 #ifndef Q_QDOC
185  void open() { QDialog::open(); }
186 #endif
187 #else
188  using QDialog::open;
189 #endif
190  void open(QObject *receiver, const char *member);
191  void setVisible(bool visible);
192 
193 Q_SIGNALS:
194  void fileSelected(const QString &file);
195  void filesSelected(const QStringList &files);
196  void currentChanged(const QString &path);
197  void directoryEntered(const QString &directory);
198  void filterSelected(const QString &filter);
199 
200 public:
201 #ifdef QT3_SUPPORT
202  typedef FileMode Mode;
203  inline QT3_SUPPORT void setMode(FileMode m) { setFileMode(m); }
204  inline QT3_SUPPORT FileMode mode() const { return fileMode(); }
205  inline QT3_SUPPORT void setDir(const QString &directory) { setDirectory(directory); }
206  inline QT3_SUPPORT void setDir( const QDir &directory ) { setDirectory(directory); }
207  QT3_SUPPORT QString selectedFile() const;
208 #endif
209 
210  static QString getOpenFileName(QWidget *parent = 0,
211  const QString &caption = QString(),
212  const QString &dir = QString(),
213  const QString &filter = QString(),
214  QString *selectedFilter = 0,
215  Options options = 0);
216 
217  static QString getSaveFileName(QWidget *parent = 0,
218  const QString &caption = QString(),
219  const QString &dir = QString(),
220  const QString &filter = QString(),
221  QString *selectedFilter = 0,
222  Options options = 0);
223 
224  static QString getExistingDirectory(QWidget *parent = 0,
225  const QString &caption = QString(),
226  const QString &dir = QString(),
227  Options options = ShowDirsOnly);
228 
229  static QStringList getOpenFileNames(QWidget *parent = 0,
230  const QString &caption = QString(),
231  const QString &dir = QString(),
232  const QString &filter = QString(),
233  QString *selectedFilter = 0,
234  Options options = 0);
235 
236 #ifdef QT3_SUPPORT
237  inline static QString QT3_SUPPORT getOpenFileName(const QString &dir,
238  const QString &filter = QString(),
239  QWidget *parent = 0, const char* name = 0,
240  const QString &caption = QString(),
241  QString *selectedFilter = 0,
242  bool resolveSymlinks = true)
243  { Q_UNUSED(name);
244  return getOpenFileName(parent, caption, dir, filter, selectedFilter,
245  resolveSymlinks ? Option(0) : DontResolveSymlinks); }
246 
247  inline static QString QT3_SUPPORT getSaveFileName(const QString &dir,
248  const QString &filter = QString(),
249  QWidget *parent = 0, const char* name = 0,
250  const QString &caption = QString(),
251  QString *selectedFilter = 0,
252  bool resolveSymlinks = true)
253  { Q_UNUSED(name);
254  return getSaveFileName(parent, caption, dir, filter, selectedFilter,
255  resolveSymlinks ? Option(0) : DontResolveSymlinks); }
256 
257  inline static QString QT3_SUPPORT getExistingDirectory(const QString &dir,
258  QWidget *parent = 0,
259  const char* name = 0,
260  const QString &caption = QString(),
261  bool dirOnly = true,
262  bool resolveSymlinks = true)
263  { Q_UNUSED(name);
264  return getExistingDirectory(parent, caption, dir,
265  Options((resolveSymlinks ? Option(0) : DontResolveSymlinks)
266  | (dirOnly ? ShowDirsOnly : Option(0)))); }
267 
268  inline static QStringList QT3_SUPPORT getOpenFileNames(const QString &filter,
269  const QString &dir = QString(),
270  QWidget *parent = 0,
271  const char* name = 0,
272  const QString &caption = QString(),
273  QString *selectedFilter = 0,
274  bool resolveSymlinks = true)
275  { Q_UNUSED(name);
276  return getOpenFileNames(parent, caption, dir, filter, selectedFilter,
277  resolveSymlinks ? Option(0) : DontResolveSymlinks); }
278 #endif // QT3_SUPPORT
279 
280 protected:
281  QFileDialog(const QFileDialogArgs &args);
282  void done(int result);
283  void accept();
284  void changeEvent(QEvent *e);
285 
286 private:
289 
290  Q_PRIVATE_SLOT(d_func(), void _q_pathChanged(const QString &))
291 
292  Q_PRIVATE_SLOT(d_func(), void _q_navigateBackward())
293  Q_PRIVATE_SLOT(d_func(), void _q_navigateForward())
294  Q_PRIVATE_SLOT(d_func(), void _q_navigateToParent())
295  Q_PRIVATE_SLOT(d_func(), void _q_createDirectory())
296  Q_PRIVATE_SLOT(d_func(), void _q_showListView())
297  Q_PRIVATE_SLOT(d_func(), void _q_showDetailsView())
298  Q_PRIVATE_SLOT(d_func(), void _q_showContextMenu(const QPoint &))
299  Q_PRIVATE_SLOT(d_func(), void _q_renameCurrent())
300  Q_PRIVATE_SLOT(d_func(), void _q_deleteCurrent())
301  Q_PRIVATE_SLOT(d_func(), void _q_showHidden())
302  Q_PRIVATE_SLOT(d_func(), void _q_updateOkButton())
303  Q_PRIVATE_SLOT(d_func(), void _q_currentChanged(const QModelIndex &index))
304  Q_PRIVATE_SLOT(d_func(), void _q_enterDirectory(const QModelIndex &index))
305  Q_PRIVATE_SLOT(d_func(), void _q_goToDirectory(const QString &path))
306  Q_PRIVATE_SLOT(d_func(), void _q_useNameFilter(int index))
307  Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
308  Q_PRIVATE_SLOT(d_func(), void _q_goToUrl(const QUrl &url))
309  Q_PRIVATE_SLOT(d_func(), void _q_goHome())
310  Q_PRIVATE_SLOT(d_func(), void _q_showHeader(QAction *))
311  Q_PRIVATE_SLOT(d_func(), void _q_autoCompleteFileName(const QString &text))
312  Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex & parent))
313  Q_PRIVATE_SLOT(d_func(), void _q_fileRenamed(const QString &path,
314  const QString oldName, const QString newName))
315 #if defined(Q_WS_MAC)
316  Q_PRIVATE_SLOT(d_func(), void _q_macRunNativeAppModalPanel())
317 #endif
318 };
319 
320 inline void QFileDialog::setDirectory(const QDir &adirectory)
321 { setDirectory(adirectory.absolutePath()); }
322 
323 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDialog::Options)
324 
325 #endif // QT_NO_FILEDIALOG
326 
328 
330 
331 #endif // QFILEDIALOG_H
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
The QAbstractItemDelegate class is used to display and edit data items from a model.
void setDirectory(const QString &directory)
Sets the file dialog&#39;s current directory.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual void accept()
Hides the modal dialog and sets the result code to Accepted.
Definition: qdialog.cpp:639
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
The QFileDialog class provides a dialog that allow users to select files or directories.
Definition: qfiledialog.h:66
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
ViewMode
This enum describes the view mode of the file dialog; i.
Definition: qfiledialog.h:82
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
QString absolutePath() const
Returns the absolute path (a path that starts with "/" or with a drive specification), which may contain symbolic links, but never contains redundant ".", ".." or multiple separators.
Definition: qdir.cpp:619
const char * name
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes...
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting...
Mode
Definition: qaudio.h:60
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition: qdialog.cpp:617
static const char *const filters[3]
FileMode
This enum is used to indicate what the user may select in the file dialog; i.
Definition: qfiledialog.h:83
The QItemSelection class manages information about selected items in a model.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QByteArray suffix
The QModelIndex class is used to locate data in a data model.
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
quint16 index
#define QT_DEPRECATED
Definition: qglobal.h:1094
void open()
Shows the dialog as a window modal dialog, returning immediately.
Definition: qdialog.cpp:492
#define Q_FLAGS(x)
Definition: qobjectdefs.h:85
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
void setVisible(bool visible)
Reimplemented Function
Definition: qdialog.cpp:756
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define enabled
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
#define text
Definition: qobjectdefs.h:80
Option
Some platforms allow the user to set a different icon.
Definition: qfiledialog.h:88