CustusX  22.04-rc5
An IGT application
cxStringListProperty.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 "cxStringListProperty.h"
13 
14 #include <iostream>
15 #include <QDomElement>
16 #include <QStringList>
17 #include "cxTypeConversions.h"
18 
19 namespace cx
20 {
21 
22 StringListProperty::StringListProperty()
23 {}
24 
25 StringListPropertyPtr StringListProperty::initialize(const QString& uid, QString name, QString help, QStringList value, QStringList range, QDomNode root)
26 {
28  retval->mUid = uid;
29  retval->mName = name.isEmpty() ? uid : name;
30  retval->mHelp = help;
31  retval->mStore = XmlOptionItem(uid, root.toElement());
32  retval->mValue = retval->mStore.readVariant(value).value<QStringList>();
33  retval->mRange = range;
34  return retval;
35 }
36 
38 {
39  mName = val;
40  emit changed();
41 }
42 
44 {
45  return mName;
46 }
47 
49 {
50  return mUid;
51 }
52 
54 {
55  return mHelp;
56 }
57 
58 void StringListProperty::setHelp(QString val)
59 {
60  if (val == mHelp)
61  return;
62 
63  mHelp = val;
64  emit changed();
65 }
66 
68 {
69  return this->getValue();
70 }
71 
73 {
74  this->setValue(val.value<QStringList>());
75 }
76 
77 
78 QStringList StringListProperty::getValue() const
79 {
80  return mValue;
81 }
82 
83 bool StringListProperty::setValue(const QStringList& val)
84 {
85  if (val == mValue)
86  return false;
87 
88  mValue.clear();
89  for (int i=0; i<val.size(); ++i)
90  if (mRange.contains(val[i]))
91  mValue.push_back(val[i]);
92 
93  mStore.writeVariant(mValue);
94  emit changed();
95  return true;
96 }
97 
99 {
100  return mRange;
101 }
102 
103 void StringListProperty::setValueRange(QStringList range)
104 {
105  mRange = range;
106  emit changed();
107 }
108 
113 {
114  if (mDisplayNames.count(internal))
115  return mDisplayNames[internal];
116  return internal;
117 }
118 
119 void StringListProperty::setDisplayNames(std::map<QString, QString> names)
120 {
121  mDisplayNames = names;
122  emit changed();
123 }
124 
125 } // namespace cx
126 
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
void writeVariant(const QVariant &val)
Represents one collection of strings.
virtual void setDisplayName(QString val)
static StringListPropertyPtr initialize(const QString &uid, QString name, QString help, QStringList value, QStringList range, QDomNode root=QDomNode())
virtual void setValueRange(QStringList range)
range that values can be selected from
virtual QVariant getValueAsVariant() const
Helper class for storing one string value in an xml document.
virtual void setHelp(QString val)
virtual bool setValue(const QStringList &value)
set the data value.
virtual void setDisplayNames(std::map< QString, QString > names)
virtual QStringList getValue() const
get the data value.
virtual QString convertInternal2Display(QString internal)
conversion from internal value to display value
virtual QStringList getValueRange() const
void changed()
emit when the underlying data value is changed: The user interface will be updated.
boost::shared_ptr< class StringListProperty > StringListPropertyPtr
virtual QString getDisplayName() const
name of data entity. Used for display to user.
QVariant readVariant(const QVariant &defval=QVariant()) const
virtual void setValueFromVariant(QVariant val)
virtual QString getUid() const
Namespace for all CustusX production code.