C++ Web Framework  3.0
qlistobject.h
1 /*
2  Copyright 2017 Herik Lima de Castro and Marcelo Medeiros Eler
3  Distributed under MIT license, or public domain if desired and
4  recognized in your jurisdiction.
5  See file LICENSE for detail.
6 */
7 
8 #ifndef QLISTOBJECT_H
9 #define QLISTOBJECT_H
10 
11 #include <QObject>
12 #include "cppwebframework_global.h"
13 
14 CWF_BEGIN_NAMESPACE
20 class CPPWEBFRAMEWORKSHARED_EXPORT QListObject : public QObject
21 {
22  Q_OBJECT
23 private:
24  bool autoDelete = false;
25 public:
30  explicit QListObject(QObject *parent = 0) : QObject(parent) {}
34  explicit QListObject(QObject *parent, const std::initializer_list<QObject *> &objects) : QObject(parent) { add(objects); }
38  explicit QListObject(const std::initializer_list<QObject *> &objects) : QObject(nullptr) { add(objects); }
42  ~QListObject();
48  inline QObject *operator [](int index) const { return children()[index]; }
53  inline int size() const { return children().count(); }
58  inline void add(QObject *object) { object->setParent(this); }
62  inline void add(const std::initializer_list<QObject *> &objects)
63  {
64  std::for_each(objects.begin(), objects.end(), [&](QObject *o){ o->setParent(this); });
65  }
70  inline void remove(QObject *object) { object->setParent(nullptr); }
75  inline bool getAutoDelete() const { return autoDelete; }
80  inline void setAutoDelete(bool value) { autoDelete = value; }
81 };
82 
83 CWF_END_NAMESPACE
84 
85 #endif // QLISTOBJECT_H
QListObject(const std::initializer_list< QObject *> &objects)
Contructs a QListObject with N elements.
Definition: qlistobject.h:38
void add(const std::initializer_list< QObject *> &objects)
This method add a N new QObjects to the list.
Definition: qlistobject.h:62
QListObject(QObject *parent=0)
This constructor can receive a parent.
Definition: qlistobject.h:30
bool getAutoDelete() const
getAutoDelete
Definition: qlistobject.h:75
int size() const
This method returns the number of elements in this QListObject.
Definition: qlistobject.h:53
void add(QObject *object)
This method add a new QObject to the list.
Definition: qlistobject.h:58
QListObject(QObject *parent, const std::initializer_list< QObject *> &objects)
Contructs a QListObject with N elements.
Definition: qlistobject.h:34
The QListObject class is used to pass a list of object to a view page. NOTE: Always when you need to ...
Definition: qlistobject.h:20
void setAutoDelete(bool value)
setAutoDelete
Definition: qlistobject.h:80