diff --git a/Modules/QtWidgets/include/QmitkStepperAdapter.h b/Modules/QtWidgets/include/QmitkStepperAdapter.h index cc71c92e43..aec3ab6201 100644 --- a/Modules/QtWidgets/include/QmitkStepperAdapter.h +++ b/Modules/QtWidgets/include/QmitkStepperAdapter.h @@ -1,75 +1,55 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef QMITKSTEPPERADAPTER_H_HEADER_INCLUDED_C1E77191 #define QMITKSTEPPERADAPTER_H_HEADER_INCLUDED_C1E77191 -#include "itkCommand.h" -#include "itkObject.h" +#include "MitkQtWidgetsExports.h" #include "mitkStepper.h" #include "qobject.h" -#include "MitkQtWidgetsExports.h" + //##Documentation //## @brief Helper class to connect Qt-based navigators to instances of Stepper //## -//## The constructor has to be provided with the \a Navigator -//## that wants to use the \a Stepper. The \a Navigator has to define the +//## The constructor has to be provided with the navigation widget +//## that wants to use the Stepper. The navigation widget has to define the //## slots \a Refetch() and \a SetStepper(mitk::Stepper *). \a SetStepper will be -//## called only once to pass the \a Stepper to the \a Navigator. When the values of -//## the \a Stepper changes, \a Refetch() will be called. The \a Navigator can than +//## called only once to pass the Stepper to the navigation widget. When the values of +//## the Stepper changes, \a Refetch() will be called. The navigation widget can then //## ask the \a Stepper for its new values. -//## \warning The \a Navigator has to be aware that it might have caused the changes +//## \warning The navigation widget has to be aware that it might have caused the changes //## of the \a Stepper itself. So take care that no infinite recursion is created! class MITKQTWIDGETS_EXPORT QmitkStepperAdapter : public QObject { Q_OBJECT public: - QmitkStepperAdapter(QObject* navigator, mitk::Stepper* stepper); + QmitkStepperAdapter(QObject* navigationWidget, mitk::Stepper* stepper); ~QmitkStepperAdapter() override; - void SetStepper(mitk::Stepper *stepper) - { - this->SendStepper(stepper); - this->Refetch(); - } - - class ItkEventListener : public itk::Command - { - public: - mitkClassMacroItkParent(ItkEventListener, itk::Command); - ItkEventListener(QmitkStepperAdapter *receiver) - : m_Receiver(receiver){ - - }; - void Execute(itk::Object *, const itk::EventObject &) override { emit m_Receiver->Refetch(); }; - void Execute(const itk::Object *, const itk::EventObject &) override { emit m_Receiver->Refetch(); }; - protected: - QmitkStepperAdapter *m_Receiver; - }; + void SetStepper(mitk::Stepper* stepper); signals: - void signal_dummy(); + void Refetch(); void SendStepper(mitk::Stepper *); protected: + mitk::Stepper::Pointer m_Stepper; long m_ObserverTag; - friend class QmitkStepperAdapter::ItkEventListener; - ItkEventListener::Pointer m_ItkEventListener; }; #endif diff --git a/Modules/QtWidgets/src/QmitkStepperAdapter.cpp b/Modules/QtWidgets/src/QmitkStepperAdapter.cpp index 7339ab3bd8..15531579a6 100644 --- a/Modules/QtWidgets/src/QmitkStepperAdapter.cpp +++ b/Modules/QtWidgets/src/QmitkStepperAdapter.cpp @@ -1,33 +1,41 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkStepperAdapter.h" -QmitkStepperAdapter::QmitkStepperAdapter(QObject* navigator, mitk::Stepper* stepper) - : QObject(navigator) +#include + +QmitkStepperAdapter::QmitkStepperAdapter(QObject* navigationWidget, mitk::Stepper* stepper) + : QObject(navigationWidget) , m_Stepper(stepper) { - connect(this, SIGNAL(SendStepper(mitk::Stepper *)), navigator, SLOT(SetStepper(mitk::Stepper *))); - connect(this, SIGNAL(Refetch()), navigator, SLOT(Refetch())); + connect(this, SIGNAL(SendStepper(mitk::Stepper*)), navigationWidget, SLOT(SetStepper(mitk::Stepper*))); + connect(this, SIGNAL(Refetch()), navigationWidget, SLOT(Refetch())); emit SendStepper(stepper); - m_ItkEventListener = new ItkEventListener(this); - m_ObserverTag = m_Stepper->AddObserver(itk::ModifiedEvent(), m_ItkEventListener); + auto modifiedCommand = itk::SimpleMemberCommand::New(); + modifiedCommand->SetCallbackFunction(this, &QmitkStepperAdapter::Refetch); + m_ObserverTag = m_Stepper->AddObserver(itk::ModifiedEvent(), modifiedCommand); emit Refetch(); } QmitkStepperAdapter::~QmitkStepperAdapter() { - m_ItkEventListener->Delete(); m_Stepper->RemoveObserver(m_ObserverTag); } + +void QmitkStepperAdapter::SetStepper(mitk::Stepper* stepper) +{ + this->SendStepper(stepper); + this->Refetch(); +}