NorMIT-nav  22.09
An IGT application
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) 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 
12 #include "cxSpaceProperty.h"
13 #include <iostream>
14 #include <QDomElement>
15 #include <QStringList>
16 #include "cxTypeConversions.h"
17 #include "cxSpaceProvider.h"
18 
19 namespace cx
20 {
21 
22 SpaceProperty::SpaceProperty() : mIsReadOnly(false)
23 {
24 
25 }
26 
30 SpacePropertyPtr SpaceProperty::initialize(const QString& uid, QString name, QString help, Space value, std::vector<Space> range, QDomNode root)
31 {
32  SpacePropertyPtr retval(new SpaceProperty());
33  retval->mUid = uid;
34  retval->mName = name.isEmpty() ? uid : name;
35  retval->mHelp = help;
36  retval->mRange = range;
37  retval->mStore = XmlOptionItem(uid, root.toElement());
38  retval->mValue = Space::fromString(retval->mStore.readValue(value.toString()));
39  retval->mAllowOnlyValuesInRange = true;
40  return retval;
41 }
42 
44 {
45  mProvider = provider;
46  connect(mProvider.get(), &SpaceProvider::spaceAddedOrRemoved, this, &SpaceProperty::providerChangedSlot);
47  this->providerChangedSlot();
48 }
49 
50 void SpaceProperty::providerChangedSlot()
51 {
52  std::map<QString, QString> names = mProvider->getDisplayNamesForCoordRefObjects();
53  this->setRefObjectDisplayNames(names);
54 
55  std::vector<CoordinateSystem> spaces = mProvider->getSpacesToPresentInGUI();
56  this->setValueRange(spaces);
57 }
58 
59 
61 {
62  mIsReadOnly = val;
63  emit changed();
64 }
65 
67 {
68  return mName;
69 }
70 
71 QString SpaceProperty::getUid() const
72 {
73  return mUid;
74 }
75 
76 QString SpaceProperty::getHelp() const
77 {
78  return mHelp;
79 }
80 
81 void SpaceProperty::setHelp(QString val)
82 {
83  if (val == mHelp)
84  return;
85 
86  mHelp = val;
87  emit changed();
88 }
89 
90 
92 {
93  return mValue;
94 }
95 
97 {
98  if (val == mValue)
99  return false;
100 
101  mValue = val;
102  mStore.writeValue(val.toString());
103  emit valueWasSet();
104  emit changed();
105  return true;
106 }
107 
108 std::vector<Space> SpaceProperty::getValueRange() const
109 {
110  return mRange;
111 }
112 
113 void SpaceProperty::setValueRange(std::vector<Space> range)
114 {
115  mRange = range;
116  emit changed();
117 }
118 
123 {
124  if (mDisplayNames.count(internal))
125  return mDisplayNames[internal];
126  return internal;
127 }
128 
129 void SpaceProperty::setRefObjectDisplayNames(std::map<QString, QString> names)
130 {
131  mDisplayNames = names;
132  emit changed();
133 }
134 
135 } // namespace cx
cx::SpaceProperty::setSpaceProvider
void setSpaceProvider(SpaceProviderPtr provider)
Definition: cxSpaceProperty.cpp:43
cx::SpaceProperty::setValueRange
virtual void setValueRange(std::vector< Space > range)
range of value. Use if data is constrained to a set.
Definition: cxSpaceProperty.cpp:113
cx::SpaceProperty::convertRefObjectInternal2Display
virtual QString convertRefObjectInternal2Display(QString internal)
conversion from internal value to display value
Definition: cxSpaceProperty.cpp:122
cx::SpaceProvider::spaceAddedOrRemoved
void spaceAddedOrRemoved()
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cx::SpaceProperty::setHelp
virtual void setHelp(QString val)
Definition: cxSpaceProperty.cpp:81
cx::SpaceProperty::setValue
virtual bool setValue(const Space &value)
set the data value.
Definition: cxSpaceProperty.cpp:96
cx::SpaceProperty::setRefObjectDisplayNames
virtual void setRefObjectDisplayNames(std::map< QString, QString > names)
Definition: cxSpaceProperty.cpp:129
cxSpaceProperty.h
cx::SpaceProperty::initialize
static SpacePropertyPtr initialize(const QString &uid, QString name, QString help, Space value=Space(), std::vector< Space > range=std::vector< Space >(), QDomNode root=QDomNode())
Definition: cxSpaceProperty.cpp:30
cx::SpaceProperty::getValue
virtual Space getValue() const
get the data value.
Definition: cxSpaceProperty.cpp:91
cx::SpaceProperty::getDisplayName
virtual QString getDisplayName() const
name of data entity. Used for display to user.
Definition: cxSpaceProperty.cpp:66
cx::SpaceProperty::valueWasSet
void valueWasSet()
cx::XmlOptionItem
Helper class for storing one string value in an xml document.
Definition: cxXmlOptionItem.h:38
cx::SpaceProperty::getUid
virtual QString getUid() const
Definition: cxSpaceProperty.cpp:71
cxTypeConversions.h
cx::SpaceProperty::setReadOnly
void setReadOnly(bool val)
Definition: cxSpaceProperty.cpp:60
cx::CoordinateSystem::fromString
static CoordinateSystem fromString(QString text)
Definition: cxCoordinateSystemHelpers.cpp:24
cx::CoordinateSystem::toString
QString toString() const
Definition: cxCoordinateSystemHelpers.cpp:19
cx::SpaceProperty::getValueRange
virtual std::vector< Space > getValueRange() const
Definition: cxSpaceProperty.cpp:108
cx::SpacePropertyPtr
boost::shared_ptr< class SpaceProperty > SpacePropertyPtr
Definition: cxSpaceProperty.h:25
cx::SpaceProperty
Definition: cxSpaceProperty.h:30
cx::XmlOptionItem::writeValue
void writeValue(const QString &val)
Definition: cxXmlOptionItem.cpp:189
cx::SpaceProperty::getHelp
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
Definition: cxSpaceProperty.cpp:76
cx::SpaceProviderPtr
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Definition: cxLogicManager.h:23
cx::CoordinateSystem
Identification of a Coordinate system.
Definition: cxCoordinateSystemHelpers.h:31
cxSpaceProvider.h