QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VideoTelemetryOverlay.cc
Go to the documentation of this file.
2
3#include <QtCore/QStringList>
4
5#include "Fact.h"
6#include "FactValueGrid.h"
9
11 : QObject(parent)
12{
13 _timer.setInterval(kUpdateIntervalMs);
14 (void) connect(&_timer, &QTimer::timeout, this, &VideoTelemetryOverlay::_update);
15 (void) connect(enabled, &Fact::rawValueChanged, this,
16 [this](const QVariant& value) { _setEnabled(value.toBool()); });
18 [this] { _layoutStale = true; });
20 [this](const QString& settingsGroup) {
22 _layoutStale = true;
23 }
24 });
25 _setEnabled(enabled->rawValue().toBool());
26}
27
28void VideoTelemetryOverlay::_setEnabled(bool enabled)
29{
30 if (!enabled) {
31 _timer.stop();
32 if (!_text.isEmpty()) {
33 _text.clear();
34 emit textChanged();
35 }
36 return;
37 }
38 // The first update waits for the timer, so that one at startup runs once the application is up.
39 _layoutStale = true;
40 _timer.start();
41}
42
43void VideoTelemetryOverlay::_update()
44{
45 if (_layoutStale) {
46 _telemetry.readLayout();
47 _layoutStale = false;
48 }
49
50 QStringList parts;
51 if (const std::optional<QList<TelemetryBarValues::Value>> values = _telemetry.read()) {
52 for (const TelemetryBarValues::Value& value : *values) {
53 // Non-breaking spaces keep each value on one line where the overlay wraps.
54 parts << QStringLiteral("%1: %2").arg(value.name, value.value.trimmed()).replace(u' ', QChar::Nbsp);
55 }
56 }
57 const QString text = parts.join(QStringLiteral(" "));
58 if (text != _text) {
59 _text = text;
60 emit textChanged();
61 }
62}
static FactValueGridLayouts * instance()
void saved(const QString &settingsGroup)
A grid of settings group settingsGroup saved its layout.
A Fact is used to hold a single value within the system.
Definition Fact.h:15
void rawValueChanged(const QVariant &value)
QVariant rawValue() const
Definition Fact.h:87
static const QString telemetryBarSettingsGroup
static MultiVehicleManager * instance()
void activeVehicleChanged(Vehicle *activeVehicle)
VideoTelemetryOverlay(Fact *enabled, QObject *parent=nullptr)
Shows the overlay while enabled, a bool Fact, is on.