public:
PropertyTemplate (PropertyDescriptor<T> p, T const& v)
: PropertyBase (p.property_id)
+ , _have_old (false)
, _current (v)
{}
return _current;
}
- /** If this property has been changed since the last clear_history() call
- (or its construction), add an (XML) property describing the old value
- to the XMLNode @param old and another describing the current value to
- the XMLNode @param current.
- */
+ void clear_history () {
+ _have_old = false;
+ }
+
void add_history_state (XMLNode* history_node) const {
+ /* We can get to the current state of a scalar property like this one simply
+ by knowing what the new state is.
+ */
history_node->add_property (property_name(), to_string (_current));
}
owner_state.add_property (property_name(), to_string (_current));
}
+ bool changed () const { return _have_old; }
+ void set_state_from_property (PropertyBase const * p) {
+ T v = dynamic_cast<const PropertyTemplate<T>* > (p)->val ();
+ if (v != _current) {
+ set (v);
+ }
+ }
+
protected:
/** Constructs a PropertyTemplate with a default
value for _old and _current.
virtual std::string to_string (T const& v) const = 0;
virtual T from_string (std::string const& s) const = 0;
+ bool _have_old;
T _current;
T _old;
};
: PropertyTemplate<T> (q, v)
{}
- void diff (PropertyList& before, PropertyList& after) const {
+ void diff (PropertyList& undo, PropertyList& redo) const {
if (this->_have_old) {
- before.add (new Property<T> (this->property_id(), this->_old));
- after.add (new Property<T> (this->property_id(), this->_current));
+ undo.add (new Property<T> (this->property_id(), this->_old));
+ redo.add (new Property<T> (this->property_id(), this->_current));
}
}