diff --git a/Modules/Qmitk/QmitkServiceListWidget.H b/Modules/Qmitk/QmitkServiceListWidget.H new file mode 100644 index 0000000000..6d8f6bd527 --- /dev/null +++ b/Modules/Qmitk/QmitkServiceListWidget.H @@ -0,0 +1,159 @@ +/*=================================================================== + +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 _QmitkServiceListWidget_H_INCLUDED +#define _QmitkServiceListWidget_H_INCLUDED + +#include "QmitkExports.h" +#include "ui_QmitkServiceListWidgetControls.h" +#include + +//QT headers +#include +#include + +//Microservices +#include "usServiceReference.h" +#include "usModuleContext.h" +#include "usServiceEvent.h" + +/** +* @brief TODO +* +* @ingroup QMITK +*/ +class QMITK_EXPORT QmitkServiceListWidget :public QWidget +{ + + //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) + Q_OBJECT + + public: + + static const std::string VIEW_ID; + + QmitkServiceListWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); + virtual ~QmitkServiceListWidget(); + + /* @brief This method is part of the widget an needs not to be called seperately. */ + virtual void CreateQtPartControl(QWidget *parent); + /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ + virtual void CreateConnections(); + + /* + * \brief Initializes the connection to the registry. The string filter is an LDAP parsable String, compare mitk::ModuleContext for examples on filtering. + */ + void Initialize(mitk::ModuleContext* context, std::string interfaceName, std::string filter); + + /* + * \brief TODO + */ + template + T GetSelectedService(); + + /* + * \brief TODO + */ + mitk::ServiceReference* GetSelectedService(); + + + + /* + *\brief This Function listens to ServiceRegistry changes and updates the + * list of devices accordingly. The User of this Widget does not need to use this method, + * it is instead used to recieve events from the module registry. + */ + void OnServiceEvent(const mitk::ServiceEvent event); + + + + signals: + + /* + *\brief Emitted when a new service mathing the filter connects. + */ + void ServiceConnected(mitk::ServiceReference*); + + /* + *\brief Emitted directly before a service matching the filter disconnects. + */ + void ServiceDisconnected(mitk::ServiceReference*); + + /* + *\brief Emitted when a service mathing the filter changes it's properties. + */ + void ServiceChanged(mitk::ServiceReference*); + + /* + *\brief Emitted the user selects a Service from the list + */ + void ServiceSelected(mitk::ServiceReference*); + + public slots: + + protected slots: + + /* + \brief Called, when the selection in the servicelist changes + */ + void OnServiceSelectionChanged(); + + + protected: + + Ui::QmitkServiceListWidgetControls* m_Controls; ///< member holding the UI elements of this widget + + /* + * \brief Internal Structure used to link services to their QListWidgetItems + */ + struct ServiceListLink { + mitk::ServiceReference* service; + QListWidgetItem* item; + }; + + /* + * \brief Contains a list of currently active servicesand their entires in the list. This is wiped with every ServiceRegistryEvent. + */ + std::vector m_ListContent; + + /* + * \brief Constructs a ListItem from the given service for display in the list of services. + */ + QListWidgetItem* ConstructItemFromService(mitk::ServiceReference* serviceRef); + + /* + * \brief Returns the serviceReference corresponding to the given ListEntry or null if none was found (which really shouldn't happen). + */ + mitk::ServiceReference* GetServiceForListItem(QListWidgetItem* item); + + /* + * \brief Returns a list of ServiceReferences matching the filter criteria by querying the service registry. + */ + std::list GetAllRegisteredServices(); + + + + + private: + + mitk::ModuleContext* m_Context; + /** \brief a filter to further narrow down the list of results **/ + std::string m_Filter; + /** \brief The name of the ServiceInterface that this class should list **/ + std::string m_Interface; +}; + +#endif // _QmitkServiceListWidget_H_INCLUDED diff --git a/Modules/Qmitk/QmitkServiceListWidget.cpp b/Modules/Qmitk/QmitkServiceListWidget.cpp new file mode 100644 index 0000000000..ed691d123a --- /dev/null +++ b/Modules/Qmitk/QmitkServiceListWidget.cpp @@ -0,0 +1,146 @@ +/*=================================================================== + +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. + +===================================================================*/ + +//#define _USE_MATH_DEFINES +#include + +// STL HEaders +#include + +//QT headers +#include + +//microservices +#include +#include "mitkModuleContext.h" +#include + + +const std::string QmitkServiceListWidget::VIEW_ID = "org.mitk.views.QmitkServiceListWidget"; + +QmitkServiceListWidget::QmitkServiceListWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) +{ + m_Controls = NULL; + CreateQtPartControl(this); +} + +QmitkServiceListWidget::~QmitkServiceListWidget() +{ + +} + + +//////////////////// INITIALIZATION ///////////////////// + +void QmitkServiceListWidget::CreateQtPartControl(QWidget *parent) +{ + if (!m_Controls) + { + // create GUI widgets + m_Controls = new Ui::QmitkServiceListWidgetControls; + m_Controls->setupUi(parent); + this->CreateConnections(); + } +} + +void QmitkServiceListWidget::CreateConnections() +{ + if ( m_Controls ) + { + connect( m_Controls->m_ServiceList, SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem *)), this, SLOT(OnDeviceSelectionChanged()) ); + } +} + +void QmitkServiceListWidget::Initialize(mitk::ModuleContext* context, std::string interfaceName, std::string filter) +{ + m_Context = context; + m_Filter = filter; + m_Interface = interfaceName; + m_Context->AddServiceListener(this, &QmitkServiceListWidget::OnServiceEvent, m_Filter); +} + + +///////////////////////// Getter & Setter ///////////////////////////////// + +template +T QmitkServiceListWidget::GetSelectedService() +{ + return this->GetDeviceForListItem(this->m_Controls->m_ServiceList->currentItem()); +} + +///////////// Methods & Slots Handling Direct Interaction ///////////////// + + +void QmitkServiceListWidget::OnServiceSelectionChanged(){ + mitk::ServiceReference* ref = this->GetServiceForListItem(this->m_Controls->m_ServiceList->currentItem()); + if (ref == 0) return; + + emit (ServiceSelected(ref)); +} + + +///////////////// Methods & Slots Handling Logic ////////////////////////// + +void QmitkServiceListWidget::OnServiceEvent(const mitk::ServiceEvent event){ + // Empty ListWidget + this->m_ListContent.clear(); + m_Controls->m_ServiceList->clear(); + + // get Services + std::list services = this->GetAllRegisteredServices(); + // Transfer them to the List + for(std::list::iterator it = services.begin(); it != services.end(); ++it) + { + QListWidgetItem *newItem = ConstructItemFromService(& *it); + //Add new item to QListWidget + m_Controls->m_ServiceList->addItem(newItem); + // Construct link and add to internal List for reference + QmitkServiceListWidget::ServiceListLink link; + link.service = &*it; + link.item = newItem; + m_ListContent.push_back(link); + } +} + + +/////////////////////// HOUSEHOLDING CODE ///////////////////////////////// + +QListWidgetItem* QmitkServiceListWidget::ConstructItemFromService(mitk::ServiceReference* serviceRef){ + QListWidgetItem *result = new QListWidgetItem; + + //TODO allow formatting + std::string text = "ThisIsAService"; + + result->setText(text.c_str()); + + return result; +} + + +mitk::ServiceReference* QmitkServiceListWidget::GetServiceForListItem(QListWidgetItem* item) +{ + for(std::vector::iterator it = m_ListContent.begin(); it != m_ListContent.end(); ++it) + { + if (item == it->item) return it->service; + } + return 0; +} + + +std::list QmitkServiceListWidget::GetAllRegisteredServices(){ + //Get Service References + return m_Context->GetServiceReferences(m_Interface, m_Filter); +} diff --git a/Modules/Qmitk/QmitkServiceListWidgetControls.ui b/Modules/Qmitk/QmitkServiceListWidgetControls.ui new file mode 100644 index 0000000000..b47307b6bc --- /dev/null +++ b/Modules/Qmitk/QmitkServiceListWidgetControls.ui @@ -0,0 +1,31 @@ + + + QmitkServiceListWidgetControls + + + + 0 + 0 + 323 + 231 + + + + + 0 + 0 + + + + QmitkServiceListWidget + + + + + + + + + + + diff --git a/Modules/Qmitk/files.cmake b/Modules/Qmitk/files.cmake index e43d76ed01..2060c284b0 100644 --- a/Modules/Qmitk/files.cmake +++ b/Modules/Qmitk/files.cmake @@ -1,63 +1,66 @@ set(CPP_FILES QmitkApplicationCursor.cpp QmitkEnums.h QmitkCustomVariants.h QmitkDataStorageComboBox.cpp QmitkDataStorageListModel.cpp QmitkDataStorageTableModel.cpp QmitkDataStorageTreeModel.cpp QmitkEventAdapter.cpp QmitkLevelWindowPresetDefinitionDialog.cpp QmitkLevelWindowRangeChangeDialog.cpp QmitkLevelWindowWidgetContextMenu.cpp QmitkLevelWindowWidget.cpp QmitkLineEditLevelWindowWidget.cpp QmitkMemoryUsageIndicatorView.cpp QmitkNodeDescriptor.cpp QmitkNodeDescriptorManager.cpp QmitkRenderWindowMenu.cpp QmitkProgressBar.cpp QmitkPropertiesTableEditor.cpp QmitkPropertiesTableModel.cpp QmitkPropertyDelegate.cpp QmitkRegisterClasses.cpp QmitkRenderingManager.cpp QmitkRenderingManagerFactory.cpp QmitkRenderWindow.cpp +QmitkServiceListWidget.cpp QmitkSliderLevelWindowWidget.cpp QmitkStdMultiWidget.cpp QmitkMouseModeSwitcher.cpp ) set(MOC_H_FILES QmitkDataStorageComboBox.h QmitkDataStorageTableModel.h QmitkLevelWindowPresetDefinitionDialog.h QmitkLevelWindowRangeChangeDialog.h QmitkLevelWindowWidgetContextMenu.h QmitkLevelWindowWidget.h QmitkLineEditLevelWindowWidget.h QmitkMemoryUsageIndicatorView.h QmitkNodeDescriptor.h QmitkNodeDescriptorManager.h QmitkRenderWindowMenu.h QmitkProgressBar.h QmitkPropertiesTableEditor.h QmitkPropertyDelegate.h QmitkRenderingManager.h QmitkRenderWindow.h +QmitkServiceListWidget.h QmitkSliderLevelWindowWidget.h QmitkStdMultiWidget.h QmitkMouseModeSwitcher.h ) set(UI_FILES QmitkLevelWindowPresetDefinition.ui QmitkLevelWindowWidget.ui QmitkLevelWindowRangeChange.ui QmitkMemoryUsageIndicator.ui +QmitkServiceListWidgetControls.ui ) set(QRC_FILES Qmitk.qrc ) diff --git a/Modules/USUI/CMakeLists.txt b/Modules/USUI/CMakeLists.txt index c0ac18187a..10c7fde455 100644 --- a/Modules/USUI/CMakeLists.txt +++ b/Modules/USUI/CMakeLists.txt @@ -1,8 +1,8 @@ MITK_CREATE_MODULE(MitkUSUI #SUBPROJECTS MITK-US INCLUDE_DIRS Qmitk - DEPENDS MitkUS Qmitk QmitkExt + DEPENDS Mitk MitkUS Qmitk QmitkExt QT_MODULE GENERATED_CPP ${TOOL_GUI_CPPS} ${TOOL_CPPS} ) diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h index 2e8f70d03c..96cdf84c2b 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h @@ -1,135 +1,135 @@ /*=================================================================== 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 _QmitkUSDeviceManagerWidget_H_INCLUDED #define _QmitkUSDeviceManagerWidget_H_INCLUDED #include "MitkUSUIExports.h" #include "ui_QmitkUSDeviceManagerWidgetControls.h" #include "mitkUSDevice.h" #include //QT headers #include #include //mitk header //Microservices #include "usServiceReference.h" #include "usModuleContext.h" #include "usServiceEvent.h" /** -* @brief TODO +* @brief This Widget is used to manage available Ultrasound Devices. * * @ingroup USUI */ class MitkUSUI_EXPORT QmitkUSDeviceManagerWidget :public QWidget //, public mitk::ServiceTrackerCustomizer<> // this extension is necessary if one wants to use ServiceTracking instead of filtering { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; QmitkUSDeviceManagerWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkUSDeviceManagerWidget(); /* @brief This method is part of the widget an needs not to be called seperately. */ virtual void CreateQtPartControl(QWidget *parent); /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); /* *\brief This Function listens to ServiceRegistry changes and updates the * list of devices accordingly. */ void OnServiceEvent(const mitk::ServiceEvent event); signals: /* \brief Sent, when the user clicks "Activate Device" */ void USDeviceActivated(); public slots: protected slots: /* \brief Called, when the button "Activate Device" was clicked */ void OnClickedActivateDevice(); /* \brief Called, when the button "Disconnect Device" was clicked */ void OnClickedDisconnectDevice(); /* \brief Called, when the selection in the devicelist changes */ void OnDeviceSelectionChanged(); protected: Ui::QmitkUSDeviceManagerWidgetControls* m_Controls; ///< member holding the UI elements of this widget /* * \brief Internal Structure used to link devices to their QListWidget Items */ struct DeviceListLink { mitk::USDevice::Pointer device; QListWidgetItem* item; }; /* * \brief Contains a list of currently active devices and their entires in the list. This is wiped with every ServiceRegistryEvent. */ std::vector m_ListContent; /* * \brief Constructs a ListItem from the given device for display in the list of active devices. */ QListWidgetItem* ConstructItemFromDevice(mitk::USDevice::Pointer device); /* * \brief Returns the device corresponding to the given ListEntry or null if none was found (which really shouldnt happen). */ mitk::USDevice::Pointer GetDeviceForListItem(QListWidgetItem* item); //mitk::ServiceTracker ConstructServiceTracker(); /* * \brief Returns a List of US Devices that are currently connected by querying the service registry. */ std::vector GetAllRegisteredDevices(); private: mitk::ModuleContext* m_MitkUSContext; }; #endif // _QmitkUSDeviceManagerWidget_H_INCLUDED