Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkServiceListWidget.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef QmitkServiceListWidget_h
14 #define QmitkServiceListWidget_h
15 
16 #include <MitkQtWidgetsExports.h>
17 #include <vector>
18 
19 // QT headers
20 #include <QListWidget>
21 #include <QListWidgetItem>
22 #include <QWidget>
23 
24 // Microservices
25 #include <mitkServiceInterface.h>
26 #include <usModuleContext.h>
27 #include <usServiceEvent.h>
28 #include <usServiceReference.h>
29 #include <memory>
30 
31 namespace Ui { class QmitkServiceListWidgetControls; }
32 
49 {
50  // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject)
51  Q_OBJECT
52 
53 private:
54  us::ModuleContext *m_Context;
56  std::string m_Filter;
58  std::string m_Interface;
60  std::string m_NamingProperty;
63  bool m_AutomaticallySelectFirstEntry;
64 
65 public:
66  static const std::string VIEW_ID;
67 
68  QmitkServiceListWidget(QWidget *p = nullptr, Qt::WindowFlags f1 = {});
70 
72  void SetAutomaticallySelectFirstEntry(bool automaticallySelectFirstEntry);
73 
75  virtual void CreateQtPartControl(QWidget *parent);
78  virtual void CreateConnections();
79 
86 
94 
98  std::vector<us::ServiceReferenceU> GetAllServiceReferences();
99 
106  template <class T>
107  std::vector<T *> GetAllServices()
108  {
109  // if (this->m_Controls->m_ServiceList->currentRow()==-1) return nullptr;
110  std::vector<us::ServiceReferenceU> refs = GetAllServiceReferences();
111  std::vector<T *> result;
112  for (std::size_t i = 0; i < refs.size(); i++)
113  {
114  result.push_back(m_Context->GetService(us::ServiceReference<T>(refs[i])));
115  }
116  return result;
117  }
118 
127  template <class T>
129  {
130  if (m_ServiceList->currentRow() == -1)
131  return nullptr;
132 
133  us::ServiceReferenceU ref = GetServiceForListItem(m_ServiceList->currentItem());
134 
135  return (m_Context->GetService(us::ServiceReference<T>(ref)));
136  }
137 
155  template <class T>
156  void Initialize(const std::string &namingProperty = static_cast<std::string>(""),
157  const std::string &filter = static_cast<std::string>(""))
158  {
159  std::string interfaceName(us_service_interface_iid<T>());
160  m_Interface = interfaceName;
161  InitPrivate(namingProperty, filter);
162  }
163 
171  template <class T>
173  {
174  return m_Context->GetService(us::ServiceReference<T>(reference));
175  }
176 
183  void OnServiceEvent(const us::ServiceEvent event);
184 
185 signals:
186 
195 
200 
207 
215 
223 
224 public slots:
225 
226 protected slots:
227 
232 
233 protected:
234  std::unique_ptr<Ui::QmitkServiceListWidgetControls> m_Controls;
235  QListWidget* m_ServiceList;
236 
241  {
243  QListWidgetItem *item;
244  };
245 
251  void InitPrivate(const std::string &namingProperty, const std::string &filter);
252 
257  std::vector<ServiceListLink> m_ListContent;
258 
262  QListWidgetItem *AddServiceToList(const us::ServiceReferenceU &serviceRef);
263 
269 
275 
281 
285  std::vector<us::ServiceReferenceU> GetAllRegisteredServices();
286 
291  QString CreateCaptionForService(const us::ServiceReferenceU &serviceRef);
292 };
293 
294 #endif
#define MITKQTWIDGETS_EXPORT
This widget provides abstraction for the handling of MicroServices.
void InitPrivate(const std::string &namingProperty, const std::string &filter)
Finishes initialization after Initialize has been called.
static const std::string VIEW_ID
std::vector< ServiceListLink > m_ListContent
Contains a list of currently active services and their entries in the list. This is wiped with every ...
void ServiceModified(us::ServiceReferenceU)
Emitted when a Service matching the filter changes it's properties, or when a service that formerly n...
QListWidgetItem * AddServiceToList(const us::ServiceReferenceU &serviceRef)
Constructs a ListItem from the given service, displays it, and locally stores the service.
QmitkServiceListWidget(QWidget *p=nullptr, Qt::WindowFlags f1={})
T * GetSelectedService()
Use this function to return the currently selected service as a class directly.
us::ServiceReferenceU GetServiceForListItem(QListWidgetItem *item)
Returns the serviceReference corresponding to the given ListEntry or an invalid one if none was found...
std::unique_ptr< Ui::QmitkServiceListWidgetControls > m_Controls
member holding the UI elements of this widget
void ServiceModifiedEndMatch(us::ServiceReferenceU)
Emitted when a Service matching the filter changes it's properties,.
void ServiceUnregistering(us::ServiceReferenceU)
Emitted directly before a Service matching the filter is being unregistered.
bool GetIsServiceSelected()
Will return true, if a service is currently selected and false otherwise.
std::vector< us::ServiceReferenceU > GetAllServiceReferences()
void OnServiceEvent(const us::ServiceEvent event)
This Function listens to ServiceRegistry changes and updates the list of services accordingly.
void ServiceRegistered(us::ServiceReferenceU)
Emitted when a new Service matching the filter is being registered.
bool ChangeServiceOnList(const us::ServiceReferenceU &serviceRef)
Changes list entry of given service to match the changed service properties.
std::vector< us::ServiceReferenceU > GetAllRegisteredServices()
Returns a list of ServiceReferences matching the filter criteria by querying the service registry.
T * TranslateReference(const us::ServiceReferenceU &reference)
Translates a serviceReference to a class of the given type.
us::ServiceReferenceU GetSelectedServiceReference()
Returns the currently selected Service as a ServiceReference.
std::vector< T * > GetAllServices()
Use this function to return the all listed services as a class directly.
virtual void CreateQtPartControl(QWidget *parent)
This method is part of the widget an needs not to be called separately.
void SetAutomaticallySelectFirstEntry(bool automaticallySelectFirstEntry)
Set if the first entry of the list should be selected automatically if no entry was selected before.
void Initialize(const std::string &namingProperty=static_cast< std::string >(""), const std::string &filter=static_cast< std::string >(""))
Initializes the Widget with essential parameters.
~QmitkServiceListWidget() override
void ServiceSelectionChanged(us::ServiceReferenceU)
Emitted if the user selects a Service from the list.
virtual void CreateConnections()
This method is part of the widget an needs not to be called separately. (Creation of the connections ...
QString CreateCaptionForService(const us::ServiceReferenceU &serviceRef)
Gets string from the naming property of the service.
bool RemoveServiceFromList(const us::ServiceReferenceU &serviceRef)
Removes the given service from the list and cleans up. Returns true if successful,...
void OnServiceSelectionChanged()
Called, when the selection in the list of Services changes.
void * GetService(const ServiceReferenceBase &reference)
Returns the service object referenced by the specified ServiceReferenceBase object.
Provides the MITK_DECLARE_SERVICE_INTERFACE macro for registering C++ interfaces with both the CppMic...