Medical Imaging Interaction Toolkit  2024.12.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 = {});
66  ~QmitkServiceListWidget() override;
67 
69  void SetAutomaticallySelectFirstEntry(bool automaticallySelectFirstEntry);
70 
72  virtual void CreateQtPartControl(QWidget *parent);
75  virtual void CreateConnections();
76 
82  bool GetIsServiceSelected();
83 
90  us::ServiceReferenceU GetSelectedServiceReference();
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 
189  void ServiceRegistered(us::ServiceReferenceU);
190 
194  void ServiceUnregistering(us::ServiceReferenceU);
195 
201  void ServiceModified(us::ServiceReferenceU);
202 
209  void ServiceModifiedEndMatch(us::ServiceReferenceU);
210 
217  void ServiceSelectionChanged(us::ServiceReferenceU);
218 
219 public slots:
220 
221 protected slots:
222 
226  void OnServiceSelectionChanged();
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 
262  bool RemoveServiceFromList(const us::ServiceReferenceU &serviceRef);
263 
268  bool ChangeServiceOnList(const us::ServiceReferenceU &serviceRef);
269 
274  us::ServiceReferenceU GetServiceForListItem(QListWidgetItem *item);
275 
279  std::vector<us::ServiceReferenceU> GetAllRegisteredServices();
280 
285  QString CreateCaptionForService(const us::ServiceReferenceU &serviceRef);
286 };
287 
288 #endif
QmitkServiceListWidget::Initialize
void Initialize(const std::string &namingProperty=static_cast< std::string >(""), const std::string &filter=static_cast< std::string >(""))
Initializes the Widget with essential parameters.
Definition: QmitkServiceListWidget.h:151
usServiceEvent.h
MITKQTWIDGETS_EXPORT
#define MITKQTWIDGETS_EXPORT
Definition: MitkQtWidgetsExports.h:15
mitkServiceInterface.h
QmitkServiceListWidget::m_Controls
Ui::QmitkServiceListWidgetControls * m_Controls
member holding the UI elements of this widget
Definition: QmitkServiceListWidget.h:229
QmitkServiceListWidget
This widget provides abstraction for the handling of MicroServices.
Definition: QmitkServiceListWidget.h:45
QmitkServiceListWidget::VIEW_ID
static const std::string VIEW_ID
Definition: QmitkServiceListWidget.h:63
us::ServiceReference
Definition: usModule.h:40
QmitkServiceListWidget::GetSelectedService
T * GetSelectedService()
Use this function to return the currently selected service as a class directly.
Definition: QmitkServiceListWidget.h:125
usServiceReference.h
MitkQtWidgetsExports.h
QmitkServiceListWidget::m_ListContent
std::vector< ServiceListLink > m_ListContent
Contains a list of currently active services and their entires in the list. This is wiped with every ...
Definition: QmitkServiceListWidget.h:251
QmitkServiceListWidget::GetAllServices
std::vector< T * > GetAllServices()
Use this function to return the all listed services as a class directly.
Definition: QmitkServiceListWidget.h:104
us::ServiceEvent
Definition: usServiceEvent.h:55
QmitkServiceListWidget::TranslateReference
T * TranslateReference(const us::ServiceReferenceU &reference)
Translates a serviceReference to a class of the given type.
Definition: QmitkServiceListWidget.h:167
usModuleContext.h