CustusX  15.4.0-beta
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() : mIsReadOnly(false)
44 {
45 
46 }
47 
51 StringPropertyPtr StringProperty::initialize(const QString& uid, QString name, QString help, QString value, QStringList range, QDomNode root)
52 {
53  StringPropertyPtr retval(new StringProperty());
54  retval->mUid = uid;
55  retval->mName = name.isEmpty() ? uid : name;
56  retval->mHelp = help;
57  retval->mRange = range;
58  retval->mStore = XmlOptionItem(uid, root.toElement());
59  retval->mValue = retval->mStore.readValue(value);
60  retval->mAllowOnlyValuesInRange = true;
61  return retval;
62 }
63 
64 StringPropertyPtr StringProperty::initialize(const QString& uid, QString name, QString help, QString value, QDomNode root)
65 {
66  StringPropertyPtr retval(new StringProperty());
67  retval->mUid = uid;
68  retval->mName = name.isEmpty() ? uid : name;
69  retval->mHelp = help;
70  //retval->mRange = range;
71  retval->mStore = XmlOptionItem(uid, root.toElement());
72  retval->mValue = retval->mStore.readValue(value);
73  retval->mAllowOnlyValuesInRange = false;
74  return retval;
75 }
76 
77 void StringProperty::setReadOnly(bool val)
78 {
79  mIsReadOnly = val;
80  emit changed();
81 }
82 
83 QString StringProperty::getDisplayName() const
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 
108 QString StringProperty::getValue() const
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 
139 QString StringProperty::convertInternal2Display(QString internal)
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
Helper class for storing one string value in an xml document.
boost::shared_ptr< class StringProperty > StringPropertyPtr
Represents one option of the string type. The data are stored within a xml document.
QString readValue(const QString &defval) const