├── README.md
├── QSettingsDialog
├── resources
│ ├── gear_in.ico
│ └── setting_tools.ico
├── doc
│ ├── images
│ │ ├── mac_sample.png
│ │ ├── win_sample.png
│ │ ├── x11_sample.png
│ │ └── dialogwidget_button.png
│ └── modules_snippet.html
├── variantwidgets
│ ├── resources
│ │ ├── add.ico
│ │ ├── arrow_up.ico
│ │ ├── delete.ico
│ │ ├── arrow_down.ico
│ │ ├── calculator.ico
│ │ └── outlook_calendar_day.ico
│ ├── variantwidgets.pri
│ ├── settingscheckbox.cpp
│ ├── settingskeyedit.cpp
│ ├── settingscoloredit.cpp
│ ├── settingscheckbox.h
│ ├── settingsfontcombobox.cpp
│ ├── settingscoloredit.h
│ ├── settingskeyedit.h
│ ├── qsettingsdialog_variantwidgets_res.qrc
│ ├── settingsfontcombobox.h
│ ├── settingsslider.h
│ ├── settingsgroupbox.h
│ ├── settingsenumwidgetfactory.h
│ ├── settingsrichtextedit.h
│ ├── settingsgroupbox.cpp
│ ├── settingsflagschecklist.h
│ ├── settingspathedit.h
│ ├── settingsdatetimeedit.h
│ ├── private.pri
│ ├── grp_variantwidgets.dox
│ ├── variantwidgetsregistrator.h
│ ├── settingsspinbox.h
│ ├── settingsspinbox.cpp
│ ├── settingsenumwidgetfactory.cpp
│ ├── settingslistedit.h
│ ├── qsettingsextendedtypes.h
│ ├── settingsslider.cpp
│ ├── settingslineedit.h
│ ├── settingspathedit.cpp
│ ├── settingsenumcombobox.h
│ ├── settingsflagschecklist.cpp
│ ├── settingsdatetimeedit.cpp
│ ├── settingsrichtextedit.cpp
│ ├── settingslineedit.cpp
│ ├── settingslistedit.cpp
│ ├── settingsenumcombobox.cpp
│ ├── variantwidgetsregistrator.cpp
│ └── settingslistedit.ui
├── loaders
│ ├── private.pri
│ ├── loaders.pri
│ ├── grp_loaders.dox
│ ├── qsettingspropertyloader.dox
│ ├── qsettingssettingsloader.h
│ ├── qsettingspropertyloader.h
│ ├── qsettingssettingsloader.dox
│ ├── qsettingspropertyentry.cpp
│ ├── qsettingssettingsloader.cpp
│ ├── qsettingspropertyloader.cpp
│ └── qsettingspropertyentry.h
├── submodules
│ └── submodules.pri
├── qsettingsdialog_res.qrc
├── core
│ ├── container_path_syntax.txt
│ ├── exceptions.cpp
│ ├── qsettingsloader.cpp
│ ├── private.pri
│ ├── core.pri
│ ├── qsettingsentry.dox
│ ├── qsettingsentry_p.h
│ ├── settingspathparser.h
│ ├── exceptions.h
│ ├── grp_core.dox
│ ├── qasyncsettingscontainer_p.h
│ ├── qsettingsdialog_p.h
│ ├── qsettingsloaderentry.h
│ ├── qsettingsdisplayengine.h
│ ├── containerelements.h
│ ├── qasyncsettingscontainer.h
│ ├── qasyncsettingscontainer.dox
│ ├── qsettingsentry.cpp
│ ├── qsettingsloader.h
│ ├── qsettingsentry.h
│ ├── specialgroupmap.h
│ ├── settingspathparser.cpp
│ ├── qsettingsloader.dox
│ ├── qsettingslayout.h
│ └── qsettingsdialog.h
├── dialogui
│ ├── qsettingswidget.cpp
│ ├── qsettingsgroupwidgetfactory.dox
│ ├── private.pri
│ ├── commonfactoryregistry.h
│ ├── dialogui.pri
│ ├── commonfactoryregistry.cpp
│ ├── qsettingswidgetfactoryregistry.h
│ ├── grp_dialogui.dox
│ ├── qsettingsgroupwidgetfactory.h
│ ├── qsettingswidgetfactory.h
│ ├── qsettingsdialogwidget.cpp
│ ├── qsettingsdialogwidget.dox
│ ├── qsettingswidgetfactoryregistry.dox
│ ├── settingsengine.h
│ ├── qsettingswidgetfactory.dox
│ ├── qsettingswidget.h
│ ├── qsettingswidget.dox
│ ├── qsettingsgroupwidget.cpp
│ ├── checkinghelper.h
│ ├── qsettingsdialogwidget.h
│ ├── qsettingsgroupwidget.h
│ ├── settingsdisplaydialog.h
│ ├── qsettingsgroupwidget.dox
│ └── qsettingswidgetdialogengine.h
├── qtexception.cpp
├── qtexception.h
├── qsettingsdialog_global.cpp
├── qsettingsdialog.pri
├── generateIncludes.bat
├── qsettingsdialog_global.h
└── QSettingsDialog.pro
├── Examples
├── VariantWidgetsTest
│ ├── metawrapper.cpp
│ ├── VariantWidgetsTest.pro
│ └── metawrapper.h
├── Examples.pro
├── LoadersTest
│ ├── LoadersTest.pro
│ └── main.cpp
├── SimpleExample
│ ├── SimpleExample.pro
│ └── main.cpp
├── EngineTest
│ ├── testentry.h
│ ├── EngineTest.pro
│ ├── swidget.h
│ ├── delayedtestentry.h
│ ├── testentry.cpp
│ ├── swidget.cpp
│ └── delayedtestentry.cpp
└── loadLib.pri
├── QSettingsDialog.pro
├── .gitignore
├── .gitmodules
└── LICENSE
/README.md:
--------------------------------------------------------------------------------
1 | # QSettingsDialog
2 | Has been replaced by https://github.com/Skycoder42/QtMvvm
3 |
--------------------------------------------------------------------------------
/QSettingsDialog/resources/gear_in.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/resources/gear_in.ico
--------------------------------------------------------------------------------
/QSettingsDialog/doc/images/mac_sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/doc/images/mac_sample.png
--------------------------------------------------------------------------------
/QSettingsDialog/doc/images/win_sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/doc/images/win_sample.png
--------------------------------------------------------------------------------
/QSettingsDialog/doc/images/x11_sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/doc/images/x11_sample.png
--------------------------------------------------------------------------------
/QSettingsDialog/resources/setting_tools.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/resources/setting_tools.ico
--------------------------------------------------------------------------------
/Examples/VariantWidgetsTest/metawrapper.cpp:
--------------------------------------------------------------------------------
1 | #include "metawrapper.h"
2 |
3 | MetaWrapper::MetaWrapper(QObject *parent) : QObject(parent)
4 | {
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/resources/add.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/variantwidgets/resources/add.ico
--------------------------------------------------------------------------------
/QSettingsDialog/doc/images/dialogwidget_button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/doc/images/dialogwidget_button.png
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/resources/arrow_up.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/variantwidgets/resources/arrow_up.ico
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/resources/delete.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/variantwidgets/resources/delete.ico
--------------------------------------------------------------------------------
/QSettingsDialog/loaders/private.pri:
--------------------------------------------------------------------------------
1 | SOURCES += \
2 | $$PWD/qsettingspropertyloader.cpp \
3 | $$PWD/qsettingspropertyentry.cpp \
4 | $$PWD/qsettingssettingsloader.cpp
5 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/resources/arrow_down.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/variantwidgets/resources/arrow_down.ico
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/resources/calculator.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/variantwidgets/resources/calculator.ico
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/resources/outlook_calendar_day.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/HEAD/QSettingsDialog/variantwidgets/resources/outlook_calendar_day.ico
--------------------------------------------------------------------------------
/Examples/Examples.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = subdirs
2 |
3 | SUBDIRS += \
4 | EngineTest \
5 | VariantWidgetsTest \
6 | LoadersTest \
7 | SimpleExample
8 |
9 | OTHER_FILES += loadLib.pri
10 |
--------------------------------------------------------------------------------
/QSettingsDialog/submodules/submodules.pri:
--------------------------------------------------------------------------------
1 | #dialogui, variantwidgets
2 | include(./DialogMaster/dialogmaster.pri)
3 | #variantwidgets
4 | include(./QColorEdit/qcoloredit.pri)
5 | include(./QPathEdit/qpathedit.pri)
6 |
--------------------------------------------------------------------------------
/QSettingsDialog.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = subdirs
2 |
3 | SUBDIRS += \
4 | QSettingsDialog \
5 | Examples
6 |
7 | Examples.depends += QSettingsDialog
8 |
9 | DISTFILES += \
10 | README.md \
11 | LICENSE \
12 | ClassModel.qmodel
13 |
--------------------------------------------------------------------------------
/QSettingsDialog/qsettingsdialog_res.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | resources/setting_tools.ico
4 | resources/gear_in.ico
5 |
6 |
7 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/variantwidgets.pri:
--------------------------------------------------------------------------------
1 | HEADERS += $$PWD/variantwidgetsregistrator.h \
2 | $$PWD/qsettingsextendedtypes.h
3 |
4 | INCLUDEPATH += $$PWD
5 |
6 | include(private.pri)
7 |
8 | DISTFILES += \
9 | $$PWD/grp_variantwidgets.dox \
10 | $$PWD/variantwidgetsregistrator.dox
11 |
--------------------------------------------------------------------------------
/QSettingsDialog/doc/modules_snippet.html:
--------------------------------------------------------------------------------
1 |
2 | The following diagramm describes how the modules are connected with each other:
3 |
4 |

5 |
The Modules in a class diagram
6 |
--------------------------------------------------------------------------------
/QSettingsDialog/loaders/loaders.pri:
--------------------------------------------------------------------------------
1 | HEADERS += \
2 | $$PWD/qsettingspropertyloader.h \
3 | $$PWD/qsettingspropertyentry.h \
4 | $$PWD/qsettingssettingsloader.h
5 |
6 | INCLUDEPATH += $$PWD
7 |
8 | include(private.pri)
9 |
10 | DISTFILES += \
11 | $$PWD/grp_loaders.dox \
12 | $$PWD/qsettingspropertyloader.dox \
13 | $$PWD/qsettingssettingsloader.dox
14 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/container_path_syntax.txt:
--------------------------------------------------------------------------------
1 | default format:
2 | {categoryId}[/{sectionId}[/{groupId}]]
3 |
4 | allowed id charaters:
5 | 0..9 a..z A..Z _ -
6 | -> NO LEADING NUMBERS
7 |
8 | special characters:
9 | -> current element
10 | . -> default element
11 | / -> seperator between path elements
12 |
13 | special sequenzes:
14 | -> current path
15 | .. -> all default
16 |
17 |
--------------------------------------------------------------------------------
/Examples/LoadersTest/LoadersTest.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2016-06-26T14:28:48
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TARGET = LoadersTest
12 | TEMPLATE = app
13 |
14 | SOURCES += main.cpp
15 |
16 | include(../loadLib.pri)
17 |
--------------------------------------------------------------------------------
/Examples/SimpleExample/SimpleExample.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2016-07-04T21:07:49
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TARGET = SimpleExample
12 | TEMPLATE = app
13 |
14 | SOURCES += main.cpp
15 |
16 | include(../loadLib.pri)
17 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingswidget.cpp:
--------------------------------------------------------------------------------
1 | #include "qsettingswidget.h"
2 |
3 | QSettingsWidgetBase::QSettingsWidgetBase() :
4 | changedCache()
5 | {}
6 |
7 | QSettingsWidgetBase::~QSettingsWidgetBase() {}
8 |
9 | bool QSettingsWidgetBase::hasValueChanged() const
10 | {
11 | return (this->changedCache != this->getValue());
12 | }
13 |
14 | void QSettingsWidgetBase::resetValueChanged()
15 | {
16 | this->changedCache = this->getValue();
17 | }
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # C++ objects and libs
2 |
3 | *.slo
4 | *.lo
5 | *.o
6 | *.a
7 | *.la
8 | *.lai
9 | *.so
10 | *.dll
11 | *.dylib
12 |
13 | # Qt-es
14 |
15 | /.qmake.cache
16 | /.qmake.stash
17 | *.pro.user
18 | *.pro.user.*
19 | *.qbs.user
20 | *.qbs.user.*
21 | *.moc
22 | moc_*.cpp
23 | qrc_*.cpp
24 | ui_*.h
25 | Makefile*
26 | *build-*
27 |
28 | # QtCreator
29 |
30 | *.autosave
31 |
32 | #QtCtreator Qml
33 | *.qmlproject.user
34 | *.qmlproject.user.*
35 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "QSettingsDialog/DialogMaster"]
2 | path = QSettingsDialog/submodules/DialogMaster
3 | url = https://github.com/Skycoder42/DialogMaster.git
4 | [submodule "QSettingsDialog/QColorEdit"]
5 | path = QSettingsDialog/submodules/QColorEdit
6 | url = https://github.com/Skycoder42/QColorEdit.git
7 | [submodule "QSettingsDialog/QPathEdit"]
8 | path = QSettingsDialog/submodules/QPathEdit
9 | url = https://github.com/Skycoder42/QPathEdit.git
10 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingscheckbox.cpp:
--------------------------------------------------------------------------------
1 | #include "settingscheckbox.h"
2 |
3 | SettingsCheckBox::SettingsCheckBox(QWidget *parent) :
4 | QSettingsWidget(parent)
5 | {}
6 |
7 | void SettingsCheckBox::setValue(const QVariant &value)
8 | {
9 | this->setChecked(value.toBool());
10 | }
11 |
12 | QVariant SettingsCheckBox::getValue() const
13 | {
14 | return this->isChecked();
15 | }
16 |
17 | void SettingsCheckBox::resetValue()
18 | {
19 | this->setChecked(false);
20 | }
21 |
--------------------------------------------------------------------------------
/QSettingsDialog/qtexception.cpp:
--------------------------------------------------------------------------------
1 | #include "qtexception.h"
2 |
3 | QtException::QtException(const QString &what, int code) :
4 | std::exception(),
5 | error(what.toUtf8()),
6 | eCode(code)
7 | {}
8 |
9 | QString QtException::qWhat() const
10 | {
11 | return QString::fromUtf8(this->error);
12 | }
13 |
14 | int QtException::code() const
15 | {
16 | return this->eCode;
17 | }
18 |
19 | const char *QtException::what() const noexcept
20 | {
21 | return this->error.constData();
22 | }
23 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingskeyedit.cpp:
--------------------------------------------------------------------------------
1 | #include "settingskeyedit.h"
2 |
3 | SettingsKeyEdit::SettingsKeyEdit(QWidget *parent) :
4 | QSettingsWidget(parent)
5 | {}
6 |
7 | void SettingsKeyEdit::setValue(const QVariant &value)
8 | {
9 | this->setKeySequence(value.value());
10 | }
11 |
12 | QVariant SettingsKeyEdit::getValue() const
13 | {
14 | return this->keySequence();
15 | }
16 |
17 | void SettingsKeyEdit::resetValue()
18 | {
19 | this->clear();
20 | }
21 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingscoloredit.cpp:
--------------------------------------------------------------------------------
1 | #include "settingscoloredit.h"
2 |
3 | SettingsColorEdit::SettingsColorEdit(QWidget *parent) :
4 | QSettingsWidget(parent)
5 | {}
6 |
7 | void SettingsColorEdit::setValue(const QVariant &value)
8 | {
9 | this->setColor(value.value());
10 | }
11 |
12 | QVariant SettingsColorEdit::getValue() const
13 | {
14 | return this->color();
15 | }
16 |
17 | void SettingsColorEdit::resetValue()
18 | {
19 | this->setColor(QColor());
20 | }
21 |
--------------------------------------------------------------------------------
/Examples/VariantWidgetsTest/VariantWidgetsTest.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2016-06-19T11:08:30
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TARGET = VariantWidgetsTest
12 | TEMPLATE = app
13 |
14 |
15 | SOURCES += main.cpp \
16 | metawrapper.cpp
17 |
18 | HEADERS += \
19 | metawrapper.h
20 |
21 | include(../loadLib.pri)
22 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingsgroupwidgetfactory.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @class QSettingsGroupWidgetFactory
3 |
4 | For each kind of group widget you want, create a factory and register this factory for a display id using
5 | QSettingsWidgetDialogEngine::addGroupFactory.
6 |
7 | @note Use this class only if you need a special way to create the widgets. If all you need is a `new MyCustomGroup(parent);`,
8 | simply use QSettingsWidgetDialogEngine::addGroupWidgetType instead of creating a new factory implementation.
9 | */
10 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingscheckbox.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSCHECKBOX_H
2 | #define SETTINGSCHECKBOX_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 |
7 | class SettingsCheckBox : public QSettingsWidget
8 | {
9 | public:
10 | SettingsCheckBox(QWidget *parent = nullptr);
11 |
12 | // QSettingsWidgetBase interface
13 | void setValue(const QVariant &value) override;
14 | QVariant getValue() const override;
15 | void resetValue() override;
16 | };
17 |
18 | #endif // SETTINGSCHECKBOX_H
19 |
--------------------------------------------------------------------------------
/Examples/EngineTest/testentry.h:
--------------------------------------------------------------------------------
1 | #ifndef TESTENTRY_H
2 | #define TESTENTRY_H
3 |
4 | #include
5 |
6 | class TestEntry : public QSettingsLoaderEntry
7 | {
8 | public:
9 | TestEntry(bool optional, bool working, QVariant data = QVariant());
10 |
11 | bool load(QVariant outParam data, bool outParam userEdited) override;
12 | bool save(const QVariant &data) override;
13 | bool reset() override;
14 |
15 | private:
16 | QVariant origData;
17 | QVariant data;
18 | };
19 |
20 | #endif // TESTENTRY_H
21 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/private.pri:
--------------------------------------------------------------------------------
1 | HEADERS += \
2 | $$PWD/settingsdisplaydialog.h \
3 | $$PWD/settingsengine.h \
4 | $$PWD/checkinghelper.h \
5 | $$PWD/commonfactoryregistry.h
6 |
7 | SOURCES += \
8 | $$PWD/qsettingswidget.cpp \
9 | $$PWD/settingsdisplaydialog.cpp \
10 | $$PWD/settingsengine.cpp \
11 | $$PWD/qsettingswidgetdialogengine.cpp \
12 | $$PWD/commonfactoryregistry.cpp \
13 | $$PWD/qsettingsdialogwidget.cpp \
14 | $$PWD/qsettingsgroupwidget.cpp
15 |
16 | FORMS += \
17 | $$PWD/settingsdisplaydialog.ui
18 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsfontcombobox.cpp:
--------------------------------------------------------------------------------
1 | #include "settingsfontcombobox.h"
2 |
3 | SettingsFontComboBox::SettingsFontComboBox(QWidget *parent) :
4 | QSettingsWidget(parent)
5 | {}
6 |
7 | void SettingsFontComboBox::setValue(const QVariant &value)
8 | {
9 | this->setCurrentFont(value.value());
10 | }
11 |
12 | QVariant SettingsFontComboBox::getValue() const
13 | {
14 | return this->currentFont();
15 | }
16 |
17 | void SettingsFontComboBox::resetValue()
18 | {
19 | this->setCurrentIndex(-1);
20 | }
21 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingscoloredit.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSCOLOREDIT_H
2 | #define SETTINGSCOLOREDIT_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 |
7 | class SettingsColorEdit : public QSettingsWidget
8 | {
9 | public:
10 | SettingsColorEdit(QWidget *parent = nullptr);
11 |
12 | // QSettingsWidgetBase interface
13 | void setValue(const QVariant &value) override;
14 | QVariant getValue() const override;
15 | void resetValue() override;
16 | };
17 |
18 | #endif // SETTINGSCOLOREDIT_H
19 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingskeyedit.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSKEYEDIT_H
2 | #define SETTINGSKEYEDIT_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 |
7 | class SettingsKeyEdit : public QSettingsWidget
8 | {
9 | public:
10 | SettingsKeyEdit(QWidget *parent = nullptr);
11 |
12 | // QSettingsWidgetBase interface
13 | void setValue(const QVariant &value) override;
14 | QVariant getValue() const override;
15 | void resetValue() override;
16 | };
17 |
18 | #endif // SETTINGSKEYEDIT_H
19 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/exceptions.cpp:
--------------------------------------------------------------------------------
1 | #include "exceptions.h"
2 |
3 | InvalidContainerPathException::InvalidContainerPathException() :
4 | QtException("Invalid container format!")
5 | {}
6 |
7 | LayoutPropertyNotDefinedException::LayoutPropertyNotDefinedException() :
8 | QtException("The layout property you are trying to access is not defined for the current layout type")
9 | {}
10 |
11 | InvalidTargetLayoutException::InvalidTargetLayoutException() :
12 | QtException("The target layout container is either empty or of an invalid layout type")
13 | {}
14 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/qsettingsdialog_variantwidgets_res.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | resources/delete.ico
4 | resources/add.ico
5 | resources/arrow_down.ico
6 | resources/arrow_up.ico
7 | resources/calculator.ico
8 | resources/outlook_calendar_day.ico
9 |
10 |
11 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsfontcombobox.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSFONTCOMBOBOX_H
2 | #define SETTINGSFONTCOMBOBOX_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 |
7 | class SettingsFontComboBox : public QSettingsWidget
8 | {
9 | public:
10 | SettingsFontComboBox(QWidget *parent = nullptr);
11 |
12 | // QSettingsWidgetBase interface
13 | void setValue(const QVariant &value) override;
14 | QVariant getValue() const override;
15 | void resetValue() override;
16 | };
17 |
18 | #endif // SETTINGSFONTCOMBOBOX_H
19 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsslider.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSSLIDER_H
2 | #define SETTINGSSLIDER_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 |
7 | class SettingsSlider : public QSettingsWidget
8 | {
9 | Q_OBJECT
10 |
11 | public:
12 | SettingsSlider(QWidget *parent = nullptr);
13 |
14 | // QSettingsWidgetBase interface
15 | void setValue(const QVariant &value) override;
16 | QVariant getValue() const override;
17 | void resetValue() override;
18 |
19 | private slots:
20 | void showValue();
21 | };
22 |
23 | #endif // SETTINGSSLIDER_H
24 |
--------------------------------------------------------------------------------
/Examples/EngineTest/EngineTest.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2016-06-05T16:00:06
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui concurrent
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TARGET = EngineTest
12 | TEMPLATE = app
13 |
14 | SOURCES += main.cpp \
15 | testentry.cpp \
16 | delayedtestentry.cpp \
17 | swidget.cpp
18 |
19 | HEADERS += \
20 | testentry.h \
21 | delayedtestentry.h \
22 | swidget.h
23 |
24 | include(../loadLib.pri)
25 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qsettingsloader.cpp:
--------------------------------------------------------------------------------
1 | #include "qsettingsloader.h"
2 |
3 | QSettingsLoader::QSettingsLoader() {}
4 |
5 | QSimpleSettingsLoader *QSettingsLoader::simple()
6 | {
7 | return safe_cast(this);
8 | }
9 |
10 | QAsyncSettingsLoader *QSettingsLoader::async()
11 | {
12 | return safe_cast(this);
13 | }
14 |
15 | bool QSimpleSettingsLoader::isAsync() const
16 | {
17 | return false;
18 | }
19 |
20 | bool QAsyncSettingsLoader::isAsync() const
21 | {
22 | return true;
23 | }
24 |
25 | QAsyncSettingsLoader::QAsyncSettingsLoader() :
26 | QObject(nullptr),
27 | QSettingsLoader()
28 | {}
29 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/private.pri:
--------------------------------------------------------------------------------
1 | HEADERS += \
2 | $$PWD/qsettingsdialog_p.h \
3 | $$PWD/containerelements.h \
4 | $$PWD/settingspathparser.h \
5 | $$PWD/sortedmap.h \
6 | $$PWD/specialgroupmap.h \
7 | $$PWD/qsettingslayout_p.h \
8 | $$PWD/qsettingsentry_p.h \
9 | $$PWD/qasyncsettingscontainer_p.h
10 |
11 | SOURCES += \
12 | $$PWD/qsettingsloader.cpp \
13 | $$PWD/qsettingsdialog.cpp \
14 | $$PWD/settingspathparser.cpp \
15 | $$PWD/qsettingscontainer.cpp \
16 | $$PWD/exceptions.cpp \
17 | $$PWD/specialgroupmap.cpp \
18 | $$PWD/qsettingslayout.cpp \
19 | $$PWD/qsettingsentry.cpp \
20 | $$PWD/qasyncsettingscontainer.cpp
21 |
--------------------------------------------------------------------------------
/Examples/VariantWidgetsTest/metawrapper.h:
--------------------------------------------------------------------------------
1 | #ifndef METAWRAPPER_H
2 | #define METAWRAPPER_H
3 |
4 | #include
5 |
6 | class MetaWrapper : public QObject
7 | {
8 | Q_OBJECT
9 | public:
10 | enum TestEnum {
11 | Value0,
12 | Value1,
13 | Value2,
14 | Value3,
15 | Value42 = 42
16 | };
17 | Q_ENUM(TestEnum)
18 |
19 | enum TestFlag {
20 | Flag0 = 0x00,
21 | Flag1 = 0x01,
22 | Flag2 = 0x02,
23 | Flag3 = (Flag1 | Flag2),
24 | Flag8 = 0x08,
25 | Flag16 = 0x10,
26 | Flag34 = (0x20 | Flag2)
27 | };
28 | Q_DECLARE_FLAGS(TestFlags, TestFlag)
29 | Q_FLAG(TestFlags)
30 |
31 | explicit MetaWrapper(QObject *parent = 0);
32 | };
33 |
34 | #endif // METAWRAPPER_H
35 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/core.pri:
--------------------------------------------------------------------------------
1 | HEADERS += \
2 | $$PWD/qsettingsentry.h \
3 | $$PWD/qsettingsloader.h \
4 | $$PWD/qsettingsloaderentry.h \
5 | $$PWD/qsettingsdialog.h \
6 | $$PWD/qsettingscontainer.h \
7 | $$PWD/exceptions.h \
8 | $$PWD/qsettingslayout.h \
9 | $$PWD/qsettingsdisplayengine.h \
10 | $$PWD/qasyncsettingscontainer.h
11 |
12 | DISTFILES += \
13 | $$PWD/container_path_syntax.txt \
14 | $$PWD/grp_core.dox \
15 | $$PWD/qsettingsloader.dox \
16 | $$PWD/qsettingsdialog.dox \
17 | $$PWD/qsettingsentry.dox \
18 | $$PWD/qsettingslayout.dox \
19 | $$PWD/qsettingscontainer.dox \
20 | $$PWD/qasyncsettingscontainer.dox
21 |
22 | INCLUDEPATH += $$PWD
23 |
24 | include(private.pri)
25 |
--------------------------------------------------------------------------------
/QSettingsDialog/loaders/grp_loaders.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @defgroup grp_loaders Loaders
3 |
4 | @brief The loaders module contains the basic loader classes
5 |
6 | This module contains predefined loaders for the most common settings sources: Object-Properties and a settings file.
7 |
8 | ### Core Structure
9 | The following diagramm describes the Loaders structure. **Bold** classes are the most important ones for you as an api user:
10 |
11 | @image html structure_loaders.svg "The Loaders-Structure in a class diagram"
12 |
13 | ### Examples
14 | The core can be found in any of the default examples, but all of it's features are tested out in the LoadersTest. Use this
15 | example if you interested in all the feature of the Loaders.
16 | */
17 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qsettingsentry.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @class QSettingsEntry
3 |
4 | Each entry contains data about how to be displayed, as well as a QSettingsLoader, that will be used tu load/save the actual settings data.
5 |
6 | Most of the entries functions are focus around it's appeareance - the display name, a tooltip, ... - two of those are special. The first one is
7 | the QSettingsEntry::displayType. By default, it can be set via the constructor and read with that function. The display id will be used to determine the edit
8 | widget of entry. Together with this come the QSettingsEntry::uiProperties (as well as QSettingsEntry::setUiProperties and QSettingsEntry::setUiProperty). These
9 | can be used to set properties for that edit widget.
10 | */
11 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/commonfactoryregistry.h:
--------------------------------------------------------------------------------
1 | #ifndef COMMONFACTORYREGISTRY_H
2 | #define COMMONFACTORYREGISTRY_H
3 |
4 | #include "qsettingswidgetfactoryregistry.h"
5 |
6 | class CommonFactoryRegistry : public QSettingsWidgetFactoryRegistry
7 | {
8 | public:
9 | CommonFactoryRegistry();
10 |
11 | static void addGlobalFactory(int id, QSettingsWidgetFactory *factory);
12 |
13 | void insertFactory(int id, QSettingsWidgetFactory *factory);
14 | QSharedPointer tryResolve(int displayId) override;
15 |
16 | private:
17 | static QHash> globalFactories;
18 |
19 | QHash> factoryMap;
20 | };
21 |
22 |
23 |
24 | #endif // COMMONFACTORYREGISTRY_H
25 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/dialogui.pri:
--------------------------------------------------------------------------------
1 | HEADERS += \
2 | $$PWD/qsettingswidget.h \
3 | $$PWD/qsettingswidgetdialogengine.h \
4 | $$PWD/qsettingswidgetfactory.h \
5 | $$PWD/qsettingswidgetfactoryregistry.h \
6 | $$PWD/qsettingsdialogwidget.h \
7 | $$PWD/qsettingsgroupwidget.h \
8 | $$PWD/qsettingsgroupwidgetfactory.h
9 |
10 | INCLUDEPATH += $$PWD
11 |
12 | include(private.pri)
13 |
14 | DISTFILES += \
15 | $$PWD/grp_dialogui.dox \
16 | $$PWD/qsettingswidget.dox \
17 | $$PWD/qsettingswidgetfactory.dox \
18 | $$PWD/qsettingswidgetfactoryregistry.dox \
19 | $$PWD/qsettingsdialogwidget.dox \
20 | $$PWD/qsettingsgroupwidget.dox \
21 | $$PWD/qsettingsgroupwidgetfactory.dox \
22 | $$PWD/qsettingswidgetdialogengine.dox
23 |
--------------------------------------------------------------------------------
/Examples/EngineTest/swidget.h:
--------------------------------------------------------------------------------
1 | #ifndef SWIDGET_H
2 | #define SWIDGET_H
3 |
4 | #include
5 | #include
6 |
7 | class SFactory : public QSettingsWidgetFactory
8 | {
9 | public:
10 | SFactory(bool isDelayed);
11 | QSettingsWidgetBase *createWidget(QWidget *parent) override;
12 |
13 | private:
14 | bool isDelayed;
15 | };
16 |
17 | class SWidget : public QSettingsWidget
18 | {
19 | public:
20 | SWidget(QWidget *parent, bool ttip, QString pattern = QString());
21 |
22 | void setValue(const QVariant &value) override;
23 | QVariant getValue() const override;
24 | void resetValue() override;
25 | bool searchExpression(const QRegularExpression ®ex) override;
26 |
27 | private:
28 | QString pattern;
29 | };
30 |
31 | #endif // SWIDGET_H
32 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/commonfactoryregistry.cpp:
--------------------------------------------------------------------------------
1 | #include "commonfactoryregistry.h"
2 |
3 | QHash> CommonFactoryRegistry::globalFactories;
4 |
5 | CommonFactoryRegistry::CommonFactoryRegistry() :
6 | factoryMap(globalFactories)
7 | {}
8 |
9 | void CommonFactoryRegistry::addGlobalFactory(int id, QSettingsWidgetFactory *factory)
10 | {
11 | globalFactories.insert(id, QSharedPointer(factory));
12 | }
13 |
14 | void CommonFactoryRegistry::insertFactory(int id, QSettingsWidgetFactory *factory)
15 | {
16 | this->factoryMap.insert(id, QSharedPointer(factory));
17 | }
18 |
19 | QSharedPointer CommonFactoryRegistry::tryResolve(int displayId)
20 | {
21 | return this->factoryMap.value(displayId);
22 | }
23 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsgroupbox.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSGROUPBOX_H
2 | #define SETTINGSGROUPBOX_H
3 |
4 | #include "qsettingsgroupwidget.h"
5 | #include
6 | #include
7 |
8 | class SettingsGroupBox : public QSettingsGroupWidget
9 | {
10 | public:
11 | SettingsGroupBox(QWidget *parent = nullptr);
12 |
13 | // QSettingsGroupWidgetBase interface
14 | void setName(const QString &name) override;
15 | void setTooltip(const QString &tooltip) override;
16 | void setOptional(bool optional) override;
17 | bool isChecked() const override;
18 | void setChecked(bool checked) override;
19 |
20 | protected:
21 | void addWidgetWithLabel(QWidget *label, QWidget *content) override;
22 |
23 | private:
24 | QFormLayout *layout;
25 | };
26 |
27 | #endif // SETTINGSGROUPBOX_H
28 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingswidgetfactoryregistry.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSWIDGETFACTORYREGISTRY_H
2 | #define QSETTINGSWIDGETFACTORYREGISTRY_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include "qsettingswidgetfactory.h"
6 | #include
7 |
8 | //! A registry to load widget factories based on an id. @ingroup grp_dialogui
9 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsWidgetFactoryRegistry
10 | {
11 | public:
12 | //! Virtual Destructor
13 | inline virtual ~QSettingsWidgetFactoryRegistry() {}
14 |
15 | //! The prioritoy of this registry
16 | virtual inline int priority() const {
17 | return 0;
18 | }
19 | //! Tries to find a registry for the given id
20 | virtual QSharedPointer tryResolve(int displayId) = 0;
21 | };
22 |
23 | #endif // QSETTINGSWIDGETFACTORYREGISTRY_H
24 |
--------------------------------------------------------------------------------
/Examples/EngineTest/delayedtestentry.h:
--------------------------------------------------------------------------------
1 | #ifndef DELAYEDTESTENTRY_H
2 | #define DELAYEDTESTENTRY_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | class DelayedTestEntry : public QAsyncSettingsLoader, public QSettingsEntry
10 | {
11 | Q_OBJECT
12 | public:
13 | explicit DelayedTestEntry(QVariant data, int delayMSecs);
14 |
15 | // QSettingsEntry interface
16 | public:
17 | QSettingsLoader *getLoader() final;
18 | void freeLoader(QSettingsLoader *loader) final;
19 |
20 | // QAsyncSettingsLoader interface
21 | public slots:
22 | void loadData() override;
23 | void saveData(const QVariant &data) override;
24 | void resetData() override;
25 |
26 | private:
27 | QVariant data;
28 | int delayMSecs;
29 | };
30 |
31 | #endif // DELAYEDTESTENTRY_H
32 |
--------------------------------------------------------------------------------
/Examples/loadLib.pri:
--------------------------------------------------------------------------------
1 | win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../QSettingsDialog/release/ -lQSettingsDialog
2 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../QSettingsDialog/debug/ -lQSettingsDialog
3 | else:mac {
4 | QMAKE_LFLAGS += -F$$OUT_PWD/../../QSettingsDialog/
5 | QMAKE_LFLAGS += '-Wl,-rpath,\'@executable_path/../../../../../QSettingsDialog\''
6 | LIBS += -F$$OUT_PWD/../../QSettingsDialog/ -framework QSettingsDialog
7 | } else:unix: LIBS += -L$$OUT_PWD/../../QSettingsDialog/ -lQSettingsDialog
8 |
9 | INCLUDEPATH += $$PWD/../QSettingsDialog
10 | INCLUDEPATH += $$PWD/../QSettingsDialog/core
11 | INCLUDEPATH += $$PWD/../QSettingsDialog/dialogui
12 | INCLUDEPATH += $$PWD/../QSettingsDialog/loaders
13 | INCLUDEPATH += $$PWD/../QSettingsDialog/variantwidgets
14 | DEPENDPATH += $$PWD/../QSettingsDialog
15 |
--------------------------------------------------------------------------------
/QSettingsDialog/qtexception.h:
--------------------------------------------------------------------------------
1 | #ifndef QTEXCEPTION_H
2 | #define QTEXCEPTION_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include
6 | #include
7 |
8 | //! A basic exception type for Qt Exceptions
9 | class QSETTINGSDIALOGSHARED_EXPORT QtException : public std::exception
10 | {
11 | public:
12 | //! Creates a new QtException from an error messsage and an error code
13 | QtException(const QString &what = QString(), int code = 0);
14 |
15 | //! Returns the error string of the exception
16 | QString qWhat() const;
17 | //! Returns the error code of the exception
18 | int code() const;
19 | //! Returns the error string of the exception as charactar array
20 | const char *what() const noexcept final;
21 |
22 | private:
23 | const QByteArray error;
24 | const int eCode;
25 | };
26 |
27 | #endif // QTEXCEPTION_H
28 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qsettingsentry_p.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSENTRY_P_H
2 | #define QSETTINGSENTRY_P_H
3 |
4 | #include "qsettingsentry.h"
5 |
6 | class QSettingsEntryPrivate
7 | {
8 | public:
9 | struct LoaderDeleter {
10 | static void cleanup(QSettingsLoader *loader);
11 | };
12 |
13 | inline QSettingsEntryPrivate(int displaytype, QSettingsLoader *loader) :
14 | displaytype(displaytype),
15 | loader(loader),
16 | name(),
17 | optional(),
18 | tooltip(),
19 | properties()
20 | #ifndef QT_NO_DEBUG
21 | ,refCounter(0)
22 | #endif
23 | {}
24 |
25 | const int displaytype;
26 | QScopedPointer loader;
27 |
28 | QString name;
29 | bool optional;
30 | QString tooltip;
31 |
32 | UiPropertyMap properties;
33 |
34 | #ifndef QT_NO_DEBUG
35 | int refCounter;
36 | #endif
37 | };
38 |
39 | #endif // QSETTINGSENTRY_P_H
40 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsenumwidgetfactory.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSENUMWIDGETFACTORY_H
2 | #define SETTINGSENUMWIDGETFACTORY_H
3 |
4 | #include "qsettingswidgetfactoryregistry.h"
5 | #include
6 | #include
7 |
8 | class SettingsEnumWidgetFactory : public QSettingsWidgetFactory
9 | {
10 | public:
11 | SettingsEnumWidgetFactory(const QMetaEnum &metaEnum);
12 |
13 | // QSettingsWidgetFactory interface
14 | QSettingsWidgetBase *createWidget(QWidget *parent) override;
15 |
16 | private:
17 | QMetaEnum metaEnum;
18 | };
19 |
20 | class SettingsEnumWidgetRegistry : public QSettingsWidgetFactoryRegistry
21 | {
22 | public:
23 | // QSettingsWidgetFactoryRegistry interface
24 | int priority() const override;
25 | QSharedPointer tryResolve(int displayId) override;
26 | };
27 |
28 | #endif // SETTINGSENUMWIDGETFACTORY_H
29 |
--------------------------------------------------------------------------------
/Examples/EngineTest/testentry.cpp:
--------------------------------------------------------------------------------
1 | #include "testentry.h"
2 | #include
3 | #include "swidget.h"
4 |
5 | TestEntry::TestEntry(bool optional, bool working, QVariant data) :
6 | QSettingsLoaderEntry(working ? 0 : -1),
7 | origData(data),
8 | data(data)
9 | {
10 | this->setEntryName("Test Entry");
11 | this->setOptional(optional);
12 | this->setTooltip("Baum == 42");
13 | }
14 |
15 | bool TestEntry::load(QVariant outParam data, bool outParam userEdited)
16 | {
17 | userEdited = !this->data.isNull();
18 | data = this->data;
19 | return true;
20 | }
21 |
22 | bool TestEntry::save(const QVariant &data)
23 | {
24 | qDebug() << "SAVING from" << this->data << "to" << data;
25 | this->data = data;
26 | return true;
27 | }
28 |
29 | bool TestEntry::reset()
30 | {
31 | qDebug() << "RESETTING to" << this->origData;
32 | this->data = this->origData;
33 | return true;
34 | }
35 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsrichtextedit.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSRICHTEXTEDIT_H
2 | #define SETTINGSRICHTEXTEDIT_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 | #include
7 | #include
8 |
9 | class SettingsRichTextEdit : public QSettingsWidget
10 | {
11 | Q_OBJECT
12 |
13 | public:
14 | SettingsRichTextEdit(QWidget *parent = nullptr);
15 |
16 | // QSettingsWidgetBase interface
17 | void setValue(const QVariant &value) override;
18 | QVariant getValue() const override;
19 | void resetValue() override;
20 |
21 | protected:
22 | void contextMenuEvent(QContextMenuEvent *e) override;
23 |
24 | private slots:
25 | void updateActionsStatus();
26 | void editFont();
27 | void editColor();
28 |
29 | private:
30 | QAction *boldAction;
31 | QAction *italicAction;
32 | QAction *underlinedAction;
33 | };
34 |
35 | #endif // SETTINGSRICHTEXTEDIT_H
36 |
--------------------------------------------------------------------------------
/Examples/EngineTest/swidget.cpp:
--------------------------------------------------------------------------------
1 | #include "swidget.h"
2 |
3 | SWidget::SWidget(QWidget *parent, bool ttip, QString pattern) :
4 | QSettingsWidget(parent),
5 | pattern(pattern)
6 | {
7 | if(ttip)
8 | this->setToolTip("Mikeichalt");
9 | }
10 |
11 | void SWidget::setValue(const QVariant &value)
12 | {
13 | this->setText(value.toString());
14 | }
15 |
16 | QVariant SWidget::getValue() const
17 | {
18 | return this->text();
19 | }
20 |
21 | void SWidget::resetValue()
22 | {
23 | this->clear();
24 | }
25 |
26 | bool SWidget::searchExpression(const QRegularExpression ®ex)
27 | {
28 | return regex.match(pattern).hasMatch();
29 | }
30 |
31 |
32 |
33 | SFactory::SFactory(bool isDelayed) :
34 | isDelayed(isDelayed)
35 | {}
36 |
37 | QSettingsWidgetBase *SFactory::createWidget(QWidget *parent)
38 | {
39 | if(this->isDelayed)
40 | return new SWidget(parent, true, "qu");
41 | else
42 | return new SWidget(parent, false);
43 | }
44 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/settingspathparser.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSPATHPARSER_H
2 | #define SETTINGSPATHPARSER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include "qsettingsdialog.h"
8 |
9 | class SettingsPathParser
10 | {
11 | public:
12 | static void validateId(const QString &id, bool realIdOnly);
13 | static QVector parseFullPath(const QString &path);
14 | static QStringList parsePartialPath(const QString &path);
15 |
16 | static QString createPath(const QString &categoryId, const QString §ionId, const QString &groupId = QString());
17 | static QString joinPath(const QString §ionPath, const QString &groupId);
18 |
19 | private:
20 | static const QRegularExpression realIdRegex;
21 | static const QRegularExpression allIdRegex;
22 | static const QRegularExpression fullPathRegex;
23 | static const QRegularExpression fullSectionPathRegex;
24 | static const QRegularExpression partialPathRegex;
25 | };
26 |
27 | #endif // SETTINGSPATHPARSER_H
28 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/grp_dialogui.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @defgroup grp_dialogui Dialog-UI
3 |
4 | @brief The display module of the dialog library
5 |
6 | The Dialog-UI part of the library is responsible for creating the actual visible dialog from the cores data. This module defines
7 | the QSettingsWidgetDialogEngine that will be used as default engine by the QSettingsDialog for dialog creation. The most important
8 | part of this engine are it's add/registery functions, that allow you to define custom edit widgets and group widgets.
9 |
10 | ### Dialog-UI Structure
11 | The following diagramm describes the Dialog-UI structure. **Bold** classes are the most important ones for you as an api user:
12 |
13 | @image html structure_dialogui.svg "The Dialog-UI-Structure in a class diagram"
14 |
15 | ### Examples
16 | The core can be found in any of the default examples, but all of it's features are tested out in the EngineTest and the VariantWidgetsTest. Use these
17 | examples if you interested in all the feature of the Dialog-UI.
18 | */
19 |
--------------------------------------------------------------------------------
/QSettingsDialog/loaders/qsettingspropertyloader.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @class QSettingsPropertyLoader
3 |
4 | The loader can be created on any QObject or any class marked as #Q_GADGET. It relays the dialogs loading calls to read and write
5 | a specific property on that object/gadget. The loader is an async loader and thus can be created on any thread. This allows you to load
6 | properties from object on any thread, without having to care about synchronisation or other thread problems.
7 |
8 | @attention The loader must **always** live on the same thread as the object it was created for. It thats not the case, your application
9 | will most likely crash!
10 | */
11 |
12 | /*!
13 | @fn QSettingsPropertyLoader::metatypeId
14 |
15 | @returns The properties metatype id.
16 |
17 | This function simply uses QMetaProperty::type (and QMetaProperty::userType) to get the type id for the property.
18 | This can be used with a settings entry, to find a fitting edit widget for that type. To simplify this,
19 | have a look a the QSettingsPropertyEntry.
20 | */
21 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/exceptions.h:
--------------------------------------------------------------------------------
1 | #ifndef EXCEPTIONS_H
2 | #define EXCEPTIONS_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include "qtexception.h"
6 |
7 | /*!
8 | * @addtogroup grp_core
9 | * @{
10 | */
11 |
12 | //! An exception that will be thrown if an invalid container path is used
13 | class QSETTINGSDIALOGSHARED_EXPORT InvalidContainerPathException : public QtException
14 | {
15 | public:
16 | InvalidContainerPathException();
17 | };
18 |
19 | //! An exception that indicates you are trying to access an undefined property in a QSettingsLayout
20 | class QSETTINGSDIALOGSHARED_EXPORT LayoutPropertyNotDefinedException : public QtException
21 | {
22 | public:
23 | LayoutPropertyNotDefinedException();
24 | };
25 |
26 | //! An exception that is thrown if you try to add an element to a QSettingsLayout that does not accept this kind of element
27 | class QSETTINGSDIALOGSHARED_EXPORT InvalidTargetLayoutException : public QtException
28 | {
29 | public:
30 | InvalidTargetLayoutException();
31 | };
32 | //! @}
33 |
34 | #endif // EXCEPTIONS_H
35 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingsgroupwidgetfactory.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSGROUPWIDGETFACTORY_H
2 | #define QSETTINGSGROUPWIDGETFACTORY_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include "qsettingsgroupwidget.h"
6 |
7 | //! The base class for a factory to create QSettingsGroupWidgets @ingroup grp_dialogui
8 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsGroupWidgetFactory
9 | {
10 | public:
11 | //! Virtual destructor
12 | inline virtual ~QSettingsGroupWidgetFactory() {}
13 |
14 | //! Creates a new instance of the group widget
15 | virtual QSettingsGroupWidgetBase *createGroupWidget(QWidget *parent) = 0;
16 | };
17 |
18 | //! @intuse Generic base class for a factory to create QSettingsWidgets @ingroup grp_dialogui
19 | template
20 | class GenericSettingsGroupWidgetFactory : public QSettingsGroupWidgetFactory
21 | {
22 | public:
23 | QSettingsGroupWidgetBase *createGroupWidget(QWidget *parent) final {
24 | return new TSettingsGroupWidget(parent);
25 | }
26 | };
27 |
28 | #endif // QSETTINGSGROUPWIDGETFACTORY_H
29 |
--------------------------------------------------------------------------------
/QSettingsDialog/qsettingsdialog_global.cpp:
--------------------------------------------------------------------------------
1 | #include "qsettingsdialog_global.h"
2 | #include "qasyncsettingscontainer_p.h"
3 | #include
4 |
5 | #include "variantwidgetsregistrator.h"
6 |
7 | void qSettingsDialogSetup()
8 | {
9 | qRegisterMetaType();
10 | qRegisterMetaType>();
11 | qRegisterMetaType();
12 |
13 | bool ok;
14 | auto loadMode = qEnvironmentVariableIntValue(VARIANT_WIDGETS_AUTOLOAD, &ok);
15 | if(!ok)
16 | loadMode = AUTOLOAD_GROUPS | AUTOLOAD_WIDGETS | AUTOLOAD_ENUMS | AUTOLOAD_EXTENDED;
17 |
18 | if(loadMode & AUTOLOAD_GROUPS)
19 | VariantWidgetsRegistrator::registerGroupWidgets();
20 | if(loadMode & AUTOLOAD_WIDGETS)
21 | VariantWidgetsRegistrator::registerVariantWidgets();
22 | if(loadMode & AUTOLOAD_ENUMS)
23 | VariantWidgetsRegistrator::registerEnumFactories();
24 | if(loadMode & AUTOLOAD_EXTENDED)
25 | VariantWidgetsRegistrator::registerExtendedVariantWidgets();
26 | }
27 |
28 | Q_COREAPP_STARTUP_FUNCTION(qSettingsDialogSetup)
29 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsgroupbox.cpp:
--------------------------------------------------------------------------------
1 | #include "settingsgroupbox.h"
2 | #include "checkinghelper.h"
3 |
4 | SettingsGroupBox::SettingsGroupBox(QWidget *parent) :
5 | QSettingsGroupWidget(parent),
6 | layout(new QFormLayout(this))
7 | {
8 | this->setLayout(this->layout);
9 | }
10 |
11 | void SettingsGroupBox::setName(const QString &name)
12 | {
13 | this->setTitle(name);
14 | }
15 |
16 | void SettingsGroupBox::setTooltip(const QString &tooltip)
17 | {
18 | this->setToolTip(tooltip);
19 | }
20 |
21 | void SettingsGroupBox::setOptional(bool optional)
22 | {
23 | this->setCheckable(optional);
24 | }
25 |
26 | bool SettingsGroupBox::isChecked() const
27 | {
28 | if(this->isCheckable())
29 | return this->QGroupBox::isChecked();
30 | else
31 | return true;
32 | }
33 |
34 | void SettingsGroupBox::setChecked(bool checked)
35 | {
36 | if(this->isCheckable())
37 | this->QGroupBox::setChecked(checked);
38 | }
39 |
40 |
41 | void SettingsGroupBox::addWidgetWithLabel(QWidget *label, QWidget *content)
42 | {
43 | this->layout->addRow(label, content);
44 | }
45 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsflagschecklist.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSFLAGSCHECKLIST_H
2 | #define SETTINGSFLAGSCHECKLIST_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 | #include
7 |
8 | class SettingsFlagsCheckList : public QSettingsWidget
9 | {
10 | Q_OBJECT
11 | Q_PROPERTY(bool translated READ translated WRITE setTranslated NOTIFY translatedChanged)
12 |
13 | public:
14 | SettingsFlagsCheckList(const QMetaEnum &metaEnum, QWidget *parent = nullptr);
15 |
16 | // QSettingsWidgetBase interface
17 | void setValue(const QVariant &value) override;
18 | QVariant getValue() const override;
19 | void resetValue() override;
20 |
21 | bool translated() const;
22 |
23 | public slots:
24 | void setTranslated(bool translated);
25 |
26 | signals:
27 | void translatedChanged(bool translated);
28 |
29 | private slots:
30 | void updateFlags(int value);
31 | void reloadFlags();
32 |
33 | private:
34 | QMetaEnum metaEnum;
35 | QButtonGroup *checkGroup;
36 | int currentFlags;
37 | bool m_translated;
38 | };
39 |
40 | #endif // SETTINGSFLAGSCHECKLIST_H
41 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/grp_core.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @defgroup grp_core Core
3 |
4 | @brief The core module of the dialog library
5 |
6 | The core module contains the part of the API that is used to manage the dialog, it's logic and organization. It's this part that you will
7 | use in most cases. The central class is the QSettingsDialog - It is used to create a settings dialog. Have a look at it's documentation.
8 | While the core api handles most of the organization, the actual creation and execution of the dialog does not happen here. This part is handled
9 | by the (exchangeable) @ref grp_dialogui "Dialog-UI". For more options on loaders, check the @ref grp_loaders "Loaders".
10 |
11 | ### Core Structure
12 | The following diagramm describes the core structure. **Bold** classes are the most important ones for you as an api user:
13 |
14 | @image html structure_core.svg "The Core-Structure in a class diagram"
15 |
16 | ### Examples
17 | The core can be found in any of the default examples, but all of it's features are tested out in the EngineTest. Use this
18 | example if you interested in all the feature of the core.
19 | */
20 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingspathedit.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSPATHEDIT_H
2 | #define SETTINGSPATHEDIT_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 |
7 | class SettingsPathEdit : public QSettingsWidget
8 | {
9 | public:
10 | SettingsPathEdit(QWidget *parent = nullptr);
11 |
12 | void setValue(const QVariant &value) override;
13 | QVariant getValue() const override;
14 | void resetValue() override;
15 | };
16 |
17 | class SettingsIconEdit : public QSettingsWidget
18 | {
19 | Q_OBJECT
20 | Q_PROPERTY(bool asQIcon READ asQIcon WRITE setAsQIcon NOTIFY asQIconChanged)
21 |
22 | public:
23 | SettingsIconEdit(QWidget *parent = nullptr);
24 |
25 | void setValue(const QVariant &value) override;
26 | QVariant getValue() const override;
27 | void resetValue() override;
28 | bool asQIcon() const;
29 |
30 | public slots:
31 | void setAsQIcon(bool asQIcon);
32 |
33 | signals:
34 | void asQIconChanged(bool asQIcon);
35 |
36 | private slots:
37 | void updateIcon(const QString &path);
38 |
39 | private:
40 | bool m_asQIcon;
41 | };
42 |
43 | #endif // SETTINGSPATHEDIT_H
44 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsdatetimeedit.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSDATEEDIT_H
2 | #define SETTINGSDATEEDIT_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 |
7 | class SettingsDateEdit : public QSettingsWidget
8 | {
9 | public:
10 | SettingsDateEdit(QWidget *parent = nullptr);
11 |
12 | // QSettingsWidgetBase interface
13 | void setValue(const QVariant &value) override;
14 | QVariant getValue() const override;
15 | void resetValue() override;
16 | };
17 |
18 | class SettingsTimeEdit : public QSettingsWidget
19 | {
20 | public:
21 | SettingsTimeEdit(QWidget *parent = nullptr);
22 |
23 | // QSettingsWidgetBase interface
24 | void setValue(const QVariant &value) override;
25 | QVariant getValue() const override;
26 | void resetValue() override;
27 | };
28 |
29 | class SettingsDateTimeEdit : public QSettingsWidget
30 | {
31 | public:
32 | SettingsDateTimeEdit(QWidget *parent = nullptr);
33 |
34 | // QSettingsWidgetBase interface
35 | void setValue(const QVariant &value) override;
36 | QVariant getValue() const override;
37 | void resetValue() override;
38 | };
39 |
40 | #endif // SETTINGSDATEEDIT_H
41 |
--------------------------------------------------------------------------------
/Examples/EngineTest/delayedtestentry.cpp:
--------------------------------------------------------------------------------
1 | #include "delayedtestentry.h"
2 | #include
3 | #include
4 | #include "swidget.h"
5 |
6 | DelayedTestEntry::DelayedTestEntry(QVariant data, int delayMSecs) :
7 | QAsyncSettingsLoader(),
8 | QSettingsEntry(1, nullptr),
9 | data(data),
10 | delayMSecs(delayMSecs)
11 | {
12 | this->setEntryName("Delayed Entry");
13 | this->setTooltip("Baum == 42");
14 | }
15 |
16 | QSettingsLoader *DelayedTestEntry::getLoader()
17 | {
18 | return this;
19 | }
20 |
21 | void DelayedTestEntry::freeLoader(QSettingsLoader *)
22 | {
23 | }
24 |
25 | void DelayedTestEntry::loadData()
26 | {
27 | QTimer::singleShot(this->delayMSecs, this, [=]() {
28 | emit loadDone(true, this->data, !this->data.isNull());
29 | });
30 | }
31 |
32 | void DelayedTestEntry::saveData(const QVariant &data)
33 | {
34 | QTimer::singleShot(this->delayMSecs, this, [=]() {
35 | qDebug() << "SAVING from" << this->data << "to" << data;
36 | emit saveDone(true);
37 | });
38 | }
39 |
40 | void DelayedTestEntry::resetData()
41 | {
42 | QTimer::singleShot(this->delayMSecs, this, [=]() {
43 | qDebug() << "RESETTING to" << this->data;
44 | emit resetDone(true);
45 | });
46 | }
47 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/private.pri:
--------------------------------------------------------------------------------
1 | HEADERS += \
2 | $$PWD/settingscheckbox.h \
3 | $$PWD/settingsspinbox.h \
4 | $$PWD/settingslineedit.h \
5 | $$PWD/settingsdatetimeedit.h \
6 | $$PWD/settingscoloredit.h \
7 | $$PWD/settingslistedit.h \
8 | $$PWD/settingsfontcombobox.h \
9 | $$PWD/settingskeyedit.h \
10 | $$PWD/settingsenumcombobox.h \
11 | $$PWD/settingsflagschecklist.h \
12 | $$PWD/settingsenumwidgetfactory.h \
13 | $$PWD/settingspathedit.h \
14 | $$PWD/settingsslider.h \
15 | $$PWD/settingsrichtextedit.h \
16 | $$PWD/settingsgroupbox.h
17 |
18 | SOURCES += $$PWD/variantwidgetsregistrator.cpp \
19 | $$PWD/settingscheckbox.cpp \
20 | $$PWD/settingsspinbox.cpp \
21 | $$PWD/settingslineedit.cpp \
22 | $$PWD/settingsdatetimeedit.cpp \
23 | $$PWD/settingscoloredit.cpp \
24 | $$PWD/settingslistedit.cpp \
25 | $$PWD/settingsfontcombobox.cpp \
26 | $$PWD/settingskeyedit.cpp \
27 | $$PWD/settingsenumcombobox.cpp \
28 | $$PWD/settingsflagschecklist.cpp \
29 | $$PWD/settingsenumwidgetfactory.cpp \
30 | $$PWD/settingspathedit.cpp \
31 | $$PWD/settingsslider.cpp \
32 | $$PWD/settingsrichtextedit.cpp \
33 | $$PWD/settingsgroupbox.cpp
34 |
35 | FORMS += \
36 | $$PWD/settingslistedit.ui
37 |
38 | RESOURCES += \
39 | $$PWD/qsettingsdialog_variantwidgets_res.qrc
40 |
--------------------------------------------------------------------------------
/Examples/LoadersTest/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | int main(int argc, char *argv[])
9 | {
10 | QApplication a(argc, argv);
11 | QApplication::setApplicationName("appname");
12 |
13 | QSettingsDialog dialog;
14 |
15 | QObject::connect(&dialog, &QSettingsDialog::saved, [](bool close) {
16 | qDebug() << "---- Save completed" << (close ? "with" : "without") << "closing ----";
17 | });
18 | QObject::connect(&dialog, &QSettingsDialog::resetted, []() {
19 | qDebug() << "---- Reset completed ----";
20 | });
21 | QObject::connect(&dialog, &QSettingsDialog::canceled, []() {
22 | qDebug() << "---- Dialog was canceled ----";
23 | });
24 |
25 | QObject::connect(qApp, &QApplication::applicationNameChanged, []() {
26 | qDebug() << "Name was changed!!! To" << QApplication::applicationName();
27 | });
28 |
29 | dialog.appendEntry(new QSettingsPropertyEntry("applicationName", qApp, "property"));
30 |
31 | QSettings settings(QApplication::applicationDirPath() + "/settings.ini", QSettings::IniFormat);
32 | dialog.appendEntry(new QSettingsEntry(QMetaType::QDateTime,
33 | new QSettingsSettingsLoader(&settings, "datetime"),
34 | "settings.ini"));
35 |
36 | dialog.openSettings();
37 | return a.exec();
38 | }
39 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/grp_variantwidgets.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @defgroup grp_variantwidgets Variant-Widgets
3 |
4 | @brief A module containing all default edit and group widgets
5 |
6 | This module is basically a collection of edit and group widgets. These widgets are organized into groups and can be added as global defaults
7 | to the engine, with the statuc VariantWidgetsRegistrator class.
8 |
9 | ### Extended Types
10 | The Variant-Widgets define three special types. These are mainly there to be used as types for special edit widgets. Each of those
11 | three types can be implicitly converted to it's base class and can be created from it's base. The types are:
12 | - FilePath -> uses a path edit (instead of a lineedit)
13 | - IntRange -> uses a slider (instead of a spinner)
14 | - HtmlText -> uses a rich text edit (instead of a lineedit)
15 | Check VariantWidgetsRegistrator::registerExtendedVariantWidgets for details on how to use them
16 |
17 | ### Core Structure
18 | The following diagramm describes the Variant-Widgets structure. **Bold** classes are the most important ones for you as an api user:
19 |
20 | @image html structure_variantwidgets.svg "The Variant-Widgets-Structure in a class diagram"
21 |
22 | ### Examples
23 | The core can be found in any of the default examples, but all of it's features are tested out in the VariantWidgetsTest. Use this
24 | example if you interested in all the feature of the Variant-Widgets.
25 | */
26 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/variantwidgetsregistrator.h:
--------------------------------------------------------------------------------
1 | #ifndef VARIANTWIDGETSREGISTRATOR_H
2 | #define VARIANTWIDGETSREGISTRATOR_H
3 |
4 | #include "qsettingsdialog_global.h"
5 |
6 | //! Enviroment variable name for autoload configuration @ingroup grp_variantwidgets
7 | #define VARIANT_WIDGETS_AUTOLOAD "env_qsettingsdialog_autoload"
8 | //! Enviroment variable value to autoload groups @ingroup grp_variantwidgets
9 | #define AUTOLOAD_GROUPS 0b1000
10 | //! Enviroment variable value to autoload default edit widgets @ingroup grp_variantwidgets
11 | #define AUTOLOAD_WIDGETS 0b0100
12 | //! Enviroment variable value to autoload enum factories @ingroup grp_variantwidgets
13 | #define AUTOLOAD_ENUMS 0b0010
14 | //! Enviroment variable value to autoload extended edit widgets @ingroup grp_variantwidgets
15 | #define AUTOLOAD_EXTENDED 0b0001
16 |
17 | //! A static class to globally register different types of edit widgets @ingroup grp_variantwidgets
18 | class QSETTINGSDIALOGSHARED_EXPORT VariantWidgetsRegistrator
19 | {
20 | public:
21 | //! Registeres the default group widgets
22 | static void registerGroupWidgets();
23 | //! Registeres the default edit widgets
24 | static void registerVariantWidgets();
25 | //! Registeres the enum and flag edit widget facotries
26 | static void registerEnumFactories();
27 | //! Registeres the extended edit widgets
28 | static void registerExtendedVariantWidgets();
29 | };
30 |
31 | #endif // VARIANTWIDGETSREGISTRATOR_H
32 |
--------------------------------------------------------------------------------
/QSettingsDialog/qsettingsdialog.pri:
--------------------------------------------------------------------------------
1 | CONFIG(debug, debug|release): CONFIG += add_rpath
2 |
3 | win32 {
4 | msvc {
5 | contains(QT_ARCH, x86_64) {
6 | CONFIG(release, debug|release): LIBS += -L$$PWD/msvc64/release/ -lQSettingsDialog
7 | else:CONFIG(debug, debug|release): LIBS += -L$$PWD/msvc64/debug/ -lQSettingsDialog
8 | } else {
9 | CONFIG(release, debug|release): LIBS += -L$$PWD/msvc/release/ -lQSettingsDialog
10 | else:CONFIG(debug, debug|release): LIBS += -L$$PWD/msvc/debug/ -lQSettingsDialog
11 | }
12 | }
13 | } else:mac:contains(QT_ARCH, x86_64) {
14 | CONFIG(release, debug|release) {
15 | QMAKE_LFLAGS += -F$$PWD/clang64/release/
16 | add_rpath: QMAKE_LFLAGS += '-Wl,-rpath,\'$$PWD/clang64/release\''
17 | LIBS += -F$$PWD/clang64/release/ -framework QSettingsDialog
18 | } else:CONFIG(debug, debug|release) {
19 | QMAKE_LFLAGS += -F$$PWD/clang64/debug/
20 | add_rpath: QMAKE_LFLAGS += '-Wl,-rpath,\'$$PWD/clang64/debug\''
21 | LIBS += -F$$PWD/clang64/debug/ -framework QSettingsDialog
22 | }
23 | } else:unix:!mac:contains(QT_ARCH, x86_64) {
24 | CONFIG(release, debug|release) {
25 | add_rpath: QMAKE_LFLAGS += '-Wl,-rpath,\'$$PWD/gcc64/release\''
26 | LIBS += -L$$PWD/gcc64/release/ -lQSettingsDialog
27 | } else:CONFIG(debug, debug|release) {
28 | add_rpath: QMAKE_LFLAGS += '-Wl,-rpath,\'$$PWD/gcc64/debug\''
29 | LIBS += -L$$PWD/gcc64/debug/ -lQSettingsDialog
30 | }
31 | }
32 |
33 | INCLUDEPATH += $$PWD/include
34 | DEPENDPATH += $$PWD/include
35 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qasyncsettingscontainer_p.h:
--------------------------------------------------------------------------------
1 | #ifndef QASYNCSETTINGSCONTAINER_P_H
2 | #define QASYNCSETTINGSCONTAINER_P_H
3 |
4 | #include "qsettingscontainer.h"
5 |
6 | class QAsyncSettingsContainerPrivate : public QObject
7 | {
8 | Q_OBJECT
9 |
10 | public:
11 | struct EntryInfo {
12 | bool isEntry;
13 | int id;
14 | int index;
15 | };
16 |
17 | QAsyncSettingsContainerPrivate(QSettingsDialog *settingsDialog, const QString &containerPath);
18 |
19 | QSettingsDialog *settingsDialog;
20 | const QString containerPath;
21 |
22 | Q_INVOKABLE int count() const;
23 | Q_INVOKABLE QAsyncSettingsContainerPrivate::EntryInfo entryInfoFromIndex(int index) const;
24 | Q_INVOKABLE QAsyncSettingsContainerPrivate::EntryInfo entryInfoFromId(int id) const;
25 |
26 | Q_INVOKABLE QSharedPointer getEntry(int val, bool isId) const;
27 |
28 | Q_INVOKABLE int insertEntry(int index, QSharedPointer entry);
29 |
30 | Q_INVOKABLE bool removeEntry(int val, bool isId);
31 | Q_INVOKABLE bool moveEntry(int indexFrom, int indexTo);
32 |
33 | private:
34 | QSettingsContainer *container;
35 |
36 | Q_INVOKABLE void init(QSettingsDialog *settingsDialog, const QString &containerPath, bool isGroup);
37 | };
38 |
39 | Q_DECLARE_METATYPE(QAsyncSettingsContainerPrivate::EntryInfo)
40 | Q_DECLARE_METATYPE(QSharedPointer)
41 | Q_DECLARE_OPAQUE_POINTER(QSettingsDialog*)
42 | Q_DECLARE_METATYPE(QSettingsDialog*)
43 |
44 | #endif // QASYNCSETTINGSCONTAINER_P_H
45 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingswidgetfactory.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSWIDGETFACTORY_H
2 | #define QSETTINGSWIDGETFACTORY_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include "qsettingswidget.h"
6 |
7 | //! The base class for a factory to create QSettingsWidgets @ingroup grp_dialogui
8 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsWidgetFactory
9 | {
10 | public:
11 | //! Virtual destructor
12 | inline virtual ~QSettingsWidgetFactory() {}
13 |
14 | //! Creates a new instance of the settings widget
15 | virtual QSettingsWidgetBase *createWidget(QWidget *parent) = 0;
16 | };
17 |
18 | //! @intuse Generic base class for a factory to create QSettingsWidgets @ingroup grp_dialogui
19 | template
20 | class GenericSettingsWidgetFactory : public QSettingsWidgetFactory
21 | {
22 | public:
23 | QSettingsWidgetBase *createWidget(QWidget *parent) final {
24 | return new TSettingsWidget(parent);
25 | }
26 | };
27 |
28 | //! A macro for type converter registration @ingroup grp_dialogui
29 | #define REGISTER_TYPE_CONVERTERS(TypeA, TypeB) do {\
30 | QMetaType::registerConverter([](TypeA aVal) -> TypeB {\
31 | return (TypeB)aVal;\
32 | });\
33 | QMetaType::registerConverter([](TypeB bVal) -> TypeA {\
34 | return TypeA(bVal);\
35 | });\
36 | } while(false)
37 |
38 | //! A macro to register flag types @ingroup grp_dialogui
39 | #define REGISTER_FLAG_CONVERTERS(FlagsType) REGISTER_TYPE_CONVERTERS(FlagsType, int)
40 |
41 | #endif // QSETTINGSWIDGETFACTORY_H
42 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qsettingsdialog_p.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSDIALOG_P_H
2 | #define QSETTINGSDIALOG_P_H
3 |
4 | #include "qsettingsdialog.h"
5 | #include "containerelements.h"
6 | #include "settingsengine.h"
7 | #include "qsettingsdisplayengine.h"
8 | #include
9 | #include
10 |
11 | class QSettingsDialogPrivate
12 | {
13 | private:
14 | friend class QSettingsDialog;
15 | QSettingsDialogPrivate(QSettingsDialog *q_ptr, QSettingsDisplayEngine *engine);
16 | QAtomicInt currentIdMax;
17 |
18 | public:
19 | static QSettingsDialogPrivate *getPrivateInstance(QSettingsDialog *dialog);
20 |
21 | QSettingsDialog *q_ptr;
22 |
23 | QSharedPointer rootElement;
24 |
25 | QString categoryId;
26 | QString sectionId;
27 | QString groupId;
28 |
29 | QScopedPointer displayEngine;
30 | QPointer currentDialog;
31 |
32 | int getNextId();
33 |
34 | QSharedPointer getCategory(QString categoryId = QString());
35 | QSharedPointer getSection(QString sectionId = QString(),
36 | const QString &categoryId = QString());
37 | QSharedPointer getGroup(QString groupId = QString(),
38 | const QString §ionId = QString(),
39 | const QString &categoryId = QString());
40 |
41 | QString findEntryPath(int id);
42 | QSharedPointer findEntryGroup(int id);
43 |
44 | int showDialog(bool asExec, QWidget *parentWindow);
45 | };
46 |
47 | #endif // QSETTINGSDIALOG_P_H
48 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qsettingsloaderentry.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSLOADERENTRY_H
2 | #define QSETTINGSLOADERENTRY_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include "qsettingsentry.h"
6 | #include "qsettingsloader.h"
7 |
8 | //! A combination of a QSettingsEntry and a QSimpleSettingsLoader in one class \ingroup grp_core
9 | class QSettingsLoaderEntry : public QSettingsEntry, public QSimpleSettingsLoader
10 | {
11 | public:
12 | //! Creates a new loader entry from a display id
13 | inline QSettingsLoaderEntry(int displaytype) :
14 | QSettingsEntry(displaytype, nullptr)
15 | {}
16 | //! Creates a new loader entry from a display id and it's properties
17 | QSettingsLoaderEntry(int displaytype,
18 | const QString &name,
19 | bool optional = false,
20 | const QString &tooltip = QString(),
21 | const UiPropertyMap &properties = UiPropertyMap()) :
22 | QSettingsEntry(displaytype, nullptr, name, optional, tooltip, properties)
23 | {}
24 | //! Creates a new loader entry from a display id and it's properties
25 | template
26 | QSettingsLoaderEntry(int displaytype,
27 | const QString &name,
28 | bool optional,
29 | const QString &tooltip,
30 | Args... properties) :
31 | QSettingsEntry(displaytype, nullptr, name, optional, tooltip, properties...)
32 | {}
33 |
34 | inline QSettingsLoader *getLoader() final {
35 | return this;
36 | }
37 | inline void freeLoader(QSettingsLoader *) final {}
38 | };
39 |
40 | #endif // QSETTINGSLOADERENTRY_H
41 |
--------------------------------------------------------------------------------
/QSettingsDialog/loaders/qsettingssettingsloader.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSSETTINGSLOADER_H
2 | #define QSETTINGSSETTINGSLOADER_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include "qsettingsloader.h"
6 | #include
7 | #include
8 |
9 | class QSettingsSettingsLoaderPrivate;
10 | //! A loader to load data from QSettings @ingroup grp_loaders
11 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsSettingsLoader : public QSimpleSettingsLoader
12 | {
13 | public:
14 | //! Creates a loader for a key in the default QSettings
15 | QSettingsSettingsLoader(const QString &key);
16 | //! Creates a loader for a key in given QSettings
17 | QSettingsSettingsLoader(QSettings *settings, const QString &key, bool ownSettings = false);
18 | //! Destructor
19 | ~QSettingsSettingsLoader();
20 |
21 | // QSimpleSettingsLoader interface
22 | bool load(QVariant outParam data, bool outParam userEdited) override;
23 | bool save(const QVariant &data) override;
24 | bool reset() override;
25 |
26 | //! Creates a list of loaders for a group in the settings
27 | static QHash createLoaders(QSettings *settings,
28 | const QString &rootKey = QString(),
29 | bool recursive = false);
30 |
31 | private:
32 | QScopedPointer d_ptr;
33 |
34 | static QHash createLoadersImpl(QSettings *settings,
35 | const QString &rootKey,
36 | bool recursive);
37 | };
38 |
39 | #endif // QSETTINGSSETTINGSLOADER_H
40 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016, Felix Barz
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | * Neither the name of QSettingsDialog nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingsdialogwidget.cpp:
--------------------------------------------------------------------------------
1 | #include "qsettingsdialogwidget.h"
2 | #include
3 | #include
4 | #include
5 |
6 | QSettingsDialogWidgetBase::QSettingsDialogWidgetBase(QWidget *parent) :
7 | QSettingsWidget(parent),
8 | btn(new QPushButton(this))
9 | {
10 | this->btn->setAutoDefault(false);
11 | this->btn->setDefault(false);
12 |
13 | connect(this->btn, &QPushButton::clicked,
14 | this, &QSettingsDialogWidgetBase::showDialog);
15 |
16 | auto layout = new QHBoxLayout(this);
17 | layout->setContentsMargins(QMargins());
18 | layout->setSpacing(0);
19 | layout->addWidget(this->btn);
20 | layout->addStretch();
21 | this->setLayout(layout);
22 | }
23 |
24 | QIcon QSettingsDialogWidgetBase::buttonIcon() const
25 | {
26 | return QIcon();
27 | }
28 |
29 | void QSettingsDialogWidgetBase::showEvent(QShowEvent *event)
30 | {
31 | this->btn->setText(this->buttonText());
32 | this->btn->setIcon(this->buttonIcon());
33 | this->QWidget::showEvent(event);
34 | }
35 |
36 | void QSettingsDialogWidgetBase::wrapInDialog(QDialog *dialog, QWidget *element, bool fixedSize)
37 | {
38 | element->setParent(dialog);
39 | auto layout = new QHBoxLayout(dialog);
40 | layout->setContentsMargins(QMargins());
41 | layout->setSpacing(0);
42 | layout->addWidget(element);
43 | dialog->setLayout(layout);
44 |
45 | dialog->setWindowIcon(element->windowIcon());
46 | dialog->setWindowIconText(element->windowIconText());
47 | dialog->setWindowTitle(element->windowTitle());
48 |
49 | DialogMaster::masterDialog(dialog, fixedSize);
50 | }
51 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsspinbox.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSSPINBOX_H
2 | #define SETTINGSSPINBOX_H
3 |
4 | #include "qsettingswidget.h"
5 | #include "qsettingswidgetfactory.h"
6 | #include
7 |
8 | #ifdef min
9 | #undef min
10 | #endif
11 | #ifdef max
12 | #undef max
13 | #endif
14 |
15 | class SettingsSpinBox : public QSettingsWidget
16 | {
17 | public:
18 | SettingsSpinBox(QWidget *parent = nullptr);
19 |
20 | // QSettingsWidgetBase interface
21 | void setValue(const QVariant &value) override;
22 | QVariant getValue() const override;
23 | void resetValue() override;
24 | };
25 |
26 | class SettingsDoubleSpinBox : public QSettingsWidget
27 | {
28 | public:
29 | SettingsDoubleSpinBox(QWidget *parent = nullptr);
30 |
31 | // QSettingsWidgetBase interface
32 | void setValue(const QVariant &value) override;
33 | QVariant getValue() const override;
34 | void resetValue() override;
35 | };
36 |
37 | class SpinBoxFactory : public QSettingsWidgetFactory
38 | {
39 | public:
40 | SpinBoxFactory(int max, int min);
41 |
42 | // QSettingsWidgetFactory interface
43 | QSettingsWidgetBase *createWidget(QWidget *parent) final;
44 |
45 | private:
46 | int max;
47 | int min;
48 | };
49 |
50 | class DoubleSpinBoxFactory : public QSettingsWidgetFactory
51 | {
52 | public:
53 | DoubleSpinBoxFactory(double max, double min);
54 |
55 | // QSettingsWidgetFactory interface
56 | QSettingsWidgetBase *createWidget(QWidget *parent) final;
57 |
58 | private:
59 | double max;
60 | double min;
61 | };
62 |
63 | #endif // SETTINGSSPINBOX_H
64 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsspinbox.cpp:
--------------------------------------------------------------------------------
1 | #include "settingsspinbox.h"
2 |
3 | SettingsSpinBox::SettingsSpinBox(QWidget *parent) :
4 | QSettingsWidget(parent)
5 | {}
6 |
7 | void SettingsSpinBox::setValue(const QVariant &value)
8 | {
9 | this->QSpinBox::setValue(value.toInt());
10 | }
11 |
12 | QVariant SettingsSpinBox::getValue() const
13 | {
14 | return this->value();
15 | }
16 |
17 | void SettingsSpinBox::resetValue()
18 | {
19 | this->setValue(0);
20 | }
21 |
22 |
23 |
24 | SettingsDoubleSpinBox::SettingsDoubleSpinBox(QWidget *parent) :
25 | QSettingsWidget(parent)
26 | {}
27 |
28 | void SettingsDoubleSpinBox::setValue(const QVariant &value)
29 | {
30 | this->QDoubleSpinBox::setValue(value.toDouble());
31 | }
32 |
33 | QVariant SettingsDoubleSpinBox::getValue() const
34 | {
35 | return this->value();
36 | }
37 |
38 | void SettingsDoubleSpinBox::resetValue()
39 | {
40 | this->setValue(0.0);
41 | }
42 |
43 |
44 |
45 | SpinBoxFactory::SpinBoxFactory(int max, int min) :
46 | max(max),
47 | min(min)
48 | {}
49 |
50 | QSettingsWidgetBase *SpinBoxFactory::createWidget(QWidget *parent)
51 | {
52 | SettingsSpinBox *box = new SettingsSpinBox(parent);
53 | box->setRange(this->min, this->max);
54 | return box;
55 | }
56 |
57 |
58 |
59 | DoubleSpinBoxFactory::DoubleSpinBoxFactory(double max, double min) :
60 | max(max),
61 | min(min)
62 | {}
63 |
64 | QSettingsWidgetBase *DoubleSpinBoxFactory::createWidget(QWidget *parent)
65 | {
66 | SettingsDoubleSpinBox *box = new SettingsDoubleSpinBox(parent);
67 | box->setRange(this->min, this->max);
68 | return box;
69 | }
70 |
--------------------------------------------------------------------------------
/QSettingsDialog/generateIncludes.bat:
--------------------------------------------------------------------------------
1 | :: This file contains all public include files, ordered by category. These are all headers, that are within the submodules and not part of a private.pri file:
2 | :: Argument 1: out path
3 | :: Working Directory: QSettingsDialog library root path 21
4 | @echo off
5 | mkdir %1
6 |
7 | :: --- global ---
8 | xcopy .\qsettingsdialog_global.h %1\* /y
9 | xcopy .\qtexception.h %1\* /y
10 |
11 | :: --- core ---
12 | xcopy .\core\exceptions.h %1\* /y
13 | xcopy .\core\qsettingsdialog.h %1\* /y
14 | xcopy .\core\qsettingsentry.h %1\* /y
15 | xcopy .\core\qsettingsloader.h %1\* /y
16 | xcopy .\core\qsettingsloaderentry.h %1\* /y
17 | xcopy .\core\qsettingscontainer.h %1\* /y
18 | xcopy .\core\qasyncsettingscontainer.h %1\* /y
19 | xcopy .\core\qsettingslayout.h %1\* /y
20 | xcopy .\core\qsettingsdisplayengine.h %1\* /y
21 |
22 | :: --- dialogui ---
23 | xcopy .\dialogui\qsettingswidgetdialogengine.h %1\* /y
24 | xcopy .\dialogui\qsettingswidget.h %1\* /y
25 | xcopy .\dialogui\qsettingswidgetfactory.h %1\* /y
26 | xcopy .\dialogui\qsettingswidgetfactoryregistry.h %1\* /y
27 | xcopy .\dialogui\qsettingsdialogwidget.h %1\* /y
28 | xcopy .\dialogui\qsettingsgroupwidget.h %1\* /y
29 | xcopy .\dialogui\qsettingsgroupwidgetfactory.h %1\* /y
30 |
31 | :: --- loaders ---
32 | xcopy .\loaders\qsettingspropertyloader.h %1\* /y
33 | xcopy .\loaders\qsettingspropertyentry.h %1\* /y
34 | xcopy .\loaders\qsettingssettingsloader.h %1\* /y
35 |
36 | :: --- variantwidgets ---
37 | xcopy .\variantwidgets\variantwidgetsregistrator.h %1\* /y
38 | xcopy .\variantwidgets\qsettingsextendedtypes.h %1\* /y
39 |
--------------------------------------------------------------------------------
/QSettingsDialog/qsettingsdialog_global.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSDIALOGENGINE_GLOBAL_H
2 | #define QSETTINGSDIALOGENGINE_GLOBAL_H
3 |
4 | #include
5 | #include
6 | #ifndef QT_NO_DEBUG
7 | #include
8 | #endif
9 |
10 | #if defined(QSETTINGSDIALOG_LIBRARY)
11 | # define QSETTINGSDIALOGSHARED_EXPORT Q_DECL_EXPORT
12 | #else
13 | # define QSETTINGSDIALOGSHARED_EXPORT Q_DECL_IMPORT
14 | #endif
15 |
16 | //! Simple define for "&" to mark parameters as out-parameter @ingroup grp_core
17 | #define outParam &
18 |
19 | #ifdef QT_NO_DEBUG
20 | #define safe_cast static_cast
21 | #else
22 | template
23 | inline TTo safeCast(TFrom from) {
24 | Q_ASSERT_X(dynamic_cast(from), "", "static cast not possible! Dynamic cast assertion failed!");
25 | return static_cast(from);
26 | }
27 | #define safe_cast safeCast
28 | #endif
29 |
30 | #ifdef QT_NO_DEBUG
31 | #define sharedSafeCast(type, sharedPointer) sharedPointer.staticCast()
32 | #else
33 | template
34 | inline QSharedPointer safeCast_sharedPointer(QSharedPointer from) {
35 | Q_ASSERT_X(from.template dynamicCast(), "", "static cast not possible! Dynamic cast assertion failed!");
36 | return from.template staticCast();
37 | }
38 | #define sharedSafeCast(type, sharedPointer) safeCast_sharedPointer(sharedPointer)
39 | #endif
40 |
41 | //! a Hash for strings to variant, to provide properties for edit widgets @ingroup grp_core
42 | typedef QHash UiPropertyMap;
43 |
44 | #endif // QSETTINGSDIALOGENGINE_GLOBAL_H
45 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsenumwidgetfactory.cpp:
--------------------------------------------------------------------------------
1 | #include "settingsenumwidgetfactory.h"
2 | #include
3 |
4 | #include "settingsenumcombobox.h"
5 | #include "settingsflagschecklist.h"
6 |
7 | SettingsEnumWidgetFactory::SettingsEnumWidgetFactory(const QMetaEnum &metaEnum) :
8 | metaEnum(metaEnum)
9 | {}
10 |
11 | QSettingsWidgetBase *SettingsEnumWidgetFactory::createWidget(QWidget *parent)
12 | {
13 | if(this->metaEnum.isFlag())
14 | return new SettingsFlagsCheckList(this->metaEnum, parent);
15 | else
16 | return new SettingsEnumEditWrapper(this->metaEnum, parent);
17 | }
18 |
19 |
20 |
21 | int SettingsEnumWidgetRegistry::priority() const
22 | {
23 | return 42;
24 | }
25 |
26 | QSharedPointer SettingsEnumWidgetRegistry::tryResolve(int displayId)
27 | {
28 | auto metaObject = QMetaType::metaObjectForType(displayId);
29 | if(metaObject) {
30 | QStringList metaNameList = QString::fromLocal8Bit(QMetaType::typeName(displayId)).split(QStringLiteral("::"));
31 | int index = -1;
32 | QString testName = metaNameList.takeLast();
33 | forever {
34 | index = metaObject->indexOfEnumerator(testName.toLocal8Bit().constData());
35 | if(index >= 0)
36 | break;
37 | else if(metaNameList.isEmpty())
38 | break;
39 | else
40 | testName = testName.prepend(metaNameList.takeLast() + QStringLiteral("::"));
41 | }
42 |
43 | auto metaEnum = metaObject->enumerator(index);
44 | if(metaEnum.isValid())
45 | return QSharedPointer(new SettingsEnumWidgetFactory(metaEnum));
46 | }
47 |
48 | return QSharedPointer();
49 | }
50 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingsdialogwidget.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @class QSettingsDialogWidgetBase
3 |
4 | This base class can be used to create edit widgets that should show a dialog instead of showing the
5 | edit inline. Within the settings dialog itself, this widget will be repesented by a simple button.
6 | Once it gets clicked, the real dialog will be shown.
7 |
8 | @image html dialogwidget_button.png "The button within the settings dialog"
9 | */
10 |
11 | /*!
12 | @class QSettingsDialogWidget
13 |
14 | @tparam TDialog The class to create this dialog for. Must be a QSettingsWidget with a @a TWidget that inherits from QWidget
15 |
16 | You can use this class to simply create a dialog widget by simply implementing a normal QSettingsWidget and using this
17 | type for the registration. If your QSettingsWidget inherits QDialog instead of just QWidget, the widget itself will be shown as dialog.
18 | If it does not inherit QDialog, the settings dialog widget will create a wrapping QDialog to show the custom widget inside of it.
19 |
20 | Simple example. Your custom widget looks like this:
21 | ```cpp
22 | class MyDialog : QSettingsQWidget
23 | {
24 | public:
25 | MyDialog(QWidget *parent = nullptr);
26 | //...
27 | }
28 | ```
29 |
30 | To register it as a dialog, simply use the QSettingsDialogWidget for the registration:
31 | ```cpp
32 | QSettingsWidgetDialogEngine *engine = (QSettingsWidgetDialogEngine*)settingsDialog->displayEngine();
33 | engine->addWidgetType>(424242);
34 | ```
35 |
36 | @note The default implementation of this class uses the dialogs QWidget::windowTitle and QWidget::windowIcon
37 | for the button.
38 | */
39 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingswidgetfactoryregistry.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @class QSettingsWidgetFactoryRegistry
3 |
4 | Normally, you will not need to create a factory registry. You only have factories (QSettingsWidgetFactory) or directly registered QSettingsWidgets.
5 | However, in some cases you may need to provide an alternative way of finding those factories. In that case, the registry is what you need.
6 |
7 | The dialog engine uses multiple registries, and will try to find a factory for a given id in one of these. The order is determined by the priority of each registry.
8 | */
9 |
10 | /*!
11 | @fn QSettingsWidgetFactoryRegistry::priority
12 |
13 | @returns The priority of this factory.
14 |
15 | The prioritoy is used to order the factories. The priority for a factory type should be constant, because it will be only used once, when the factory is
16 | inserted into the list of factories. The default implementation returns `0`.
17 |
18 | @note Priorities are ordered ascending, meaning that a factory with a priority of `-100` will be used before one with `0`, and one with `100` at the very end.
19 | */
20 |
21 | /*!
22 | @fn QSettingsWidgetFactoryRegistry::tryResolve
23 |
24 | @param displayId The id that is tried to be resolved
25 | @returns A factory, if the id was successfully resolve, or `nullptr`, if it was not resolved.
26 |
27 | This function should check whether the id is know, and if yes return a fitting factory. If not, just return `nullptr`.
28 | If a value is returned, the given factory will be used by the engine to create the edit widget. If it's null, the
29 | next factory in the list will be asked usw until either all registries are done or a factory was found.
30 | */
31 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingslistedit.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSLISTEDIT_H
2 | #define SETTINGSLISTEDIT_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 | #include
7 |
8 | namespace Ui {
9 | class SettingsListEdit;
10 | }
11 |
12 | class ListEditWidget : public QWidget//NOTE move out of here -> new, global repo?
13 | {
14 | Q_OBJECT
15 |
16 | Q_PROPERTY(bool buttonsVisible READ areButtonsVisible WRITE setButtonsVisible)
17 | Q_PROPERTY(QStringList stringList READ stringList WRITE setStringList RESET clear NOTIFY stringListChanged)
18 |
19 | public:
20 | explicit ListEditWidget(const QStringList &stringList, QWidget *parent = Q_NULLPTR);
21 | explicit ListEditWidget(QWidget *parent = Q_NULLPTR);
22 | ~ListEditWidget();
23 |
24 | bool areButtonsVisible() const;
25 | QStringList stringList() const;
26 |
27 | public slots:
28 | void setButtonsVisible(bool buttonsVisible);
29 | void setStringList(QStringList stringList);
30 | void clear();
31 |
32 | signals:
33 | void stringListChanged(QStringList stringList);
34 |
35 | private slots:
36 | void modelChanged();
37 |
38 | void on_actionAdd_triggered();
39 | void on_actionRemove_triggered();
40 | void on_actionMove_Up_triggered();
41 | void on_actionMove_Down_triggered();
42 |
43 | private:
44 | Ui::SettingsListEdit *ui;
45 | QStringListModel *model;
46 | };
47 |
48 | class SettingsListEditWidget : public QSettingsWidget
49 | {
50 | public:
51 | SettingsListEditWidget(QWidget *parent = nullptr);
52 |
53 | // QSettingsWidgetBase interface
54 | void setValue(const QVariant &value) override;
55 | QVariant getValue() const override;
56 | void resetValue() override;
57 | };
58 |
59 | #endif // SETTINGSLISTEDIT_H
60 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qsettingsdisplayengine.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSDISPLAYENGINE_H
2 | #define QSETTINGSDISPLAYENGINE_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | class QWindow;
6 | struct SettingsRoot;
7 |
8 | //! @intuse An interface for a display instance that can be controlled by the dialog @ingroup grp_core
9 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsDisplayInstance
10 | {
11 | public:
12 | //! Virtual destructor
13 | inline virtual ~QSettingsDisplayInstance() {}
14 |
15 | //! Sets the parent window of this instance
16 | virtual void setParentWindow(QWidget *parent) = 0;
17 | //! Sets the parent window of this instance
18 | virtual void setParentWindow(QWindow *parent) = 0;
19 | //! Passes the current settings structure, to create the ui
20 | virtual void createUi(const QSharedPointer &rootElement) = 0;
21 |
22 | public slots:
23 | //! Opens the dialog non blocking
24 | virtual void open() = 0;
25 | //! Opens the dialog blocking, waiting for a result
26 | virtual int exec() = 0;
27 |
28 | signals:
29 | //! Should be emitted everytime settings are saved
30 | virtual void saved(bool closed) = 0;
31 | //! Should be emitted when settings have been resetted and the dialog closed
32 | virtual void resetted() = 0;
33 | //! Should be emitted when the dialog was canceled
34 | virtual void canceled() = 0;
35 | };
36 |
37 | //! @intuse An interface for an engine to create display dialogs @ingroup grp_core
38 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsDisplayEngine
39 | {
40 | public:
41 | //! Virtual destructor
42 | inline virtual ~QSettingsDisplayEngine() {}
43 |
44 | //! Creates a new display instance
45 | virtual QSettingsDisplayInstance *createInstance() = 0;
46 | };
47 |
48 | #endif // QSETTINGSDISPLAYENGINE_H
49 |
--------------------------------------------------------------------------------
/QSettingsDialog/loaders/qsettingspropertyloader.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSPROPERTYLOADER_H
2 | #define QSETTINGSPROPERTYLOADER_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include
6 | #include
7 | #include
8 | #include "qsettingsloader.h"
9 |
10 | class QSettingsPropertyLoaderPrivate;
11 | //! A loader to load properties from objects and gadgets @ingroup grp_loaders
12 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsPropertyLoader : public QAsyncSettingsLoader
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | //! Creates a loader for a property on an object
18 | explicit QSettingsPropertyLoader(const char *propertyName, QObject *object);
19 | //! Creates a loader for a property on an object
20 | explicit QSettingsPropertyLoader(const QMetaProperty &metaProperty, QObject *object);
21 | //! Creates a loader for a property on an gadget, with the gadgets static metaobject
22 | explicit QSettingsPropertyLoader(const char *propertyName, QMetaObject *metaObject, void *gadget);
23 | //! Creates a loader for a property on an gadget
24 | explicit QSettingsPropertyLoader(const QMetaProperty &metaProperty, void *gadget);
25 | //! Destructor
26 | ~QSettingsPropertyLoader();
27 |
28 | //! Returns the properties metatype id. Can be used for the QSettingsEntry
29 | int metatypeId() const;
30 | //! Returns whether the constructed loader points to a valid property on a valid object/gadget
31 | bool isValid() const;
32 |
33 | public slots:
34 | // QAsyncSettingsLoader interface
35 | void loadData() override;
36 | void saveData(const QVariant &data) override;
37 | void resetData() override;
38 |
39 | private:
40 | QScopedPointer d_ptr;
41 | };
42 |
43 | #endif // QSETTINGSPROPERTYLOADER_H
44 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/qsettingsextendedtypes.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSEXTENDEDTYPES_H
2 | #define QSETTINGSEXTENDEDTYPES_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | //! A custom type that represents a file path (is a QString) @ingroup grp_variantwidgets
9 | class FilePath : public QString
10 | {
11 | public:
12 | //! Creates a FilePath by passing the arguments to the QString constructor
13 | template
14 | FilePath(Args... args) :
15 | QString(args...)
16 | {}
17 |
18 | //! QVariant Converter
19 | operator QVariant() {
20 | return (QString)*this;
21 | }
22 | };
23 |
24 | //! A custom type that represents an integer range (is an int) @ingroup grp_variantwidgets
25 | class IntRange
26 | {
27 | public:
28 | //! Creates a IntRange from a value
29 | IntRange(int value = 0) :
30 | value(value)
31 | {}
32 |
33 | //! Converter to int
34 | operator int() {
35 | return this->value;
36 | }
37 |
38 | //! QVariant Converter
39 | operator QVariant() {
40 | return this->value;
41 | }
42 |
43 | //! assignment operator from int
44 | IntRange &operator=(int value) {
45 | this->value = value;
46 | return (*this);
47 | }
48 |
49 | private:
50 | int value;
51 | };
52 |
53 | //! A custom type that represents html-text (is a QString) @ingroup grp_variantwidgets
54 | class HtmlText : public QString
55 | {
56 | public:
57 | //! Creates a HtmlText by passing the arguments to the QString constructor
58 | template
59 | HtmlText(Args... args) :
60 | QString(args...)
61 | {}
62 |
63 | //! QVariant Converter
64 | operator QVariant() {
65 | return (QString)*this;
66 | }
67 | };
68 |
69 | Q_DECLARE_METATYPE(FilePath)
70 | Q_DECLARE_METATYPE(IntRange)
71 | Q_DECLARE_METATYPE(HtmlText)
72 |
73 | #endif // QSETTINGSEXTENDEDTYPES_H
74 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsslider.cpp:
--------------------------------------------------------------------------------
1 | #include "settingsslider.h"
2 | #include
3 | #include
4 | #include
5 |
6 | SettingsSlider::SettingsSlider(QWidget *parent) :
7 | QSettingsWidget(parent)
8 | {
9 | this->setOrientation(Qt::Horizontal);
10 |
11 | connect(this, &SettingsSlider::sliderPressed,
12 | this, &SettingsSlider::showValue,
13 | Qt::QueuedConnection);
14 | connect(this, &SettingsSlider::sliderMoved,
15 | this, &SettingsSlider::showValue,
16 | Qt::QueuedConnection);
17 | }
18 |
19 | void SettingsSlider::setValue(const QVariant &value)
20 | {
21 | this->QSlider::setValue(value.toInt());
22 | }
23 |
24 | QVariant SettingsSlider::getValue() const
25 | {
26 | return this->value();
27 | }
28 |
29 | void SettingsSlider::resetValue()
30 | {
31 | this->QSlider::setValue(0);
32 | }
33 |
34 | void SettingsSlider::showValue()
35 | {
36 | QPoint point;
37 | if(this->orientation() == Qt::Horizontal) {
38 | auto pos = QStyle::sliderPositionFromValue(this->minimum(),
39 | this->maximum(),
40 | this->value(),
41 | this->width() -
42 | this->style()->pixelMetric(QStyle::PM_SliderLength));
43 | point = QPoint(pos,
44 | this->style()->pixelMetric(QStyle::PM_SliderLength));
45 | } else {
46 | auto pos = QStyle::sliderPositionFromValue(this->minimum(),
47 | this->maximum(),
48 | this->value(),
49 | this->height() -
50 | this->style()->pixelMetric(QStyle::PM_SliderLength),
51 | true);
52 | point = QPoint(this->style()->pixelMetric(QStyle::PM_SliderThickness),
53 | pos - this->style()->pixelMetric(QStyle::PM_SliderLength));
54 | }
55 | point = this->mapToGlobal(point);
56 | QToolTip::showText(point, QLocale().toString(this->value()), this);
57 | }
58 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingslineedit.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSLINEEDIT_H
2 | #define SETTINGSLINEEDIT_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 | #include
7 | #include
8 |
9 | class SettingsLineEdit : public QSettingsWidget
10 | {
11 | public:
12 | SettingsLineEdit(QWidget *parent = nullptr);
13 |
14 | // QSettingsWidgetBase interface
15 | bool hasValueChanged() const override;
16 | void resetValueChanged() override;
17 | void setValue(const QVariant &value) override;
18 | QVariant getValue() const override;
19 | void resetValue() override;
20 | };
21 |
22 | class SettingsByteLineEdit : public SettingsLineEdit
23 | {
24 | public:
25 | SettingsByteLineEdit(QWidget *parent = nullptr);
26 |
27 | // QSettingsWidgetBase interface
28 | void setValue(const QVariant &value) override;
29 | QVariant getValue() const override;
30 | };
31 |
32 | class SettingsUrlLineEdit : public QSettingsWidget
33 | {
34 | public:
35 | SettingsUrlLineEdit(QWidget *parent = nullptr);
36 |
37 | // QSettingsWidgetBase interface
38 | void setValue(const QVariant &value) override;
39 | QVariant getValue() const override;
40 | void resetValue() override;
41 | };
42 |
43 | class QUrlValidator : public QValidator
44 | {
45 | public:
46 | QUrlValidator(QObject *parent = nullptr);
47 |
48 | // QValidator interface
49 | State validate(QString &text, int &) const override;
50 | void fixup(QString &text) const override;
51 | };
52 |
53 | class SettingsUuidEdit : public QSettingsWidget
54 | {
55 | public:
56 | SettingsUuidEdit(QWidget *parent = nullptr);
57 |
58 | // QSettingsWidgetBase interface
59 | void setValue(const QVariant &value) override;
60 | QVariant getValue() const override;
61 | void resetValue() override;
62 |
63 | private:
64 | void generateId();
65 |
66 | static QUuid toUuid(QString text);
67 | };
68 |
69 | #endif // SETTINGSLINEEDIT_H
70 |
--------------------------------------------------------------------------------
/QSettingsDialog/QSettingsDialog.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2016-06-02T21:32:33
4 | #
5 | #-------------------------------------------------
6 |
7 | TEMPLATE = lib
8 | QT += widgets
9 | CONFIG += c++14
10 |
11 | TARGET = QSettingsDialog
12 | VERSION = 1.0.0
13 |
14 | win32 {
15 | QMAKE_TARGET_COMPANY = "Skycoder42"
16 | QMAKE_TARGET_PRODUCT = "QSettingsDialog"
17 | QMAKE_TARGET_DESCRIPTION = $$QMAKE_TARGET_PRODUCT
18 | QMAKE_TARGET_COPYRIGHT = "Felix Barz"
19 |
20 | CONFIG += skip_target_version_ext
21 | } else:mac {
22 | QMAKE_TARGET_BUNDLE_PREFIX = "com.Skycoder42."
23 | QMAKE_FRAMEWORK_BUNDLE_NAME = "QSettingsDialog"
24 |
25 | CONFIG += lib_bundle
26 | QMAKE_LFLAGS_SONAME = -Wl,-install_name,@rpath/
27 | QMAKE_LFLAGS += '-Wl,-rpath,\'@executable_path/../Frameworks\''
28 | } else:unix {
29 | QMAKE_LFLAGS += '-Wl,-rpath,\'.\''
30 | QMAKE_LFLAGS += '-Wl,-rpath,\'\$$ORIGIN/../lib\''
31 | QMAKE_LFLAGS += '-Wl,-rpath,\'\$$ORIGIN/lib\''
32 | }
33 |
34 | DEFINES += QSETTINGSDIALOG_LIBRARY
35 |
36 | HEADERS += qsettingsdialog_global.h \
37 | qtexception.h
38 |
39 | SOURCES += \
40 | qtexception.cpp \
41 | qsettingsdialog_global.cpp
42 |
43 | RESOURCES += \
44 | qsettingsdialog_res.qrc
45 |
46 | DISTFILES += \
47 | $$PWD/classmodel.qmodel \
48 | qsettingsdialog.pri \
49 | generateIncludes.bat \
50 | doc/QSettingsDialog.doxy \
51 | doc/images/dialogwidget_button.png \
52 | doc/images/structure_core.svg \
53 | doc/modules_snippet.html \
54 | doc/images/structure_dialogui.svg \
55 | doc/images/structure_global.svg \
56 | doc/images/structure_loaders.svg \
57 | doc/images/structure_variantwidgets.svg
58 |
59 | include(./submodules/submodules.pri)
60 | #parts
61 | include(./core/core.pri)
62 | include(./dialogui/dialogui.pri)
63 | include(./variantwidgets/variantwidgets.pri)
64 | include(./loaders/loaders.pri)
65 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/containerelements.h:
--------------------------------------------------------------------------------
1 | #ifndef CONTAINERELEMENT_H
2 | #define CONTAINERELEMENT_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include "sortedmap.h"
8 | #include "specialgroupmap.h"
9 | #include "qsettingsentry.h"
10 | #include "exceptions.h"
11 | #include
12 |
13 | class QSettingsContainer;
14 | struct SettingsGroup
15 | {
16 | int displayId;
17 | QString name;
18 | QString tooltip;
19 | bool isOptional;
20 |
21 | SortedMap entries;
22 |
23 | inline SettingsGroup(int displayId, const QString &name) :
24 | displayId(displayId),
25 | name(name),
26 | tooltip(),
27 | isOptional(false),
28 | entries()
29 | {}
30 | };
31 |
32 | struct SettingsSection
33 | {
34 | QString name;
35 | QIcon icon;
36 | QString tooltip;
37 |
38 | SpecialGroupMap groups;
39 |
40 | inline SettingsSection(const QString &name) :
41 | name(name),
42 | icon(),
43 | tooltip(),
44 | groups()
45 | {}
46 |
47 | static inline QSharedPointer createDefaultSection() {
48 | return QSharedPointer(new SettingsSection(QSettingsDialog::tr("General")));
49 | }
50 | };
51 |
52 | struct SettingsCategory
53 | {
54 | QString name;
55 | QIcon icon;
56 | QString tooltip;
57 |
58 | QSharedPointer defaultSection;
59 | SortedMap sections;
60 |
61 | inline SettingsCategory(const QString &name) :
62 | name(name),
63 | icon(),
64 | tooltip(),
65 | defaultSection(),
66 | sections()
67 | {}
68 |
69 | static inline QSharedPointer createDefaultCategory() {
70 | auto cat = new SettingsCategory(QSettingsDialog::tr("General Settings"));
71 | cat->icon = QIcon(QStringLiteral(":/QSettingsDialog/icons/settings.ico"));
72 | return QSharedPointer(cat);
73 | }
74 | };
75 |
76 | struct SettingsRoot
77 | {
78 | QSharedPointer defaultCategory;
79 | SortedMap categories;
80 | };
81 |
82 | #endif // CONTAINERELEMENT_H
83 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingspathedit.cpp:
--------------------------------------------------------------------------------
1 | #include "settingspathedit.h"
2 | #include
3 | #include
4 |
5 | SettingsPathEdit::SettingsPathEdit(QWidget *parent) :
6 | QSettingsWidget(parent)
7 | {
8 | this->setEditable(true);
9 | }
10 |
11 | void SettingsPathEdit::setValue(const QVariant &value)
12 | {
13 | this->setPath(value.toString(), true);
14 | }
15 |
16 | QVariant SettingsPathEdit::getValue() const
17 | {
18 | return this->path();
19 | }
20 |
21 | void SettingsPathEdit::resetValue()
22 | {
23 | this->clear();
24 | }
25 |
26 |
27 |
28 | SettingsIconEdit::SettingsIconEdit(QWidget *parent) :
29 | QSettingsWidget(parent)
30 | {
31 | this->setEditable(false);
32 | this->setStyle(QPathEdit::JoinedButton, QLineEdit::LeadingPosition);
33 | QStringList sList;
34 | foreach(auto data, QImageReader::supportedMimeTypes())
35 | sList.append(QString::fromUtf8(data));
36 | sList.append(QStringLiteral("application/octet-stream"));
37 | this->setMimeTypeFilters(sList);
38 | this->setDefaultDirectory(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
39 |
40 | connect(this, &SettingsIconEdit::pathChanged,
41 | this, &SettingsIconEdit::updateIcon);
42 | }
43 |
44 | void SettingsIconEdit::setValue(const QVariant &value)
45 | {
46 | if(this->m_asQIcon) {
47 | this->clear();
48 | this->setDialogButtonIcon(value.value());
49 | } else
50 | this->setPath(value.toString(), false);
51 | }
52 |
53 | QVariant SettingsIconEdit::getValue() const
54 | {
55 | if(this->m_asQIcon)
56 | return this->dialogButtonIcon();
57 | else
58 | return this->path();
59 | }
60 |
61 | void SettingsIconEdit::resetValue()
62 | {
63 | this->clear();
64 | this->resetDialogButtonIcon();
65 | }
66 |
67 | bool SettingsIconEdit::asQIcon() const
68 | {
69 | return m_asQIcon;
70 | }
71 |
72 | void SettingsIconEdit::setAsQIcon(bool asQIcon)
73 | {
74 | if (m_asQIcon == asQIcon)
75 | return;
76 |
77 | m_asQIcon = asQIcon;
78 | emit asQIconChanged(asQIcon);
79 | }
80 |
81 | void SettingsIconEdit::updateIcon(const QString &path)
82 | {
83 | this->setDialogButtonIcon(QIcon(path));
84 | }
85 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/settingsengine.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSENGINE_H
2 | #define SETTINGSENGINE_H
3 |
4 | #include
5 | #include
6 | #include "qsettingsentry.h"
7 | #include "qsettingsloader.h"
8 | #include "qsettingswidget.h"
9 | #include "checkinghelper.h"
10 |
11 | class SettingsEngine : public QObject
12 | {
13 | Q_OBJECT
14 | public:
15 | explicit SettingsEngine(QObject *parent = nullptr);
16 | ~SettingsEngine();
17 |
18 | void addEntry(QSharedPointer entry,
19 | QSettingsWidgetBase *currentWidget,
20 | CheckingHelper *checkingHelper);
21 |
22 | public slots:
23 | void startLoading();
24 | void startSaving();
25 | void startResetting();
26 |
27 | void abortOperation();
28 |
29 | signals:
30 | void progressMaxChanged(int max);
31 | void progressValueChanged(int value);
32 |
33 | void operationCompleted(int errorCount);
34 | void operationAborted();
35 |
36 | private slots:
37 | void entryLoaded(bool successful, const QVariant &data, bool isUserEdited);
38 | void entrySaved(bool successful);
39 | void entryResetted(bool successful);
40 |
41 | private:
42 | struct EntryInfoBase {
43 | QSharedPointer entry;
44 | QSettingsWidgetBase *currentWidget;
45 | CheckingHelper *checkingHelper;
46 | };
47 | template
48 | struct EntryInfo : public EntryInfoBase {
49 | TLoader *currentLoader;
50 |
51 | inline EntryInfo(QSharedPointer entry,
52 | QSettingsWidgetBase *currentWidget,
53 | CheckingHelper *checkingHelper,
54 | TLoader *currentLoader) :
55 | EntryInfoBase({entry, currentWidget, checkingHelper}),
56 | currentLoader(currentLoader)
57 | {}
58 | };
59 |
60 | QList> simpleEntries;
61 | QList> asyncEntries;
62 |
63 | QHash activeAsyncs;
64 | int currentCount;
65 | int errorCount;
66 |
67 | void updateEntry(EntryInfoBase &entry, const QVariant &data, bool isUserEdited);
68 | void disableEntry(EntryInfoBase &entry);
69 | void updateProgress(bool increment);
70 | void tryLoadComplete();
71 | };
72 |
73 | #endif // SETTINGSENGINE_H
74 |
--------------------------------------------------------------------------------
/QSettingsDialog/loaders/qsettingssettingsloader.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @class QSettingsSettingsLoader
3 |
4 | With this loader type, any value from QSettings can be used in the dialog
5 |
6 | @note QSettings does **not** preserve the type for simple types as int/double/… . If you check the returned QVariants
7 | type, you will always get QString for those. However, the values are convertible to int/double/… . So as long as you know
8 | which type to use, it's fine. Because of this, and because an entry can be not existing, unlike the property loader,
9 | the QSettings loader does not provide a member to get the metatype of the used settings entry.
10 | */
11 |
12 | /*!
13 | @fn QSettingsSettingsLoader::QSettingsSettingsLoader(QSettings *, const QString &, bool)
14 |
15 | @param settings The settings object to be used
16 | @param key The key within the settings to load/write to
17 | @param ownSettings If `true`, the loader will delete the @a settings when it's destroyed. If `false`, thats not the case
18 |
19 | If you set the @a settings to be owned, the desturction of the loader will destroy them too. If not, the loader will not do anything.
20 | However, if you pass not owned settings, you have to make shure the object will not be destroyed until the loader was destroyed. Otherwise,
21 | your application will most likely crash.
22 | */
23 |
24 | /*!
25 | @fn QSettingsSettingsLoader::createLoaders
26 |
27 | @param settings The settings object to be used
28 | @param rootKey The group key to scan
29 | @param recursive Specifies, whether searching should be performed recusive or not
30 | @returns A map of settings keys (including the @a key part) to the loader for that key.
31 |
32 | This function will scan the given @a key group of the @a settings and create loaders for all child entries in that
33 | group. If @a recursive is `false`, only the direct child entries will be used. If it is `true`, this function will
34 | recusivly scan all subgroups and create entries for all of them.
35 |
36 | The resulting map contains all entries with their keys as key. Each key will include the @a key that was passed to this
37 | function. The @a settings state will not be changed, and none of the returned loaders will have ownership of the settings.
38 | */
39 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingswidgetfactory.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @class QSettingsWidgetFactory
3 |
4 | For each kind of widget you want, create a factory and register this factory for a display id using
5 | QSettingsWidgetDialogEngine::addFactory.
6 |
7 | @note Use this class only if you need a special way to create the widgets. If all you need is a `new MyEditWidget(parent);`,
8 | simply use QSettingsWidgetDialogEngine::addWidgetType instead of creating a new factory implementation.
9 | */
10 |
11 | /*!
12 | @def REGISTER_TYPE_CONVERTERS
13 |
14 | @param TypeA The first, custom type that provides the converters
15 | @param TypeB the second, less complex type, that serves as "target" of these converters
16 |
17 | This macro can be used to register simple type converters for QVariant. This may be required for some types to make it possible to
18 | use them with edit widgets.
19 |
20 | Simple example: You defined your own class `SuperInt`. To edit it, you use a spinbox. Now since the spinbox uses `int` as a type, you need
21 | to convert these types. First step is to create conversion functionality in `SuperInt`. You will need a constructor from `int` and a conversion
22 | operator to `int`:
23 | @code{.cpp}
24 | class SuperInt {
25 | public:
26 | SuperInt(int value);
27 |
28 | operator int();
29 | }
30 | @endcode
31 |
32 | Next step is to register the converter using this macro. You do this in your `main` after you have create the `QApplication`:
33 | @code{.cpp}
34 | REGISTER_TYPE_CONVERTERS(SuperInt, int);
35 | @endcode
36 |
37 | Thats it. Now `QVariant` is able to internally convert these two types into each other, which makes it possible to do for example this:
38 | @code{.cpp}
39 | SuperInt sup(42);
40 | QVariant var = QVariant::fromValue(sup);
41 | int test = var.toInt();//this will work now
42 | QVariant var2 = test;
43 | SuperInt back = var2.value();//will work too
44 | @endcode
45 | */
46 |
47 | /*!
48 | @def REGISTER_FLAG_CONVERTERS
49 |
50 | @param FlagsType The custom QFlags class that should have it's converters registered
51 |
52 | This macro will use REGISTER_TYPE_CONVERTERS to make it possible to convert your custom flags from and to `int`. This is required
53 | if you want to use the flags type with the QSettingsDialog!
54 | */
55 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingswidget.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSWIDGET_H
2 | #define QSETTINGSWIDGET_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include
6 | #include
7 | #include
8 | #include "qsettingsentry.h"
9 |
10 | //! The base class for edit widgets in the settings dialog @ingroup grp_dialogui
11 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsWidgetBase
12 | {
13 | public:
14 | //! Constructor
15 | QSettingsWidgetBase();
16 | //! Virtual Destructor
17 | virtual ~QSettingsWidgetBase();
18 |
19 | //! Must return this as QWidget (a cast)
20 | virtual QWidget *asWidget() = 0;
21 | //! Will be called to initialize the widgets properties with the given ones
22 | virtual void initialize(const UiPropertyMap &uiPropertyMap) = 0;
23 |
24 | //! Will be called to determine, whether the value has changed or not
25 | virtual bool hasValueChanged() const;
26 | //! Resets the value changed status to unchanged
27 | virtual void resetValueChanged();
28 |
29 | //! Sets the edit widgets "value"
30 | virtual void setValue(const QVariant &value) = 0;
31 | //! Gets the edit widgets "value"
32 | virtual QVariant getValue() const = 0;
33 | //! Resets the edit widgets "value"
34 | virtual void resetValue() = 0;
35 |
36 | //! Will be called to search for a specific expression inside the edit widget
37 | virtual inline bool searchExpression(const QRegularExpression ®ex) {
38 | return regex.pattern().isEmpty();
39 | }
40 |
41 | private:
42 | QVariant changedCache;
43 | };
44 |
45 | //! Generic base class for settings widgets @ingroup grp_dialogui
46 | template
47 | class QSettingsWidget : public TWidget, public QSettingsWidgetBase
48 | {
49 | public:
50 | //! Creates a new widget with a parent
51 | inline QSettingsWidget(QWidget *parent = nullptr) :
52 | TWidget(parent),
53 | QSettingsWidgetBase()
54 | {}
55 |
56 | inline QWidget *asWidget() final {
57 | return this;
58 | }
59 | void initialize(const UiPropertyMap &uiPropertyMap) override {
60 | for(UiPropertyMap::const_iterator it = uiPropertyMap.constBegin(), end = uiPropertyMap.constEnd(); it != end; ++it)
61 | this->setProperty(it.key().toLocal8Bit().constData(), it.value());
62 | }
63 | };
64 |
65 | Q_DECLARE_METATYPE(QSettingsWidgetBase*)
66 |
67 | #endif // QSETTINGSWIDGET_H
68 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qasyncsettingscontainer.h:
--------------------------------------------------------------------------------
1 | #ifndef QASYNCSETTINGSCONTAINER_H
2 | #define QASYNCSETTINGSCONTAINER_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include
6 | #include "qsettingscontainer.h"
7 |
8 | class QAsyncSettingsContainerPrivate;
9 | //! A special class that allows access to the settings dialog from different threads
10 | class QSETTINGSDIALOGSHARED_EXPORT QAsyncSettingsContainer : public QSettingsContainer
11 | {
12 | Q_OBJECT
13 | public:
14 | //! Creates a new container for a container at the given path for the given dialog
15 | explicit QAsyncSettingsContainer(QSettingsDialog *settingsDialog, const QString &containerPath, QObject *parent = nullptr);
16 | //! Destructor
17 | ~QAsyncSettingsContainer();
18 |
19 | // QSettingsContainer interface
20 | QSettingsDialog *dialog() const override;
21 | QString containerPath() const override;
22 |
23 | int elementCount() const override;
24 | bool isEntry(int index) const override;
25 | int getEntryIndex(int id) const override;
26 | int getEntryId(int index) const override;
27 | QSharedPointer getEntry(int id) const override;
28 | QSharedPointer getEntryFromIndex(int index) const override;
29 |
30 | bool transferElement(int indexFrom, QSettingsContainer *targetContainer, int indexTo) override;
31 |
32 | public slots:
33 | int appendEntry(QSettingsEntry *entry) override;
34 | int prependEntry(QSettingsEntry *entry) override;
35 | int insertEntry(int index, QSettingsEntry *entry) override;
36 | int insertEntry(int index, QSharedPointer entry) override;
37 | bool removeEntry(int id) override;
38 | bool removeElementFromIndex(int index) override;
39 | void moveElement(int indexFrom, int indexTo) override;
40 | //! Asynchronously moves the element from the old to the new index
41 | void moveElementAsync(int indexFrom, int indexTo);
42 |
43 | //! Asynchronously appends the entry to the container
44 | void appendEntryAsync(QSettingsEntry *entry);
45 | //! Asynchronously prepends the entry to the container
46 | void prependEntryAsync(QSettingsEntry *entry);
47 |
48 | protected:
49 | bool acceptEntry(int index, int id, QSharedPointer entry) override;
50 |
51 | private:
52 | QScopedPointer d_ptr;
53 | };
54 |
55 | #endif // QASYNCSETTINGSCONTAINER_H
56 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsenumcombobox.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSENUMCOMBOBOX_H
2 | #define SETTINGSENUMCOMBOBOX_H
3 |
4 | #include "qsettingswidget.h"
5 | #include
6 | #include
7 | #include
8 |
9 | class SettingsEnumComboBox : public QSettingsWidget
10 | {
11 | Q_OBJECT
12 |
13 | Q_PROPERTY(bool translated READ translated WRITE setTranslated NOTIFY translatedChanged)
14 |
15 | public:
16 | SettingsEnumComboBox(const QMetaEnum &metaEnum, QWidget *parent = nullptr);
17 |
18 | // QSettingsWidgetBase interface
19 | void setValue(const QVariant &value) override;
20 | QVariant getValue() const override;
21 | void resetValue() override;
22 |
23 | bool translated() const;
24 |
25 | public slots:
26 | void setTranslated(bool translated);
27 |
28 | signals:
29 | void translatedChanged(bool translated);
30 |
31 | private:
32 | QMetaEnum metaEnum;
33 | bool m_translated;
34 | };
35 |
36 | class SettingsEnumRadioList : public QSettingsWidget
37 | {
38 | Q_OBJECT
39 |
40 | Q_PROPERTY(bool translated READ translated WRITE setTranslated NOTIFY translatedChanged)
41 |
42 | public:
43 | SettingsEnumRadioList(const QMetaEnum &metaEnum, QWidget *parent = nullptr);
44 |
45 | // QSettingsWidgetBase interface
46 | void setValue(const QVariant &value) override;
47 | QVariant getValue() const override;
48 | void resetValue() override;
49 |
50 | bool translated() const;
51 |
52 | public slots:
53 | void setTranslated(bool translated);
54 |
55 | signals:
56 | void translatedChanged(bool translated);
57 |
58 | private:
59 | QMetaEnum metaEnum;
60 | QButtonGroup *checkGroup;
61 | bool m_translated;
62 | };
63 |
64 | class SettingsEnumEditWrapper : public QSettingsWidget
65 | {
66 | public:
67 | SettingsEnumEditWrapper(const QMetaEnum &metaEnum, QWidget *parent = nullptr);
68 |
69 | // QSettingsWidgetBase interface
70 | void initialize(const UiPropertyMap &uiPropertyMap) override;
71 | bool hasValueChanged() const override;
72 | void resetValueChanged() override;
73 | void setValue(const QVariant &value) override;
74 | QVariant getValue() const override;
75 | void resetValue() override;
76 | bool searchExpression(const QRegularExpression ®ex) override;
77 |
78 | private:
79 | QMetaEnum metaEnum;
80 | QSettingsWidgetBase *current;
81 | };
82 |
83 | #endif // SETTINGSENUMCOMBOBOX_H
84 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingswidget.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @class QSettingsWidgetBase
3 |
4 | Implementations must inherit from `QWidget`!
5 |
6 | @note You should not use this class directly. It simply serves as base for the generic interface. You should
7 | only implement the QSettingsWidget interface!
8 | */
9 |
10 | /*!
11 | @fn QSettingsWidgetBase::asWidget
12 |
13 | @returns `(QWidget*)this;`
14 |
15 | @warning This function **MUST** return itself. It's basically a shortcut for `(QWidget*)element`, and is there
16 | to ensure all widgets that implement this interface do inherit `QWidget`.
17 | */
18 |
19 | /*!
20 | @fn QSettingsWidgetBase::hasValueChanged
21 |
22 | @returns `true`, if the value has changed since the last reset, `false` if not
23 |
24 | This function will determine whether the data within this edit will be saved or not. Only if it returs true,
25 | data will actually be saved. The "changed" is relative to the status from the last `QSettingsWidgetBase::resetValueChanged`.
26 | This means, immediatly after a call to that function, this one should always return `false`. And only if the current state of the
27 | edit is different from the one it had when that funcion was called, `true` shall be returned
28 |
29 | @note For most edit widgets, the default implementation is sufficient.
30 | */
31 |
32 | /*!
33 | @fn QSettingsWidgetBase::resetValueChanged
34 |
35 | See QSettingsWidgetBase::hasValueChanged.
36 |
37 | @note For most edit widgets, the default implementation is sufficient.
38 | */
39 |
40 | /*!
41 | @fn QSettingsWidgetBase::searchExpression
42 |
43 | @param regex The regular expression to match against
44 | @returns `true`, if this edit matches the expression, `false` if not
45 |
46 | Reimplement this function if your edit should be used to help find search entries. The default implementation
47 | matches on nothing
48 |
49 | @note If the @a regex is empty, this function must always return `true`.
50 | */
51 |
52 | /*!
53 | @class QSettingsWidget
54 |
55 | @tparam TWidget A class that is or inherits QWidget. It will be the primary base class of this widget
56 |
57 | Use this generic interface to create your own edit widget implementations:
58 |
59 | @code{.cpp}
60 | class MyEditWidget : QSettingsWidget
61 | {
62 | public:
63 | //...
64 | }
65 | @endcode
66 |
67 | The class can then be registered to the dialog using QSettingsWidgetDialogEngine::addWidgetType.
68 | */
69 |
--------------------------------------------------------------------------------
/QSettingsDialog/loaders/qsettingspropertyentry.cpp:
--------------------------------------------------------------------------------
1 | #include "qsettingspropertyentry.h"
2 | #include "qsettingspropertyloader.h"
3 |
4 |
5 |
6 | QSettingsPropertyEntry::QSettingsPropertyEntry(const char *propertyName, QObject *object) :
7 | QSettingsEntry(0, new QSettingsPropertyLoader(propertyName, object))
8 | {}
9 |
10 | QSettingsPropertyEntry::QSettingsPropertyEntry(const QMetaProperty &metaProperty, QObject *object) :
11 | QSettingsEntry(0, new QSettingsPropertyLoader(metaProperty, object))
12 | {}
13 |
14 | QSettingsPropertyEntry::QSettingsPropertyEntry(const char *propertyName, QMetaObject *metaObject, void *gadget) :
15 | QSettingsEntry(0, new QSettingsPropertyLoader(propertyName, metaObject, gadget))
16 | {}
17 |
18 | QSettingsPropertyEntry::QSettingsPropertyEntry(const QMetaProperty &metaProperty, void *gadget) :
19 | QSettingsEntry(0, new QSettingsPropertyLoader(metaProperty, gadget))
20 | {}
21 |
22 | QSettingsPropertyEntry::QSettingsPropertyEntry(const char *propertyName, QObject *object, const QString &name, bool optional, const QString &tooltip, const UiPropertyMap &properties) :
23 | QSettingsEntry(0, new QSettingsPropertyLoader(propertyName, object), name, optional, tooltip, properties)
24 | {}
25 |
26 | QSettingsPropertyEntry::QSettingsPropertyEntry(const QMetaProperty &metaProperty, QObject *object, const QString &name, bool optional, const QString &tooltip, const UiPropertyMap &properties) :
27 | QSettingsEntry(0, new QSettingsPropertyLoader(metaProperty, object), name, optional, tooltip, properties)
28 | {}
29 |
30 | QSettingsPropertyEntry::QSettingsPropertyEntry(const char *propertyName, QMetaObject *metaObject, void *gadget, const QString &name, bool optional, const QString &tooltip, const UiPropertyMap &properties) :
31 | QSettingsEntry(0, new QSettingsPropertyLoader(propertyName, metaObject, gadget), name, optional, tooltip, properties)
32 | {}
33 |
34 | QSettingsPropertyEntry::QSettingsPropertyEntry(const QMetaProperty &metaProperty, void *gadget, const QString &name, bool optional, const QString &tooltip, const UiPropertyMap &properties) :
35 | QSettingsEntry(0, new QSettingsPropertyLoader(metaProperty, gadget), name, optional, tooltip, properties)
36 | {}
37 |
38 | int QSettingsPropertyEntry::displaytype()
39 | {
40 | auto loader = safe_cast(this->getLoader());
41 | auto id = loader->metatypeId();
42 | this->freeLoader(loader);
43 | return id;
44 | }
45 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qasyncsettingscontainer.dox:
--------------------------------------------------------------------------------
1 | /*!
2 | @class QAsyncSettingsContainer
3 |
4 | This special container allows synchronized and asynchronous access to a specific group of the settings dialog from
5 | a different thread than the mainthread. It internally uses Qts metasystem to make queued method invokations, making it completly
6 | threadsafe on a functional level.
7 |
8 | @warning Even though it's save to call all of the functions, there is no locking mechanism. This means that the state of the dialog can change
9 | between two function calls, making calls like `container->insertEntry(container->elementCount(), entry);` unsafe, if other components of the
10 | application are accessing the containers target group/section at the same time!
11 |
12 | ### Synchronous Access:
13 | All functions that are define by the QSettingsDialog interface are synchronous. This means they will block until the mainthread handled the request.
14 | Internally, a Qt::BlockingQueuedConnection is used to archiev this.
15 |
16 | @warning The blocking calls will block the calling thread until the mainthread was able to process the call. This means it is forbidden
17 | to call any of those from the mainthread itself.
18 |
19 | ### Asynchronous Access:
20 | The two functions QAsyncSettingsContainer::appendEntryAsync, QAsyncSettingsContainer::prependEntryAsync and QAsyncSettingsContainer::moveElementAsync can be used for asynchronous calls. They will
21 | return immediatly and post the event to the mainthread without waiting for it. It's safe to call those from everywhere.
22 | */
23 |
24 | /*!
25 | @fn QAsyncSettingsContainer::appendEntryAsync
26 |
27 | @param entry The entry to be appended
28 |
29 | This call will post the appending to the main thread. As soon as it is handled, the the element will be appended.
30 | The call will return immideatly and will not wait for the execution.
31 | */
32 |
33 | /*!
34 | @fn QAsyncSettingsContainer::prependEntryAsync
35 |
36 | @param entry The entry to be prepend
37 |
38 | This call will post the prepending to the main thread. As soon as it is handled, the the element will be prepended.
39 | The call will return immideatly and will not wait for the execution.
40 | */
41 |
42 | /*!
43 | @fn QAsyncSettingsContainer::moveElementAsync
44 |
45 | @param indexFrom The index to move from
46 | @param indexTo The index to move to
47 |
48 | This call will post the moving to the main thread. As soon as it is handled, the the element will be moved.
49 | The call will return immideatly and will not wait for the execution.
50 | */
51 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsflagschecklist.cpp:
--------------------------------------------------------------------------------
1 | #include "settingsflagschecklist.h"
2 | #include
3 | #include
4 | #include
5 |
6 | SettingsFlagsCheckList::SettingsFlagsCheckList(const QMetaEnum &metaEnum, QWidget *parent) :
7 | QSettingsWidget(parent),
8 | metaEnum(metaEnum),
9 | checkGroup(new QButtonGroup(this)),
10 | currentFlags(0),
11 | m_translated(false)
12 | {
13 | this->checkGroup->setExclusive(false);
14 | connect(this->checkGroup, QOverload::of(&QButtonGroup::buttonClicked),
15 | this, &SettingsFlagsCheckList::updateFlags);
16 |
17 | auto layout = new QVBoxLayout(this);
18 | layout->setContentsMargins(QMargins());
19 | this->setLayout(layout);
20 |
21 | for(int i = 0; i < this->metaEnum.keyCount(); i++) {
22 | auto box = new QCheckBox(QString::fromLocal8Bit(this->metaEnum.key(i)), this);
23 | layout->addWidget(box);
24 | this->checkGroup->addButton(box, this->metaEnum.value(i));
25 | }
26 |
27 | this->setTranslated(true);
28 | }
29 |
30 | void SettingsFlagsCheckList::setValue(const QVariant &value)
31 | {
32 | this->currentFlags = value.toInt();
33 | this->reloadFlags();
34 | }
35 |
36 | QVariant SettingsFlagsCheckList::getValue() const
37 | {
38 | return this->currentFlags;
39 | }
40 |
41 | void SettingsFlagsCheckList::resetValue()
42 | {
43 | this->currentFlags = 0;
44 | this->reloadFlags();
45 | }
46 |
47 | bool SettingsFlagsCheckList::translated() const
48 | {
49 | return m_translated;
50 | }
51 |
52 | void SettingsFlagsCheckList::setTranslated(bool translated)
53 | {
54 | if (m_translated == translated)
55 | return;
56 | m_translated = translated;
57 |
58 | for(int i = 0; i < this->metaEnum.keyCount(); i++) {
59 | QString text;
60 | if(translated)
61 | text = QCoreApplication::translate(this->metaEnum.name(), this->metaEnum.key(i));
62 | else
63 | text = QString::fromLocal8Bit(this->metaEnum.key(i));
64 |
65 | auto box = this->checkGroup->button(this->metaEnum.value(i));
66 | box->setText(text);
67 | }
68 |
69 | emit translatedChanged(translated);
70 | }
71 |
72 |
73 | void SettingsFlagsCheckList::updateFlags(int value)
74 | {
75 | if(this->checkGroup->button(value)->isChecked())
76 | this->currentFlags |= value;
77 | else
78 | this->currentFlags &= ~value;
79 | this->reloadFlags();
80 | }
81 |
82 | void SettingsFlagsCheckList::reloadFlags()
83 | {
84 | for(int i = 0; i < this->metaEnum.keyCount(); i++) {
85 | auto value = this->metaEnum.value(i);
86 | this->checkGroup->button(value)->setChecked((this->currentFlags & value) == value);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingsgroupwidget.cpp:
--------------------------------------------------------------------------------
1 | #include "qsettingsgroupwidget.h"
2 | #include
3 | #include
4 | #include "settingsdisplaydialog.h"
5 |
6 | QSettingsGroupWidgetBase::~QSettingsGroupWidgetBase() {}
7 |
8 | void QSettingsGroupWidgetBase::addWidgetRaw(QSharedPointer entry, QWidget *content, bool hasError)
9 | {
10 | QWidget *label = nullptr;
11 | if(entry->isOptional()) {
12 | auto optBox = new QCheckBox(this->asWidget());
13 | optBox->setText(entry->entryName() + SettingsDisplayDialog::tr(":"));
14 | QObject::connect(optBox, &QCheckBox::toggled,
15 | content, &QWidget::setEnabled);
16 | label = optBox;
17 | } else {
18 | auto cLabel = new QLabel(this->asWidget());
19 | cLabel->setText(entry->entryName() + SettingsDisplayDialog::tr(":"));
20 | label = cLabel;
21 | }
22 | this->entryMap.insert(entry, {label, dynamic_cast(content)});
23 |
24 | label->setToolTip(entry->tooltip());
25 | if(content->toolTip().isNull())
26 | content->setToolTip(entry->tooltip());
27 | if(hasError)
28 | label->setEnabled(false);
29 | else
30 | content->setEnabled(!entry->isOptional());
31 |
32 | this->addWidgetWithLabel(label, content);
33 | }
34 |
35 | void QSettingsGroupWidgetBase::setEntryChecked(QSharedPointer entry, bool checked)
36 | {
37 | auto box = dynamic_cast(this->entryMap.value(entry).first);
38 | if(box)
39 | return box->setChecked(checked);
40 | }
41 |
42 | void QSettingsGroupWidgetBase::setEntryLabelEnabled(QSharedPointer entry, bool enabled)
43 | {
44 | auto widget = this->entryMap.value(entry).first;
45 | if(widget)
46 | widget->setEnabled(enabled);
47 | }
48 |
49 | bool QSettingsGroupWidgetBase::isEntryChecked(QSharedPointer entry) const
50 | {
51 | auto box = dynamic_cast(this->entryMap.value(entry).first);
52 | if(box)
53 | return box->isChecked();
54 | else
55 | return true;
56 | }
57 |
58 | bool QSettingsGroupWidgetBase::searchExpression(const QRegularExpression ®ex, const QString &searchStyleSheet)
59 | {
60 | bool someFound = false;
61 |
62 | foreach(auto element, this->entryMap) {
63 | auto &label = element.first;
64 | auto &content = element.second;
65 |
66 | if(!regex.pattern().isEmpty() &&
67 | (regex.match(label->property("text").toString()).hasMatch() ||
68 | (content && content->searchExpression(regex)))) {
69 | label->setStyleSheet(searchStyleSheet);
70 | someFound = true;
71 | } else
72 | label->setStyleSheet(QString());
73 | }
74 |
75 | return someFound;
76 | }
77 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qsettingsentry.cpp:
--------------------------------------------------------------------------------
1 | #include "qsettingsentry.h"
2 | #include "qsettingsentry_p.h"
3 | #include
4 |
5 | #define d this->d_ptr
6 |
7 | QSettingsEntry::QSettingsEntry(int displaytype, QSettingsLoader *loader) :
8 | d_ptr(new QSettingsEntryPrivate(displaytype, loader))
9 | {}
10 |
11 | QSettingsEntry::QSettingsEntry(int displaytype, QSettingsLoader *loader, const QString &name, bool optional, const QString &tooltip, const UiPropertyMap &properties) :
12 | d_ptr(new QSettingsEntryPrivate(displaytype, loader))
13 | {
14 | d->name = name;
15 | d->optional = optional;
16 | d->tooltip = tooltip;
17 | d->properties = properties;
18 | }
19 |
20 | QSettingsEntry::~QSettingsEntry()
21 | {
22 | #ifndef QT_NO_DEBUG
23 | Q_ASSERT_X(d->refCounter == 0, Q_FUNC_INFO, "settings entry destroyed with active loaders!");
24 | #endif
25 | }
26 |
27 | QString QSettingsEntry::entryName() const
28 | {
29 | return d->name;
30 | }
31 |
32 | void QSettingsEntry::setEntryName(const QString &name)
33 | {
34 | d->name = name;
35 | }
36 |
37 | bool QSettingsEntry::isOptional() const
38 | {
39 | return d->optional;
40 | }
41 |
42 | void QSettingsEntry::setOptional(bool optional)
43 | {
44 | d->optional = optional;
45 | }
46 |
47 | QString QSettingsEntry::tooltip() const
48 | {
49 | return d->tooltip;
50 | }
51 |
52 | void QSettingsEntry::setTooltip(const QString &tooltip)
53 | {
54 | d->tooltip = tooltip;
55 | }
56 |
57 | UiPropertyMap QSettingsEntry::uiProperties() const
58 | {
59 | return d->properties;
60 | }
61 |
62 | void QSettingsEntry::setUiProperties(const UiPropertyMap &properties)
63 | {
64 | d->properties = properties;
65 | }
66 |
67 | void QSettingsEntry::setUiProperty(const QString &name, const QVariant &value)
68 | {
69 | d->properties.insert(name, value);
70 | }
71 |
72 | int QSettingsEntry::displaytype()
73 | {
74 | return d->displaytype;
75 | }
76 |
77 | QSettingsLoader *QSettingsEntry::getLoader()
78 | {
79 | #ifndef QT_NO_DEBUG
80 | d->refCounter++;
81 | #endif
82 | return d->loader.data();
83 | }
84 |
85 | void QSettingsEntry::freeLoader(QSettingsLoader *)
86 | {
87 | #ifndef QT_NO_DEBUG
88 | d->refCounter--;
89 | #endif
90 | }
91 |
92 | void QSettingsEntryPrivate::LoaderDeleter::cleanup(QSettingsLoader *loader)
93 | {
94 | if(loader && loader->isAsync()) {
95 | auto async = loader->async();
96 | if(async->thread() == QThread::currentThread())
97 | async->deleteLater();
98 | else
99 | QMetaObject::invokeMethod(async, "deleteLater", Qt::QueuedConnection);
100 | } else
101 | delete loader;
102 | }
103 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/checkinghelper.h:
--------------------------------------------------------------------------------
1 | #ifndef CHECKINGHELPER_H
2 | #define CHECKINGHELPER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include "qsettingsgroupwidget.h"
8 |
9 | class CheckingHelper
10 | {
11 | public:
12 | inline CheckingHelper() :
13 | initState(false)
14 | {}
15 | inline virtual ~CheckingHelper() {}
16 |
17 | inline void resetInitState() {
18 | this->initState = this->testChecked();
19 | }
20 | virtual void doCheck() = 0;
21 | inline bool checkedChanged() const {
22 | return this->initState != this->testChecked();
23 | }
24 | virtual bool testChecked() const = 0;
25 | virtual void disableLabel() = 0;
26 |
27 | private:
28 | bool initState;
29 | };
30 |
31 | class CheckingLabel : public QLabel, public CheckingHelper
32 | {
33 | public:
34 | inline CheckingLabel(QWidget *parent = nullptr) :
35 | QLabel(parent),
36 | CheckingHelper()
37 | {}
38 |
39 | inline void doCheck() override {}
40 |
41 | inline bool testChecked() const override {
42 | return true;
43 | }
44 |
45 | inline void disableLabel() override {
46 | this->setEnabled(false);
47 | }
48 | };
49 |
50 | class CheckingCheckBox : public QCheckBox, public CheckingHelper
51 | {
52 | public:
53 | inline CheckingCheckBox(QWidget *parent = nullptr) :
54 | QCheckBox(parent),
55 | CheckingHelper()
56 | {}
57 |
58 | inline void doCheck() override {
59 | this->setChecked(true);
60 | }
61 |
62 | inline bool testChecked() const override {
63 | return this->isChecked();
64 | }
65 |
66 | inline void disableLabel() override {
67 | this->setEnabled(false);
68 | }
69 | };
70 |
71 | class GroupCheckingHelper : public CheckingHelper
72 | {
73 | public:
74 | inline GroupCheckingHelper(QSettingsGroupWidgetBase *element, QSharedPointer entry) :
75 | CheckingHelper(),
76 | element(element),
77 | entry(entry)
78 | {
79 | QObject::connect(element->asWidget(), &QWidget::destroyed, [this](){
80 | delete this;
81 | });
82 | }
83 |
84 | inline void doCheck() override {
85 | this->element->setEntryChecked(this->entry, true);
86 | this->element->setChecked(true);
87 | }
88 |
89 | inline bool testChecked() const override {
90 | if(this->element->isChecked())
91 | return this->element->isEntryChecked(this->entry);
92 | else
93 | return false;
94 | }
95 |
96 | inline void disableLabel() override {
97 | this->element->setEntryLabelEnabled(this->entry, false);
98 | }
99 |
100 | private:
101 | QSettingsGroupWidgetBase *element;
102 | QSharedPointer entry;
103 | };
104 |
105 | #endif // CHECKINGHELPER_H
106 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qsettingsloader.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSLOADER_H
2 | #define QSETTINGSLOADER_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include
6 | #include
7 |
8 | class QSimpleSettingsLoader;
9 | class QAsyncSettingsLoader;
10 | /*!
11 | * @addtogroup grp_core
12 | * @{
13 | */
14 |
15 | //! The basic settings loader class. Serves as utility class
16 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsLoader
17 | {
18 | friend class QSimpleSettingsLoader;
19 | friend class QAsyncSettingsLoader;
20 | Q_DISABLE_COPY(QSettingsLoader)
21 |
22 | public:
23 | //! Virtual destructor
24 | virtual inline ~QSettingsLoader() {}
25 | //! Specifies, whether this loader is async or not
26 | virtual bool isAsync() const = 0;
27 |
28 | //! Casts this instance to a QSimpleSettingsLoader. Will assert if the conversion fails
29 | QSimpleSettingsLoader *simple();
30 | //! Casts this instance to a QAsyncSettingsLoader. Will assert if the conversion fails
31 | QAsyncSettingsLoader *async();
32 |
33 | private:
34 | //! Private constructor to prevent implementation from other classes
35 | QSettingsLoader();
36 | };
37 |
38 | //! Defines a simple, synchronous loader
39 | class QSETTINGSDIALOGSHARED_EXPORT QSimpleSettingsLoader : public QSettingsLoader
40 | {
41 | public:
42 | bool isAsync() const final;
43 |
44 | //! Will be called if settings need to be loaded form this loader
45 | virtual bool load(QVariant outParam data, bool outParam userEdited) = 0;
46 | //! Will be called to save settings from the dialog to this loader
47 | virtual bool save(const QVariant &data) = 0;
48 | //! Will be called to reset the data this loader manages
49 | virtual bool reset() = 0;
50 | };
51 |
52 | //! Defines an asynchronous loader, that can load settings from any thread with any delay
53 | class QSETTINGSDIALOGSHARED_EXPORT QAsyncSettingsLoader : public QObject, public QSettingsLoader
54 | {
55 | Q_OBJECT
56 |
57 | public:
58 | //! Constructs a new loader (without a parent)
59 | QAsyncSettingsLoader();
60 |
61 | bool isAsync() const final;
62 |
63 | public slots:
64 | //! Will be called asynchronously to load data from the objects thread
65 | virtual void loadData() = 0;
66 | //! Will be called asynchronously to save data to the objects thread
67 | virtual void saveData(const QVariant &data) = 0;
68 | //! Will be called asynchronously to reset data to the objects thread
69 | virtual void resetData() = 0;
70 |
71 | signals:
72 | //! Has to be emitted when loading was completed
73 | void loadDone(bool successful, const QVariant &data, bool isUserEdited = true);
74 | //! Has to be emitted when saving was completed
75 | void saveDone(bool successful);
76 | //! Has to be emitted when resetting was completed
77 | void resetDone(bool successful);
78 | };
79 | //! @}
80 |
81 | #endif // QSETTINGSLOADER_H
82 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingsdialogwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSDIALOGWIDGET_H
2 | #define QSETTINGSDIALOGWIDGET_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include "qsettingswidget.h"
6 | #include
7 | #include
8 | #include
9 | class QPushButton;
10 |
11 | //! The base class for dialog based edit widgets in the settings dialog @ingroup grp_dialogui
12 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsDialogWidgetBase : public QSettingsWidget
13 | {
14 | public:
15 | //! Creates a new dialog widget with a parent
16 | QSettingsDialogWidgetBase(QWidget *parent = nullptr);
17 |
18 | //! Returns the text to be shown in the dialog button
19 | virtual QString buttonText() const = 0;
20 | //! Returns the icon to be shown in the dialog button
21 | virtual QIcon buttonIcon() const;
22 | //! Will be called to show the dialog
23 | virtual void showDialog() = 0;
24 |
25 | protected:
26 | //! Overwritten to load button data when showed
27 | void showEvent(QShowEvent *event) final;
28 |
29 | //! Helper to "wrap" any widget inside a dialog
30 | static void wrapInDialog(QDialog *dialog, QWidget *element, bool fixedSize = false);
31 |
32 | private:
33 | QPushButton *btn;
34 | };
35 |
36 | //! A generic class to easily create a dialog widget from a normal one @ingroup grp_dialogui
37 | template
38 | class QSettingsDialogWidget : public QSettingsDialogWidgetBase
39 | {
40 | public:
41 | //! Creates a new dialog widget with a parent
42 | QSettingsDialogWidget(QWidget *parent = nullptr) :
43 | QSettingsDialogWidgetBase(parent),
44 | dialog(nullptr),
45 | widget(new TSettingsWidget(this))
46 | {
47 | if(this->widget->inherits("QDialog"))
48 | this->dialog = (QDialog*)this->widget;
49 | else {
50 | this->dialog = new QDialog(this);
51 | wrapInDialog(this->dialog, this->widget);
52 | }
53 | }
54 |
55 | // QSettingsWidgetBase interface
56 | bool hasValueChanged() const final {
57 | return this->widget->hasValueChanged();
58 | }
59 | void resetValueChanged() final {
60 | this->widget->resetValueChanged();
61 | }
62 | void setValue(const QVariant &value) final {
63 | this->widget->setValue(value);
64 | }
65 | QVariant getValue() const final {
66 | return this->widget->getValue();
67 | }
68 | void resetValue() final {
69 | this->widget->resetValue();
70 | }
71 | bool searchExpression(const QRegularExpression ®ex) final {
72 | return this->widget->searchExpression(regex);
73 | }
74 |
75 | // QSettingsDialogWidgetBase interface
76 | QString buttonText() const override {
77 | return this->widget->windowTitle();
78 | }
79 | QIcon buttonIcon() const override {
80 | return this->widget->windowIcon();
81 | }
82 | void showDialog() final {
83 | this->dialog->open();
84 | }
85 |
86 | private:
87 | QDialog *dialog;
88 | TSettingsWidget *widget;
89 | };
90 |
91 | #endif // QSETTINGSDIALOGWIDGET_H
92 |
--------------------------------------------------------------------------------
/QSettingsDialog/loaders/qsettingssettingsloader.cpp:
--------------------------------------------------------------------------------
1 | #include "qsettingssettingsloader.h"
2 |
3 | #define d this->d_ptr
4 |
5 | class QSettingsSettingsLoaderPrivate
6 | {
7 | public:
8 | QSettingsSettingsLoaderPrivate(QSettings *settings, const QString &key, bool own);
9 | ~QSettingsSettingsLoaderPrivate();
10 |
11 | QSettings *settings;
12 | bool deleteSettings;
13 | QString key;
14 | };
15 |
16 | QSettingsSettingsLoader::QSettingsSettingsLoader(const QString &key) :
17 | d_ptr(new QSettingsSettingsLoaderPrivate(new QSettings(), key, true))
18 | {}
19 |
20 | QSettingsSettingsLoader::QSettingsSettingsLoader(QSettings *settings, const QString &key, bool ownSettings) :
21 | d_ptr(new QSettingsSettingsLoaderPrivate(settings, key, ownSettings))
22 | {}
23 |
24 | QSettingsSettingsLoader::~QSettingsSettingsLoader() {}
25 |
26 |
27 | bool QSettingsSettingsLoader::load(QVariant &data, bool &userEdited)
28 | {
29 | if(!d->settings)
30 | return false;
31 | data = d->settings->value(d->key);
32 | userEdited = d->settings->contains(d->key);
33 | return true;
34 | }
35 |
36 | bool QSettingsSettingsLoader::save(const QVariant &data)
37 | {
38 | if(!d->settings)
39 | return false;
40 | d->settings->setValue(d->key, data);
41 | return true;
42 | }
43 |
44 | bool QSettingsSettingsLoader::reset()
45 | {
46 | if(!d->settings)
47 | return false;
48 | d->settings->remove(d->key);
49 | return true;
50 | }
51 |
52 | QHash QSettingsSettingsLoader::createLoaders(QSettings *settings, const QString &rootKey, bool recursive)
53 | {
54 | if(!rootKey.isEmpty())
55 | settings->beginGroup(rootKey);
56 |
57 | auto resMap = createLoadersImpl(settings, rootKey, recursive);
58 |
59 | if(!rootKey.isEmpty())
60 | settings->endGroup();
61 | return resMap;
62 | }
63 |
64 | QHash QSettingsSettingsLoader::createLoadersImpl(QSettings *settings, const QString &rootKey, bool recursive)
65 | {
66 | auto beginBase = rootKey.isEmpty() ? QString() : rootKey + QLatin1Char('/');
67 | QHash resMap;
68 |
69 | foreach(auto key, settings->childKeys())
70 | resMap.insert(beginBase + key, new QSettingsSettingsLoader(settings, beginBase + key));
71 |
72 | if(recursive) {
73 | foreach(auto group, settings->childGroups()) {
74 | auto newKey = beginBase + group;
75 | settings->beginGroup(rootKey);
76 | resMap.unite(createLoadersImpl(settings, newKey, true));
77 | settings->endGroup();
78 | }
79 | }
80 |
81 | return resMap;
82 | }
83 |
84 |
85 |
86 | QSettingsSettingsLoaderPrivate::QSettingsSettingsLoaderPrivate(QSettings *settings, const QString &key, bool own) :
87 | settings(settings),
88 | deleteSettings(own),
89 | key(key)
90 | {}
91 |
92 | QSettingsSettingsLoaderPrivate::~QSettingsSettingsLoaderPrivate()
93 | {
94 | if(this->deleteSettings)
95 | this->settings->deleteLater();
96 | }
97 |
--------------------------------------------------------------------------------
/Examples/SimpleExample/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 |
9 | QSettings settings(QApplication::applicationDirPath() + "/test.ini", QSettings::IniFormat);
10 |
11 | //a simple example showing how to display values from settings with the dialog
12 | QSettingsDialog dialog;
13 | dialog.appendEntry(new QSettingsEntry(QMetaType::QString,
14 | new QSettingsSettingsLoader(&settings, "appName"),
15 | "App name"));
16 | dialog.appendEntry(new QSettingsEntry(QMetaType::QString,
17 | new QSettingsSettingsLoader(&settings, "companyName"),
18 | "Company name"));
19 |
20 | dialog.setGroup("versionGroup", 0, "Version", true, "Please configure the version");
21 | dialog.appendEntry(new QSettingsEntry(QMetaType::Int,
22 | new QSettingsSettingsLoader(&settings, "version/major"),
23 | "Major",
24 | false,
25 | QString(),
26 | {{"minimum", 0}, {"maximum", 9}}));
27 | dialog.appendEntry(new QSettingsEntry(QMetaType::Int,
28 | new QSettingsSettingsLoader(&settings, "version/minor"),
29 | "Minor",
30 | false,
31 | QString(),
32 | {{"minimum", 0}, {"maximum", 9}}));
33 | dialog.appendEntry(new QSettingsEntry(QMetaType::Int,
34 | new QSettingsSettingsLoader(&settings, "version/patch"),
35 | "Patch",
36 | false,
37 | QString(),
38 | {{"minimum", 0}, {"maximum", 9}}));
39 |
40 | dialog.unsetGroup();
41 | dialog.appendEntry(new QSettingsEntry(QMetaType::QString,
42 | new QSettingsSettingsLoader(&settings, "authorName"),
43 | "Load Programmer",
44 | true));
45 |
46 | dialog.setSection("more", "More Stuff");
47 | dialog.appendEntry(new QSettingsEntry(QMetaType::Bool,
48 | new QSettingsSettingsLoader(&settings, "allow/A"),
49 | "Allow Option A"));
50 | dialog.appendEntry(new QSettingsEntry(QMetaType::Bool,
51 | new QSettingsSettingsLoader(&settings, "allow/B"),
52 | "Allow Option B"));
53 | dialog.appendEntry(new QSettingsEntry(QMetaType::Bool,
54 | new QSettingsSettingsLoader(&settings, "allow/C"),
55 | "Allow Option C"));
56 |
57 | dialog.setCategory("secret", "Secret Secure Settings", QIcon(":/QSettingsDialog/icons/gearSettings.ico"));
58 | dialog.setSection(".");//will not be required in next version
59 | dialog.appendEntry(new QSettingsEntry(QMetaType::QUrl,
60 | new QSettingsSettingsLoader(&settings, "secretUrl"),
61 | "Very secret url"));
62 | dialog.appendEntry(new QSettingsEntry(QMetaType::QColor,
63 | new QSettingsSettingsLoader(&settings, "secretColor"),
64 | "Very secret color"));
65 |
66 | return dialog.execSettings();
67 | }
68 |
--------------------------------------------------------------------------------
/QSettingsDialog/variantwidgets/settingsdatetimeedit.cpp:
--------------------------------------------------------------------------------
1 | #include "settingsdatetimeedit.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | static void setupCornerButton(QWidget *parent, QCalendarWidget *calendar);
9 |
10 | SettingsDateEdit::SettingsDateEdit(QWidget *parent) :
11 | QSettingsWidget(parent)
12 | {
13 | this->setCalendarPopup(true);
14 | setupCornerButton(this, this->calendarWidget());
15 | }
16 |
17 | void SettingsDateEdit::setValue(const QVariant &value)
18 | {
19 | this->setDate(value.toDate());
20 | }
21 |
22 | QVariant SettingsDateEdit::getValue() const
23 | {
24 | return this->date();
25 | }
26 |
27 | void SettingsDateEdit::resetValue()
28 | {
29 | this->setDate(QDate());
30 | }
31 |
32 |
33 |
34 | SettingsTimeEdit::SettingsTimeEdit(QWidget *parent) :
35 | QSettingsWidget(parent)
36 | {}
37 |
38 | void SettingsTimeEdit::setValue(const QVariant &value)
39 | {
40 | qDebug("data");
41 | this->setTime(value.toTime());
42 | }
43 |
44 | QVariant SettingsTimeEdit::getValue() const
45 | {
46 | return this->time();
47 | }
48 |
49 | void SettingsTimeEdit::resetValue()
50 | {
51 | this->setTime(QTime());
52 | }
53 |
54 |
55 |
56 | SettingsDateTimeEdit::SettingsDateTimeEdit(QWidget *parent) :
57 | QSettingsWidget(parent)
58 | {
59 | this->setCalendarPopup(true);
60 | setupCornerButton(this, this->calendarWidget());
61 | }
62 |
63 | void SettingsDateTimeEdit::setValue(const QVariant &value)
64 | {
65 | this->setDateTime(value.toDateTime());
66 | }
67 |
68 | QVariant SettingsDateTimeEdit::getValue() const
69 | {
70 | return this->dateTime();
71 | }
72 |
73 | void SettingsDateTimeEdit::resetValue()
74 | {
75 | this->setDateTime(QDateTime());
76 | }
77 |
78 |
79 |
80 | static void setupCornerButton(QWidget *parent, QCalendarWidget *calendar)
81 | {
82 | //setup calendar widget
83 | calendar->setVerticalHeaderFormat(QCalendarWidget::ISOWeekNumbers);
84 | auto viewTable = calendar->findChild(QStringLiteral("qt_calendar_calendarview"));
85 | if(viewTable) {
86 | auto todayButton = new QToolButton(viewTable);
87 | todayButton->setAutoRaise(true);
88 | todayButton->setIcon(QIcon(QStringLiteral(":/QSettingsDialog/icons/today.ico")));
89 | QObject::connect(todayButton, &QToolButton::clicked, calendar, [calendar](){
90 | calendar->setSelectedDate(QDate::currentDate());
91 | });
92 |
93 | auto vHeader = viewTable->verticalHeader();
94 | QObject::connect(vHeader, &QHeaderView::geometriesChanged,
95 | parent, [=](){
96 | todayButton->setFixedSize(todayButton->width(), vHeader->sectionSize(0));
97 | });
98 |
99 | auto hHeader = viewTable->horizontalHeader();
100 | QObject::connect(hHeader, &QHeaderView::geometriesChanged,
101 | parent, [=](){
102 | todayButton->setFixedSize(hHeader->sectionSize(0) - 1, todayButton->height());
103 | });
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/QSettingsDialog/dialogui/qsettingsgroupwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSGROUPWIDGET_H
2 | #define QSETTINGSGROUPWIDGET_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include "qsettingsentry.h"
6 | #include
7 | class QSettingsWidgetBase;
8 | class QCheckBox;
9 |
10 | //! The base class for group widgets in the settings dialog @ingroup grp_dialogui
11 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsGroupWidgetBase
12 | {
13 | public:
14 | //! Virtual destructor
15 | virtual ~QSettingsGroupWidgetBase();
16 |
17 | //! Must return this as QWidget (a cast)
18 | virtual QWidget *asWidget() = 0;
19 | //! Will be called to initialize the widgets properties with the given ones
20 | virtual void initialize(const UiPropertyMap &uiPropertyMap) = 0;
21 |
22 | //! Will be called to set the name (title) of the group
23 | virtual void setName(const QString &name) = 0;
24 | //! Will be called to set the tooltip of the group
25 | virtual void setTooltip(const QString &tooltip) = 0;
26 | //! Will be called to set the group optional or required
27 | virtual void setOptional(bool optional) = 0;
28 |
29 | //! Returns whether the group is checked or not
30 | virtual bool isChecked() const = 0;
31 | //! Sets the groups checked state
32 | virtual void setChecked(bool checked) = 0;
33 |
34 | //! Adds a widget to the dialog in a raw way.
35 | virtual void addWidgetRaw(QSharedPointer entry, QWidget *content, bool hasError);
36 | //! Sets an entry within the dialog to be checked
37 | virtual void setEntryChecked(QSharedPointer entry, bool checked);
38 | //! Enables or disables an entry (and it's label) in the group
39 | virtual void setEntryLabelEnabled(QSharedPointer entry, bool enabled);
40 | //! Will be called to find out whether one entry within the group is checked
41 | virtual bool isEntryChecked(QSharedPointer entry) const;
42 |
43 | //! Called to search for the expression within the group and it's children
44 | virtual bool searchExpression(const QRegularExpression ®ex, const QString &searchStyleSheet);
45 |
46 | protected:
47 | //! Simple way to add widgets with a label to the group
48 | virtual void addWidgetWithLabel(QWidget *label, QWidget *content) = 0;
49 |
50 | //! Defines one "element" within the group - label and edit widget
51 | typedef QPair GroupElement;
52 | //! A map that contains all elements withing this group, by their entry
53 | QHash, GroupElement> entryMap;
54 | };
55 |
56 | //! Generic base class for group widgets @ingroup grp_dialogui
57 | template
58 | class QSettingsGroupWidget : public TWidget, public QSettingsGroupWidgetBase
59 | {
60 | public:
61 | //! Creates a new group widget with a parent
62 | inline QSettingsGroupWidget(QWidget *parent = nullptr) :
63 | TWidget(parent),
64 | QSettingsGroupWidgetBase()
65 | {}
66 |
67 | inline QWidget *asWidget() final {
68 | return this;
69 | }
70 | void initialize(const UiPropertyMap &uiPropertyMap) override {
71 | for(UiPropertyMap::const_iterator it = uiPropertyMap.constBegin(), end = uiPropertyMap.constEnd(); it != end; ++it)
72 | this->setProperty(it.key().toLocal8Bit().constData(), it.value());
73 | }
74 | };
75 |
76 | #endif // QSETTINGSGROUPWIDGET_H
77 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/qsettingsentry.h:
--------------------------------------------------------------------------------
1 | #ifndef QSETTINGSENTRY_H
2 | #define QSETTINGSENTRY_H
3 |
4 | #include "qsettingsdialog_global.h"
5 | #include
6 | #include
7 | #include "qsettingsloader.h"
8 |
9 | class QSettingsEntryPrivate;
10 | //! Represents one settings entry within the settings dialog. \ingroup grp_core
11 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsEntry
12 | {
13 | friend class SettingsEntryLayout;
14 |
15 | public:
16 | //! Creates a new entry from a display id and a loader @own loader
17 | QSettingsEntry(int displaytype, QSettingsLoader *loader);
18 | //! Creates a new entry from a display id, a loader and it's properties @own loader
19 | QSettingsEntry(int displaytype,
20 | QSettingsLoader *loader,
21 | const QString &name,
22 | bool optional = false,
23 | const QString &tooltip = QString(),
24 | const UiPropertyMap &properties = UiPropertyMap());
25 | //! Creates a new entry from a display id, a loader and it's properties @own loader
26 | template
27 | QSettingsEntry(int displaytype,
28 | QSettingsLoader *loader,
29 | const QString &name,
30 | bool optional,
31 | const QString &tooltip,
32 | Args... properties);
33 | //! Virtual destructor
34 | virtual ~QSettingsEntry();
35 |
36 | //! Returns the display name of this entry
37 | QString entryName() const;
38 | //! Sets the display name of this entry
39 | void setEntryName(const QString &name);
40 | //! Specifies, whether the entry is optional or not
41 | bool isOptional() const;
42 | //! Sets the entry be optional or not optional
43 | void setOptional(bool optional);
44 | //! Returns the tooltip this entry has
45 | QString tooltip() const;
46 | //! Sets this entries tooltip
47 | void setTooltip(const QString &tooltip);
48 |
49 | //! Returns the properties that should be set on the ui-elements for this entry
50 | UiPropertyMap uiProperties() const;
51 | //! Sets the properties that should be set on the ui-elements for this entry
52 | void setUiProperties(const UiPropertyMap &properties);
53 | //! Adds a new property to the existing ones that should be set on the ui-elements for this entry
54 | void setUiProperty(const QString &name, const QVariant &value);
55 |
56 | //! Returns the display type id for this entry
57 | virtual int displaytype();
58 | //! Will be called to get a reference to loader this entry holds
59 | virtual QSettingsLoader *getLoader();
60 | //! Will be called to remove a reference to the loader this entry holds
61 | virtual void freeLoader(QSettingsLoader *loader);//TODO required?
62 |
63 | private:
64 | QScopedPointer d_ptr;
65 | };
66 |
67 |
68 |
69 | template
70 | UiPropertyMap mapWrapper(const char *key, TVariant value) {
71 | return UiPropertyMap({{key, QVariant::fromValue(value)}});
72 | }
73 |
74 | template
75 | UiPropertyMap mapWrapper(const char *key, TVariant value, Args... params) {
76 | auto map = mapWrapper(params...);
77 | map.insert(key, QVariant::fromValue(value));
78 | return map;
79 | }
80 |
81 | template
82 | QSettingsEntry::QSettingsEntry(int metatype, QSettingsLoader *loader, const QString &name, bool optional, const QString &tooltip, Args... properties) :
83 | QSettingsEntry(metatype, loader, name, optional, tooltip, mapWrapper(properties...))
84 | {}
85 |
86 | #endif // QSETTINGSENTRY_H
87 |
--------------------------------------------------------------------------------
/QSettingsDialog/loaders/qsettingspropertyloader.cpp:
--------------------------------------------------------------------------------
1 | #include "qsettingspropertyloader.h"
2 | #include
3 |
4 | #define d this->d_ptr
5 |
6 | class QSettingsPropertyLoaderPrivate
7 | {
8 | public:
9 | QMetaProperty property;
10 | QPointer object;
11 | void *gadget;
12 |
13 | QSettingsPropertyLoaderPrivate() :
14 | property(),
15 | object(nullptr),
16 | gadget(nullptr)
17 | {}
18 | };
19 |
20 | QSettingsPropertyLoader::QSettingsPropertyLoader(const char *propertyName, QObject *object) :
21 | QAsyncSettingsLoader(),
22 | d_ptr(new QSettingsPropertyLoaderPrivate())
23 | {
24 | d->object = object;
25 | auto meta = object->metaObject();
26 | int index = meta->indexOfProperty(propertyName);
27 | if(index >= 0)
28 | d->property = meta->property(index);
29 | }
30 |
31 | QSettingsPropertyLoader::QSettingsPropertyLoader(const QMetaProperty &metaProperty, QObject *object) :
32 | QAsyncSettingsLoader(),
33 | d_ptr(new QSettingsPropertyLoaderPrivate())
34 | {
35 | d->object = object;
36 | d->property = metaProperty;
37 | }
38 |
39 | QSettingsPropertyLoader::QSettingsPropertyLoader(const char *propertyName, QMetaObject *metaObject, void *gadget) :
40 | QAsyncSettingsLoader(),
41 | d_ptr(new QSettingsPropertyLoaderPrivate())
42 | {
43 | d->gadget = gadget;
44 | int index = metaObject->indexOfProperty(propertyName);
45 | if(index >= 0)
46 | d->property = metaObject->property(index);
47 | }
48 |
49 | QSettingsPropertyLoader::QSettingsPropertyLoader(const QMetaProperty &metaProperty, void *gadget) :
50 | QAsyncSettingsLoader(),
51 | d_ptr(new QSettingsPropertyLoaderPrivate())
52 | {
53 | d->gadget = gadget;
54 | d->property = metaProperty;
55 | }
56 |
57 | QSettingsPropertyLoader::~QSettingsPropertyLoader() {}
58 |
59 | int QSettingsPropertyLoader::metatypeId() const
60 | {
61 | auto id = d->property.userType();
62 | if(id == QMetaType::UnknownType)
63 | id = d->property.type();
64 | return id;
65 | }
66 |
67 | bool QSettingsPropertyLoader::isValid() const
68 | {
69 | return (!d->object.isNull() || d->gadget) &&
70 | d->property.isValid() &&
71 | d->property.isReadable();
72 | }
73 |
74 | void QSettingsPropertyLoader::loadData()
75 | {
76 | if(!d->property.isReadable())
77 | emit loadDone(false, QVariant());
78 |
79 | if(d->object) {
80 | auto value = d->property.read(d->object);
81 | emit loadDone(true, value);
82 | } else if(d->gadget) {
83 | auto value = d->property.readOnGadget(d->gadget);
84 | emit loadDone(true, value);
85 | } else
86 | emit loadDone(false, QVariant());
87 | }
88 |
89 | void QSettingsPropertyLoader::saveData(const QVariant &data)
90 | {
91 | if(!d->property.isWritable())
92 | emit saveDone(false);
93 |
94 | if(d->object) {
95 | auto ok = d->property.write(d->object, data);
96 | emit saveDone(ok);
97 | } else if(d->gadget) {
98 | auto ok = d->property.writeOnGadget(d->gadget, data);
99 | emit saveDone(ok);
100 | } else
101 | emit saveDone(false);
102 | }
103 |
104 | void QSettingsPropertyLoader::resetData()
105 | {
106 | if(!d->property.isResettable())
107 | emit resetDone(false);
108 |
109 | if(d->object) {
110 | auto ok = d->property.reset(d->object);
111 | emit resetDone(ok);
112 | } else if(d->gadget) {
113 | auto ok = d->property.resetOnGadget(d->gadget);
114 | emit resetDone(ok);
115 | } else
116 | emit resetDone(false);
117 | }
118 |
--------------------------------------------------------------------------------
/QSettingsDialog/core/specialgroupmap.h:
--------------------------------------------------------------------------------
1 | #ifndef SPECIALGROUPMAP_H
2 | #define SPECIALGROUPMAP_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "sortedmap.h"
9 | struct SettingsGroup;
10 | class QSettingsEntry;
11 |
12 | class SpecialGroupMap
13 | {
14 | public:
15 | typedef QPair, QSharedPointer> Value;
16 | typedef QPair Entry;
17 |
18 | SpecialGroupMap();
19 | ~SpecialGroupMap();
20 |
21 | //global operations
22 | int size() const;
23 | bool hasIndex(int index) const;
24 | QVariant id(int index) const;
25 | int index(const QVariant &id) const;
26 | QList entries() const;
27 | Entry entry(int index) const;
28 | bool remove(int index);
29 | Entry take(int index);
30 | void move(int indexFrom, int indexTo);
31 |
32 | //group base operations
33 | QSharedPointer append(const QString &id, SettingsGroup *entry);
34 | void append(const QString &id, const QSharedPointer