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 Python compatibility to query and retrieve widget #1064

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 20 additions & 6 deletions Libs/DICOM/Widgets/ctkDICOMQueryRetrieveWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ctkDICOMQueryRetrieveWidgetPrivate: public Ui_ctkDICOMQueryRetrieveWidget

protected:
ctkDICOMQueryRetrieveWidget* const q_ptr;

public:
ctkDICOMQueryRetrieveWidgetPrivate(ctkDICOMQueryRetrieveWidget& obj);
~ctkDICOMQueryRetrieveWidgetPrivate();
Expand All @@ -68,7 +68,7 @@ class ctkDICOMQueryRetrieveWidgetPrivate: public Ui_ctkDICOMQueryRetrieveWidget
QSharedPointer<ctkDICOMDatabase> RetrieveDatabase;
ctkDICOMModel Model;
ctkDICOMQuery *CurrentQuery;

QProgressDialog* ProgressDialog;
QString CurrentServer;
bool UseProgressDialog;
Expand Down Expand Up @@ -117,7 +117,7 @@ void ctkDICOMQueryRetrieveWidgetPrivate::init()

//----------------------------------------------------------------------------
ctkDICOMQueryRetrieveWidget::ctkDICOMQueryRetrieveWidget(QWidget* parentWidget)
: Superclass(parentWidget)
: Superclass(parentWidget)
, d_ptr(new ctkDICOMQueryRetrieveWidgetPrivate(*this))
{
Q_D(ctkDICOMQueryRetrieveWidget);
Expand All @@ -137,13 +137,27 @@ void ctkDICOMQueryRetrieveWidget::setRetrieveDatabase(QSharedPointer<ctkDICOMDat
d->RetrieveDatabase = dicomDatabase;
}

//----------------------------------------------------------------------------
void ctkDICOMQueryRetrieveWidget::setRetrieveDatabase(ctkDICOMDatabase* dicomDatabase)
{
Q_D(ctkDICOMQueryRetrieveWidget);
if (dicomDatabase == nullptr)
{
logger.error("Failed to set retrieve database - nullptr given");
return;
}

d->RetrieveDatabase = QSharedPointer<ctkDICOMDatabase>(dicomDatabase);;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra ;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, ownership of the database is passed to this widget (the widget will delete the object when it is destroyed). This would be unexpected and have quite high chance of double-delete.

Maybe we could fix this by setting a custom deleter function that does not actually delete the object (does not do anything).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't consider this. What I'm not sure about is the reason to use a QSharedPointer in the first place. I thought about making it a simple pointer but it may break the API and didn't want to do that. Not sure what you think about this.

Copy link
Member

@lassoan lassoan Jan 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared pointer makes sense because the database ownership is complicated (it may be used without a widget or used by multiple widgets) and it is very important to cleanly delete it during application exit. Unfortunately, shared pointer support has not been implemented in PythonQt, so we need workarounds.

Search for skipDelete in this repository for how a dual mode use is inplemented in another class.

}

//----------------------------------------------------------------------------
QSharedPointer<ctkDICOMDatabase> ctkDICOMQueryRetrieveWidget::retrieveDatabase()const
{
Q_D(const ctkDICOMQueryRetrieveWidget);
return d->RetrieveDatabase;
}

//----------------------------------------------------------------------------
void ctkDICOMQueryRetrieveWidget::useProgressDialog(bool enable)
{
Q_D(ctkDICOMQueryRetrieveWidget);
Expand Down Expand Up @@ -270,11 +284,11 @@ void ctkDICOMQueryRetrieveWidget::query()
d->StudyAndSeriesInstanceUIDPairList.push_back(std::make_pair( StudyAndSeriesInstanceUIDPair.first, StudyAndSeriesInstanceUIDPair.second ));
}
}

if (!progress.wasCanceled())
{
d->Model.setDatabase(d->QueryResultDatabase.database());

d->dicomTableManager->setDICOMDatabase(&(d->QueryResultDatabase));
}
d->RetrieveButton->setEnabled(d->QueriesByStudyUID.keys().size() != 0);
Expand Down Expand Up @@ -392,7 +406,7 @@ void ctkDICOMQueryRetrieveWidget::retrieve()
logger.error ( "Retrieve failed" );
if(d->UseProgressDialog)
{
if ( QMessageBox::question ( this,
if ( QMessageBox::question ( this,
tr("Query Retrieve"), tr("Retrieve failed. Keep trying?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
{
Expand Down
8 changes: 5 additions & 3 deletions Libs/DICOM/Widgets/ctkDICOMQueryRetrieveWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "ctkDICOMWidgetsExport.h"

// Qt includes
// Qt includes
#include <QWidget>
#include <QItemSelection>
#include <QMap>
Expand All @@ -39,8 +39,9 @@ class ctkDICOMQueryRetrieveWidgetPrivate;
/// \ingroup DICOM_Widgets
class CTK_DICOM_WIDGETS_EXPORT ctkDICOMQueryRetrieveWidget : public QWidget
{
Q_OBJECT;
Q_OBJECT
Q_PROPERTY(ctkDICOMTableManager* dicomTableManager READ dicomTableManager)

public:
typedef QWidget Superclass;
explicit ctkDICOMQueryRetrieveWidget(QWidget* parent=0);
Expand All @@ -52,10 +53,11 @@ Q_PROPERTY(ctkDICOMTableManager* dicomTableManager READ dicomTableManager)
QSharedPointer<ctkDICOMDatabase> retrieveDatabase()const;

/// enable or disable ctk progress bars
void useProgressDialog(bool enable);
Q_INVOKABLE void useProgressDialog(bool enable);

public Q_SLOTS:
void setRetrieveDatabase(QSharedPointer<ctkDICOMDatabase> retrieveDatabase);
void setRetrieveDatabase(ctkDICOMDatabase* dicomDatabase);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to describe who owns the dicomDatabase object after this call.

void query();
void retrieve();
void cancel();
Expand Down