NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxSpaceProperty.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 
33 #include "cxSpaceProperty.h"
34 #include <iostream>
35 #include <QDomElement>
36 #include <QStringList>
37 #include "cxTypeConversions.h"
38 #include "cxSpaceProvider.h"
39 
40 namespace cx
41 {
42 
43 SpaceProperty::SpaceProperty() : mIsReadOnly(false)
44 {
45 
46 }
47 
51 SpacePropertyPtr SpaceProperty::initialize(const QString& uid, QString name, QString help, Space value, std::vector<Space> range, QDomNode root)
52 {
53  SpacePropertyPtr retval(new SpaceProperty());
54  retval->mUid = uid;
55  retval->mName = name.isEmpty() ? uid : name;
56  retval->mHelp = help;
57  retval->mRange = range;
58  retval->mStore = XmlOptionItem(uid, root.toElement());
59  retval->mValue = Space::fromString(retval->mStore.readValue(value.toString()));
60  retval->mAllowOnlyValuesInRange = true;
61  return retval;
62 }
63 
65 {
66  mProvider = provider;
67  connect(mProvider.get(), &SpaceProvider::spaceAddedOrRemoved, this, &SpaceProperty::providerChangedSlot);
68  this->providerChangedSlot();
69 }
70 
71 void SpaceProperty::providerChangedSlot()
72 {
73  std::map<QString, QString> names = mProvider->getDisplayNamesForCoordRefObjects();
74  this->setRefObjectDisplayNames(names);
75 
76  std::vector<CoordinateSystem> spaces = mProvider->getSpacesToPresentInGUI();
77  this->setValueRange(spaces);
78 }
79 
80 
82 {
83  mIsReadOnly = val;
84  emit changed();
85 }
86 
88 {
89  return mName;
90 }
91 
92 QString SpaceProperty::getUid() const
93 {
94  return mUid;
95 }
96 
97 QString SpaceProperty::getHelp() const
98 {
99  return mHelp;
100 }
101 
102 void SpaceProperty::setHelp(QString val)
103 {
104  if (val == mHelp)
105  return;
106 
107  mHelp = val;
108  emit changed();
109 }
110 
111 
113 {
114  return mValue;
115 }
116 
118 {
119  if (val == mValue)
120  return false;
121 
122  mValue = val;
123  mStore.writeValue(val.toString());
124  emit valueWasSet();
125  emit changed();
126  return true;
127 }
128 
129 std::vector<Space> SpaceProperty::getValueRange() const
130 {
131  return mRange;
132 }
133 
134 void SpaceProperty::setValueRange(std::vector<Space> range)
135 {
136  mRange = range;
137  emit changed();
138 }
139 
144 {
145  if (mDisplayNames.count(internal))
146  return mDisplayNames[internal];
147  return internal;
148 }
149 
150 void SpaceProperty::setRefObjectDisplayNames(std::map<QString, QString> names)
151 {
152  mDisplayNames = names;
153  emit changed();
154 }
155 
156 } // namespace cx
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
void setSpaceProvider(SpaceProviderPtr provider)
static SpacePropertyPtr initialize(const QString &uid, QString name, QString help, Space value=Space(), std::vector< Space > range=std::vector< Space >(), QDomNode root=QDomNode())
void spaceAddedOrRemoved()
boost::shared_ptr< class SpaceProperty > SpacePropertyPtr
virtual void setHelp(QString val)
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
Helper class for storing one string value in an xml document.
virtual QString convertRefObjectInternal2Display(QString internal)
conversion from internal value to display value
Identification of a Coordinate system.
virtual Space getValue() const
get the data value.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
void writeValue(const QString &val)
void setReadOnly(bool val)
virtual std::vector< Space > getValueRange() const
virtual QString getUid() const
virtual void setRefObjectDisplayNames(std::map< QString, QString > names)
virtual void setValueRange(std::vector< Space > range)
range of value. Use if data is constrained to a set.
static CoordinateSystem fromString(QString text)
virtual bool setValue(const Space &value)
set the data value.