qfiledialog.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QFILEDIALOG_H
  40. #define QFILEDIALOG_H
  41. #include <QtCore/qdir.h>
  42. #include <QtCore/qstring.h>
  43. #include <QtCore/qurl.h>
  44. #include <QtWidgets/qdialog.h>
  45. QT_BEGIN_NAMESPACE
  46. #ifndef QT_NO_FILEDIALOG
  47. class QModelIndex;
  48. class QItemSelection;
  49. struct QFileDialogArgs;
  50. class QFileIconProvider;
  51. class QFileDialogPrivate;
  52. class QAbstractItemDelegate;
  53. class QAbstractProxyModel;
  54. class Q_WIDGETS_EXPORT QFileDialog : public QDialog
  55. {
  56. Q_OBJECT
  57. Q_FLAGS(Options)
  58. Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
  59. Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode)
  60. Q_PROPERTY(AcceptMode acceptMode READ acceptMode WRITE setAcceptMode)
  61. Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE false)
  62. Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks DESIGNABLE false)
  63. Q_PROPERTY(bool confirmOverwrite READ confirmOverwrite WRITE setConfirmOverwrite DESIGNABLE false)
  64. Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix)
  65. Q_PROPERTY(bool nameFilterDetailsVisible READ isNameFilterDetailsVisible
  66. WRITE setNameFilterDetailsVisible DESIGNABLE false)
  67. Q_PROPERTY(Options options READ options WRITE setOptions)
  68. Q_PROPERTY(QStringList supportedSchemes READ supportedSchemes WRITE setSupportedSchemes)
  69. public:
  70. enum ViewMode { Detail, List };
  71. Q_ENUM(ViewMode)
  72. enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
  73. Q_ENUM(FileMode)
  74. enum AcceptMode { AcceptOpen, AcceptSave };
  75. Q_ENUM(AcceptMode)
  76. enum DialogLabel { LookIn, FileName, FileType, Accept, Reject };
  77. enum Option
  78. {
  79. ShowDirsOnly = 0x00000001,
  80. DontResolveSymlinks = 0x00000002,
  81. DontConfirmOverwrite = 0x00000004,
  82. DontUseSheet = 0x00000008,
  83. DontUseNativeDialog = 0x00000010,
  84. ReadOnly = 0x00000020,
  85. HideNameFilterDetails = 0x00000040,
  86. DontUseCustomDirectoryIcons = 0x00000080
  87. };
  88. Q_ENUM(Option)
  89. Q_DECLARE_FLAGS(Options, Option)
  90. QFileDialog(QWidget *parent, Qt::WindowFlags f);
  91. explicit QFileDialog(QWidget *parent = Q_NULLPTR,
  92. const QString &caption = QString(),
  93. const QString &directory = QString(),
  94. const QString &filter = QString());
  95. ~QFileDialog();
  96. void setDirectory(const QString &directory);
  97. inline void setDirectory(const QDir &directory);
  98. QDir directory() const;
  99. void setDirectoryUrl(const QUrl &directory);
  100. QUrl directoryUrl() const;
  101. void selectFile(const QString &filename);
  102. QStringList selectedFiles() const;
  103. void selectUrl(const QUrl &url);
  104. QList<QUrl> selectedUrls() const;
  105. void setNameFilterDetailsVisible(bool enabled);
  106. bool isNameFilterDetailsVisible() const;
  107. void setNameFilter(const QString &filter);
  108. void setNameFilters(const QStringList &filters);
  109. QStringList nameFilters() const;
  110. void selectNameFilter(const QString &filter);
  111. QString selectedNameFilter() const;
  112. #ifndef QT_NO_MIMETYPE
  113. void setMimeTypeFilters(const QStringList &filters);
  114. QStringList mimeTypeFilters() const;
  115. void selectMimeTypeFilter(const QString &filter);
  116. #endif
  117. QDir::Filters filter() const;
  118. void setFilter(QDir::Filters filters);
  119. void setViewMode(ViewMode mode);
  120. ViewMode viewMode() const;
  121. void setFileMode(FileMode mode);
  122. FileMode fileMode() const;
  123. void setAcceptMode(AcceptMode mode);
  124. AcceptMode acceptMode() const;
  125. void setReadOnly(bool enabled);
  126. bool isReadOnly() const;
  127. void setResolveSymlinks(bool enabled);
  128. bool resolveSymlinks() const;
  129. void setSidebarUrls(const QList<QUrl> &urls);
  130. QList<QUrl> sidebarUrls() const;
  131. QByteArray saveState() const;
  132. bool restoreState(const QByteArray &state);
  133. void setConfirmOverwrite(bool enabled);
  134. bool confirmOverwrite() const;
  135. void setDefaultSuffix(const QString &suffix);
  136. QString defaultSuffix() const;
  137. void setHistory(const QStringList &paths);
  138. QStringList history() const;
  139. void setItemDelegate(QAbstractItemDelegate *delegate);
  140. QAbstractItemDelegate *itemDelegate() const;
  141. void setIconProvider(QFileIconProvider *provider);
  142. QFileIconProvider *iconProvider() const;
  143. void setLabelText(DialogLabel label, const QString &text);
  144. QString labelText(DialogLabel label) const;
  145. void setSupportedSchemes(const QStringList &schemes);
  146. QStringList supportedSchemes() const;
  147. #ifndef QT_NO_PROXYMODEL
  148. void setProxyModel(QAbstractProxyModel *model);
  149. QAbstractProxyModel *proxyModel() const;
  150. #endif
  151. void setOption(Option option, bool on = true);
  152. bool testOption(Option option) const;
  153. void setOptions(Options options);
  154. Options options() const;
  155. using QDialog::open;
  156. void open(QObject *receiver, const char *member);
  157. void setVisible(bool visible) Q_DECL_OVERRIDE;
  158. Q_SIGNALS:
  159. void fileSelected(const QString &file);
  160. void filesSelected(const QStringList &files);
  161. void currentChanged(const QString &path);
  162. void directoryEntered(const QString &directory);
  163. void urlSelected(const QUrl &url);
  164. void urlsSelected(const QList<QUrl> &urls);
  165. void currentUrlChanged(const QUrl &url);
  166. void directoryUrlEntered(const QUrl &directory);
  167. void filterSelected(const QString &filter);
  168. public:
  169. static QString getOpenFileName(QWidget *parent = Q_NULLPTR,
  170. const QString &caption = QString(),
  171. const QString &dir = QString(),
  172. const QString &filter = QString(),
  173. QString *selectedFilter = Q_NULLPTR,
  174. Options options = Options());
  175. static QUrl getOpenFileUrl(QWidget *parent = Q_NULLPTR,
  176. const QString &caption = QString(),
  177. const QUrl &dir = QUrl(),
  178. const QString &filter = QString(),
  179. QString *selectedFilter = Q_NULLPTR,
  180. Options options = Options(),
  181. const QStringList &supportedSchemes = QStringList());
  182. static QString getSaveFileName(QWidget *parent = Q_NULLPTR,
  183. const QString &caption = QString(),
  184. const QString &dir = QString(),
  185. const QString &filter = QString(),
  186. QString *selectedFilter = Q_NULLPTR,
  187. Options options = Options());
  188. static QUrl getSaveFileUrl(QWidget *parent = Q_NULLPTR,
  189. const QString &caption = QString(),
  190. const QUrl &dir = QUrl(),
  191. const QString &filter = QString(),
  192. QString *selectedFilter = Q_NULLPTR,
  193. Options options = Options(),
  194. const QStringList &supportedSchemes = QStringList());
  195. static QString getExistingDirectory(QWidget *parent = Q_NULLPTR,
  196. const QString &caption = QString(),
  197. const QString &dir = QString(),
  198. Options options = ShowDirsOnly);
  199. static QUrl getExistingDirectoryUrl(QWidget *parent = Q_NULLPTR,
  200. const QString &caption = QString(),
  201. const QUrl &dir = QUrl(),
  202. Options options = ShowDirsOnly,
  203. const QStringList &supportedSchemes = QStringList());
  204. static QStringList getOpenFileNames(QWidget *parent = Q_NULLPTR,
  205. const QString &caption = QString(),
  206. const QString &dir = QString(),
  207. const QString &filter = QString(),
  208. QString *selectedFilter = Q_NULLPTR,
  209. Options options = Options());
  210. static QList<QUrl> getOpenFileUrls(QWidget *parent = Q_NULLPTR,
  211. const QString &caption = QString(),
  212. const QUrl &dir = QUrl(),
  213. const QString &filter = QString(),
  214. QString *selectedFilter = Q_NULLPTR,
  215. Options options = Options(),
  216. const QStringList &supportedSchemes = QStringList());
  217. protected:
  218. QFileDialog(const QFileDialogArgs &args);
  219. void done(int result) Q_DECL_OVERRIDE;
  220. void accept() Q_DECL_OVERRIDE;
  221. void changeEvent(QEvent *e) Q_DECL_OVERRIDE;
  222. private:
  223. Q_DECLARE_PRIVATE(QFileDialog)
  224. Q_DISABLE_COPY(QFileDialog)
  225. Q_PRIVATE_SLOT(d_func(), void _q_pathChanged(const QString &))
  226. Q_PRIVATE_SLOT(d_func(), void _q_navigateBackward())
  227. Q_PRIVATE_SLOT(d_func(), void _q_navigateForward())
  228. Q_PRIVATE_SLOT(d_func(), void _q_navigateToParent())
  229. Q_PRIVATE_SLOT(d_func(), void _q_createDirectory())
  230. Q_PRIVATE_SLOT(d_func(), void _q_showListView())
  231. Q_PRIVATE_SLOT(d_func(), void _q_showDetailsView())
  232. Q_PRIVATE_SLOT(d_func(), void _q_showContextMenu(const QPoint &))
  233. Q_PRIVATE_SLOT(d_func(), void _q_renameCurrent())
  234. Q_PRIVATE_SLOT(d_func(), void _q_deleteCurrent())
  235. Q_PRIVATE_SLOT(d_func(), void _q_showHidden())
  236. Q_PRIVATE_SLOT(d_func(), void _q_updateOkButton())
  237. Q_PRIVATE_SLOT(d_func(), void _q_currentChanged(const QModelIndex &index))
  238. Q_PRIVATE_SLOT(d_func(), void _q_enterDirectory(const QModelIndex &index))
  239. Q_PRIVATE_SLOT(d_func(), void _q_emitUrlSelected(const QUrl &))
  240. Q_PRIVATE_SLOT(d_func(), void _q_emitUrlsSelected(const QList<QUrl> &))
  241. Q_PRIVATE_SLOT(d_func(), void _q_nativeCurrentChanged(const QUrl &))
  242. Q_PRIVATE_SLOT(d_func(), void _q_nativeEnterDirectory(const QUrl&))
  243. Q_PRIVATE_SLOT(d_func(), void _q_goToDirectory(const QString &path))
  244. Q_PRIVATE_SLOT(d_func(), void _q_useNameFilter(int index))
  245. Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
  246. Q_PRIVATE_SLOT(d_func(), void _q_goToUrl(const QUrl &url))
  247. Q_PRIVATE_SLOT(d_func(), void _q_goHome())
  248. Q_PRIVATE_SLOT(d_func(), void _q_showHeader(QAction *))
  249. Q_PRIVATE_SLOT(d_func(), void _q_autoCompleteFileName(const QString &text))
  250. Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex & parent))
  251. Q_PRIVATE_SLOT(d_func(), void _q_fileRenamed(const QString &path,
  252. const QString &oldName,
  253. const QString &newName))
  254. friend class QPlatformDialogHelper;
  255. };
  256. inline void QFileDialog::setDirectory(const QDir &adirectory)
  257. { setDirectory(adirectory.absolutePath()); }
  258. Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDialog::Options)
  259. #endif // QT_NO_FILEDIALOG
  260. QT_END_NAMESPACE
  261. #endif // QFILEDIALOG_H