Skip to content

Commit

Permalink
Merge pull request #759 from openstudiocoalition/758_results_url
Browse files Browse the repository at this point in the history
Fix #758 - Properly encode path to QUrl when trying to display results
  • Loading branch information
jmarrec authored Oct 14, 2024
2 parents 7317203 + 3d70f41 commit 20695ee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 33 additions & 0 deletions src/model_editor/test/Utilities_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../Utilities.hpp"

#include <clocale>
#include <QUrl>

using openstudio::toPath;
using openstudio::toQString;
Expand Down Expand Up @@ -113,3 +114,35 @@ TEST_F(ModelEditorFixture, Path_Conversions) {
EXPECT_EQ(t, std::string(toQString(toString(p)).toUtf8()));
EXPECT_EQ(t, toString(toPath(toQString(toString(p)))));
}

TEST_F(ModelEditorFixture, MorePath_Conversions) {
struct PathTestCase
{
std::string inputPath;
QString expectedPath;
QString expectedUrl;
};

std::vector<PathTestCase> testCases = {
{"C:\\Users\\Test\\eplustbl.html", "C:/Users/Test/eplustbl.html", "file:///C:/Users/Test/eplustbl.html"},
{"C:/Users/Test/eplustbl.html", "C:/Users/Test/eplustbl.html", "file:///C:/Users/Test/eplustbl.html"},
{"C:\\Users/Test/eplustbl.html", "C:/Users/Test/eplustbl.html", "file:///C:/Users/Test/eplustbl.html"},
{"C:\\Users\\Test# ^\\eplustbl.html", "C:/Users/Test# ^/eplustbl.html", "file:///C:/Users/Test%23%20%5E/eplustbl.html"},
{"/home/Test/eplustbl.html", "/home/Test/eplustbl.html", "file:///home/Test/eplustbl.html"},
{"/home/Test# ^/eplustbl.html", "/home/Test# ^/eplustbl.html", "file:///home/Test%23%20%5E/eplustbl.html"},
};

// double check the conversions in openstudio_lib/ResultsTabView.cpp
for (const auto& testCase : testCases) {
openstudio::path osPath = toPath(testCase.inputPath);
QString qPath = toQString(osPath);
EXPECT_EQ(qPath, testCase.expectedPath);
QUrl url = QUrl::fromLocalFile(qPath);
EXPECT_EQ(url.toString(QUrl::FullyEncoded), testCase.expectedUrl);

std::cout << "Input: " << testCase.inputPath << ", "
<< "OS Path: " << osPath << ", "
<< "QPath: " << qPath.toStdString() << ", "
<< "Url: " << url.toString().toStdString() << std::endl;
}
}
3 changes: 1 addition & 2 deletions src/openstudio_lib/ResultsTabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ void ResultsView::populateComboBox(const std::vector<openstudio::path>& reports)
QString fullPathString = toQString(report);

QFile file(fullPathString);
fullPathString.prepend("file:///");

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

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

m_progressBar->setError(false);

QUrl url(filename);
QUrl url = QUrl::fromLocalFile(filename);
m_view->load(url);
}

Expand Down

0 comments on commit 20695ee

Please sign in to comment.