Setting a property to null in collections removes property

This commit is contained in:
Nyall Dawson 2016-03-17 17:36:13 +11:00
parent 5e9f6ac5cc
commit c23de083ce
4 changed files with 13 additions and 3 deletions

View File

@ -630,7 +630,8 @@ class QgsPropertyCollection
* @param key integer key for property. Any existing property with the same key will be deleted
* and replaced by this property. The intended use case is that a context specific enum is cast to
* int and used for the key value.
* @param property property to add. Ownership is transferred to the collection.
* @param property property to add. Ownership is transferred to the collection. Setting a property
* to null will remove the property from the collection.
*/
void setProperty( int key, QgsAbstractProperty* property /Transfer/ );

View File

@ -724,7 +724,9 @@ void QgsPropertyCollection::setProperty( int key, QgsAbstractProperty* property
if ( hasProperty( key ) )
delete mProperties.take( key );
mProperties.insert( key, property );
if ( property )
mProperties.insert( key, property );
mDirty = true;
}

View File

@ -718,7 +718,8 @@ class CORE_EXPORT QgsPropertyCollection
* @param key integer key for property. Any existing property with the same key will be deleted
* and replaced by this property. The intended use case is that a context specific enum is cast to
* int and used for the key value.
* @param property property to add. Ownership is transferred to the collection.
* @param property property to add. Ownership is transferred to the collection. Setting a property
* to null will remove the property from the collection.
*/
void setProperty( int key, QgsAbstractProperty* property );

View File

@ -797,6 +797,12 @@ void TestQgsProperty::propertyCollection()
QCOMPARE( collection.count(), 2 );
QCOMPARE( collection.propertyKeys().toSet(), QSet<int>() << Property1 << Property3 );
//test removing a property
collection.setProperty( Property1, nullptr );
QVERIFY( !collection.property( Property1 ) );
QVERIFY( !collection.hasProperty( Property1 ) );
QCOMPARE( collection.propertyKeys(), QList<int>() << Property3 );
//clear
collection.clear();
QCOMPARE( collection.count(), 0 );