Fraxinus  2023.01.05-dev+develop.0da12
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
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 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.
Namespace for all CustusX production code.