QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FactGroupListModel.cc
Go to the documentation of this file.
2#include "Vehicle.h"
3
4FactGroupListModel::FactGroupListModel(const char* factGroupNamePrefix, QObject* parent)
5 : QmlObjectListModel(parent)
6 , _factGroupNamePrefix(factGroupNamePrefix)
7{
8
9}
10
12{
14
15 if (_shouldHandleMessage(message, ids)) {
16 for (const uint32_t id : ids) {
17 _findOrAddFactGroupById(vehicle, id);
18 }
19 }
20}
21
23{
24 return QStringLiteral("%1%2").arg(_factGroupNamePrefix).arg(id);
25}
26
28{
29 int i = 0;
30
31 // We maintain the list in order sorted by id so the ui shows them sorted.
32 for (; i < static_cast<int>(count()); i++) {
33 auto *const currentGroup = value<FactGroupWithId*>(i);
34 const int currentId = currentGroup->id()->rawValue().toInt();
35 if (currentId > static_cast<int>(id)) {
36 break;
37 } else if (currentId == static_cast<int>(id)) {
38 return currentGroup;
39 }
40 }
41
42 auto *const newGroup = _createFactGroupWithId(id);
43 insert(static_cast<int>(i), newGroup);
45
46 return newGroup;
47}
struct __mavlink_message mavlink_message_t
FactGroupListModel(const char *factGroupNamePrefix, QObject *parent=nullptr)
virtual bool _shouldHandleMessage(const mavlink_message_t &message, QList< uint32_t > &ids) const =0
FactGroupWithId * _findOrAddFactGroupById(Vehicle *vehicle, uint32_t id)
virtual FactGroupWithId * _createFactGroupWithId(uint32_t id)=0
QString _factGroupNameWithId(uint32_t id) const
void handleMessageForFactGroupCreation(Vehicle *vehicle, const mavlink_message_t &message)
Allows for creation/updating of dynamic FactGroups based on incoming messages.
const char * _factGroupNamePrefix
void _addFactGroup(FactGroup *factGroup, const QString &name)
Definition FactGroup.cc:130
QModelIndex index(int row, int column=0, const QModelIndex &parent=QModelIndex()) const override
int count() const override final
void insert(int index, QObject *object)