28 #include <QCoreApplication>
31 #include <QMessageBox>
33 #include <QModelIndex>
34 #include <QPersistentModelIndex>
35 #include <QProgressDialog>
42 #include <QHBoxLayout>
46 #include "ctkDirectoryButton.h"
47 #include "ctkFileDialog.h"
50 #include "ctkDICOMDatabase.h"
51 #include "ctkDICOMFilterProxyModel.h"
52 #include "ctkDICOMIndexer.h"
58 #include "ctkThumbnailLabel.h"
59 #include "ctkDICOMQueryResultsTabWidget.h"
60 #include "ctkDICOMQueryRetrieveWidget.h"
61 #include "ctkDICOMQueryWidget.h"
73 #include <ctkLogger.h>
74 static ctkLogger logger(
"org.commontk.DICOM.Widgets.DICOMAppWidget");
115 std::map<ctkDICOMModel::IndexType, QStringList>
getSelection()
const;
128 ThumbnailsWidget(NULL),
129 ThumbnailWidthSlider(NULL),
133 QueryRetrieveWidget(NULL)
135 DICOMDatabase = QSharedPointer<ctkDICOMDatabase> (
new ctkDICOMDatabase);
137 DICOMDatabase->setThumbnailGenerator(ThumbnailGenerator.data());
163 ActionImport->setToolTip(
"Open and load a DICOM file or folder");
168 ActionQuery->setToolTip(
"Query and Retrieve DICOM studies from a DICOM node");
169 q->connect(
ActionQuery, SIGNAL(triggered()), q, SLOT(openQueryDialog()));
173 ActionRemove->setToolTip(
"Remove selection from database");
174 q->connect(
ActionRemove, SIGNAL(triggered()), q, SLOT(onRemoveAction()));
177 QSplitter* splitter =
new QSplitter;
178 splitter->setOrientation(Qt::Vertical);
182 TreeView->setAlternatingRowColors(
true);
185 QWidget* ThumbnailsFullWidget =
new QWidget;
186 splitter->addWidget(ThumbnailsFullWidget);
187 QVBoxLayout* ThumbnailsFullWidgetLayout =
new QVBoxLayout(ThumbnailsFullWidget);
188 ThumbnailsFullWidgetLayout->setMargin(0);
191 ThumbnailsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
200 connect(
ThumbnailWidthSlider, SIGNAL(valueChanged(
int)), q, SLOT(onThumbnailWidthSliderValueChanged(
int)));
209 q->connect(db, SIGNAL(schemaUpdateStarted(
int)), q, SLOT(schemaUpdateStarted(
int)));
210 q->connect(db, SIGNAL(schemaUpdateProgress(
int)), q, SLOT(schemaUpdateProgress(
int)));
211 q->connect(db, SIGNAL(schemaUpdateProgress(QString)), q, SLOT(schemaUpdateProgress(QString)));
212 q->connect(db, SIGNAL(schemaUpdated()), q, SLOT(schemaUpdated()));
254 void DICOMAppWidget::schemaUpdateStarted(
int)
258 void DICOMAppWidget::schemaUpdateProgress(QString val)
261 void DICOMAppWidget::schemaUpdateProgress(
int val)
264 void DICOMAppWidget::schemaUpdated()
271 QModelIndexList selection =
TreeView->selectionModel()->selectedIndexes();
274 foreach(index,selection)
276 if (index.column()!=0)
286 std::map<ctkDICOMModel::IndexType, QStringList> retval;
287 QModelIndexList selection =
TreeView->selectionModel()->selectedIndexes();
290 foreach(index,selection)
292 QModelIndex index0 = index.sibling(index.row(), 0);
297 retval[type].removeDuplicates();
333 connect(&d->Importer, SIGNAL(indexingCompleted()),
334 &d->mDICOMModel, SLOT(reset()));
339 d->TreeView->setSortingEnabled(
true);
340 d->TreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
341 d->TreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
342 d->DICOMProxyModel.setSourceModel(&d->mDICOMModel);
343 d->TreeView->setModel(&d->mDICOMModel);
345 d->ThumbnailsWidget->setThumbnailSize(
346 QSize(d->ThumbnailWidthSlider->value(), d->ThumbnailWidthSlider->value()));
349 connect(d->TreeView, SIGNAL(collapsed(QModelIndex)),
this, SLOT(
onTreeCollapsed(QModelIndex)));
350 connect(d->TreeView, SIGNAL(expanded(QModelIndex)),
this, SLOT(
onTreeExpanded(QModelIndex)));
353 d->ToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
359 connect(d->TreeView->selectionModel(),
360 &QItemSelectionModel::selectionChanged,
363 connect(d->TreeView->selectionModel(),
364 &QItemSelectionModel::currentChanged,
369 connect(d->TreeView, SIGNAL(clicked(QModelIndex)),
this, SLOT(
onModelSelected(QModelIndex)));
387 return d->Importer.displayImportSummary();
394 return d->Importer.setDisplayImportSummary(onOff);
401 return d->Importer.patientsAddedDuringImport();
408 return d->Importer.studiesAddedDuringImport();
415 return d->Importer.seriesAddedDuringImport();
422 return d->Importer.instancesAddedDuringImport();
430 d->showUpdateSchemaDialog();
431 d->DICOMDatabase->updateSchemaIfNeeded();
440 settings.
setValue(
"DatabaseDirectory", directory);
444 d->DICOMDatabase->closeDatabase();
447 QString databaseFileName = directory + QString(
"/ctkDICOM.sql");
450 d->DICOMDatabase->openDatabase( databaseFileName );
452 CX_LOG_CHANNEL_INFO(
"dicom") <<
"Open Database " << databaseFileName.toStdString() <<
", open= " << d->DICOMDatabase->isOpen();
455 catch (std::exception& e)
457 CX_LOG_CHANNEL_ERROR(
"dicom") <<
"Database error: " << qPrintable(d->DICOMDatabase->lastError());
459 d->DICOMDatabase->closeDatabase();
466 d->mDICOMModel.setDatabase(d->DICOMDatabase);
468 d->TreeView->resizeColumnToContents(0);
469 d->Importer.setDatabase(d->DICOMDatabase);
472 d->ThumbnailsWidget->setDatabaseDirectory(directory);
473 d->ThumbnailsWidget->setDatabase(d->DICOMDatabase);
481 return settings.
value(
"DatabaseDirectory").toString();
488 d->DICOMDatabase->setTagsToPrecache(tags);
495 return d->DICOMDatabase->tagsToPrecache();
501 return d->DICOMDatabase.data();
509 d->getQueryRetrieveWidget()->show();
510 d->getQueryRetrieveWidget()->raise();
518 d->mDICOMModel.reset();
542 d->removeSelection();
549 d->mDICOMModel.setDatabase(d->DICOMDatabase);
556 d->mDICOMModel.reset();
563 d->Importer.onImportDirectory(directory);
573 d->ThumbnailsWidget->addThumbnails(next);
584 QModelIndex index0 = index.sibling(index.row(), 0);
586 d->ActionRemove->setEnabled(
593 d->ActionRemove->setEnabled(
false);
601 d->TreeView->resizeColumnToContents(0);
608 d->TreeView->resizeColumnToContents(0);
609 d->TreeView->resizeColumnToContents(1);
616 d->ThumbnailsWidget->setThumbnailSize(QSize(val, val));
622 d->ToolBar->addAction(action);
#define CX_LOG_CHANNEL_INFO(channel)
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void setValue(const QString &key, const QVariant &value)
Settings * settings()
Shortcut for accessing the settings instance.
thumbnail generator class
#define CX_LOG_CHANNEL_ERROR(channel)