Skip to content

Commit

Permalink
BUG: Conceal empty patient and study widgets during filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Punzo committed May 16, 2024
1 parent 890e51b commit 13d243c
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 111 deletions.
1 change: 0 additions & 1 deletion Libs/DICOM/Core/ctkDICOMQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ bool ctkDICOMQuery::queryPatients()
{
logger.warn(QString("ctkDICOMQuery: the number of responses of the query task at patients level "
"surpassed the maximum value of permitted results (i.e. %1).").arg(d->MaximumPatientsQuery));

break;
}
DcmDataset *dataset = (*it)->m_dataset;
Expand Down
1 change: 0 additions & 1 deletion Libs/DICOM/Core/ctkDICOMScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMScheduler : public ctkJobScheduler
Q_INVOKABLE void runJobs(const QMap<QString, ctkDICOMJobDetail>& jobDetails);
Q_INVOKABLE void raiseJobsPriorityForSeries(const QStringList& selectedSeriesInstanceUIDs,
QThread::Priority priority = QThread::HighestPriority);

///@}

///@{
Expand Down
25 changes: 19 additions & 6 deletions Libs/DICOM/Widgets/ctkDICOMPatientItemWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ctkDICOMPatientItemWidgetPrivate : public Ui_ctkDICOMPatientItemWidget
QString formatDate(const QString&);
bool isStudyItemAlreadyAdded(const QString& studyItem);
void clearLayout(QLayout* layout, bool deleteWidgets = true);
void createStudies(bool queryRetrieve = true);
void createStudies();
void updateAllowedServersUIFromDB();
void setAllDeniedServerEnabledStatus(bool enabled);
void saveAllowedServersStringListFromUI();
Expand Down Expand Up @@ -100,6 +100,8 @@ class ctkDICOMPatientItemWidgetPrivate : public Ui_ctkDICOMPatientItemWidget
QStringList AllowedServers = QStringList();

bool IsGUIUpdating;
bool QueryOn;
bool RetrieveOn;
};

//----------------------------------------------------------------------------
Expand All @@ -125,6 +127,8 @@ ctkDICOMPatientItemWidgetPrivate::ctkDICOMPatientItemWidgetPrivate(ctkDICOMPatie
this->StudiesListVerticalSpacer = new QSpacerItem(0, 5, QSizePolicy::Fixed, QSizePolicy::Expanding);

this->IsGUIUpdating = false;
this->QueryOn = true;
this->RetrieveOn = true;
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -233,7 +237,7 @@ void ctkDICOMPatientItemWidgetPrivate::clearLayout(QLayout* layout, bool deleteW
}

//----------------------------------------------------------------------------
void ctkDICOMPatientItemWidgetPrivate::createStudies(bool queryRetrieve)
void ctkDICOMPatientItemWidgetPrivate::createStudies()
{
Q_Q(ctkDICOMPatientItemWidget);
if (this->IsGUIUpdating)
Expand Down Expand Up @@ -269,6 +273,7 @@ void ctkDICOMPatientItemWidgetPrivate::createStudies(bool queryRetrieve)
QStringList studiesList = this->DicomDatabase->studiesForPatient(this->PatientItem);
if (studiesList.count() == 0)
{
q->emit updateGUIFinished();
return;
}

Expand Down Expand Up @@ -369,7 +374,7 @@ void ctkDICOMPatientItemWidgetPrivate::createStudies(bool queryRetrieve)
if (cont < this->NumberOfStudiesPerPatient)
{
studyItemWidget->setCollapsed(false);
studyItemWidget->generateSeries(queryRetrieve);
studyItemWidget->generateSeries(this->QueryOn, this->RetrieveOn);
}
cont++;

Expand All @@ -388,6 +393,7 @@ void ctkDICOMPatientItemWidgetPrivate::createStudies(bool queryRetrieve)
studiesListWidgetLayout->addItem(this->StudiesListVerticalSpacer);

this->IsGUIUpdating = false;
q->emit updateGUIFinished();
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -761,6 +767,8 @@ void ctkDICOMPatientItemWidget::addStudyItemWidget(const QString& studyItem)
this, SLOT(onSeriesItemClicked()));
this->connect(studyItemWidget->seriesListTableWidget(), SIGNAL(itemSelectionChanged()),
this, SLOT(raiseSelectedSeriesJobsPriority()));
this->connect(studyItemWidget, SIGNAL(updateGUIFinished()),
this, SIGNAL(updateGUIFinished()));

d->StudyItemWidgetsList.append(studyItemWidget);
}
Expand Down Expand Up @@ -830,17 +838,22 @@ void ctkDICOMPatientItemWidget::updateAllowedServersUIFromDB()
}

//------------------------------------------------------------------------------
void ctkDICOMPatientItemWidget::generateStudies(bool queryRetrieve)
void ctkDICOMPatientItemWidget::generateStudies(bool query, bool retrieve)
{
Q_D(ctkDICOMPatientItemWidget);

d->createStudies(queryRetrieve);
if (queryRetrieve && d->Scheduler && d->Scheduler->queryRetrieveServersCount() > 0)
d->QueryOn = query;
d->RetrieveOn = retrieve;
if (query && d->Scheduler && d->Scheduler->queryRetrieveServersCount() > 0)
{
d->Scheduler->queryStudies(d->PatientID,
QThread::NormalPriority,
d->AllowedServers);
}
else
{
d->createStudies();
}
}

//------------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion Libs/DICOM/Widgets/ctkDICOMPatientItemWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,17 @@ class CTK_DICOM_WIDGETS_EXPORT ctkDICOMPatientItemWidget : public QWidget
///@}

public Q_SLOTS:
void generateStudies(bool queryRetrieve = true);
void generateStudies(bool query = true, bool retrieve = true);
void generateSeriesAtToggle(bool toggled = true, const QString& studyItem = "");
void updateGUIFromScheduler(const QVariant& data);
void onSeriesItemClicked();
void raiseSelectedSeriesJobsPriority();
void onPatientServersCheckableComboBoxChanged();

Q_SIGNALS:
/// Emitted when the GUI finished to update after a studies query.
void updateGUIFinished();

protected:
QScopedPointer<ctkDICOMPatientItemWidgetPrivate> d_ptr;

Expand Down
46 changes: 29 additions & 17 deletions Libs/DICOM/Widgets/ctkDICOMSeriesItemWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ctkDICOMSeriesItemWidgetPrivate : public Ui_ctkDICOMSeriesItemWidget

void init();
QString getDICOMCenterFrameFromInstances(QStringList instancesList);
void createThumbnail(ctkDICOMJobDetail td, bool queryRetrieve = true);
void createThumbnail(ctkDICOMJobDetail td);
void drawModalityThumbnail();
void drawThumbnail(const QString& file, int numberOfFrames);
void drawTextWithShadow(QPainter *painter,
Expand Down Expand Up @@ -101,6 +101,9 @@ class ctkDICOMSeriesItemWidgetPrivate : public Ui_ctkDICOMSeriesItemWidget
int NumberOfDownloads;
QImage ThumbnailImage;
bool isThumbnailDocument;

bool QueryOn;
bool RetrieveOn;
};

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -133,6 +136,9 @@ ctkDICOMSeriesItemWidgetPrivate::ctkDICOMSeriesItemWidgetPrivate(ctkDICOMSeriesI

this->DicomDatabase = nullptr;
this->Scheduler = nullptr;

this->QueryOn = true;
this->RetrieveOn = true;
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -197,7 +203,7 @@ QString ctkDICOMSeriesItemWidgetPrivate::getDICOMCenterFrameFromInstances(QStrin
}

//----------------------------------------------------------------------------
void ctkDICOMSeriesItemWidgetPrivate::createThumbnail(ctkDICOMJobDetail td, bool queryRetrieve)
void ctkDICOMSeriesItemWidgetPrivate::createThumbnail(ctkDICOMJobDetail td)
{
if (!this->DicomDatabase)
{
Expand Down Expand Up @@ -301,7 +307,7 @@ void ctkDICOMSeriesItemWidgetPrivate::createThumbnail(ctkDICOMJobDetail td, bool
(jobType == ctkDICOMJobResponseSet::JobType::None ||
jobType == ctkDICOMJobResponseSet::JobType::QueryInstances))
{
if (queryRetrieve)
if (this->RetrieveOn)
{
this->Scheduler->retrieveSOPInstance(this->PatientID,
this->StudyInstanceUID,
Expand All @@ -326,7 +332,7 @@ void ctkDICOMSeriesItemWidgetPrivate::createThumbnail(ctkDICOMJobDetail td, bool
this->Scheduler->getJobsByDICOMUIDs({},
{},
{this->SeriesInstanceUID});
if (jobs.count() == 0 && queryRetrieve)
if (jobs.count() == 0 && this->RetrieveOn)
{
this->Scheduler->retrieveSeries(this->PatientID,
this->StudyInstanceUID,
Expand Down Expand Up @@ -417,15 +423,15 @@ void ctkDICOMSeriesItemWidgetPrivate::drawThumbnail(const QString& file, int num
font.setPixelSize(textSize);

QPixmap resultPixmap(scaledThumbnailSizePixel, scaledThumbnailSizePixel);
resultPixmap.fill(Qt::transparent);

ctkDICOMThumbnailGenerator thumbnailGenerator;
thumbnailGenerator.setWidth(scaledThumbnailSizePixel);
thumbnailGenerator.setHeight(scaledThumbnailSizePixel);
bool thumbnailGenerated = true;
bool emptyThumbnailGenerated = false;
QPainter painter;
if (this->ThumbnailImage.width() != scaledThumbnailSizePixel)

if (this->ThumbnailImage.isNull())
{
if (!thumbnailGenerator.generateThumbnail(file, this->ThumbnailImage))
{
Expand All @@ -443,11 +449,12 @@ void ctkDICOMSeriesItemWidgetPrivate::drawThumbnail(const QString& file, int num
painter.end();
}
}
else
{
}

if (thumbnailGenerated)
{
QColor firstPixelColor = this->ThumbnailImage.pixelColor(0, 0);
resultPixmap.fill(firstPixelColor);
}
}

if (thumbnailGenerated && !this->isThumbnailDocument)
Expand All @@ -456,7 +463,6 @@ void ctkDICOMSeriesItemWidgetPrivate::drawThumbnail(const QString& file, int num
{
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
painter.setRenderHint(QPainter::LosslessImageRendering, true);
painter.setFont(font);

QRectF rect = resultPixmap.rect();
Expand Down Expand Up @@ -770,11 +776,11 @@ void ctkDICOMSeriesItemWidget::forceRetrieve()
{
Q_D(ctkDICOMSeriesItemWidget);

d->IsCloud = true;
d->IsCloud = false;
d->RetrieveFailed = false;
d->StopJobs = false;
ctkDICOMJobDetail td;
d->createThumbnail(td);
d->DicomDatabase->removeSeries(d->SeriesInstanceUID, false, false);
this->generateInstances(true);
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -862,7 +868,7 @@ void ctkDICOMSeriesItemWidget::setDicomDatabase(QSharedPointer<ctkDICOMDatabase>
}

//------------------------------------------------------------------------------
void ctkDICOMSeriesItemWidget::generateInstances(bool queryRetrieve)
void ctkDICOMSeriesItemWidget::generateInstances(bool query, bool retrieve)
{
Q_D(ctkDICOMSeriesItemWidget);
if (!d->DicomDatabase)
Expand All @@ -871,10 +877,11 @@ void ctkDICOMSeriesItemWidget::generateInstances(bool queryRetrieve)
return;
}

ctkDICOMJobDetail td;
d->createThumbnail(td, queryRetrieve);
d->QueryOn = query;
d->RetrieveOn = retrieve;

QStringList instancesList = d->DicomDatabase->instancesForSeries(d->SeriesInstanceUID);
if (queryRetrieve && !d->StopJobs &&
if (query && !d->StopJobs &&
instancesList.count() == 0 &&
d->Scheduler &&
d->Scheduler->queryRetrieveServersCount() > 0)
Expand All @@ -885,6 +892,11 @@ void ctkDICOMSeriesItemWidget::generateInstances(bool queryRetrieve)
d->RaiseJobsPriority ? QThread::HighestPriority : QThread::NormalPriority,
d->AllowedServers);
}
else
{
ctkDICOMJobDetail td;
d->createThumbnail(td);
}
}

//----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Libs/DICOM/Widgets/ctkDICOMSeriesItemWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class CTK_DICOM_WIDGETS_EXPORT ctkDICOMSeriesItemWidget : public QWidget
void setDicomDatabase(QSharedPointer<ctkDICOMDatabase> dicomDatabase);

public Q_SLOTS:
void generateInstances(bool queryRetrieve = true);
void generateInstances(bool query = true, bool retrieve = true);
void updateGUIFromScheduler(const QVariant& data);
void updateSeriesProgressBar(const QVariant& data);
void onJobStarted(const QVariant& data);
Expand Down
Loading

0 comments on commit 13d243c

Please sign in to comment.