Skip to content

Commit

Permalink
Merge pull request #2886 from MRtrix3/fix_drag_drop_mrview_windows
Browse files Browse the repository at this point in the history
Fix drag & drop on Windows for mrview
  • Loading branch information
daljit46 authored Aug 28, 2024
2 parents 64e6647 + 1f2656d commit d9ddbd4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 6 deletions.
33 changes: 33 additions & 0 deletions src/gui/mrview/qthelpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright (c) 2008-2024 the MRtrix3 contributors.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Covered Software is provided under this License on an "as is"
* basis, without warranty of any kind, either expressed, implied, or
* statutory, including, without limitation, warranties that the
* Covered Software is free of defects, merchantable, fit for a
* particular purpose or non-infringing.
* See the Mozilla Public License v. 2.0 for more details.
*
* For more details, see http://www.mrtrix.org/.
*/

#include "gui/mrview/qthelpers.h"

#include <QString>
#include <QUrl>

#include <string>

namespace MR::GUI::MRView::QtHelpers {

std::string url_to_std_string(const QUrl &url) {
const bool isLocal = url.isLocalFile();
const std::string str = isLocal ? url.toLocalFile().toStdString() : url.toString().toStdString();

return str;
}

} // namespace MR::GUI::MRView::QtHelpers
26 changes: 26 additions & 0 deletions src/gui/mrview/qthelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Copyright (c) 2008-2024 the MRtrix3 contributors.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Covered Software is provided under this License on an "as is"
* basis, without warranty of any kind, either expressed, implied, or
* statutory, including, without limitation, warranties that the
* Covered Software is free of defects, merchantable, fit for a
* particular purpose or non-infringing.
* See the Mozilla Public License v. 2.0 for more details.
*
* For more details, see http://www.mrtrix.org/.
*/

#pragma once
#include <string>

class QUrl;

namespace MR::GUI::MRView::QtHelpers {

std::string url_to_std_string(const QUrl &url);

} // namespace MR::GUI::MRView::QtHelpers
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 @@ -775,5 +776,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 @@ -369,7 +370,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
5 changes: 4 additions & 1 deletion 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,7 +155,9 @@ void Window::GLArea::dropEvent(QDropEvent *event) {
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size() && i < 32; ++i) {
try {
list.push_back(std::make_unique<MR::Header>(MR::Header::open(urlList.at(i).path().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 d9ddbd4

Please sign in to comment.