Fraxinus  17.12
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
34 #include "cxPatientModelService.h"
35 #include "cxData.h"
36 #include "cxImageAlgorithms.h"
37 #include "cxImage.h"
38 
39 namespace cx
40 {
41 
43  mTypeRegexp(typeRegexp),
44  mPatientModelService(patientModelService),
45  mOnly2D(false)
46 {
47  mValueName = "Select data";
48  mUidRegexp = "";
49  mHelp = mValueName;
50  connect(mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SIGNAL(changed()));
51 }
52 
56 std::map<QString, DataPtr> SelectDataStringPropertyBase::filterOnType(std::map<QString, DataPtr> input, QString regexp)
57 {
58  QRegExp reg(regexp);
59 
60  std::map<QString, DataPtr>::iterator iter, current;
61 
62  for (iter=input.begin(); iter!=input.end(); )
63  {
64  current = iter++; // increment iterator before erasing!
65  if (!current->second->getType().contains(reg))
66  input.erase(current);
67  }
68 
69  return input;
70 }
71 
73 {
74  mTypeRegexp = regexp;
75  emit changed();
76 }
77 
81 std::map<QString, DataPtr> SelectDataStringPropertyBase::filterOnUid(std::map<QString, DataPtr> input, QString regexp) const
82 {
83 
84  QRegExp reg(regexp);
85 
86  std::map<QString, DataPtr>::iterator iter, current;
87  for (iter=input.begin(); iter!=input.end(); )
88  {
89  current = iter++; // increment iterator before erasing!
90  if (!current->second->getUid().contains(reg))
91  input.erase(current);
92  }
93 
94  return input;
95 }
96 
97 std::map<QString, DataPtr> SelectDataStringPropertyBase::filterImagesOn2D(std::map<QString, DataPtr> input, bool only2D) const
98 {
99  if(!only2D)
100  return input;
101 
102  std::map<QString, DataPtr>::iterator iter, current;
103  for (iter=input.begin(); iter!=input.end(); )
104  {
105  current = iter++; // increment iterator before erasing!
106  ImagePtr image = boost::dynamic_pointer_cast<Image>(current->second);
107  if(image && !image->is2D())
108  input.erase(current);
109  }
110 
111  return input;
112 }
113 
115 {
116  mOnly2D = only2D;
117  emit changed();
118 }
119 
121 {
122  mUidRegexp = regexp;
123  emit changed();
124 }
125 
127 {
128  std::map<QString, DataPtr> data = mPatientModelService->getDatas();
130  data = this->filterOnUid(data, mUidRegexp);
131  data = this->filterImagesOn2D(data, mOnly2D);
132  std::vector<DataPtr> sorted = sortOnGroupsAndAcquisitionTime(data);
133  QStringList retval;
134  retval << "";
135  for (unsigned i=0; i<sorted.size(); ++i)
136  retval << sorted[i]->getUid();
137  return retval;
138 }
139 
141 {
142  DataPtr data = mPatientModelService->getData(internal);
143  if (!data)
144  return "<no data>";
145  return qstring_cast(data->getName());
146 }
147 
149 {
150  return mHelp;
151 }
152 
154 {
155  return mValueName;
156 }
157 
159 {
160  mHelp = text;
161  emit changed();
162 }
164 {
165  mValueName = val;
166  emit changed();
167 }
168 
170 {
171  return mPatientModelService->getData(this->getValue());
172 }
173 
175 {
176  return mPatientModelService->getData(uid);
177 }
178 
179 } //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:48
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:66
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.