diff --git a/autotests/kurlnavigatortest.h b/autotests/kurlnavigatortest.h --- a/autotests/kurlnavigatortest.h +++ b/autotests/kurlnavigatortest.h @@ -43,6 +43,7 @@ void testButtonUrl_data(); void testButtonUrl(); + void testButtonText(); void testInitWithRedundantPathSeparators(); diff --git a/autotests/kurlnavigatortest.cpp b/autotests/kurlnavigatortest.cpp --- a/autotests/kurlnavigatortest.cpp +++ b/autotests/kurlnavigatortest.cpp @@ -20,15 +20,19 @@ #include "kurlnavigatortest.h" #include #include +#include +#include #include +#include #include "kurlnavigator.h" #include "kurlcombobox.h" QTEST_MAIN(KUrlNavigatorTest) void KUrlNavigatorTest::initTestCase() { + QStandardPaths::setTestModeEnabled(true); m_navigator = new KUrlNavigator(nullptr, QUrl(QStringLiteral("file:///A")), nullptr); } @@ -255,6 +259,21 @@ QCOMPARE(buttonUrl, expectedButtonUrl); } +void KUrlNavigatorTest::testButtonText() +{ + KFilePlacesModel model; + const QUrl url = QUrl::fromLocalFile(QDir::currentPath()); + model.addPlace("&Here", url); + KUrlNavigator navigator(&model, url, nullptr); + + QList buttons = navigator.findChildren(); + const auto it = std::find_if(buttons.cbegin(), buttons.cend(), [](QPushButton *button) { + return button->text() == QLatin1String("&Here"); + }); + QVERIFY(it != buttons.cend()); + QCOMPARE((*it)->property("plainText").toString(), QStringLiteral("Here")); +} + void KUrlNavigatorTest::testInitWithRedundantPathSeparators() { KUrlNavigator temp_nav(nullptr, QUrl::fromLocalFile(QStringLiteral("/home/foo///test")), nullptr); diff --git a/src/filewidgets/kurlnavigatorbutton.cpp b/src/filewidgets/kurlnavigatorbutton.cpp --- a/src/filewidgets/kurlnavigatorbutton.cpp +++ b/src/filewidgets/kurlnavigatorbutton.cpp @@ -595,7 +595,7 @@ const int sourceLength = source.length(); QString dest; - dest.reserve(sourceLength); + dest.resize(sourceLength); int sourceIndex = 0; int destIndex = 0; @@ -611,6 +611,8 @@ ++destIndex; } + dest.resize(destIndex); + return dest; } diff --git a/src/filewidgets/kurlnavigatorbutton_p.h b/src/filewidgets/kurlnavigatorbutton_p.h --- a/src/filewidgets/kurlnavigatorbutton_p.h +++ b/src/filewidgets/kurlnavigatorbutton_p.h @@ -54,6 +54,7 @@ class KUrlNavigatorButton : public KUrlNavigatorButtonBase { Q_OBJECT + Q_PROPERTY(QString plainText READ plainText) // for the unittest public: explicit KUrlNavigatorButton(const QUrl &url, QWidget *parent);