File indexing completed on 2024-05-12 16:42:03

0001 /*
0002     SPDX-FileCopyrightText: 2004-2018 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 // ----------------------------------------------------------------------------
0011 // QT Includes
0012 
0013 #include <QDialog>
0014 
0015 // ----------------------------------------------------------------------------
0016 // KDE Includes
0017 
0018 // ----------------------------------------------------------------------------
0019 // Project Includes
0020 
0021 class QDate;
0022 
0023 class MyMoneyMoney;
0024 class MyMoneySplit;
0025 class MyMoneyTransaction;
0026 class MyMoneySecurity;
0027 
0028 namespace Ui {
0029 class KCurrencyCalculator;
0030 }
0031 
0032 typedef qint64 signed64;
0033 
0034 /**
0035   * @author Thomas Baumgart
0036   */
0037 
0038 class KCurrencyCalculatorPrivate;
0039 class KCurrencyCalculator : public QDialog
0040 {
0041     Q_OBJECT
0042     Q_DISABLE_COPY(KCurrencyCalculator)
0043 
0044 public:
0045     /**
0046       * @param from the @p from currency
0047       * @param to   the @p to currency
0048       * @param value the value to be converted
0049       * @param shares the number of foreign currency units
0050       * @param date the date when the conversion took place
0051       * @param resultFraction the smallest fraction of the result (default 100)
0052       * @param parent see QWidget constructor
0053       *
0054       * @note @p value must not be 0!
0055       */
0056     explicit KCurrencyCalculator(const MyMoneySecurity& from,
0057                                  const MyMoneySecurity& to,
0058                                  const MyMoneyMoney& value,
0059                                  const MyMoneyMoney& shares,
0060                                  const QDate& date,
0061                                  const signed64 resultFraction = 100,
0062                                  QWidget *parent = nullptr);
0063     ~KCurrencyCalculator();
0064 
0065     /**
0066      * This method returns the price determined by the method selected by the user
0067      * which is either
0068      *
0069      * a) based on the resulting amount or
0070      * b) based on direct price entry.
0071      *
0072      * In case a) the price is returned without precision loss as the division
0073      * of the amount entered by the user and the @a value passed as argument.
0074      * In case b) it is returned with the selected global price precision.
0075      */
0076     MyMoneyMoney price() const;
0077 
0078     void setupPriceEditor();
0079 
0080     static bool setupSplitPrice(MyMoneyMoney& shares,
0081                                 const MyMoneyTransaction& t,
0082                                 const MyMoneySplit& s,
0083                                 const QMap<QString,
0084                                 MyMoneyMoney>& priceInfo,
0085                                 QWidget* parentWidget);
0086 
0087 protected Q_SLOTS:
0088     void slotSetToAmount();
0089     void slotSetExchangeRate();
0090     void slotUpdateResult(const QString& txt);
0091     void slotUpdateRate(const QString& txt);
0092     void accept() override;
0093 
0094 private:
0095     KCurrencyCalculatorPrivate * const d_ptr;
0096     Q_DECLARE_PRIVATE(KCurrencyCalculator)
0097 };
0098 
0099 #endif