Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxSelectDataStringPropertyBase.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 #include "cxPatientModelService.h"
14 #include "cxData.h"
15 #include "cxImageAlgorithms.h"
16 #include "cxImage.h"
17 
18 namespace cx
19 {
20 
22  mTypeRegexp(typeRegexp),
23  mPatientModelService(patientModelService),
24  mOnly2D(false)
25 {
26  mValueName = "Select data";
27  mUidRegexp = "";
28  mHelp = mValueName;
29  connect(mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SIGNAL(changed()));
30 }
31 
35 std::map<QString, DataPtr> SelectDataStringPropertyBase::filterOnType(std::map<QString, DataPtr> input, QString regexp)
36 {
37  QRegExp reg(regexp);
38 
39  std::map<QString, DataPtr>::iterator iter, current;
40 
41  for (iter=input.begin(); iter!=input.end(); )
42  {
43  current = iter++; // increment iterator before erasing!
44  if (!current->second->getType().contains(reg))
45  input.erase(current);
46  }
47 
48  return input;
49 }
50 
52 {
53  mTypeRegexp = regexp;
54  emit changed();
55 }
56 
60 std::map<QString, DataPtr> SelectDataStringPropertyBase::filterOnUid(std::map<QString, DataPtr> input, QString regexp) const
61 {
62 
63  QRegExp reg(regexp);
64 
65  std::map<QString, DataPtr>::iterator iter, current;
66  for (iter=input.begin(); iter!=input.end(); )
67  {
68  current = iter++; // increment iterator before erasing!
69  if (!current->second->getUid().contains(reg))
70  input.erase(current);
71  }
72 
73  return input;
74 }
75 
76 std::map<QString, DataPtr> SelectDataStringPropertyBase::filterImagesOn2D(std::map<QString, DataPtr> input, bool only2D) const
77 {
78  if(!only2D)
79  return input;
80 
81  std::map<QString, DataPtr>::iterator iter, current;
82  for (iter=input.begin(); iter!=input.end(); )
83  {
84  current = iter++; // increment iterator before erasing!
85  ImagePtr image = boost::dynamic_pointer_cast<Image>(current->second);
86  if(image && !image->is2D())
87  input.erase(current);
88  }
89 
90  return input;
91 }
92 
94 {
95  mOnly2D = only2D;
96  emit changed();
97 }
98 
100 {
101  mUidRegexp = regexp;
102  emit changed();
103 }
104 
106 {
107  std::map<QString, DataPtr> data = mPatientModelService->getDatas();
109  data = this->filterOnUid(data, mUidRegexp);
110  data = this->filterImagesOn2D(data, mOnly2D);
111  std::vector<DataPtr> sorted = sortOnGroupsAndAcquisitionTime(data);
112  QStringList retval;
113  retval << "";
114  for (unsigned i=0; i<sorted.size(); ++i)
115  retval << sorted[i]->getUid();
116  return retval;
117 }
118 
120 {
121  DataPtr data = mPatientModelService->getData(internal);
122  if (!data)
123  return "<no data>";
124  return qstring_cast(data->getName());
125 }
126 
128 {
129  return mHelp;
130 }
131 
133 {
134  return mValueName;
135 }
136 
138 {
139  mHelp = text;
140  emit changed();
141 }
143 {
144  mValueName = val;
145  emit changed();
146 }
147 
149 {
150  return mPatientModelService->getData(this->getValue());
151 }
152 
154 {
155  return mPatientModelService->getData(uid);
156 }
157 
158 } //cx
QString qstring_cast(const T &val)
SelectDataStringPropertyBase(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
std::map< QString, DataPtr > filterOnUid(std::map< QString, DataPtr > input, QString regexp) const
std::map< QString, DataPtr > filterImagesOn2D(std::map< QString, DataPtr > input, bool only2D) const
virtual QString getDisplayName() const
name of data entity. Used for display to user.
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
virtual void setValueName(const QString name)
static std::map< QString, DataPtr > filterOnType(std::map< QString, DataPtr > input, QString regexp)
boost::shared_ptr< class Data > DataPtr
std::vector< T > sortOnGroupsAndAcquisitionTime(std::map< QString, T > input)
A volumetric data set.
Definition: cxImage.h:45
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
virtual QString getUid() const
virtual QString convertInternal2Display(QString internal)
range of value. Use if data is constrained to a set.
virtual QString getValue() const =0
get the data value.
Namespace for all CustusX production code.