From fc61f1a0899b6aeed6418ab9a729f3aada97af42 Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Tue, 1 Dec 2020 17:07:04 -0300 Subject: [PATCH] SubtitleWriter: update to use new intruments widget --- src/VideoManager/SubtitleWriter.cc | 34 ++++++++++++++++++++++++---------- src/VideoManager/SubtitleWriter.h | 5 +++-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/VideoManager/SubtitleWriter.cc b/src/VideoManager/SubtitleWriter.cc index 41bdf28..33ee726 100644 --- a/src/VideoManager/SubtitleWriter.cc +++ b/src/VideoManager/SubtitleWriter.cc @@ -17,6 +17,9 @@ #include "SubtitleWriter.h" #include "QGCApplication.h" #include "QGCCorePlugin.h" +#include "FactValueGrid.h" +#include "HorizontalFactValueGrid.h" +#include "InstrumentValueData.h" #include #include #include @@ -33,11 +36,22 @@ SubtitleWriter::SubtitleWriter(QObject* parent) void SubtitleWriter::startCapturingTelemetry(const QString& videoFile) { - // Get the facts displayed in the values widget and capture them, removing the "Vehicle." prefix. - QSettings settings; - settings.beginGroup("ValuesWidget"); - _values = settings.value("large").toStringList().replaceInStrings(QStringLiteral("Vehicle."), QString()); - _values += settings.value("small").toStringList().replaceInStrings(QStringLiteral("Vehicle."), QString()); + // Delete facts of last run + _facts.clear(); + + // Gather the facts currently displayed into _facts + FactValueGrid* grid = new FactValueGrid(); + grid->setProperty("userSettingsGroup", HorizontalFactValueGrid::telemetryBarUserSettingsGroup); + grid->setProperty("defaultSettingsGroup", HorizontalFactValueGrid::telemetryBarDefaultSettingsGroup); + grid->_loadSettings(); + for (int colIndex = 0; colIndex < grid->columns()->count(); colIndex++) { + QmlObjectListModel* list = grid->columns()->value(colIndex); + for (int rowIndex = 0; rowIndex < list->count(); rowIndex++) { + InstrumentValueData* value = list->value(rowIndex); + _facts += value->fact(); + } + } + grid->deleteLater(); // One subtitle always starts where the previous ended _lastEndTime = QTime(0, 0); @@ -102,10 +116,10 @@ void SubtitleWriter::_captureTelemetry() QStringList valuesStrings; // Make a list of "factname:" strings and other with the values, so one can be aligned left and the other right - for (const auto& i : _values) { - valuesStrings << QStringLiteral("%2 %3").arg(vehicle->getFact(i)->cookedValueString()) - .arg(vehicle->getFact(i)->cookedUnits()); - namesStrings << QStringLiteral("%1:").arg(vehicle->getFact(i)->shortDescription()); + for (const Fact* fact : _facts) { + valuesStrings << QStringLiteral("%2 %3").arg(fact->cookedValueString()) + .arg(fact->cookedUnits()); + namesStrings << QStringLiteral("%1:").arg(fact->shortDescription()); } // The time to start displaying this subtitle text @@ -118,7 +132,7 @@ void SubtitleWriter::_captureTelemetry() // This splits the screen in N parts and uses the N-1 internal parts to align the subtitles to. // Should we try to get the resolution from the pipeline? This seems to work fine with other resolutions too. static const int rowWidth = (1920 + offsetFactor)/(nRows+1); - int nValuesByRow = ceil(_values.length() / nRows); + int nValuesByRow = ceil(_facts.length() / nRows); QList dataColumns; QStringList stringColumns; diff --git a/src/VideoManager/SubtitleWriter.h b/src/VideoManager/SubtitleWriter.h index 902f1f0..35053b1 100644 --- a/src/VideoManager/SubtitleWriter.h +++ b/src/VideoManager/SubtitleWriter.h @@ -17,6 +17,7 @@ #pragma once #include "QGCLoggingCategory.h" +#include "Fact.h" #include #include #include @@ -42,9 +43,9 @@ private slots: private: QTimer _timer; - QStringList _values; + QList _facts; QTime _lastEndTime; QFile _file; - static const int _sampleRate; + static const int _sampleRate; // Sample rate in Hz for getting telemetry data, most players do weird stuff when > 1Hz };