blob: f129c8de1c3039b0d59b3f5c6ad7016f26cebcac (
plain)
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
|
#include "PropertyAddState.h"
#include "timeperiod.h"
#include <QDateTime>
#include <QDebug>
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<TimePeriod>(toAdd);
break;
case QVariant::Time:
result = current.toTime() + qvariant_cast<TimePeriod>(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;
const char *propertyName = propertyAdder.propertyName;
QVariant toAdd = propertyAdder.valueToAdd;
QVariant current = object->property(propertyName);
object->setProperty(propertyName, addProperties(current, toAdd));
}
}
|