├── .gitignore ├── .gitmodules ├── ClassModel.qmodel ├── Examples ├── EngineTest │ ├── EngineTest.pro │ ├── delayedtestentry.cpp │ ├── delayedtestentry.h │ ├── main.cpp │ ├── swidget.cpp │ ├── swidget.h │ ├── testentry.cpp │ └── testentry.h ├── Examples.pro ├── LoadersTest │ ├── LoadersTest.pro │ └── main.cpp ├── SimpleExample │ ├── SimpleExample.pro │ └── main.cpp ├── VariantWidgetsTest │ ├── VariantWidgetsTest.pro │ ├── main.cpp │ ├── metawrapper.cpp │ └── metawrapper.h └── loadLib.pri ├── LICENSE ├── QSettingsDialog.pro ├── QSettingsDialog ├── QSettingsDialog.pro ├── classmodel.qmodel ├── core │ ├── container_path_syntax.txt │ ├── containerelements.h │ ├── core.pri │ ├── exceptions.cpp │ ├── exceptions.h │ ├── grp_core.dox │ ├── private.pri │ ├── qasyncsettingscontainer.cpp │ ├── qasyncsettingscontainer.dox │ ├── qasyncsettingscontainer.h │ ├── qasyncsettingscontainer_p.h │ ├── qsettingscontainer.cpp │ ├── qsettingscontainer.dox │ ├── qsettingscontainer.h │ ├── qsettingsdialog.cpp │ ├── qsettingsdialog.dox │ ├── qsettingsdialog.h │ ├── qsettingsdialog_p.h │ ├── qsettingsdisplayengine.h │ ├── qsettingsentry.cpp │ ├── qsettingsentry.dox │ ├── qsettingsentry.h │ ├── qsettingsentry_p.h │ ├── qsettingslayout.cpp │ ├── qsettingslayout.dox │ ├── qsettingslayout.h │ ├── qsettingslayout_p.h │ ├── qsettingsloader.cpp │ ├── qsettingsloader.dox │ ├── qsettingsloader.h │ ├── qsettingsloaderentry.h │ ├── settingspathparser.cpp │ ├── settingspathparser.h │ ├── sortedmap.h │ ├── specialgroupmap.cpp │ └── specialgroupmap.h ├── dialogui │ ├── checkinghelper.h │ ├── commonfactoryregistry.cpp │ ├── commonfactoryregistry.h │ ├── dialogui.pri │ ├── grp_dialogui.dox │ ├── private.pri │ ├── qsettingsdialogwidget.cpp │ ├── qsettingsdialogwidget.dox │ ├── qsettingsdialogwidget.h │ ├── qsettingsgroupwidget.cpp │ ├── qsettingsgroupwidget.dox │ ├── qsettingsgroupwidget.h │ ├── qsettingsgroupwidgetfactory.dox │ ├── qsettingsgroupwidgetfactory.h │ ├── qsettingswidget.cpp │ ├── qsettingswidget.dox │ ├── qsettingswidget.h │ ├── qsettingswidgetdialogengine.cpp │ ├── qsettingswidgetdialogengine.dox │ ├── qsettingswidgetdialogengine.h │ ├── qsettingswidgetfactory.dox │ ├── qsettingswidgetfactory.h │ ├── qsettingswidgetfactoryregistry.dox │ ├── qsettingswidgetfactoryregistry.h │ ├── settingsdisplaydialog.cpp │ ├── settingsdisplaydialog.h │ ├── settingsdisplaydialog.ui │ ├── settingsengine.cpp │ └── settingsengine.h ├── doc │ ├── QSettingsDialog.doxy │ ├── images │ │ ├── dialogwidget_button.png │ │ ├── mac_sample.png │ │ ├── structure_core.svg │ │ ├── structure_dialogui.svg │ │ ├── structure_global.svg │ │ ├── structure_loaders.svg │ │ ├── structure_variantwidgets.svg │ │ ├── win_sample.png │ │ └── x11_sample.png │ └── modules_snippet.html ├── generateIncludes.bat ├── loaders │ ├── grp_loaders.dox │ ├── loaders.pri │ ├── private.pri │ ├── qsettingspropertyentry.cpp │ ├── qsettingspropertyentry.h │ ├── qsettingspropertyloader.cpp │ ├── qsettingspropertyloader.dox │ ├── qsettingspropertyloader.h │ ├── qsettingssettingsloader.cpp │ ├── qsettingssettingsloader.dox │ └── qsettingssettingsloader.h ├── qsettingsdialog.pri ├── qsettingsdialog_global.cpp ├── qsettingsdialog_global.h ├── qsettingsdialog_res.qrc ├── qtexception.cpp ├── qtexception.h ├── resources │ ├── gear_in.ico │ └── setting_tools.ico ├── submodules │ └── submodules.pri └── variantwidgets │ ├── grp_variantwidgets.dox │ ├── private.pri │ ├── qsettingsdialog_variantwidgets_res.qrc │ ├── qsettingsextendedtypes.h │ ├── resources │ ├── add.ico │ ├── arrow_down.ico │ ├── arrow_up.ico │ ├── calculator.ico │ ├── delete.ico │ └── outlook_calendar_day.ico │ ├── settingscheckbox.cpp │ ├── settingscheckbox.h │ ├── settingscoloredit.cpp │ ├── settingscoloredit.h │ ├── settingsdatetimeedit.cpp │ ├── settingsdatetimeedit.h │ ├── settingsenumcombobox.cpp │ ├── settingsenumcombobox.h │ ├── settingsenumwidgetfactory.cpp │ ├── settingsenumwidgetfactory.h │ ├── settingsflagschecklist.cpp │ ├── settingsflagschecklist.h │ ├── settingsfontcombobox.cpp │ ├── settingsfontcombobox.h │ ├── settingsgroupbox.cpp │ ├── settingsgroupbox.h │ ├── settingskeyedit.cpp │ ├── settingskeyedit.h │ ├── settingslineedit.cpp │ ├── settingslineedit.h │ ├── settingslistedit.cpp │ ├── settingslistedit.h │ ├── settingslistedit.ui │ ├── settingspathedit.cpp │ ├── settingspathedit.h │ ├── settingsrichtextedit.cpp │ ├── settingsrichtextedit.h │ ├── settingsslider.cpp │ ├── settingsslider.h │ ├── settingsspinbox.cpp │ ├── settingsspinbox.h │ ├── variantwidgets.pri │ ├── variantwidgetsregistrator.cpp │ ├── variantwidgetsregistrator.dox │ └── variantwidgetsregistrator.h └── README.md /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Examples/Examples.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += \ 4 | EngineTest \ 5 | VariantWidgetsTest \ 6 | LoadersTest \ 7 | SimpleExample 8 | 9 | OTHER_FILES += loadLib.pri 10 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Examples/VariantWidgetsTest/metawrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "metawrapper.h" 2 | 3 | MetaWrapper::MetaWrapper(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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.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.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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/core/qsettingsdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef QSETTINGSDIALOG_H 2 | #define QSETTINGSDIALOG_H 3 | 4 | #include "qsettingsdialog_global.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "exceptions.h" 10 | #include "qsettingsentry.h" 11 | class QSettingsDisplayEngine; 12 | class QSettingsContainer; 13 | 14 | class QSettingsDialogPrivate; 15 | //! The main class that represents the dialog itself. \ingroup grp_core 16 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsDialog : public QObject 17 | { 18 | Q_OBJECT 19 | friend class QSettingsDialogPrivate; 20 | 21 | public: 22 | //! Creates a new settings dialog with a parent 23 | explicit QSettingsDialog(QObject *parent = nullptr); 24 | //! Creates a new settings dialog with a parent and a custom display engine 25 | explicit QSettingsDialog(QSettingsDisplayEngine *engine, QObject *parent = nullptr); 26 | //! Destructor 27 | ~QSettingsDialog(); 28 | 29 | //! Returns the current display engine of dialog 30 | QSettingsDisplayEngine *displayEngine() const; 31 | //! Sets the display engine to a new one @own engine 32 | void setDisplayEngine(QSettingsDisplayEngine *engine); 33 | 34 | //container organisation - getters 35 | //! Returns the complete current container path 36 | QString containerPath() const; 37 | //! Returns the current container path up to the section, excluding groups 38 | QString sectionContainerPath() const; 39 | //! Returns the current category id 40 | QString categoryId() const; 41 | //! Returns the current section id 42 | QString sectionId() const; 43 | //! Returns the current group id 44 | QString groupId() const; 45 | 46 | //container organisation - setters 47 | //! Sets the current category and optionally modifies it's appeareance 48 | void setCategory(const QString &id, 49 | const QString &name = QString(), 50 | const QIcon &icon = QIcon(), 51 | const QString &tooltip = QString()); 52 | //! Sets the current section and optionally modifies it's appeareance 53 | void setSection(const QString &id, 54 | const QString &name = QString(), 55 | const QIcon &icon = QIcon(), 56 | const QString &tooltip = QString()); 57 | //! Sets the current group and optionally modifies it's appeareance 58 | void setGroup(const QString &id, 59 | int displayId = -1, 60 | const QString &name = QString(), 61 | int optional = -1, 62 | const QString &tooltip = QString()); 63 | //! Sets the current group to nothing 64 | void unsetGroup(); 65 | 66 | //! Sets the whole container path (category, section and (optionally) group) 67 | void setContainer(const QString &containerPath); 68 | //! Removes the container with the given path 69 | bool removeContainer(const QString &containerPath); 70 | 71 | //! Creates a new settings container for the current path configuration 72 | QSettingsContainer *currentContainer(QObject *parent = nullptr); 73 | //! Creates a new async settings container for the current path configuration 74 | QSettingsContainer *currentContainerAsync(QObject *parent = nullptr); 75 | //! Creates a new settings container for the current section 76 | QSettingsContainer *currentSectionContainer(QObject *parent = nullptr); 77 | //! Creates a new async settings container for the current section 78 | QSettingsContainer *currentSectionContainerAsync(QObject *parent = nullptr); 79 | 80 | //entry organisation 81 | //! Appends the given entry to the current container 82 | int appendEntry(QSettingsEntry *entry); 83 | //! Appends the given entry to to the container specified 84 | int appendEntry(const QString &containerPath, QSettingsEntry *entry); 85 | //! Prepends the given entry to the current container 86 | int prependEntry(QSettingsEntry *entry); 87 | //! Prepends the given entry to to the container specified 88 | int prependEntry(const QString &containerPath, QSettingsEntry *entry); 89 | 90 | //! Searches for an entry with the given id 91 | QSharedPointer getEntry(int id) const; 92 | //! Searches for the path of the container of the entry with the given id 93 | QString getEntryPath(int id) const; 94 | //! Searches for an entry with the given id and removes it 95 | bool removeEntry(int id); 96 | 97 | //helper 98 | //! Creates a container path string from category, section and group 99 | static QString createContainerPath(QString category = QString(), 100 | QString section = QString(), 101 | QString group = QString()); 102 | 103 | public slots: 104 | //! Creates a new display dialog and shows it without blocking 105 | void openSettings(QWidget *parentWindow = nullptr); 106 | //! Creates a new display dialog and shows it blocking 107 | int execSettings(QWidget *parentWindow = nullptr); 108 | 109 | signals: 110 | //! Will be emitted everytime the user saves his settings. 111 | void saved(bool closed); 112 | //! Will be emitted if the user resets the settings 113 | void resetted(); 114 | //! Will be emitted if the user canceld the settings dialog 115 | void canceled(); 116 | 117 | private slots: 118 | void completed(bool close = true); 119 | 120 | private: 121 | QScopedPointer d_ptr; 122 | }; 123 | 124 | #endif // QSETTINGSDIALOG_H 125 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/core/qsettingslayout.h: -------------------------------------------------------------------------------- 1 | #ifndef QSETTINGSLAYOUT_H 2 | #define QSETTINGSLAYOUT_H 3 | 4 | #include "qsettingsdialog_global.h" 5 | #include "exceptions.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | class QSettingsDialog; 11 | class QSettingsContainer; 12 | 13 | class QSettingsLayoutPrivate; 14 | //! A general class to modifiy the appereance of elements of a settings dialog @ingroup grp_core 15 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsLayout 16 | { 17 | friend class SettingsEntryLayout; 18 | friend class SettingsGroupLayout; 19 | friend class SettingsSectionLayout; 20 | friend class SettingsCategoryLayout; 21 | friend class SettingsRootLayout; 22 | 23 | public: 24 | //! Defines the different elements a layout can be created for 25 | enum LayoutType { 26 | DialogLayout, //!< The layout represents the dialog itself 27 | CategoryLayout, //!< The layout represents a category 28 | SectionLayout, //!< The layout represents a section 29 | GroupLayout, //!< The layout represents a group 30 | EntryLayout //!< The layout represents an entry 31 | }; 32 | 33 | //! Creates a new layout for the given dialogs root element or current container 34 | explicit QSettingsLayout(QSettingsDialog *settingsDialog, bool fromCurrentContainer = false); 35 | //! Creates a new layout for the given container in the dialog or an entry within that container 36 | explicit QSettingsLayout(QSettingsDialog *settingsDialog, const QString &containerPath, int entryId = -1); 37 | //! Creates a new layout from the given container 38 | explicit QSettingsLayout(QSettingsContainer *container); 39 | 40 | //! Returns the container id of the current container 41 | QString id() const; 42 | //! Returns the element type this layout represents 43 | LayoutType layoutType() const; 44 | //! Returns whether this layout is a null-layout (does not represent anything) 45 | bool isNull() const; 46 | 47 | //! Returns the dialog this layout belongs to 48 | QSettingsDialog *dialog() const; 49 | //! Returns the full container path of the element 50 | QString containerPath() const; 51 | 52 | //! Returns the parent container element, if available 53 | QSettingsLayout parentContainer() const; 54 | 55 | //! Gets the elements display id 56 | int displayId() const; 57 | //! Sets the elements display id 58 | void setDisplayId(int displayId); 59 | //! Gets the elements name 60 | QString name() const; 61 | //! Sets the elements name 62 | void setName(const QString &name); 63 | //! Gets the elements icon 64 | QIcon icon() const; 65 | //! Sets the elements icon 66 | void setIcon(const QIcon &icon); 67 | //! Gets the elements tooltip 68 | QString tooltip() const; 69 | //! Sets the elements tooltip 70 | void setTooltip(const QString &tooltip); 71 | //! Gets whether the element is optional or not 72 | bool isOptional() const; 73 | //! Sets whether the element is optional or not 74 | void setOptional(bool optional); 75 | 76 | //! Returns the elements default child element 77 | QSettingsLayout defaultElement(bool allowCreateNew = false) const; 78 | //! Removes the default element, if it exists 79 | bool removeDefaultElement(); 80 | 81 | //! Returns the number of children this element has 82 | int elementCount() const; 83 | //! Gets the child element at the given position 84 | QSettingsLayout elementAt(int index) const; 85 | //! Gets the child index of the given element within this element 86 | int indexOfElement(const QSettingsLayout &element) const; 87 | //! Gets the child index of the given element by name within this element 88 | int indexOfElement(const QString &elementName) const; 89 | //! Creates a new child element at the given index 90 | QSettingsLayout createElement(int index, 91 | const QString &id, 92 | const QString &name = QString(), 93 | const QIcon &icon = QIcon(), 94 | const QString &tooltip = QString()); 95 | //! Creates a new optional child element at the given index 96 | QSettingsLayout createGroupElement(int index, 97 | const QString &id, 98 | int displayId = 0, 99 | const QString &name = QString(), 100 | bool optional = false, 101 | const QString &tooltip = QString()); 102 | //! Removes the child element at the given index 103 | void removeElement(int index); 104 | //! Moves the child from one index to a new one 105 | void moveElement(int indexFrom, int indexTo); 106 | 107 | //! Transfers a child from this layout to the given target 108 | void transferElement(int indexFrom, QSettingsLayout targetLayout, int indexTo); 109 | 110 | private: 111 | QSharedPointer d_ptr; 112 | 113 | QSettingsLayout(QSettingsLayoutPrivate *d_ptr); 114 | }; 115 | 116 | #endif // QSETTINGSLAYOUT_H 117 | -------------------------------------------------------------------------------- /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/qsettingsloader.dox: -------------------------------------------------------------------------------- 1 | /*! 2 | @class QSimpleSettingsLoader 3 | 4 | The simple loader can be used to manage settings sources that are fast and can be accessed synchronously from the main thread. 5 | 6 | For sources that belong to different threads or will take some time to be loaded/saved, please use QAsyncSettingsLoader 7 | */ 8 | 9 | /*! 10 | @fn QSimpleSettingsLoader::load 11 | 12 | @param data **[outParam]** A reference to the `QVariant` object to load the data into. (Defaults to `QVariant::Invalid`) 13 | @param userEdited **[outParam]** A reference to a `bool` to specify whether the value comes from the user or is the default. (Defaults to `false`) 14 | @returns Should return `true`, if loading was successful, `false` if not 15 | 16 | This method will be called from the engine to load settings for the display dialog. The loaded value should be written into `data`. You can use 17 | the @a userEdited parameter to activate/deactivate the entry. If loading was successful return `true`. If not return `false` and an error will be shown 18 | to the user and the entry that uses this loader will be diabled. 19 | */ 20 | 21 | /*! 22 | @fn QSimpleSettingsLoader::save 23 | 24 | @param data The data to be saved. 25 | @returns `true`, if saving was successful, `false` if not 26 | 27 | If saving was successful return `true`. If not return `false` and an error will be shown 28 | to the user and the entry that uses this loader will be diabled. 29 | */ 30 | 31 | /*! 32 | @fn QSimpleSettingsLoader::reset 33 | 34 | @returns `true`, if resetting was successful, `false` if not 35 | 36 | If resetting was successful return `true`. If not return `false` and an error will be shown 37 | to the user and the entry that uses this loader will be diabled. 38 | */ 39 | 40 | /*! 41 | @class QAsyncSettingsLoader 42 | 43 | A QObject based loader, capable of loading data from different threads and data with long loading/saving times. Create async loaders 44 | on the thread that holds the data (or move them there). The engine will call the load/save/reset methods with a Qt::QueuedConnection 45 | and will use the same to react to the signals that indicate a completition of the corresponding task. 46 | 47 | For simple sources, that can load fast and on the main thread, please use QSimpleSettingsLoader. 48 | */ 49 | 50 | /*! 51 | @fn QAsyncSettingsLoader::loadData 52 | 53 | As soon as loading is finished, you have to emit the loadDone signal. This has to be emitted in **any case**!. You can use the signals 54 | parameters to tell the engine about the result of loading. 55 | */ 56 | 57 | /*! 58 | @fn QAsyncSettingsLoader::saveData 59 | 60 | @param data The data to be saved. 61 | 62 | As soon as saving is finished, you have to emit the saveDone signal. This has to be emitted in **any case**!. You can use the signals 63 | parameter to tell the engine about the result of saving. 64 | */ 65 | 66 | /*! 67 | @fn QAsyncSettingsLoader::resetData 68 | 69 | As soon as resetting is finished, you have to emit the resetDone signal. This has to be emitted in **any case**!. You can use the signals 70 | parameter to tell the engine about the result of resetting. 71 | */ 72 | 73 | /*! 74 | @fn QAsyncSettingsLoader::loadDone 75 | 76 | @param successful Should be `true`, if loading was successful, `false` if not 77 | @param data A `QVariant` object that contains the loaded data (Use QVariant::Invalid if loading failed) 78 | @param isUserEdited A `bool` to specify whether the value comes from the user or is the default. (Defaults to `false`) 79 | 80 | The loaded value should be in @a data. You can use the @a isUserEdited parameter to activate/deactivate the entry. If loading was successful, 81 | the parameter should be `true`. If not use `false` and an error will be shown to the user and the entry that uses this loader will be diabled. 82 | */ 83 | 84 | /*! 85 | @fn QAsyncSettingsLoader::saveDone 86 | 87 | @param successful Should be `true`, if saving was successful, `false` if not 88 | 89 | If saving was successful, the parameter should be `true`. If not use `false` and an error will be shown 90 | to the user and the entry that uses this loader will be diabled. 91 | */ 92 | 93 | /*! 94 | @fn QAsyncSettingsLoader::resetDone 95 | 96 | @param successful Should be `true`, if resetting was successful, `false` if not 97 | 98 | If resetting was successful, the parameter should be `true`. If not use `false` and an error will be shown 99 | to the user and the entry that uses this loader will be diabled. 100 | */ 101 | 102 | -------------------------------------------------------------------------------- /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/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/core/settingspathparser.cpp: -------------------------------------------------------------------------------- 1 | #include "settingspathparser.h" 2 | 3 | const QRegularExpression SettingsPathParser::realIdRegex(QStringLiteral(R"__(^([0-9a-z_\-]+)$)__"), 4 | QRegularExpression::CaseInsensitiveOption | 5 | QRegularExpression::OptimizeOnFirstUsageOption); 6 | const QRegularExpression SettingsPathParser::allIdRegex(QStringLiteral(R"__(^([0-9a-z_\-]*|\.)$)__"), 7 | QRegularExpression::CaseInsensitiveOption | 8 | QRegularExpression::OptimizeOnFirstUsageOption); 9 | const QRegularExpression SettingsPathParser::fullPathRegex(QStringLiteral(R"__(^(\.\.|([0-9a-z_\-]*|\.)\/([0-9a-z_\-]*|\.)(?:(\/)([0-9a-z_\-]*))?)?$)__"), 10 | QRegularExpression::CaseInsensitiveOption | 11 | QRegularExpression::OptimizeOnFirstUsageOption); 12 | const QRegularExpression SettingsPathParser::partialPathRegex(QStringLiteral(R"__(^(\.\.|([0-9a-z_\-]*|\.)(?:\/([0-9a-z_\-]*|\.)(?:\/([0-9a-z_\-]*|\.))?)?)?$)__"), 13 | QRegularExpression::CaseInsensitiveOption | 14 | QRegularExpression::OptimizeOnFirstUsageOption); 15 | 16 | void SettingsPathParser::validateId(const QString &id, bool realIdOnly) 17 | { 18 | if(realIdOnly) { 19 | if(!realIdRegex.match(id).hasMatch()) 20 | throw InvalidContainerPathException(); 21 | } else { 22 | if(!allIdRegex.match(id).hasMatch()) 23 | throw InvalidContainerPathException(); 24 | } 25 | } 26 | 27 | QVector SettingsPathParser::parseFullPath(const QString &path) 28 | { 29 | auto match = fullPathRegex.match(path); 30 | if(!match.hasMatch()) 31 | throw InvalidContainerPathException(); 32 | 33 | if(match.captured(1).isEmpty()) 34 | return QVector(3, QString()); 35 | else if(match.captured(1) == QStringLiteral("..")) 36 | return {QStringLiteral("."), QStringLiteral(".")}; 37 | else { 38 | if(match.captured(4).isEmpty()) { 39 | return { 40 | match.captured(2), 41 | match.captured(3) 42 | }; 43 | } else { 44 | return { 45 | match.captured(2), 46 | match.captured(3), 47 | match.captured(5) 48 | }; 49 | } 50 | } 51 | } 52 | 53 | #include 54 | QStringList SettingsPathParser::parsePartialPath(const QString &path) 55 | { 56 | auto match = partialPathRegex.match(path); 57 | if(!match.hasMatch()) 58 | throw InvalidContainerPathException(); 59 | 60 | if(match.captured(1).isEmpty()) 61 | return QVector(3, QString()).toList(); 62 | else if(match.captured(1) == QStringLiteral("..")) 63 | return {QStringLiteral("."), QStringLiteral(".")}; 64 | else { 65 | auto all = match.capturedTexts(); 66 | all.removeFirst(); 67 | qDebug() << all; 68 | return all; 69 | } 70 | } 71 | 72 | QString SettingsPathParser::createPath(const QString &categoryId, const QString §ionId, const QString &groupId) 73 | { 74 | validateId(categoryId, false); 75 | validateId(sectionId, false); 76 | if(groupId.isNull()) 77 | return QStringList({categoryId, sectionId}).join(QLatin1Char('/')); 78 | else { 79 | validateId(groupId, false); 80 | return QStringList({categoryId, sectionId, groupId}).join(QLatin1Char('/')); 81 | } 82 | } 83 | 84 | QString SettingsPathParser::joinPath(const QString §ionPath, const QString &groupId) 85 | { 86 | auto elements = parseFullPath(sectionPath); 87 | if(elements.size() != 2) 88 | throw InvalidContainerPathException(); 89 | 90 | validateId(groupId, false); 91 | elements.append(groupId); 92 | return elements.toList().join(QLatin1Char('/')); 93 | } 94 | -------------------------------------------------------------------------------- /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/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 &entry); 35 | QSharedPointer prepend(const QString &id, SettingsGroup *entry); 36 | void prepend(const QString &id, const QSharedPointer &entry); 37 | QSharedPointer insert(int index, const QString &id, SettingsGroup *entry); 38 | void insert(int index, const QString &id, const QSharedPointer &entry); 39 | 40 | int index(const QString &id) const; 41 | bool contains(const QString &id) const; 42 | 43 | QList groupKeys() const; 44 | QList> groupValues() const; 45 | SortedMap createGroupMap() const; 46 | 47 | QSharedPointer valueId(const QString &id) const; 48 | bool removeId(const QString &id); 49 | QSharedPointer takeId(const QString &id); 50 | 51 | //custom operations 52 | QSharedPointer append(const int &id, QSettingsEntry *entry); 53 | void append(const int &id, const QSharedPointer &entry); 54 | QSharedPointer prepend(const int &id, QSettingsEntry *entry); 55 | void prepend(const int &id, const QSharedPointer &entry); 56 | QSharedPointer insert(int index, const int &id, QSettingsEntry *entry); 57 | void insert(int index, const int &id, const QSharedPointer &entry); 58 | 59 | int index(const int &id) const; 60 | bool contains(const int &id) const; 61 | 62 | QList customKeys() const; 63 | QList> customValues() const; 64 | SortedMap createCustomMap() const; 65 | 66 | QSharedPointer valueId(const int &id) const; 67 | bool removeId(const int &id); 68 | QSharedPointer takeId(const int &id); 69 | 70 | class const_iterator 71 | { 72 | friend class SpecialGroupMap; 73 | public: 74 | typename SpecialGroupMap::Entry operator*(); 75 | bool operator!=(const const_iterator& other) const; 76 | const_iterator &operator++(); 77 | 78 | private: 79 | const_iterator(const SpecialGroupMap &map, int index); 80 | 81 | const SpecialGroupMap ↦ 82 | int index; 83 | }; 84 | 85 | const_iterator begin() const; 86 | const_iterator end() const; 87 | 88 | private: 89 | QHash> groups; 90 | QHash> customGroups; 91 | QVariantList totalOrder; 92 | 93 | void cleanTotal(const QVariant &value); 94 | }; 95 | 96 | #endif // SPECIALGROUPMAP_H 97 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/dialogui/qsettingsgroupwidget.dox: -------------------------------------------------------------------------------- 1 | /*! 2 | @class QSettingsGroupWidgetBase 3 | 4 | Implementations must inherit from `QWidget`! 5 | 6 | Custom groups can be used to provide a customized way to organize entries in a group. Because of the way the dialog is build up, 7 | the raw mechanics and organization within the dialog can get very complicated. To make it possible to create custom groups in a simple 8 | way, there are two approaches on creating a custom group 9 | 10 | ### Simple implementation 11 | All you have to do is to provide a widget that can somehow contain children. All you have to do is implement the QSettingsGroupWidgetBase::addWidgetWithLabel 12 | method. (And the other **pure** virtual functions). This way the group will handle all the complex stuff on it's own. However, this requires you to 13 | provide a group that can handle a label and a widget. For groups that are more complex, the second method must be used. 14 | 15 | ### Raw implementation 16 | Instead of using the simple implementation, override all the management functions: 17 | - QSettingsGroupWidgetBase::addWidgetRaw 18 | - QSettingsGroupWidgetBase::setEntryChecked 19 | - QSettingsGroupWidgetBase::setEntryLabelEnabled 20 | - QSettingsGroupWidgetBase::isEntryChecked 21 | - QSettingsGroupWidgetBase::searchExpression 22 | 23 | This requies you to do all the complex checking and searching logic on your own, but you can create fully customized groups. 24 | 25 | @note You should not use this class directly. It simply serves as base for the generic interface. You should 26 | only implement the QSettingsGroupWidget interface! 27 | */ 28 | 29 | /*! 30 | @fn QSettingsGroupWidgetBase::asWidget 31 | 32 | @returns `(QWidget*)this;` 33 | 34 | @warning This function **MUST** return itself. It's basically a shortcut for `(QWidget*)element`, and is there 35 | to ensure all widgets that implement this interface do inherit `QWidget`. 36 | */ 37 | 38 | /*! 39 | @fn QSettingsGroupWidgetBase::setOptional 40 | 41 | @param optional If `true`, the group should be optional, if `false` required. 42 | 43 | Optional groups are a way to make it possible for the user to batch-enable settings. If a group is optional and checked, or required, it should let 44 | the user use the contents normally. If it optional and unchecked, the contents should be disabled, preventing the user from accessing them. 45 | If the settings get saved, all children within an unchecked group will be resetted. Otherwise the normal operation for them will be used. 46 | */ 47 | 48 | /*! 49 | @fn QSettingsGroupWidgetBase::addWidgetWithLabel 50 | 51 | @param label The widget that operates as a label. Will be a QLabel or a QCheckBox 52 | @param content The edit widget, a QSettingsWidgetBase implementation (here simply as QWidget) 53 | 54 | This function should simply add the two given widget into the groups display layout. All the logic connecting 55 | them and other managemant stuff is done by the group itself. In most cases the implementations of this 56 | function will simply add those two widget into a QLayout. 57 | */ 58 | 59 | /*! 60 | @class QSettingsGroupWidget 61 | 62 | @tparam TWidget A class that is or inherits QWidget. It will be the primary base class of this widget 63 | 64 | Use this generic interface to create your own group widget implementations: 65 | 66 | @code{.cpp} 67 | class MyGroupWidget : QSettingsGroupWidget 68 | { 69 | public: 70 | //... 71 | } 72 | @endcode 73 | 74 | The class can then be registered to the dialog using QSettingsWidgetDialogEngine::addGroupWidgetType. 75 | 76 | @attention Please check the base class documentation if you want to create a custom group! 77 | */ 78 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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/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/dialogui/qsettingswidgetdialogengine.h: -------------------------------------------------------------------------------- 1 | #ifndef QSETTINGSWIDGETDIALOGENGINE_H 2 | #define QSETTINGSWIDGETDIALOGENGINE_H 3 | 4 | #include "qsettingsdialog_global.h" 5 | #include "qsettingsdisplayengine.h" 6 | #include "qsettingswidgetfactoryregistry.h" 7 | #include "qsettingsgroupwidgetfactory.h" 8 | #include "qsettingsentry.h" 9 | #include 10 | 11 | class QSettingsWidgetDialogEnginePrivate; 12 | //! The default engine implementation for the settings dialog @ingroup grp_dialogui 13 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsWidgetDialogEngine : public QSettingsDisplayEngine 14 | { 15 | public: 16 | //! Creates a new dialog engine 17 | QSettingsWidgetDialogEngine(); 18 | //! Destructor 19 | ~QSettingsWidgetDialogEngine(); 20 | 21 | QSettingsDisplayInstance *createInstance() override; 22 | 23 | //! @intuse Returns the stylesheet to be applied to labels that are a search match 24 | QString searchStyleSheet() const; 25 | 26 | //! Adds a new settings widget factory with the given id to the default registry @own factory 27 | void addFactory(int displayId, QSettingsWidgetFactory *factory); 28 | //! Adds a new settings widget factory with the given id to the default registry 29 | template 30 | void addWidgetType(int displayId); 31 | 32 | //! Adds a new group widget factory with the given id @own factory 33 | void addGroupFactory(int displayId, QSettingsGroupWidgetFactory *factory, const UiPropertyMap &properties = UiPropertyMap()); 34 | //! Adds a new group widget factory with the given id 35 | template 36 | void addGroupWidgetType(int displayId, const UiPropertyMap &properties = UiPropertyMap()); 37 | //! Creates a clone of a group with a new id and different properties 38 | void cloneGroupFactoryWithProperties(int originalId, int cloneId, const UiPropertyMap &properties); 39 | 40 | //! @intuse Tries to create a new settings widget for the given id 41 | QSettingsWidgetBase *createWidget(int displayId, 42 | const UiPropertyMap &properties, 43 | QWidget *parent) const; 44 | //! @intuse Tries to create a new group widget for the given id 45 | QSettingsGroupWidgetBase *createGroupWidget(int displayId, 46 | QWidget *parent) const; 47 | 48 | //! Adds a new settings widget factory with the given id to the global default registry @own factory 49 | static void registerGlobalFactory(int displayId, QSettingsWidgetFactory *factory); 50 | //! Adds a new settings widget factory with the given id to the global default registry 51 | template 52 | static void registerGlobalWidgetType(int displayId); 53 | 54 | //! Adds a new settings group factory with the given id to the global groups @own factory 55 | static void registerGlobalGroupFactory(int displayId, QSettingsGroupWidgetFactory *factory); 56 | //! Adds a new settings group factory with the given id to the global groups 57 | template 58 | static void registerGlobalGroupWidgetType(int displayId); 59 | //! Creates a clone of a global group with a new id and different properties 60 | static void cloneGlobalGroupFactoryWithProperties(int originalId, int cloneId, const UiPropertyMap &properties); 61 | 62 | //! Adds a new factory registry to this dialog @own registry 63 | void addRegistry(QSettingsWidgetFactoryRegistry *registry); 64 | //! Adds a new factory registry to the global registries @own registry 65 | static void registerGlobalRegistry(QSettingsWidgetFactoryRegistry *registry); 66 | 67 | private: 68 | QScopedPointer d_ptr; 69 | }; 70 | 71 | template 72 | void QSettingsWidgetDialogEngine::addWidgetType(int displayId) { 73 | this->addFactory(displayId, new GenericSettingsWidgetFactory()); 74 | } 75 | 76 | template 77 | void QSettingsWidgetDialogEngine::addGroupWidgetType(int displayId, const UiPropertyMap &properties) { 78 | this->addGroupFactory(displayId, new GenericSettingsGroupWidgetFactory(), properties); 79 | } 80 | 81 | template 82 | void QSettingsWidgetDialogEngine::registerGlobalWidgetType(int displayId) { 83 | registerGlobalFactory(displayId, new GenericSettingsWidgetFactory()); 84 | } 85 | 86 | template 87 | void QSettingsWidgetDialogEngine::registerGlobalGroupWidgetType(int displayId) { 88 | registerGlobalGroupFactory(displayId, new GenericSettingsGroupWidgetFactory()); 89 | } 90 | 91 | #endif // QSETTINGSWIDGETDIALOGENGINE_H 92 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /QSettingsDialog/dialogui/settingsdisplaydialog.h: -------------------------------------------------------------------------------- 1 | #ifndef SETTINGSDISPLAYDIALOG_H 2 | #define SETTINGSDISPLAYDIALOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "qsettingswidgetdialogengine.h" 11 | #include "containerelements.h" 12 | #include "qsettingsgroupwidget.h" 13 | class SettingsEngine; 14 | 15 | namespace Ui { 16 | class SettingsDisplayDialog; 17 | } 18 | 19 | class CategoryItemDelegate : public QStyledItemDelegate 20 | { 21 | public: 22 | CategoryItemDelegate(std::function updateFunc, 23 | const QSize &iconSize, 24 | int layoutSpacing, 25 | QObject *parent = Q_NULLPTR); 26 | 27 | QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE; 28 | private: 29 | QSize iconSize; 30 | std::function updateFunc; 31 | }; 32 | 33 | class SettingsDisplayDialog : public QDialog, public QSettingsDisplayInstance 34 | { 35 | Q_OBJECT 36 | 37 | public: 38 | explicit SettingsDisplayDialog(QSettingsWidgetDialogEngine *engine); 39 | ~SettingsDisplayDialog(); 40 | 41 | void setParentWindow(QWidget *parent) override; 42 | void setParentWindow(QWindow *parent) override; 43 | void createUi(const QSharedPointer &elementRoot) override; 44 | 45 | public slots: 46 | void open() override; 47 | int exec() override; 48 | 49 | signals: 50 | void saved(bool closed) final; 51 | void resetted() final; 52 | void canceled() final; 53 | 54 | protected: 55 | void showEvent(QShowEvent *ev) override; 56 | 57 | private slots: 58 | void startSaving(bool isApply); 59 | void startResetting(); 60 | 61 | void engineFinished(int errorCount); 62 | void completeAbort(); 63 | 64 | void resetListSize(); 65 | void updateWidth(int width); 66 | 67 | void buttonBoxClicked(QAbstractButton *button); 68 | void on_filterLineEdit_textChanged(const QString &searchText); 69 | 70 | private: 71 | enum OperationMode { 72 | Idle, 73 | Load, 74 | Save, 75 | Apply, 76 | Reset 77 | }; 78 | 79 | QSettingsWidgetDialogEngine *dialogEngine; 80 | SettingsEngine *engine; 81 | 82 | Ui::SettingsDisplayDialog *ui; 83 | CategoryItemDelegate *delegate; 84 | int maxWidthBase; 85 | 86 | OperationMode currentMode; 87 | QProgressDialog *workingDialog; 88 | 89 | int calcSpacing(Qt::Orientation orientation); 90 | 91 | void createCategory(const QSharedPointer &category); 92 | void createSection(const QSharedPointer §ion, QTabWidget *tabWidget); 93 | void createGroup(const QSharedPointer &group, QWidget *contentWidget, QFormLayout *layout); 94 | void createEntry(const QSharedPointer &entry, QWidget *sectionWidget, QFormLayout *layout); 95 | void createEntry(const QSharedPointer &entry, QSettingsGroupWidgetBase *group); 96 | 97 | QWidget *createErrorWidget(QWidget *parent); 98 | 99 | void searchInDialog(const QRegularExpression ®ex); 100 | bool searchInCategory(const QRegularExpression ®ex, QTabWidget *tab); 101 | bool searchInSection(const QRegularExpression ®ex, QWidget *contentWidget); 102 | bool searchInGroup(const QRegularExpression ®ex, QSettingsGroupWidgetBase *groupWidget); 103 | bool searchInEntry(const QRegularExpression ®ex, QWidget *label, QSettingsWidgetBase *content); 104 | }; 105 | 106 | #endif // SETTINGSDISPLAYDIALOG_H 107 | -------------------------------------------------------------------------------- /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/doc/images/dialogwidget_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/doc/images/dialogwidget_button.png -------------------------------------------------------------------------------- /QSettingsDialog/doc/images/mac_sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/doc/images/mac_sample.png -------------------------------------------------------------------------------- /QSettingsDialog/doc/images/win_sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/doc/images/win_sample.png -------------------------------------------------------------------------------- /QSettingsDialog/doc/images/x11_sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/doc/images/x11_sample.png -------------------------------------------------------------------------------- /QSettingsDialog/doc/modules_snippet.html: -------------------------------------------------------------------------------- 1 |

Modules Structure

2 |

The following diagramm describes how the modules are connected with each other:

3 |
4 | structure_core.svg 5 |
The Modules in a class diagram
6 |
-------------------------------------------------------------------------------- /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/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/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/loaders/private.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/qsettingspropertyloader.cpp \ 3 | $$PWD/qsettingspropertyentry.cpp \ 4 | $$PWD/qsettingssettingsloader.cpp 5 | -------------------------------------------------------------------------------- /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/loaders/qsettingspropertyentry.h: -------------------------------------------------------------------------------- 1 | #ifndef QSETTINGSPROPERTYENTRY_H 2 | #define QSETTINGSPROPERTYENTRY_H 3 | 4 | #include "qsettingsdialog_global.h" 5 | #include "qsettingsentry.h" 6 | class QSettingsPropertyLoader; 7 | 8 | //! A class that combines the QSettingsEntry and the QSettingsPropertyLoader @ingroup grp_loaders 9 | class QSETTINGSDIALOGSHARED_EXPORT QSettingsPropertyEntry : public QSettingsEntry 10 | { 11 | public: 12 | //! Creates a property entry for a property on an object 13 | explicit QSettingsPropertyEntry(const char *propertyName, QObject *object); 14 | //! Creates a property entry for a property on an object 15 | explicit QSettingsPropertyEntry(const QMetaProperty &metaProperty, QObject *object); 16 | //! Creates a property entry for a property on a gadget, with the gadgets static metaobject 17 | explicit QSettingsPropertyEntry(const char *propertyName, QMetaObject *metaObject, void *gadget); 18 | //! Creates a property entry for a property on a gadget 19 | explicit QSettingsPropertyEntry(const QMetaProperty &metaProperty, void *gadget); 20 | 21 | //! Creates a property entry for a property on an object, with entry properties 22 | explicit QSettingsPropertyEntry(const char *propertyName, 23 | QObject *object, 24 | const QString &name, 25 | bool optional = false, 26 | const QString &tooltip = QString(), 27 | const UiPropertyMap &properties = UiPropertyMap()); 28 | //! Creates a property entry for a property on an object, with entry properties 29 | explicit QSettingsPropertyEntry(const QMetaProperty &metaProperty, 30 | QObject *object, 31 | const QString &name, 32 | bool optional = false, 33 | const QString &tooltip = QString(), 34 | const UiPropertyMap &properties = UiPropertyMap()); 35 | //! Creates a property entry for a property on a gadget, with the gadgets static metaobject, with entry properties 36 | explicit QSettingsPropertyEntry(const char *propertyName, 37 | QMetaObject *metaObject, 38 | void *gadget, 39 | const QString &name, 40 | bool optional = false, 41 | const QString &tooltip = QString(), 42 | const UiPropertyMap &properties = UiPropertyMap()); 43 | //! Creates a property entry for a property on a gadget, with entry properties 44 | explicit QSettingsPropertyEntry(const QMetaProperty &metaProperty, 45 | void *gadget, 46 | const QString &name, 47 | bool optional = false, 48 | const QString &tooltip = QString(), 49 | const UiPropertyMap &properties = UiPropertyMap()); 50 | 51 | //! Creates a property entry for a property on an object, with entry properties 52 | template 53 | explicit QSettingsPropertyEntry(const char *propertyName, 54 | QObject *object, 55 | const QString &name, 56 | bool optional, 57 | const QString &tooltip, 58 | Args... properties); 59 | //! Creates a property entry for a property on an object, with entry properties 60 | template 61 | explicit QSettingsPropertyEntry(const QMetaProperty &metaProperty, 62 | QObject *object, 63 | const QString &name, 64 | bool optional, 65 | const QString &tooltip, 66 | Args... properties); 67 | //! Creates a property entry for a property on a gadget, with the gadgets static metaobject, with entry properties 68 | template 69 | explicit QSettingsPropertyEntry(const char *propertyName, 70 | QMetaObject *metaObject, 71 | void *gadget, 72 | const QString &name, 73 | bool optional, 74 | const QString &tooltip, 75 | Args... properties); 76 | //! Creates a property entry for a property on a gadget, with entry properties 77 | template 78 | explicit QSettingsPropertyEntry(const QMetaProperty &metaProperty, 79 | void *gadget, 80 | const QString &name, 81 | bool optional, 82 | const QString &tooltip, 83 | Args... properties); 84 | 85 | int displaytype() override; 86 | }; 87 | 88 | 89 | template 90 | QSettingsPropertyEntry::QSettingsPropertyEntry(const char *propertyName, QObject *object, const QString &name, bool optional, const QString &tooltip, Args... properties) : 91 | QSettingsPropertyEntry(propertyName, object, name, optional, tooltip, mapWrapper(properties...)) 92 | {} 93 | 94 | template 95 | QSettingsPropertyEntry::QSettingsPropertyEntry(const QMetaProperty &metaProperty, QObject *object, const QString &name, bool optional, const QString &tooltip, Args... properties) : 96 | QSettingsPropertyEntry(metaProperty, object, name, optional, tooltip, mapWrapper(properties...)) 97 | {} 98 | 99 | template 100 | QSettingsPropertyEntry::QSettingsPropertyEntry(const char *propertyName, QMetaObject *metaObject, void *gadget, const QString &name, bool optional, const QString &tooltip, Args... properties) : 101 | QSettingsPropertyEntry(propertyName, metaObject, gadget, name, optional, tooltip, mapWrapper(properties...)) 102 | {} 103 | 104 | template 105 | QSettingsPropertyEntry::QSettingsPropertyEntry(const QMetaProperty &metaProperty, void *gadget, const QString &name, bool optional, const QString &tooltip, Args... properties) : 106 | QSettingsPropertyEntry(metaProperty, gadget, name, optional, tooltip, mapWrapper(properties...)) 107 | {} 108 | 109 | #endif // QSETTINGSPROPERTYENTRY_H 110 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/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/qsettingsdialog_res.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | resources/setting_tools.ico 4 | resources/gear_in.ico 5 | 6 | 7 | -------------------------------------------------------------------------------- /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/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/resources/gear_in.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/resources/gear_in.ico -------------------------------------------------------------------------------- /QSettingsDialog/resources/setting_tools.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/resources/setting_tools.ico -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/resources/add.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/variantwidgets/resources/add.ico -------------------------------------------------------------------------------- /QSettingsDialog/variantwidgets/resources/arrow_down.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/variantwidgets/resources/arrow_down.ico -------------------------------------------------------------------------------- /QSettingsDialog/variantwidgets/resources/arrow_up.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/variantwidgets/resources/arrow_up.ico -------------------------------------------------------------------------------- /QSettingsDialog/variantwidgets/resources/calculator.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/variantwidgets/resources/calculator.ico -------------------------------------------------------------------------------- /QSettingsDialog/variantwidgets/resources/delete.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/variantwidgets/resources/delete.ico -------------------------------------------------------------------------------- /QSettingsDialog/variantwidgets/resources/outlook_calendar_day.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Skycoder42/QSettingsDialog/5fd3d3442c21411d7e2cec90d4b0869a930e88d4/QSettingsDialog/variantwidgets/resources/outlook_calendar_day.ico -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /QSettingsDialog/variantwidgets/settingsenumcombobox.cpp: -------------------------------------------------------------------------------- 1 | #include "settingsenumcombobox.h" 2 | #include 3 | #include 4 | #include 5 | 6 | SettingsEnumComboBox::SettingsEnumComboBox(const QMetaEnum &metaEnum, QWidget *parent) : 7 | QSettingsWidget(parent), 8 | metaEnum(metaEnum), 9 | m_translated(false) 10 | { 11 | this->setTranslated(true); 12 | } 13 | 14 | void SettingsEnumComboBox::setValue(const QVariant &value) 15 | { 16 | auto intVal = value.toInt(); 17 | for(int i = 0; i < this->metaEnum.keyCount(); i++) { 18 | if(this->metaEnum.value(i) == intVal) { 19 | this->setCurrentIndex(i); 20 | break; 21 | } 22 | } 23 | } 24 | 25 | QVariant SettingsEnumComboBox::getValue() const 26 | { 27 | return this->metaEnum.value(this->currentIndex()); 28 | } 29 | 30 | void SettingsEnumComboBox::resetValue() 31 | { 32 | this->setCurrentIndex(-1); 33 | } 34 | 35 | bool SettingsEnumComboBox::translated() const 36 | { 37 | return m_translated; 38 | } 39 | 40 | void SettingsEnumComboBox::setTranslated(bool translated) 41 | { 42 | if (m_translated == translated) 43 | return; 44 | m_translated = translated; 45 | 46 | auto cIndex = this->currentIndex(); 47 | QStringList enumValues; 48 | for(int i = 0; i < this->metaEnum.keyCount(); i++) { 49 | QString text; 50 | if(translated) 51 | text = QCoreApplication::translate(this->metaEnum.name(), this->metaEnum.key(i)); 52 | else 53 | text = QString::fromLocal8Bit(this->metaEnum.key(i)); 54 | enumValues.append(text); 55 | } 56 | this->clear(); 57 | this->addItems(enumValues); 58 | this->setCurrentIndex(cIndex); 59 | 60 | emit translatedChanged(translated); 61 | } 62 | 63 | 64 | 65 | SettingsEnumRadioList::SettingsEnumRadioList(const QMetaEnum &metaEnum, QWidget *parent) : 66 | QSettingsWidget(parent), 67 | metaEnum(metaEnum), 68 | checkGroup(new QButtonGroup(this)), 69 | m_translated(false) 70 | { 71 | this->checkGroup->setExclusive(true); 72 | 73 | auto layout = new QVBoxLayout(this); 74 | layout->setContentsMargins(QMargins()); 75 | this->setLayout(layout); 76 | 77 | for(int i = 0; i < this->metaEnum.keyCount(); i++) { 78 | auto box = new QRadioButton(QString::fromLocal8Bit(this->metaEnum.key(i)), this); 79 | layout->addWidget(box); 80 | this->checkGroup->addButton(box, this->metaEnum.value(i)); 81 | } 82 | 83 | this->setTranslated(true); 84 | } 85 | 86 | void SettingsEnumRadioList::setValue(const QVariant &value) 87 | { 88 | auto id = value.toInt(); 89 | this->checkGroup->button(id)->setChecked(true); 90 | } 91 | 92 | QVariant SettingsEnumRadioList::getValue() const 93 | { 94 | return this->checkGroup->checkedId(); 95 | } 96 | 97 | void SettingsEnumRadioList::resetValue() 98 | { 99 | this->checkGroup->checkedButton()->setChecked(false); 100 | } 101 | 102 | bool SettingsEnumRadioList::translated() const 103 | { 104 | return m_translated; 105 | } 106 | 107 | void SettingsEnumRadioList::setTranslated(bool translated) 108 | { 109 | if (m_translated == translated) 110 | return; 111 | m_translated = translated; 112 | 113 | for(int i = 0; i < this->metaEnum.keyCount(); i++) { 114 | QString text; 115 | if(translated) 116 | text = QCoreApplication::translate(this->metaEnum.name(), this->metaEnum.key(i)); 117 | else 118 | text = QString::fromLocal8Bit(this->metaEnum.key(i)); 119 | 120 | auto box = this->checkGroup->button(this->metaEnum.value(i)); 121 | box->setText(text); 122 | } 123 | 124 | emit translatedChanged(translated); 125 | } 126 | 127 | 128 | 129 | SettingsEnumEditWrapper::SettingsEnumEditWrapper(const QMetaEnum &metaEnum, QWidget *parent) : 130 | QSettingsWidget(parent), 131 | metaEnum(metaEnum), 132 | current(new SettingsEnumComboBox(metaEnum, this)) 133 | { 134 | auto layout = new QVBoxLayout(this); 135 | layout->setContentsMargins(QMargins()); 136 | this->setLayout(layout); 137 | layout->addWidget(this->current->asWidget()); 138 | } 139 | 140 | void SettingsEnumEditWrapper::initialize(const UiPropertyMap &uiPropertyMap) 141 | { 142 | if(uiPropertyMap.contains(QStringLiteral("showAsRadio"))) { 143 | auto asRadio = uiPropertyMap.value(QStringLiteral("showAsRadio")).toBool(); 144 | this->current->asWidget()->deleteLater(); 145 | if(asRadio) 146 | this->current = new SettingsEnumRadioList(this->metaEnum, this); 147 | else 148 | this->current = new SettingsEnumComboBox(this->metaEnum, this); 149 | this->layout()->addWidget(this->current->asWidget()); 150 | } 151 | 152 | this->current->initialize(uiPropertyMap); 153 | } 154 | 155 | bool SettingsEnumEditWrapper::hasValueChanged() const 156 | { 157 | return this->current->hasValueChanged(); 158 | } 159 | 160 | void SettingsEnumEditWrapper::resetValueChanged() 161 | { 162 | this->current->resetValueChanged(); 163 | } 164 | 165 | void SettingsEnumEditWrapper::setValue(const QVariant &value) 166 | { 167 | this->current->setValue(value); 168 | } 169 | 170 | QVariant SettingsEnumEditWrapper::getValue() const 171 | { 172 | return this->current->getValue(); 173 | } 174 | 175 | void SettingsEnumEditWrapper::resetValue() 176 | { 177 | this->current->resetValue(); 178 | } 179 | 180 | bool SettingsEnumEditWrapper::searchExpression(const QRegularExpression ®ex) 181 | { 182 | return this->current->searchExpression(regex); 183 | } 184 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/variantwidgets/settingslineedit.cpp: -------------------------------------------------------------------------------- 1 | #include "settingslineedit.h" 2 | #include 3 | #include 4 | #include 5 | 6 | SettingsLineEdit::SettingsLineEdit(QWidget *parent) : 7 | QSettingsWidget(parent) 8 | {} 9 | 10 | bool SettingsLineEdit::hasValueChanged() const 11 | { 12 | return this->isModified(); 13 | } 14 | 15 | void SettingsLineEdit::resetValueChanged() 16 | { 17 | this->setModified(false); 18 | } 19 | 20 | void SettingsLineEdit::setValue(const QVariant &value) 21 | { 22 | this->setText(value.toString()); 23 | } 24 | 25 | QVariant SettingsLineEdit::getValue() const 26 | { 27 | return this->text(); 28 | } 29 | 30 | void SettingsLineEdit::resetValue() 31 | { 32 | this->clear(); 33 | } 34 | 35 | 36 | 37 | SettingsByteLineEdit::SettingsByteLineEdit(QWidget *parent) : 38 | SettingsLineEdit(parent) 39 | {} 40 | 41 | void SettingsByteLineEdit::setValue(const QVariant &value) 42 | { 43 | this->setText(QString::fromUtf8(value.toByteArray())); 44 | } 45 | 46 | QVariant SettingsByteLineEdit::getValue() const 47 | { 48 | return this->text().toUtf8(); 49 | } 50 | 51 | 52 | 53 | SettingsUrlLineEdit::SettingsUrlLineEdit(QWidget *parent) : 54 | QSettingsWidget(parent) 55 | { 56 | this->setValidator(new QUrlValidator(this)); 57 | connect(this, &SettingsUrlLineEdit::editingFinished, this, [this](){ 58 | QString text = this->text(); 59 | this->validator()->fixup(text); 60 | this->setText(text); 61 | }); 62 | } 63 | 64 | void SettingsUrlLineEdit::setValue(const QVariant &value) 65 | { 66 | this->setText(value.toUrl().toString()); 67 | } 68 | 69 | QVariant SettingsUrlLineEdit::getValue() const 70 | { 71 | return QUrl(this->text()); 72 | } 73 | 74 | void SettingsUrlLineEdit::resetValue() 75 | { 76 | this->clear(); 77 | } 78 | 79 | 80 | 81 | QUrlValidator::QUrlValidator(QObject *parent) : 82 | QValidator(parent) 83 | {} 84 | 85 | QValidator::State QUrlValidator::validate(QString &text, int &) const 86 | { 87 | return QUrl::fromUserInput(text).isValid() ? Acceptable : Intermediate; 88 | } 89 | 90 | void QUrlValidator::fixup(QString &text) const 91 | { 92 | text = QUrl::fromUserInput(text).toString(); 93 | } 94 | 95 | SettingsUuidEdit::SettingsUuidEdit(QWidget *parent) : 96 | QSettingsWidget(parent) 97 | { 98 | static const QRegularExpression regex(QStringLiteral(R"__(^\{?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}?$)__"), 99 | QRegularExpression::CaseInsensitiveOption | QRegularExpression::OptimizeOnFirstUsageOption); 100 | this->setValidator(new QRegularExpressionValidator(regex, this)); 101 | connect(this, &SettingsUrlLineEdit::editingFinished, this, [this](){ 102 | QString text = this->text(); 103 | this->setText(toUuid(text).toString().toUpper()); 104 | }); 105 | 106 | auto action = this->addAction(QIcon(QStringLiteral(":/QSettingsDialog/icons/calc.ico")), QLineEdit::TrailingPosition); 107 | connect(action, &QAction::triggered, 108 | this, &SettingsUuidEdit::generateId); 109 | } 110 | 111 | void SettingsUuidEdit::setValue(const QVariant &value) 112 | { 113 | this->setText(value.toUuid().toString().toUpper()); 114 | } 115 | 116 | QVariant SettingsUuidEdit::getValue() const 117 | { 118 | return toUuid(this->text()); 119 | } 120 | 121 | void SettingsUuidEdit::resetValue() 122 | { 123 | this->setText(QUuid().toString().toUpper()); 124 | } 125 | 126 | void SettingsUuidEdit::generateId() 127 | { 128 | this->setText(QUuid::createUuid().toString().toUpper()); 129 | } 130 | 131 | QUuid SettingsUuidEdit::toUuid(QString text) 132 | { 133 | if(!text.startsWith(QLatin1Char('{'))) 134 | text.prepend(QLatin1Char('{')); 135 | if(!text.endsWith(QLatin1Char('}'))) 136 | text.append(QLatin1Char('}')); 137 | return QUuid(text); 138 | } 139 | -------------------------------------------------------------------------------- /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/variantwidgets/settingslistedit.cpp: -------------------------------------------------------------------------------- 1 | #include "settingslistedit.h" 2 | #include "ui_settingslistedit.h" 3 | 4 | ListEditWidget::ListEditWidget(const QStringList &stringList, QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SettingsListEdit), 7 | model(new QStringListModel(stringList, this)) 8 | { 9 | this->ui->setupUi(this); 10 | this->ui->listView->setModel(this->model); 11 | 12 | this->ui->actionRemove->setShortcut(QKeySequence::Delete); 13 | QAction *seperator = new QAction(this); 14 | seperator->setSeparator(true); 15 | this->ui->listView->addActions({ 16 | this->ui->actionAdd, 17 | this->ui->actionRemove, 18 | seperator, 19 | this->ui->actionMove_Up, 20 | this->ui->actionMove_Down 21 | }); 22 | this->ui->addButton->setDefaultAction(this->ui->actionAdd); 23 | this->ui->removeButton->setDefaultAction(this->ui->actionRemove); 24 | this->ui->moveUpButton->setDefaultAction(this->ui->actionMove_Up); 25 | this->ui->moveDownButton->setDefaultAction(this->ui->actionMove_Down); 26 | 27 | connect(this->model, &QStringListModel::dataChanged, 28 | this, &ListEditWidget::modelChanged); 29 | connect(this->model, &QStringListModel::rowsInserted, 30 | this, &ListEditWidget::modelChanged); 31 | connect(this->model, &QStringListModel::rowsRemoved, 32 | this, &ListEditWidget::modelChanged); 33 | } 34 | 35 | ListEditWidget::ListEditWidget(QWidget *parent) : 36 | ListEditWidget(QStringList(), parent) 37 | {} 38 | 39 | ListEditWidget::~ListEditWidget() 40 | { 41 | delete this->ui; 42 | } 43 | 44 | bool ListEditWidget::areButtonsVisible() const 45 | { 46 | return this->ui->buttonContainerWidget->isVisible(); 47 | } 48 | 49 | QStringList ListEditWidget::stringList() const 50 | { 51 | return this->model->stringList(); 52 | } 53 | 54 | void ListEditWidget::setButtonsVisible(bool buttonsVisible) 55 | { 56 | this->ui->buttonContainerWidget->setVisible(buttonsVisible); 57 | } 58 | 59 | void ListEditWidget::setStringList(QStringList stringList) 60 | { 61 | if (this->model->stringList() == stringList) 62 | return; 63 | 64 | this->model->setStringList(stringList); 65 | emit stringListChanged(stringList); 66 | } 67 | 68 | void ListEditWidget::clear() 69 | { 70 | this->model->setStringList(QStringList()); 71 | } 72 | 73 | void ListEditWidget::modelChanged() 74 | { 75 | emit stringListChanged(this->model->stringList()); 76 | } 77 | 78 | void ListEditWidget::on_actionAdd_triggered() 79 | { 80 | int row = this->ui->listView->currentIndex().row() + 1; 81 | this->model->insertRow(row); 82 | QModelIndex newIndex = this->model->index(row); 83 | this->ui->listView->setCurrentIndex(newIndex); 84 | this->ui->listView->edit(newIndex); 85 | } 86 | 87 | void ListEditWidget::on_actionRemove_triggered() 88 | { 89 | QModelIndex index = this->ui->listView->currentIndex(); 90 | if(index.isValid()) 91 | this->model->removeRow(index.row()); 92 | } 93 | 94 | void ListEditWidget::on_actionMove_Up_triggered() 95 | { 96 | int row = this->ui->listView->currentIndex().row(); 97 | if(row > 0) { 98 | QStringList list = this->model->stringList(); 99 | list.move(row, row - 1); 100 | this->model->setStringList(list); 101 | this->ui->listView->setCurrentIndex(this->model->index(row - 1)); 102 | emit stringListChanged(list); 103 | } 104 | } 105 | 106 | void ListEditWidget::on_actionMove_Down_triggered() 107 | { 108 | int row = this->ui->listView->currentIndex().row(); 109 | QStringList list = this->model->stringList(); 110 | if(row < list.size() - 1) { 111 | list.move(row, row + 1); 112 | this->model->setStringList(list); 113 | this->ui->listView->setCurrentIndex(this->model->index(row + 1)); 114 | emit stringListChanged(list); 115 | } 116 | } 117 | 118 | 119 | 120 | SettingsListEditWidget::SettingsListEditWidget(QWidget *parent) : 121 | QSettingsWidget(parent) 122 | {} 123 | 124 | void SettingsListEditWidget::setValue(const QVariant &value) 125 | { 126 | this->setStringList(value.toStringList()); 127 | } 128 | 129 | QVariant SettingsListEditWidget::getValue() const 130 | { 131 | return this->stringList(); 132 | } 133 | 134 | void SettingsListEditWidget::resetValue() 135 | { 136 | this->clear(); 137 | } 138 | -------------------------------------------------------------------------------- /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/variantwidgets/settingslistedit.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SettingsListEdit 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | 15 | 0 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 28 | 29 | Qt::ActionsContextMenu 30 | 31 | 32 | true 33 | 34 | 35 | true 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 0 44 | 45 | 46 | 0 47 | 48 | 49 | 0 50 | 51 | 52 | 0 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | Qt::Horizontal 64 | 65 | 66 | 67 | 281 68 | 20 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | :/QSettingsDialog/icons/add.ico:/QSettingsDialog/icons/add.ico 87 | 88 | 89 | Add 90 | 91 | 92 | Adds a new entry to the list 93 | 94 | 95 | Ctrl+Ins 96 | 97 | 98 | Qt::WidgetWithChildrenShortcut 99 | 100 | 101 | 102 | 103 | 104 | :/QSettingsDialog/icons/delete.ico:/QSettingsDialog/icons/delete.ico 105 | 106 | 107 | Remove 108 | 109 | 110 | Removes the selected entry from the list 111 | 112 | 113 | Qt::WidgetWithChildrenShortcut 114 | 115 | 116 | 117 | 118 | 119 | :/QSettingsDialog/icons/up.ico:/QSettingsDialog/icons/up.ico 120 | 121 | 122 | Move Up 123 | 124 | 125 | Moves the selected entry up in the list 126 | 127 | 128 | PgUp 129 | 130 | 131 | Qt::WidgetWithChildrenShortcut 132 | 133 | 134 | 135 | 136 | 137 | :/QSettingsDialog/icons/down.ico:/QSettingsDialog/icons/down.ico 138 | 139 | 140 | Move Down 141 | 142 | 143 | Moves the selected entry down in the list 144 | 145 | 146 | PgDown 147 | 148 | 149 | Qt::WidgetWithChildrenShortcut 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /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/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/settingsrichtextedit.cpp: -------------------------------------------------------------------------------- 1 | #include "settingsrichtextedit.h" 2 | #include 3 | #include 4 | #include 5 | 6 | SettingsRichTextEdit::SettingsRichTextEdit(QWidget *parent) : 7 | QSettingsWidget(parent), 8 | boldAction(new QAction(tr("Bold"), this)), 9 | italicAction(new QAction(tr("Italic"), this)), 10 | underlinedAction(new QAction(tr("Underlined"), this)) 11 | { 12 | connect(this, &SettingsRichTextEdit::cursorPositionChanged, 13 | this, &SettingsRichTextEdit::updateActionsStatus); 14 | 15 | this->boldAction->setShortcut(QKeySequence::Bold); 16 | this->boldAction->setCheckable(true); 17 | connect(this->boldAction, &QAction::triggered, 18 | this, [=](bool checked){ 19 | this->setFontWeight(checked ? QFont::Bold : QFont::Normal); 20 | }); 21 | this->addAction(this->boldAction); 22 | 23 | this->italicAction->setShortcut(QKeySequence::Italic); 24 | this->italicAction->setCheckable(true); 25 | connect(this->italicAction, &QAction::triggered, 26 | this, &SettingsRichTextEdit::setFontItalic); 27 | this->addAction(this->italicAction); 28 | 29 | this->underlinedAction->setShortcut(QKeySequence::Underline); 30 | this->underlinedAction->setCheckable(true); 31 | connect(this->underlinedAction, &QAction::triggered, 32 | this, &SettingsRichTextEdit::setFontUnderline); 33 | this->addAction(this->underlinedAction); 34 | 35 | auto seperator1 = new QAction(this); 36 | seperator1->setSeparator(true); 37 | this->addAction(seperator1); 38 | 39 | auto fontAction = new QAction(tr("Edit Font"), this); 40 | connect(fontAction, &QAction::triggered, 41 | this, &SettingsRichTextEdit::editFont); 42 | this->addAction(fontAction); 43 | 44 | auto colorAction = new QAction(tr("Edit Color"), this); 45 | connect(colorAction, &QAction::triggered, 46 | this, &SettingsRichTextEdit::editColor); 47 | this->addAction(colorAction); 48 | 49 | auto seperator2 = new QAction(this); 50 | seperator2->setSeparator(true); 51 | this->addAction(seperator2); 52 | } 53 | 54 | void SettingsRichTextEdit::setValue(const QVariant &value) 55 | { 56 | this->setHtml(value.toString()); 57 | } 58 | 59 | QVariant SettingsRichTextEdit::getValue() const 60 | { 61 | return this->toHtml(); 62 | } 63 | 64 | void SettingsRichTextEdit::resetValue() 65 | { 66 | this->clear(); 67 | } 68 | 69 | void SettingsRichTextEdit::contextMenuEvent(QContextMenuEvent *e) 70 | { 71 | auto menu = this->createStandardContextMenu(e->pos()); 72 | menu->insertActions(menu->actions().first(), this->actions()); 73 | menu->exec(this->mapToGlobal(e->pos())); 74 | menu->deleteLater(); 75 | } 76 | 77 | void SettingsRichTextEdit::updateActionsStatus() 78 | { 79 | this->boldAction->setChecked(this->fontWeight() != QFont::Normal); 80 | this->italicAction->setChecked(this->fontItalic()); 81 | this->underlinedAction->setChecked(this->fontUnderline()); 82 | } 83 | 84 | void SettingsRichTextEdit::editFont() 85 | { 86 | auto ok = false; 87 | auto resFont = DialogMaster::getFont(&ok, 88 | this->currentFont(), 89 | this, 90 | tr("Edit Font")); 91 | if(ok) 92 | this->setCurrentFont(resFont); 93 | } 94 | 95 | void SettingsRichTextEdit::editColor() 96 | { 97 | auto resColor = DialogMaster::getColor(this->textColor(), 98 | this, 99 | tr("Edit Color")); 100 | if(resColor.isValid()) 101 | this->setTextColor(resColor); 102 | } 103 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/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/variantwidgets/variantwidgetsregistrator.cpp: -------------------------------------------------------------------------------- 1 | #include "variantwidgetsregistrator.h" 2 | #include "qsettingsextendedtypes.h" 3 | #include "qsettingswidgetdialogengine.h" 4 | #include "settingsenumwidgetfactory.h" 5 | #include 6 | 7 | #include "settingscheckbox.h" 8 | #include "settingsspinbox.h" 9 | #include "settingslineedit.h" 10 | #include "settingsdatetimeedit.h" 11 | #include "settingscoloredit.h" 12 | #include "settingslistedit.h" 13 | #include "settingsfontcombobox.h" 14 | #include "settingskeyedit.h" 15 | 16 | #include "settingspathedit.h" 17 | #include "settingsslider.h" 18 | #include "settingsrichtextedit.h" 19 | 20 | #include "settingsgroupbox.h" 21 | 22 | void VariantWidgetsRegistrator::registerGroupWidgets() 23 | { 24 | QSettingsWidgetDialogEngine::registerGlobalGroupWidgetType(0); 25 | } 26 | 27 | void VariantWidgetsRegistrator::registerVariantWidgets() 28 | { 29 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::Bool); 30 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::Int, 31 | new SpinBoxFactory(std::numeric_limits::max(), 32 | std::numeric_limits::min())); 33 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::UInt, 34 | new SpinBoxFactory(std::numeric_limits::max(), 0)); 35 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::Double, 36 | new DoubleSpinBoxFactory(std::numeric_limits::max(), 37 | std::numeric_limits::min())); 38 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QString); 39 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QByteArray); 40 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::Long, 41 | new SpinBoxFactory(std::numeric_limits::max(), 42 | std::numeric_limits::min())); 43 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::LongLong, 44 | new SpinBoxFactory(std::numeric_limits::max(), 45 | std::numeric_limits::min())); 46 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::Short, 47 | new SpinBoxFactory(std::numeric_limits::max(), 48 | std::numeric_limits::min())); 49 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::Char, 50 | new SpinBoxFactory(std::numeric_limits::max(), 51 | std::numeric_limits::min())); 52 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::ULong, new SpinBoxFactory(std::numeric_limits::max(), 0)); 53 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::ULongLong, new SpinBoxFactory(std::numeric_limits::max(), 0)); 54 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::UShort, new SpinBoxFactory(std::numeric_limits::max(), 0)); 55 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::SChar, 56 | new SpinBoxFactory(std::numeric_limits::max(), 57 | std::numeric_limits::min())); 58 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::UChar, new SpinBoxFactory(std::numeric_limits::max(), 0)); 59 | QSettingsWidgetDialogEngine::registerGlobalFactory(QMetaType::Float, 60 | new DoubleSpinBoxFactory(std::numeric_limits::max(), 61 | std::numeric_limits::min())); 62 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QDate); 63 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QTime); 64 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QColor); 65 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QStringList); 66 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QUrl); 67 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QDateTime); 68 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QFont); 69 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QKeySequence); 70 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QUuid); 71 | } 72 | 73 | void VariantWidgetsRegistrator::registerEnumFactories() 74 | { 75 | QSettingsWidgetDialogEngine::registerGlobalRegistry(new SettingsEnumWidgetRegistry()); 76 | } 77 | 78 | void VariantWidgetsRegistrator::registerExtendedVariantWidgets() 79 | { 80 | auto pathId = qRegisterMetaType(); 81 | auto rangeId = qRegisterMetaType(); 82 | auto htmlId = qRegisterMetaType(); 83 | 84 | REGISTER_TYPE_CONVERTERS(FilePath, QString); 85 | REGISTER_TYPE_CONVERTERS(IntRange, int); 86 | REGISTER_TYPE_CONVERTERS(HtmlText, QString); 87 | 88 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(pathId); 89 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(rangeId); 90 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(htmlId); 91 | 92 | QSettingsWidgetDialogEngine::registerGlobalWidgetType(QMetaType::QIcon); 93 | } 94 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QSettingsDialog 2 | Has been replaced by https://github.com/Skycoder42/QtMvvm 3 | --------------------------------------------------------------------------------