From 9fa9620f086fd69dbfd4959938628b4cb17cd095 Mon Sep 17 00:00:00 2001 From: Sergii Dmytrenko <30838113+varajan@users.noreply.github.com> Date: Sun, 7 Dec 2025 02:37:33 +0200 Subject: [PATCH] feat(cpn): make it possible to use same scale in Log Viewer graph (#6818) --- companion/src/logsdialog.cpp | 96 +++++++++++++++---- companion/src/logsdialog.h | 1 + companion/src/logsdialog.ui | 32 ++++++- companion/src/translations/companion_cs.ts | 9 +- companion/src/translations/companion_da.ts | 9 +- companion/src/translations/companion_de.ts | 9 +- companion/src/translations/companion_en.ts | 9 +- companion/src/translations/companion_es.ts | 9 +- companion/src/translations/companion_fi.ts | 9 +- companion/src/translations/companion_fr.ts | 9 +- companion/src/translations/companion_he.ts | 9 +- companion/src/translations/companion_it.ts | 9 +- companion/src/translations/companion_ja.ts | 9 +- companion/src/translations/companion_ko.ts | 9 +- companion/src/translations/companion_nl.ts | 9 +- companion/src/translations/companion_pl.ts | 9 +- companion/src/translations/companion_pt.ts | 9 +- companion/src/translations/companion_sv.ts | 9 +- companion/src/translations/companion_zh_CN.ts | 4 +- companion/src/translations/companion_zh_TW.ts | 9 +- 20 files changed, 222 insertions(+), 55 deletions(-) diff --git a/companion/src/logsdialog.cpp b/companion/src/logsdialog.cpp index 24b1a0799..f493cb9af 100644 --- a/companion/src/logsdialog.cpp +++ b/companion/src/logsdialog.cpp @@ -124,7 +124,13 @@ LogsDialog::LogsDialog(QWidget *parent) : connect(ui->customPlot, &QCustomPlot::legendDoubleClick, this, &LogsDialog::legendDoubleClick); connect(ui->FieldsTW, &QTableWidget::itemSelectionChanged, this, &LogsDialog::plotLogs); connect(ui->logTable, &QTableWidget::itemSelectionChanged, this, &LogsDialog::plotLogs); - connect(ui->Reset_PB, &QPushButton::clicked, this, &LogsDialog::plotLogs); + connect(ui->Reset_PB, &QPushButton::clicked, this, [this]() { + ui->ZoomX_ChkB->setChecked(false); + ui->ZoomY_ChkB->setChecked(false); + ui->CommonAxes_ChkB->setChecked(false); + plotLogs(); + }); + connect(ui->CommonAxes_ChkB, &QPushButton::clicked, this, &LogsDialog::plotLogs); connect(ui->SaveSession_PB, &QPushButton::clicked, this, &LogsDialog::saveSession); connect(ui->fileOpen_PB, &QPushButton::clicked, this, &LogsDialog::fileOpen); connect(ui->mapsButton, &QPushButton::clicked, this, &LogsDialog::mapsButtonClicked); @@ -822,6 +828,50 @@ void LogsDialog::sessionsCurrentIndexChanged(int index) plotLogs(); } +std::pair LogsDialog::GetMinMaxY() const +{ + double minVal = 0.0; + double maxVal = 0.0; + bool found = false; + + // determine selected rows in the log table + QModelIndexList sel = ui->logTable->selectionModel()->selectedRows(); + bool hasSelection = !sel.isEmpty(); + QVarLengthArray selectedRows; + + if (hasSelection) { + selectedRows.reserve(sel.size()); + for (const QModelIndex &idx : sel) selectedRows.append(idx.row()); + } + + // iterate over selected fields and rows to compute global min/max Y + for (QTableWidgetItem *fieldItem : ui->FieldsTW->selectedItems()) { + const int col = fieldItem->row() + 2; // Date and Time are first two columns + const int rows = hasSelection ? selectedRows.length() : ui->logTable->rowCount(); + + for (int r = 0; r < rows; ++r) { + const int tableRow = hasSelection ? selectedRows.at(r) : r; + QTableWidgetItem *cell = ui->logTable->item(tableRow, col); + if (!cell) continue; + + bool ok = false; + const double v = cell->text().toDouble(&ok); + if (!ok) continue; + + if (!found) { + minVal = maxVal = v; + found = true; + } else { + if (v < minVal) minVal = v; + if (v > maxVal) maxVal = v; + } + } + } + + if (!found) return {0.0, 0.0}; + return {minVal, maxVal}; +} + void LogsDialog::plotLogs() { if (plotLock) return; @@ -836,6 +886,7 @@ void LogsDialog::plotLogs() QModelIndexList selection = ui->logTable->selectionModel()->selectedRows(); int rowCount = selection.length(); bool hasLogSelection; + bool useCommonAxes = ui->CommonAxes_ChkB->isChecked(); QVarLengthArray selectedRows; if (rowCount) { @@ -922,23 +973,25 @@ void LogsDialog::plotLogs() plots.coords.at(i).max_y < yAxesRanges[plots.coords.at(i).yaxis].min) ) { - switch (plots.coords[i].yaxis) { - case firstLeft: - plots.coords[i].yaxis = firstRight; - break; - case firstRight: - plots.coords[i].yaxis = secondLeft; - break; - case secondLeft: - plots.coords[i].yaxis = secondRight; - break; - case secondRight: - plots.tooManyRanges = true; - break; - default: - break; + if (!useCommonAxes) { + switch (plots.coords[i].yaxis) { + case firstLeft: + plots.coords[i].yaxis = firstRight; + break; + case firstRight: + plots.coords[i].yaxis = secondLeft; + break; + case secondLeft: + plots.coords[i].yaxis = secondRight; + break; + case secondRight: + plots.tooManyRanges = true; + break; + default: + break; + } + if (plots.tooManyRanges) break; } - if (plots.tooManyRanges) break; actualRange = yAxesRanges[plots.coords.at(i).yaxis].max - yAxesRanges[plots.coords.at(i).yaxis].min; @@ -986,9 +1039,12 @@ void LogsDialog::plotLogs() removeAllGraphs(); axisRect->axis(QCPAxis::atBottom)->setRange(plots.min_x, plots.max_x); - - axisRect->axis(QCPAxis::atLeft)->setRange(yAxesRanges[firstLeft].min, - yAxesRanges[firstLeft].max); + if (useCommonAxes) { + auto [min, max] = this->GetMinMaxY(); + axisRect->axis(QCPAxis::atLeft)->setRange(min, max); + } else { + axisRect->axis(QCPAxis::atLeft)->setRange(yAxesRanges[firstLeft].min, yAxesRanges[firstLeft].max); + } if (plots.tooManyRanges) { axisRect->axis(QCPAxis::atLeft)->setTickLabels(false); diff --git a/companion/src/logsdialog.h b/companion/src/logsdialog.h index 3ac9495ac..1772c09da 100644 --- a/companion/src/logsdialog.h +++ b/companion/src/logsdialog.h @@ -82,6 +82,7 @@ private slots: void sessionsCurrentIndexChanged(int index); void mapsButtonClicked(); void yAxisChangeRanges(QCPRange range); + std::pair GetMinMaxY() const; private: QList csvlog; diff --git a/companion/src/logsdialog.ui b/companion/src/logsdialog.ui index 2f47a9cc6..9fc2232a5 100644 --- a/companion/src/logsdialog.ui +++ b/companion/src/logsdialog.ui @@ -167,7 +167,36 @@ - + + + + + 10 + 0 + + + + + 10 + 20 + + + + + 0 + 0 + + + + + + + + Use common Y axis + + + + Reset @@ -341,6 +370,7 @@ mapsButton ZoomX_ChkB ZoomY_ChkB + CommonAxes_ChkB Reset_PB sessions_CB diff --git a/companion/src/translations/companion_cs.ts b/companion/src/translations/companion_cs.ts index b284c3cbc..b15d04eba 100644 --- a/companion/src/translations/companion_cs.ts +++ b/companion/src/translations/companion_cs.ts @@ -6967,12 +6967,17 @@ Are you sure ? Prohlížeč logu - + + Use common Y axis + Použít společnou osu Y + + + Filename Soubor - + Open LogFile Otevřít diff --git a/companion/src/translations/companion_da.ts b/companion/src/translations/companion_da.ts index 47a9600d4..7a1c707a5 100644 --- a/companion/src/translations/companion_da.ts +++ b/companion/src/translations/companion_da.ts @@ -7035,12 +7035,17 @@ Er du sikker? Companion log viser - + + Use common Y axis + Brug fælles Y-akse + + + Filename Filnavn - + Open LogFile Åbn logfil diff --git a/companion/src/translations/companion_de.ts b/companion/src/translations/companion_de.ts index 82a8b410c..04e4a4e17 100644 --- a/companion/src/translations/companion_de.ts +++ b/companion/src/translations/companion_de.ts @@ -6967,12 +6967,17 @@ Sind Sie sicher? Companion Log ansehen - + + Use common Y axis + Gemeinsame Y-Achse verwenden + + + Filename Dateiname - + Open LogFile Öffne LogDatei diff --git a/companion/src/translations/companion_en.ts b/companion/src/translations/companion_en.ts index 37cc56cd6..f9262663e 100644 --- a/companion/src/translations/companion_en.ts +++ b/companion/src/translations/companion_en.ts @@ -6921,12 +6921,17 @@ Are you sure ? - + + Use common Y axis + + + + Filename - + Open LogFile diff --git a/companion/src/translations/companion_es.ts b/companion/src/translations/companion_es.ts index bd0c37831..511e3e602 100644 --- a/companion/src/translations/companion_es.ts +++ b/companion/src/translations/companion_es.ts @@ -7032,12 +7032,17 @@ Esta función no puede ser deshabilitada en la radio. Visor de registros de Companion - + + Use common Y axis + Usar eje Y común + + + Filename Nombre archivo - + Open LogFile Abrir archivo registros diff --git a/companion/src/translations/companion_fi.ts b/companion/src/translations/companion_fi.ts index fa136dd83..25c08b416 100644 --- a/companion/src/translations/companion_fi.ts +++ b/companion/src/translations/companion_fi.ts @@ -7020,12 +7020,17 @@ Are you sure ? Companion logit - + + Use common Y axis + Käytä yhteistä Y-akselia + + + Filename Tiedoston nimi - + Open LogFile Avaa logi diff --git a/companion/src/translations/companion_fr.ts b/companion/src/translations/companion_fr.ts index 45ac06630..2d5754abf 100644 --- a/companion/src/translations/companion_fr.ts +++ b/companion/src/translations/companion_fr.ts @@ -7025,12 +7025,17 @@ Cette fonction ne peut pas être désactivée sur la radio. Visualiseur de Log - + + Use common Y axis + Utiliser un axe Y commun + + + Filename Nom de fichier - + Open LogFile Ouvrir fichier de Log diff --git a/companion/src/translations/companion_he.ts b/companion/src/translations/companion_he.ts index 98272374b..83985829f 100644 --- a/companion/src/translations/companion_he.ts +++ b/companion/src/translations/companion_he.ts @@ -6891,12 +6891,17 @@ Are you sure ? - + + Use common Y axis + השתמש בציר Y משותף + + + Filename - + Open LogFile diff --git a/companion/src/translations/companion_it.ts b/companion/src/translations/companion_it.ts index 2fddbb904..864cfc6bc 100644 --- a/companion/src/translations/companion_it.ts +++ b/companion/src/translations/companion_it.ts @@ -7015,12 +7015,17 @@ Are you sure ? Visualizzatore di Log di Companion - + + Use common Y axis + Usa l’asse Y comune + + + Filename Nome file - + Open LogFile Apri file di log diff --git a/companion/src/translations/companion_ja.ts b/companion/src/translations/companion_ja.ts index 762e42059..03da59763 100644 --- a/companion/src/translations/companion_ja.ts +++ b/companion/src/translations/companion_ja.ts @@ -7046,14 +7046,19 @@ Are you sure ? Reset リセット + + + + Use common Y axis + 共通の Y 軸を使用する - + Filename ファイル名 - + Open LogFile ログファイルを開く diff --git a/companion/src/translations/companion_ko.ts b/companion/src/translations/companion_ko.ts index 0281bc2c8..bfef45590 100644 --- a/companion/src/translations/companion_ko.ts +++ b/companion/src/translations/companion_ko.ts @@ -7053,14 +7053,19 @@ Are you sure ? Reset 초기화 + + + + Use common Y axis + 공통 Y축 사용 - + Filename 파일 이름 - + Open LogFile 로그 파일 열기 diff --git a/companion/src/translations/companion_nl.ts b/companion/src/translations/companion_nl.ts index 820b96c78..e94c72859 100644 --- a/companion/src/translations/companion_nl.ts +++ b/companion/src/translations/companion_nl.ts @@ -6891,12 +6891,17 @@ Are you sure ? - + + Use common Y axis + Gemeenschappelijke Y-as gebruiken + + + Filename - + Open LogFile diff --git a/companion/src/translations/companion_pl.ts b/companion/src/translations/companion_pl.ts index a8d851b07..114ae1d07 100644 --- a/companion/src/translations/companion_pl.ts +++ b/companion/src/translations/companion_pl.ts @@ -6998,12 +6998,17 @@ Are you sure ? Companion przegląd logów - + + Use common Y axis + Użyj wspólnej osi Y + + + Filename Nazwa pliku - + Open LogFile Otwórz plik logów diff --git a/companion/src/translations/companion_pt.ts b/companion/src/translations/companion_pt.ts index f8088c10f..235e0a3bb 100644 --- a/companion/src/translations/companion_pt.ts +++ b/companion/src/translations/companion_pt.ts @@ -6891,12 +6891,17 @@ Are you sure ? - + + Use common Y axis + Usar eixo Y comum + + + Filename - + Open LogFile diff --git a/companion/src/translations/companion_sv.ts b/companion/src/translations/companion_sv.ts index 79eadf752..bae0683b0 100644 --- a/companion/src/translations/companion_sv.ts +++ b/companion/src/translations/companion_sv.ts @@ -7092,12 +7092,17 @@ att fungera. Detta går inte att ändra från radion. Companion loggläsare - + + Use common Y axis + Använd gemensam Y-axel + + + Filename Filnamn - + Open LogFile Öppna loggfil diff --git a/companion/src/translations/companion_zh_CN.ts b/companion/src/translations/companion_zh_CN.ts index 163a26252..a3148a51e 100644 --- a/companion/src/translations/companion_zh_CN.ts +++ b/companion/src/translations/companion_zh_CN.ts @@ -7110,12 +7110,12 @@ Are you sure ? 重设 - + Filename 文件名 - + Open LogFile 打开 Log 文件 diff --git a/companion/src/translations/companion_zh_TW.ts b/companion/src/translations/companion_zh_TW.ts index 7379e5e0b..ef35292cb 100644 --- a/companion/src/translations/companion_zh_TW.ts +++ b/companion/src/translations/companion_zh_TW.ts @@ -7108,14 +7108,19 @@ Are you sure ? Reset 重設 + + + + Use common Y axis + 使用共同的 Y 軸 - + Filename 文件名 - + Open LogFile 打開 Log 文件