File indexing completed on 2024-12-22 04:59:46

0001 /*
0002     SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #ifndef KITINERARY_PRICEUTIL_H
0007 #define KITINERARY_PRICEUTIL_H
0008 
0009 #include "kitinerary_export.h"
0010 
0011 #include <qobjectdefs.h>
0012 
0013 class QString;
0014 class QStringView;
0015 class QVariant;
0016 
0017 namespace KItinerary {
0018 
0019 /** Utilities for dealing with price/currency information of items. */
0020 class KITINERARY_EXPORT PriceUtil
0021 {
0022     Q_GADGET
0023 public:
0024     /** Returns @c true if @p item has valid price and currency information. */
0025     Q_INVOKABLE static bool hasPrice(const QVariant &item);
0026 
0027     /** Returns @c true if @p item can have price/currency information. */
0028     Q_INVOKABLE static bool canHavePrice(const QVariant &item);
0029 
0030     /** Returns the price value from @p item. */
0031     Q_INVOKABLE static double price(const QVariant &item);
0032     /** Returns the currency value from @p item. */
0033     Q_INVOKABLE static QString currency(const QVariant &item);
0034 
0035     /** Sets @p price and @p currency on @p item. */
0036     Q_INVOKABLE static void setPrice(QVariant &item, double price, const QString &currency);
0037 
0038     /** Returns the number of decimals to represent the sub-unit of @p currency.
0039      *  @param currency ISO 4217 currency code
0040      */
0041     // TODO this is rather material for KI18nLocaleData
0042     static int decimalCount(QStringView currency);
0043     Q_INVOKABLE static int decimalCount(const QString &currency); // QML doesn't support QStringView yet...
0044 
0045     // TODO add method for computing the total price of a set of items
0046 };
0047 
0048 }
0049 
0050 #endif