feat(cpn): make it possible to use same scale in Log Viewer graph (#6818)
This commit is contained in:
@@ -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<double, double> 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<int> 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<int> 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);
|
||||
|
||||
Reference in New Issue
Block a user