void QgsSettings::beginGroup( const QString &prefix, const QgsSettings::Section section ) { QString pKey = prefixedKey( prefix, section ); mUserSettings->beginGroup( pKey ); if ( mGlobalSettings ) { mGlobalSettings->beginGroup( pKey ); } }
QVariant QgsSettings::value( const QString &key, const QVariant &defaultValue, const QgsSettings::Section section ) const { QString pKey = prefixedKey( key, section ); if ( !mUserSettings->value( pKey ).isNull() ) { return mUserSettings->value( pKey ); } if ( mGlobalSettings ) { return mGlobalSettings->value( pKey, defaultValue ); } return defaultValue; }
void QgsSettings::setValue( const QString &key, const QVariant &value, const QgsSettings::Section section ) { // TODO: add valueChanged signal // Do not store if it hasn't changed from default value // First check if the values are different and if at least one of them is valid. // The valid check is required because different invalid QVariant types // like QVariant(QVariant::String) and QVariant(QVariant::Int)) // may be considered different and we don't want to store the value in that case. QVariant currentValue { QgsSettings::value( prefixedKey( key, section ) ) }; if ( ( currentValue.isValid() || value.isValid() ) && ( currentValue != value ) ) { mUserSettings->setValue( prefixedKey( key, section ), value ); } // Deliberately an "else if" because we want to remove a value from the user settings // only if the value is different than the one stored in the global settings (because // it would be the default anyway). The first check is necessary because the global settings // might be a nullptr (for example in case of standalone scripts or apps). else if ( mGlobalSettings && mGlobalSettings->value( prefixedKey( key, section ) ) == currentValue ) { mUserSettings->remove( prefixedKey( key, section ) ); } }
MojErr MojDbIndexTest::assertContains(TestIndex& ti, MojObject id, const MojDbKey& key) { MojDbKey prefixedKey(key); MojErr err = prefixedKey.byteVec().insert(0, 1, MojObjectWriter::MarkerZeroIntValue); MojErrCheck(err); if (ti.m_incDel) { MojDbKey::ByteVec vec = prefixedKey.byteVec(); MojErr err = vec.insert(1, 1, MojObjectWriter::MarkerTrueValue); MojTestErrCheck(err); MojDbKey keyTrue; err = keyTrue.assign(vec.begin(), vec.size()); MojTestErrCheck(err); err = vec.setAt(1, MojObjectWriter::MarkerFalseValue); MojTestErrCheck(err); MojDbKey keyFalse; err = keyFalse.assign(vec.begin(), vec.size()); MojTestErrCheck(err); MojTestAssert(ti.m_set.contains(keyTrue) || ti.m_set.contains(keyFalse)); } else { MojTestAssert(ti.m_set.contains(prefixedKey)); } return MojErrNone; }
void QgsSettings::setValue( const QString &key, const QVariant &value, const QgsSettings::Section section ) { // TODO: add valueChanged signal mUserSettings->setValue( prefixedKey( key, section ), value ); }
void QgsSettings::remove( const QString &key, const QgsSettings::Section section ) { QString pKey = prefixedKey( key, section ); mUserSettings->remove( pKey ); }
bool QgsSettings::contains( const QString &key, const QgsSettings::Section section ) const { QString pKey = prefixedKey( key, section ); return mUserSettings->contains( pKey ) || ( mGlobalSettings && mGlobalSettings->contains( pKey ) ); }