1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKFILEDIALOGIMPL_P_H
5#define QQUICKFILEDIALOGIMPL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick/private/qquicklistview_p.h>
19#include <QtQuickTemplates2/private/qquickdialog_p.h>
20
21#include "qtquickdialogs2quickimplglobal_p.h"
22
23QT_BEGIN_NAMESPACE
24
25class QQuickComboBox;
26class QQuickDialogButtonBox;
27class QQuickTextField;
28class QQuickLabel;
29
30class QQuickFileDialogImplAttached;
31class QQuickFileDialogImplAttachedPrivate;
32class QQuickFileDialogImplPrivate;
33class QQuickFileNameFilter;
34class QQuickFolderBreadcrumbBar;
35class QQuickSideBar;
36
37class Q_QUICKDIALOGS2QUICKIMPL_EXPORT QQuickFileDialogImpl : public QQuickDialog
38{
39 Q_OBJECT
40 Q_PROPERTY(QUrl currentFolder READ currentFolder WRITE setCurrentFolder NOTIFY currentFolderChanged FINAL)
41 Q_PROPERTY(QUrl selectedFile READ selectedFile WRITE setSelectedFile NOTIFY selectedFileChanged FINAL)
42 Q_PROPERTY(QStringList nameFilters READ nameFilters NOTIFY nameFiltersChanged FINAL)
43 Q_PROPERTY(QQuickFileNameFilter *selectedNameFilter READ selectedNameFilter CONSTANT)
44 Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY selectedFileChanged FINAL)
45 Q_PROPERTY(QString currentFolderName READ currentFolderName NOTIFY selectedFileChanged FINAL)
46 QML_NAMED_ELEMENT(FileDialogImpl)
47 QML_ATTACHED(QQuickFileDialogImplAttached)
48 QML_ADDED_IN_VERSION(6, 2)
49 Q_MOC_INCLUDE(<QtQuickDialogs2Utils/private/qquickfilenamefilter_p.h>)
50 Q_MOC_INCLUDE(<QtQuickDialogs2QuickImpl/private/qquickfolderbreadcrumbbar_p.h>)
51 Q_MOC_INCLUDE(<QtQuickDialogs2QuickImpl/private/qquicksidebar_p.h>)
52
53public:
54 explicit QQuickFileDialogImpl(QObject *parent = nullptr);
55
56 static QQuickFileDialogImplAttached *qmlAttachedProperties(QObject *object);
57
58 enum class SetReason {
59 // Either user interaction or e.g. a change in ListView's currentIndex after changing its model.
60 External,
61 // As a result of the user setting an initial selectedFile.
62 Internal
63 };
64
65 QUrl currentFolder() const;
66 void setCurrentFolder(const QUrl &currentFolder, SetReason setReason = SetReason::External);
67
68 QUrl selectedFile() const;
69 void setSelectedFile(const QUrl &file);
70 void setInitialCurrentFolderAndSelectedFile(const QUrl &file);
71
72 QSharedPointer<QFileDialogOptions> options() const;
73 void setOptions(const QSharedPointer<QFileDialogOptions> &options);
74
75 QStringList nameFilters() const;
76 void resetNameFilters();
77
78 QQuickFileNameFilter *selectedNameFilter() const;
79
80 void setAcceptLabel(const QString &label);
81 void setRejectLabel(const QString &label);
82
83 QString fileName() const;
84 void setFileName(const QString &fileName);
85
86 QString currentFolderName() const;
87
88public Q_SLOTS:
89 void selectNameFilter(const QString &filter);
90
91Q_SIGNALS:
92 void currentFolderChanged(const QUrl &folderUrl);
93 void selectedFileChanged(const QUrl &selectedFileUrl);
94 void nameFiltersChanged();
95 void fileSelected(const QUrl &fileUrl);
96 void filterSelected(const QString &filter);
97
98private:
99 void componentComplete() override;
100 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override;
101
102 Q_DISABLE_COPY(QQuickFileDialogImpl)
103 Q_DECLARE_PRIVATE(QQuickFileDialogImpl)
104};
105
106class Q_QUICKDIALOGS2QUICKIMPL_EXPORT QQuickFileDialogImplAttached : public QObject
107{
108 Q_OBJECT
109 Q_PROPERTY(QQuickDialogButtonBox *buttonBox READ buttonBox WRITE setButtonBox NOTIFY buttonBoxChanged FINAL)
110 Q_PROPERTY(QQuickComboBox *nameFiltersComboBox READ nameFiltersComboBox WRITE setNameFiltersComboBox NOTIFY nameFiltersComboBoxChanged)
111 Q_PROPERTY(QQuickListView *fileDialogListView READ fileDialogListView WRITE setFileDialogListView NOTIFY fileDialogListViewChanged)
112 Q_PROPERTY(QQuickFolderBreadcrumbBar *breadcrumbBar READ breadcrumbBar WRITE setBreadcrumbBar NOTIFY breadcrumbBarChanged)
113 Q_PROPERTY(QQuickLabel *fileNameLabel READ fileNameLabel WRITE setFileNameLabel NOTIFY fileNameLabelChanged FINAL)
114 Q_PROPERTY(QQuickTextField *fileNameTextField READ fileNameTextField WRITE setFileNameTextField NOTIFY fileNameTextFieldChanged FINAL)
115 Q_PROPERTY(QQuickDialog *overwriteConfirmationDialog READ overwriteConfirmationDialog WRITE setOverwriteConfirmationDialog NOTIFY overwriteConfirmationDialogChanged FINAL)
116 Q_PROPERTY(QQuickSideBar *sideBar READ sideBar WRITE setSideBar NOTIFY sideBarChanged FINAL)
117 Q_MOC_INCLUDE(<QtQuickTemplates2/private/qquickdialogbuttonbox_p.h>)
118 Q_MOC_INCLUDE(<QtQuickTemplates2/private/qquickcombobox_p.h>)
119 Q_MOC_INCLUDE(<QtQuickTemplates2/private/qquicktextfield_p.h>)
120 Q_MOC_INCLUDE(<QtQuickTemplates2/private/qquicklabel_p.h>)
121
122public:
123 explicit QQuickFileDialogImplAttached(QObject *parent = nullptr);
124
125 QQuickDialogButtonBox *buttonBox() const;
126 void setButtonBox(QQuickDialogButtonBox *buttonBox);
127
128 QQuickComboBox *nameFiltersComboBox() const;
129 void setNameFiltersComboBox(QQuickComboBox *nameFiltersComboBox);
130
131 QString selectedNameFilter() const;
132 void selectNameFilter(const QString &filter);
133
134 QQuickListView *fileDialogListView() const;
135 void setFileDialogListView(QQuickListView *fileDialogListView);
136
137 QQuickFolderBreadcrumbBar *breadcrumbBar() const;
138 void setBreadcrumbBar(QQuickFolderBreadcrumbBar *breadcrumbBar);
139
140 QQuickLabel *fileNameLabel() const;
141 void setFileNameLabel(QQuickLabel *fileNameLabel);
142
143 QQuickTextField *fileNameTextField() const;
144 void setFileNameTextField(QQuickTextField *fileNameTextField);
145
146 QQuickDialog *overwriteConfirmationDialog() const;
147 void setOverwriteConfirmationDialog(QQuickDialog *dialog);
148
149 QQuickSideBar *sideBar() const;
150 void setSideBar(QQuickSideBar *sideBar);
151
152Q_SIGNALS:
153 void buttonBoxChanged();
154 void nameFiltersComboBoxChanged();
155 void fileDialogListViewChanged();
156 void breadcrumbBarChanged();
157 void fileNameLabelChanged();
158 void fileNameTextFieldChanged();
159 void overwriteConfirmationDialogChanged();
160 Q_REVISION(6, 9) void sideBarChanged();
161
162private:
163 Q_DISABLE_COPY(QQuickFileDialogImplAttached)
164 Q_DECLARE_PRIVATE(QQuickFileDialogImplAttached)
165};
166
167QT_END_NAMESPACE
168
169#endif // QQUICKFILEDIALOGIMPL_P_H
170

source code of qtdeclarative/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl_p.h