Mantid
Loading...
Searching...
No Matches
SetValueWhenProperty.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
13
14#include <boost/lexical_cast.hpp>
15#include <cassert>
16#include <exception>
17#include <stdexcept>
18
19using namespace Mantid::Kernel;
20
21namespace Mantid::Kernel {
22
32 // Find the property
33 if (algo == nullptr)
34 throw std::runtime_error("Algorithm properties passed to SetValueWhenProperty was null");
35
36 Property *prop = nullptr;
37 try {
39 } catch (Exception::NotFoundError &) {
40 prop = nullptr; // Ensure we still have null pointer
41 }
42 if (!prop)
43 throw std::runtime_error("Property " + m_watchedPropName + " was not found in SetValueWhenProperty");
44 return prop->value();
45}
46
55bool SetValueWhenProperty::isConditionChanged(const IPropertyManager *algo, const std::string &changedPropName) const {
56 auto watchedProp = algo->getPointerToProperty(m_watchedPropName);
57 bool hasWatchedPropChanged = false;
58 if (watchedProp->name() == changedPropName) {
59 hasWatchedPropChanged = true;
60 }
61
62 return hasWatchedPropChanged;
63}
64
65void SetValueWhenProperty::applyChanges(const IPropertyManager *algo, Kernel::Property *const currentProperty) {
66 const std::string watchedPropertyValue = getPropertyValue(algo);
67
68 std::string newValue = m_changeCriterion(currentProperty->value(), watchedPropertyValue);
69 currentProperty->setValue(newValue);
70}
71
74
76
77} // namespace Mantid::Kernel
Exception for when an item is not found in a collection.
Definition: Exception.h:145
Interface to PropertyManager.
virtual Property * getPointerToProperty(const std::string &name) const =0
Get a pointer to property by name.
Interface for modifiers to Property's that specify if they should be enabled or visible in a GUI.
Base class for properties.
Definition: Property.h:94
virtual std::string setValue(const std::string &)=0
Set the value of the property via a string.
virtual std::string value() const =0
Returns the value of the property as a string.
bool isConditionChanged(const IPropertyManager *algo, const std::string &changedPropName) const override
Return true always.
void applyChanges(const Mantid::Kernel::IPropertyManager *algo, Kernel::Property *const pProp) override
If a new value should be set, the change is applied here.
std::string getPropertyValue(const IPropertyManager *algo) const
Checks the algorithm and property are both valid and attempts to get the value associated with the pr...
std::function< std::string(std::string, std::string)> m_changeCriterion
Function to check if changes should be applied.
std::string m_watchedPropName
Name of the watched property, based on which we may set the value of the current property.
IPropertySettings * clone() const override
Make a copy of the present type of IPropertySettings.
void modify_allowed_values(Property *const)
Stub function to satisfy the interface.