File indexing completed on 2025-01-05 03:59:10
0001 /* 0002 SPDX-FileCopyrightText: 2008 Torsten Rahn <rahn@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "GeoSceneGroup.h" 0008 0009 #include "GeoSceneProperty.h" 0010 #include "GeoSceneTypes.h" 0011 0012 #include "digikam_debug.h" 0013 0014 namespace Marble 0015 { 0016 0017 GeoSceneGroup::GeoSceneGroup( const QString& name ) 0018 : m_name( name ) 0019 { 0020 } 0021 0022 GeoSceneGroup::~GeoSceneGroup() 0023 { 0024 qDeleteAll( m_properties ); 0025 } 0026 0027 bool GeoSceneGroup::propertyAvailable( const QString& name, bool& available ) const 0028 { 0029 QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin(); 0030 QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd(); 0031 for (; it != end; ++it) { 0032 if ( (*it)->name() == name ) { 0033 available = (*it)->available(); 0034 return true; 0035 } 0036 } 0037 0038 available = false; 0039 0040 return false; 0041 } 0042 0043 bool GeoSceneGroup::setPropertyValue( const QString& name, bool value ) 0044 { 0045 QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin(); 0046 QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd(); 0047 for (; it != end; ++it) { 0048 if ( (*it)->name() == name ) { 0049 (*it)->setValue( value ); 0050 Q_EMIT valueChanged( name, value ); 0051 return true; 0052 } 0053 } 0054 0055 return false; 0056 } 0057 0058 bool GeoSceneGroup::propertyValue( const QString& name, bool& value ) const 0059 { 0060 QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin(); 0061 QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd(); 0062 for (; it != end; ++it) { 0063 if ( (*it)->name() == name ) { 0064 value = (*it)->value(); 0065 return true; 0066 } 0067 } 0068 0069 value = false; 0070 0071 return false; 0072 } 0073 0074 void GeoSceneGroup::addProperty( GeoSceneProperty* property ) 0075 { 0076 Q_ASSERT(property); 0077 if (!property) { 0078 return; 0079 } 0080 0081 // Remove any property that has the same name 0082 QVector<GeoSceneProperty*>::iterator it = m_properties.begin(); 0083 while (it != m_properties.end()) { 0084 GeoSceneProperty* currentProperty = *it; 0085 if ( currentProperty->name() == property->name() ) { 0086 delete currentProperty; 0087 m_properties.erase(it); 0088 break; 0089 } 0090 else { 0091 ++it; 0092 } 0093 } 0094 0095 m_properties.append( property ); 0096 0097 // Establish connection to the outside, e.g. the LegendBrowser 0098 connect ( property, SIGNAL(valueChanged(QString,bool)), 0099 SIGNAL(valueChanged(QString,bool)) ); 0100 Q_EMIT valueChanged( property->name(), property->value() ); 0101 } 0102 0103 const GeoSceneProperty* GeoSceneGroup::property( const QString& name ) const 0104 { 0105 GeoSceneProperty* property = nullptr; 0106 0107 QVector<GeoSceneProperty*>::const_iterator it = m_properties.constBegin(); 0108 QVector<GeoSceneProperty*>::const_iterator end = m_properties.constEnd(); 0109 for (; it != end; ++it) { 0110 if ( (*it)->name() == name ) { 0111 property = *it; 0112 break; 0113 } 0114 } 0115 0116 return property; 0117 } 0118 0119 // implement non-const method by means of const method, 0120 // for details, see "Effective C++" (third edition) 0121 GeoSceneProperty* GeoSceneGroup::property( const QString& name ) 0122 { 0123 return const_cast<GeoSceneProperty*> 0124 ( static_cast<GeoSceneGroup const *>( this )->property( name )); 0125 } 0126 0127 QVector<GeoSceneProperty*> GeoSceneGroup::properties() 0128 { 0129 return m_properties; 0130 } 0131 0132 QVector<const GeoSceneProperty*> GeoSceneGroup::properties() const 0133 { 0134 QVector<const GeoSceneProperty*> result; 0135 result.reserve(m_properties.size()); 0136 0137 for ( const GeoSceneProperty *property: m_properties ) { 0138 result << property; 0139 } 0140 0141 return result; 0142 } 0143 0144 QString GeoSceneGroup::name() const 0145 { 0146 return m_name; 0147 } 0148 0149 const char *GeoSceneGroup::nodeType() const 0150 { 0151 return GeoSceneTypes::GeoSceneGroupType; 0152 } 0153 0154 } 0155 0156 #include "moc_GeoSceneGroup.cpp"