Skip to content
Permalink
Browse files
Setting a property to null in collections removes property
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent 5e9f6ac commit c23de083ce854db9d293da0596621d3993be4f04
Showing with 13 additions and 3 deletions.
  1. +2 −1 python/core/qgsproperty.sip
  2. +3 −1 src/core/qgsproperty.cpp
  3. +2 −1 src/core/qgsproperty.h
  4. +6 −0 tests/src/core/testqgsproperty.cpp
@@ -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/ );

@@ -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;
}

@@ -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 );

@@ -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 );

0 comments on commit c23de08

Please sign in to comment.