diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-08-13 21:31:19 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-08-14 09:26:06 +0000 |
commit | 7b6180a2d6b5def11b95485a3323a37f92b57ba9 (patch) | |
tree | 580d2b4fe1fdce0b5df56124801f48cdb4e29eab /src/imports/platform/qquickplatformfolderdialog.cpp | |
parent | 877ac7226c8ae4ec9b8d1652a7da1f73d78bc5c7 (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/qquickplatformfolderdialog.cpp')
-rw-r--r-- | src/imports/platform/qquickplatformfolderdialog.cpp | 84 |
1 files changed, 51 insertions, 33 deletions
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 |