1/*
2 * SPDX-FileCopyrightText: 2007-2009 Petri Damstén <damu@iki.fi>
3 * SPDX-FileCopyrightText: 2014 John Layt <jlayt@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#ifndef KUNITCONVERSION_UNITCATEGORY_P_H
9#define KUNITCONVERSION_UNITCATEGORY_P_H
10
11#include "unitcategory.h"
12
13#include <KLocalizedString>
14
15#include <QMap>
16
17class QNetworkAccessManager;
18
19namespace KUnitConversion
20{
21class UnitCategoryPrivate : public QSharedData
22{
23public:
24 UnitCategoryPrivate();
25 UnitCategoryPrivate(CategoryId id, const QString &name, const QString &description);
26 virtual ~UnitCategoryPrivate();
27
28 UnitCategoryPrivate *clone();
29 bool operator==(const UnitCategoryPrivate &other) const;
30 bool operator!=(const UnitCategoryPrivate &other) const;
31
32 virtual Value convert(const Value &value, const Unit &toUnit);
33
34 virtual bool hasOnlineConversionTable() const
35 {
36 return false;
37 }
38
39 virtual UpdateJob* syncConversionTable(std::chrono::seconds updateSkipPeriod)
40 {
41 Q_UNUSED(updateSkipPeriod)
42 return nullptr;
43 }
44
45 void addDefaultUnit(const Unit &unit);
46 void addCommonUnit(const Unit &unit);
47 void addUnit(const Unit &unit);
48
49 static inline UnitCategoryPrivate* get(const UnitCategory &category)
50 {
51 return category.d.data();
52 }
53
54 static inline UnitCategory makeCategory(CategoryId id, const QString &name, const QString &description)
55 {
56 return UnitCategory(new UnitCategoryPrivate(id, name, description));
57 }
58 static inline UnitCategory makeCategory(UnitCategoryPrivate *dd)
59 {
60 return UnitCategory(dd);
61 }
62
63 static inline UpdateJob* makeUpdateJob(QNetworkReply *reply)
64 {
65 return new UpdateJob(reply);
66 }
67
68 /** Network access manager to use for online updates.
69 * @see syncConversionTable
70 */
71 static QNetworkAccessManager* nam();
72
73 CategoryId m_id;
74 QString m_name;
75 QString m_description;
76 KLocalizedString m_symbolStringFormat;
77 Unit m_defaultUnit;
78 QMap<QString, Unit> m_unitMap;
79 QMap<UnitId, Unit> m_idMap;
80 QList<Unit> m_units;
81 QList<Unit> m_mostCommonUnits;
82};
83
84} // KUnitConversion namespace
85
86#endif // KUNITCONVERSION_UNITCATEGORY_P_H
87

source code of kunitconversion/src/unitcategory_p.h