Implemented removeEntry(), so now it's possible to remove existing project keys.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@2315 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mcoletti 2004-11-22 22:13:47 +00:00
parent 09aed6fed8
commit 1751ad9a54

View File

@ -90,6 +90,13 @@ public:
*/
virtual void dump( ) const = 0;
/**
deletes the given key
@param keyname key list tokenized by '/' by caller
*/
virtual bool remove( QStringList & keyname ) = 0;
/**
restores property hierarchy to given DOM node
@ -114,6 +121,9 @@ public:
*/
virtual size_t count() const = 0;
/// Does this property not have any subkeys or values?
virtual bool isEmpty() const = 0;
}; // class Property
@ -202,6 +212,26 @@ public:
}
}
/**
deletes the given key
@param keyname key list tokenized by '/' by caller
*/
/* virtual */ bool remove( QStringList & keyname )
{
// NOP; parent PropertyKey will delete this PropertyValue in its remove()
return false; // we shouldn't ever be calling this, so return false
} // remove
/// Does this property not have any subkeys or values?
/* virtual */ bool isEmpty() const
{ // values are leaf nodes, so are always empty
return true;
}
/* virtual */ bool readXML( QDomNode & keyNode )
{
// this *should* be a DOM element node
@ -660,7 +690,8 @@ public:
return true;
}
virtual void dump( ) const
/* virtual */ void dump( ) const
{
for ( QDictIterator<Property> i(properties_); i.current(); ++i )
{
@ -670,6 +701,47 @@ public:
}
}
/**
deletes the given key
@param keyname key list tokenized by '/' by caller
*/
/* virtual */ bool remove( QStringList & keyName )
{
// save the current key, which should be the front of the key list
QString const currentKey = keyName.front();
// now pop it off
keyName.pop_front();
if ( keyName.empty() ) // then we have a leaf node
{
properties_.remove( currentKey );
}
else if ( properties_.find( currentKey ) )
{ // recurse down to next key
properties_[currentKey]->remove( keyName );
// if that subkey is now empty, then delete it, too
if ( properties_[currentKey]->isEmpty() )
{
properties_.remove( currentKey );
}
}
else
{
qDebug( "%s:%d cannot find key %s to remove",
__FILE__, __LINE__, currentKey.ascii() );
return false;
}
return true;
} // remove
/* virtual */ bool readXML( QDomNode & keyNode )
{
size_t i = 0;
@ -731,6 +803,7 @@ public:
return true;
}
/// how many elements are contained within this one?
size_t count() const
{
@ -738,6 +811,13 @@ public:
}
/// Does this property not have any subkeys or values?
/* virtual */ bool isEmpty() const
{
return properties_.isEmpty();
}
private:
@ -2097,6 +2177,7 @@ QgsProject::readBoolEntry ( QString const & scope,
bool
QgsProject::removeEntry ( QString const & scope, const QString & key )
{
qDebug( "%s:%d not implemented yet", __FILE__, __LINE__ );
return false;
QStringList keyTokens = QStringList::split( '/', key );
return imp_->properties_[scope].remove( keyTokens );
} // QgsProject::removeEntry