diff --git a/Modules/DicomUI/include/QmitkDicomLocalStorageWidget.h b/Modules/DicomUI/include/QmitkDicomLocalStorageWidget.h index 376cbc4b4c..357d90fab9 100644 --- a/Modules/DicomUI/include/QmitkDicomLocalStorageWidget.h +++ b/Modules/DicomUI/include/QmitkDicomLocalStorageWidget.h @@ -1,134 +1,138 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QmitkDicomLocalStorageWidget_h #define QmitkDicomLocalStorageWidget_h // #include #include "ui_QmitkDicomLocalStorageWidgetControls.h" #include // include ctk #include #include #include //include QT #include #include #include #include #include class QProgressDialog; class QLabel; /** * \brief QmitkDicomLocalStorageWidget is a QWidget providing functionality for dicom storage and import. * * \sa QmitkFunctionality * \ingroup Functionalities */ class MITKDICOMUI_EXPORT QmitkDicomLocalStorageWidget : public QWidget { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string Widget_ID; /** * \brief QmitkDicomLocalStorageWidget(QWidget *parent) constructor. * * \param parent is a pointer to the parent widget */ QmitkDicomLocalStorageWidget(QWidget *parent); /** * \brief QmitkDicomExternalDataWidget destructor. */ virtual ~QmitkDicomLocalStorageWidget(); /** * \brief CreateQtPartControl(QWidget *parent) sets the view objects from ui_QmitkDicomExternalDataWidgetControls.h. * * \param parent is a pointer to the parent widget */ virtual void CreateQtPartControl(QWidget *parent); /** * \brief SetDatabaseDirectory sets database directory. * * \param newDatabaseDirectory contains path to new database directoy. */ void SetDatabaseDirectory(QString newDatabaseDirectory); signals: /// @brief emitted when import into database is finished. void SignalFinishedImport(); /** * @brief emitted when view button is clicked. * @param QHash containing dicom UIDs properties. */ void SignalDicomToDataManager(QHash); /// \brief emitted if cancel button is pressed. void SignalCancelImport(); public slots: /// @brief Called when indexing into database is finished. /// In this slot the models database with new imports is set. /// This causes a model update. void OnFinishedImport(); /// @brief Called when view button was clicked. void OnViewButtonClicked(); /// @brief Called delete button was clicked. void OnDeleteButtonClicked(); /// @brief Called when adding a dicom directory. Starts a thread adding the directory. void OnStartDicomImport(const QString& dicomData); /// @brief Called when adding a list of dicom files. Starts a thread adding the dicom files. void OnStartDicomImport(const QStringList& dicomData); /// @brief Called when the selection in the series table has changed void OnSeriesSelectionChanged(const QStringList&); protected: void SetDatabase(QString databaseFile); /// \brief SetupProgressDialog Sets up progress dialog. void SetupProgressDialog(QWidget* parent); + bool DeletePatients(); + bool DeleteStudies(); + bool DeleteSeries(); + QProgressDialog* m_ProgressDialog; QLabel* m_ProgressDialogLabel; ctkDICOMDatabase* m_LocalDatabase; ctkDICOMIndexer* m_LocalIndexer; Ui::QmitkDicomLocalStorageWidgetControls* m_Controls; }; #endif // _QmitkDicomLocalStorageWidget_H_INCLUDED diff --git a/Modules/DicomUI/src/QmitkDicomLocalStorageWidget.cpp b/Modules/DicomUI/src/QmitkDicomLocalStorageWidget.cpp index 64d3e3aa4f..3a8932cf62 100644 --- a/Modules/DicomUI/src/QmitkDicomLocalStorageWidget.cpp +++ b/Modules/DicomUI/src/QmitkDicomLocalStorageWidget.cpp @@ -1,157 +1,237 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Qmitk #include "QmitkDicomLocalStorageWidget.h" //#include // Qt #include #include #include +#include const std::string QmitkDicomLocalStorageWidget::Widget_ID = "org.mitk.Widgets.QmitkDicomLocalStorageWidget"; QmitkDicomLocalStorageWidget::QmitkDicomLocalStorageWidget(QWidget *parent) : QWidget(parent) , m_Controls(0) , m_LocalIndexer(new ctkDICOMIndexer(parent)) { CreateQtPartControl(this); } QmitkDicomLocalStorageWidget::~QmitkDicomLocalStorageWidget() { m_LocalDatabase->closeDatabase(); } void QmitkDicomLocalStorageWidget::CreateQtPartControl( QWidget *parent ) { if ( !m_Controls ) { m_Controls = new Ui::QmitkDicomLocalStorageWidgetControls; m_Controls->setupUi( parent ); this->SetupProgressDialog(this); connect(m_Controls->deleteButton,SIGNAL(clicked()),this,SLOT(OnDeleteButtonClicked())); connect(m_Controls->viewInternalDataButton, SIGNAL(clicked()), this , SLOT(OnViewButtonClicked())); connect(m_Controls->ctkDicomBrowser, SIGNAL(seriesSelectionChanged(const QStringList&)), this, SLOT(OnSeriesSelectionChanged(const QStringList&))); connect(m_Controls->ctkDicomBrowser, SIGNAL(seriesSelectionChanged(const QStringList&)), this, SLOT(OnSeriesSelectionChanged(const QStringList&))); connect(m_Controls->ctkDicomBrowser, SIGNAL(seriesDoubleClicked(const QModelIndex&)), this, SLOT(OnViewButtonClicked())); connect(m_LocalIndexer, SIGNAL(indexingComplete()),this, SLOT(OnFinishedImport())); connect(m_LocalIndexer, SIGNAL(indexingComplete()),this, SIGNAL(SignalFinishedImport())); connect(m_LocalIndexer, SIGNAL(indexingComplete()),this, SLOT(OnFinishedImport())); connect(m_LocalIndexer, SIGNAL(indexingFilePath(const QString&)), m_ProgressDialogLabel, SLOT(setText(const QString&))); connect(m_LocalIndexer, SIGNAL(progress(int)), m_ProgressDialog, SLOT(setValue(int))); connect(m_ProgressDialog, SIGNAL(canceled()), m_LocalIndexer, SLOT(cancel())); m_Controls->ctkDicomBrowser->setTableOrientation(Qt::Vertical); } } void QmitkDicomLocalStorageWidget::OnStartDicomImport(const QString& dicomData) { if(m_LocalDatabase->isOpen()) { m_LocalIndexer->addDirectory(*m_LocalDatabase,dicomData,m_LocalDatabase->databaseDirectory()); } } void QmitkDicomLocalStorageWidget::OnStartDicomImport(const QStringList& dicomData) { if(m_LocalDatabase->isOpen()) { m_ProgressDialog->show(); m_LocalIndexer->addListOfFiles(*m_LocalDatabase,dicomData,m_LocalDatabase->databaseDirectory()); } } void QmitkDicomLocalStorageWidget::OnFinishedImport() { m_ProgressDialog->setValue(m_ProgressDialog->maximum()); } void QmitkDicomLocalStorageWidget::OnDeleteButtonClicked() { - QStringList selectedSeriesUIDs = m_Controls->ctkDicomBrowser->currentSeriesSelection(); - QString uid; - foreach (uid, selectedSeriesUIDs) + if (!this->DeletePatients()) { - m_LocalDatabase->removeSeries(uid); + if (!this->DeleteStudies()) + { + this->DeleteSeries(); + } } - QStringList selectedStudiesUIDs = m_Controls->ctkDicomBrowser->currentStudiesSelection(); - foreach(uid, selectedStudiesUIDs) + + m_Controls->ctkDicomBrowser->updateTableViews(); +} + +bool QmitkDicomLocalStorageWidget::DeletePatients() +{ + auto selectedPatientUIDs = m_Controls->ctkDicomBrowser->currentPatientsSelection(); + + if (!selectedPatientUIDs.empty()) { - m_LocalDatabase->removeStudy(uid); + QStringList studyUIDs; + + for (const auto& patientUID : selectedPatientUIDs) + studyUIDs.append(m_LocalDatabase->studiesForPatient(patientUID)); + + QStringList seriesUIDs; + + for (const auto& studyUID : studyUIDs) + seriesUIDs.append(m_LocalDatabase->seriesForStudy(studyUID)); + + auto answer = QMessageBox::question(nullptr, "Delete Patients", + QString("Do you really want to delete %1 %2, containing %3 series in %4 %5?") + .arg(selectedPatientUIDs.count()) + .arg(selectedPatientUIDs.count() != 1 ? "patients" : "patient") + .arg(seriesUIDs.count()) + .arg(studyUIDs.count()) + .arg(studyUIDs.count() != 1 ? "studies" : "study")); + + if (answer == QMessageBox::Ok) + { + for (const auto& patientUID : selectedPatientUIDs) + m_LocalDatabase->removePatient(patientUID); + } + + return true; } - QStringList selectedPatientUIDs = m_Controls->ctkDicomBrowser->currentPatientsSelection(); - foreach(uid, selectedPatientUIDs) + + return false; +} + +bool QmitkDicomLocalStorageWidget::DeleteStudies() +{ + auto selectedStudyUIDs = m_Controls->ctkDicomBrowser->currentStudiesSelection(); + + if (!selectedStudyUIDs.empty()) { - m_LocalDatabase->removePatient(uid); + QStringList seriesUIDs; + + for (const auto& studyUID : selectedStudyUIDs) + seriesUIDs.append(m_LocalDatabase->seriesForStudy(studyUID)); + + auto answer = QMessageBox::question(nullptr, "Delete Studies", + QString("Do you really want to delete %1 %2, containing %3 series?") + .arg(selectedStudyUIDs.count()) + .arg(selectedStudyUIDs.count() != 1 ? "studies" : "study") + .arg(seriesUIDs.count())); + + if (answer == QMessageBox::Ok) + { + for (const auto& studyUID : selectedStudyUIDs) + m_LocalDatabase->removeStudy(studyUID); + } + + return true; } - m_Controls->ctkDicomBrowser->updateTableViews(); + + return false; +} + +bool QmitkDicomLocalStorageWidget::DeleteSeries() +{ + auto selectedSeriesUIDs = m_Controls->ctkDicomBrowser->currentSeriesSelection(); + + if (!selectedSeriesUIDs.empty()) + { + auto answer = QMessageBox::question(nullptr, "Delete Series", + QString("Do you really want to delete %1 series?") + .arg(selectedSeriesUIDs.count())); + + if (answer == QMessageBox::Ok) + { + for (const auto& seriesUID : selectedSeriesUIDs) + m_LocalDatabase->removeSeries(seriesUID); + } + + return true; + } + + return false; } void QmitkDicomLocalStorageWidget::OnViewButtonClicked() { QStringList uids = m_Controls->ctkDicomBrowser->currentSeriesSelection(); QString uid; foreach (uid, uids) { QStringList filesForSeries = m_LocalDatabase->filesForSeries(uid); QHash eventProperty; eventProperty.insert("FilesForSeries", filesForSeries); emit SignalDicomToDataManager(eventProperty); } } void QmitkDicomLocalStorageWidget::SetDatabaseDirectory(QString newDatatbaseDirectory) { QDir databaseDirecory = QDir(newDatatbaseDirectory); if(!databaseDirecory.exists()) { databaseDirecory.mkpath(databaseDirecory.absolutePath()); } QString newDatatbaseFile = databaseDirecory.absolutePath() + QString("/ctkDICOM.sql"); this->SetDatabase(newDatatbaseFile); } void QmitkDicomLocalStorageWidget::SetDatabase(QString databaseFile) { m_LocalDatabase = new ctkDICOMDatabase(databaseFile); m_LocalDatabase->setParent(this); m_Controls->ctkDicomBrowser->setDICOMDatabase(m_LocalDatabase); } void QmitkDicomLocalStorageWidget::OnSeriesSelectionChanged(const QStringList &s) { m_Controls->viewInternalDataButton->setEnabled((s.size() != 0)); } void QmitkDicomLocalStorageWidget::SetupProgressDialog(QWidget* parent) { m_ProgressDialog = new QProgressDialog("DICOM Import", "Cancel", 0, 100, parent,Qt::WindowTitleHint | Qt::WindowSystemMenuHint); m_ProgressDialogLabel = new QLabel("Initialization...", m_ProgressDialog); m_ProgressDialog->setLabel(m_ProgressDialogLabel); m_ProgressDialog->setWindowModality(Qt::ApplicationModal); m_ProgressDialog->setMinimumDuration(0); }