Fraxinus  16.5.0-fx-rc1
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 "cxStringProperty.h"
34 
35 #include <iostream>
36 #include <QDomElement>
37 #include <QStringList>
38 #include "cxTypeConversions.h"
39 
40 namespace cx
41 {
42 
43 StringProperty::StringProperty() :
44  mIsReadOnly(false)
45 {}
46 
50 StringPropertyPtr StringProperty::initialize(const QString& uid, QString name, QString help, QString value, QStringList range, QDomNode root)
51 {
52  StringPropertyPtr retval = initialize(uid, name, help, value, root);
53  retval->mRange = range;
54  retval->mAllowOnlyValuesInRange = true;
55  return retval;
56 }
57 
58 StringPropertyPtr StringProperty::initialize(const QString& uid, QString name, QString help, QString value, QDomNode root)
59 {
60  StringPropertyPtr retval(new StringProperty());
61  retval->mUid = uid;
62  retval->mName = name.isEmpty() ? uid : name;
63  retval->mHelp = help;
64  retval->mStore = XmlOptionItem(uid, root.toElement());
65  retval->mValue = retval->mStore.readValue(value);
66  retval->mAllowOnlyValuesInRange = false;
67  return retval;
68 }
69 
71 {
72  mIsReadOnly = val;
73  emit changed();
74 }
75 
77 {
78  mName = val;
79  emit changed();
80 }
81 
82 
84 {
85  return mName;
86 }
87 
88 QString StringProperty::getUid() const
89 {
90  return mUid;
91 }
92 
93 QString StringProperty::getHelp() const
94 {
95  return mHelp;
96 }
97 
98 void StringProperty::setHelp(QString val)
99 {
100  if (val == mHelp)
101  return;
102 
103  mHelp = val;
104  emit changed();
105 }
106 
107 
109 {
110  return mValue;
111 }
112 
113 bool StringProperty::setValue(const QString& val)
114 {
115  if (val == mValue)
116  return false;
117 
118  mValue = val;
119  mStore.writeValue(val);
120  emit valueWasSet();
121  emit changed();
122  return true;
123 }
124 
125 QStringList StringProperty::getValueRange() const
126 {
127  return mRange;
128 }
129 
130 void StringProperty::setValueRange(QStringList range)
131 {
132  mRange = range;
133  emit changed();
134 }
135 
140 {
141  if (mDisplayNames.count(internal))
142  return mDisplayNames[internal];
143  return internal;
144 }
145 
146 void StringProperty::setDisplayNames(std::map<QString, QString> names)
147 {
148  mDisplayNames = names;
149  emit changed();
150 }
151 
152 } // 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)
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