From 7167ce41b61d2ba2cdb526777a4233eb84a3b66a Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 6 Dec 2014 17:33:25 -0500 Subject: Imported Upstream version 2.99.6 --- SQLiteStudio3/guiSQLiteStudio/configmapper.h | 121 +++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 SQLiteStudio3/guiSQLiteStudio/configmapper.h (limited to 'SQLiteStudio3/guiSQLiteStudio/configmapper.h') diff --git a/SQLiteStudio3/guiSQLiteStudio/configmapper.h b/SQLiteStudio3/guiSQLiteStudio/configmapper.h new file mode 100644 index 0000000..049d25a --- /dev/null +++ b/SQLiteStudio3/guiSQLiteStudio/configmapper.h @@ -0,0 +1,121 @@ +#ifndef CONFIGMAPPER_H +#define CONFIGMAPPER_H + +#include "common/bihash.h" +#include "guiSQLiteStudio_global.h" +#include + +class CfgMain; +class CfgEntry; +class CustomConfigWidgetPlugin; +class ConfigComboBox; + +class GUI_API_EXPORT ConfigMapper : public QObject +{ + Q_OBJECT + + public: + explicit ConfigMapper(CfgMain* cfgMainList); + ConfigMapper(const QList cfgMainList); + + void loadToWidget(QWidget* topLevelWidget); + void loadToWidget(CfgEntry* config, QWidget* widget); + void saveFromWidget(QWidget* widget, bool noTransaction = false); + void setInternalCustomConfigWidgets(const QList& value); + + /** + * @brief Scans widget and binds widgets to proper config objects. + * @param topLevelWidget Toplevel widget that contains all required configuration widgets. + * + * It goes through all widgets in given top level widget and looks for statusText property + * that matches any of config entries in CfgMain instance(s) passed in constructor. + * + * For each matched pair (QWidget::statusText() to CfgEntry::getFullKey()) it remembers + * pair of QWidget and CfgEntry and from now on when CfgEntry is modified, the QWidget + * gets updated with the value and vice versa - when QWidget gets new input, then CfgEntry + * is updated with that value. All these updates are done in real time. + * + * @note Binding mechanism can be used only against CfgMain that is not persistable. + * If you try to bind CfgMain that is persistable, it just won't work and it is intended + * that way, because having a QWidget bind to a persistable CfgEntry would cause lots + * of database updates to store changing value (like from QLineEdit). For persistable please + * use loadToWidget() and saveFromWidget() methods, as you can call them when necessary. + */ + void bindToConfig(QWidget* topLevelWidget); + + /** + * @brief Releases any bingins against widgets. + * + * This simply revokes what was done with bindToConfig(). + */ + void unbindFromConfig(); + + QWidget* getBindWidgetForConfig(CfgEntry* key) const; + CfgEntry* getBindConfigForWidget(QWidget* widget) const; + + QList getExtraWidgets() const; + + /** + * @brief Sets list of extra widgets to load/save values to/from. + * @param value List of widgets. + * + * Extra widgets list can be provided to the mapper if it will be impossible to find those widgets + * just by looking for childrens of top widget recurrently. This is for example the case + * when widgets are embedded in QAbstractItemView::setIndexWidget(). Such widgets have to be + * provided as list of extra widgets to the mapper, so the mapper handles them when loading/saving + * values. + */ + void setExtraWidgets(const QList &value); + void addExtraWidget(QWidget* w); + void addExtraWidgets(const QList& list); + void clearExtraWidgets(); + + private: + void applyConfigToWidget(QWidget *widget, const QHash& allConfigEntries, const QHash &config); + void applyConfigToWidget(QWidget *widget, CfgEntry* cfgEntry, const QVariant& configValue); + void handleSpecialWidgets(QWidget *widget, const QHash& allConfigEntries); + void handleConfigComboBox(QWidget *widget, const QHash& allConfigEntries); + void connectCommonNotifierToWidget(QWidget *widget, CfgEntry* key); + bool connectCustomNotifierToWidget(QWidget *widget, CfgEntry* cfgEntry); + void applyCommonConfigToWidget(QWidget *widget, const QVariant& value, CfgEntry* cfgEntry); + bool applyCustomConfigToWidget(CfgEntry* key, QWidget *widget, const QVariant& value); + void saveWidget(QWidget* widget, const QHash& allConfigEntries); + void saveFromWidget(QWidget* widget, CfgEntry* cfgEntry); + void saveCommonConfigFromWidget(QWidget *widget, CfgEntry* key); + bool saveCustomConfigFromWidget(QWidget *widget, CfgEntry* key); + QVariant getCommonConfigValueFromWidget(QWidget *widget, CfgEntry* key, bool& ok); + QVariant getCustomConfigValueFromWidget(QWidget *widget, CfgEntry* key, bool& ok); + QVariant getConfigValueFromWidget(QWidget *widget, CfgEntry* key); + CfgEntry* getConfigEntry(QWidget* widget, const QHash& allConfigEntries); + CfgEntry* getEntryForProperty(QWidget* widget, const char* propertyName, const QHash& allConfigEntries); + QHash getAllConfigEntries(); + QList getAllConfigWidgets(QWidget* parent); + bool isPersistant() const; + + QList cfgMainList; + QList internalCustomConfigWidgets; + bool realTimeUpdates = false; + QHash widgetToConfigEntry; + QHash configEntryToWidgets; + QHash specialConfigEntryToWidgets; + bool updatingEntry = false; + QList extraWidgets; + QHash allEntries; + + static constexpr const char* CFG_MODEL_PROPERTY = "cfg"; + static constexpr const char* CFG_NOTIFY_PROPERTY = "notify"; + static constexpr const char* CFG_PREVIEW_PROPERTY = "preview"; + + private slots: + void handleModified(); + void entryChanged(const QVariant& newValue); + void uiConfigEntryChanged(); + void updateConfigComboModel(const QVariant& value); + void notifiableConfigKeyChanged(); + + signals: + void modified(); + void notifyEnabledWidgetModified(QWidget* widget, CfgEntry* key, const QVariant& value); +}; + +#endif // CONFIGMAPPER_H -- cgit v1.2.3