aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <[email protected]>2021-11-24 14:57:40 +0100
committerMitch Curtis <[email protected]>2022-01-05 16:59:15 +0100
commit13399bd54d084ed837ec061ca9315dbd173f3b48 (patch)
tree5a6435f072df4889463ae266fc1e98384b66a5e8
parentc1938ddbb45c75593c8a21aaec2420f8f2c7b3d8 (diff)
Replace currentFile(s) with selectedFile(s)
selectedFile can represent the currently-selected file (if the platform supports it), and so we can free up "currentFolder" for FolderDialog now that it means the folder that is being displayed, rather than the folder that is currently selected. [ChangeLog][QtQuickDialogs] FileDialog's currentFile and currentFiles properties have been deprecated. The selectedFile and selectedFiles properties now refer to the currently selected file(s), as well as the final selection. Fixes: QTBUG-98562 Task-number: QTBUG-87798 Pick-to: 6.3 Change-Id: Ic66481332338f21169a9f63617cf4db4be83265d Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r--src/quickcontrols2impl/qquickplatformtheme.cpp9
-rw-r--r--src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp69
-rw-r--r--src/quickdialogs2/quickdialogs2/qquickfiledialog_p.h1
-rw-r--r--src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogdelegate.cpp2
-rw-r--r--src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl.cpp66
-rw-r--r--src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl_p.h7
-rw-r--r--src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl_p_p.h3
-rw-r--r--src/quickdialogs2/quickdialogs2quickimpl/qquickfolderbreadcrumbbar.cpp5
-rw-r--r--src/quickdialogs2/quickdialogs2quickimpl/qquickplatformfiledialog.cpp4
-rw-r--r--tests/auto/quickdialogs/qquickfiledialogimpl/tst_qquickfiledialogimpl.cpp63
10 files changed, 94 insertions, 135 deletions
diff --git a/src/quickcontrols2impl/qquickplatformtheme.cpp b/src/quickcontrols2impl/qquickplatformtheme.cpp
index b636b36397..e9b903d038 100644
--- a/src/quickcontrols2impl/qquickplatformtheme.cpp
+++ b/src/quickcontrols2impl/qquickplatformtheme.cpp
@@ -56,11 +56,16 @@ QQuickPlatformTheme::QQuickPlatformTheme(QObject *parent) :
QVariant QQuickPlatformTheme::themeHint(QPlatformTheme::ThemeHint themeHint) const
{
- if (themeHint == QPlatformTheme::ShowDirectoriesFirst) {
- // Allow tests to force this value, otherwise they get very messy and difficult to understand.
+ // Allow tests to force some theme hint values, otherwise they get very messy and difficult to understand.
+ switch (themeHint) {
+ case QPlatformTheme::ShowDirectoriesFirst: {
const QVariant showDirsFirst = qEnvironmentVariable("QT_QUICK_DIALOGS_SHOW_DIRS_FIRST");
if (showDirsFirst.isValid() && showDirsFirst.canConvert<bool>())
return showDirsFirst;
+ break;
+ }
+ default:
+ break;
}
return QGuiApplicationPrivate::platformTheme()->themeHint(themeHint);
}
diff --git a/src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp b/src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp
index a5c6a954e9..6ed2bf70a3 100644
--- a/src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp
+++ b/src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp
@@ -159,18 +159,16 @@ void QQuickFileDialog::setFileMode(FileMode mode)
\qmlproperty url QtQuick.Dialogs::FileDialog::selectedFile
\readonly
- This property holds the final accepted file.
+ This property holds the last file that was selected in the dialog.
If there are multiple selected files, this property refers to the first
file.
- Unlike the \l currentFile property, the \c selectedFile property is not
- updated while the user is selecting files in the dialog, but only after the
- final selection has been made. That is, when the user has clicked
- \uicontrol OK to accept a file. Alternatively, the
- \l {Dialog::}{accepted()} signal can be handled to get the final selection.
+ The value of this property is updated each time the user selects a file in
+ the dialog, and when the dialog is accepted. Handle the
+ \l {Dialog::}{accepted()} signal to get the final selection.
- \sa selectedFiles, currentFile, {Dialog::}{accepted()}, currentFolder
+ \sa selectedFiles, {Dialog::}{accepted()}, currentFolder
*/
QUrl QQuickFileDialog::selectedFile() const
{
@@ -180,15 +178,13 @@ QUrl QQuickFileDialog::selectedFile() const
/*!
\qmlproperty list<url> QtQuick.Dialogs::FileDialog::selectedFiles
- This property holds the final accepted files.
+ This property holds the last files that were selected in the dialog.
- Unlike the \l currentFiles property, the \c selectedFiles property is not
- updated while the user is selecting files in the dialog, but only after the
- final selection has been made. That is, when the user has clicked
- \uicontrol OK to accept files. Alternatively, the \l {Dialog::}{accepted()}
- signal can be handled to get the final selection.
+ The value of this property is updated each time the user selects files in
+ the dialog, and when the dialog is accepted. Handle the
+ \l {Dialog::}{accepted()} signal to get the final selection.
- \sa currentFiles, {Dialog::}{accepted()}, currentFolder
+ \sa {Dialog::}{accepted()}, currentFolder
*/
QList<QUrl> QQuickFileDialog::selectedFiles() const
{
@@ -202,57 +198,48 @@ void QQuickFileDialog::setSelectedFiles(const QList<QUrl> &selectedFiles)
bool firstChanged = m_selectedFiles.value(0) != selectedFiles.value(0);
m_selectedFiles = selectedFiles;
- if (firstChanged)
+ if (firstChanged) {
emit selectedFileChanged();
+ emit currentFileChanged();
+ }
emit selectedFilesChanged();
+ emit currentFilesChanged();
}
/*!
\qmlproperty url QtQuick.Dialogs::FileDialog::currentFile
+ \deprecated [6.3] Use \l selectedFile instead.
This property holds the currently selected file in the dialog.
- Unlike the \l selectedFile property, the \c currentFile property is updated
- while the user is selecting files in the dialog, even before the final
- selection has been made.
-
\sa selectedFile, currentFiles, currentFolder
*/
QUrl QQuickFileDialog::currentFile() const
{
- return currentFiles().value(0);
+ return selectedFile();
}
void QQuickFileDialog::setCurrentFile(const QUrl &file)
{
- setCurrentFiles(QList<QUrl>() << file);
+ setSelectedFiles(QList<QUrl>() << file);
}
/*!
\qmlproperty list<url> QtQuick.Dialogs::FileDialog::currentFiles
+ \deprecated [6.3] Use \l selectedFiles instead.
This property holds the currently selected files in the dialog.
- Unlike the \l selectedFiles property, the \c currentFiles property is
- updated while the user is selecting files in the dialog, even before the
- final selection has been made.
-
\sa selectedFiles, currentFile, currentFolder
*/
QList<QUrl> QQuickFileDialog::currentFiles() const
{
- if (QPlatformFileDialogHelper *fileDialog = qobject_cast<QPlatformFileDialogHelper *>(handle()))
- return fileDialog->selectedFiles();
- return m_options->initiallySelectedFiles();
+ return selectedFiles();
}
void QQuickFileDialog::setCurrentFiles(const QList<QUrl> &currentFiles)
{
- if (QPlatformFileDialogHelper *fileDialog = qobject_cast<QPlatformFileDialogHelper *>(handle())) {
- for (const QUrl &file : currentFiles)
- fileDialog->selectFile(file);
- }
- m_options->setInitiallySelectedFiles(currentFiles);
+ setSelectedFiles(currentFiles);
}
/*!
@@ -541,10 +528,13 @@ bool QQuickFileDialog::useNativeDialog() const
void QQuickFileDialog::onCreate(QPlatformDialogHelper *dialog)
{
if (QPlatformFileDialogHelper *fileDialog = qobject_cast<QPlatformFileDialogHelper *>(dialog)) {
- connect(fileDialog, &QPlatformFileDialogHelper::currentChanged, this, &QQuickFileDialog::currentFileChanged);
- connect(fileDialog, &QPlatformFileDialogHelper::currentChanged, this, &QQuickFileDialog::currentFilesChanged);
+ connect(fileDialog, &QPlatformFileDialogHelper::currentChanged, this, [=](){ setSelectedFiles(fileDialog->selectedFiles()); });
connect(fileDialog, &QPlatformFileDialogHelper::directoryEntered, this, &QQuickFileDialog::currentFolderChanged);
fileDialog->setOptions(m_options);
+
+ // Need to call this manually once on creation because QPlatformFileDialogHelper::currentChanged
+ // has already been emitted by this point (because of QQuickFileDialogImplPrivate::updateSelectedFile).
+ setSelectedFiles(fileDialog->selectedFiles());
}
}
@@ -580,15 +570,6 @@ void QQuickFileDialog::onHide(QPlatformDialogHelper *dialog)
}
}
-void QQuickFileDialog::accept()
-{
- if (QPlatformFileDialogHelper *fileDialog = qobject_cast<QPlatformFileDialogHelper *>(handle())) {
- // Take the currently selected files and make them the final set of files.
- setSelectedFiles(fileDialog->selectedFiles());
- }
- QQuickAbstractDialog::accept();
-}
-
QUrl QQuickFileDialog::addDefaultSuffix(const QUrl &file) const
{
QUrl url = file;
diff --git a/src/quickdialogs2/quickdialogs2/qquickfiledialog_p.h b/src/quickdialogs2/quickdialogs2/qquickfiledialog_p.h
index 1d1a0e82d1..ef86e11133 100644
--- a/src/quickdialogs2/quickdialogs2/qquickfiledialog_p.h
+++ b/src/quickdialogs2/quickdialogs2/qquickfiledialog_p.h
@@ -146,7 +146,6 @@ protected:
void onCreate(QPlatformDialogHelper *dialog) override;
void onShow(QPlatformDialogHelper *dialog) override;
void onHide(QPlatformDialogHelper *dialog) override;
- void accept() override;
private:
QUrl addDefaultSuffix(const QUrl &file) const;
diff --git a/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogdelegate.cpp b/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogdelegate.cpp
index d212b6c7f6..30ce27fd56 100644
--- a/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogdelegate.cpp
+++ b/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogdelegate.cpp
@@ -84,7 +84,7 @@ void QQuickFileDialogDelegatePrivate::highlightFile()
if (converted) {
attached->view()->setCurrentIndex(index);
if (fileDialog)
- fileDialog->setCurrentFile(file);
+ fileDialog->setSelectedFile(file);
else if (folderDialog)
folderDialog->setSelectedFolder(file);
}
diff --git a/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl.cpp b/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl.cpp
index 85fe0d37e7..64c624b5ec 100644
--- a/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl.cpp
+++ b/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl.cpp
@@ -52,6 +52,7 @@
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcCurrentFolder, "qt.quick.dialogs.quickfiledialogimpl.currentFolder")
+Q_LOGGING_CATEGORY(lcUpdateSelectedFile, "qt.quick.dialogs.quickfiledialogimpl.updateSelectedFile")
Q_LOGGING_CATEGORY(lcOptions, "qt.quick.dialogs.quickfiledialogimpl.options")
Q_LOGGING_CATEGORY(lcNameFilters, "qt.quick.dialogs.quickfiledialogimpl.namefilters")
Q_LOGGING_CATEGORY(lcAttachedNameFilters, "qt.quick.dialogs.quickfiledialogimplattached.namefilters")
@@ -83,7 +84,7 @@ void QQuickFileDialogImplPrivate::updateEnabled()
return;
}
- openButton->setEnabled(!currentFile.isEmpty() && attached->breadcrumbBar()
+ openButton->setEnabled(!selectedFile.isEmpty() && attached->breadcrumbBar()
&& !attached->breadcrumbBar()->textField()->isVisible());
}
@@ -94,22 +95,22 @@ void QQuickFileDialogImplPrivate::updateEnabled()
\a oldFolderPath is the previous value of \c folder.
*/
-void QQuickFileDialogImplPrivate::updateCurrentFile(const QString &oldFolderPath)
+void QQuickFileDialogImplPrivate::updateSelectedFile(const QString &oldFolderPath)
{
Q_Q(QQuickFileDialogImpl);
QQuickFileDialogImplAttached *attached = attachedOrWarn();
if (!attached || !attached->fileDialogListView())
return;
- QString newCurrentFilePath;
- int newCurrentFileIndex = 0;
+ QString newSelectedFilePath;
+ int newSelectedFileIndex = 0;
const QString newFolderPath = QQmlFile::urlToLocalFileOrQrc(currentFolder);
if (!oldFolderPath.isEmpty() && !newFolderPath.isEmpty()) {
// If the user went up a directory (or several), we should set
- // currentFile to be the directory that we were in (or
+ // selectedFile to be the directory that we were in (or
// its closest ancestor that is a child of the new directory).
// E.g. if oldFolderPath is /foo/bar/baz/abc/xyz, and newFolderPath is /foo/bar,
- // then we want to set currentFile to be /foo/bar/baz.
+ // then we want to set selectedFile to be /foo/bar/baz.
const int indexOfFolder = oldFolderPath.indexOf(newFolderPath);
if (indexOfFolder != -1) {
// [folder]
@@ -117,24 +118,24 @@ void QQuickFileDialogImplPrivate::updateCurrentFile(const QString &oldFolderPath
// /foo/bar/baz/abc/xyz
// [rel...Paths]
QStringList relativePaths = oldFolderPath.mid(indexOfFolder + newFolderPath.size()).split(QLatin1Char('/'), Qt::SkipEmptyParts);
- newCurrentFilePath = newFolderPath + QLatin1Char('/') + relativePaths.first();
+ newSelectedFilePath = newFolderPath + QLatin1Char('/') + relativePaths.first();
// Now find the index of that directory so that we can set the ListView's currentIndex to it.
const QDir newFolderDir(newFolderPath);
// Just to be safe...
if (!newFolderDir.exists()) {
- qmlWarning(q) << "Directory" << newCurrentFilePath << "doesn't exist; can't get a file entry list for it";
+ qmlWarning(q) << "Directory" << newSelectedFilePath << "doesn't exist; can't get a file entry list for it";
return;
}
const QFileInfoList dirs = newFolderDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::DirsFirst);
- const QFileInfo newCurrentFileInfo(newCurrentFilePath);
+ const QFileInfo newSelectedFileInfo(newSelectedFilePath);
// The directory can contain files, but since we put dirs first, that should never affect the indices.
- newCurrentFileIndex = dirs.indexOf(newCurrentFileInfo);
+ newSelectedFileIndex = dirs.indexOf(newSelectedFileInfo);
}
}
- if (newCurrentFilePath.isEmpty()) {
+ if (newSelectedFilePath.isEmpty()) {
// When entering into a directory that isn't a parent of the old one, the first
// file delegate should be selected.
// TODO: is there a cheaper way to do this? QDirIterator doesn't support sorting,
@@ -145,13 +146,15 @@ void QQuickFileDialogImplPrivate::updateCurrentFile(const QString &oldFolderPath
if (newFolderDir.exists()) {
const QFileInfoList files = newFolderDir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::DirsFirst);
if (!files.isEmpty())
- newCurrentFilePath = files.first().absoluteFilePath();
+ newSelectedFilePath = files.first().absoluteFilePath();
}
}
- if (!newCurrentFilePath.isEmpty()) {
- q->setCurrentFile(QUrl::fromLocalFile(newCurrentFilePath));
- attached->fileDialogListView()->setCurrentIndex(newCurrentFileIndex);
+ const QUrl newSelectedFileUrl = QUrl::fromLocalFile(newSelectedFilePath);
+ qCDebug(lcUpdateSelectedFile) << "updateSelectedFile is setting selectedFile to" << newSelectedFileUrl;
+ q->setSelectedFile(newSelectedFileUrl);
+ if (!newSelectedFilePath.isEmpty()) {
+ attached->fileDialogListView()->setCurrentIndex(newSelectedFileIndex);
if (QQuickItem *currentItem = attached->fileDialogListView()->currentItem())
currentItem->forceActiveFocus();
}
@@ -165,19 +168,19 @@ void QQuickFileDialogImplPrivate::handleAccept()
void QQuickFileDialogImplPrivate::handleClick(QQuickAbstractButton *button)
{
Q_Q(QQuickFileDialogImpl);
- if (buttonRole(button) == QPlatformDialogHelper::AcceptRole && currentFile.isValid()) {
+ if (buttonRole(button) == QPlatformDialogHelper::AcceptRole && selectedFile.isValid()) {
// The "Open" button was clicked, so we need to set the file to the current file, if any.
- const QFileInfo fileInfo(currentFile.toLocalFile());
+ const QFileInfo fileInfo(selectedFile.toLocalFile());
if (fileInfo.isDir()) {
// If it's a directory, navigate to it.
- q->setCurrentFolder(currentFile);
+ q->setCurrentFolder(selectedFile);
// Don't call accept(), because selecting a folder != accepting the dialog.
} else {
// Otherwise it's a file, so select it and close the dialog.
- q->setSelectedFile(currentFile);
+ q->setSelectedFile(selectedFile);
q->accept();
QQuickDialogPrivate::handleClick(button);
- emit q->fileSelected(currentFile);
+ emit q->fileSelected(selectedFile);
}
}
}
@@ -209,8 +212,7 @@ void QQuickFileDialogImpl::setCurrentFolder(const QUrl &currentFolder)
d->currentFolder = currentFolder;
// Since the directory changed, the old file can no longer be selected.
- setCurrentFile(QUrl());
- d->updateCurrentFile(oldFolderPath);
+ d->updateSelectedFile(oldFolderPath);
emit currentFolderChanged(d->currentFolder);
}
@@ -227,24 +229,8 @@ void QQuickFileDialogImpl::setSelectedFile(const QUrl &selectedFile)
return;
d->selectedFile = selectedFile;
- emit selectedFileChanged();
-}
-
-QUrl QQuickFileDialogImpl::currentFile() const
-{
- Q_D(const QQuickFileDialogImpl);
- return d->currentFile;
-}
-
-void QQuickFileDialogImpl::setCurrentFile(const QUrl &currentFile)
-{
- Q_D(QQuickFileDialogImpl);
- if (currentFile == d->currentFile)
- return;
-
- d->currentFile = currentFile;
d->updateEnabled();
- emit currentFileChanged(d->currentFile);
+ emit selectedFileChanged(d->selectedFile);
}
QSharedPointer<QFileDialogOptions> QQuickFileDialogImpl::options() const
@@ -432,7 +418,7 @@ void QQuickFileDialogImplAttachedPrivate::fileDialogListViewCurrentIndexChanged(
if (!fileDialogDelegate)
return;
- fileDialogImpl->setCurrentFile(fileDialogDelegate->file());
+ fileDialogImpl->setSelectedFile(fileDialogDelegate->file());
}
QQuickFileDialogImplAttached::QQuickFileDialogImplAttached(QObject *parent)
diff --git a/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl_p.h b/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl_p.h
index 4a9668000f..c2bcee0f65 100644
--- a/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl_p.h
+++ b/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl_p.h
@@ -72,7 +72,6 @@ class Q_QUICKDIALOGS2QUICKIMPL_PRIVATE_EXPORT QQuickFileDialogImpl : public QQui
Q_OBJECT
Q_PROPERTY(QUrl currentFolder READ currentFolder WRITE setCurrentFolder NOTIFY currentFolderChanged FINAL)
Q_PROPERTY(QUrl selectedFile READ selectedFile WRITE setSelectedFile NOTIFY selectedFileChanged FINAL)
- Q_PROPERTY(QUrl currentFile READ currentFile WRITE setCurrentFile NOTIFY currentFileChanged FINAL)
Q_PROPERTY(QStringList nameFilters READ nameFilters NOTIFY nameFiltersChanged FINAL)
Q_PROPERTY(QQuickFileNameFilter *selectedNameFilter READ selectedNameFilter CONSTANT)
QML_NAMED_ELEMENT(FileDialogImpl)
@@ -92,9 +91,6 @@ public:
QUrl selectedFile() const;
void setSelectedFile(const QUrl &file);
- QUrl currentFile() const;
- void setCurrentFile(const QUrl &currentFile);
-
QSharedPointer<QFileDialogOptions> options() const;
void setOptions(const QSharedPointer<QFileDialogOptions> &options);
@@ -111,8 +107,7 @@ public Q_SLOTS:
Q_SIGNALS:
void currentFolderChanged(const QUrl &folderUrl);
- void selectedFileChanged();
- void currentFileChanged(const QUrl &currentFileUrl);
+ void selectedFileChanged(const QUrl &selectedFileUrl);
void nameFiltersChanged();
void fileSelected(const QUrl &fileUrl);
void filterSelected(const QString &filter);
diff --git a/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl_p_p.h b/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl_p_p.h
index b7ecdcdeeb..d2336e9aa1 100644
--- a/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl_p_p.h
+++ b/src/quickdialogs2/quickdialogs2quickimpl/qquickfiledialogimpl_p_p.h
@@ -78,7 +78,7 @@ public:
void setNameFilters(const QStringList &filters);
void updateEnabled();
- void updateCurrentFile(const QString &oldFolderPath);
+ void updateSelectedFile(const QString &oldFolderPath);
void handleAccept() override;
void handleClick(QQuickAbstractButton *button) override;
@@ -86,7 +86,6 @@ public:
QSharedPointer<QFileDialogOptions> options;
QUrl currentFolder;
QUrl selectedFile;
- QUrl currentFile;
QStringList nameFilters;
mutable QQuickFileNameFilter *selectedNameFilter = nullptr;
QString acceptLabel;
diff --git a/src/quickdialogs2/quickdialogs2quickimpl/qquickfolderbreadcrumbbar.cpp b/src/quickdialogs2/quickdialogs2quickimpl/qquickfolderbreadcrumbbar.cpp
index fb182e2d55..c639f2a9fd 100644
--- a/src/quickdialogs2/quickdialogs2quickimpl/qquickfolderbreadcrumbbar.cpp
+++ b/src/quickdialogs2/quickdialogs2quickimpl/qquickfolderbreadcrumbbar.cpp
@@ -319,13 +319,8 @@ void QQuickFolderBreadcrumbBarPrivate::textFieldAccepted()
setDialogFolder(fileUrl);
} else if (!enteredPathIsDir && (enteredPathExists || !mustExist)) {
qCDebug(lcTextInput) << "path entered is a file; setting file and calling accept()";
- // It's important that we set the currentFile here, as that's what
- // QQuickPlatformFileDialog::selectedFiles() needs to return, and
- // QQuickFileDialog::accept() sets its file property based on
- // selectedFiles().
if (isFileDialog()) {
auto fileDialog = asFileDialog();
- fileDialog->setCurrentFile(fileUrl);
fileDialog->setSelectedFile(fileUrl);
fileDialog->accept();
} else {
diff --git a/src/quickdialogs2/quickdialogs2quickimpl/qquickplatformfiledialog.cpp b/src/quickdialogs2/quickdialogs2quickimpl/qquickplatformfiledialog.cpp
index 2e301da4bd..1d5412b0f8 100644
--- a/src/quickdialogs2/quickdialogs2quickimpl/qquickplatformfiledialog.cpp
+++ b/src/quickdialogs2/quickdialogs2quickimpl/qquickplatformfiledialog.cpp
@@ -103,7 +103,7 @@ QQuickPlatformFileDialog::QQuickPlatformFileDialog(QObject *parent)
// urls += QUrl::fromLocalFile(file);
// emit filesSelected(urls);
// });
- connect(m_dialog, &QQuickFileDialogImpl::currentFileChanged, this, &QQuickPlatformFileDialog::currentChanged);
+ connect(m_dialog, &QQuickFileDialogImpl::selectedFileChanged, this, &QQuickPlatformFileDialog::currentChanged);
connect(m_dialog, &QQuickFileDialogImpl::currentFolderChanged, this, &QQuickPlatformFileDialog::directoryEntered);
connect(m_dialog, &QQuickFileDialogImpl::filterSelected, this, &QQuickPlatformFileDialog::filterSelected);
@@ -150,7 +150,7 @@ void QQuickPlatformFileDialog::selectFile(const QUrl &file)
QList<QUrl> QQuickPlatformFileDialog::selectedFiles() const
{
// TODO: support for multiple selected files
- return { m_dialog->currentFile() };
+ return { m_dialog->selectedFile() };
}
void QQuickPlatformFileDialog::setFilter()
diff --git a/tests/auto/quickdialogs/qquickfiledialogimpl/tst_qquickfiledialogimpl.cpp b/tests/auto/quickdialogs/qquickfiledialogimpl/tst_qquickfiledialogimpl.cpp
index 83163c4285..e70c7e7171 100644
--- a/tests/auto/quickdialogs/qquickfiledialogimpl/tst_qquickfiledialogimpl.cpp
+++ b/tests/auto/quickdialogs/qquickfiledialogimpl/tst_qquickfiledialogimpl.cpp
@@ -203,11 +203,11 @@ void tst_QQuickFileDialogImpl::defaults()
QQuickFileDialogImpl *quickDialog = window->findChild<QQuickFileDialogImpl*>();
QTRY_VERIFY(quickDialog->isOpened());
QVERIFY(quickDialog);
- COMPARE_URL(quickDialog->selectedFile(), QUrl());
COMPARE_URL(quickDialog->currentFolder(), QUrl::fromLocalFile(QDir().absolutePath()));
- COMPARE_URL(dialog->currentFile(), QUrl::fromLocalFile(tempSubDir.path()));
- COMPARE_URLS(dialog->currentFiles(), { QUrl::fromLocalFile(tempSubDir.path()) });
- COMPARE_URL(quickDialog->currentFile(), QUrl::fromLocalFile(tempSubDir.path()));
+ COMPARE_URL(dialog->selectedFile(), QUrl::fromLocalFile(tempSubDir.path()));
+ COMPARE_URLS(dialog->selectedFiles(), { QUrl::fromLocalFile(tempSubDir.path()) });
+ COMPARE_URL(dialog->currentFile(), dialog->selectedFile());
+ COMPARE_URLS(dialog->currentFiles(), dialog->selectedFiles());
QCOMPARE(quickDialog->title(), QString());
}
@@ -221,12 +221,10 @@ void tst_QQuickFileDialogImpl::chooseFileViaStandardButtons()
QTRY_VERIFY(dialogHelper.isQuickDialogOpen());
// Select the delegate by clicking once.
- QSignalSpy dialogFileChangedSpy(dialogHelper.dialog, SIGNAL(selectedFileChanged()));
- QVERIFY(dialogFileChangedSpy.isValid());
+ QSignalSpy dialogSelectedFileChangedSpy(dialogHelper.dialog, SIGNAL(selectedFileChanged()));
+ QVERIFY(dialogSelectedFileChangedSpy.isValid());
QSignalSpy dialogCurrentFileChangedSpy(dialogHelper.dialog, SIGNAL(currentFileChanged()));
QVERIFY(dialogCurrentFileChangedSpy.isValid());
- QSignalSpy quickDialogCurrentFileChangedSpy(dialogHelper.quickDialog, SIGNAL(currentFileChanged(const QUrl &)));
- QVERIFY(quickDialogCurrentFileChangedSpy.isValid());
auto fileDialogListView = dialogHelper.quickDialog->findChild<QQuickListView*>("fileDialogListView");
QVERIFY(fileDialogListView);
@@ -234,13 +232,12 @@ void tst_QQuickFileDialogImpl::chooseFileViaStandardButtons()
QTRY_VERIFY(findViewDelegateItem(fileDialogListView, 2, delegate));
COMPARE_URL(delegate->file(), QUrl::fromLocalFile(tempFile2->fileName()));
QVERIFY(clickButton(delegate));
- COMPARE_URL(dialogHelper.quickDialog->currentFile(), QUrl::fromLocalFile(tempFile2->fileName()));
- COMPARE_URL(dialogHelper.dialog->currentFile(), QUrl::fromLocalFile(tempFile2->fileName()));
- COMPARE_URLS(dialogHelper.dialog->currentFiles(), { QUrl::fromLocalFile(tempFile2->fileName()) });
- // Only currentFile-related signals should be emitted.
- QCOMPARE(dialogFileChangedSpy.count(), 0);
+ COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempFile2->fileName()));
+ COMPARE_URL(dialogHelper.quickDialog->selectedFile(), QUrl::fromLocalFile(tempFile2->fileName()));
+ COMPARE_URL(dialogHelper.dialog->currentFile(), dialogHelper.dialog->selectedFile());
+ COMPARE_URLS(dialogHelper.dialog->currentFiles(), { dialogHelper.dialog->selectedFile() });
+ QCOMPARE(dialogSelectedFileChangedSpy.count(), 1);
QCOMPARE(dialogCurrentFileChangedSpy.count(), 1);
- QCOMPARE(quickDialogCurrentFileChangedSpy.count(), 1);
// Click the "Open" button.
QVERIFY(dialogHelper.quickDialog->footer());
@@ -251,8 +248,9 @@ void tst_QQuickFileDialogImpl::chooseFileViaStandardButtons()
QVERIFY(clickButton(openButton));
COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempFile2->fileName()));
COMPARE_URLS(dialogHelper.dialog->selectedFiles(), { QUrl::fromLocalFile(tempFile2->fileName()) });
- QCOMPARE(dialogFileChangedSpy.count(), 1);
COMPARE_URL(dialogHelper.quickDialog->selectedFile(), QUrl::fromLocalFile(tempFile2->fileName()));
+ QCOMPARE(dialogSelectedFileChangedSpy.count(), 1);
+ QCOMPARE(dialogCurrentFileChangedSpy.count(), 1);
QTRY_VERIFY(!dialogHelper.quickDialog->isVisible());
QVERIFY(!dialogHelper.dialog->isVisible());
}
@@ -407,13 +405,12 @@ void tst_QQuickFileDialogImpl::changeFolderViaStandardButtons()
QTRY_VERIFY(findViewDelegateItem(fileDialogListView, 0, delegate));
COMPARE_URL(delegate->file(), QUrl::fromLocalFile(tempSubDir.path()));
QVERIFY(clickButton(delegate));
- // The selectedFile and currentFolder shouldn't change yet.
- COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl());
- COMPARE_URLS(dialogHelper.dialog->selectedFiles(), {});
+ // The selectedFile should change, but not currentFolder.
+ COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempSubDir.path()));
+ COMPARE_URLS(dialogHelper.dialog->selectedFiles(), { QUrl::fromLocalFile(tempSubDir.path()) });
+ COMPARE_URL(dialogHelper.dialog->currentFile(), dialogHelper.dialog->selectedFile());
+ COMPARE_URLS(dialogHelper.dialog->currentFiles(), dialogHelper.dialog->selectedFiles());
COMPARE_URL(dialogHelper.dialog->currentFolder(), QUrl::fromLocalFile(tempDir.path()));
- // The currentFile should, though.
- COMPARE_URL(dialogHelper.dialog->currentFile(), QUrl::fromLocalFile(tempSubDir.path()));
- COMPARE_URLS(dialogHelper.dialog->currentFiles(), { QUrl::fromLocalFile(tempSubDir.path()) });
// Click the "Open" button. The dialog should navigate to that directory, but still be open.
QVERIFY(dialogHelper.quickDialog->footer());
@@ -422,7 +419,7 @@ void tst_QQuickFileDialogImpl::changeFolderViaStandardButtons()
QQuickAbstractButton* openButton = findDialogButton(dialogButtonBox, "Open");
QVERIFY(openButton);
QVERIFY(clickButton(openButton));
- COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl());
+ COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempSubSubDir.path()));
COMPARE_URL(dialogHelper.dialog->currentFolder(), QUrl::fromLocalFile(tempSubDir.path()));
QVERIFY(dialogHelper.dialog->isVisible());
@@ -448,13 +445,15 @@ void tst_QQuickFileDialogImpl::changeFolderViaDoubleClick()
COMPARE_URL(subDirDelegate->file(), QUrl::fromLocalFile(tempSubDir.path()));
QVERIFY(doubleClickButton(subDirDelegate));
// The first file in the directory should be selected, which is "sub-sub-dir".
- COMPARE_URL(dialogHelper.dialog->currentFile(), QUrl::fromLocalFile(tempSubSubDir.path()));
- COMPARE_URLS(dialogHelper.dialog->currentFiles(), { QUrl::fromLocalFile(tempSubSubDir.path()) });
+ COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempSubSubDir.path()));
+ COMPARE_URLS(dialogHelper.dialog->selectedFiles(), { QUrl::fromLocalFile(tempSubSubDir.path()) });
+ COMPARE_URL(dialogHelper.dialog->currentFile(), dialogHelper.dialog->selectedFile());
+ COMPARE_URLS(dialogHelper.dialog->currentFiles(), { dialogHelper.dialog->selectedFiles() });
QQuickFileDialogDelegate *subSubDirDelegate = nullptr;
QTRY_VERIFY(findViewDelegateItem(fileDialogListView, 0, subSubDirDelegate));
QCOMPARE(subSubDirDelegate->isHighlighted(), true);
- COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl());
- COMPARE_URLS(dialogHelper.dialog->selectedFiles(), {});
+ COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempSubSubDir.path()));
+ COMPARE_URLS(dialogHelper.dialog->selectedFiles(), { QUrl::fromLocalFile(tempSubSubDir.path()) });
COMPARE_URL(dialogHelper.dialog->currentFolder(), QUrl::fromLocalFile(tempSubDir.path()));
// Since we only chose a folder, the dialog should still be open.
QVERIFY(dialogHelper.dialog->isVisible());
@@ -489,14 +488,14 @@ void tst_QQuickFileDialogImpl::chooseFolderViaTextEdit()
// Hit enter to accept.
QTest::keyClick(dialogHelper.window(), Qt::Key_Return);
// The first file in the directory should be selected, which is "sub-sub-dir".
- COMPARE_URL(dialogHelper.dialog->currentFile(), QUrl::fromLocalFile(tempSubSubDir.path()));
+ COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempSubSubDir.path()));
auto fileDialogListView = dialogHelper.quickDialog->findChild<QQuickListView*>("fileDialogListView");
QVERIFY(fileDialogListView);
QQuickFileDialogDelegate *subSubDirDelegate = nullptr;
QTRY_VERIFY(findViewDelegateItem(fileDialogListView, 0, subSubDirDelegate));
QCOMPARE(subSubDirDelegate->isHighlighted(), true);
- COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl());
- COMPARE_URLS(dialogHelper.dialog->selectedFiles(), {});
+ COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempSubSubDir.path()));
+ COMPARE_URLS(dialogHelper.dialog->selectedFiles(), { QUrl::fromLocalFile(tempSubSubDir.path()) });
COMPARE_URL(dialogHelper.dialog->currentFolder(), QUrl::fromLocalFile(tempSubDir.path()));
QTRY_VERIFY(dialogHelper.dialog->isVisible());
@@ -590,15 +589,15 @@ void tst_QQuickFileDialogImpl::chooseFileAndThenFolderViaTextEdit()
// Hit enter to accept.
QTest::keyClick(dialogHelper.window(), Qt::Key_Return);
// The first file in the directory should be selected, which is "sub-sub-dir".
- COMPARE_URL(dialogHelper.dialog->currentFile(), QUrl::fromLocalFile(tempSubSubDir.path()));
+ COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempSubSubDir.path()));
auto fileDialogListView = dialogHelper.quickDialog->findChild<QQuickListView*>("fileDialogListView");
QVERIFY(fileDialogListView);
QQuickFileDialogDelegate *subSubDirDelegate = nullptr;
QTRY_VERIFY(findViewDelegateItem(fileDialogListView, 0, subSubDirDelegate));
QCOMPARE(subSubDirDelegate->isHighlighted(), true);
// We just changed directories, so the actual selected file shouldn't change.
- COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempFile2->fileName()));
- COMPARE_URLS(dialogHelper.dialog->selectedFiles(), { QUrl::fromLocalFile(tempFile2->fileName()) });
+ COMPARE_URL(dialogHelper.dialog->selectedFile(), QUrl::fromLocalFile(tempSubSubDir.path()));
+ COMPARE_URLS(dialogHelper.dialog->selectedFiles(), { QUrl::fromLocalFile(tempSubSubDir.path()) });
COMPARE_URL(dialogHelper.dialog->currentFolder(), QUrl::fromLocalFile(tempSubDir.path()));
QTRY_VERIFY(dialogHelper.dialog->isVisible());