QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AirframeComponentAirframes.cc
Go to the documentation of this file.
2#include <QtCore/QFile>
3
4QMap<QString, AirframeComponentAirframes::AirframeType_t*> AirframeComponentAirframes::rgAirframeTypes;
5
6QMap<QString, AirframeComponentAirframes::AirframeType_t*>& AirframeComponentAirframes::get() {
7
8#if 0
9 // Set a single airframe to prevent the UI from going crazy
10 if (rgAirframeTypes.count() == 0) {
11 // Standard planes
12 AirframeType_t *standardPlane = new AirframeType_t;
13 standardPlane->name = "Standard Airplane";
14 standardPlane->imageResource = "qrc:/qmlimages/Airframe/Plane.svg";
15 AirframeInfo_t *easystar = new AirframeInfo_t;
16 easystar->name = "Multiplex Easystar 1/2";
17 easystar->autostartId = 2100;
18 standardPlane->rgAirframeInfo.append(easystar);
19 rgAirframeTypes.insert("StandardPlane", standardPlane);
20 qDebug() << "Adding plane config";
21
22 // Flying wings
23 }
24#endif
25
26 return rgAirframeTypes;
27}
28
29QList<AirframeComponentAirframes::AirframeType_t*> AirframeComponentAirframes::sortedTypes()
30{
31 // Standard airframes show first so users don't have to scroll past the
32 // exotic frames to find a regular quad. The remainder follows in QMap
33 // (alphabetical) order.
34 static const char *priorityNames[] = {
35 "Quadrotor x",
36 "Standard Plane",
37 "Standard VTOL",
38 };
39
40 QList<AirframeType_t*> sorted;
41 for (const char *name : priorityNames) {
42 AirframeType_t *type = rgAirframeTypes.value(QLatin1String(name), nullptr);
43 if (type) {
44 sorted.append(type);
45 }
46 }
47 for (AirframeType_t *type : rgAirframeTypes) {
48 if (!sorted.contains(type)) {
49 sorted.append(type);
50 }
51 }
52
53 return sorted;
54}
55
56void AirframeComponentAirframes::insert(QString& group, QString& image, QString& name, int id)
57{
59 if (!rgAirframeTypes.contains(group)) {
60 g = new AirframeType_t;
61 g->name = group;
62
63 if (image.length() > 0) {
64 g->imageResource = QString(":/qmlimages/Airframe/%1.svg").arg(image);
65 if (!QFile::exists(g->imageResource)) {
66 g->imageResource.clear();
67 } else {
68 g->imageResource.prepend(QStringLiteral("qrc"));
69 }
70 }
71
72 if (g->imageResource.isEmpty()) {
73 g->imageResource = QString("qrc:/qmlimages/Airframe/AirframeUnknown.svg");
74 }
75
76 rgAirframeTypes.insert(group, g);
77 } else {
78 g = rgAirframeTypes.value(group);
79 }
80
82 i->name = name;
83 i->autostartId = id;
84
85 g->rgAirframeInfo.append(i);
86}
87
89
90 // Run through all and delete them
91 for (int tindex = 0; tindex < AirframeComponentAirframes::get().count(); tindex++) {
92
94
95 for (int index = 0; index < pType->rgAirframeInfo.count(); index++) {
96 const AirframeComponentAirframes::AirframeInfo_t* pInfo = pType->rgAirframeInfo.at(index);
97 delete pInfo;
98 }
99
100 delete pType;
101 }
102
103 rgAirframeTypes.clear();
104}
static void insert(QString &group, QString &image, QString &name, int id)
static QMap< QString, AirframeComponentAirframes::AirframeType_t * > & get()
static QMap< QString, AirframeType_t * > rgAirframeTypes
static QList< AirframeType_t * > sortedTypes()