# HG changeset patch # User Michiel Broek # Date 1676206716 -3600 # Node ID 49ac23d25f61d1fed67cfbdb49b51554c1b03d51 # Parent 520306773450d16d57aa729a28e1d43652bc6e44 In monitor iSpindel: in the chart calculate the ranges, do't let the toolkit do that. Save the path for chart image download in the user settings. In the tooltip for the battery voltage line, also show the remaining battery capacity. In the monitor window show the battery capacity digit instead of allways 0. Updated the translations. diff -r 520306773450 -r 49ac23d25f61 src/ChartiSpindel.cpp --- a/src/ChartiSpindel.cpp Sat Feb 11 15:48:02 2023 +0100 +++ b/src/ChartiSpindel.cpp Sun Feb 12 13:58:36 2023 +0100 @@ -23,6 +23,9 @@ { QSqlQuery query; double timestamp; + double sg_min = 1.2, sg_max = 0.8, sg; + double temp_min = 100, temp_max = 0, temp; + double batt_min = 4.5, batt_max = 3.0, batt; qDebug() << "ChartiSpindel:" << code << name; @@ -53,9 +56,28 @@ query.exec(); while (query.next()) { timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000; - temperature->append(timestamp, query.value("temperature").toDouble()); - density->append(timestamp, query.value("sg").toDouble()); - battery ->append(timestamp, round(query.value("battery").toDouble() * 500) / 500); + + sg = query.value("sg").toDouble(); + if ((ceil(sg * 100) / 100) > sg_max) + sg_max = ceil(sg * 100) / 100; + if ((floor(sg * 100) / 100) < sg_min) + sg_min = floor(sg * 100) / 100; + + temp = query.value("temperature").toDouble(); + if (ceil(temp) > temp_max) + temp_max = ceil(temp); + if (floor(temp) < temp_min) + temp_min = floor(temp); + + batt = round(query.value("battery").toDouble() * 500) / 500; + if ((ceil(batt * 10) / 10) > batt_max) + batt_max = ceil(batt * 10) / 10; + if ((floor(batt * 10) / 10) < batt_min) + batt_min = floor(batt * 10) / 10; + + temperature->append(timestamp, temp); + density->append(timestamp, sg); + battery ->append(timestamp, batt); } temperature->setName(tr("Temperature")); @@ -84,6 +106,7 @@ density->attachAxis(axisX); QValueAxis *axisYT = new QValueAxis; + axisYT->setRange(temp_min, temp_max); axisYT->setTickCount(10); axisYT->setLabelFormat("%.1f"); axisYT->setTitleText(tr("Temperature °C")); @@ -92,6 +115,7 @@ temperature->attachAxis(axisYT); QValueAxis *axisYD = new QValueAxis; + axisYD->setRange(sg_min, sg_max); axisYD->setTickCount(10); axisYD->setLabelFormat("%.3f"); axisYD->setTitleText("SG"); @@ -100,6 +124,7 @@ density->attachAxis(axisYD); QValueAxis *axisYB = new QValueAxis; + axisYB->setRange(batt_min, batt_max); axisYB->setTickCount(10); axisYB->setLabelFormat("%.2f"); axisYB->setTitleText(tr("Battery volt")); @@ -131,12 +156,30 @@ void ChartiSpindel::savePNG() { - QString path = QFileDialog::getSaveFileName(this, tr("Save Image"), QDir::homePath() + "/ispindel.png", tr("Image (*.png)")); + QSettings settings(QSettings::IniFormat, QSettings::UserScope, "mbse", "bmsapp"); + QString dirName; + + /* + * First check if the directory stored in the settings file exists. + * It might be on a removable media that was last used ... + * If so, fallback to the user's home directory. + */ + dirName = settings.value("paths/download").toString(); + if (! QDir(dirName).exists()) { + dirName = QDir::homePath(); + } + + QString path = QFileDialog::getSaveFileName(this, tr("Save Image"), dirName + "/ispindel.png", tr("Image (*.png)")); if (path.isEmpty()) { QMessageBox::warning(this, tr("Save File"), tr("No image file selected.")); return; } + /* + * Update to current selected path + */ + settings.setValue("paths/download", QFileInfo(path).absolutePath()); + QImage img((chartView->size()), QImage::Format_ARGB32); QPainter painter; painter.begin(&img); @@ -161,8 +204,16 @@ t_tooltip->setText(QString(tr("%1\nTemperature %2°C")).arg(timeis.toString("dd-MM-yyyy hh:mm")).arg(point.y(), 2, 'f', 1)); else if (series == density) t_tooltip->setText(QString(tr("%1\nDensity %2 SG")).arg(timeis.toString("dd-MM-yyyy hh:mm")).arg(point.y(), 5, 'f', 4)); - else if (series == battery) - t_tooltip->setText(QString(tr("%1\nBattery %2 volt")).arg(timeis.toString("dd-MM-yyyy hh:mm")).arg(point.y(), 3, 'f', 2)); + else if (series == battery) { + double batt = point.y() - 3.064; /* 0% */ + if (batt < 0) + batt = 0; + batt = round(batt / 1.17875 * 1000.0) / 10; /* 100% range */ + if (batt > 100) + batt = 100; + t_tooltip->setText(QString(tr("%1\nBattery %2 volt\nCapacity %3%")).arg(timeis.toString("dd-MM-yyyy hh:mm")) + .arg(point.y(), 3, 'f', 2).arg(batt, 2, 'f', 1, '0')); + } t_tooltip->setAnchor(point); t_tooltip->setZValue(11); t_tooltip->updateGeometry(); diff -r 520306773450 -r 49ac23d25f61 src/DetailiSpindel.cpp --- a/src/DetailiSpindel.cpp Sat Feb 11 15:48:02 2023 +0100 +++ b/src/DetailiSpindel.cpp Sun Feb 12 13:58:36 2023 +0100 @@ -65,8 +65,6 @@ { QSqlQuery query; - qDebug() << "DetailiSpindel::refreshTable()"; - query.prepare("SELECT * FROM mon_ispindels WHERE record = :recno"); query.bindValue(":recno", this->recno); query.exec(); @@ -145,7 +143,7 @@ double batt = query.value("battery").toDouble() - 3.064; // 0% voltage if (batt < 0) batt = 0; - batt = round(batt / 1.17875 * 100.0); // 100% range + batt = round(batt / 1.17875 * 1000.0) / 10; // 100% range if (batt > 100) batt = 100; ui->batVal->setText(QString("%1%").arg(batt, 2, 'f', 1, '0')); diff -r 520306773450 -r 49ac23d25f61 translations/bmsapp_en.ts --- a/translations/bmsapp_en.ts Sat Feb 11 15:48:02 2023 +0100 +++ b/translations/bmsapp_en.ts Sun Feb 12 13:58:36 2023 +0100 @@ -163,81 +163,82 @@ ChartiSpindel - + BMSapp - iSpindel - + Save - + Temperature - + SG - - Battery - - - - - Date - - - + Battery + + + + + Date + + + + Temperature °C - + Battery volt - + Save Image - + Image (*.png) - + Save File - + No image file selected. - + %1 Temperature %2°C - + %1 Density %2 SG - + %1 -Battery %2 volt +Battery %2 volt +Capacity %3% @@ -1001,12 +1002,12 @@ - + Online - + Offline diff -r 520306773450 -r 49ac23d25f61 translations/bmsapp_nl.ts --- a/translations/bmsapp_nl.ts Sat Feb 11 15:48:02 2023 +0100 +++ b/translations/bmsapp_nl.ts Sun Feb 12 13:58:36 2023 +0100 @@ -193,7 +193,7 @@ ChartiSpindel - + BMSapp - iSpindel BMSapp - iSpindel @@ -202,79 +202,87 @@ Temp °C - + Save Bewaar - + Temperature Temperatuur - + SG SG - - Battery - Batterij - - - - Date - Datum - - + Battery + Batterij + + + + Date + Datum + + + Temperature °C Temperatuur °C - + Battery volt Batterij volt - + Save Image Opslaan plaatje - + Image (*.png) Plaatje (*.png) - + Save File Bestand opslaan - + No image file selected. Geen plaatjes bestand gekozen. - + %1 Temperature %2°C %1 Temperatuur %2°C - + %1 Density %2 SG %1 Dichtheid %2 SG - + + %1 +Battery %2 volt +Capacity %3% + %1 +Batterij %2 volt +Capaciteit %3% + + %1 Battery %2 volt - %1 + %1 Batterij %2 volt @@ -1078,12 +1086,12 @@ BMSapp - Detail iSpindel - + Online Online - + Offline Offline diff -r 520306773450 -r 49ac23d25f61 ui/DetailiSpindel.ui --- a/ui/DetailiSpindel.ui Sat Feb 11 15:48:02 2023 +0100 +++ b/ui/DetailiSpindel.ui Sun Feb 12 13:58:36 2023 +0100 @@ -509,7 +509,7 @@ 740 130 261 - 291 + 281 @@ -675,16 +675,16 @@ 740 - 430 + 420 261 - 101 + 111 90 - 60 + 70 80 23