Commit 6d3527a3 authored by Adriaan de Groot's avatar Adriaan de Groot 💬 Committed by Arjen Hiemstra
Browse files

Fix tooltip display of double (float) values.

The port from KLocale -> QLocale left out the format-specifier
in the call to QLocale::toString(double, char, int), so we
ended up with the "precision" specifier as the char parameter --
speficying the format char. It looks like 0 (NUL) is interpreted
as 'f' on the Qt side, and precision is then 6.

The result was tooltip output like "31,405,564.000000 KiB"
which is nonsense -- there is no reason for six digits
of precision when displaying KiB until such a time as
micro-kibibytes ( 1/122 of a bit) are addressable.

Force format 'f' to avoid scientific notation, and
set precision to 0 for integer sensors, -1 (I assume that becomes
6 again internally in QLocale::toString()) otherwise.
The static_assert() is there as a reminder of which method
in QLocale should be called here.
parent b3ece5c0
......@@ -513,7 +513,8 @@ void FancyPlotter::setTooltip()
description = sensor->name();
if(sensor->isOk()) {
lastValue = QLocale().toString( sensor->lastValue, (sensor->isInteger)?0:-1 );
static_assert(std::is_same<double, decltype(sensor->lastValue)>::value, "Sensor values should be double");
lastValue = QLocale().toString( sensor->lastValue, 'f', (sensor->isInteger)?0:-1 );
if (sensor->unit() == QLatin1String("%"))
lastValue = i18nc("units", "%1%", lastValue);
else if( !sensor->unit().isEmpty() )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment