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.

Sun, 12 Feb 2023 13:58:36 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 12 Feb 2023 13:58:36 +0100
changeset 494
49ac23d25f61
parent 493
520306773450
child 495
6aa29aaa3f4d

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.

src/ChartiSpindel.cpp file | annotate | diff | comparison | revisions
src/DetailiSpindel.cpp file | annotate | diff | comparison | revisions
translations/bmsapp_en.ts file | annotate | diff | comparison | revisions
translations/bmsapp_nl.ts file | annotate | diff | comparison | revisions
ui/DetailiSpindel.ui file | annotate | diff | comparison | revisions
--- 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();
--- 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'));
--- 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 @@
 <context>
     <name>ChartiSpindel</name>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="30"/>
+        <location filename="../src/ChartiSpindel.cpp" line="33"/>
         <source>BMSapp - iSpindel </source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="35"/>
+        <location filename="../src/ChartiSpindel.cpp" line="38"/>
         <source>Save</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="61"/>
+        <location filename="../src/ChartiSpindel.cpp" line="83"/>
         <source>Temperature</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="63"/>
+        <location filename="../src/ChartiSpindel.cpp" line="85"/>
         <source>SG</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="67"/>
-        <source>Battery</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../src/ChartiSpindel.cpp" line="79"/>
-        <source>Date</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
         <location filename="../src/ChartiSpindel.cpp" line="89"/>
+        <source>Battery</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../src/ChartiSpindel.cpp" line="101"/>
+        <source>Date</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../src/ChartiSpindel.cpp" line="112"/>
         <source>Temperature °C</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="105"/>
+        <location filename="../src/ChartiSpindel.cpp" line="130"/>
         <source>Battery volt</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="134"/>
+        <location filename="../src/ChartiSpindel.cpp" line="172"/>
         <source>Save Image</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="134"/>
+        <location filename="../src/ChartiSpindel.cpp" line="172"/>
         <source>Image (*.png)</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="136"/>
+        <location filename="../src/ChartiSpindel.cpp" line="174"/>
         <source>Save File</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="136"/>
+        <location filename="../src/ChartiSpindel.cpp" line="174"/>
         <source>No image file selected.</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="161"/>
+        <location filename="../src/ChartiSpindel.cpp" line="204"/>
         <source>%1
 Temperature %2°C</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="163"/>
+        <location filename="../src/ChartiSpindel.cpp" line="206"/>
         <source>%1
 Density %2 SG</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="165"/>
+        <location filename="../src/ChartiSpindel.cpp" line="214"/>
         <source>%1
-Battery %2 volt</source>
+Battery %2 volt
+Capacity %3%</source>
         <translation type="unfinished"></translation>
     </message>
 </context>
@@ -1001,12 +1002,12 @@
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/DetailiSpindel.cpp" line="96"/>
+        <location filename="../src/DetailiSpindel.cpp" line="92"/>
         <source>Online</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/DetailiSpindel.cpp" line="160"/>
+        <location filename="../src/DetailiSpindel.cpp" line="156"/>
         <source>Offline</source>
         <translation type="unfinished"></translation>
     </message>
--- 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 @@
 <context>
     <name>ChartiSpindel</name>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="30"/>
+        <location filename="../src/ChartiSpindel.cpp" line="33"/>
         <source>BMSapp - iSpindel </source>
         <translation>BMSapp - iSpindel </translation>
     </message>
@@ -202,79 +202,87 @@
         <translation type="vanished">Temp °C</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="35"/>
+        <location filename="../src/ChartiSpindel.cpp" line="38"/>
         <source>Save</source>
         <translation>Bewaar</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="61"/>
+        <location filename="../src/ChartiSpindel.cpp" line="83"/>
         <source>Temperature</source>
         <translation>Temperatuur</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="63"/>
+        <location filename="../src/ChartiSpindel.cpp" line="85"/>
         <source>SG</source>
         <translation>SG</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="67"/>
-        <source>Battery</source>
-        <translation>Batterij</translation>
-    </message>
-    <message>
-        <location filename="../src/ChartiSpindel.cpp" line="79"/>
-        <source>Date</source>
-        <translation>Datum</translation>
-    </message>
-    <message>
         <location filename="../src/ChartiSpindel.cpp" line="89"/>
+        <source>Battery</source>
+        <translation>Batterij</translation>
+    </message>
+    <message>
+        <location filename="../src/ChartiSpindel.cpp" line="101"/>
+        <source>Date</source>
+        <translation>Datum</translation>
+    </message>
+    <message>
+        <location filename="../src/ChartiSpindel.cpp" line="112"/>
         <source>Temperature °C</source>
         <translation>Temperatuur °C</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="105"/>
+        <location filename="../src/ChartiSpindel.cpp" line="130"/>
         <source>Battery volt</source>
         <translation>Batterij volt</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="134"/>
+        <location filename="../src/ChartiSpindel.cpp" line="172"/>
         <source>Save Image</source>
         <translation>Opslaan plaatje</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="134"/>
+        <location filename="../src/ChartiSpindel.cpp" line="172"/>
         <source>Image (*.png)</source>
         <translation>Plaatje (*.png)</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="136"/>
+        <location filename="../src/ChartiSpindel.cpp" line="174"/>
         <source>Save File</source>
         <translation>Bestand opslaan</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="136"/>
+        <location filename="../src/ChartiSpindel.cpp" line="174"/>
         <source>No image file selected.</source>
         <translation>Geen plaatjes bestand gekozen.</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="161"/>
+        <location filename="../src/ChartiSpindel.cpp" line="204"/>
         <source>%1
 Temperature %2°C</source>
         <translation>%1
 Temperatuur %2°C</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="163"/>
+        <location filename="../src/ChartiSpindel.cpp" line="206"/>
         <source>%1
 Density %2 SG</source>
         <translation>%1
 Dichtheid %2 SG</translation>
     </message>
     <message>
-        <location filename="../src/ChartiSpindel.cpp" line="165"/>
+        <location filename="../src/ChartiSpindel.cpp" line="214"/>
+        <source>%1
+Battery %2 volt
+Capacity %3%</source>
+        <translation>%1
+Batterij %2 volt
+Capaciteit %3%</translation>
+    </message>
+    <message>
         <source>%1
 Battery %2 volt</source>
-        <translation>%1
+        <translation type="vanished">%1
 Batterij %2 volt</translation>
     </message>
 </context>
@@ -1078,12 +1086,12 @@
         <translation>BMSapp - Detail iSpindel</translation>
     </message>
     <message>
-        <location filename="../src/DetailiSpindel.cpp" line="96"/>
+        <location filename="../src/DetailiSpindel.cpp" line="92"/>
         <source>Online</source>
         <translation>Online</translation>
     </message>
     <message>
-        <location filename="../src/DetailiSpindel.cpp" line="160"/>
+        <location filename="../src/DetailiSpindel.cpp" line="156"/>
         <source>Offline</source>
         <translation>Offline</translation>
     </message>
--- 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 @@
         <x>740</x>
         <y>130</y>
         <width>261</width>
-        <height>291</height>
+        <height>281</height>
        </rect>
       </property>
       <widget class="QLabel" name="progressLabel">
@@ -675,16 +675,16 @@
       <property name="geometry">
        <rect>
         <x>740</x>
-        <y>430</y>
+        <y>420</y>
         <width>261</width>
-        <height>101</height>
+        <height>111</height>
        </rect>
       </property>
       <widget class="QPushButton" name="quitButton">
        <property name="geometry">
         <rect>
          <x>90</x>
-         <y>60</y>
+         <y>70</y>
          <width>80</width>
          <height>23</height>
         </rect>

mercurial