Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkDicomExternalDataWidget.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 // Qmitk
15 #include <mitkLogMacros.h>
16 
17 // CTK
18 #include <ctkFileDialog.h>
19 
20 // Qt
21 #include <QCheckBox>
22 #include <QMessageBox>
23 #include <QTemporaryFile>
24 
25 const std::string QmitkDicomExternalDataWidget::Widget_ID = "org.mitk.Widgets.QmitkDicomExternalDataWidget";
26 
28  : QWidget(parent), m_ProgressDialog(nullptr), m_Controls(nullptr)
29 {
30  Initialize();
31  CreateQtPartControl(this);
32 }
33 
35 {
36 }
37 
39 {
40  // build up qt Widget, unless already done
41  if (!m_Controls)
42  {
43  // create GUI widgets from the Qt Designer's .ui file
44  m_Controls = new Ui::QmitkDicomExternalDataWidgetControls;
45  m_Controls->setupUi(parent);
46  m_Controls->viewExternalDataButton->setVisible(true);
47  m_Controls->ctkDICOMBrowser->setTableOrientation(Qt::Vertical);
48  m_Controls->ctkDICOMBrowser->setDICOMDatabase(m_ExternalDatabase);
49 
52 
53  // connect buttons
54  connect(m_Controls->downloadButton, SIGNAL(clicked()), this, SLOT(OnDownloadButtonClicked()));
55  connect(m_Controls->viewExternalDataButton, SIGNAL(clicked()), this, SLOT(OnViewButtonClicked()));
56  connect(m_Controls->directoryButton, SIGNAL(clicked()), m_ImportDialog, SLOT(show()));
57 
58  connect(m_Controls->ctkDICOMBrowser,
59  SIGNAL(seriesSelectionChanged(const QStringList &)),
60  this,
61  SLOT(OnSeriesSelectionChanged(const QStringList &)));
62  connect(
63  m_Controls->ctkDICOMBrowser, SIGNAL(seriesDoubleClicked(const QModelIndex &)), this, SLOT(OnViewButtonClicked()));
64 
65  connect(m_ImportDialog, SIGNAL(fileSelected(QString)), this, SLOT(OnStartDicomImport(QString)));
66 
67  connect(m_ExternalIndexer,
68  SIGNAL(indexingFilePath(const QString &)),
70  SLOT(setLabelText(const QString &)));
71  connect(m_ExternalIndexer, SIGNAL(progress(int)), m_ProgressDialog, SLOT(setValue(int)));
72  // actually the progress dialog closes if the maximum value is reached, BUT
73  // the following line is needed since the external indexer wont reach maximum value (100 % progress)
74  connect(m_ExternalIndexer, SIGNAL(indexingComplete()), m_ProgressDialog, SLOT(close()));
75  connect(m_ProgressDialog, SIGNAL(canceled()), m_ExternalIndexer, SLOT(cancel()));
76  }
77 }
78 
80 {
81  m_ExternalDatabase = new ctkDICOMDatabase(this);
82 
83  try
84  {
85  // this used to be an in-memory database, but latest CTK enhancements made it difficult
86  // to maintain this mechanism
87  QTemporaryFile tmpDatabaseFile;
88  tmpDatabaseFile.open();
89  tmpDatabaseFile.setAutoRemove(false);
90  m_ExternalDatabase->openDatabase(tmpDatabaseFile.fileName(), QString("EXTERNAL-DB"));
91  }
92  catch (const std::exception&)
93  {
94  MITK_ERROR << "Database error: " << m_ExternalDatabase->lastError().toStdString();
95  m_ExternalDatabase->closeDatabase();
96  return;
97  }
98 
99  m_ExternalIndexer = new ctkDICOMIndexer(this);
100 }
101 
103 {
104  QStringList filesToDownload = GetFileNamesFromIndex();
105  if (filesToDownload.size() == 0)
106  {
107  QMessageBox info;
108  info.setText("You have to select an entry in the DICOM browser for import.");
109  info.exec();
110  return;
111  }
113 }
114 
116 {
117  QStringList uids = m_Controls->ctkDICOMBrowser->currentSeriesSelection();
118  QString uid;
119  foreach (uid, uids)
120  {
121  QStringList filesForSeries = m_ExternalDatabase->filesForSeries(uid);
122  QHash<QString, QVariant> eventProperty;
123  eventProperty.insert("FilesForSeries", filesForSeries);
124  if (!filesForSeries.isEmpty())
125  {
126  QString modality = m_ExternalDatabase->fileValue(filesForSeries.at(0), "0008,0060");
127  eventProperty.insert("Modality", modality);
128  }
129  emit SignalDicomToDataManager(eventProperty);
130  }
131 }
132 
134 {
135  QStringList filePaths;
136 
137  QString uid;
138  QStringList seriesUIDs = m_Controls->ctkDICOMBrowser->currentSeriesSelection();
139  foreach (uid, seriesUIDs)
140  {
141  filePaths.append(m_ExternalDatabase->filesForSeries(uid));
142  }
143  if (!filePaths.empty())
144  return filePaths;
145 
146  QStringList studyUIDs = m_Controls->ctkDICOMBrowser->currentStudiesSelection();
147 
148  foreach (uid, studyUIDs)
149  {
150  seriesUIDs = m_ExternalDatabase->seriesForStudy(uid);
151  foreach (uid, seriesUIDs)
152  {
153  filePaths.append(m_ExternalDatabase->filesForSeries(uid));
154  }
155  }
156  if (!filePaths.empty())
157  return filePaths;
158 
159  QStringList patientsUIDs = m_Controls->ctkDICOMBrowser->currentPatientsSelection();
160 
161  foreach (uid, patientsUIDs)
162  {
163  studyUIDs = m_ExternalDatabase->studiesForPatient(uid);
164 
165  foreach (uid, studyUIDs)
166  {
167  seriesUIDs = m_ExternalDatabase->seriesForStudy(uid);
168  foreach (uid, seriesUIDs)
169  {
170  filePaths.append(m_ExternalDatabase->filesForSeries(uid));
171  }
172  }
173  }
174  return filePaths;
175 }
176 
178 {
179  m_ImportDialog->close();
180  // no need to show / start the progress dialog, as the dialog
181  // appears by receiving the progress signal from the external indexer
182 
183  m_LastImportDirectory = directory;
185 }
186 
188 {
189  m_Controls->viewExternalDataButton->setEnabled((s.size() != 0));
190 }
191 
193 {
194  // Initialize import widget
195  m_ImportDialog = new ctkFileDialog(this);
196  // Since copy on import is not working at the moment
197  // this feature is disabled
198  // QCheckBox* importCheckbox = new QCheckBox("Copy on import", m_ImportDialog);
199  // m_ImportDialog->setBottomWidget(importCheckbox);
200  m_ImportDialog->setFileMode(QFileDialog::Directory);
201  m_ImportDialog->setLabelText(QFileDialog::Accept, "Import");
202  m_ImportDialog->setWindowTitle("Import DICOM files from directory");
203  m_ImportDialog->setWindowModality(Qt::ApplicationModal);
204 }
205 
207 {
208  m_ProgressDialog = new QProgressDialog("Initialization ...", "Cancel", 0, 100, this);
209  m_ProgressDialog->setWindowTitle("DICOM Import");
210  m_ProgressDialog->setWindowModality(Qt::ApplicationModal);
211  m_ProgressDialog->setMinimumDuration(0);
212  // FIX T20008: immediately set the progress dialog value to maximum --> will close the dialog
213  m_ProgressDialog->setValue(100);
214 }
void OnDownloadButtonClicked()
Called when download button was clicked.
~QmitkDicomExternalDataWidget() override
QmitkDicomExternalDataWidget destructor.
Ui::QmitkDicomExternalDataWidgetControls * m_Controls
void OnSeriesSelectionChanged(const QStringList &s)
#define MITK_ERROR
Definition: mitkLogMacros.h:20
virtual void CreateQtPartControl(QWidget *parent)
CreateQtPartControl(QWidget *parent) sets the view objects from ui_QmitkDicomExternalDataWidgetContro...
static void info(const char *fmt,...)
Definition: svm.cpp:86
void OnStartDicomImport(const QString &)
Called when adding a dicom directory. Starts a thread adding the directory.
void SetupImportDialog()
SetupImportDialog Sets up import dialog.
void Initialize()
Initializes the widget. This method has to be called before widget can start.
QStringList GetFileNamesFromIndex()
Get the list of filepath from current selected index in TreeView. All file paths referring to the ind...
void SignalStartDicomImport(const QStringList &)
emitted when import into database is finished.
void SignalDicomToDataManager(QHash< QString, QVariant >)
emitted when view button is clicked.
void OnViewButtonClicked()
Called when view button was clicked.
QmitkDicomExternalDataWidget(QWidget *parent)
QmitkDicomExternalDataWidget(QWidget *parent) constructor.