Пример #1
0
QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format,
        QSettings::Scope scope,
        const QString &organization,
        const QString &application)
{
#ifndef QT_BOOTSTRAPPED
    if (organization == QLatin1String("Qt"))
    {
        QString organizationDomain = QCoreApplication::organizationDomain();
        QString applicationName = QCoreApplication::applicationName();

        QSettingsPrivate *newSettings;
        if (format == QSettings::NativeFormat) {
            newSettings = new QMacSettingsPrivate(scope, organizationDomain, applicationName);
        } else {
            newSettings = new QConfFileSettingsPrivate(format, scope, organizationDomain, applicationName);
        }

        newSettings->beginGroupOrArray(QSettingsGroup(normalizedKey(organization)));
        if (!application.isEmpty())
            newSettings->beginGroupOrArray(QSettingsGroup(normalizedKey(application)));

        return newSettings;
    }
#endif
    if (format == QSettings::NativeFormat) {
        return new QMacSettingsPrivate(scope, organization, application);
    } else {
        return new QConfFileSettingsPrivate(format, scope, organization, application);
    }
}
Пример #2
0
const QVariant &Settings::localValue(const QString &key, const QVariant &def) {
  QString normKey = normalizedKey(group, key);
  if(!isCached(normKey)) {
    create_qsettings;
    setCacheValue(normKey, s.value(normKey, def));
  }
  return cacheValue(normKey);
}
Пример #3
0
bool Settings::localKeyExists(const QString &key)
{
    QString normKey = normalizedKey(group, key);
    // Do NOT check the cache as default values get cached, too.  Otherwise loading a setting once
    // will mark it as existing in settings, even when it only exists in cache (and not on disk).
    create_qsettings;
    return s.contains(normKey);
}
Пример #4
0
void Settings::removeLocalKey(const QString &key) {
  create_qsettings;
  s.beginGroup(group);
  s.remove(key);
  s.endGroup();
  QString normKey = normalizedKey(group, key);
  if(isCached(normKey))
    settingsCache.remove(normKey);
}
Пример #5
0
void Settings::setLocalValue(const QString &key, const QVariant &data) {
  QString normKey = normalizedKey(group, key);
  create_qsettings;
  s.setValue(normKey, data);
  setCacheValue(normKey, data);
  if(hasNotifier(normKey)) {
    emit notifier(normKey)->valueChanged(data);
  }
}
Пример #6
0
bool Settings::localKeyExists(const QString& key) const
{
    QString normKey = normalizedKey(_group, key);
    if (!isKeyPersistedCached(normKey)) {
        create_qsettings;
        // Cache whether or not key exists on disk
        // We can't cache key value as we don't know the default
        setCacheKeyPersisted(normKey, s.contains(normKey));
    }

    return cacheKeyPersisted(normKey);
}
Пример #7
0
void Settings::removeLocalKey(const QString &key)
{
    create_qsettings;
    s.beginGroup(group);
    s.remove(key);
    s.endGroup();
    QString normKey = normalizedKey(group, key);
    if (isCached(normKey)) {
        settingsCache.remove(normKey);
    }
    if (hasNotifier(normKey)) {
        emit notifier(normKey)->valueChanged({});
    }
}
Пример #8
0
QVariant Settings::localValue(const QString& key, const QVariant& def) const
{
    QString normKey = normalizedKey(_group, key);
    if (!isCached(normKey)) {
        create_qsettings;
        // Since we're loading from settings anyways, cache whether or not the key exists on disk
        setCacheKeyPersisted(normKey, s.contains(normKey));
        // Cache key value
        setCacheValue(normKey, s.value(normKey, def));
    }
    if (cacheKeyPersisted(normKey)) {
        return cacheValue(normKey);
    }
    // Don't return possibly wrong cached values
    // A key gets cached with the first default value requested and never changes afterwards
    return def;
}
Пример #9
0
void Settings::initAndNotify(const QString &key, QObject *receiver, const char *slot, const QVariant &defaultValue) {
  notify(key, receiver, slot);
  emit notifier(normalizedKey(group, key))->valueChanged(localValue(key, defaultValue));
}