23#include "KPropertyFactory.h" 
   24#include "KPropertyListData.h" 
   25#include "KPropertySet_p.h" 
   26#include "KProperty_p.h" 
   27#include "kproperty_debug.h" 
   32static bool compatibleTypes(
const QVariant& currentValue, 
const QVariant &value)
 
   54KProperty::Private::Private(
KProperty *prop)
 
   55        : q(prop), 
type(
KProperty::Auto), listData(nullptr), changed(false), storable(true),
 
   56        readOnly(false), visible(true),
 
   57        composed(nullptr), useComposedProperty(true),
 
   58        sets(nullptr), parent(nullptr), children(nullptr), relatedProperties(nullptr)
 
   62void KProperty::Private::setCaptionForDisplaying(
const QString& captionForDisplaying)
 
   65    if (caption == captionForDisplaying) {
 
   68    this->captionForDisplaying = captionForDisplaying;
 
   71KProperty::Private::~Private()
 
   75        qDeleteAll(*children);
 
   78    delete relatedProperties;
 
   83bool KProperty::Private::valueDiffersInternal(
const QVariant &otherValue, KProperty::ValueOptions options)
 
   85    if (!compatibleTypes(value, otherValue)) {
 
   86        kprWarning() << 
"INCOMPATIBLE TYPES! old=" << value << 
"new=" << otherValue << 
"in property" << q->name();
 
  106        const double factor = pow(10.0, option(
"precision", KPROPERTY_DEFAULT_DOUBLE_VALUE_PRECISION).toDouble());
 
  111        return static_cast<qlonglong
>(value.
toDouble() * factor) != 
static_cast<qlonglong
>(otherValue.
toDouble() * factor);
 
  114    } 
else if (composed && !(options & ValueOption::IgnoreComposedProperty)) {
 
  115        return !composed->valuesEqual(value, otherValue);
 
  118        return value != otherValue;
 
  122bool KProperty::Private::setValueInternal(
const QVariant &newValue, KProperty::ValueOptions valueOptions)
 
  125        kprWarning() << 
"COULD NOT SET value to a null property";
 
  130    if (!valueDiffersInternal(newValue, valueOptions)) {
 
  145        parent->d->childValueChanged(q, newValue, valueOptions);
 
  149    if (composed && useComposedProperty) {
 
  151        composed->setChildValueChangedEnabled(
false);
 
  153            q, newValue, valueOptions | ValueOption::IgnoreComposedProperty 
 
  155        composed->setChildValueChangedEnabled(
true);
 
  164        emitPropertyChanged(); 
 
  169void KProperty::Private::addChild(
KProperty *prop)
 
  175    if (!children || std::find(children->begin(), children->end(), prop) == children->end()) { 
 
  179        children->append(prop);
 
  182        kprWarning() << 
"property" << 
name 
  183                   << 
": child property" << prop->
name() << 
"already added";
 
  198    if (set == newSet || (sets && sets->contains(newSet))) {
 
  207void KProperty::Private::addRelatedProperty(
KProperty *property)
 
  209    if (!relatedProperties)
 
  212    if (!relatedProperties->contains(property)) {
 
  213        relatedProperties->append(property);
 
  217void KProperty::Private::emitPropertyChanged()
 
  224        realSets = parent->d->sets;
 
  229                emit s->propertyChangedInternal(*s, *q);
 
  230                emit s->propertyChanged(*s, *q);
 
  240            realSet = parent->d->set;
 
  249            emit realSet->propertyChangedInternal(*realSet, *q);
 
  250            emit realSet->propertyChanged(*realSet, *q);
 
  255void KProperty::Private::childValueChanged(
KProperty *child, 
const QVariant &value,
 
  256                                           KProperty::ValueOptions valueOptions)
 
  261    composed->childValueChangedInternal(
 
  275    d->setCaptionForDisplaying(
caption);
 
  278    if (
type == 
int(Auto)) {
 
  284        parent->d->addChild(
this);
 
 
  294    d->setCaptionForDisplaying(
caption);
 
  297    if (
type == 
int(Auto)) {
 
  303        parent->d->addChild(
this);
 
 
  318KProperty::~KProperty()
 
  338    return d->caption.
isEmpty() ? d->captionForDisplaying : d->caption;
 
 
  344    return d->captionForDisplaying;
 
 
  350    d->setCaptionForDisplaying(
caption);
 
 
  356    return d->description;
 
 
  362    d->description = desc;
 
 
  374    if (d->type != 
type) {
 
  377        d->composed = KPropertyFactoryManager::self()->createComposedProperty(
this);
 
 
  407    return d->setValueInternal(
value, options);
 
 
  413    Q_UNUSED(doNotUseThisOverload);
 
  414    Q_UNUSED(doNotUseThisOverload2);
 
  419    return !d->valueDiffersInternal(
value, valueOptions);
 
 
  429    bool cleared = 
false;
 
  431        KPropertySetPrivate::d(d->set)->informAboutClearing(&cleared); 
 
  438    if (d->parent && d->parent->value() == d->parent->oldValue())
 
  439        d->parent->d->changed = 
false;
 
  444                emit set->propertyReset(*set, *
this);
 
  447        emit d->set->propertyReset(*d->set, *
this);
 
 
  459    if (list == d->listData)
 
 
  477    return d->name.isEmpty();
 
 
  487        for (
const KProperty* p : *d->children) {
 
 
  516    d->readOnly = readOnly;
 
 
  528    d->visible = visible;
 
 
  533    return d->valueSyncPolicy;
 
 
  539    d->valueSyncPolicy = policy;
 
 
  551    d->storable = storable;
 
 
  558        d->options.remove(
name);
 
  560        d->options[
name] = val;
 
 
  566    return d->option(
name, defaultValue);
 
 
  572    return !d->options.isEmpty() || (d->parent && d->parent->hasOptions());
 
 
  587    if (&property == 
this)
 
  591    d->listData = 
nullptr;
 
  593    d->children = 
nullptr;
 
  594    delete d->relatedProperties;
 
  595    d->relatedProperties = 
nullptr;
 
  597    d->composed = 
nullptr;
 
  599    d->name = 
property.d->name;
 
  601    d->description = 
property.d->description;
 
  602    d->type = 
property.d->type;
 
  604    d->iconName = 
property.d->iconName;
 
  605    d->valueSyncPolicy = 
property.d->valueSyncPolicy;
 
  606    d->visible = 
property.d->visible;
 
  607    d->storable = 
property.d->storable;
 
  608    d->readOnly = 
property.d->readOnly;
 
  609    d->options = 
property.d->options;
 
  611    if (property.d->listData) {
 
  614    if (property.d->composed) {
 
  616        d->composed = KPropertyFactoryManager::self()->createComposedProperty(
this);
 
  620        d->value = 
property.d->value;
 
  621        if (property.d->children) {
 
  632    if (property.d->relatedProperties) {
 
  637    d->oldValue = 
property.d->oldValue;
 
  638    d->changed = 
property.d->changed;
 
 
  645    return ((d->name == prop.d->name) && (
value() == prop.
value()));
 
 
  666        if ((*it)->name() == 
name)
 
 
  686    if (d->composed == prop)
 
 
  693int Property::sortingKey()
 const 
  695    return d->sortingKey;
 
  698void Property::setSortingKey(
int key)
 
  709        << 
"NAME=" << p.
name();
 
  724        dbg.
nospace() << 
" VALUE=<INVALID>";
 
  739        dbg.
nospace() << 
" OPTIONS(" << p.d->options.count() << 
"): [";
 
  741        std::sort(optionKeys.
begin(), optionKeys.
end());
 
 
An interface for for composed property handlers.
 
A data container for properties of list type.
 
The base class representing a single property.
 
QVariant option(const char *name, const QVariant &defaultValue=QVariant()) const
Returns value of given option Option is set if returned value is not null. If there is no option for ...
 
void setName(const QByteArray &name)
Sets name of the property.
 
KProperty()
Constructs a null property.
 
bool operator==(const KProperty &prop) const
 
void setVisible(bool visible)
 
KProperty & operator=(const QVariant &val)
 
KProperty * child(const QByteArray &name)
 
friend KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KProperty &p)
qDebug() stream operator. Writes property p to the debug output in a nicely formatted way.
 
ValueSyncPolicy
Synchronization policy for property values.
 
KComposedPropertyInterface * composedProperty() const
 
void setDescription(const QString &description)
 
bool hasOptions() const
Returns true if at least one option is specified for this property If there are no options defined tr...
 
void setValueSyncPolicy(ValueSyncPolicy policy)
Sets synchronization policy for property values of this property See ValueSyncPolicy for details.
 
QString description() const
 
QString captionForDisplaying() const
 
void setIconName(const QString &name)
 
bool isModified() const
Return true if value of this property or value of any child property is modified.
 
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
Sets value of the property.
 
void setStorable(bool storable)
 
KPropertyListData * listData() const
 
@ IgnoreOld
Do not remember the old value before setting a new one.
 
@ IgnoreComposedProperty
Do not use composed property when comparing values.
 
void setReadOnly(bool readOnly)
 
void setListData(KPropertyListData *list)
 
const QList< KProperty * > * children() const
 
bool operator!=(const KProperty &prop) const
 
ValueSyncPolicy valueSyncPolicy() const
 
void setOption(const char *name, const QVariant &val)
 
void setCaption(const QString &caption)
 
void setComposedProperty(KComposedPropertyInterface *prop)
 
QVariant oldValue() const
 
bool valueEqualsTo(const QVariant &value, ValueOptions valueOptions=ValueOptions()) const
 
void clearModifiedFlag()
Clears the "modified" flag for this property and all its child properties.
 
KProperty * parent() const
 
Type type(const QSqlDatabase &db)
 
QString name(StandardAction id)
 
const char * constData() const const
 
bool isNull() const const
 
bool isEmpty() const const
 
QString simplified() const const
 
bool isNull() const const
 
bool isValid() const const
 
void setValue(QVariant &&value)
 
double toDouble(bool *ok) const const
 
QString toString() const const