File indexing completed on 2024-05-19 05:06:50

0001 /*
0002     SPDX-FileCopyrightText: 2004-2021 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KCURRENCYCALCULATOR_H
0008 #define KCURRENCYCALCULATOR_H
0009 
0010 #include "kmm_base_dialogs_export.h"
0011 
0012 // ----------------------------------------------------------------------------
0013 // QT Includes
0014 
0015 #include <QDialog>
0016 
0017 // ----------------------------------------------------------------------------
0018 // KDE Includes
0019 
0020 // ----------------------------------------------------------------------------
0021 // Project Includes
0022 
0023 class QDate;
0024 
0025 class MyMoneyMoney;
0026 class MyMoneySplit;
0027 class MyMoneyTransaction;
0028 class MyMoneySecurity;
0029 class MultiCurrencyEdit;
0030 
0031 namespace Ui {
0032 class KCurrencyCalculator;
0033 }
0034 
0035 typedef qint64 signed64;
0036 
0037 /**
0038   * @author Thomas Baumgart
0039   */
0040 
0041 class KCurrencyCalculatorPrivate;
0042 class KMM_BASE_DIALOGS_EXPORT KCurrencyCalculator : public QDialog
0043 {
0044     Q_OBJECT
0045     Q_DISABLE_COPY(KCurrencyCalculator)
0046 
0047 public:
0048     explicit KCurrencyCalculator(QWidget* parent = nullptr);
0049 
0050     /**
0051       * @param from the @p from currency
0052       * @param to   the @p to currency
0053       * @param value the value to be converted
0054       * @param shares the number of foreign currency units
0055       * @param date the date when the conversion took place
0056       * @param resultFraction the smallest fraction of the result (default 100)
0057       * @param parent see QWidget constructor
0058       *
0059       * @note @p value must not be 0!
0060       */
0061     KCurrencyCalculator(const MyMoneySecurity& from,
0062                         const MyMoneySecurity& to,
0063                         const MyMoneyMoney& value,
0064                         const MyMoneyMoney& shares,
0065                         const QDate& date,
0066                         const signed64 resultFraction = 100,
0067                         QWidget* parent = nullptr);
0068 
0069     ~KCurrencyCalculator();
0070 
0071     /**
0072      * This method returns the price determined by the method selected by the user
0073      * which is either
0074      *
0075      * a) based on the resulting amount or
0076      * b) based on direct price entry.
0077      *
0078      * In case a) the price is returned without precision loss as the division
0079      * of the amount entered by the user and the @a value passed as argument.
0080      * In case b) it is returned with the selected global price precision.
0081      */
0082     MyMoneyMoney price() const;
0083 
0084     void setupPriceEditor();
0085 
0086     static bool setupSplitPrice(MyMoneyMoney& shares,
0087                                 const MyMoneyTransaction& t,
0088                                 const MyMoneySplit& s,
0089                                 const QMap<QString,
0090                                 MyMoneyMoney>& priceInfo,
0091                                 QWidget* parentWidget);
0092 
0093     void setFromCurrency(const MyMoneySecurity& sec);
0094     void setToCurrency(const MyMoneySecurity& sec);
0095     void setFromAmount(const MyMoneyMoney& amount);
0096     void setToAmount(const MyMoneyMoney& amount);
0097     void setDate(const QDate& date);
0098     void setResultFraction(signed64 fraction);
0099 
0100     /**
0101      * This method asks the user for exchange rate information
0102      * according to the data found in the @a amountEdit widget.
0103      * In case the two commodities in @a amountEdit are identical
0104      * the method returns immediately.
0105      */
0106     static void updateConversion(MultiCurrencyEdit* amountEdit, const QDate date);
0107 
0108 protected Q_SLOTS:
0109     void slotSetToAmount();
0110     void slotSetExchangeRate();
0111     void slotUpdateResult(const QString& txt);
0112     void slotUpdateRate(const QString& txt);
0113     void accept() override;
0114 
0115 private:
0116     KCurrencyCalculatorPrivate * const d_ptr;
0117     Q_DECLARE_PRIVATE(KCurrencyCalculator)
0118 };
0119 
0120 #endif