QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QmlObjectListModel.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <QtCore/QLoggingCategory>
6
7Q_DECLARE_LOGGING_CATEGORY(QmlObjectListModelLog)
8
10{
11 Q_OBJECT
12 QML_ELEMENT
13 QML_UNCREATABLE("")
14
15public:
16 QmlObjectListModel(QObject* parent = nullptr);
17
18 // Overrides from ObjectListModelBase
19 int count() const override final;
20 bool isEmpty() const override final { return count() == 0; }
21 void setDirty(bool dirty) override final;
22 void clear() override final;
23 QObject* removeOne(const QObject* object) override final { return removeAt(indexOf(object)); }
24 bool contains(const QObject* object) override final { return _objectList.indexOf(object) != -1; }
25 void clearAndDeleteContents() override final;
26
27 // QmlObjectListModel specific methods
28 Q_INVOKABLE QObject* get(int index);
29 QObject* operator[](int index);
30 const QObject* operator[](int index) const;
31 void append(QObject* object);
32 void append(QList<QObject*> objects);
33 QObjectList swapObjectList(const QObjectList& newlist);
34 QObject* removeAt(int index);
35 void insert(int index, QObject* object);
36 void insert(int index, QList<QObject*> objects);
37 int indexOf(const QObject* object) { return _objectList.indexOf(object); }
38 void move(int from, int to);
39 template<class T> T value(int index) const { return qobject_cast<T>(_objectList[index]); }
40 QList<QObject*>* objectList() { return &_objectList; }
41
42protected:
43 // Overrides from QAbstractListModel
44 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
45 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
46 bool insertRows(int position, int rows, const QModelIndex& index = QModelIndex()) override;
47 bool removeRows(int position, int rows, const QModelIndex& index = QModelIndex()) override;
48 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
49
50private:
51 QList<QObject*> _objectList;
52};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
T value(int index) const
bool isEmpty() const override final
bool contains(const QObject *object) override final
QList< QObject * > * objectList()