Commit 48f5eeff authored by Ismael Asensio's avatar Ismael Asensio Committed by Nate Graham
Browse files

[applets/weather] Use unit description from KUnitConversion

Summary:
Use unit description directly from KUnitConversion instead of making a new string.
This avoids duplicating translation strings and improves consistency.
The units name is now `description` (`symbol`) also for consistency with krunner

Test Plan:
No behavior changes within the applet
`Configure` -> `Units` shows translated `description` (`symbol`) for every unit

Reviewers: #plasma, ngraham

Reviewed By: ngraham

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24953
parent 4092da9d
......@@ -18,6 +18,8 @@
#ifndef ABSTRACTUNITLISTMODEL_H
#define ABSTRACTUNITLISTMODEL_H
#include "util.h"
#include <KUnitConversion/Unit>
#include <QAbstractListModel>
......@@ -27,7 +29,7 @@ class UnitItem
{
public:
UnitItem() {}
UnitItem(const QString &_name, KUnitConversion::UnitId _unitId) : name(_name), unitId(_unitId) {}
UnitItem(KUnitConversion::UnitId _unitId) : name(Util::nameFromUnitId(_unitId)), unitId(_unitId) {}
QString name;
KUnitConversion::UnitId unitId;
......
......@@ -34,9 +34,9 @@ static QObject* temperatureUnitListModelSingletonTypeProvider(QQmlEngine *engine
Q_UNUSED(scriptEngine)
QVector<UnitItem> items {
UnitItem(i18nc("@item", "Celsius \302\260C"), KUnitConversion::Celsius),
UnitItem(i18nc("@item", "Fahrenheit \302\260F"), KUnitConversion::Fahrenheit),
UnitItem(i18nc("@item", "Kelvin K"), KUnitConversion::Kelvin)
UnitItem(KUnitConversion::Celsius),
UnitItem(KUnitConversion::Fahrenheit),
UnitItem(KUnitConversion::Kelvin)
};
return new AbstractUnitListModel(items);
......@@ -48,11 +48,11 @@ static QObject* pressureUnitListModelSingletonTypeProvider(QQmlEngine *engine, Q
Q_UNUSED(scriptEngine)
QVector<UnitItem> items {
UnitItem(i18nc("@item", "Hectopascals hPa"), KUnitConversion::Hectopascal),
UnitItem(i18nc("@item", "Kilopascals kPa"), KUnitConversion::Kilopascal),
UnitItem(i18nc("@item", "Millibars mbar"), KUnitConversion::Millibar),
UnitItem(i18nc("@item", "Inches of Mercury inHg"), KUnitConversion::InchesOfMercury),
UnitItem(i18nc("@item", "Millimeters of Mercury mmHg"), KUnitConversion::MillimetersOfMercury)
UnitItem(KUnitConversion::Hectopascal),
UnitItem(KUnitConversion::Kilopascal),
UnitItem(KUnitConversion::Millibar),
UnitItem(KUnitConversion::InchesOfMercury),
UnitItem(KUnitConversion::MillimetersOfMercury)
};
return new AbstractUnitListModel(items);
......@@ -64,11 +64,11 @@ static QObject* windSpeedUnitListModelSingletonTypeProvider(QQmlEngine *engine,
Q_UNUSED(scriptEngine)
QVector<UnitItem> items {
UnitItem(i18nc("@item", "Meters per Second m/s"), KUnitConversion::MeterPerSecond),
UnitItem(i18nc("@item", "Kilometers per Hour km/h"), KUnitConversion::KilometerPerHour),
UnitItem(i18nc("@item", "Miles per Hour mph"), KUnitConversion::MilePerHour),
UnitItem(i18nc("@item", "Knots kt"), KUnitConversion::Knot),
UnitItem(i18nc("@item", "Beaufort scale bft"), KUnitConversion::Beaufort)
UnitItem(KUnitConversion::MeterPerSecond),
UnitItem(KUnitConversion::KilometerPerHour),
UnitItem(KUnitConversion::MilePerHour),
UnitItem(KUnitConversion::Knot),
UnitItem(KUnitConversion::Beaufort)
};
return new AbstractUnitListModel(items);
......@@ -80,8 +80,8 @@ static QObject* visibilityUnitListModelSingletonTypeProvider(QQmlEngine *engine,
Q_UNUSED(scriptEngine)
QVector<UnitItem> items {
UnitItem(i18nc("@item", "Kilometers"), KUnitConversion::Kilometer),
UnitItem(i18nc("@item", "Miles"), KUnitConversion::Mile)
UnitItem(KUnitConversion::Kilometer),
UnitItem(KUnitConversion::Mile)
};
return new AbstractUnitListModel(items);
......
......@@ -18,6 +18,7 @@
#include "util.h"
// KF
#include <KUnitConversion/Converter>
#include <KUnitConversion/Value>
#include <KLocalizedString>
// Qt
......@@ -40,6 +41,7 @@ Util::Util(QObject *parent)
{
}
KUnitConversion::Converter Util::m_converter;
QString Util::existingWeatherIconName(const QString &iconName) const
{
......@@ -81,3 +83,10 @@ QString Util::percentToDisplayString(double value) const
return i18nc("value percentsymbol", "%1 %", formattedPercentValue);
}
QString Util::nameFromUnitId(KUnitConversion::UnitId unitId)
{
const KUnitConversion::Unit unit = m_converter.unit(unitId);
QString unitDescription = i18nc("@item %1 is a unit description and %2 its unit symbol",
"%1 (%2)", unit.description(), unit.symbol());
return unitDescription;
}
......@@ -44,8 +44,10 @@ public:
int valueUnitType, int precision = 0) const;
Q_INVOKABLE QString percentToDisplayString(double value) const;
static QString nameFromUnitId(KUnitConversion::UnitId unitId);
private:
KUnitConversion::Converter m_converter;
static KUnitConversion::Converter m_converter;
};
#endif
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