CustusX  22.04-rc5
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
virtual QString convertInternal2Display(QString internal)
conversion from internal value to display value
virtual bool setValue(const QString &value)
set the data value.
virtual void setDisplayName(QString val)
static StringListPropertyPtr initialize(const QString &uid, QString name, QString help, QStringList value, QStringList range, QDomNode root=QDomNode())
Helper class for storing one string value in an xml document.
boost::shared_ptr< class StringProperty > StringPropertyPtr
virtual void setValueRange(QStringList range)
range of value. Use if data is constrained to a set.
virtual QString getUid() const
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual void setHelp(QString val)
Represents one option of the string type. The data are stored within a xml document.
virtual QStringList getValueRange() const
void changed()
emit when the underlying data value is changed: The user interface will be updated.
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
void writeValue(const QString &val)
virtual QString getDisplayName() const
name of data entity. Used for display to user.
void setReadOnly(bool val)
virtual void setDisplayNames(std::map< QString, QString > names)
virtual QString getValue() const
get the data value.
QString readValue(const QString &defval) const
Namespace for all CustusX production code.