Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:13.2
libqt5-qtbase
0002-QUrl-fromLocalFile-QString-should-lead-to-...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0002-QUrl-fromLocalFile-QString-should-lead-to-an-empty-U.patch of Package libqt5-qtbase
From 18bb76b3b27edf8d980e414bc2b91c44ad80aab2 Mon Sep 17 00:00:00 2001 From: David Faure <david.faure@kdab.com> Date: Wed, 9 Jul 2014 15:03:35 +0200 Subject: [PATCH 2/4] QUrl: fromLocalFile(QString()) should lead to an empty URL. This is much more useful than the URL "file:", it allows to use "empty path" and "empty URL" for the same meaning (e.g. not set). QFileDialog actually uses "file:" though, as the URL for the "My Computer" item in the sidebar. This patch preserves that. [ChangeLog][QtCore][QUrl] QUrl::fromLocalFile now returns an empty URL if the input string is empty. Change-Id: Ib5ce1a3cdf5f229368e5bcd83c62c1d1ac9f8a17 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit fd331a5b3a122393cd697a8b856dd52cfd31d698) --- src/corelib/io/qurl.cpp | 4 ++++ src/widgets/dialogs/qfiledialog.cpp | 4 ++-- src/widgets/dialogs/qsidebar.cpp | 3 ++- tests/auto/corelib/io/qurl/tst_qurl.cpp | 5 +++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index c109fc4..00ffc4f 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -3714,11 +3714,15 @@ bool QUrl::isDetached() const "//servername/path/to/file.txt". Note that only certain platforms can actually open this file using QFile::open(). + An empty \a localFile leads to an empty URL (since Qt 5.4). + \sa toLocalFile(), isLocalFile(), QDir::toNativeSeparators() */ QUrl QUrl::fromLocalFile(const QString &localFile) { QUrl url; + if (localFile.isEmpty()) + return url; url.setScheme(fileScheme()); QString deslashified = QDir::fromNativeSeparators(localFile); diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 037964b..82a4a4c 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -2783,7 +2783,7 @@ void QFileDialogPrivate::createWidgets() qFileDialogUi->setupUi(q); QList<QUrl> initialBookmarks; - initialBookmarks << QUrl::fromLocalFile(QLatin1String("")) + initialBookmarks << QUrl(QLatin1String("file:")) << QUrl::fromLocalFile(QDir::homePath()); qFileDialogUi->sidebar->setModelAndUrls(model, initialBookmarks); QFileDialog::connect(qFileDialogUi->sidebar, SIGNAL(goToUrl(QUrl)), @@ -3760,7 +3760,7 @@ void QFileDialogComboBox::showPopup() idx = idx.parent(); } // add "my computer" - list.append(QUrl::fromLocalFile(QLatin1String(""))); + list.append(QUrl(QLatin1String("file:"))); urlModel->addUrls(list, 0); idx = model()->index(model()->rowCount() - 1, 0); diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp index 3d22992..7b691dc 100644 --- a/src/widgets/dialogs/qsidebar.cpp +++ b/src/widgets/dialogs/qsidebar.cpp @@ -249,7 +249,8 @@ void QUrlModel::addUrls(const QList<QUrl> &list, int row, bool move) continue; //this makes sure the url is clean const QString cleanUrl = QDir::cleanPath(url.toLocalFile()); - url = QUrl::fromLocalFile(cleanUrl); + if (!cleanUrl.isEmpty()) + url = QUrl::fromLocalFile(cleanUrl); for (int j = 0; move && j < rowCount(); ++j) { QString local = index(j, 0).data(UrlRole).toUrl().toLocalFile(); diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index d5eab54..b8bab87 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -235,6 +235,11 @@ void tst_QUrl::constructing() QVERIFY(url == url); QVERIFY(!(url < url)); + QUrl fromLocal = QUrl::fromLocalFile(QString()); + QVERIFY(!fromLocal.isValid()); + QVERIFY(fromLocal.isEmpty()); + QCOMPARE(fromLocal.toString(), QString()); + QUrl justHost("qt-project.org"); QVERIFY(!justHost.isEmpty()); QVERIFY(justHost.host().isEmpty()); -- 2.1.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor