QFileDialog: Return empty QUrl from the static get..FileUrl() functions.
Task-number: QTBUG-38672 Change-Id: Idf554cd93d1a79db7c82f3165bd128fb31ead3e5 Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
a17aaed1cd
commit
d915432c23
@ -2128,6 +2128,11 @@ QString QFileDialog::getOpenFileName(QWidget *parent,
|
||||
return QString();
|
||||
}
|
||||
|
||||
static inline QUrl dialogResultToUrl(const QString &file)
|
||||
{
|
||||
return file.isEmpty() ? QUrl() : QUrl::fromLocalFile(file);
|
||||
}
|
||||
|
||||
/*!
|
||||
This is a convenience static function that returns an existing file
|
||||
selected by the user. If the user presses Cancel, it returns an
|
||||
@ -2166,7 +2171,7 @@ QUrl QFileDialog::getOpenFileUrl(QWidget *parent,
|
||||
Q_UNUSED(supportedSchemes);
|
||||
|
||||
// Falls back to local file
|
||||
return QUrl::fromLocalFile(getOpenFileName(parent, caption, dir.toLocalFile(), filter, selectedFilter, options));
|
||||
return dialogResultToUrl(getOpenFileName(parent, caption, dir.toLocalFile(), filter, selectedFilter, options));
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -2424,7 +2429,7 @@ QUrl QFileDialog::getSaveFileUrl(QWidget *parent,
|
||||
Q_UNUSED(supportedSchemes);
|
||||
|
||||
// Falls back to local file
|
||||
return QUrl::fromLocalFile(getSaveFileName(parent, caption, dir.toLocalFile(), filter, selectedFilter, options));
|
||||
return dialogResultToUrl(getSaveFileName(parent, caption, dir.toLocalFile(), filter, selectedFilter, options));
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -2532,7 +2537,7 @@ QUrl QFileDialog::getExistingDirectoryUrl(QWidget *parent,
|
||||
Q_UNUSED(supportedSchemes);
|
||||
|
||||
// Falls back to local file
|
||||
return QUrl::fromLocalFile(getExistingDirectory(parent, caption, dir.toLocalFile(), options));
|
||||
return dialogResultToUrl(getExistingDirectory(parent, caption, dir.toLocalFile(), options));
|
||||
}
|
||||
|
||||
inline static QString _qt_get_directory(const QString &path)
|
||||
|
@ -171,6 +171,7 @@ private slots:
|
||||
void tildeExpansion();
|
||||
#endif // QT_BUILD_INTERNAL
|
||||
#endif
|
||||
void getFileUrl();
|
||||
|
||||
private:
|
||||
QByteArray userSettings;
|
||||
@ -1429,5 +1430,49 @@ void tst_QFiledialog::tildeExpansion()
|
||||
#endif // QT_BUILD_INTERNAL
|
||||
#endif
|
||||
|
||||
class DialogRejecter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DialogRejecter()
|
||||
{
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setInterval(1000);
|
||||
connect(timer, &QTimer::timeout, this, &DialogRejecter::rejectFileDialog);
|
||||
timer->start();
|
||||
}
|
||||
|
||||
public slots:
|
||||
void rejectFileDialog()
|
||||
{
|
||||
if (QWidget *w = QApplication::activeModalWidget())
|
||||
if (QDialog *d = qobject_cast<QDialog *>(w))
|
||||
d->reject();
|
||||
}
|
||||
};
|
||||
|
||||
void tst_QFiledialog::getFileUrl()
|
||||
{
|
||||
// QTBUG-38672 , static functions should return empty Urls
|
||||
const QFileDialog::Options options = QFileDialog::DontUseNativeDialog;
|
||||
DialogRejecter dr;
|
||||
|
||||
QUrl url = QFileDialog::getOpenFileUrl(0, QStringLiteral("getOpenFileUrl"),
|
||||
QUrl(), QString(), Q_NULLPTR, options);
|
||||
QVERIFY(url.isEmpty());
|
||||
QVERIFY(!url.isValid());
|
||||
|
||||
url = QFileDialog::getExistingDirectoryUrl(0, QStringLiteral("getExistingDirectoryUrl"),
|
||||
QUrl(), options | QFileDialog::ShowDirsOnly);
|
||||
QVERIFY(url.isEmpty());
|
||||
QVERIFY(!url.isValid());
|
||||
|
||||
url = QFileDialog::getSaveFileUrl(0, QStringLiteral("getSaveFileUrl"),
|
||||
QUrl(), QString(), Q_NULLPTR, options);
|
||||
QVERIFY(url.isEmpty());
|
||||
QVERIFY(!url.isValid());
|
||||
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QFiledialog)
|
||||
#include "tst_qfiledialog.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user