Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkServiceListWidget Class Reference

This widget provides abstraction for the handling of MicroServices. More...

#include <QmitkServiceListWidget.h>

Inheritance diagram for QmitkServiceListWidget:
Collaboration diagram for QmitkServiceListWidget:

Classes

struct  ServiceListLink
 Internal structure used to link ServiceReferences to their QListWidgetItems. More...
 

Signals

void ServiceRegistered (us::ServiceReferenceU)
 Emitted when a new Service matching the filter is being registered. More...
 
void ServiceUnregistering (us::ServiceReferenceU)
 Emitted directly before a Service matching the filter is being unregistered. More...
 
void ServiceModified (us::ServiceReferenceU)
 Emitted when a Service matching the filter changes it's properties, or when a service that formerly not matched the filter changed it's properties and now matches the filter. More...
 
void ServiceModifiedEndMatch (us::ServiceReferenceU)
 Emitted when a Service matching the filter changes it's properties,. More...
 
void ServiceSelectionChanged (us::ServiceReferenceU)
 Emitted if the user selects a Service from the list. More...
 

Public Member Functions

 QmitkServiceListWidget (QWidget *p=0, Qt::WindowFlags f1=0)
 
virtual ~QmitkServiceListWidget ()
 
void SetAutomaticallySelectFirstEntry (bool automaticallySelectFirstEntry)
 Set if the first entry of the list should be selected automatically if no entry was selected before. More...
 
virtual void CreateQtPartControl (QWidget *parent)
 This method is part of the widget an needs not to be called separately. More...
 
virtual void CreateConnections ()
 This method is part of the widget an needs not to be called separately. (Creation of the connections of main and control widget.) More...
 
bool GetIsServiceSelected ()
 Will return true, if a service is currently selected and false otherwise. More...
 
us::ServiceReferenceU GetSelectedServiceReference ()
 Returns the currently selected Service as a ServiceReference. More...
 
std::vector< us::ServiceReferenceUGetAllServiceReferences ()
 
template<class T >
std::vector< T * > GetAllServices ()
 Use this function to return the all listed services as a class directly. More...
 
template<class T >
T * GetSelectedService ()
 Use this function to return the currently selected service as a class directly. More...
 
template<class T >
void Initialize (const std::string &namingProperty=static_cast< std::string >(""), const std::string &filter=static_cast< std::string >(""))
 Initializes the Widget with essential parameters. More...
 
template<class T >
T * TranslateReference (const us::ServiceReferenceU &reference)
 Translates a serviceReference to a class of the given type. More...
 
void OnServiceEvent (const us::ServiceEvent event)
 This Function listens to ServiceRegistry changes and updates the list of services accordingly. More...
 

Static Public Attributes

static const std::string VIEW_ID
 

Protected Slots

void OnServiceSelectionChanged ()
 Called, when the selection in the list of Services changes. More...
 

Protected Member Functions

void InitPrivate (const std::string &namingProperty, const std::string &filter)
 Finishes initialization after Initialize has been called. More...
 
QListWidgetItem * AddServiceToList (const us::ServiceReferenceU &serviceRef)
 Constructs a ListItem from the given service, displays it, and locally stores the service. More...
 
bool RemoveServiceFromList (const us::ServiceReferenceU &serviceRef)
 Removes the given service from the list and cleans up. Returns true if successful, false if service was not found. More...
 
bool ChangeServiceOnList (const us::ServiceReferenceU &serviceRef)
 Changes list entry of given service to match the changed service properties. More...
 
us::ServiceReferenceU GetServiceForListItem (QListWidgetItem *item)
 Returns the serviceReference corresponding to the given ListEntry or an invalid one if none was found (will evaluate to false in bool expressions). More...
 
std::vector< us::ServiceReferenceUGetAllRegisteredServices ()
 Returns a list of ServiceReferences matching the filter criteria by querying the service registry. More...
 
QString CreateCaptionForService (const us::ServiceReferenceU &serviceRef)
 Gets string from the naming property of the service. More...
 

Protected Attributes

Ui::QmitkServiceListWidgetControls * m_Controls
 member holding the UI elements of this widget More...
 
std::vector< ServiceListLinkm_ListContent
 Contains a list of currently active services and their entires in the list. This is wiped with every ServiceRegistryEvent. More...
 

Detailed Description

This widget provides abstraction for the handling of MicroServices.

Place one in your Plugin and set it to look for a certain interface. One can also specify a filter and / or a property to use for captioning of the services. It also offers functionality to signal ServiceEvents and to return the actual classes, so only a minimum of interaction with the MicroserviceInterface is required. To get started, just put it in your Plugin or Widget, call the Initialize Method and optionally connect it's signals. As QT limits templating possibilities, events only throw ServiceReferences. You can manually dereference them using TranslateServiceReference()

Definition at line 49 of file QmitkServiceListWidget.h.

Constructor & Destructor Documentation

QmitkServiceListWidget::QmitkServiceListWidget ( QWidget *  p = 0,
Qt::WindowFlags  f1 = 0 
)

Definition at line 32 of file QmitkServiceListWidget.cpp.

References CreateQtPartControl().

QmitkServiceListWidget::~QmitkServiceListWidget ( )
virtual

Definition at line 38 of file QmitkServiceListWidget.cpp.

References OnServiceEvent().

Member Function Documentation

QListWidgetItem * QmitkServiceListWidget::AddServiceToList ( const us::ServiceReferenceU serviceRef)
protected

Constructs a ListItem from the given service, displays it, and locally stores the service.

Definition at line 160 of file QmitkServiceListWidget.cpp.

References CreateCaptionForService(), QmitkServiceListWidget::ServiceListLink::item, m_Controls, m_ListContent, OnServiceSelectionChanged(), and QmitkServiceListWidget::ServiceListLink::service.

Referenced by InitPrivate(), and OnServiceEvent().

bool QmitkServiceListWidget::ChangeServiceOnList ( const us::ServiceReferenceU serviceRef)
protected

Changes list entry of given service to match the changed service properties.

Returns
true if successful, false if service was not found

Definition at line 205 of file QmitkServiceListWidget.cpp.

References CreateCaptionForService(), and m_ListContent.

Referenced by OnServiceEvent().

QString QmitkServiceListWidget::CreateCaptionForService ( const us::ServiceReferenceU serviceRef)
protected

Gets string from the naming property of the service.

Returns
caption string for given us::ServiceReferenceU

Definition at line 237 of file QmitkServiceListWidget.cpp.

References us::Any::Empty(), MITK_WARN, and us::Any::ToString().

Referenced by AddServiceToList(), and ChangeServiceOnList().

void QmitkServiceListWidget::CreateConnections ( )
virtual

This method is part of the widget an needs not to be called separately. (Creation of the connections of main and control widget.)

Definition at line 62 of file QmitkServiceListWidget.cpp.

References m_Controls, and OnServiceSelectionChanged().

Referenced by CreateQtPartControl().

void QmitkServiceListWidget::CreateQtPartControl ( QWidget *  parent)
virtual

This method is part of the widget an needs not to be called separately.

Definition at line 50 of file QmitkServiceListWidget.cpp.

References CreateConnections(), us::GetModuleContext(), and m_Controls.

Referenced by QmitkServiceListWidget().

std::vector< us::ServiceReferenceU > QmitkServiceListWidget::GetAllRegisteredServices ( )
protected

Returns a list of ServiceReferences matching the filter criteria by querying the service registry.

Definition at line 231 of file QmitkServiceListWidget.cpp.

Referenced by InitPrivate().

std::vector< us::ServiceReferenceU > QmitkServiceListWidget::GetAllServiceReferences ( )
Returns
Returns all service references that are displayed in this widget.

Definition at line 117 of file QmitkServiceListWidget.cpp.

References m_ListContent.

template<class T >
std::vector<T *> QmitkServiceListWidget::GetAllServices ( )
inline

Use this function to return the all listed services as a class directly.

Make sure you pass the appropriate type, or else this call will fail. Usually, you will pass the class itself, not the SmartPointer, but the function returns a pointer.

Definition at line 108 of file QmitkServiceListWidget.h.

bool QmitkServiceListWidget::GetIsServiceSelected ( )

Will return true, if a service is currently selected and false otherwise.

Call this before requesting service references to avoid invalid ServiceReferences.

Definition at line 95 of file QmitkServiceListWidget.cpp.

References m_Controls.

template<class T >
T* QmitkServiceListWidget::GetSelectedService ( )
inline

Use this function to return the currently selected service as a class directly.

Make sure you pass the appropriate type, or else this call will fail. Usually, you will pass the class itself, not the SmartPointer, but the function returns a pointer. Example:

mitk::USDevice::Pointer device = GetSelectedService<mitk::USDevice>(); 
Returns
Returns the current selected device. Returns NULL if no device is selected.

Definition at line 129 of file QmitkServiceListWidget.h.

us::ServiceReferenceU QmitkServiceListWidget::GetSelectedServiceReference ( )

Returns the currently selected Service as a ServiceReference.

If no Service is selected, the result will probably be a bad pointer. call GetIsServiceSelected() beforehand to avoid this

Definition at line 112 of file QmitkServiceListWidget.cpp.

References GetServiceForListItem(), and m_Controls.

us::ServiceReferenceU QmitkServiceListWidget::GetServiceForListItem ( QListWidgetItem *  item)
protected

Returns the serviceReference corresponding to the given ListEntry or an invalid one if none was found (will evaluate to false in bool expressions).

Definition at line 220 of file QmitkServiceListWidget.cpp.

References m_ListContent.

Referenced by GetSelectedServiceReference(), and OnServiceSelectionChanged().

template<class T >
void QmitkServiceListWidget::Initialize ( const std::string &  namingProperty = static_cast<std::string>(""),
const std::string &  filter = static_cast<std::string>("") 
)
inline

Initializes the Widget with essential parameters.

The string filter is an LDAP parsable String, compare mitk::ModuleContext for examples on filtering. Pass class T to tell the widget which class it should filter for - only services of this class will be listed. NamingProperty is a property that will be used to caption the Items in the list. If no filter is supplied, all matching interfaces are shown. If no namingProperty is supplied, the interfaceName will be used to caption Items in the list. For example, this Initialization will filter for all USDevices that are set to active. The USDevice's model will be used to display it in the list:

    std::string filter = "(&(" + us::ServiceConstants::OBJECTCLASS() + "=" +
"org.mitk.services.UltrasoundDevice)(IsActive=true))";
    m_Controls.m_ActiveVideoDevices->Initialize<mitk::USDevice>(mitk::USDevice::GetPropertyKeys().US_PROPKEY_NAME
,filter);
* 

Definition at line 155 of file QmitkServiceListWidget.h.

void QmitkServiceListWidget::InitPrivate ( const std::string &  namingProperty,
const std::string &  filter 
)
protected

Finishes initialization after Initialize has been called.

This function assumes that m_Interface is set correctly (Which Initialize does).

Definition at line 73 of file QmitkServiceListWidget.cpp.

References AddServiceToList(), GetAllRegisteredServices(), m_Controls, m_ListContent, us::ServiceConstants::OBJECTCLASS(), and OnServiceEvent().

void QmitkServiceListWidget::OnServiceEvent ( const us::ServiceEvent  event)

This Function listens to ServiceRegistry changes and updates the list of services accordingly.

The user of this widget does not need to call this method, it is instead used to recieve events from the module registry.

Definition at line 129 of file QmitkServiceListWidget.cpp.

References AddServiceToList(), ChangeServiceOnList(), us::ServiceEvent::GetServiceReference(), us::ServiceEvent::GetType(), us::ServiceEvent::MODIFIED, us::ServiceEvent::MODIFIED_ENDMATCH, us::ServiceEvent::REGISTERED, RemoveServiceFromList(), ServiceModified(), ServiceModifiedEndMatch(), ServiceRegistered(), ServiceUnregistering(), and us::ServiceEvent::UNREGISTERING.

Referenced by InitPrivate(), and ~QmitkServiceListWidget().

void QmitkServiceListWidget::OnServiceSelectionChanged ( )
protectedslot

Called, when the selection in the list of Services changes.

Definition at line 100 of file QmitkServiceListWidget.cpp.

References GetServiceForListItem(), m_Controls, and ServiceSelectionChanged().

Referenced by AddServiceToList(), and CreateConnections().

bool QmitkServiceListWidget::RemoveServiceFromList ( const us::ServiceReferenceU serviceRef)
protected

Removes the given service from the list and cleans up. Returns true if successful, false if service was not found.

Definition at line 187 of file QmitkServiceListWidget.cpp.

References m_Controls, and m_ListContent.

Referenced by OnServiceEvent().

void QmitkServiceListWidget::ServiceModified ( us::ServiceReferenceU  )
signal

Emitted when a Service matching the filter changes it's properties, or when a service that formerly not matched the filter changed it's properties and now matches the filter.

Referenced by OnServiceEvent().

void QmitkServiceListWidget::ServiceModifiedEndMatch ( us::ServiceReferenceU  )
signal

Emitted when a Service matching the filter changes it's properties,.

and the new properties make it fall trough the filter. This effectively means that the widget will not track the service anymore. Usually, the Service should still be useable though

Referenced by OnServiceEvent().

void QmitkServiceListWidget::ServiceRegistered ( us::ServiceReferenceU  )
signal

Emitted when a new Service matching the filter is being registered.

Be careful if you use a filter: If a device does not match the filter when registering, but modifies it's properties later to match the filter, then the first signal you will see this device in will be ServiceModified.

Referenced by OnServiceEvent().

void QmitkServiceListWidget::ServiceSelectionChanged ( us::ServiceReferenceU  )
signal

Emitted if the user selects a Service from the list.

If no service is selected, an invalid serviceReference is returned. The user can easily check for this. if (serviceReference) will evaluate to false, if the reference is invalid and true if valid.

Referenced by OnServiceSelectionChanged().

void QmitkServiceListWidget::ServiceUnregistering ( us::ServiceReferenceU  )
signal

Emitted directly before a Service matching the filter is being unregistered.

Referenced by OnServiceEvent().

void QmitkServiceListWidget::SetAutomaticallySelectFirstEntry ( bool  automaticallySelectFirstEntry)

Set if the first entry of the list should be selected automatically if no entry was selected before.

Definition at line 43 of file QmitkServiceListWidget.cpp.

template<class T >
T* QmitkServiceListWidget::TranslateReference ( const us::ServiceReferenceU reference)
inline

Translates a serviceReference to a class of the given type.

Use this to translate the signal's parameters. To adhere to the MicroService contract, only ServiceReferences stemming from the same widget should be used as parameters for this method.

mitk::USDevice::Pointer device = TranslateReference<mitk::USDevice>(myDeviceReference); 

Definition at line 171 of file QmitkServiceListWidget.h.

Member Data Documentation

Ui::QmitkServiceListWidgetControls* QmitkServiceListWidget::m_Controls
protected
std::vector<ServiceListLink> QmitkServiceListWidget::m_ListContent
protected

Contains a list of currently active services and their entires in the list. This is wiped with every ServiceRegistryEvent.

Definition at line 255 of file QmitkServiceListWidget.h.

Referenced by AddServiceToList(), ChangeServiceOnList(), GetAllServiceReferences(), GetServiceForListItem(), InitPrivate(), and RemoveServiceFromList().

const std::string QmitkServiceListWidget::VIEW_ID
static

Definition at line 67 of file QmitkServiceListWidget.h.


The documentation for this class was generated from the following files: