QSettingsDialog  1.0.0
A Qt library to easily create a settings dialog for user configurable settings
qsettingsgroupwidget.h
1 #ifndef QSETTINGSGROUPWIDGET_H
2 #define QSETTINGSGROUPWIDGET_H
3 
4 #include "qsettingsdialog_global.h"
5 #include "qsettingsentry.h"
6 #include <QHash>
8 class QCheckBox;
9 
11 class QSETTINGSDIALOGSHARED_EXPORT QSettingsGroupWidgetBase
12 {
13 public:
15  virtual ~QSettingsGroupWidgetBase();
16 
18  virtual QWidget *asWidget() = 0;
20  virtual void initialize(const UiPropertyMap &uiPropertyMap) = 0;
21 
23  virtual void setName(const QString &name) = 0;
25  virtual void setTooltip(const QString &tooltip) = 0;
27  virtual void setOptional(bool optional) = 0;
28 
30  virtual bool isChecked() const = 0;
32  virtual void setChecked(bool checked) = 0;
33 
35  virtual void addWidgetRaw(QSharedPointer<QSettingsEntry> entry, QWidget *content, bool hasError);
37  virtual void setEntryChecked(QSharedPointer<QSettingsEntry> entry, bool checked);
39  virtual void setEntryLabelEnabled(QSharedPointer<QSettingsEntry> entry, bool enabled);
41  virtual bool isEntryChecked(QSharedPointer<QSettingsEntry> entry) const;
42 
44  virtual bool searchExpression(const QRegularExpression &regex, const QString &searchStyleSheet);
45 
46 protected:
48  virtual void addWidgetWithLabel(QWidget *label, QWidget *content) = 0;
49 
54 };
55 
57 template <class TWidget>
59 {
60 public:
62  inline QSettingsGroupWidget(QWidget *parent = nullptr) :
63  TWidget(parent),
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
const_iterator constEnd() const
QPair< QWidget *, QSettingsWidgetBase * > GroupElement
Defines one "element" within the group - label and edit widget.
Definition: qsettingsgroupwidget.h:51
Generic base class for group widgets.
Definition: qsettingsgroupwidget.h:58
QWidget * asWidget() final
Must return this as QWidget (a cast)
Definition: qsettingsgroupwidget.h:67
The base class for edit widgets in the settings dialog.
Definition: qsettingswidget.h:11
QHash< QSharedPointer< QSettingsEntry >, GroupElement > entryMap
A map that contains all elements withing this group, by their entry.
Definition: qsettingsgroupwidget.h:53
QSettingsGroupWidget(QWidget *parent=nullptr)
Creates a new group widget with a parent.
Definition: qsettingsgroupwidget.h:62
const_iterator constBegin() const
The base class for group widgets in the settings dialog.
Definition: qsettingsgroupwidget.h:11
void initialize(const UiPropertyMap &uiPropertyMap) override
Will be called to initialize the widgets properties with the given ones.
Definition: qsettingsgroupwidget.h:70