Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 // Qmitk
19 #include <mitkLogMacros.h>
20 
21 // CTK
22 #include <ctkFileDialog.h>
23 
24 // Qt
25 #include <QCheckBox>
26 #include <QMessageBox>
27 
28 const std::string QmitkDicomExternalDataWidget::Widget_ID = "org.mitk.Widgets.QmitkDicomExternalDataWidget";
29 
31  : QWidget(parent), m_Controls(nullptr), m_ProgressDialog(nullptr)
32 {
33  Initialize();
34  CreateQtPartControl(this);
35 }
36 
38 {
39 }
40 
42 {
43  // build up qt Widget, unless already done
44  if (!m_Controls)
45  {
46  // create GUI widgets from the Qt Designer's .ui file
47  m_Controls = new Ui::QmitkDicomExternalDataWidgetControls;
48  m_Controls->setupUi(parent);
49  m_Controls->viewExternalDataButton->setVisible(true);
50  m_Controls->ctkDICOMBrowser->setTableOrientation(Qt::Vertical);
51  m_Controls->ctkDICOMBrowser->setDICOMDatabase(m_ExternalDatabase);
52 
55 
56  // connect buttons
57  connect(m_Controls->downloadButton, SIGNAL(clicked()), this, SLOT(OnDownloadButtonClicked()));
58  connect(m_Controls->viewExternalDataButton, SIGNAL(clicked()), this, SLOT(OnViewButtonClicked()));
59  connect(m_Controls->directoryButton, SIGNAL(clicked()), m_ImportDialog, SLOT(show()));
60 
61  connect(m_Controls->ctkDICOMBrowser,
62  SIGNAL(seriesSelectionChanged(const QStringList &)),
63  this,
64  SLOT(OnSeriesSelectionChanged(const QStringList &)));
65  connect(
66  m_Controls->ctkDICOMBrowser, SIGNAL(seriesDoubleClicked(const QModelIndex &)), this, SLOT(OnViewButtonClicked()));
67 
68  connect(m_ImportDialog, SIGNAL(fileSelected(QString)), this, SLOT(OnStartDicomImport(QString)));
69 
70  connect(m_ExternalIndexer,
71  SIGNAL(indexingFilePath(const QString &)),
73  SLOT(setLabelText(const QString &)));
74  connect(m_ExternalIndexer, SIGNAL(progress(int)), m_ProgressDialog, SLOT(setValue(int)));
75  // actually the progress dialog closes if the maximum value is reached, BUT
76  // the following line is needed since the external indexer wont reach maximum value (100 % progress)
77  connect(m_ExternalIndexer, SIGNAL(indexingComplete()), m_ProgressDialog, SLOT(close()));
78  connect(m_ProgressDialog, SIGNAL(canceled()), m_ExternalIndexer, SLOT(cancel()));
79  }
80 }
81 
83 {
84  m_ExternalDatabase = new ctkDICOMDatabase(this);
85 
86  try
87  {
88  m_ExternalDatabase->openDatabase(QString(":memory:"), QString("EXTERNAL-DB"));
89  }
90  catch (std::exception e)
91  {
92  MITK_ERROR << "Database error: " << m_ExternalDatabase->lastError().toStdString();
93  m_ExternalDatabase->closeDatabase();
94  return;
95  }
96 
97  m_ExternalIndexer = new ctkDICOMIndexer(this);
98 }
99 
101 {
102  QStringList filesToDownload = GetFileNamesFromIndex();
103  if (filesToDownload.size() == 0)
104  {
105  QMessageBox info;
106  info.setText("You have to select an entry in the DICOM browser for import.");
107  info.exec();
108  return;
109  }
111 }
112 
114 {
115  QStringList uids = m_Controls->ctkDICOMBrowser->currentSeriesSelection();
116  QString uid;
117  foreach (uid, uids)
118  {
119  QStringList filesForSeries = m_ExternalDatabase->filesForSeries(uid);
120  QHash<QString, QVariant> eventProperty;
121  eventProperty.insert("FilesForSeries", filesForSeries);
122  if (!filesForSeries.isEmpty())
123  {
124  QString modality = m_ExternalDatabase->fileValue(filesForSeries.at(0), "0008,0060");
125  eventProperty.insert("Modality", modality);
126  }
127  emit SignalDicomToDataManager(eventProperty);
128  }
129 }
130 
132 {
133  QStringList filePaths;
134 
135  QString uid;
136  QStringList seriesUIDs = m_Controls->ctkDICOMBrowser->currentSeriesSelection();
137  foreach (uid, seriesUIDs)
138  {
139  filePaths.append(m_ExternalDatabase->filesForSeries(uid));
140  }
141  if (!filePaths.empty())
142  return filePaths;
143 
144  QStringList studyUIDs = m_Controls->ctkDICOMBrowser->currentStudiesSelection();
145 
146  foreach (uid, studyUIDs)
147  {
148  seriesUIDs = m_ExternalDatabase->seriesForStudy(uid);
149  foreach (uid, seriesUIDs)
150  {
151  filePaths.append(m_ExternalDatabase->filesForSeries(uid));
152  }
153  }
154  if (!filePaths.empty())
155  return filePaths;
156 
157  QStringList patientsUIDs = m_Controls->ctkDICOMBrowser->currentPatientsSelection();
158 
159  foreach (uid, patientsUIDs)
160  {
161  studyUIDs = m_ExternalDatabase->studiesForPatient(uid);
162 
163  foreach (uid, studyUIDs)
164  {
165  seriesUIDs = m_ExternalDatabase->seriesForStudy(uid);
166  foreach (uid, seriesUIDs)
167  {
168  filePaths.append(m_ExternalDatabase->filesForSeries(uid));
169  }
170  }
171  }
172  return filePaths;
173 }
174 
176 {
177  m_ImportDialog->close();
178  // no need to show / start the progress dialog, as the dialog
179  // appears by receiving the progress signal from the external indexer
180 
181  m_LastImportDirectory = directory;
183 }
184 
186 {
187  m_Controls->viewExternalDataButton->setEnabled((s.size() != 0));
188 }
189 
191 {
192  // Initialize import widget
193  m_ImportDialog = new ctkFileDialog(this);
194  // Since copy on import is not working at the moment
195  // this feature is disabled
196  // QCheckBox* importCheckbox = new QCheckBox("Copy on import", m_ImportDialog);
197  // m_ImportDialog->setBottomWidget(importCheckbox);
198  m_ImportDialog->setFileMode(QFileDialog::Directory);
199  m_ImportDialog->setLabelText(QFileDialog::Accept, "Import");
200  m_ImportDialog->setWindowTitle("Import DICOM files from directory");
201  m_ImportDialog->setWindowModality(Qt::ApplicationModal);
202 }
203 
205 {
206  m_ProgressDialog = new QProgressDialog("Initialization ...", "Cancel", 0, 100, this);
207  m_ProgressDialog->setWindowTitle("DICOM Import");
208  m_ProgressDialog->setWindowModality(Qt::ApplicationModal);
209  m_ProgressDialog->setMinimumDuration(0);
210  // FIX T20008: immediately set the progress dialog value to maximum --> will close the dialog
211  m_ProgressDialog->setValue(100);
212 }
void OnDownloadButtonClicked()
Called when download button was clicked.
Ui::QmitkDicomExternalDataWidgetControls * m_Controls
void OnSeriesSelectionChanged(const QStringList &s)
#define MITK_ERROR
Definition: mitkLogMacros.h:24
virtual void CreateQtPartControl(QWidget *parent)
CreateQtPartControl(QWidget *parent) sets the view objects from ui_QmitkDicomExternalDataWidgetContro...
virtual ~QmitkDicomExternalDataWidget()
QmitkDicomExternalDataWidget destructor.
static void info(const char *fmt,...)
Definition: svm.cpp:100
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.