QSettingsDialog  1.0.0
A Qt library to easily create a settings dialog for user configurable settings
qsettingscontainer.h
1 #ifndef QSETTINGSCONTAINER_H
2 #define QSETTINGSCONTAINER_H
3 
4 #include "qsettingsdialog_global.h"
5 #include <QObject>
6 #include <QScopedPointer>
7 #include "qsettingsentry.h"
8 #include "exceptions.h"
9 class QSettingsDialog;
10 class QSettingsLayout;
11 
13 class QSETTINGSDIALOGSHARED_EXPORT QSettingsContainer : public QObject
14 {
15  Q_OBJECT
16 
17 public:
19  virtual QSettingsDialog *dialog() const = 0;
21  virtual QString containerPath() const = 0;
22 
24  virtual int elementCount() const = 0;
26  virtual bool isEntry(int index) const = 0;
28  virtual int getEntryIndex(int id) const = 0;
30  virtual int getEntryId(int index) const = 0;
32  virtual QSharedPointer<QSettingsEntry> getEntry(int id) const = 0;
34  virtual QSharedPointer<QSettingsEntry> getEntryFromIndex(int index) const = 0;
35 
37  virtual bool transferElement(int indexFrom, QSettingsContainer *targetContainer, int indexTo) = 0;
38 
39 public slots:
41  virtual int appendEntry(QSettingsEntry *entry) = 0;
43  virtual int prependEntry(QSettingsEntry *entry) = 0;
45  virtual int insertEntry(int index, QSettingsEntry *entry) = 0;
47  virtual int insertEntry(int index, QSharedPointer<QSettingsEntry> entry) = 0;
48 
50  virtual bool removeEntry(int id) = 0;
52  virtual bool removeElementFromIndex(int index) = 0;
54  virtual void moveElement(int indexFrom, int indexTo) = 0;
55 
56 protected:
58  inline QSettingsContainer(QObject *parent = nullptr) :
59  QObject(parent)
60  {}
61 
63  virtual bool acceptEntry(int index, int id, QSharedPointer<QSettingsEntry> entry) = 0;
65  inline bool doAccept(QSettingsContainer *target, int index, int id, QSharedPointer<QSettingsEntry> entry) {
66  return target->acceptEntry(index, id, entry);
67  }
68 };
69 
71 class QGroupSettingsContainerPrivate;
73 class QSETTINGSDIALOGSHARED_EXPORT QGroupSettingsContainer : public QSettingsContainer
74 {
75  Q_OBJECT
76 
77 public:
79  explicit QGroupSettingsContainer(QSettingsDialog *settingsDialog, const QString &containerPath, QObject *parent = nullptr);
81  explicit QGroupSettingsContainer(const QSettingsLayout &layout, QObject *parent = nullptr);
84 
85  QSettingsDialog *dialog() const override;
86  QString containerPath() const override;
87 
88  int elementCount() const override;
89  bool isEntry(int index) const override;
90  int getEntryIndex(int id) const override;
91  int getEntryId(int index) const override;
92  QSharedPointer<QSettingsEntry> getEntry(int id) const override;
93  QSharedPointer<QSettingsEntry> getEntryFromIndex(int index) const override;
94 
95  bool transferElement(int indexFrom, QSettingsContainer *targetContainer, int indexTo) override;
96 
98  QSectionSettingsContainer *parentSection();
100  QSectionSettingsContainer *parentSection(QObject *parent) const;
101 
102 public slots:
103  int appendEntry(QSettingsEntry *entry) override;
104  int prependEntry(QSettingsEntry *entry) override;
105  int insertEntry(int index, QSettingsEntry *entry) override;
106  int insertEntry(int index, QSharedPointer<QSettingsEntry> entry) override;
107 
108  bool removeEntry(int id) override;
109  bool removeElementFromIndex(int index) override;
110  void moveElement(int indexFrom, int indexTo) override;
111 
112 protected:
113  bool acceptEntry(int index, int id, QSharedPointer<QSettingsEntry> entry) override;
114 
115 private:
117 };
118 
119 class QSectionSettingsContainerPrivate;
121 class QSETTINGSDIALOGSHARED_EXPORT QSectionSettingsContainer : public QSettingsContainer
122 {
123  Q_OBJECT
124 
125 public:
127  explicit QSectionSettingsContainer(QSettingsDialog *settingsDialog, const QString &containerPath, QObject *parent = nullptr);
129  explicit QSectionSettingsContainer(const QSettingsLayout &layout, QObject *parent = nullptr);
132 
133  QSettingsDialog *dialog() const override;
134  QString containerPath() const override;
135 
136  int elementCount() const override;
137  bool isEntry(int index) const override;
138 
139  int getEntryIndex(int id) const override;
141  int getGroupIndex(const QString &id) const;
142 
144  QVariant getElementId(int index) const;
145  int getEntryId(int index) const override;
147  QString getGrouptId(int index) const;
148 
149  QSharedPointer<QSettingsEntry> getEntry(int id) const override;
150  QSharedPointer<QSettingsEntry> getEntryFromIndex(int index) const override;
151 
152  bool transferElement(int indexFrom, QSettingsContainer *targetContainer, int indexTo) override;
153 
155  QGroupSettingsContainer *createGroupContainer(const QString &id);
157  QGroupSettingsContainer *createGroupContainer(const QString &id, QObject *parent) const;
159  QGroupSettingsContainer *createGroupContainerFromIndex(int index);
161  QGroupSettingsContainer *createGroupContainerFromIndex(int index, QObject *parent) const;
162 
163 public slots:
164  int appendEntry(QSettingsEntry *entry) override;
165  int prependEntry(QSettingsEntry *entry) override;
166  int insertEntry(int index, QSettingsEntry *entry) override;
167  int insertEntry(int index, QSharedPointer<QSettingsEntry> entry) override;
168 
170  void appendGroup(const QString &id,
171  int displayId = 0,
172  const QString &name = QString(),
173  bool optional = false,
174  const QString &tooltip = QString());
176  void prependGroup(const QString &id,
177  int displayId = 0,
178  const QString &name = QString(),
179  bool optional = false,
180  const QString &tooltip = QString());
182  void insertGroup(int index,
183  const QString &id,
184  int displayId = 0,
185  const QString &name = QString(),
186  bool optional = false,
187  const QString &tooltip = QString());
188 
189  bool removeEntry(int id) override;
191  bool removeGroup(const QString &id);
192  bool removeElementFromIndex(int index) override;
193  void moveElement(int indexFrom, int indexTo) override;
194 
195 protected:
196  bool acceptEntry(int index, int id, QSharedPointer<QSettingsEntry> entry) override;
197 
198 private:
200 };
201 
202 #endif // QSETTINGSCONTAINER_H
virtual void moveElement(int indexFrom, int indexTo)=0
Moves the element from the old to the new index.
virtual QSharedPointer< QSettingsEntry > getEntryFromIndex(int index) const =0
Returns the entry at the given index.
virtual bool transferElement(int indexFrom, QSettingsContainer *targetContainer, int indexTo)=0
Tries to transfer the element at index to the target container.
virtual int getEntryId(int index) const =0
Returns the id for the entry at the index.
virtual int appendEntry(QSettingsEntry *entry)=0
Appends the entry to the containers children.
bool doAccept(QSettingsContainer *target, int index, int id, QSharedPointer< QSettingsEntry > entry)
[INTERNAL USE] Helper function
Definition: qsettingscontainer.h:65
virtual QSharedPointer< QSettingsEntry > getEntry(int id) const =0
Returns the entry with the given id.
virtual bool removeEntry(int id)=0
Removes the entry with the given id.
virtual int insertEntry(int index, QSettingsEntry *entry)=0
Inserts the entry to the containers children at the given index.
A settings container for groups.
Definition: qsettingscontainer.h:73
virtual int elementCount() const =0
Returns the number of elements in this container.
A generic class the defines methods for settings containers.
Definition: qsettingscontainer.h:13
virtual QSettingsDialog * dialog() const =0
Returns the dialog this container belongs to.
A settings container for sections.
Definition: qsettingscontainer.h:121
QSettingsContainer(QObject *parent=nullptr)
Protected constructor.
Definition: qsettingscontainer.h:58
virtual bool isEntry(int index) const =0
Checks whether the element at the given index is an entry or not.
Represents one settings entry within the settings dialog.
Definition: qsettingsentry.h:11
virtual int getEntryIndex(int id) const =0
Searches for entries index.
virtual QString containerPath() const =0
Returns the container path this container has.
virtual bool acceptEntry(int index, int id, QSharedPointer< QSettingsEntry > entry)=0
Will be called to insert the given entry from a transfer.
A general class to modifiy the appereance of elements of a settings dialog.
Definition: qsettingslayout.h:15
virtual bool removeElementFromIndex(int index)=0
Removes the element at the given index.
The main class that represents the dialog itself.
Definition: qsettingsdialog.h:16
virtual int prependEntry(QSettingsEntry *entry)=0
Prepends the entry to the containers children.