Skip to content

Commit 20695ee

Browse files
authored
Merge pull request #759 from openstudiocoalition/758_results_url
Fix #758 - Properly encode path to QUrl when trying to display results
2 parents 7317203 + 3d70f41 commit 20695ee

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/model_editor/test/Utilities_GTest.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "../Utilities.hpp"
1212

1313
#include <clocale>
14+
#include <QUrl>
1415

1516
using openstudio::toPath;
1617
using openstudio::toQString;
@@ -113,3 +114,35 @@ TEST_F(ModelEditorFixture, Path_Conversions) {
113114
EXPECT_EQ(t, std::string(toQString(toString(p)).toUtf8()));
114115
EXPECT_EQ(t, toString(toPath(toQString(toString(p)))));
115116
}
117+
118+
TEST_F(ModelEditorFixture, MorePath_Conversions) {
119+
struct PathTestCase
120+
{
121+
std::string inputPath;
122+
QString expectedPath;
123+
QString expectedUrl;
124+
};
125+
126+
std::vector<PathTestCase> testCases = {
127+
{"C:\\Users\\Test\\eplustbl.html", "C:/Users/Test/eplustbl.html", "file:///C:/Users/Test/eplustbl.html"},
128+
{"C:/Users/Test/eplustbl.html", "C:/Users/Test/eplustbl.html", "file:///C:/Users/Test/eplustbl.html"},
129+
{"C:\\Users/Test/eplustbl.html", "C:/Users/Test/eplustbl.html", "file:///C:/Users/Test/eplustbl.html"},
130+
{"C:\\Users\\Test# ^\\eplustbl.html", "C:/Users/Test# ^/eplustbl.html", "file:///C:/Users/Test%23%20%5E/eplustbl.html"},
131+
{"/home/Test/eplustbl.html", "/home/Test/eplustbl.html", "file:///home/Test/eplustbl.html"},
132+
{"/home/Test# ^/eplustbl.html", "/home/Test# ^/eplustbl.html", "file:///home/Test%23%20%5E/eplustbl.html"},
133+
};
134+
135+
// double check the conversions in openstudio_lib/ResultsTabView.cpp
136+
for (const auto& testCase : testCases) {
137+
openstudio::path osPath = toPath(testCase.inputPath);
138+
QString qPath = toQString(osPath);
139+
EXPECT_EQ(qPath, testCase.expectedPath);
140+
QUrl url = QUrl::fromLocalFile(qPath);
141+
EXPECT_EQ(url.toString(QUrl::FullyEncoded), testCase.expectedUrl);
142+
143+
std::cout << "Input: " << testCase.inputPath << ", "
144+
<< "OS Path: " << osPath << ", "
145+
<< "QPath: " << qPath.toStdString() << ", "
146+
<< "Url: " << url.toString().toStdString() << std::endl;
147+
}
148+
}

src/openstudio_lib/ResultsTabView.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ void ResultsView::populateComboBox(const std::vector<openstudio::path>& reports)
301301
QString fullPathString = toQString(report);
302302

303303
QFile file(fullPathString);
304-
fullPathString.prepend("file:///");
305304

306305
if (openstudio::toString(report.filename()) == "eplustbl.html" || openstudio::toString(report.filename()) == "eplustbl.htm") {
307306

@@ -360,7 +359,7 @@ void ResultsView::comboBoxChanged(int index) {
360359

361360
m_progressBar->setError(false);
362361

363-
QUrl url(filename);
362+
QUrl url = QUrl::fromLocalFile(filename);
364363
m_view->load(url);
365364
}
366365

0 commit comments

Comments
 (0)