Skip to content
Snippets Groups Projects
Commit d996b9a7 authored by Raquel Alvarez's avatar Raquel Alvarez
Browse files

Merge pull request #13935 from mantidproject/feature/13925_AlgorithmProxy_possible_bug

Ensure AlgorithmProxy keeps everything up to date with CopyPropertiesfrom
parents 6ff86a4f 2a2c3180
No related branches found
No related tags found
No related merge requests found
...@@ -116,6 +116,8 @@ public: ...@@ -116,6 +116,8 @@ public:
void setPropertyValue(const std::string &name, const std::string &value); void setPropertyValue(const std::string &name, const std::string &value);
/// Do something after a property was set /// Do something after a property was set
void afterPropertySet(const std::string &); void afterPropertySet(const std::string &);
/// Make m_properties point to the same PropertyManager as po.
void copyPropertiesFrom(const PropertyManagerOwner &po);
//@} //@}
void cancel(); void cancel();
......
...@@ -218,6 +218,17 @@ void AlgorithmProxy::afterPropertySet(const std::string &name) { ...@@ -218,6 +218,17 @@ void AlgorithmProxy::afterPropertySet(const std::string &name) {
copyPropertiesFrom(*m_alg); copyPropertiesFrom(*m_alg);
} }
/**
* Copy properties from another property manager
* Making sure that the concrete alg is kept in sync
* @param po :: The property manager to copy
*/
void AlgorithmProxy::copyPropertiesFrom(const PropertyManagerOwner &po) {
PropertyManagerOwner::copyPropertiesFrom(po);
createConcreteAlg(true);
m_alg->copyPropertiesFrom(*this);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Private methods // Private methods
//---------------------------------------------------------------------- //----------------------------------------------------------------------
......
...@@ -212,6 +212,30 @@ public: ...@@ -212,6 +212,30 @@ public:
} }
TS_ASSERT_EQUALS("InputWorkspace", alg->workspaceMethodInputProperty()); TS_ASSERT_EQUALS("InputWorkspace", alg->workspaceMethodInputProperty());
} }
void test_copyPropertiesFrom() {
IAlgorithm_sptr alg =
AlgorithmManager::Instance().create("ToyAlgorithmProxy");
alg->initialize();
alg->setPropertyValue("prop1", "string");
alg->setPropertyValue("prop2", "1");
IAlgorithm_sptr algCopy =
AlgorithmManager::Instance().create("ToyAlgorithmProxy");
auto algProxy = boost::dynamic_pointer_cast<AlgorithmProxy>(alg);
auto algCopyProxy = boost::dynamic_pointer_cast<AlgorithmProxy>(algCopy);
algCopyProxy->copyPropertiesFrom(*algProxy);
int val = boost::lexical_cast<int>(algCopy->getPropertyValue("prop2"));
TS_ASSERT_EQUALS(val, 1);
// set another value and check the other value is unaffected
algCopy->setPropertyValue("prop1", "A difference");
int val2 = boost::lexical_cast<int>(algCopy->getPropertyValue("prop2"));
TS_ASSERT_EQUALS(val, val2);
}
}; };
#endif /*ALGORITHMPROXYTEST_H_*/ #endif /*ALGORITHMPROXYTEST_H_*/
...@@ -65,7 +65,9 @@ public: ...@@ -65,7 +65,9 @@ public:
void setPropertyOrdinal(const int &index, const std::string &value); void setPropertyOrdinal(const int &index, const std::string &value);
/// Make m_properties point to the same PropertyManager as po. /// Make m_properties point to the same PropertyManager as po.
void copyPropertiesFrom(const PropertyManagerOwner &po) { *this = po; } virtual void copyPropertiesFrom(const PropertyManagerOwner &po) {
*this = po;
}
bool existsProperty(const std::string &name) const; bool existsProperty(const std::string &name) const;
bool validateProperties() const; bool validateProperties() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment