Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxDoubleProperty.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 
13 #include "cxDoubleProperty.h"
14 
15 #include <iostream>
16 #include <QDomElement>
17 #include <QStringList>
18 
19 
20 namespace cx
21 {
22 DoubleProperty::DoubleProperty()
23 {
24  mFactor = 1.0;
25 }
26 
30 DoublePropertyPtr DoubleProperty::initialize(const QString& uid, QString name, QString help, double value,
31  DoubleRange range, int decimals, QDomNode root)
32 {
33  DoublePropertyPtr retval(new DoubleProperty());
34  retval->mUid = uid;
35  retval->mName = name.isEmpty() ? uid : name;
36  retval->mHelp = help;
37  retval->mRange = range;
38  retval->mStore = XmlOptionItem(uid, root.toElement());
39  retval->mValue = retval->mStore.readValue(QString::number(value)).toDouble();
40  retval->mDecimals = decimals;
41  return retval;
42 }
43 
45 {
46  mFactor = factor;
47 }
48 
50 {
51  return mName;
52 }
53 
54 QString DoubleProperty::getUid() const
55 {
56  return mUid;
57 }
58 
59 QString DoubleProperty::getHelp() const
60 {
61  return mHelp;
62 }
63 
65 {
66  return mValue;
67 }
68 
69 bool DoubleProperty::setValue(double val)
70 {
71  if (val == mValue)
72  return false;
73 
74  mValue = val;
75  mStore.writeValue(QString::number(val));
76  emit valueWasSet();
77  emit changed();
78  return true;
79 }
80 
82 {
83  return mRange;
84 }
85 
87 {
88  mRange = range;
89  emit changed();
90 }
91 
93 {
94  return mDecimals;
95 }
96 
97 } // namespace cx
virtual DoubleRange getValueRange() const
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
Helper class for storing one string value in an xml document.
virtual void setValueRange(DoubleRange range)
range of value. Use if data is constrained to a set.
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
void writeValue(const QString &val)
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
virtual double getValue() const
get the data value.
virtual bool setValue(double value)
set the data value.
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
void setInternal2Display(double factor)
virtual QString getUid() const
virtual int getValueDecimals() const
number of relevant decimals in value
QString readValue(const QString &defval) const
virtual QString getDisplayName() const
name of data entity. Used for display to user.
Namespace for all CustusX production code.