File indexing completed on 2024-05-12 16:42:18
0001 /* 0002 SPDX-FileCopyrightText: 2016-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 LEDGERMODEL_H 0008 #define LEDGERMODEL_H 0009 0010 #include "kmm_models_export.h" 0011 0012 // ---------------------------------------------------------------------------- 0013 // QT Includes 0014 0015 #include <QAbstractTableModel> 0016 0017 // ---------------------------------------------------------------------------- 0018 // KDE Includes 0019 0020 // ---------------------------------------------------------------------------- 0021 // Project Includes 0022 0023 class MyMoneyObject; 0024 class MyMoneySchedule; 0025 class MyMoneySplit; 0026 class MyMoneyTransaction; 0027 class LedgerTransaction; 0028 0029 namespace eMyMoney { 0030 namespace File { 0031 enum class Object; 0032 } 0033 } 0034 0035 class LedgerModelPrivate; 0036 class KMM_MODELS_EXPORT LedgerModel : public QAbstractTableModel 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 explicit LedgerModel(QObject* parent = nullptr); 0042 virtual ~LedgerModel(); 0043 0044 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 0045 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 0046 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 0047 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0048 0049 Qt::ItemFlags flags(const QModelIndex& index) const override; 0050 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; 0051 0052 /** 0053 * clears all objects currently in the model 0054 */ 0055 void unload(); 0056 0057 /** 0058 * Adds the transaction items in the @a list to the model 0059 */ 0060 void addTransactions(const QList<QPair<MyMoneyTransaction, MyMoneySplit> >& list); 0061 0062 /** 0063 * Adds a single transaction @a t to the model 0064 */ 0065 void addTransaction(const LedgerTransaction& t); 0066 0067 /** 0068 * Adds a single split based on its transactionSplitId 0069 */ 0070 void addTransaction(const QString& transactionSplitId); 0071 0072 /** 0073 * Adds the schedule items in the @a list to the model 0074 */ 0075 void addSchedules(const QList< MyMoneySchedule >& list, int previewPeriod); 0076 0077 /** 0078 * Loads the model with data from the engine 0079 */ 0080 void load(); 0081 0082 /** 0083 * This method extracts the transaction id from a combined 0084 * transactionSplitId and returns it. In case the @a transactionSplitId does 0085 * not resembles a transactionSplitId an empty string is returned. 0086 */ 0087 QString transactionIdFromTransactionSplitId(const QString& transactionSplitId) const; 0088 0089 public Q_SLOTS: 0090 void slotAddTransaction (eMyMoney::File::Object objType, const QString& id); 0091 void slotModifyTransaction(eMyMoney::File::Object objType, const QString& id); 0092 void slotRemoveTransaction(eMyMoney::File::Object objType, const QString& id); 0093 void slotAddSchedule (eMyMoney::File::Object objType, const QString& id); 0094 void slotModifySchedule (eMyMoney::File::Object objType, const QString& id); 0095 void slotRemoveSchedule (eMyMoney::File::Object objType, const QString& id); 0096 0097 private: 0098 Q_DISABLE_COPY(LedgerModel) 0099 Q_DECLARE_PRIVATE(LedgerModel) 0100 const QScopedPointer<LedgerModelPrivate> d_ptr; 0101 }; 0102 0103 #endif // LEDGERMODEL_H 0104