aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/platform
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-08-13 21:31:19 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-08-14 09:26:06 +0000
commit7b6180a2d6b5def11b95485a3323a37f92b57ba9 (patch)
tree580d2b4fe1fdce0b5df56124801f48cdb4e29eab /src/imports/platform
parent877ac7226c8ae4ec9b8d1652a7da1f73d78bc5c7 (diff)
FolderDialog: replace folderSelected() with a declarative property
Follow the same convention that ColorDialog and FontDialog. Change-Id: I49834daf908aadf145949c0b749c6c066f63fd83 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/imports/platform')
-rw-r--r--src/imports/platform/plugins.qmltypes9
-rw-r--r--src/imports/platform/qquickplatformfolderdialog.cpp84
-rw-r--r--src/imports/platform/qquickplatformfolderdialog_p.h13
3 files changed, 60 insertions, 46 deletions
diff --git a/src/imports/platform/plugins.qmltypes b/src/imports/platform/plugins.qmltypes
index d751e45f..d7e85c9e 100644
--- a/src/imports/platform/plugins.qmltypes
+++ b/src/imports/platform/plugins.qmltypes
@@ -132,18 +132,11 @@ Module {
prototype: "QQuickPlatformDialog"
exports: ["Qt.labs.platform/FolderDialog 1.0"]
exportMetaObjectRevisions: [0]
+ Property { name: "folder"; type: "QUrl" }
Property { name: "currentFolder"; type: "QUrl" }
Property { name: "options"; type: "QFileDialogOptions::FileDialogOptions" }
Property { name: "acceptLabel"; type: "string" }
Property { name: "rejectLabel"; type: "string" }
- Signal {
- name: "folderSelected"
- Parameter { name: "folder"; type: "QUrl" }
- }
- Signal {
- name: "foldersSelected"
- Parameter { name: "folders"; type: "QList<QUrl>" }
- }
}
Component {
name: "QQuickPlatformFontDialog"
diff --git a/src/imports/platform/qquickplatformfolderdialog.cpp b/src/imports/platform/qquickplatformfolderdialog.cpp
index 04c39f6f..7aa0a7e9 100644
--- a/src/imports/platform/qquickplatformfolderdialog.cpp
+++ b/src/imports/platform/qquickplatformfolderdialog.cpp
@@ -59,9 +59,10 @@ QT_BEGIN_NAMESPACE
\image qtlabsplatform-folderdialog-gtk.png
To show a folder dialog, construct an instance of FolderDialog, set the
- desired properties, and call \l {Dialog::}{open()}. FolderDialog emits
- the \l folderSelected() and \l foldersSelected() signals when the user
- has selected folder(s).
+ desired properties, and call \l {Dialog::}{open()}. The \l currentFolder
+ property can be used to determine the currently selected folder in the
+ dialog. The \l folder property is updated only after the final selection
+ has been made by accepting the dialog.
\code
MenuItem {
@@ -72,7 +73,11 @@ QT_BEGIN_NAMESPACE
FolderDialog {
id: folderDialog
currentFolder: viewer.folder
- onFolderSelected: viewer.folder = folder
+ }
+
+ MyViewer {
+ id: viewer
+ folder: folderDialog.folder
}
\endcode
@@ -95,29 +100,41 @@ QT_BEGIN_NAMESPACE
\sa FileDialog
*/
-/*!
- \qmlsignal void Qt.labs.platform::FolderDialog::folderSelected(url folder)
-
- This signal is emitted when a \a folder has been selected.
+Q_DECLARE_LOGGING_CATEGORY(qtLabsPlatformDialogs)
- \sa foldersSelected(), currentFolder
-*/
+QQuickPlatformFolderDialog::QQuickPlatformFolderDialog(QObject *parent)
+ : QQuickPlatformDialog(parent), m_options(QFileDialogOptions::create())
+{
+ m_options->setFileMode(QFileDialogOptions::Directory);
+ m_options->setAcceptMode(QFileDialogOptions::AcceptOpen);
+}
/*!
- \qmlsignal void Qt.labs.platform::FolderDialog::foldersSelected(list<url> folders)
+ \qmlproperty url Qt.labs.platform::FolderDialog::folder
- This signal is emitted when multiple \a folders have been selected.
+ This property holds the final accepted folder.
- \sa folderSelected(), currentFolder
-*/
+ Unlike the \l currentFolder property, the \c folder property is not updated
+ while the user is selecting folders in the dialog, but only after the final
+ selection has been made. That is, when the user has clicked \uicontrol OK
+ to accept a folder. Alternatively, the \l {Dialog::}{accepted()} signal
+ can be handled to get the final selection.
-Q_DECLARE_LOGGING_CATEGORY(qtLabsPlatformDialogs)
+ \sa currentFolder, {Dialog::}{accepted()}
+*/
+QUrl QQuickPlatformFolderDialog::folder() const
+{
+ return m_folder;
+}
-QQuickPlatformFolderDialog::QQuickPlatformFolderDialog(QObject *parent)
- : QQuickPlatformDialog(parent), m_options(QFileDialogOptions::create())
+void QQuickPlatformFolderDialog::setFolder(const QUrl &folder)
{
- m_options->setFileMode(QFileDialogOptions::Directory);
- m_options->setAcceptMode(QFileDialogOptions::AcceptOpen);
+ if (m_folder == folder)
+ return;
+
+ m_folder = folder;
+ setCurrentFolder(folder);
+ emit folderChanged();
}
/*!
@@ -125,15 +142,17 @@ QQuickPlatformFolderDialog::QQuickPlatformFolderDialog(QObject *parent)
This property holds the currently selected folder in the dialog.
- \sa folderSelected(), foldersSelected()
+ Unlike the \l folder property, the \c currentFolder property is updated
+ while the user is selecting folders in the dialog, even before the final
+ selection has been made.
+
+ \sa folder
*/
QUrl QQuickPlatformFolderDialog::currentFolder() const
{
- if (m_current.isEmpty()) {
- if (QPlatformFileDialogHelper *fileDialog = qobject_cast<QPlatformFileDialogHelper *>(handle()))
- m_current = fileDialog->directory();
- }
- return m_current;
+ if (QPlatformFileDialogHelper *fileDialog = qobject_cast<QPlatformFileDialogHelper *>(handle()))
+ return fileDialog->directory();
+ return QUrl();
}
void QQuickPlatformFolderDialog::setCurrentFolder(const QUrl &folder)
@@ -249,14 +268,7 @@ QPlatformDialogHelper *QQuickPlatformFolderDialog::createHelper()
qCDebug(qtLabsPlatformDialogs) << "FolderDialog:" << dialog;
if (QPlatformFileDialogHelper *fileDialog = qobject_cast<QPlatformFileDialogHelper *>(dialog)) {
- connect(fileDialog, &QPlatformFileDialogHelper::fileSelected, this, &QQuickPlatformFolderDialog::folderSelected);
- connect(fileDialog, &QPlatformFileDialogHelper::filesSelected, this, &QQuickPlatformFolderDialog::foldersSelected);
- connect(fileDialog, &QPlatformFileDialogHelper::currentChanged, [this](const QUrl &url) {
- if (m_current == url)
- return;
- m_current = url;
- emit currentFolderChanged();
- });
+ connect(fileDialog, &QPlatformFileDialogHelper::directoryEntered, this, &QQuickPlatformFolderDialog::currentFolderChanged);
fileDialog->setOptions(m_options);
}
return dialog;
@@ -267,4 +279,10 @@ void QQuickPlatformFolderDialog::applyOptions()
m_options->setWindowTitle(title());
}
+void QQuickPlatformFolderDialog::accept()
+{
+ setFolder(currentFolder());
+ QQuickPlatformDialog::accept();
+}
+
QT_END_NAMESPACE
diff --git a/src/imports/platform/qquickplatformfolderdialog_p.h b/src/imports/platform/qquickplatformfolderdialog_p.h
index 39dc025f..2c0fdf51 100644
--- a/src/imports/platform/qquickplatformfolderdialog_p.h
+++ b/src/imports/platform/qquickplatformfolderdialog_p.h
@@ -57,6 +57,7 @@ QT_BEGIN_NAMESPACE
class QQuickPlatformFolderDialog : public QQuickPlatformDialog
{
Q_OBJECT
+ Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged FINAL)
Q_PROPERTY(QUrl currentFolder READ currentFolder WRITE setCurrentFolder NOTIFY currentFolderChanged FINAL)
Q_PROPERTY(QFileDialogOptions::FileDialogOptions options READ options WRITE setOptions RESET resetOptions NOTIFY optionsChanged FINAL)
Q_PROPERTY(QString acceptLabel READ acceptLabel WRITE setAcceptLabel RESET resetAcceptLabel NOTIFY acceptLabelChanged FINAL)
@@ -66,8 +67,11 @@ class QQuickPlatformFolderDialog : public QQuickPlatformDialog
public:
explicit QQuickPlatformFolderDialog(QObject *parent = nullptr);
+ QUrl folder() const;
+ void setFolder(const QUrl &folder);
+
QUrl currentFolder() const;
- void setCurrentFolder(const QUrl &url);
+ void setCurrentFolder(const QUrl &folder);
QFileDialogOptions::FileDialogOptions options() const;
void setOptions(QFileDialogOptions::FileDialogOptions options);
@@ -82,20 +86,19 @@ public:
void resetRejectLabel();
Q_SIGNALS:
+ void folderChanged();
void currentFolderChanged();
void optionsChanged();
void acceptLabelChanged();
void rejectLabelChanged();
- void folderSelected(const QUrl &folder);
- void foldersSelected(const QList<QUrl> &folders);
-
protected:
QPlatformDialogHelper *createHelper() override;
void applyOptions() override;
+ void accept() override;
private:
- mutable QUrl m_current;
+ QUrl m_folder;
QSharedPointer<QFileDialogOptions> m_options;
};