QVariant SettingsDatabase::value(const QString &key, const QVariant &defaultValue) const { const QString effectiveKey = d->effectiveKey(key); QVariant value = defaultValue; SettingsMap::const_iterator i = d->m_settings.constFind(effectiveKey); if (i != d->m_settings.constEnd() && i.value().isValid()) { value = i.value(); } else if (d->m_db.isOpen()) { // Try to read the value from the database QSqlQuery query(d->m_db); query.prepare(QLatin1String("SELECT value FROM settings WHERE key = ?")); query.addBindValue(effectiveKey); query.exec(); if (query.next()) { value = query.value(0); if (debug_settings) qDebug() << "Retrieved:" << effectiveKey << "=" << value; } // Cache the result d->m_settings.insert(effectiveKey, value); } return value; }
QString Settings::toString() const { QString result = "{\n"; for (SettingsMap::const_iterator it = _settings.constBegin(); it != _settings.constEnd(); ++it) { result += QString(" \"%1\":\"%2\",\n").arg(_markup(it.key())) .arg(_markup(it.value().toString())); } result += " \"#end\": \"\"\n"; result += "}\n"; return result; }