#include "PropertyAddState.h" #include "timeperiod.h" #include #include PropertyAddState::PropertyAddState(QState *parent) : QState(parent) { } void PropertyAddState::addToProperty(QObject *object, const char *propertyName, const QVariant &valueToAdd) { m_propertyAdditions.append(PropertyAdder(object, propertyName, valueToAdd)); } QVariant PropertyAddState::addProperties(const QVariant ¤t, const QVariant &toAdd) const { QVariant result; switch (current.type()) { case QVariant::DateTime: result = current.toDateTime() + qvariant_cast(toAdd); break; case QVariant::Time: result = current.toTime() + qvariant_cast(toAdd); break; default: qWarning("PropertyAddState::addProperties: QVariant type '%s' not supported", current.typeName()); }; return result; } void PropertyAddState::onEntry() { foreach (PropertyAdder propertyAdder, m_propertyAdditions) { QObject *object = propertyAdder.object; QByteArray propertyName = propertyAdder.propertyName; QVariant toAdd = propertyAdder.valueToAdd; QVariant current = object->property(propertyName); object->setProperty(propertyName, addProperties(current, toAdd)); } }