diff --git a/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.cpp b/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.cpp index a651bc37c6..de49a92b0f 100644 --- a/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.cpp @@ -1,108 +1,79 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkUSAbstractCustomWidget.h" #include #include std::string QmitkUSAbstractCustomWidget::US_DEVICE_PROPKEY_CLASS() { static std::string s = "ork.mitk.services.UltrasoundCustomWidget.deviceClass"; return s; } QmitkUSAbstractCustomWidget::QmitkUSAbstractCustomWidget(QWidget* parent) : QWidget(parent), m_PrototypeServiceFactory(0), m_IsClonedForQt(false) { } QmitkUSAbstractCustomWidget::~QmitkUSAbstractCustomWidget() { delete m_PrototypeServiceFactory; } void QmitkUSAbstractCustomWidget::SetDevice(mitk::USDevice::Pointer device) { m_Device = device; if ( device ) { this->OnDeviceSet(); } } mitk::USDevice::Pointer QmitkUSAbstractCustomWidget::GetDevice() const { return m_Device; } QmitkUSAbstractCustomWidget* QmitkUSAbstractCustomWidget::CloneForQt(QWidget* parent) const { QmitkUSAbstractCustomWidget* clonedWidget = this->Clone(parent); + clonedWidget->Initialize(); // initialize the Qt stuff of the widget clonedWidget->m_IsClonedForQt = true; // set flag that this object was really cloned return clonedWidget; } -us::ServiceRegistration QmitkUSAbstractCustomWidget::RegisterService(us::ModuleContext* context) -{ - if (this->m_PrototypeServiceFactory) { return us::ServiceRegistration(); } - - // create an us::PrototypeServiceFactory which is user on any following call - // to QmitkUSAbstractCustomWidget::RegisterService(); this factory uses the - // clone method of the concrete subclass which should be created - struct PrototypeFactory : public us::PrototypeServiceFactory - { - QmitkUSAbstractCustomWidget* const m_Prototype; - - PrototypeFactory(QmitkUSAbstractCustomWidget* prototype) - : m_Prototype(prototype) {} - - us::InterfaceMap GetService(us::Module* /*module*/, const us::ServiceRegistrationBase& /*registration*/) - { - return us::MakeInterfaceMap(m_Prototype->Clone()); - } - - void UngetService(us::Module*, const us::ServiceRegistrationBase&, const us::InterfaceMap& service) - { - delete us::ExtractInterface(service); - } - }; - - m_PrototypeServiceFactory = new PrototypeFactory(this); - - return context->RegisterService(this->m_PrototypeServiceFactory, this->GetServiceProperties()); -} - us::ServiceProperties QmitkUSAbstractCustomWidget::GetServiceProperties() const { us::ServiceProperties result; result[QmitkUSAbstractCustomWidget::US_DEVICE_PROPKEY_CLASS()] = this->GetDeviceClass(); return result; } void QmitkUSAbstractCustomWidget::showEvent ( QShowEvent * event ) { // using object from micro service directly in Qt without cloning it first // can cause problems when Qt deletes this object -> throw an exception to // show that object should be cloned before if ( ! m_IsClonedForQt ) { MITK_ERROR << "Object wasn't cloned with CloneForQt() before using as QWidget."; mitkThrow() << "Object wasn't cloned with CloneForQt() before using as QWidget."; } QWidget::showEvent(event); -} +} \ No newline at end of file diff --git a/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.h b/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.h index d98a464d54..b11a549f19 100644 --- a/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.h @@ -1,155 +1,157 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QmitkUSAbstractCustomWidget_h #define QmitkUSAbstractCustomWidget_h #include #include #include "mitkUSDevice.h" // Microservices #include #include #include #include namespace us { - class PrototypeServiceFactory; + struct PrototypeServiceFactory; class ModuleContext; } /** * \brief Abstract superclass for all custom control widgets of mitk::USDevice classes. * * The custom control widgets are made available using a us::PrototypeServiceFactory. This means that each * concrete subclass should be registered in the microservice by calling * QmitkUSAbstractCustomWidget::RegisterService() on an object. The best place for doing this would be in * the corresponding module or plugin activator. * * Afterwards a copy of the registered object can be obtained from the microservice as shown in the example * below. Do not forget to call QmitkUSAbstractCustomWidget::CloneForQt() on the object received from the * microservice. This is necessary to allow deleting the object as it is necessary in Qt for removing it from * a layout. * * * Subclasses must implement three methods: * - QmitkUSAbstractCustomWidget::OnDeviceSet() -> should handle initialization when mitk:USDevice was set * - QmitkUSAbstractCustomWidget::GetDeviceClass() -> must return device class of corresponding mitk::USDevice * - QmitkUSAbstractCustomWidget::Clone() -> must create a copy of the current object * * * The code to use a custom control widget in a plugin can look like this: * * \code * ctkPluginContext* pluginContext = // get the plugig context * mitk::USDevice device = // get the ultrasound device * * // get service references for ultrasound device * std::string filter = "(ork.mitk.services.UltrasoundCustomWidget.deviceClass=" + device->GetDeviceClass() + ")"; * QString interfaceName ( us_service_interface_iid() ); * QList serviceRefs = pluginContext->getServiceReferences(interfaceName, QString::fromStdString(filter)); * * if (serviceRefs.size() > 0) * { * // get widget from the service and make sure that it is cloned, so that * // it can be deleted if it should be removed from the GUI later * QmitkUSAbstractCustomWidget* widget = pluginContext->getService * (serviceRefs.at(0))->CloneForQt(parentWidget); * // now the widget can be used like any other QWidget * } * \endcode */ class MitkUSUI_EXPORT QmitkUSAbstractCustomWidget : public QWidget { Q_OBJECT public: QmitkUSAbstractCustomWidget(QWidget* parent = 0); virtual ~QmitkUSAbstractCustomWidget(); void SetDevice(mitk::USDevice::Pointer device); mitk::USDevice::Pointer GetDevice() const; /** * \brief Called every time a mitk::USDevice was set with QmitkUSAbstractCustomWidget::SetDevice(). * A sublcass can implement this function to handle initialiation actions * necessary when a device was set. */ virtual void OnDeviceSet() = 0; /** * \brief Subclass must implement this method to return device class of corresponding mitk::USDevice. * * \return same value as mitk::USDevice::GetDeviceClass() of the corresponding mitk::USDevice */ virtual std::string GetDeviceClass() const = 0; /** * \brief Subclass must implement this method to return a pointer to a copy of the object. */ virtual QmitkUSAbstractCustomWidget* Clone(QWidget* parent = 0) const = 0; + /** + * \brief Method for initializing the Qt stuff of the widget (setupUI, connect). + * This method will be called in CloneForQt() and has to be implemented by concrete + * subclasses. + * \warning All Qt initialization stuff belongs into this method rather than in the constructor. + */ + virtual void Initialize() = 0; + /** * \brief Return pointer to copy of the object. * Internally use of QmitkUSAbstractCustomWidget::Clone() with additionaly * setting an internal flag that the object was really cloned. */ QmitkUSAbstractCustomWidget* CloneForQt(QWidget* parent = 0) const; - /** - * \brief Register object as micro service. - * The object will be registered using an us::PrototypeServiceFactory. - */ - us::ServiceRegistration RegisterService(us::ModuleContext* context); - /** * \brief Returns the properties of the micro service. * Properties consist of just the device class of the corresponding * mitk::USDevice. */ us::ServiceProperties GetServiceProperties() const; /** * \brief Overwritten Qt even method. * It is checked if the object was cloned with * QmitkUSAbstractCustomWidget::CloneForQt() before. An exception is thrown * if not. This is done, because using the object from micro service directly * in Qt without cloning it first can cause problems after Qt deleted the * object. * * \throws mitk::Exception */ void showEvent ( QShowEvent * event ); /** * \brief Property key for the class name of corresponding us device object. */ static std::string US_DEVICE_PROPKEY_CLASS(); private: mitk::USDevice::Pointer m_Device; us::PrototypeServiceFactory* m_PrototypeServiceFactory; bool m_IsClonedForQt; }; // This is the microservice declaration. Do not meddle! US_DECLARE_SERVICE_INTERFACE(QmitkUSAbstractCustomWidget, "org.mitk.QmitkUSAbstractCustomWidget") #endif // QmitkUSAbstractCustomWidget_h diff --git a/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.cpp b/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.cpp index b29c41d763..18cbbb1913 100644 --- a/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.cpp @@ -1,121 +1,123 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkUSControlsCustomVideoDeviceWidget.h" #include "ui_QmitkUSControlsCustomVideoDeviceWidget.h" #include #include QmitkUSControlsCustomVideoDeviceWidget::QmitkUSControlsCustomVideoDeviceWidget(QWidget *parent) : QmitkUSAbstractCustomWidget(parent), ui(new Ui::QmitkUSControlsCustomVideoDeviceWidget) { - ui->setupUi(this); - - connect( ui->crop_left, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()) ); - connect( ui->crop_right, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()) ); - connect( ui->crop_top, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()) ); - connect( ui->crop_bot, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()) ); - m_Cropping.left = 0; m_Cropping.top = 0; m_Cropping.right = 0; m_Cropping.bottom = 0; - } QmitkUSControlsCustomVideoDeviceWidget::~QmitkUSControlsCustomVideoDeviceWidget() { delete ui; } std::string QmitkUSControlsCustomVideoDeviceWidget::GetDeviceClass() const { return mitk::USVideoDevice::GetDeviceClassStatic(); } QmitkUSAbstractCustomWidget* QmitkUSControlsCustomVideoDeviceWidget::Clone(QWidget* parent) const { QmitkUSAbstractCustomWidget* clonedWidget = new QmitkUSControlsCustomVideoDeviceWidget(parent); clonedWidget->SetDevice(this->GetDevice()); return clonedWidget; } void QmitkUSControlsCustomVideoDeviceWidget::OnDeviceSet() { m_ControlInterface = dynamic_cast (this->GetDevice()->GetControlInterfaceCustom().GetPointer()); if ( m_ControlInterface.IsNotNull() ) { mitk::USImageVideoSource::USImageCropping cropping = m_ControlInterface->GetCropArea(); ui->crop_left->setValue(cropping.left); ui->crop_right->setValue(cropping.right); ui->crop_bot->setValue(cropping.bottom); ui->crop_top->setValue(cropping.top); } else { MITK_WARN("QmitkUSAbstractCustomWidget")("QmitkUSControlsCustomVideoDeviceWidget") << "Did not get a custom video device control interface."; } ui->crop_left->setEnabled(m_ControlInterface.IsNotNull()); ui->crop_right->setEnabled(m_ControlInterface.IsNotNull()); ui->crop_bot->setEnabled(m_ControlInterface.IsNotNull()); ui->crop_top->setEnabled(m_ControlInterface.IsNotNull()); } +void QmitkUSControlsCustomVideoDeviceWidget::Initialize() +{ + ui->setupUi(this); + + connect( ui->crop_left, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()) ); + connect( ui->crop_right, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()) ); + connect( ui->crop_top, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()) ); + connect( ui->crop_bot, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()) ); +} + void QmitkUSControlsCustomVideoDeviceWidget::OnCropAreaChanged() { if ( m_ControlInterface.IsNull() ) { return; } mitk::USImageVideoSource::USImageCropping cropping; cropping.left = ui->crop_left->value(); cropping.top = ui->crop_top->value(); cropping.right = ui->crop_right->value(); cropping.bottom = ui->crop_bot->value(); try { m_ControlInterface->SetCropArea(cropping); m_Cropping = cropping; } catch (mitk::Exception e) { m_ControlInterface->SetCropArea(m_Cropping); // reset to last valid crop //reset values BlockSignalAndSetValue(ui->crop_left, m_Cropping.left); BlockSignalAndSetValue(ui->crop_right, m_Cropping.right); BlockSignalAndSetValue(ui->crop_top, m_Cropping.top); BlockSignalAndSetValue(ui->crop_bot, m_Cropping.bottom); // inform user QMessageBox msgBox; msgBox.setInformativeText("The crop area you specified is invalid.\nPlease make sure that no more pixels are cropped than are available."); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); MITK_WARN << "User tried to crop beyond limits of the image"; } } void QmitkUSControlsCustomVideoDeviceWidget::BlockSignalAndSetValue(QSpinBox* target, int value) { bool oldState = target->blockSignals(true); target->setValue(value); target->blockSignals(oldState); -} +} \ No newline at end of file diff --git a/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.h b/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.h index 27bfd20bf5..66fcca5357 100644 --- a/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.h @@ -1,87 +1,89 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QmitkUSControlsCustomVideoDeviceWidget_H #define QmitkUSControlsCustomVideoDeviceWidget_H #include "QmitkUSAbstractCustomWidget.h" #include "mitkUSVideoDeviceCustomControls.h" #include "mitkUSVideoDevice.h" #include namespace Ui { class QmitkUSControlsCustomVideoDeviceWidget; } /** \brief Widget for custom controls of mitk::USVideoDevice. * This class handles the itk::USVideoDeviceCustomControls of video device * objects. */ class QmitkUSControlsCustomVideoDeviceWidget : public QmitkUSAbstractCustomWidget { Q_OBJECT private slots: /** * \brief Called when user changes one of the crop area control elements. */ void OnCropAreaChanged(); public: /** * Constructs widget object. All gui control elements will be disabled until * QmitkUSAbstractCustomWidget::SetDevice() was called. */ explicit QmitkUSControlsCustomVideoDeviceWidget(QWidget *parent = 0); ~QmitkUSControlsCustomVideoDeviceWidget(); /** * Getter for the device class of mitk:USVideoDevice. */ virtual std::string GetDeviceClass() const; /** * Creates new QmitkUSAbstractCustomWidget with the same mitk::USVideoDevice * and the same mitk::USVideoDeviceCustomControls which were set on the * original object. * * This method is just for being calles by the factory. Use * QmitkUSAbstractCustomWidget::CloneForQt() instead, if you want a clone of * an object. */ virtual QmitkUSAbstractCustomWidget* Clone(QWidget* parent = 0) const; /** * Gets control interface from the device which was currently set. Control * elements are according to current crop area of the device. If custom * control interface is null, the control elements stay disabled. */ virtual void OnDeviceSet(); + virtual void Initialize(); + protected: void BlockSignalAndSetValue(QSpinBox* target, int value); mitk::USImageVideoSource::USImageCropping m_Cropping; private: Ui::QmitkUSControlsCustomVideoDeviceWidget* ui; mitk::USVideoDeviceCustomControls::Pointer m_ControlInterface; }; #endif // QmitkUSControlsCustomVideoDeviceWidget_H \ No newline at end of file diff --git a/Modules/USUI/files.cmake b/Modules/USUI/files.cmake index 3935575c6d..d88a79270d 100644 --- a/Modules/USUI/files.cmake +++ b/Modules/USUI/files.cmake @@ -1,35 +1,36 @@ set(CPP_FILES mitkUSUIActivator.cpp + mitkUSUICustomWidgetFactory.cpp Qmitk/QmitkUSDeviceManagerWidget.cpp Qmitk/QmitkUSNewVideoDeviceWidget.cpp Qmitk/QmitkUSControlsBModeWidget.cpp Qmitk/QmitkUSControlsDopplerWidget.cpp Qmitk/QmitkUSControlsProbesWidget.cpp Qmitk/QmitkUSControlsCustomVideoDeviceWidget.cpp Qmitk/QmitkUSAbstractCustomWidget.cpp Qmitk/QmitkComboBoxStepThrough.cpp ) set(UI_FILES Qmitk/QmitkUSDeviceManagerWidgetControls.ui Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui Qmitk/QmitkUSControlsBModeWidget.ui Qmitk/QmitkUSControlsDopplerWidget.ui Qmitk/QmitkUSControlsProbesWidget.ui Qmitk/QmitkUSControlsCustomVideoDeviceWidget.ui ) set(MOC_H_FILES Qmitk/QmitkUSDeviceManagerWidget.h Qmitk/QmitkUSNewVideoDeviceWidget.h Qmitk/QmitkUSControlsBModeWidget.h Qmitk/QmitkUSControlsDopplerWidget.h Qmitk/QmitkUSControlsProbesWidget.h Qmitk/QmitkUSControlsCustomVideoDeviceWidget.h Qmitk/QmitkUSAbstractCustomWidget.h Qmitk/QmitkComboBoxStepThrough.h ) set(QRC_FILES resources/USUI.qrc ) diff --git a/Modules/USUI/mitkUSUIActivator.cpp b/Modules/USUI/mitkUSUIActivator.cpp index 1a3bd67228..b24668ccc0 100644 --- a/Modules/USUI/mitkUSUIActivator.cpp +++ b/Modules/USUI/mitkUSUIActivator.cpp @@ -1,38 +1,64 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkUSUIActivator.h" +#include "mitkUSUICustomWidgetFactory.h" +#include "QmitkUSControlsCustomVideoDeviceWidget.h" mitk::USUIActivator::USUIActivator() + : m_CustomWidgetFactory(0), m_CustomVideoDeviceWidget(0) { - } mitk::USUIActivator::~USUIActivator() { + delete m_CustomWidgetFactory; + delete m_CustomVideoDeviceWidget; + if ( m_ServiceRegistration ) { m_ServiceRegistration.Unregister(); } } void mitk::USUIActivator::Load(us::ModuleContext* context) { - m_ServiceRegistration = m_CustomVideoDeviceWidget.RegisterService(context); + // create a custom video device widget, which will be used as + // a prototype for the custom widget factory + if ( ! m_CustomVideoDeviceWidget ) + { + m_CustomVideoDeviceWidget = new QmitkUSControlsCustomVideoDeviceWidget(); + } + + // create a factory for custom widgets, using the video device + // widget as a prototype + if ( ! m_CustomWidgetFactory ) + { + m_CustomWidgetFactory = new mitk::USUICustomWidgetFactory(m_CustomVideoDeviceWidget); + } + + // register the custom widget factory as a microservice + m_ServiceRegistration = m_CustomWidgetFactory->RegisterService(context); } void mitk::USUIActivator::Unload(us::ModuleContext* /*context*/) { m_ServiceRegistration.Unregister(); m_ServiceRegistration = 0; -} + + delete m_CustomWidgetFactory; + m_CustomWidgetFactory = 0; + + delete m_CustomVideoDeviceWidget; + m_CustomVideoDeviceWidget = 0; +} \ No newline at end of file diff --git a/Modules/USUI/mitkUSUIActivator.h b/Modules/USUI/mitkUSUIActivator.h index 474a0f2fdb..fdafa04987 100644 --- a/Modules/USUI/mitkUSUIActivator.h +++ b/Modules/USUI/mitkUSUIActivator.h @@ -1,60 +1,65 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef __mitkUSUIActivator_h #define __mitkUSUIActivator_h -#include "QmitkUSControlsCustomVideoDeviceWidget.h" +#include "QmitkUSAbstractCustomWidget.h" // Microservices #include #include +class QmitkUSControlsCustomVideoDeviceWidget; + namespace mitk { + class USUICustomWidgetFactory; + /** * \brief Module activator for the USUI module. * Registers custom widget for mitk::USVideoDevice as microservice. */ class USUIActivator : public us::ModuleActivator { public: USUIActivator(); virtual ~USUIActivator(); /** * Custom video device widget is registered as a micro service on module * load. A plugin can get this widget then when using a * mitk::USVideoDevice. */ void Load(us::ModuleContext* context); /** * Custom video device widget is deregistered from micro service on module * unload. */ void Unload(us::ModuleContext* context); protected: us::ServiceRegistration m_ServiceRegistration; - QmitkUSControlsCustomVideoDeviceWidget m_CustomVideoDeviceWidget; + USUICustomWidgetFactory* m_CustomWidgetFactory; + QmitkUSControlsCustomVideoDeviceWidget* m_CustomVideoDeviceWidget; }; } // namespace mitk US_EXPORT_MODULE_ACTIVATOR(MitkUSUI, mitk::USUIActivator) -#endif // __mitkUSUIActivator_h +#endif // __mitkUSUIActivator_h \ No newline at end of file diff --git a/Modules/USUI/mitkUSUICustomWidgetFactory.cpp b/Modules/USUI/mitkUSUICustomWidgetFactory.cpp new file mode 100644 index 0000000000..41435a6965 --- /dev/null +++ b/Modules/USUI/mitkUSUICustomWidgetFactory.cpp @@ -0,0 +1,43 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkUSUICustomWidgetFactory.h" + +#include "QmitkUSAbstractCustomWidget.h" + +#include + +mitk::USUICustomWidgetFactory::USUICustomWidgetFactory(QmitkUSAbstractCustomWidget* prototype) + : m_Prototype(prototype) +{ +} + +us::ServiceRegistration mitk::USUICustomWidgetFactory::RegisterService(us::ModuleContext* context) +{ + return context->RegisterService(m_Prototype, m_Prototype->GetServiceProperties()); +} + +us::InterfaceMap mitk::USUICustomWidgetFactory::GetService(us::Module* /*module*/, const us::ServiceRegistrationBase& /*registration*/) +{ + // clone the prototype for returning a uniqe instance + return us::MakeInterfaceMap(m_Prototype->Clone()); +} + +void mitk::USUICustomWidgetFactory::UngetService(us::Module*, const us::ServiceRegistrationBase&, const us::InterfaceMap& service) +{ + // just delete the given service + delete us::ExtractInterface(service); +} \ No newline at end of file diff --git a/Modules/USUI/mitkUSUICustomWidgetFactory.h b/Modules/USUI/mitkUSUICustomWidgetFactory.h new file mode 100644 index 0000000000..d5e743f2ec --- /dev/null +++ b/Modules/USUI/mitkUSUICustomWidgetFactory.h @@ -0,0 +1,49 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef MITKUSUICUSTOMWIDGETFACTORY_H +#define MITKUSUICUSTOMWIDGETFACTORY_H + +#include + +class QmitkUSAbstractCustomWidget; + +namespace us { +class ModuleContext; +} + +namespace mitk { +/** + * \brief Prototype service factory for creating unique instances of QmitUSAbstractCustomWidget. + */ +class USUICustomWidgetFactory : public us::PrototypeServiceFactory { +public: + USUICustomWidgetFactory(QmitkUSAbstractCustomWidget* prototype); + + /** + * \brief Registers this factory in the given module context. + */ + us::ServiceRegistration RegisterService(us::ModuleContext* context); + + us::InterfaceMap GetService(us::Module* /*module*/, const us::ServiceRegistrationBase& /*registration*/); + void UngetService(us::Module*, const us::ServiceRegistrationBase&, const us::InterfaceMap& service); + +private: + QmitkUSAbstractCustomWidget* const m_Prototype; +}; +} // namespace mitk + +#endif // MITKUSUICUSTOMWIDGETFACTORY_H \ No newline at end of file