CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxColorProperty.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 "cxColorProperty.h"
14 #include "cxVector3D.h"
15 #include "cxTypeConversions.h"
16 
17 
18 namespace cx
19 {
20 
24 ColorPropertyPtr ColorProperty::initialize(const QString& uid, QString name, QString help, QColor value,
25  QDomNode root)
26 {
27  ColorPropertyPtr retval(new ColorProperty());
28  retval->mUid = uid;
29  retval->mName = name.isEmpty() ? uid : name;
30  retval->mHelp = help;
31  retval->mStore = XmlOptionItem(uid, root.toElement());
32  retval->mValue = string2color(retval->mStore.readValue(color2string(value)));
33  return retval;
34 }
35 
37 {
38  return mName;
39 }
40 
41 QString ColorProperty::getUid() const
42 {
43  return mUid;
44 }
45 
46 QString ColorProperty::getHelp() const
47 {
48  return mHelp;
49 }
50 
52 {
53  return mValue;
54 }
55 
56 bool ColorProperty::setValue(QColor val)
57 {
58  if (val == mValue)
59  return false;
60 
61  mValue = val;
62  mStore.writeValue(color2string(val));
63  emit valueWasSet();
64  emit changed();
65  return true;
66 }
67 
68 } // namespace cx
69 
QColor string2color(QString input, QColor defaultValue)
boost::shared_ptr< class ColorProperty > ColorPropertyPtr
QString color2string(QColor color)
virtual QString getUid() const
virtual bool setValue(QColor value)
set the data value.
Helper class for storing one string value in an xml document.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
void writeValue(const QString &val)
virtual QColor getValue() const
get the data value.
static ColorPropertyPtr initialize(const QString &uid, QString name, QString help, QColor value, QDomNode root=QDomNode())
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
Namespace for all CustusX production code.