QSettingsDialog  1.0.0
A Qt library to easily create a settings dialog for user configurable settings
qsettingswidget.h
1 #ifndef QSETTINGSWIDGET_H
2 #define QSETTINGSWIDGET_H
3 
4 #include "qsettingsdialog_global.h"
5 #include <QWidget>
6 #include <QVariant>
7 #include <QRegularExpression>
8 #include "qsettingsentry.h"
9 
11 class QSETTINGSDIALOGSHARED_EXPORT QSettingsWidgetBase
12 {
13 public:
17  virtual ~QSettingsWidgetBase();
18 
20  virtual QWidget *asWidget() = 0;
22  virtual void initialize(const UiPropertyMap &uiPropertyMap) = 0;
23 
25  virtual bool hasValueChanged() const;
27  virtual void resetValueChanged();
28 
30  virtual void setValue(const QVariant &value) = 0;
32  virtual QVariant getValue() const = 0;
34  virtual void resetValue() = 0;
35 
37  virtual inline bool searchExpression(const QRegularExpression &regex) {
38  return regex.pattern().isEmpty();
39  }
40 
41 private:
42  QVariant changedCache;
43 };
44 
46 template <class TWidget>
48 {
49 public:
51  inline QSettingsWidget(QWidget *parent = nullptr) :
52  TWidget(parent),
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
QString pattern() const
void initialize(const UiPropertyMap &uiPropertyMap) override
Will be called to initialize the widgets properties with the given ones.
Definition: qsettingswidget.h:59
QWidget * asWidget() final
Must return this as QWidget (a cast)
Definition: qsettingswidget.h:56
virtual bool searchExpression(const QRegularExpression &regex)
Will be called to search for a specific expression inside the edit widget.
Definition: qsettingswidget.h:37
const_iterator constEnd() const
bool isEmpty() const
The base class for edit widgets in the settings dialog.
Definition: qsettingswidget.h:11
const_iterator constBegin() const
QSettingsWidget(QWidget *parent=nullptr)
Creates a new widget with a parent.
Definition: qsettingswidget.h:51
Generic base class for settings widgets.
Definition: qsettingswidget.h:47