diff options
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/configmapper.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/configmapper.cpp | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/configmapper.cpp b/SQLiteStudio3/guiSQLiteStudio/configmapper.cpp index b36d985..704104b 100644 --- a/SQLiteStudio3/guiSQLiteStudio/configmapper.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/configmapper.cpp @@ -293,14 +293,14 @@ void ConfigMapper::applyConfigToWidget(QWidget* widget, const QHash<QString, Cfg { configValue = config[cfgEntry->getFullKey()]; if (!configValue.isValid()) - configValue = cfgEntry->getDefultValue(); + configValue = cfgEntry->getDefaultValue(); } else if (cfgEntry->isPersistable()) { // In case this is a persistable config, we should have everything in the config hash, which is just one, initial database query. // If we don't, than we don't want to call get(), because it will cause one more query to the database for it. // We go with the default value. - configValue = cfgEntry->getDefultValue(); + configValue = cfgEntry->getDefaultValue(); } else { @@ -329,18 +329,36 @@ void ConfigMapper::applyConfigToWidget(QWidget* widget, CfgEntry* cfgEntry, cons void ConfigMapper::applyConfigDefaultValueToWidget(QWidget* widget) { - QString keyStr = widget->property(CFG_MODEL_PROPERTY).toString(); + CfgEntry* key = getConfigForWidget(widget); + if (!key) + { + qWarning() << "Asked to apply config value to widget" << widget + << "but it's config entry key was not found."; + return; + } + + applyConfigToWidget(widget, key, key->getDefaultValue()); +} + +CfgEntry* ConfigMapper::getConfigForWidget(QWidget* widget) +{ + QString keyStr = getConfigFullKeyForWidget(widget); QHash<QString, CfgEntry*> allConfigEntries = getAllConfigEntries(); if (!allConfigEntries.contains(keyStr)) { - qWarning() << "Asked to apply config value to widget" << widget << "but it's config entry key was not found:" << keyStr; - return; + qWarning() << "Config entry with key not found:" << keyStr; + return nullptr; } - CfgEntry* key = allConfigEntries[keyStr]; - applyConfigToWidget(widget, key, key->getDefultValue()); + return allConfigEntries[keyStr]; } +QString ConfigMapper::getConfigFullKeyForWidget(QWidget* widget) +{ + return widget->property(CFG_MODEL_PROPERTY).toString(); +} + + void ConfigMapper::handleSpecialWidgets(QWidget* widget, const QHash<QString, CfgEntry*>& allConfigEntries) { handleConfigComboBox(widget, allConfigEntries); @@ -372,7 +390,7 @@ bool ConfigMapper::applyCustomConfigToWidget(CfgEntry* key, QWidget* widget, con handlers += internalCustomConfigWidgets; handlers += PLUGINS->getLoadedPlugins<CustomConfigWidgetPlugin>(); - for (CustomConfigWidgetPlugin* handler : handlers) + for (CustomConfigWidgetPlugin*& handler : handlers) { if (handler->isConfigForWidget(key, widget)) { @@ -389,11 +407,11 @@ bool ConfigMapper::connectCustomNotifierToWidget(QWidget* widget, CfgEntry* cfgE handlers += internalCustomConfigWidgets; handlers += PLUGINS->getLoadedPlugins<CustomConfigWidgetPlugin>(); - for (CustomConfigWidgetPlugin* handler : handlers) + for (CustomConfigWidgetPlugin*& handler : handlers) { if (handler->isConfigForWidget(cfgEntry, widget)) { - connect(widget, handler->getModifiedNotifier(), this, SIGNAL(modified())); + connect(widget, handler->getModifiedNotifier(), this, SLOT(handleCustomModified())); if (widget->property(CFG_NOTIFY_PROPERTY).isValid() && widget->property(CFG_NOTIFY_PROPERTY).toBool()) connect(widget, handler->getModifiedNotifier(), this, SLOT(uiConfigEntryChanged())); @@ -430,7 +448,7 @@ bool ConfigMapper::saveCustomConfigFromWidget(QWidget* widget, CfgEntry* key) handlers += internalCustomConfigWidgets; handlers += PLUGINS->getLoadedPlugins<CustomConfigWidgetPlugin>(); - for (CustomConfigWidgetPlugin* plugin : handlers) + for (CustomConfigWidgetPlugin*& plugin : handlers) { if (plugin->isConfigForWidget(key, widget)) { @@ -470,7 +488,7 @@ QHash<QString, CfgEntry *> ConfigMapper::getAllConfigEntries() if (allEntries.isEmpty()) { QString key; - for (CfgMain* cfgMain : cfgMainList) + for (CfgMain*& cfgMain : cfgMainList) { QHashIterator<QString,CfgCategory*> catIt(cfgMain->getCategories()); while (catIt.hasNext()) @@ -627,7 +645,13 @@ void ConfigMapper::handleModified() handleDependencyChange(widget); - emit modified(); + emit modified(widget); +} + +void ConfigMapper::handleCustomModified() +{ + QWidget* widget = dynamic_cast<QWidget*>(sender()); + emit modified(widget); } void ConfigMapper::entryChanged(const QVariant& newValue) |
