NorMIT-nav  22.09
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
cx::DoubleProperty::valueWasSet
void valueWasSet()
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::DoubleProperty::getValueRange
virtual DoubleRange getValueRange() const
Definition: cxDoubleProperty.cpp:81
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cx::DoubleProperty::setValueRange
virtual void setValueRange(DoubleRange range)
range of value. Use if data is constrained to a set.
Definition: cxDoubleProperty.cpp:86
cx::DoubleProperty::getValue
virtual double getValue() const
get the data value.
Definition: cxDoubleProperty.cpp:64
cx::DoubleProperty::getValueDecimals
virtual int getValueDecimals() const
number of relevant decimals in value
Definition: cxDoubleProperty.cpp:92
cxDoubleProperty.h
cx::DoubleProperty
Definition: cxDoubleProperty.h:48
cx::DoubleProperty::setValue
virtual bool setValue(double value)
set the data value.
Definition: cxDoubleProperty.cpp:69
cx::DoubleProperty::setInternal2Display
void setInternal2Display(double factor)
Definition: cxDoubleProperty.cpp:44
cx::DoubleProperty::initialize
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
Definition: cxDoubleProperty.cpp:30
cx::DoublePropertyPtr
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
Definition: cxReconstructionMethodService.h:33
cx::XmlOptionItem
Helper class for storing one string value in an xml document.
Definition: cxXmlOptionItem.h:38
cx::DoubleProperty::getHelp
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
Definition: cxDoubleProperty.cpp:59
cx::XmlOptionItem::writeValue
void writeValue(const QString &val)
Definition: cxXmlOptionItem.cpp:189
cx::DoubleRange
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
cx::DoubleProperty::getDisplayName
virtual QString getDisplayName() const
name of data entity. Used for display to user.
Definition: cxDoubleProperty.cpp:49
cx::DoubleProperty::getUid
virtual QString getUid() const
Definition: cxDoubleProperty.cpp:54