File indexing completed on 2024-05-19 05:08:36
0001 /* 0002 SPDX-FileCopyrightText: 2021 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef MULTICURRENCYEDIT_H 0007 #define MULTICURRENCYEDIT_H 0008 0009 #include "kmm_base_widgets_export.h" 0010 0011 // ---------------------------------------------------------------------------- 0012 // QT Includes 0013 0014 class QWidget; 0015 0016 // ---------------------------------------------------------------------------- 0017 // KDE Includes 0018 0019 // ---------------------------------------------------------------------------- 0020 // Project Includes 0021 0022 class MyMoneyMoney; 0023 class MyMoneySecurity; 0024 0025 class MultiCurrencyEdit 0026 { 0027 public: 0028 typedef enum { 0029 DisplayValue, 0030 DisplayShares, 0031 } DisplayState; 0032 0033 virtual ~MultiCurrencyEdit() = default; 0034 0035 /** 0036 * Use @a commodity for amounts in the value portion. 0037 */ 0038 virtual void setValueCommodity(const MyMoneySecurity& commodity) = 0; 0039 0040 /** 0041 * Returns the commodity used for amounts in the value portion. 0042 */ 0043 virtual MyMoneySecurity valueCommodity() const = 0; 0044 0045 /** 0046 * Use @a commodity for amounts in the shares portion. 0047 */ 0048 virtual void setSharesCommodity(const MyMoneySecurity& commodity) = 0; 0049 0050 /** 0051 * Returns the commodity used for amounts in the shares portion. 0052 */ 0053 virtual MyMoneySecurity sharesCommodity() const = 0; 0054 0055 /** 0056 * Use @a commodity for amounts in the values and shares portion. 0057 * This is a convenience method for single currency amounts 0058 */ 0059 virtual void setCommodity(const MyMoneySecurity& commodity) = 0; 0060 0061 /** 0062 * This returns the amount entered in the valueCommodity. 0063 */ 0064 virtual MyMoneyMoney value() const = 0; 0065 0066 /** 0067 * This returns the amount entered in the sharesCommodity. 0068 */ 0069 virtual MyMoneyMoney shares() const = 0; 0070 0071 /** 0072 * Sets the value portion to @a amount. 0073 * 0074 * @note This method does not Q_EMIT the amountChanged() signal 0075 */ 0076 virtual void setValue(const MyMoneyMoney& amount) = 0; 0077 0078 /** 0079 * Sets the shares portion to @a amount. 0080 * 0081 * @note This method does not Q_EMIT the amountChanged() signal 0082 */ 0083 virtual void setShares(const MyMoneyMoney& amount) = 0; 0084 0085 /** 0086 * Allows to setup an initial @a price for the two 0087 * selected currencies. The following equation is used 0088 * 0089 * value = shares * price 0090 */ 0091 virtual void setInitialExchangeRate(const MyMoneyMoney& price) = 0; 0092 0093 virtual MyMoneyMoney initialExchangeRate() const = 0; 0094 0095 /** 0096 * Returns a pointer to the edit widget 0097 */ 0098 virtual QWidget* widget() = 0; 0099 0100 /** 0101 * Sets the current display state of the widget to 0102 * be in @a state. 0103 */ 0104 virtual void setDisplayState(DisplayState state) = 0; 0105 0106 /** 0107 * Returns the current display state of the widget. 0108 * 0109 * @retval DisplayState::Value when display is showing amount in valueCommodity 0110 * @retval DisplayState::Shares when display is showing amount in sharesCommodity 0111 */ 0112 virtual DisplayState displayState() const = 0; 0113 0114 /** 0115 * Returns the precision in number of fraction digits for 0116 * the given display state passed in @a state. 0117 */ 0118 virtual int precision(DisplayState state) const = 0; 0119 0120 /** 0121 * Checks if multiple currencies are used. 0122 * 0123 * @retval false sharesCommodity and valueCommodity are identical 0124 * @retval true sharesCommodity and valueCommodity differ 0125 */ 0126 virtual bool hasMultipleCurrencies() const = 0; 0127 }; 0128 0129 #endif // MULTICURRENCYEDIT_H