QtGui/qfiledialog.h Source File

qfiledialog.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 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 
66 class Q_GUI_EXPORT QFileDialog : public QDialog
67 {
68  Q_OBJECT
70  Q_FLAGS(Options)
71  Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
72  Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode)
73  Q_PROPERTY(AcceptMode acceptMode READ acceptMode WRITE setAcceptMode)
74  Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE false)
75  Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks DESIGNABLE false)
76  Q_PROPERTY(bool confirmOverwrite READ confirmOverwrite WRITE setConfirmOverwrite DESIGNABLE false)
77  Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix)
78  Q_PROPERTY(bool nameFilterDetailsVisible READ isNameFilterDetailsVisible
79  WRITE setNameFilterDetailsVisible DESIGNABLE false)
80  Q_PROPERTY(Options options READ options WRITE setOptions)
81 
82 public:
83  enum ViewMode { Detail, List };
84  enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
85  enum AcceptMode { AcceptOpen, AcceptSave };
86  enum DialogLabel { LookIn, FileName, FileType, Accept, Reject };
87 
88  // ### Rename to FileDialogOption and FileDialogOptions for Qt 5.0
89  enum Option
90  {
91  ShowDirsOnly = 0x00000001,
92  DontResolveSymlinks = 0x00000002,
93  DontConfirmOverwrite = 0x00000004,
94  DontUseSheet = 0x00000008,
95  DontUseNativeDialog = 0x00000010,
96  ReadOnly = 0x00000020,
97  HideNameFilterDetails = 0x00000040
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);
118  QT_DEPRECATED QStringList filters() const;
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:
287  Q_DECLARE_PRIVATE(QFileDialog)
288  Q_DISABLE_COPY(QFileDialog)
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
GLint mode
Definition: GLee.h:4479
#define QT_END_NAMESPACE
Definition: qglobal.h:128
#define Q_PROPERTY(text)
Definition: qobjectdefs.h:80
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
void setVisible(bool visible)
Definition: qdir.h:58
Definition: qnamespace.h:54
GLXDrawable GLXDrawable member
Definition: GLee.h:10556
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
#define inline
Definition: image.h:2490
#define Q_SIGNALS
Definition: qobjectdefs.h:72
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
Definition: qpoint.h:53
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
void setDirectory(const QString &directory)
QString absolutePath() const
virtual void done(int)
void open()
virtual void accept()
#define Q_OBJECT
Definition: qobjectdefs.h:157
Definition: qurl.h:61
GLuint const GLchar * name
Definition: GLee.h:1704
GLenum filter
Definition: GLee.h:3431
#define Q_FLAGS(x)
Definition: qobjectdefs.h:85
#define QT_END_HEADER
Definition: qglobal.h:142
GLclampf f
Definition: GLee.h:9303
GLuint index
Definition: GLee.h:1704
virtual void changeEvent(QEvent *)