ctkDICOMBrowser.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // std includes
  15. #include <iostream>
  16. // Qt includes
  17. #include <QAction>
  18. #include <QApplication>
  19. #include <QCoreApplication>
  20. #include <QCheckBox>
  21. #include <QDebug>
  22. #include <QFile>
  23. #include <QListView>
  24. #include <QMessageBox>
  25. #include <QProgressDialog>
  26. #include <QSettings>
  27. #include <QStringListModel>
  28. // ctkWidgets includes
  29. #include "ctkDirectoryButton.h"
  30. #include "ctkFileDialog.h"
  31. #include "ctkMessageBox.h"
  32. // ctkDICOMCore includes
  33. #include "ctkDICOMDatabase.h"
  34. #include "ctkDICOMIndexer.h"
  35. // ctkDICOMWidgets includes
  36. #include "ctkDICOMBrowser.h"
  37. #include "ctkDICOMQueryResultsTabWidget.h"
  38. #include "ctkDICOMQueryRetrieveWidget.h"
  39. #include "ctkDICOMQueryWidget.h"
  40. #include "ctkDICOMTableManager.h"
  41. #include "ui_ctkDICOMBrowser.h"
  42. //logger
  43. #include <ctkLogger.h>
  44. static ctkLogger logger("org.commontk.DICOM.Widgets.ctkDICOMBrowser");
  45. //----------------------------------------------------------------------------
  46. class ctkDICOMBrowserPrivate: public Ui_ctkDICOMBrowser
  47. {
  48. public:
  49. ctkDICOMBrowser* const q_ptr;
  50. Q_DECLARE_PUBLIC(ctkDICOMBrowser);
  51. ctkDICOMBrowserPrivate(ctkDICOMBrowser* );
  52. ~ctkDICOMBrowserPrivate();
  53. ctkFileDialog* ImportDialog;
  54. ctkDICOMQueryRetrieveWidget* QueryRetrieveWidget;
  55. QSharedPointer<ctkDICOMDatabase> DICOMDatabase;
  56. QSharedPointer<ctkDICOMIndexer> DICOMIndexer;
  57. QProgressDialog *IndexerProgress;
  58. QProgressDialog *UpdateSchemaProgress;
  59. void showIndexerDialog();
  60. void showUpdateSchemaDialog();
  61. // used when suspending the ctkDICOMModel
  62. QSqlDatabase EmptyDatabase;
  63. // local count variables to keep track of the number of items
  64. // added to the database during an import operation
  65. bool DisplayImportSummary;
  66. int PatientsAddedDuringImport;
  67. int StudiesAddedDuringImport;
  68. int SeriesAddedDuringImport;
  69. int InstancesAddedDuringImport;
  70. };
  71. //----------------------------------------------------------------------------
  72. // ctkDICOMBrowserPrivate methods
  73. ctkDICOMBrowserPrivate::ctkDICOMBrowserPrivate(ctkDICOMBrowser* parent): q_ptr(parent){
  74. DICOMDatabase = QSharedPointer<ctkDICOMDatabase> (new ctkDICOMDatabase);
  75. DICOMIndexer = QSharedPointer<ctkDICOMIndexer> (new ctkDICOMIndexer);
  76. IndexerProgress = 0;
  77. UpdateSchemaProgress = 0;
  78. DisplayImportSummary = true;
  79. PatientsAddedDuringImport = 0;
  80. StudiesAddedDuringImport = 0;
  81. SeriesAddedDuringImport = 0;
  82. InstancesAddedDuringImport = 0;
  83. }
  84. ctkDICOMBrowserPrivate::~ctkDICOMBrowserPrivate()
  85. {
  86. if ( IndexerProgress )
  87. {
  88. delete IndexerProgress;
  89. }
  90. if ( UpdateSchemaProgress )
  91. {
  92. delete UpdateSchemaProgress;
  93. }
  94. }
  95. void ctkDICOMBrowserPrivate::showUpdateSchemaDialog()
  96. {
  97. Q_Q(ctkDICOMBrowser);
  98. if (UpdateSchemaProgress == 0)
  99. {
  100. //
  101. // Set up the Update Schema Progress Dialog
  102. //
  103. UpdateSchemaProgress = new QProgressDialog(
  104. q->tr("DICOM Schema Update"), "Cancel", 0, 100, q,
  105. Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
  106. // We don't want the progress dialog to resize itself, so we bypass the label
  107. // by creating our own
  108. QLabel* progressLabel = new QLabel(q->tr("Initialization..."));
  109. UpdateSchemaProgress->setLabel(progressLabel);
  110. UpdateSchemaProgress->setWindowModality(Qt::ApplicationModal);
  111. UpdateSchemaProgress->setMinimumDuration(0);
  112. UpdateSchemaProgress->setValue(0);
  113. q->connect(DICOMDatabase.data(), SIGNAL(schemaUpdateStarted(int)),
  114. UpdateSchemaProgress, SLOT(setMaximum(int)));
  115. q->connect(DICOMDatabase.data(), SIGNAL(schemaUpdateProgress(int)),
  116. UpdateSchemaProgress, SLOT(setValue(int)));
  117. q->connect(DICOMDatabase.data(), SIGNAL(schemaUpdateProgress(QString)),
  118. progressLabel, SLOT(setText(QString)));
  119. // close the dialog
  120. q->connect(DICOMDatabase.data(), SIGNAL(schemaUpdated()),
  121. UpdateSchemaProgress, SLOT(close()));
  122. }
  123. UpdateSchemaProgress->show();
  124. }
  125. void ctkDICOMBrowserPrivate::showIndexerDialog()
  126. {
  127. Q_Q(ctkDICOMBrowser);
  128. if (IndexerProgress == 0)
  129. {
  130. //
  131. // Set up the Indexer Progress Dialog
  132. //
  133. IndexerProgress = new QProgressDialog( q->tr("DICOM Import"), "Cancel", 0, 100, q,
  134. Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
  135. // We don't want the progress dialog to resize itself, so we bypass the label
  136. // by creating our own
  137. QLabel* progressLabel = new QLabel(q->tr("Initialization..."));
  138. IndexerProgress->setLabel(progressLabel);
  139. IndexerProgress->setWindowModality(Qt::ApplicationModal);
  140. IndexerProgress->setMinimumDuration(0);
  141. IndexerProgress->setValue(0);
  142. q->connect(IndexerProgress, SIGNAL(canceled()),
  143. DICOMIndexer.data(), SLOT(cancel()));
  144. q->connect(DICOMIndexer.data(), SIGNAL(progress(int)),
  145. IndexerProgress, SLOT(setValue(int)));
  146. q->connect(DICOMIndexer.data(), SIGNAL(indexingFilePath(QString)),
  147. progressLabel, SLOT(setText(QString)));
  148. q->connect(DICOMIndexer.data(), SIGNAL(indexingFilePath(QString)),
  149. q, SLOT(onFileIndexed(QString)));
  150. // close the dialog
  151. q->connect(DICOMIndexer.data(), SIGNAL(indexingComplete()),
  152. IndexerProgress, SLOT(close()));
  153. // stop indexing and reset the database if canceled
  154. q->connect(IndexerProgress, SIGNAL(canceled()),
  155. DICOMIndexer.data(), SLOT(cancel()));
  156. // allow users of this widget to know that the process has finished
  157. q->connect(IndexerProgress, SIGNAL(canceled()),
  158. q, SIGNAL(directoryImported()));
  159. q->connect(DICOMIndexer.data(), SIGNAL(indexingComplete()),
  160. q, SIGNAL(directoryImported()));
  161. }
  162. IndexerProgress->show();
  163. }
  164. //----------------------------------------------------------------------------
  165. // ctkDICOMBrowser methods
  166. //----------------------------------------------------------------------------
  167. ctkDICOMBrowser::ctkDICOMBrowser(QWidget* _parent):Superclass(_parent),
  168. d_ptr(new ctkDICOMBrowserPrivate(this))
  169. {
  170. Q_D(ctkDICOMBrowser);
  171. d->setupUi(this);
  172. // signals related to tracking inserts
  173. connect(d->DICOMDatabase.data(), SIGNAL(patientAdded(int,QString,QString,QString)), this,
  174. SLOT(onPatientAdded(int,QString,QString,QString)));
  175. connect(d->DICOMDatabase.data(), SIGNAL(studyAdded(QString)), this, SLOT(onStudyAdded(QString)));
  176. connect(d->DICOMDatabase.data(), SIGNAL(seriesAdded(QString)), this, SLOT(onSeriesAdded(QString)));
  177. connect(d->DICOMDatabase.data(), SIGNAL(instanceAdded(QString)), this, SLOT(onInstanceAdded(QString)));
  178. connect(d->tableDensityComboBox ,SIGNAL(currentIndexChanged (const QString&)),
  179. this, SLOT(onTablesDensityComboBox(QString)));
  180. //Set ToolBar button style
  181. d->ToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
  182. //Initialize Q/R widget
  183. d->QueryRetrieveWidget = new ctkDICOMQueryRetrieveWidget();
  184. d->QueryRetrieveWidget->setWindowModality ( Qt::ApplicationModal );
  185. //initialize directory from settings, then listen for changes
  186. QSettings settings;
  187. if ( settings.value("DatabaseDirectory", "") == "" )
  188. {
  189. QString directory = QString("./ctkDICOM-Database");
  190. settings.setValue("DatabaseDirectory", directory);
  191. settings.sync();
  192. }
  193. QString databaseDirectory = settings.value("DatabaseDirectory").toString();
  194. this->setDatabaseDirectory(databaseDirectory);
  195. d->DirectoryButton->setDirectory(databaseDirectory);
  196. d->dicomTableManager->setDICOMDatabase(d->DICOMDatabase.data());
  197. // TableView signals
  198. connect(d->dicomTableManager, SIGNAL(patientsSelectionChanged(const QItemSelection&, const QItemSelection&)),
  199. this, SLOT(onModelSelected(const QItemSelection&,const QItemSelection&)));
  200. connect(d->dicomTableManager, SIGNAL(studiesSelectionChanged(const QItemSelection&, const QItemSelection&)),
  201. this, SLOT(onModelSelected(const QItemSelection&,const QItemSelection&)));
  202. connect(d->dicomTableManager, SIGNAL(seriesSelectionChanged(const QItemSelection&, const QItemSelection&)),
  203. this, SLOT(onModelSelected(const QItemSelection&,const QItemSelection&)));
  204. connect(d->DirectoryButton, SIGNAL(directoryChanged(QString)), this, SLOT(setDatabaseDirectory(QString)));
  205. //Initialize import widget
  206. d->ImportDialog = new ctkFileDialog();
  207. QCheckBox* importCheckbox = new QCheckBox("Copy on import", d->ImportDialog);
  208. importCheckbox->setCheckState(Qt::Checked);
  209. d->ImportDialog->setBottomWidget(importCheckbox);
  210. d->ImportDialog->setFileMode(QFileDialog::Directory);
  211. d->ImportDialog->setLabelText(QFileDialog::Accept,"Import");
  212. d->ImportDialog->setWindowTitle("Import DICOM files from directory ...");
  213. d->ImportDialog->setWindowModality(Qt::ApplicationModal);
  214. //connect signal and slots
  215. connect(d->ImportDialog, SIGNAL(fileSelected(QString)),this,SLOT(onImportDirectory(QString)));
  216. connect(d->QueryRetrieveWidget, SIGNAL(canceled()), d->QueryRetrieveWidget, SLOT(hide()) );
  217. connect(d->QueryRetrieveWidget, SIGNAL(canceled()), this, SLOT(onQueryRetrieveFinished()) );
  218. }
  219. //----------------------------------------------------------------------------
  220. ctkDICOMBrowser::~ctkDICOMBrowser()
  221. {
  222. Q_D(ctkDICOMBrowser);
  223. d->QueryRetrieveWidget->deleteLater();
  224. d->ImportDialog->deleteLater();
  225. }
  226. //----------------------------------------------------------------------------
  227. bool ctkDICOMBrowser::displayImportSummary()
  228. {
  229. Q_D(ctkDICOMBrowser);
  230. return d->DisplayImportSummary;
  231. }
  232. //----------------------------------------------------------------------------
  233. void ctkDICOMBrowser::setDisplayImportSummary(bool onOff)
  234. {
  235. Q_D(ctkDICOMBrowser);
  236. d->DisplayImportSummary = onOff;
  237. }
  238. //----------------------------------------------------------------------------
  239. int ctkDICOMBrowser::patientsAddedDuringImport()
  240. {
  241. Q_D(ctkDICOMBrowser);
  242. return d->PatientsAddedDuringImport;
  243. }
  244. //----------------------------------------------------------------------------
  245. int ctkDICOMBrowser::studiesAddedDuringImport()
  246. {
  247. Q_D(ctkDICOMBrowser);
  248. return d->StudiesAddedDuringImport;
  249. }
  250. //----------------------------------------------------------------------------
  251. int ctkDICOMBrowser::seriesAddedDuringImport()
  252. {
  253. Q_D(ctkDICOMBrowser);
  254. return d->SeriesAddedDuringImport;
  255. }
  256. //----------------------------------------------------------------------------
  257. int ctkDICOMBrowser::instancesAddedDuringImport()
  258. {
  259. Q_D(ctkDICOMBrowser);
  260. return d->InstancesAddedDuringImport;
  261. }
  262. //----------------------------------------------------------------------------
  263. void ctkDICOMBrowser::updateDatabaseSchemaIfNeeded()
  264. {
  265. Q_D(ctkDICOMBrowser);
  266. d->showUpdateSchemaDialog();
  267. d->DICOMDatabase->updateSchemaIfNeeded();
  268. }
  269. //----------------------------------------------------------------------------
  270. void ctkDICOMBrowser::setDatabaseDirectory(const QString& directory)
  271. {
  272. Q_D(ctkDICOMBrowser);
  273. QSettings settings;
  274. settings.setValue("DatabaseDirectory", directory);
  275. settings.sync();
  276. //close the active DICOM database
  277. d->DICOMDatabase->closeDatabase();
  278. //open DICOM database on the directory
  279. QString databaseFileName = directory + QString("/ctkDICOM.sql");
  280. try
  281. {
  282. d->DICOMDatabase->openDatabase( databaseFileName );
  283. }
  284. catch (std::exception e)
  285. {
  286. std::cerr << "Database error: " << qPrintable(d->DICOMDatabase->lastError()) << "\n";
  287. d->DICOMDatabase->closeDatabase();
  288. return;
  289. }
  290. // update the database schema if needed and provide progress
  291. this->updateDatabaseSchemaIfNeeded();
  292. //pass DICOM database instance to Import widget
  293. d->QueryRetrieveWidget->setRetrieveDatabase(d->DICOMDatabase);
  294. // update the button and let any connected slots know about the change
  295. d->DirectoryButton->setDirectory(directory);
  296. d->dicomTableManager->updateTableViews();
  297. emit databaseDirectoryChanged(directory);
  298. }
  299. //----------------------------------------------------------------------------
  300. QString ctkDICOMBrowser::databaseDirectory() const
  301. {
  302. QSettings settings;
  303. return settings.value("DatabaseDirectory").toString();
  304. }
  305. //------------------------------------------------------------------------------
  306. void ctkDICOMBrowser::setTagsToPrecache( const QStringList tags)
  307. {
  308. Q_D(ctkDICOMBrowser);
  309. d->DICOMDatabase->setTagsToPrecache(tags);
  310. }
  311. //------------------------------------------------------------------------------
  312. const QStringList ctkDICOMBrowser::tagsToPrecache()
  313. {
  314. Q_D(ctkDICOMBrowser);
  315. return d->DICOMDatabase->tagsToPrecache();
  316. }
  317. //----------------------------------------------------------------------------
  318. ctkDICOMDatabase* ctkDICOMBrowser::database(){
  319. Q_D(ctkDICOMBrowser);
  320. return d->DICOMDatabase.data();
  321. }
  322. //----------------------------------------------------------------------------
  323. ctkDICOMTableManager* ctkDICOMBrowser::dicomTableManager()
  324. {
  325. Q_D(ctkDICOMBrowser);
  326. return d->dicomTableManager;
  327. }
  328. //----------------------------------------------------------------------------
  329. void ctkDICOMBrowser::onFileIndexed(const QString& filePath)
  330. {
  331. // Update the progress dialog when the file name changes
  332. // - also allows for cancel button
  333. QCoreApplication::instance()->processEvents();
  334. qDebug() << "Indexing \n\n\n\n" << filePath <<"\n\n\n";
  335. }
  336. //----------------------------------------------------------------------------
  337. void ctkDICOMBrowser::openImportDialog()
  338. {
  339. Q_D(ctkDICOMBrowser);
  340. d->ImportDialog->show();
  341. d->ImportDialog->raise();
  342. }
  343. //----------------------------------------------------------------------------
  344. void ctkDICOMBrowser::openExportDialog()
  345. {
  346. }
  347. //----------------------------------------------------------------------------
  348. void ctkDICOMBrowser::openQueryDialog()
  349. {
  350. Q_D(ctkDICOMBrowser);
  351. d->QueryRetrieveWidget->show();
  352. d->QueryRetrieveWidget->raise();
  353. }
  354. //----------------------------------------------------------------------------
  355. void ctkDICOMBrowser::onQueryRetrieveFinished()
  356. {
  357. Q_D(ctkDICOMBrowser);
  358. emit this->queryRetrieveFinished();
  359. }
  360. //----------------------------------------------------------------------------
  361. void ctkDICOMBrowser::onRemoveAction()
  362. {
  363. Q_D(ctkDICOMBrowser);
  364. QStringList selectedSeriesUIDs = d->dicomTableManager->currentSeriesSelection();
  365. foreach (const QString& uid, selectedSeriesUIDs)
  366. {
  367. d->DICOMDatabase->removeSeries(uid);
  368. }
  369. QStringList selectedStudiesUIDs = d->dicomTableManager->currentStudiesSelection();
  370. foreach (const QString& uid, selectedStudiesUIDs)
  371. {
  372. d->DICOMDatabase->removeStudy(uid);
  373. }
  374. QStringList selectedPatientUIDs = d->dicomTableManager->currentPatientsSelection();
  375. foreach (const QString& uid, selectedPatientUIDs)
  376. {
  377. d->DICOMDatabase->removePatient(uid);
  378. }
  379. // Update the table views
  380. d->dicomTableManager->updateTableViews();
  381. }
  382. //----------------------------------------------------------------------------
  383. void ctkDICOMBrowser::onRepairAction()
  384. {
  385. Q_D(ctkDICOMBrowser);
  386. QMessageBox* repairMessageBox;
  387. repairMessageBox = new QMessageBox;
  388. repairMessageBox->setWindowTitle("Database Repair");
  389. QStringList allFiles(d->DICOMDatabase->allFiles());
  390. QSet<QString> corruptedSeries;
  391. QStringList::const_iterator it;
  392. for (it = allFiles.constBegin(); it!= allFiles.constEnd();++it)
  393. {
  394. QString fileName(*it);
  395. QFile dicomFile(fileName);
  396. if(!dicomFile.exists())
  397. {
  398. QString seriesUid = d->DICOMDatabase->seriesForFile(fileName);
  399. corruptedSeries.insert(seriesUid);
  400. }
  401. }
  402. if (corruptedSeries.size() == 0)
  403. {
  404. repairMessageBox->setText("All the files in the local database are available.");
  405. repairMessageBox->addButton(QMessageBox::Ok);
  406. repairMessageBox->exec();
  407. }
  408. else
  409. {
  410. repairMessageBox->addButton(QMessageBox::Yes);
  411. repairMessageBox->addButton(QMessageBox::No);
  412. QSet<QString>::iterator i;
  413. for (i = corruptedSeries.begin(); i != corruptedSeries.end(); ++i)
  414. {
  415. QStringList fileList (d->DICOMDatabase->filesForSeries(*i));
  416. QString unavailableFileNames;
  417. QStringList::const_iterator it;
  418. for (it= fileList.constBegin(); it!= fileList.constEnd();++it)
  419. {
  420. unavailableFileNames.append(*it+"\n");
  421. }
  422. QString firstFile (*(fileList.constBegin()));
  423. QHash<QString,QString> descriptions (d->DICOMDatabase->descriptionsForFile(firstFile));
  424. repairMessageBox->setText("The files for the following series are not available on the disk: \nPatient Name: "
  425. + descriptions["PatientsName"]+ "\n"+
  426. "Study Desciption: " + descriptions["StudyDescription"]+ "\n"+
  427. "Series Desciption: " + descriptions["SeriesDescription"]+ "\n"+
  428. "Do you want to remove the series from the DICOM database? ");
  429. repairMessageBox->setDetailedText(unavailableFileNames);
  430. int selection = repairMessageBox->exec();
  431. if (selection == QMessageBox::Yes)
  432. {
  433. d->DICOMDatabase->removeSeries(*i);
  434. d->dicomTableManager->updateTableViews();
  435. }
  436. }
  437. }
  438. }
  439. //----------------------------------------------------------------------------
  440. void ctkDICOMBrowser::onTablesDensityComboBox(QString density)
  441. {
  442. Q_D(ctkDICOMBrowser);
  443. if ( density == "Comfortable")
  444. {
  445. d->dicomTableManager->setDisplayDensity(ctkDICOMTableManager::Comfortable);
  446. }
  447. else if ( density == "Cozy")
  448. {
  449. d->dicomTableManager->setDisplayDensity(ctkDICOMTableManager::Cozy);
  450. }
  451. else if ( density == "Compact")
  452. {
  453. d->dicomTableManager->setDisplayDensity(ctkDICOMTableManager::Compact);
  454. }
  455. }
  456. //----------------------------------------------------------------------------
  457. void ctkDICOMBrowser::onPatientAdded(int databaseID, QString patientID, QString patientName, QString patientBirthDate )
  458. {
  459. Q_D(ctkDICOMBrowser);
  460. Q_UNUSED(databaseID);
  461. Q_UNUSED(patientID);
  462. Q_UNUSED(patientName);
  463. Q_UNUSED(patientBirthDate);
  464. ++d->PatientsAddedDuringImport;
  465. }
  466. //----------------------------------------------------------------------------
  467. void ctkDICOMBrowser::onStudyAdded(QString studyUID)
  468. {
  469. Q_D(ctkDICOMBrowser);
  470. Q_UNUSED(studyUID);
  471. ++d->StudiesAddedDuringImport;
  472. }
  473. //----------------------------------------------------------------------------
  474. void ctkDICOMBrowser::onSeriesAdded(QString seriesUID)
  475. {
  476. Q_D(ctkDICOMBrowser);
  477. Q_UNUSED(seriesUID);
  478. ++d->SeriesAddedDuringImport;
  479. }
  480. //----------------------------------------------------------------------------
  481. void ctkDICOMBrowser::onInstanceAdded(QString instanceUID)
  482. {
  483. Q_D(ctkDICOMBrowser);
  484. Q_UNUSED(instanceUID);
  485. ++d->InstancesAddedDuringImport;
  486. }
  487. //----------------------------------------------------------------------------
  488. void ctkDICOMBrowser::onImportDirectory(QString directory)
  489. {
  490. Q_D(ctkDICOMBrowser);
  491. if (QDir(directory).exists())
  492. {
  493. QString targetDirectory;
  494. QCheckBox* copyOnImport = qobject_cast<QCheckBox*>(d->ImportDialog->bottomWidget());
  495. ctkMessageBox importTypeDialog;
  496. QString message("Do you want to copy the files to the local database directory or just add the links?");
  497. importTypeDialog.setText(message);
  498. importTypeDialog.setIcon(QMessageBox::Question);
  499. importTypeDialog.addButton("Copy",QMessageBox::AcceptRole);
  500. importTypeDialog.addButton("Add Link",QMessageBox::RejectRole);
  501. importTypeDialog.setDontShowAgainSettingsKey( "MainWindow/DontConfirmCopyOnImport" );
  502. int selection = importTypeDialog.exec();
  503. if (selection== QMessageBox::AcceptRole)
  504. {
  505. copyOnImport->setCheckState(Qt::Checked);
  506. }
  507. else
  508. {
  509. copyOnImport->setCheckState(Qt::Unchecked);
  510. }
  511. // reset counts
  512. d->PatientsAddedDuringImport = 0;
  513. d->StudiesAddedDuringImport = 0;
  514. d->SeriesAddedDuringImport = 0;
  515. d->InstancesAddedDuringImport = 0;
  516. if (copyOnImport->checkState() == Qt::Checked)
  517. {
  518. targetDirectory = d->DICOMDatabase->databaseDirectory();
  519. }
  520. // show progress dialog and perform indexing
  521. d->showIndexerDialog();
  522. d->DICOMIndexer->addDirectory(*d->DICOMDatabase,directory,targetDirectory);
  523. // display summary result
  524. if (d->DisplayImportSummary)
  525. {
  526. QString message = "Directory import completed.\n\n";
  527. message += QString("%1 New Patients\n").arg(QString::number(d->PatientsAddedDuringImport));
  528. message += QString("%1 New Studies\n").arg(QString::number(d->StudiesAddedDuringImport));
  529. message += QString("%1 New Series\n").arg(QString::number(d->SeriesAddedDuringImport));
  530. message += QString("%1 New Instances\n").arg(QString::number(d->InstancesAddedDuringImport));
  531. QMessageBox::information(this,"DICOM Directory Import", message);
  532. }
  533. }
  534. }
  535. //----------------------------------------------------------------------------
  536. void ctkDICOMBrowser::onModelSelected(const QItemSelection &item1, const QItemSelection &item2)
  537. {
  538. Q_UNUSED(item1);
  539. Q_UNUSED(item2);
  540. Q_D(ctkDICOMBrowser);
  541. d->ActionRemove->setEnabled(true);
  542. }