|
| 1 | +#include "PropertyContext.h" |
| 2 | +#include "PropertyContext_p.h" |
| 3 | + |
| 4 | +#include "PropertyGrid.h" |
| 5 | + |
| 6 | +using namespace PM; |
| 7 | + |
| 8 | +PropertyContext &PropertyContextPrivate::invalidContext() |
| 9 | +{ |
| 10 | + static PropertyContext result; |
| 11 | + |
| 12 | + return result; |
| 13 | +} |
| 14 | + |
| 15 | +PropertyContext PropertyContextPrivate::createContext(const Property &property) |
| 16 | +{ |
| 17 | + return PropertyContext(property, QVariant(), nullptr, nullptr); |
| 18 | +} |
| 19 | + |
| 20 | +PropertyContext PropertyContextPrivate::createContext(const QVariant &value, bool valid) |
| 21 | +{ |
| 22 | + PropertyContext result; |
| 23 | + result.m_value = value; |
| 24 | + result.m_isValid = valid; |
| 25 | + |
| 26 | + return result; |
| 27 | +} |
| 28 | + |
| 29 | +PropertyContext PropertyContextPrivate::createContext(const PropertyContext &other, const QVariant &newValue) |
| 30 | +{ |
| 31 | + PropertyContext result = other; |
| 32 | + result.m_value = newValue; |
| 33 | + |
| 34 | + return result; |
| 35 | +} |
| 36 | + |
| 37 | +PropertyContext PropertyContextPrivate::createContext(const Property &property, const QVariant &value, void *object, PropertyGrid *propertyGrid) |
| 38 | +{ |
| 39 | + return PropertyContext(property, value, object, propertyGrid); |
| 40 | +} |
| 41 | + |
| 42 | +void PropertyContextPrivate::setValue(PropertyContext &context, const QVariant &value) |
| 43 | +{ |
| 44 | + context.m_value = value; |
| 45 | + notifyValueChanged(context, value); |
| 46 | +} |
| 47 | + |
| 48 | +PropertyContextPrivate::valueChangedSlot_t PropertyContextPrivate::defaultValueChangedSlot() |
| 49 | +{ |
| 50 | + static valueChangedSlot_t result = [](const QVariant &) {}; |
| 51 | + |
| 52 | + return result; |
| 53 | +} |
| 54 | + |
| 55 | +void PropertyContextPrivate::disconnectValueChangedSlot(PropertyContext &context) |
| 56 | +{ |
| 57 | + context.m_valueChangedSlot = defaultValueChangedSlot(); |
| 58 | +} |
| 59 | + |
| 60 | +void PropertyContextPrivate::connectValueChangedSlot(PropertyContext &context, const valueChangedSlot_t &slot) |
| 61 | +{ |
| 62 | + context.m_valueChangedSlot = slot; |
| 63 | +} |
| 64 | + |
| 65 | +void PropertyContextPrivate::notifyValueChanged(const PropertyContext &context, const QVariant &newValue) |
| 66 | +{ |
| 67 | + context.m_valueChangedSlot(newValue); |
| 68 | +} |
| 69 | + |
| 70 | +Property PropertyContext::property() const |
| 71 | +{ |
| 72 | + return m_property; |
| 73 | +} |
| 74 | + |
| 75 | +QVariant PropertyContext::value() const |
| 76 | +{ |
| 77 | + return m_value; |
| 78 | +} |
| 79 | + |
| 80 | +bool PropertyContext::isValid() const |
| 81 | +{ |
| 82 | + return m_isValid; |
| 83 | +} |
| 84 | + |
| 85 | +PropertyGrid *PropertyContext::propertyGrid() const |
| 86 | +{ |
| 87 | + return m_propertyGrid; |
| 88 | +} |
| 89 | + |
| 90 | +PropertyContext::PropertyContext() : PropertyContext(Property(), QVariant(), nullptr, nullptr) |
| 91 | +{ |
| 92 | +} |
| 93 | + |
| 94 | +PropertyContext::PropertyContext(const Property &property, const QVariant &value, void *object, PropertyGrid *propertyGrid) : |
| 95 | + m_property(property), |
| 96 | + m_value(value), |
| 97 | + m_object(object), |
| 98 | + m_propertyGrid(propertyGrid), |
| 99 | + m_isValid(!property.name().isEmpty()), |
| 100 | + m_valueChangedSlot(PropertyContextPrivate::defaultValueChangedSlot()) |
| 101 | +{ |
| 102 | +} |
0 commit comments