From c257e458869e20e161f62b516278ad30ea9a2041 Mon Sep 17 00:00:00 2001 From: Spiros Date: Fri, 31 May 2024 20:20:16 +0300 Subject: [PATCH] Capitalize first letter --- mainwindow.cpp | 28 ++++++++++++++++++++++++++++ mainwindow.h | 1 + 2 files changed, 29 insertions(+) diff --git a/mainwindow.cpp b/mainwindow.cpp index e459bf0..f41c4c3 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -302,10 +302,14 @@ void MainWindow::addNvmeLogTable(const QJsonObject &nvmeLog) int row = 0; for (auto smartItem = nvmeLog.constBegin(); smartItem != nvmeLog.constEnd(); ++smartItem) { QString id = QString("%1").arg(row, 2, 16, QChar('0')).toUpper(); + QString name = smartItem.key().replace("_", " "); + name = toTitleCase(name); + QString raw = QString::number(smartItem.value().toInt()); raw = QString("%1").arg(raw.toUInt(nullptr), 14, 16, QChar('0')).toUpper(); + QColor statusColor; statusColor = Qt::green; // For now leave it all green @@ -436,3 +440,27 @@ QString MainWindow::getSmartctlOutput(const QStringList &arguments, bool root) process.waitForFinished(); return process.readAllStandardOutput(); } + + +QString MainWindow::toTitleCase(const QString& sentence) { + QString result; + bool capitalizeNext = true; + + for (const QChar& c : sentence) { + if (c.isLetter()) { + if (capitalizeNext) { + result += c.toUpper(); + capitalizeNext = false; + } else { + result += c.toLower(); + } + } else { + result += c; + if (c == ' ') { + capitalizeNext = true; + } + } + } + + return result; +} diff --git a/mainwindow.h b/mainwindow.h index 33059f8..1979ad5 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -43,5 +43,6 @@ private: void addNvmeLogTable(const QJsonObject &nvmeLog); void addSmartAttributesTable(const QJsonArray &attributes); QString getSmartctlOutput(const QStringList &arguments, bool root); + QString toTitleCase(const QString& sentence); }; #endif