Medical Imaging Interaction Toolkit  2025.12.02
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 "ui_QmitkServiceListWidgetControls.h"
18 #include <vector>
19 
20 // QT headers
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 
46 {
47  // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject)
48  Q_OBJECT
49 
50 private:
51  us::ModuleContext *m_Context;
53  std::string m_Filter;
55  std::string m_Interface;
57  std::string m_NamingProperty;
60  bool m_AutomaticallySelectFirstEntry;
61 
62 public:
63  static const std::string VIEW_ID;
64 
65  QmitkServiceListWidget(QWidget *p = nullptr, Qt::WindowFlags f1 = {});
67 
69  void SetAutomaticallySelectFirstEntry(bool automaticallySelectFirstEntry);
70 
72  virtual void CreateQtPartControl(QWidget *parent);
75  virtual void CreateConnections();
76 
83 
91 
95  std::vector<us::ServiceReferenceU> GetAllServiceReferences();
96 
103  template <class T>
104  std::vector<T *> GetAllServices()
105  {
106  // if (this->m_Controls->m_ServiceList->currentRow()==-1) return nullptr;
107  std::vector<us::ServiceReferenceU> refs = GetAllServiceReferences();
108  std::vector<T *> result;
109  for (std::size_t i = 0; i < refs.size(); i++)
110  {
111  result.push_back(m_Context->GetService(us::ServiceReference<T>(refs[i])));
112  }
113  return result;
114  }
115 
124  template <class T>
126  {
127  if (this->m_Controls->m_ServiceList->currentRow() == -1)
128  return nullptr;
129  us::ServiceReferenceU ref = GetServiceForListItem(this->m_Controls->m_ServiceList->currentItem());
130  return (m_Context->GetService(us::ServiceReference<T>(ref)));
131  }
132 
150  template <class T>
151  void Initialize(const std::string &namingProperty = static_cast<std::string>(""),
152  const std::string &filter = static_cast<std::string>(""))
153  {
154  std::string interfaceName(us_service_interface_iid<T>());
155  m_Interface = interfaceName;
156  InitPrivate(namingProperty, filter);
157  }
158 
166  template <class T>
168  {
169  return m_Context->GetService(us::ServiceReference<T>(reference));
170  }
171 
178  void OnServiceEvent(const us::ServiceEvent event);
179 
180 signals:
181 
190 
195 
202 
210 
218 
219 public slots:
220 
221 protected slots:
222 
227 
228 protected:
229  Ui::QmitkServiceListWidgetControls *m_Controls;
230 
235  {
237  QListWidgetItem *item;
238  };
239 
245  void InitPrivate(const std::string &namingProperty, const std::string &filter);
246 
251  std::vector<ServiceListLink> m_ListContent;
252 
256  QListWidgetItem *AddServiceToList(const us::ServiceReferenceU &serviceRef);
257 
263 
269 
275 
279  std::vector<us::ServiceReferenceU> GetAllRegisteredServices();
280 
285  QString CreateCaptionForService(const us::ServiceReferenceU &serviceRef);
286 };
287 
288 #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...
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.