QSettingsDialog  1.0.0
A Qt library to easily create a settings dialog for user configurable settings
qsettingsentry.h
1 #ifndef QSETTINGSENTRY_H
2 #define QSETTINGSENTRY_H
3 
4 #include "qsettingsdialog_global.h"
5 #include <QScopedPointer>
6 #include <QHash>
7 #include "qsettingsloader.h"
8 
9 class QSettingsEntryPrivate;
11 class QSETTINGSDIALOGSHARED_EXPORT QSettingsEntry
12 {
13  friend class SettingsEntryLayout;
14 
15 public:
17  QSettingsEntry(int displaytype, QSettingsLoader *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());
26  template<typename... Args>
27  QSettingsEntry(int displaytype,
28  QSettingsLoader *loader,
29  const QString &name,
30  bool optional,
31  const QString &tooltip,
32  Args... properties);
34  virtual ~QSettingsEntry();
35 
37  QString entryName() const;
39  void setEntryName(const QString &name);
41  bool isOptional() const;
43  void setOptional(bool optional);
45  QString tooltip() const;
47  void setTooltip(const QString &tooltip);
48 
50  UiPropertyMap uiProperties() const;
52  void setUiProperties(const UiPropertyMap &properties);
54  void setUiProperty(const QString &name, const QVariant &value);
55 
57  virtual int displaytype();
59  virtual QSettingsLoader *getLoader();
61  virtual void freeLoader(QSettingsLoader *loader);//TODO required?
62 
63 private:
65 };
66 
67 
68 
69 template<typename TVariant>
70 UiPropertyMap mapWrapper(const char *key, TVariant value) {
71  return UiPropertyMap({{key, QVariant::fromValue(value)}});
72 }
73 
74 template<typename TVariant, typename... Args>
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<typename... Args>
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
Represents one settings entry within the settings dialog.
Definition: qsettingsentry.h:11
QSettingsEntry(int displaytype, QSettingsLoader *loader)
Creates a new entry from a display id and a loader.
QVariant fromValue(const T &value)
QHash< QString, QVariant > UiPropertyMap
a Hash for strings to variant, to provide properties for edit widgets
Definition: qsettingsdialog_global.h:42
The basic settings loader class. Serves as utility class.
Definition: qsettingsloader.h:16