From kde-commits Tue Mar 11 15:20:34 2008 From: Nikolas Zimmermann Date: Tue, 11 Mar 2008 15:20:34 +0000 To: kde-commits Subject: KDE/kdeedu/marble/src/lib/geodata/scene Message-Id: <1205248834.505048.23569.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=120524884407743 SVN commit 784514 by wildfox: Don't crash on non-existant property (calling property->setName on null pointer!) Also cleanup code & style, and add an assertion. M +11 -11 GeoSceneSettings.cpp M +4 -6 GeoSceneSettings.h --- trunk/KDE/kdeedu/marble/src/lib/geodata/scene/GeoSceneSettings.cpp #784513:784514 @@ -23,29 +23,29 @@ GeoSceneSettings::GeoSceneSettings() { - /* NOOP */ } GeoSceneSettings::~GeoSceneSettings() { - qDebug("GeoSceneSettings::~GeoSceneSettings(). Object count: %d", m_properties.count()); - - foreach ( GeoSceneProperty* property, m_properties ) { - delete property; - } + qDeleteAll(m_properties); } -void GeoSceneSettings::addProperty( const QString& name, GeoSceneProperty* property ) +void GeoSceneSettings::addProperty(const QString& name, GeoSceneProperty* property) { - m_properties.insert( name, property ); + m_properties.insert(name, property); } GeoSceneProperty* GeoSceneSettings::property( const QString& name ) { - GeoSceneProperty* property = m_properties.value( name ); - if ( !property ) - addProperty( name , new GeoSceneProperty ); + GeoSceneProperty* property = m_properties.value(name); + if (property) { + Q_ASSERT(property->name() == name); + return property; + } + + property = new GeoSceneProperty; property->setName(name); + addProperty(name, property); return property; } --- trunk/KDE/kdeedu/marble/src/lib/geodata/scene/GeoSceneSettings.h #784513:784514 @@ -30,23 +30,21 @@ /** * @short Settings of a GeoScene document. */ - class GeoSceneSettings : public GeoNode { public: GeoSceneSettings(); - ~GeoSceneSettings(); + virtual ~GeoSceneSettings(); /** * @brief Add a property to the settings * @param property the new property */ - void addProperty( const QString& name, GeoSceneProperty* property ); - GeoSceneProperty* property( const QString& name ); + void addProperty(const QString& name, GeoSceneProperty*); + GeoSceneProperty* property(const QString&); protected: /// The hash table holding all the properties in the settings. - QHash < QString, GeoSceneProperty* > m_properties; + QHash m_properties; }; - #endif // GEOSCENESETTINGS_H