File indexing completed on 2025-01-05 03:59:11
0001 /* 0002 SPDX-FileCopyrightText: 2008 Torsten Rahn <rahn@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "GeoSceneSettings.h" 0008 0009 #include "GeoSceneProperty.h" 0010 #include "GeoSceneGroup.h" 0011 #include "GeoSceneTypes.h" 0012 0013 #include "digikam_debug.h" 0014 0015 namespace Marble 0016 { 0017 0018 class GeoSceneSettingsPrivate 0019 { 0020 public: 0021 ~GeoSceneSettingsPrivate() 0022 { 0023 qDeleteAll(m_properties); 0024 qDeleteAll(m_groups); 0025 } 0026 0027 /// The hash table holding all the properties in the settings. 0028 QVector<GeoSceneProperty*> m_properties; 0029 QVector<GeoSceneGroup*> m_groups; 0030 }; 0031 0032 0033 GeoSceneSettings::GeoSceneSettings() 0034 : d( new GeoSceneSettingsPrivate ) 0035 { 0036 } 0037 0038 GeoSceneSettings::~GeoSceneSettings() 0039 { 0040 delete d; 0041 } 0042 0043 const char* GeoSceneSettings::nodeType() const 0044 { 0045 return GeoSceneTypes::GeoSceneSettingsType; 0046 } 0047 0048 bool GeoSceneSettings::propertyAvailable( const QString& name, bool& available ) const 0049 { 0050 QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin(); 0051 QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd(); 0052 for (; it != propEnd; ++it) { 0053 if ( (*it)->name() == name ) { 0054 available = (*it)->available(); 0055 return true; 0056 } 0057 } 0058 0059 QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin(); 0060 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd(); 0061 for (; itGroup != groupEnd; ++itGroup) { 0062 bool success = (*itGroup)->propertyAvailable( name, available ); 0063 if ( success ) { 0064 return true; 0065 } 0066 } 0067 0068 available = false; 0069 0070 return false; 0071 } 0072 0073 bool GeoSceneSettings::setPropertyValue( const QString& name, bool value ) 0074 { 0075 qCDebug(DIGIKAM_MARBLE_LOG) << "GeoSceneSettings: Property " << name << "to" << value; 0076 0077 QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin(); 0078 QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd(); 0079 for (; it != propEnd; ++it) { 0080 if ( (*it)->name() == name ) { 0081 (*it)->setValue( value ); 0082 return true; 0083 } 0084 } 0085 0086 QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin(); 0087 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd(); 0088 for (; itGroup != groupEnd; ++itGroup) { 0089 bool success = (*itGroup)->setPropertyValue( name, value ); 0090 if ( success ) { 0091 return true; 0092 } 0093 } 0094 0095 return false; 0096 } 0097 0098 bool GeoSceneSettings::propertyValue( const QString& name, bool& value ) const 0099 { 0100 QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin(); 0101 QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd(); 0102 for (; it != propEnd; ++it) { 0103 if ( (*it)->name() == name ) { 0104 value = (*it)->value(); 0105 return true; 0106 } 0107 } 0108 0109 QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin(); 0110 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd(); 0111 for (; itGroup != groupEnd; ++itGroup) { 0112 bool success = (*itGroup)->propertyValue( name, value ); 0113 if ( success ) { 0114 return true; 0115 } 0116 } 0117 0118 value = false; 0119 0120 return false; 0121 } 0122 0123 QVector<GeoSceneProperty*> GeoSceneSettings::allProperties() 0124 { 0125 QVector<GeoSceneProperty*> allProperties; 0126 0127 QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin(); 0128 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd(); 0129 for (; itGroup != groupEnd; ++itGroup) { 0130 allProperties << (*itGroup)->properties(); 0131 } 0132 0133 allProperties << d->m_properties; 0134 0135 return allProperties; 0136 } 0137 0138 QVector<const GeoSceneProperty*> GeoSceneSettings::allProperties() const 0139 { 0140 QVector<const GeoSceneProperty*> allProperties; 0141 0142 QVector<GeoSceneGroup*>::const_iterator itGroup = d->m_groups.constBegin(); 0143 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd(); 0144 for (; itGroup != groupEnd; ++itGroup) { 0145 allProperties << const_cast<const GeoSceneGroup*>(*itGroup)->properties(); 0146 } 0147 0148 allProperties.reserve(allProperties.size() + d->m_properties.size()); 0149 for ( const GeoSceneProperty *property: d->m_properties ) { 0150 allProperties << property; 0151 } 0152 0153 return allProperties; 0154 } 0155 0156 void GeoSceneSettings::addGroup( GeoSceneGroup* group ) 0157 { 0158 // Remove any property that has the same name 0159 QVector<GeoSceneGroup*>::iterator it = d->m_groups.begin(); 0160 while (it != d->m_groups.end()) { 0161 GeoSceneGroup* currentGroup = *it; 0162 if ( currentGroup->name() == group->name() ) { 0163 delete currentGroup; 0164 d->m_groups.erase(it); 0165 break; 0166 } 0167 else { 0168 ++it; 0169 } 0170 } 0171 0172 if ( group ) { 0173 d->m_groups.append( group ); 0174 0175 // Establish connection to the outside, e.g. the LegendBrowser 0176 connect ( group, SIGNAL(valueChanged(QString,bool)), 0177 SIGNAL(valueChanged(QString,bool)) ); 0178 } 0179 } 0180 0181 const GeoSceneGroup* GeoSceneSettings::group( const QString& name ) const 0182 { 0183 GeoSceneGroup* group = nullptr; 0184 0185 QVector<GeoSceneGroup*>::const_iterator it = d->m_groups.constBegin(); 0186 QVector<GeoSceneGroup*>::const_iterator groupEnd = d->m_groups.constEnd(); 0187 for (; it != groupEnd; ++it) { 0188 if ( (*it)->name() == name ) { 0189 group = *it; 0190 break; 0191 } 0192 } 0193 0194 return group; 0195 } 0196 0197 // implement non-const method by means of const method, 0198 // for details, see "Effective C++" (third edition) 0199 GeoSceneGroup* GeoSceneSettings::group( const QString& name ) 0200 { 0201 return const_cast<GeoSceneGroup*>( static_cast<GeoSceneSettings const *>( this )->group( name )); 0202 } 0203 0204 void GeoSceneSettings::addProperty( GeoSceneProperty* property ) 0205 { 0206 // Remove any property that has the same name 0207 QVector<GeoSceneProperty*>::iterator it = d->m_properties.begin(); 0208 while (it != d->m_properties.end()) { 0209 GeoSceneProperty* currentProperty = *it; 0210 if ( currentProperty->name() == property->name() ) { 0211 delete currentProperty; 0212 d->m_properties.erase(it); 0213 break; 0214 } 0215 else { 0216 ++it; 0217 } 0218 } 0219 0220 if ( property ) { 0221 d->m_properties.append( property ); 0222 0223 // Establish connection to the outside, e.g. the LegendBrowser 0224 connect ( property, SIGNAL(valueChanged(QString,bool)), 0225 SIGNAL(valueChanged(QString,bool)) ); 0226 Q_EMIT valueChanged( property->name(), property->value() ); 0227 } 0228 } 0229 0230 const GeoSceneProperty* GeoSceneSettings::property( const QString& name ) const 0231 { 0232 GeoSceneProperty* property = nullptr; 0233 0234 QVector<GeoSceneProperty*>::const_iterator it = d->m_properties.constBegin(); 0235 QVector<GeoSceneProperty*>::const_iterator propEnd = d->m_properties.constEnd(); 0236 for (; it != propEnd; ++it) { 0237 if ( (*it)->name() == name ) { 0238 property = *it; 0239 break; 0240 } 0241 } 0242 0243 return property; 0244 } 0245 0246 // implement non-const method by means of const method, 0247 // for details, see "Effective C++" (third edition) 0248 GeoSceneProperty* GeoSceneSettings::property( const QString& name ) 0249 { 0250 return const_cast<GeoSceneProperty*> 0251 ( static_cast<GeoSceneSettings const *>( this )->property( name )); 0252 } 0253 0254 QVector<GeoSceneProperty*> GeoSceneSettings::rootProperties() 0255 { 0256 return d->m_properties; 0257 } 0258 0259 } 0260 0261 #include "moc_GeoSceneSettings.cpp"