13 qCDebug(LogViewerControllerLog) <<
this;
16LogViewerController::~LogViewerController()
18 qCDebug(LogViewerControllerLog) <<
this;
21void LogViewerController::clear()
23 _plottableFields.clear();
25 _selectedFields.clear();
26 _expandedGroups.clear();
29 _setLog(SourceType::None, QString(), tr(
"No log loaded"));
32void LogViewerController::openTLog(
const QString &path)
34 _setLog(SourceType::TLog, path, tr(
"Telemetry log loaded"));
37void LogViewerController::openBinLog(
const QString &path)
39 _setLog(SourceType::Bin, path, tr(
"DataFlash log loaded"));
42void LogViewerController::openULogFile(
const QString &path)
44 _setLog(SourceType::ULog, path, tr(
"ULog file loaded"));
47void LogViewerController::setPlottableFields(
const QStringList &fieldNames)
49 _plottableFields = fieldNames;
50 std::sort(_plottableFields.begin(), _plottableFields.end());
51 _selectedFields.clear();
56void LogViewerController::clearSelection()
58 if (_selectedFields.isEmpty()) {
62 _selectedFields.clear();
66void LogViewerController::toggleGroupExpanded(
const QString &groupName)
68 if (_expandedGroups.contains(groupName)) {
69 _expandedGroups.remove(groupName);
71 _expandedGroups.insert(groupName);
77bool LogViewerController::isGroupExpanded(
const QString &groupName)
const
79 return _expandedGroups.contains(groupName);
82void LogViewerController::setFieldSelected(
const QString &fieldName,
bool selected)
84 const bool currentlySelected = _selectedFields.contains(fieldName);
85 if (currentlySelected == selected) {
90 _selectedFields.append(fieldName);
92 _selectedFields.removeAll(fieldName);
98bool LogViewerController::isFieldSelected(
const QString &fieldName)
const
100 return _selectedFields.contains(fieldName);
103QString LogViewerController::fieldColor(
const QString &fieldName)
const
105 return _assignColorForKey(fieldName);
108QString LogViewerController::eventColor(
const QString &eventType)
const
110 if (eventType == QStringLiteral(
"mode")) {
111 return _assignColorForKey(QStringLiteral(
"event-mode"));
113 if (eventType == QStringLiteral(
"error")) {
114 return _assignColorForKey(QStringLiteral(
"event-error"));
116 if (eventType == QStringLiteral(
"event")) {
117 return _assignColorForKey(QStringLiteral(
"event-generic"));
119 if (eventType == QStringLiteral(
"warning")) {
120 return _assignColorForKey(QStringLiteral(
"event-warning"));
123 return _assignColorForKey(QStringLiteral(
"event-other"));
126QString LogViewerController::modeColor(
const QString &modeName)
const
128 static const QStringList modePalette = {
129 QStringLiteral(
"#E53935"),
130 QStringLiteral(
"#FB8C00"),
131 QStringLiteral(
"#FDD835"),
132 QStringLiteral(
"#43A047"),
133 QStringLiteral(
"#00897B"),
134 QStringLiteral(
"#00ACC1"),
135 QStringLiteral(
"#1E88E5"),
136 QStringLiteral(
"#5E35B1"),
137 QStringLiteral(
"#8E24AA"),
138 QStringLiteral(
"#D81B60"),
139 QStringLiteral(
"#6D4C41"),
140 QStringLiteral(
"#546E7A"),
144 for (
const QChar ch : modeName) {
145 hash = (hash * 31U) + ch.unicode();
148 const qsizetype idx =
static_cast<qsizetype
>(hash %
static_cast<quint32
>(modePalette.count()));
149 return modePalette[idx];
152QStringList LogViewerController::modeLegendEntries(
const QVariantList &modeSegments)
const
155 for (
const QVariant &variant : modeSegments) {
156 const QVariantMap segment = variant.toMap();
157 const QString mode = segment.value(QStringLiteral(
"mode")).toString();
158 if (!mode.isEmpty() && !modes.contains(mode)) {
166void LogViewerController::_setLog(SourceType sourceType,
const QString &path,
const QString &statusText)
168 if (_sourceType != sourceType) {
169 _sourceType = sourceType;
173 if (_currentLogPath != path) {
174 _currentLogPath = path;
178 if (_statusText != statusText) {
179 _statusText = statusText;
183 qCDebug(LogViewerControllerLog) <<
"sourceType" <<
static_cast<int>(_sourceType) <<
"path" << _currentLogPath;
186void LogViewerController::_rebuildFieldRows()
188 QHash<QString, QStringList> groupedMap;
191 for (
const QString &field : _plottableFields) {
192 const int splitIndex = field.indexOf(
'.');
193 const QString groupName = (splitIndex > 0) ? field.left(splitIndex) : tr(
"Other");
194 const QString shortName = (splitIndex > 0) ? field.mid(splitIndex + 1) : field;
195 if (!groupedMap.contains(groupName)) {
196 groups.append(groupName);
198 groupedMap[groupName].append(shortName);
201 std::sort(groups.begin(), groups.end());
204 for (
const QString &groupName : groups) {
205 QVariantMap groupRow;
206 groupRow[QStringLiteral(
"rowType")] = QStringLiteral(
"group");
207 groupRow[QStringLiteral(
"group")] = groupName;
208 rows.append(groupRow);
210 if (!_expandedGroups.contains(groupName)) {
214 QStringList fieldNames = groupedMap.value(groupName);
215 std::sort(fieldNames.begin(), fieldNames.end());
216 for (
const QString &shortName : fieldNames) {
217 QVariantMap fieldRow;
218 fieldRow[QStringLiteral(
"rowType")] = QStringLiteral(
"field");
219 fieldRow[QStringLiteral(
"group")] = groupName;
220 fieldRow[QStringLiteral(
"shortName")] = shortName;
221 fieldRow[QStringLiteral(
"fullName")] = QStringLiteral(
"%1.%2").arg(groupName, shortName);
222 rows.append(fieldRow);
230QString LogViewerController::_assignColorForKey(
const QString &key)
const
232 static const QStringList palette = {
233 QStringLiteral(
"#3776D6"),
234 QStringLiteral(
"#D9534F"),
235 QStringLiteral(
"#3FA96B"),
236 QStringLiteral(
"#D98E04"),
237 QStringLiteral(
"#7B5CC9"),
238 QStringLiteral(
"#D64E8B"),
239 QStringLiteral(
"#2FA9A2"),
240 QStringLiteral(
"#D96A2D"),
241 QStringLiteral(
"#4A6CD4"),
242 QStringLiteral(
"#6EA827"),
246 for (
const QChar ch : key) {
247 hash = (hash * 31U) + ch.unicode();
250 const qsizetype idx =
static_cast<qsizetype
>(hash %
static_cast<quint32
>(palette.count()));
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void currentLogPathChanged()
void selectedFieldsChanged()