Skip to content

Commit

Permalink
Drag-and-drop from the list of images onto metadata viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
issakomi committed May 29, 2024
1 parent 82c8956 commit 9b6b225
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 24 deletions.
5 changes: 3 additions & 2 deletions GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ MainWindow::MainWindow(
graphicswidget_y->set_aliza(aliza);
//
studyview->init_(aliza);
sqtree->set_aliza(aliza);
//
histogramview = new HistogramView(
this, static_cast<QObject*>(aliza), multi_frame, false);
Expand Down Expand Up @@ -1370,7 +1371,7 @@ void MainWindow::toggle_meta2()
if (l.empty()) return;
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
const int t = (multiview_tab) ? 3 : 2;
sqtree->set_list_of_files(l);
sqtree->set_list_of_files(l, true);
sqtree->read_file(l.at(0), true);
tabWidget->setCurrentIndex(t);
qApp->restoreOverrideCursor();
Expand Down Expand Up @@ -2277,7 +2278,7 @@ void MainWindow::trigger_image_dicom_meta()
}
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
qApp->processEvents();
sqtree->set_list_of_files(l);
sqtree->set_list_of_files(l, true);
sqtree->read_file(l.at(0), true);
const int t = (multiview_tab) ? 3 : 2;
tabWidget->setCurrentIndex(t);
Expand Down
5 changes: 3 additions & 2 deletions GUI/studygraphicswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,8 @@ void StudyGraphicsWidget::dropEvent(QDropEvent * e)
{
int i{-1};
const QMimeData * mimeData = e->mimeData();
if (mimeData && mimeData->hasFormat("application/x-qabstractitemmodeldatalist")) // FIXME
// TODO distinguish other Qt apps?
if (mimeData && mimeData->hasFormat("application/x-qabstractitemmodeldatalist"))
{
QByteArray encoded = mimeData->data("application/x-qabstractitemmodeldatalist");
QDataStream stream(&encoded, QIODevice::ReadOnly);
Expand All @@ -1298,10 +1299,10 @@ void StudyGraphicsWidget::dropEvent(QDropEvent * e)
if (item)
{
i = item->get_id();
break; // not really required, single selection
}
}
}
break;
}
}
if (i >= 0)
Expand Down
107 changes: 88 additions & 19 deletions browser/sqtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "codecutils.h"
#include "dicomutils.h"
#include "commonutils.h"
#include "aliza.h"
#include <exception>

namespace
Expand Down Expand Up @@ -2001,32 +2002,90 @@ void SQtree::dropEvent(QDropEvent * e)
if (lock0) return;
lock0 = true;
#endif
QStringList l;
QList<QUrl> urls;
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
const QMimeData * mimeData = e->mimeData();
if (mimeData && mimeData->hasUrls())
if (mimeData)
{
urls = mimeData->urls();
for (int i = 0; i < urls.size(); ++i)
if (mimeData->hasUrls())
{
l.push_back(urls.at(i).toLocalFile());
QStringList l;
const QList<QUrl> urls = mimeData->urls();
for (int i = 0; i < urls.size(); ++i)
{
l.push_back(urls.at(i).toLocalFile());
}
if (!l.empty())
{
list_of_files = QStringList(l.at(0));
horizontalSlider->blockSignals(true);
horizontalSlider->setMinimum(0);
horizontalSlider->setMaximum(0);
horizontalSlider->setValue(0);
horizontalSlider->hide();
horizontalSlider->blockSignals(false);
read_file(l.at(0), false);
}
else
{
clear_tree();
}
}
if (!l.empty())
// TODO distinguish other Qt apps?
else if (mimeData->hasFormat("application/x-qabstractitemmodeldatalist"))
{
list_of_files = QStringList(l.at(0));
horizontalSlider->blockSignals(true);
horizontalSlider->setMinimum(0);
horizontalSlider->setMaximum(0);
horizontalSlider->setValue(0);
horizontalSlider->hide();
horizontalSlider->blockSignals(false);
read_file(l.at(0), false);
QStringList l;
QByteArray encoded = mimeData->data("application/x-qabstractitemmodeldatalist");
QDataStream stream(&encoded, QIODevice::ReadOnly);
while (!stream.atEnd())
{
int r{-1};
int c{-1};
QMap<int, QVariant> role;
stream >> r >> c >> role;
#if 0
std::cout << "row = " << r << ", column = " << c << std::endl;
#endif
(void)c;
(void)role;
if (aliza)
{
const ImagesBox * imagesbox = aliza->get_imagesbox();
if (imagesbox)
{
const ListWidgetItem2 * item = static_cast<const ListWidgetItem2*>(imagesbox->listWidget->item(r));
if (item)
{
const int i = item->get_id();
const ImageVariant * v = aliza->get_image(i);
if (v)
{
l = v->filenames;
}
}
}
}
break;
}
if (!l.empty())
{
set_list_of_files(l, false);
read_file(l.at(0), false);
}
else
{
clear_tree();
}
}
else
{
clear_tree();
}
}
else
{
clear_tree();
}
qApp->restoreOverrideCursor();
#if (defined SQTREE_LOCK_TREE && SQTREE_LOCK_TREE==1)
lock0 = false;
#endif
Expand Down Expand Up @@ -2122,11 +2181,14 @@ void SQtree::open_file_and_series()
#endif
}

void SQtree::set_list_of_files(const QStringList & l)
void SQtree::set_list_of_files(const QStringList & l, const bool use_lock)
{
#if (defined SQTREE_LOCK_TREE && SQTREE_LOCK_TREE==1)
if (lock0) return;
lock0 = true;
if (use_lock)
{
if (lock0) return;
lock0 = true;
}
#endif
list_of_files = QStringList(l);
const size_t x = list_of_files.size();
Expand All @@ -2138,7 +2200,10 @@ void SQtree::set_list_of_files(const QStringList & l)
else horizontalSlider->hide();
horizontalSlider->blockSignals(false);
#if (defined SQTREE_LOCK_TREE && SQTREE_LOCK_TREE==1)
lock0 = false;
if (use_lock)
{
lock0 = false;
}
#endif
}

Expand All @@ -2148,3 +2213,7 @@ void SQtree::file_from_slider(int x)
read_file(list_of_files.at(x), true);
}

void SQtree::set_aliza(Aliza * a)
{
aliza = a;
}
6 changes: 5 additions & 1 deletion browser/sqtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#define SQTREE_LOCK_TREE 1

class Aliza;

class SQtree: public QWidget, private Ui::SQtree
{
Q_OBJECT
Expand All @@ -28,7 +30,8 @@ Q_OBJECT
void read_file(const QString&, const bool);
void read_file_and_series(const QString&, const bool);
void clear_tree();
void set_list_of_files(const QStringList&);
void set_list_of_files(const QStringList&, const bool);
void set_aliza(Aliza*);

public slots:
void open_file();
Expand Down Expand Up @@ -64,6 +67,7 @@ private slots:
QAction * copyAct;
QAction * collapseAct;
QAction * expandAct;
Aliza * aliza{};
bool in_tabwidget;
QStringList list_of_files;
#if (defined SQTREE_LOCK_TREE && SQTREE_LOCK_TREE==1)
Expand Down

0 comments on commit 9b6b225

Please sign in to comment.