From 2fe03802cf9934d81593ea5be09ad032fd51c9ca Mon Sep 17 00:00:00 2001 From: Jussi Kuokkanen Date: Mon, 11 Dec 2023 15:06:44 +0200 Subject: [PATCH] show two decimals for readables in DeviceModel --- src/tuxclocker-qt/data/DeviceModel.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/tuxclocker-qt/data/DeviceModel.cpp b/src/tuxclocker-qt/data/DeviceModel.cpp index 3c61c42..17a9ad2 100644 --- a/src/tuxclocker-qt/data/DeviceModel.cpp +++ b/src/tuxclocker-qt/data/DeviceModel.cpp @@ -344,10 +344,16 @@ template void updateReadItemText(QStandardItem *item, T value, std::optional unit) { // TODO: this can be made a lot (around 3x) faster by using direct copying // Form a string of the form "1000 MHz" if has unit - auto text = (unit.has_value()) ? QString("%1 %2").arg(value).arg(unit.value()) - : QString("%1").arg(value); + QString valueText; + if (std::is_same()) + // Show two decimals + valueText = QString{"%1"}.arg(static_cast(value), 0, 'f', 2); + else + valueText = QString{"%1"}.arg(value); + + auto text = (unit.has_value()) ? QString("%1 %2").arg(valueText).arg(unit.value()) + : QString("%1").arg(valueText); item->setText(text); - // qDebug() << item->data(DeviceModel::DynamicReadableProxyRole); } std::optional DeviceModel::setupDynReadable(