FileDialog: set url schema when using the file name text field
When using the text field to choose a file name inside the non-native
file dialog, the selectedFile property would be updated based on the
currentFolder property and what the newly typed filename was.
However, the schema was ignored.
This patch fixes the issue by also setting the schema in
QQuickFileDialogImpl::setFileName(const QString &fileName).
Fixes: QTBUG-120065
Pick-to: 6.6 6.5
Change-Id: I1860fbbc8209270d0bc6e34a4be6a91bad2253ab
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
(cherry picked from commit 26d9634468
)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
8f2aa4de88
commit
f839b0ae73
|
@ -504,7 +504,10 @@ void QQuickFileDialogImpl::setFileName(const QString &fileName)
|
|||
if (previous == fileName)
|
||||
return;
|
||||
|
||||
setSelectedFile(QUrl(currentFolder().path() + u'/' + fileName));
|
||||
QUrl newSelectedFile;
|
||||
newSelectedFile.setScheme(currentFolder().scheme());
|
||||
newSelectedFile.setPath(currentFolder().path() + u'/' + fileName);
|
||||
setSelectedFile(newSelectedFile);
|
||||
}
|
||||
|
||||
QString QQuickFileDialogImpl::currentFolderName() const
|
||||
|
|
|
@ -91,6 +91,7 @@ private slots:
|
|||
void selectNewFileViaTextField();
|
||||
void selectExistingFileShouldWarnUserWhenFileModeEqualsSaveFile();
|
||||
void fileNameTextFieldOnlyChangesWhenSelectingFiles();
|
||||
void setSchemeForSelectedFile();
|
||||
|
||||
private:
|
||||
enum DelegateOrderPolicy
|
||||
|
@ -1614,6 +1615,47 @@ void tst_QQuickFileDialogImpl::fileNameTextFieldOnlyChangesWhenSelectingFiles()
|
|||
QCOMPARE(dialogHelper.dialog->selectedFile(), tempFile11Url);
|
||||
}
|
||||
|
||||
void tst_QQuickFileDialogImpl::setSchemeForSelectedFile()
|
||||
{
|
||||
const auto tempSubFile1Url = QUrl::fromLocalFile(tempSubFile1->fileName());
|
||||
|
||||
const QVariantMap initialProperties = {
|
||||
{ "tempFile1Url", QVariant::fromValue(tempSubFile1Url) },
|
||||
{ "fileMode", QVariant::fromValue(QQuickFileDialog::SaveFile) }
|
||||
};
|
||||
FileDialogTestHelper dialogHelper(this, "setSelectedFile.qml", {}, initialProperties);
|
||||
|
||||
OPEN_QUICK_DIALOG();
|
||||
QQuickTest::qWaitForPolish(dialogHelper.window());
|
||||
|
||||
QQuickTextField *fileNameTextField =
|
||||
dialogHelper.quickDialog->findChild<QQuickTextField *>("fileNameTextField");
|
||||
QVERIFY(fileNameTextField);
|
||||
|
||||
QVERIFY(!tempSubFile1Url.scheme().isEmpty());
|
||||
QVERIFY(!dialogHelper.dialog->selectedFile().scheme().isEmpty());
|
||||
QCOMPARE(tempSubFile1Url, dialogHelper.dialog->selectedFile());
|
||||
|
||||
fileNameTextField->clear();
|
||||
|
||||
const QPoint textFieldCenterPos =
|
||||
fileNameTextField->mapToScene({ fileNameTextField->width() / 2, fileNameTextField->height() / 2 }).toPoint();
|
||||
QTest::mouseClick(dialogHelper.window(), Qt::LeftButton, Qt::NoModifier, textFieldCenterPos);
|
||||
|
||||
const QByteArray newFileName("helloworld.txt");
|
||||
for (const auto &c : newFileName)
|
||||
QTest::keyClick(dialogHelper.window(), c);
|
||||
QTest::keyClick(dialogHelper.window(), Qt::Key_Enter, Qt::NoModifier);
|
||||
|
||||
QTRY_COMPARE(fileNameTextField->text(), QString::fromLatin1(newFileName));
|
||||
|
||||
const auto newFilePath =
|
||||
QUrl::fromLocalFile(QFileInfo(tempSubFile1Url.toLocalFile()).dir().absolutePath() + u'/' + newFileName);
|
||||
QVERIFY(!newFilePath.scheme().isEmpty());
|
||||
QVERIFY(!dialogHelper.dialog->selectedFile().scheme().isEmpty());
|
||||
QCOMPARE(dialogHelper.dialog->selectedFile(), newFilePath);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QQuickFileDialogImpl)
|
||||
|
||||
#include "tst_qquickfiledialogimpl.moc"
|
||||
|
|
Loading…
Reference in New Issue