/
ParameterPropertyManager.cpp
80 lines (67 loc) · 2.03 KB
/
ParameterPropertyManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "ParameterPropertyManager.h"
#include "qtpropertymanager.h"
#include <stdexcept>
ParameterPropertyManager::ParameterPropertyManager(QObject *parent)
: QtDoublePropertyManager(parent)
{}
/**
* Throws if property error is not set
* @param property :: Property to get error for
* @return Error value of the property
*/
double ParameterPropertyManager::error(const QtProperty* property) const
{
// Cast for searching purposes
auto prop = const_cast<QtProperty*>(property);
if (!m_errors.contains(prop))
throw std::runtime_error("Parameter doesn't have error value set");
return m_errors[prop];
}
/**
* @param property :: Property to check
* @return True if error was set for the property, false otherwise
*/
bool ParameterPropertyManager::isErrorSet(const QtProperty* property) const
{
// Cast for searching purposes
auto prop = const_cast<QtProperty*>(property);
return m_errors.contains(prop);
}
/**
* @param property :: Property to set error for
* @param error :: Error value to set
*/
void ParameterPropertyManager::setError(QtProperty* property, double error)
{
m_errors[property] = error;
emit propertyChanged(property);
}
/**
* Clears error of the property, if one was set. If error was not set, the function does nothing.
* @param property :: Property to clear error for
*/
void ParameterPropertyManager::clearError(QtProperty* property)
{
m_errors.remove(property);
}
/**
* Adds error parameter value to property display
* @param property :: Property we want to display
* @return Text representation of the property
* @see QtAbstractPropertyManager
*/
QString ParameterPropertyManager::valueText(const QtProperty* property) const
{
QString originalValueText = QtDoublePropertyManager::valueText(property);
if (isErrorSet(property))
{
double propError = error(property);
int precision = decimals(property);
return originalValueText + QString(" (%1)").arg(propError, 0, 'g', precision);
}
else
{
// No error set, so don't append error value
return originalValueText;
}
}