https://bugs.kde.org/show_bug.cgi?id=427795
--- Comment #2 from Sébastien P. <[email protected]> --- Created attachment 135334 --> https://bugs.kde.org/attachment.cgi?id=135334&action=edit A very dirty fix I tried to analyze a bit. Without the knowledge of Qt/C++… a bit difficult^^. It looks like new grid system use a Unit not listed in Formatter::formatValue cases. So it goes to default one “value.toString();” (Formatter.cpp line 319 in master branch). => So I change the default to use formatNumber function. I do not know the impacts… but works fine for me. => It looks like also that the grid value is not a QVariant double. So, I add a dirty parameter (I did not find where I can change the type properly…) With my usage of applets. Only load average and disk usage are affect by that. diff --git a/formatter/Formatter.cpp b/formatter/Formatter.cpp index 29ef6a6..17d8d6d 100644 --- a/formatter/Formatter.cpp +++ b/formatter/Formatter.cpp @@ -233,7 +233,7 @@ static Unit adjustedUnit(qreal value, Unit unit, MetricPrefix prefix) return Unit(prefix + baseUnit); } -static QString formatNumber(const QVariant &value, Unit unit, MetricPrefix prefix, FormatOptions options) +static QString formatNumber(const QVariant &value, Unit unit, MetricPrefix prefix, FormatOptions options, bool forceDouble) { qreal amount = value.toDouble(); @@ -246,7 +246,7 @@ static QString formatNumber(const QVariant &value, Unit unit, MetricPrefix prefi amount /= std::pow(unitOrder(unit), adjusted - unit); } - const int precision = (value.type() != QVariant::Double && adjusted <= unit) ? 0 : 1; + const int precision = (value.type() != QVariant::Double && adjusted <= unit && !forceDouble) ? 0 : 1; const QString text = QLocale().toString(amount, 'f', precision); return unitFormat(adjusted).subs(text).toString(); @@ -307,7 +307,7 @@ QString Formatter::formatValue(const QVariant &value, Unit unit, MetricPrefix ta case UnitVolt: case UnitWatt: case UnitSecond: - return formatNumber(value, unit, targetPrefix, options); + return formatNumber(value, unit, targetPrefix, options, false); case UnitBootTimestamp: qCWarning(FORMATTER) << "UnitBootTimestamp is deprecated and is not formatted anymore"; @@ -316,7 +316,7 @@ QString Formatter::formatValue(const QVariant &value, Unit unit, MetricPrefix ta return formatTime(value); default: - return value.toString(); + return formatNumber(value, unit, targetPrefix, options, true); } } -- You are receiving this mail because: You are watching all bug changes.
