File indexing completed on 2024-05-19 05:07:27

0001 /*
0002     SPDX-FileCopyrightText: 2019 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef SPLITMODEL_H
0007 #define SPLITMODEL_H
0008 
0009 #include "kmm_mymoney_export.h"
0010 
0011 // ----------------------------------------------------------------------------
0012 // QT Includes
0013 
0014 class QUndoStack;
0015 
0016 // ----------------------------------------------------------------------------
0017 // KDE Includes
0018 
0019 // ----------------------------------------------------------------------------
0020 // Project Includes
0021 
0022 #include "mymoneymodel.h"
0023 #include "mymoneysplit.h"
0024 
0025 class KMM_MYMONEY_EXPORT SplitModel : public MyMoneyModel<MyMoneySplit>
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     enum Column {
0031         Category = 0,
0032         Memo,
0033         Tags,
0034         Payment,
0035         Deposit,
0036         // insert new columns above this line
0037         MaxColumns,
0038     };
0039 
0040     explicit SplitModel(QObject* parent = nullptr, QUndoStack* undoStack = nullptr);
0041     SplitModel(QObject* parent, QUndoStack* undoStack, const SplitModel& right);
0042     virtual ~SplitModel();
0043 
0044     int columnCount(const QModelIndex& parent = QModelIndex()) const final override;
0045     QVariant data(const QModelIndex& idx, int role = Qt::DisplayRole) const override;
0046     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const final override;
0047     Qt::ItemFlags flags(const QModelIndex & index) const override;
0048 
0049     bool setData(const QModelIndex& idx, const QVariant& value, int role = Qt::EditRole) override;
0050 
0051     void appendSplit(const MyMoneySplit& s);
0052     void appendEmptySplit();
0053     void removeEmptySplit();
0054     QModelIndex emptySplit() const;
0055 
0056     // Reimplemented for internal reasons
0057     void doRemoveItem(const MyMoneySplit& before) override;
0058     void doAddItem(const MyMoneySplit& item, const QModelIndex& parentIdx = QModelIndex()) override;
0059 
0060     static QString newSplitId();
0061     static bool isNewSplitId(const QString& id);
0062 
0063     SplitModel& operator= (const SplitModel& right);
0064 
0065     MyMoneyMoney valueSum() const;
0066 
0067     void addSplitsToTransaction(MyMoneyTransaction& t) const;
0068     QList<MyMoneySplit> splitList() const;
0069 
0070     void setTransactionCommodity(const QString& commodity);
0071     bool hasMultiCurrencySplits() const;
0072 
0073     /**
0074      * When copying an existing transaction, the IDs assigned
0075      * to the splits need to be replaced when the transaction is
0076      * actually created. This method forces new split IDs to
0077      * be assigned in addSplitsToTransaction().
0078      *
0079      * @sa addSplitsToTransaction()
0080      */
0081     void resetAllSplitIds();
0082 
0083 private Q_SLOTS:
0084     void checkForForeignCurrency() const;
0085 
0086 Q_SIGNALS:
0087     void itemCountChanged(int cnt);
0088 
0089 private:
0090     struct Private;
0091     QScopedPointer<Private> d;
0092 };
0093 
0094 #endif // SPLITMODEL_H
0095