Fraxinus  16.5.0-fx-rc8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxStringListProperty.h"
34 
35 #include <iostream>
36 #include <QDomElement>
37 #include <QStringList>
38 #include "cxTypeConversions.h"
39 
40 namespace cx
41 {
42 
43 StringListProperty::StringListProperty()
44 {}
45 
46 StringListPropertyPtr StringListProperty::initialize(const QString& uid, QString name, QString help, QStringList value, QStringList range, QDomNode root)
47 {
49  retval->mUid = uid;
50  retval->mName = name.isEmpty() ? uid : name;
51  retval->mHelp = help;
52  retval->mStore = XmlOptionItem(uid, root.toElement());
53  retval->mValue = retval->mStore.readVariant(value).value<QStringList>();
54  retval->mRange = range;
55  return retval;
56 }
57 
59 {
60  mName = val;
61  emit changed();
62 }
63 
65 {
66  return mName;
67 }
68 
70 {
71  return mUid;
72 }
73 
75 {
76  return mHelp;
77 }
78 
79 void StringListProperty::setHelp(QString val)
80 {
81  if (val == mHelp)
82  return;
83 
84  mHelp = val;
85  emit changed();
86 }
87 
89 {
90  return this->getValue();
91 }
92 
94 {
95  this->setValue(val.value<QStringList>());
96 }
97 
98 
99 QStringList StringListProperty::getValue() const
100 {
101  return mValue;
102 }
103 
104 bool StringListProperty::setValue(const QStringList& val)
105 {
106  if (val == mValue)
107  return false;
108 
109  mValue.clear();
110  for (int i=0; i<val.size(); ++i)
111  if (mRange.contains(val[i]))
112  mValue.push_back(val[i]);
113 
114  mStore.writeVariant(mValue);
115  emit changed();
116  return true;
117 }
118 
120 {
121  return mRange;
122 }
123 
124 void StringListProperty::setValueRange(QStringList range)
125 {
126  mRange = range;
127  emit changed();
128 }
129 
134 {
135  if (mDisplayNames.count(internal))
136  return mDisplayNames[internal];
137  return internal;
138 }
139 
140 void StringListProperty::setDisplayNames(std::map<QString, QString> names)
141 {
142  mDisplayNames = names;
143  emit changed();
144 }
145 
146 } // namespace cx
147 
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