File indexing completed on 2024-05-12 16:44:09

0001 /*
0002     SPDX-FileCopyrightText: 2006-2018 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef TRANSACTION_H
0008 #define TRANSACTION_H
0009 
0010 // ----------------------------------------------------------------------------
0011 // QT Includes
0012 
0013 #include <QWidgetList>
0014 
0015 // ----------------------------------------------------------------------------
0016 // KDE Includes
0017 
0018 // ----------------------------------------------------------------------------
0019 // Project Includes
0020 
0021 #include "registeritem.h"
0022 
0023 class QWidget;
0024 class QPalette;
0025 class QFontMetrics;
0026 class QTableWidget;
0027 class TransactionEditor;
0028 class TransactionEditorContainer;
0029 
0030 class MyMoneySplit;
0031 class MyMoneyTransaction;
0032 
0033 template <class Key, class Value> class QMap;
0034 
0035 namespace KMyMoneyTransactionForm {
0036 class TransactionForm;
0037 }
0038 namespace eWidgets {
0039 namespace eRegister {
0040 enum class Action;
0041 }
0042 }
0043 
0044 namespace KMyMoneyRegister
0045 {
0046 class SelectedTransactions;
0047 // keep the following list in sync with code in the constructor
0048 // of KMyMoneyRegister::Register in register.cpp
0049 
0050 class TransactionPrivate;
0051 class Transaction : public RegisterItem
0052 {
0053     Q_DISABLE_COPY(Transaction)
0054 
0055 public:
0056     explicit Transaction(Register* getParent, const MyMoneyTransaction& transaction, const MyMoneySplit& split, int uniqueId);
0057     virtual ~Transaction();
0058 
0059     virtual const char* className() override;
0060     bool isSelectable() const override;
0061     bool isSelected() const override;
0062     void setSelected(bool selected) override;
0063     bool canHaveFocus() const override;
0064     bool hasFocus() const override;
0065     bool hasEditorOpen() const override;
0066     virtual bool isScheduled() const;
0067     void setFocus(bool focus, bool updateLens = true) override;
0068     bool isErroneous() const override;
0069     QDate sortPostDate() const override;
0070     virtual int sortSamePostDate() const override;
0071     QDate sortEntryDate() const override;
0072     virtual const QString& sortPayee() const override;
0073     virtual const QList<QString>& sortTagList() const;
0074     MyMoneyMoney sortValue() const override;
0075     QString sortNumber() const override;
0076     virtual const QString& sortEntryOrder() const override;
0077     virtual eWidgets::eRegister::CashFlowDirection sortType() const override;
0078     virtual const QString& sortCategory() const override;
0079     virtual eMyMoney::Split::State sortReconcileState() const override;
0080     virtual QString id() const override;
0081     const MyMoneyTransaction& transaction() const;
0082     const MyMoneySplit& split() const;
0083     void setBalance(const MyMoneyMoney& balance);
0084     const MyMoneyMoney& balance() const;
0085 
0086     virtual int rowHeightHint() const override ;
0087 
0088     virtual bool paintRegisterCellSetup(QPainter *painter, QStyleOptionViewItem &option, const QModelIndex &index);
0089     virtual void paintRegisterCell(QPainter* painter, QStyleOptionViewItem& option, const QModelIndex& index) override;
0090 
0091     virtual void paintFormCell(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) override;
0092     virtual bool formCellText(QString& /* txt */, Qt::Alignment& /* align */, int /* row */, int /* col */, QPainter* /* painter */);
0093     virtual void registerCellText(QString& /* txt */, Qt::Alignment& /* align */, int /* row */, int /* col */, QPainter* /* painter */);
0094     virtual int registerColWidth(int /* col */, const QFontMetrics& /* cellFontMetrics */);
0095 
0096     /**
0097     * Helper method for the above method.
0098     */
0099     void registerCellText(QString& txt, int row, int col);
0100 
0101     virtual int formRowHeight(int row);
0102     virtual int formRowHeight() const;
0103 
0104     virtual void setupForm(KMyMoneyTransactionForm::TransactionForm* form);
0105     virtual void setupFormPalette(QMap<QString, QWidget*>& editWidgets);
0106     virtual void setupRegisterPalette(QMap<QString, QWidget*>& editWidgets);
0107     virtual void loadTab(KMyMoneyTransactionForm::TransactionForm* form) = 0;
0108 
0109     virtual void arrangeWidgetsInForm(QMap<QString, QWidget*>& editWidgets) = 0;
0110     virtual void arrangeWidgetsInRegister(QMap<QString, QWidget*>& editWidgets) = 0;
0111     virtual void tabOrderInForm(QWidgetList& tabOrderWidgets) const = 0;
0112     virtual void tabOrderInRegister(QWidgetList& tabOrderWidgets) const = 0;
0113 
0114     virtual eWidgets::eRegister::Action actionType() const = 0;
0115 
0116     QWidget* focusWidget(QWidget*) const;
0117     void arrangeWidget(QTableWidget* tbl, int row, int col, QWidget* w) const;
0118 
0119     bool haveNumberField() const;
0120 
0121     bool matches(const RegisterFilter&) const override;
0122 
0123     /**
0124     * Checks if the mouse hovered over an area that has a tooltip associated with it.
0125     * The mouse position is given in relative coordinates to the @a startRow and the
0126     * @a row and @a col of the item are also passed as relative values.
0127     *
0128     * If a tooltip shall be shown, this method presets the rectangle @a r with the
0129     * area in register coordinates and @a msg with the string that will be passed
0130     * to QToolTip::tip. @a true is returned in this case.
0131     *
0132     * If no tooltip is available, @a false will be returned.
0133     */
0134     virtual bool maybeTip(const QPoint& relpos, int row, int col, QRect& r, QString& msg) override;
0135 
0136     /**
0137     * This method returns the number of register rows required for a certain
0138     * item in expanded (@p expanded equals @a true) or collapsed (@p expanded
0139     * is @a false) mode.
0140     *
0141     * @param expanded returns number of maximum rows required for this item to
0142     *                 display all information (used for ledger lens and register
0143     *                 edit mode) or the minimum number of rows required.
0144     * @return number of rows required for mode selected by @p expanded
0145     */
0146     virtual int numRowsRegister(bool expanded) const = 0;
0147 
0148     /**
0149     * Provided for internal reasons. No API change. See RegisterItem::numRowsRegister()
0150     */
0151     int numRowsRegister() const override;
0152 
0153     void leaveEditMode();
0154     void startEditMode();
0155 
0156     /**
0157     * This method creates an editor for the transaction
0158     */
0159     virtual TransactionEditor* createEditor(TransactionEditorContainer* regForm, const KMyMoneyRegister::SelectedTransactions& list, const QDate& lastPostDate) = 0;
0160 
0161     virtual void setVisible(bool visible) override;
0162 
0163     virtual void setShowBalance(bool showBalance);
0164 
0165     /**
0166     * Return information if @a row should be shown (@a true )
0167     * or hidden (@a false ) in the form. Default is true.
0168     */
0169     virtual bool showRowInForm(int row) const;
0170 
0171     /**
0172     * Control visibility of @a row in the transaction form.
0173     * Only row 0 has an effect, others return @a true.
0174     */
0175     virtual void setShowRowInForm(int row, bool show);
0176 
0177     virtual void setReducedIntensity(bool reduced);
0178 
0179 protected:
0180     /**
0181     * This method converts m_split.reconcileFlag() into a readable string
0182     *
0183     * @param text Return textual representation e.g. "Cleared" (@a true) or just
0184     *             a flag e.g. "C" (@a false). Defaults to textual representation.
0185     * @return Textual representation or flag as selected via @p text of the
0186     *         reconciliation state of the split
0187     */
0188     QString reconcileState(bool text = true) const;
0189 
0190     /**
0191     * Helper method to reduce a multi line memo text into a single line.
0192     *
0193     * @param txt QString that will receive the single line memo text
0194     * @param split const reference to the split to take the memo from
0195     */
0196     void singleLineMemo(QString& txt, const MyMoneySplit& split) const;
0197 
0198     virtual void setupPalette(const QPalette& palette, QMap<QString, QWidget*>& editWidgets);
0199 
0200     Transaction(TransactionPrivate &dd, Register* parent, const MyMoneyTransaction& transaction, const MyMoneySplit& split, int uniqueId);
0201     Transaction(TransactionPrivate &dd); //for copy-constructor of derived class
0202 
0203 private:
0204     Q_DECLARE_PRIVATE(Transaction)
0205 };
0206 } // namespace
0207 
0208 #endif