Skip to content

Commit

Permalink
Add checklists widget
Browse files Browse the repository at this point in the history
  • Loading branch information
fvantienen committed May 15, 2024
1 parent 5442c95 commit 9acff22
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 10 deletions.
1 change: 1 addition & 0 deletions data/default_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<widget name="flightplan" icon="flight_plan.svg"/>
<widget name="gps_classic_viewer" icon="gps.svg"/>
<widget name="chat" icon="chat.svg"/>
<widget name="checklist" icon="checklist.svg"/>
</columnLeft>
<columnRight>
<widget name="PFD" icon="pfd.svg"/>
Expand Down
37 changes: 37 additions & 0 deletions data/pictures/checklist.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions src/common/aircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ Aircraft::Aircraft(ConfigData* config, QObject* parent): QObject(parent),
icon = user_or_app_path("pictures/aircraft_icons/" + QString(airframe->getIconName()) + ".svg");
}
checklist = airframe->getChecklistItems();
for(auto item: checklist) {
qDebug() << "Checklist item: " << item.name << " " << item.description << " " << item.type << " " << item.done;
}
status = new AircraftStatus(ac_id, this);
real = config->isReal();
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/aircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Aircraft: public QObject
Airframe* getAirframe() {return airframe;}
AircraftStatus* getStatus() {return status;}
ConfigData* getConfig() {return config;}
QList<ChecklistItem*> getChecklist() {return checklist;}
void setConfig(ConfigData* c) {config = c;}

Point2DLatLon getPosition() {return position;}
Expand All @@ -47,7 +48,7 @@ class Aircraft: public QObject
SettingMenu* setting_menu;
Airframe* airframe;
ConfigData* config;
QList<ChecklistItem> checklist;
QList<ChecklistItem*> checklist;

Point2DLatLon position;

Expand Down
7 changes: 4 additions & 3 deletions src/common/airframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ std::optional<Param> Airframe::getDefine(QString def_name, QString section_name)
return std::nullopt;
}

QList<ChecklistItem> Airframe::getChecklistItems() {
QList<ChecklistItem> items;
QList<ChecklistItem*> Airframe::getChecklistItems() {
QList<ChecklistItem*> items;

for(auto section=doc.firstChildElement().firstChildElement("checklist");
!section.isNull();
Expand All @@ -162,7 +162,8 @@ QList<ChecklistItem> Airframe::getChecklistItems() {
auto name = item.attribute("name");
auto description = item.firstChild().nodeValue();
auto type = item.attribute("type", "checkbox");
items.append({name, description, type, false});
auto checklist_item = new ChecklistItem({name, description, type, ""});
items.append(checklist_item);
}
}
return items;
Expand Down
4 changes: 2 additions & 2 deletions src/common/airframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ChecklistItem {
QString name;
QString description;
QString type;
bool done;
QString value;
};

class Airframe: public QObject
Expand All @@ -35,7 +35,7 @@ class Airframe: public QObject
void saveSettings(QString filename);
void setParams(QMap<QString, QString> changed_params);
QList<Param> getParams();
QList<ChecklistItem> getChecklistItems();
QList<ChecklistItem*> getChecklistItems();

private:
QString name;
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ set(SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/gvf_viewer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/chat.cpp
${CMAKE_CURRENT_SOURCE_DIR}/chat.ui
${CMAKE_CURRENT_SOURCE_DIR}/checklist.cpp
${CMAKE_CURRENT_SOURCE_DIR}/checklist.ui
)

set(INC_DIRS ${INC_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
70 changes: 70 additions & 0 deletions src/widgets/checklist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "checklist.h"
#include "ui_checklist.h"
#include "pprz_dispatcher.h"
#include "gcs_utils.h"
#include "AircraftManager.h"
#include "dispatcher_ui.h"
#include "chatbubble.h"
#include <QtWidgets>
#include <QDebug>
#include <ostream>

Checklist::Checklist(QString ac_id, QWidget *parent) :
QFrame(parent),
ui(new Ui::Checklist)
{
// Get the settings
auto settings_path = appConfig()->value("SETTINGS_PATH").toString();
QSettings settings(settings_path, QSettings::IniFormat);
pprzlink_id = settings.value("pprzlink/id").toString();

// Setup the UI
ui->setupUi(this);

QList<ChecklistItem*> checklist = AircraftManager::get()->getAircraft(ac_id)->getChecklist();
for(auto item: checklist) {
if(item->type == "checkbox") {
auto widget_item = new QCheckBox(item->description);
if(item->value == "true") {
widget_item->setChecked(true);
}
ui->verticalLayout->addWidget(widget_item);

connect(widget_item, &QCheckBox::toggled, this,
[=](bool state) {
item->value = (state)? QString("true") : QString("false");
sendMessage(ac_id, item);
});
}
else if(item->type == "text") {
auto widget_item = new QHBoxLayout();
auto widget_label = new QLabel(item->description);
auto widget_input = new QLineEdit();
widget_item->addWidget(widget_label);
widget_item->addWidget(widget_input);
ui->verticalLayout->addLayout(widget_item);

connect(widget_input, &QLineEdit::returnPressed, this,
[=]() {
item->value = widget_input->text();
sendMessage(ac_id, item);
});
}
}

setAutoFillBackground(true);
}

void Checklist::sendMessage(QString ac_id, ChecklistItem *item) {
auto msgDef = PprzDispatcher::get()->getDict()->getDefinition("INFO_MSG_GROUND");
pprzlink::Message pprz_msg(msgDef);
pprz_msg.addField("dest", ac_id);
pprz_msg.addField("source", pprzlink_id);
pprz_msg.addField("msg", "[PFC] " + item->name + ": " + item->value);
PprzDispatcher::get()->sendMessage(pprz_msg);
}

Checklist::~Checklist()
{
delete ui;
}
26 changes: 26 additions & 0 deletions src/widgets/checklist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef CHECKLIST_H
#define CHECKLIST_H

#include <QFrame>
#include "airframe.h"

namespace Ui {
class Checklist;
}

class Checklist : public QFrame
{
Q_OBJECT

public:
explicit Checklist(QString ac_id, QWidget *parent = nullptr);
~Checklist();

private:
void sendMessage(QString ac_id, ChecklistItem *item);

QString pprzlink_id;
Ui::Checklist *ui;
};

#endif // CHECKLIST_H
46 changes: 46 additions & 0 deletions src/widgets/checklist.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Checklist</class>
<widget class="QFrame" name="Checklist">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>30</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>350</width>
<height>30</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="rightMargin">
<number>9</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="styleSheet">
<string notr="true">font-weight:bold;</string>
</property>
<property name="text">
<string>Checklist</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
5 changes: 4 additions & 1 deletion src/widgets/widget_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
#include "tuple_helpers.h"
#include "gvf_viewer.h"
#include "chat.h"
#include "checklist.h"

using ac_widgets_list = std::tuple<
SettingsViewer, MiniStrip,
Commands, FlightPlanViewerV2,
GPSClassicViewer, FlightPlanEditor,
Plotter, LinkStatus, GVFViewer
Plotter, LinkStatus, GVFViewer,
Checklist
>;
using simple_widgets_list = std::tuple<PprzMap, Pfd, Chat>;
using containers_list = std::tuple<StackContainer, ListContainer>;
Expand All @@ -36,6 +38,7 @@ std::map<QString, size_t> AC_WIDGETS_MAP = {
{"plotter", tuple_element_index_v<Plotter, ac_widgets_list>},
{"link_status", tuple_element_index_v<LinkStatus, ac_widgets_list>},
{"gvf_viewer", tuple_element_index_v<GVFViewer, ac_widgets_list>},
{"checklist", tuple_element_index_v<Checklist, ac_widgets_list>},
};


Expand Down

0 comments on commit 9acff22

Please sign in to comment.