Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add API to select items in the DICOM browser #1002

Merged
merged 1 commit into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Libs/DICOM/Widgets/ctkDICOMBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1749,3 +1749,52 @@ void ctkDICOMBrowser::onIndexingComplete(int patientsAdded, int studiesAdded, in
// allow users of this widget to know that the process has finished
emit directoryImported();
}

//----------------------------------------------------------------------------
void ctkDICOMBrowser::setSelectedItems(ctkDICOMModel::IndexType level, QStringList uids)
{
Q_D(ctkDICOMBrowser);
if (level == ctkDICOMModel::PatientType)
{
d->dicomTableManager->setCurrentPatientsSelection(uids);
}
else if (level == ctkDICOMModel::StudyType)
{
// Select parent patient to make sure the requested studies
// are listed in the study table
QStringList patientUids;
for (const QString& uid : uids)
{
QString patientUid = d->DICOMDatabase->patientForStudy(uid);
if (!patientUids.contains(patientUid))
{
patientUids.append(patientUid);
}
}
this->setSelectedItems(ctkDICOMModel::PatientType, patientUids);

d->dicomTableManager->setCurrentStudiesSelection(uids);
}
else if (level == ctkDICOMModel::SeriesType)
{
// Select parent patients and studies to make sure the requested series
// are listed in the series table
QStringList studyUids;
for (const QString& uid : uids)
{
QString studyUid = d->DICOMDatabase->studyForSeries(uid);
if (!studyUids.contains(studyUid))
{
studyUids.append(studyUid);
}
}
// selecting the study will select the patients as well
this->setSelectedItems(ctkDICOMModel::StudyType, studyUids);

d->dicomTableManager->setCurrentSeriesSelection(uids);
}
else
{
qWarning() << Q_FUNC_INFO << " failed: invalid level";
}
}
5 changes: 5 additions & 0 deletions Libs/DICOM/Widgets/ctkDICOMBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public Q_SLOTS:

void removeSelectedItems(ctkDICOMModel::IndexType level);

/// Select items in a browser table.
/// Selection is also updated at levels higher than the specified level
/// (otherwise items would not be available at the current level).
void setSelectedItems(ctkDICOMModel::IndexType level, QStringList uids);

Q_SIGNALS:
/// Emitted when directory is changed
void databaseDirectoryChanged(const QString&);
Expand Down
21 changes: 21 additions & 0 deletions Libs/DICOM/Widgets/ctkDICOMTableManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,27 @@ QStringList ctkDICOMTableManager::currentSeriesSelection()
return d->seriesTable->currentSelection();
}

//------------------------------------------------------------------------------
void ctkDICOMTableManager::setCurrentPatientsSelection(const QStringList& uids)
{
Q_D(ctkDICOMTableManager);
d->patientsTable->setCurrentSelection(uids);
}

//------------------------------------------------------------------------------
void ctkDICOMTableManager::setCurrentStudiesSelection(const QStringList& uids)
{
Q_D(ctkDICOMTableManager);
d->studiesTable->setCurrentSelection(uids);
}

//------------------------------------------------------------------------------
void ctkDICOMTableManager::setCurrentSeriesSelection(const QStringList& uids)
{
Q_D(ctkDICOMTableManager);
d->seriesTable->setCurrentSelection(uids);
}

//------------------------------------------------------------------------------
void ctkDICOMTableManager::onPatientsQueryChanged(const QStringList &uids)
{
Expand Down
7 changes: 7 additions & 0 deletions Libs/DICOM/Widgets/ctkDICOMTableManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ class CTK_DICOM_WIDGETS_EXPORT ctkDICOMTableManager : public QWidget
Q_INVOKABLE QStringList currentStudiesSelection();
Q_INVOKABLE QStringList currentSeriesSelection();

/**
* @brief Set the current selection of the dicomTableViews
*/
Q_INVOKABLE void setCurrentPatientsSelection(const QStringList& uids);
Q_INVOKABLE void setCurrentStudiesSelection(const QStringList& uids);
Q_INVOKABLE void setCurrentSeriesSelection(const QStringList& uids);

void setDynamicTableLayout(bool);
bool dynamicTableLayout() const;

Expand Down
30 changes: 27 additions & 3 deletions Libs/DICOM/Widgets/ctkDICOMTableView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void ctkDICOMTableViewPrivate::applyColumnProperties()
int columnIndicesCount = columnIndicesByVisualIndex.size();
for (int i=0; i<columnIndicesCount-1; ++i)
{
// Last i elements are already in place
// Last i elements are already in place
for (int j=0; j<columnIndicesCount -i-1; ++j)
{
if (columnIndicesByVisualIndex[j] > columnIndicesByVisualIndex[j+1])
Expand All @@ -306,7 +306,7 @@ void ctkDICOMTableViewPrivate::applyColumnProperties()
// Change column order according to weights (use bubble sort)
for (int i=0; i<columnCount-1; ++i)
{
// Last i elements are already in place
// Last i elements are already in place
for (int j=0; j<columnCount-i-1; ++j)
{
if (columnWeights[j] > columnWeights[j+1])
Expand Down Expand Up @@ -799,6 +799,30 @@ QStringList ctkDICOMTableView::currentSelection() const
return uids;
}

//------------------------------------------------------------------------------
void ctkDICOMTableView::setCurrentSelection(const QStringList& uids)
{
Q_D(const ctkDICOMTableView);

QAbstractItemModel* tableModel = d->tblDicomDatabaseView->model();
int numberOfRows = tableModel->rowCount();
for (int row = 0; row < numberOfRows; ++row)
{
QModelIndex index = tableModel->index(row, 0);
QString uid = index.data().toString();
bool needToSelect = uids.contains(uid);
if (d->tblDicomDatabaseView->selectionModel()->isSelected(index) == needToSelect)
{
// selection state is already correct
continue;
}
QItemSelectionModel::QItemSelectionModel::SelectionFlags flags = QFlags<QItemSelectionModel::SelectionFlag>();
flags.setFlag(needToSelect ? QItemSelectionModel::Select : QItemSelectionModel::Deselect);
flags.setFlag(QItemSelectionModel::Rows);
d->tblDicomDatabaseView->selectionModel()->select(index, flags);
}
}

//------------------------------------------------------------------------------
bool ctkDICOMTableView::filterActive()
{
Expand Down Expand Up @@ -851,7 +875,7 @@ bool ctkDICOMTableView::setBatchUpdate(bool enable)
{
this->onInstanceAdded();
}
}
}
d->batchUpdateModificationPending = false;
d->batchUpdateInstanceAddedPending = false;
return !d->batchUpdate;
Expand Down
5 changes: 5 additions & 0 deletions Libs/DICOM/Widgets/ctkDICOMTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ class CTK_DICOM_WIDGETS_EXPORT ctkDICOMTableView : public QWidget
*/
Q_INVOKABLE QStringList currentSelection() const;

/**
* @brief Select rows corresponding to the provided uids.
*/
Q_INVOKABLE void setCurrentSelection(const QStringList& uids);

/**
* @brief Getting the UIDs for all rows
* @return a QStringList with the uids for all rows
Expand Down