Templatize localizeNumbers (#4412)

original idea by MM2PL
This commit is contained in:
pajlada 2023-02-25 12:44:45 +01:00 committed by GitHub
parent 4923549fdf
commit f9b23882f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 21 deletions

View file

@ -162,24 +162,6 @@ QString shortenString(const QString &str, unsigned maxWidth)
return shortened; return shortened;
} }
QString localizeNumbers(const int &number)
{
QLocale locale;
return locale.toString(number);
}
QString localizeNumbers(unsigned int number)
{
QLocale locale;
return locale.toString(number);
}
QString localizeNumbers(qsizetype number)
{
QLocale locale;
return locale.toString(number);
}
QString kFormatNumbers(const int &number) QString kFormatNumbers(const int &number)
{ {
return QString("%1K").arg(number / 1000); return QString("%1K").arg(number / 1000);

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <QColor> #include <QColor>
#include <QLocale>
#include <QString> #include <QString>
#include <QStringRef> #include <QStringRef>
@ -72,9 +73,12 @@ QString formatRichNamedLink(const QString &url, const QString &name,
QString shortenString(const QString &str, unsigned maxWidth = 50); QString shortenString(const QString &str, unsigned maxWidth = 50);
QString localizeNumbers(const int &number); template <typename T>
QString localizeNumbers(unsigned int number); QString localizeNumbers(T number)
QString localizeNumbers(qsizetype number); {
QLocale locale;
return locale.toString(number);
}
QString kFormatNumbers(const int &number); QString kFormatNumbers(const int &number);