Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef _QmitkServiceListWidget_H_INCLUDED
18 #define _QmitkServiceListWidget_H_INCLUDED
19 
20 #include "MitkQtWidgetsExports.h"
21 #include "ui_QmitkServiceListWidgetControls.h"
22 #include <vector>
23 
24 // QT headers
25 #include <QListWidgetItem>
26 #include <QWidget>
27 
28 // Microservices
29 #include "mitkServiceInterface.h"
30 #include "usModuleContext.h"
31 #include "usServiceEvent.h"
32 #include "usServiceReference.h"
33 
50 {
51  // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject)
52  Q_OBJECT
53 
54 private:
55  us::ModuleContext *m_Context;
57  std::string m_Filter;
59  std::string m_Interface;
61  std::string m_NamingProperty;
64  bool m_AutomaticallySelectFirstEntry;
65 
66 public:
67  static const std::string VIEW_ID;
68 
69  QmitkServiceListWidget(QWidget *p = 0, Qt::WindowFlags f1 = 0);
70  virtual ~QmitkServiceListWidget();
71 
73  void SetAutomaticallySelectFirstEntry(bool automaticallySelectFirstEntry);
74 
76  virtual void CreateQtPartControl(QWidget *parent);
79  virtual void CreateConnections();
80 
86  bool GetIsServiceSelected();
87 
94  us::ServiceReferenceU GetSelectedServiceReference();
95 
99  std::vector<us::ServiceReferenceU> GetAllServiceReferences();
100 
107  template <class T>
108  std::vector<T *> GetAllServices()
109  {
110  // if (this->m_Controls->m_ServiceList->currentRow()==-1) return NULL;
111  std::vector<us::ServiceReferenceU> refs = GetAllServiceReferences();
112  std::vector<T *> result;
113  for (int i = 0; i < refs.size(); i++)
114  {
115  result.push_back(m_Context->GetService(us::ServiceReference<T>(refs[i])));
116  }
117  return result;
118  }
119 
128  template <class T>
130  {
131  if (this->m_Controls->m_ServiceList->currentRow() == -1)
132  return NULL;
133  us::ServiceReferenceU ref = GetServiceForListItem(this->m_Controls->m_ServiceList->currentItem());
134  return (m_Context->GetService(us::ServiceReference<T>(ref)));
135  }
136 
154  template <class T>
155  void Initialize(const std::string &namingProperty = static_cast<std::string>(""),
156  const std::string &filter = static_cast<std::string>(""))
157  {
158  std::string interfaceName(us_service_interface_iid<T>());
159  m_Interface = interfaceName;
160  InitPrivate(namingProperty, filter);
161  }
162 
170  template <class T>
172  {
173  return m_Context->GetService(us::ServiceReference<T>(reference));
174  }
175 
182  void OnServiceEvent(const us::ServiceEvent event);
183 
184 signals:
185 
193  void ServiceRegistered(us::ServiceReferenceU);
194 
198  void ServiceUnregistering(us::ServiceReferenceU);
199 
205  void ServiceModified(us::ServiceReferenceU);
206 
213  void ServiceModifiedEndMatch(us::ServiceReferenceU);
214 
221  void ServiceSelectionChanged(us::ServiceReferenceU);
222 
223 public slots:
224 
225 protected slots:
226 
230  void OnServiceSelectionChanged();
231 
232 protected:
233  Ui::QmitkServiceListWidgetControls *m_Controls;
234 
239  {
241  QListWidgetItem *item;
242  };
243 
249  void InitPrivate(const std::string &namingProperty, const std::string &filter);
250 
255  std::vector<ServiceListLink> m_ListContent;
256 
260  QListWidgetItem *AddServiceToList(const us::ServiceReferenceU &serviceRef);
261 
266  bool RemoveServiceFromList(const us::ServiceReferenceU &serviceRef);
267 
272  bool ChangeServiceOnList(const us::ServiceReferenceU &serviceRef);
273 
278  us::ServiceReferenceU GetServiceForListItem(QListWidgetItem *item);
279 
283  std::vector<us::ServiceReferenceU> GetAllRegisteredServices();
284 
289  QString CreateCaptionForService(const us::ServiceReferenceU &serviceRef);
290 };
291 
292 #endif // _QmitkServiceListWidget_H_INCLUDED
T * TranslateReference(const us::ServiceReferenceU &reference)
Translates a serviceReference to a class of the given type.
T * GetSelectedService()
Use this function to return the currently selected service as a class directly.
Ui::QmitkServiceListWidgetControls * m_Controls
member holding the UI elements of this widget
void Initialize(const std::string &namingProperty=static_cast< std::string >(""), const std::string &filter=static_cast< std::string >(""))
Initializes the Widget with essential parameters.
#define MITKQTWIDGETS_EXPORT
static const std::string VIEW_ID
This widget provides abstraction for the handling of MicroServices.
std::vector< ServiceListLink > m_ListContent
Contains a list of currently active services and their entires in the list. This is wiped with every ...
std::vector< T * > GetAllServices()
Use this function to return the all listed services as a class directly.