Send DynamicPropertyChange event only when value is changed.

According to docs DynamicPropertyChange event should be sent from
setProperty function only when property is added, removed or
changed.

Change-Id: I080a27a4119a63580b03172f4b5b367338c6f440
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Tomasz Olszak 2014-01-08 17:12:28 +01:00 committed by The Qt Project
parent b28764c641
commit 3867bc5a10
2 changed files with 5 additions and 0 deletions

View File

@ -3809,6 +3809,8 @@ bool QObject::setProperty(const char *name, const QVariant &value)
d->extraData->propertyNames.append(name);
d->extraData->propertyValues.append(value);
} else {
if (value == d->extraData->propertyValues.at(idx))
return false;
d->extraData->propertyValues[idx] = value;
}
}

View File

@ -2950,6 +2950,9 @@ void tst_QObject::dynamicProperties()
QVERIFY(!obj.setProperty("myuserproperty", "Hello"));
QCOMPARE(obj.changedDynamicProperties.count(), 1);
QCOMPARE(obj.changedDynamicProperties.first(), QByteArray("myuserproperty"));
//check if there is no redundant DynamicPropertyChange events
QVERIFY(!obj.setProperty("myuserproperty", "Hello"));
QCOMPARE(obj.changedDynamicProperties.count(), 1);
obj.changedDynamicProperties.clear();
QCOMPARE(obj.property("myuserproperty").toString(), QString("Hello"));