Skip to content

Commit

Permalink
Parse filesystem paths using helper function
Browse files Browse the repository at this point in the history
A new QtHelpers namespace has been introduced which contains a helper
function to convert a QUrl to a std::string, ensuring that local URLs
are parsed correctly on all platforms.
  • Loading branch information
daljit46 committed May 30, 2024
1 parent 966814c commit 5f05d13
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/gui/mrview/tool/fixel/fixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "gui/mrview/tool/fixel/fixel.h"

#include "gui/dialog/file.h"
#include "gui/mrview/qthelpers.h"
#include "gui/mrview/tool/fixel/base_fixel.h"
#include "gui/mrview/tool/fixel/directory.h"
#include "gui/mrview/tool/fixel/image4D.h"
Expand Down Expand Up @@ -337,7 +338,7 @@ void Fixel::dropEvent(QDropEvent *event) {
std::vector<std::string> list;
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size() && i < max_files; ++i) {
list.push_back(urlList.at(i).path().toUtf8().constData());
list.push_back(QtHelpers::url_to_std_string(urlList.at(i)));
}
try {
add_images(list);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/mrview/tool/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "gui/dialog/file.h"
#include "gui/mrview/gui_image.h"
#include "gui/mrview/mode/slice.h"
#include "gui/mrview/qthelpers.h"
#include "gui/mrview/tool/list_model_base.h"
#include "gui/mrview/window.h"
#include "mrtrix.h"
Expand Down Expand Up @@ -204,7 +205,7 @@ void Overlay::dropEvent(QDropEvent *event) {
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size() && i < max_files; ++i) {
try {
list.push_back(std::make_unique<MR::Header>(MR::Header::open(urlList.at(i).path().toUtf8().constData())));
list.push_back(std::make_unique<MR::Header>(MR::Header::open(QtHelpers::url_to_std_string(urlList.at(i)))));
} catch (Exception &e) {
e.display();
}
Expand Down Expand Up @@ -774,5 +775,4 @@ bool Overlay::process_commandline_option(const MR::App::ParsedOption &opt) {

return false;
}

} // namespace MR::GUI::MRView::Tool
3 changes: 2 additions & 1 deletion src/gui/mrview/tool/roi_editor/roi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <string>

#include "gui/mrview/qthelpers.h"
#include "gui/mrview/tool/roi_editor/roi.h"

#include "gui/cursor.h"
Expand Down Expand Up @@ -289,7 +290,7 @@ void ROI::dropEvent(QDropEvent *event) {
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size() && i < max_files; ++i) {
try {
list.push_back(std::make_unique<MR::Header>(MR::Header::open(urlList.at(i).path().toUtf8().constData())));
list.push_back(std::make_unique<MR::Header>(MR::Header::open(QtHelpers::url_to_std_string(urlList.at(i)))));
} catch (Exception &e) {
e.display();
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/mrview/tool/tractography/tractography.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "gui/mrview/tool/tractography/tractography.h"
#include "gui/dialog/file.h"
#include "gui/lighting_dock.h"
#include "gui/mrview/qthelpers.h"
#include "gui/mrview/tool/list_model_base.h"
#include "gui/mrview/tool/tractography/track_scalar_file.h"
#include "gui/mrview/tool/tractography/tractogram.h"
Expand Down Expand Up @@ -367,7 +368,7 @@ void Tractography::dropEvent(QDropEvent *event) {
std::vector<std::string> list;
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size() && i < max_files; ++i) {
list.push_back(urlList.at(i).path().toUtf8().constData());
list.push_back(QtHelpers::url_to_std_string(urlList.at(i)));
}
try {
tractogram_list_model->add_items(list, *this);
Expand Down
6 changes: 3 additions & 3 deletions src/gui/mrview/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "gui/dialog/progress.h"
#include "gui/mrview/mode/base.h"
#include "gui/mrview/mode/list.h"
#include "gui/mrview/qthelpers.h"
#include "gui/mrview/tool/base.h"
#include "gui/mrview/tool/list.h"
#include "gui/opengl/gl.h"
Expand Down Expand Up @@ -154,9 +155,8 @@ void Window::GLArea::dropEvent(QDropEvent *event) {
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size() && i < 32; ++i) {
try {
const auto url = urlList.at(i);
const auto filePath =
url.isLocalFile() ? url.toLocalFile().toUtf8().constData() : url.toString().toUtf8().constData();
const auto &url = urlList.at(i);
const auto filePath = QtHelpers::url_to_std_string(url);
list.push_back(std::make_unique<MR::Header>(MR::Header::open(filePath)));
} catch (Exception &e) {
e.display();
Expand Down

0 comments on commit 5f05d13

Please sign in to comment.