NorMIT-nav  2023.01.05-dev+develop.0da12
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 
cx::XmlOptionItem::writeVariant
void writeVariant(const QVariant &val)
Definition: cxXmlOptionItem.cpp:172
cxStringListProperty.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::StringListProperty::getValueRange
virtual QStringList getValueRange() const
Definition: cxStringListProperty.cpp:98
cx::StringListProperty::setValueRange
virtual void setValueRange(QStringList range)
range that values can be selected from
Definition: cxStringListProperty.cpp:103
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cx::StringListProperty
Represents one collection of strings.
Definition: cxStringListProperty.h:35
cx::StringListProperty::getValue
virtual QStringList getValue() const
get the data value.
Definition: cxStringListProperty.cpp:78
cx::StringListProperty::convertInternal2Display
virtual QString convertInternal2Display(QString internal)
conversion from internal value to display value
Definition: cxStringListProperty.cpp:112
cx::StringListProperty::initialize
static StringListPropertyPtr initialize(const QString &uid, QString name, QString help, QStringList value, QStringList range, QDomNode root=QDomNode())
Definition: cxStringListProperty.cpp:25
cx::StringListProperty::setDisplayNames
virtual void setDisplayNames(std::map< QString, QString > names)
Definition: cxStringListProperty.cpp:119
cx::StringListProperty::getValueAsVariant
virtual QVariant getValueAsVariant() const
Definition: cxStringListProperty.cpp:67
cx::StringListProperty::getDisplayName
virtual QString getDisplayName() const
name of data entity. Used for display to user.
Definition: cxStringListProperty.cpp:43
cx::StringListProperty::setValueFromVariant
virtual void setValueFromVariant(QVariant val)
Definition: cxStringListProperty.cpp:72
cx::XmlOptionItem
Helper class for storing one string value in an xml document.
Definition: cxXmlOptionItem.h:38
cx::StringListProperty::getUid
virtual QString getUid() const
Definition: cxStringListProperty.cpp:48
cxTypeConversions.h
cx::StringListPropertyPtr
boost::shared_ptr< class StringListProperty > StringListPropertyPtr
Definition: cxTreeItemModel.h:21
cx::StringListProperty::getHelp
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
Definition: cxStringListProperty.cpp:53
cx::StringListProperty::setHelp
virtual void setHelp(QString val)
Definition: cxStringListProperty.cpp:58
cx::StringListProperty::setValue
virtual bool setValue(const QStringList &value)
set the data value.
Definition: cxStringListProperty.cpp:83
cx::StringListProperty::setDisplayName
virtual void setDisplayName(QString val)
Definition: cxStringListProperty.cpp:37