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