File indexing completed on 2024-05-12 16:42:20
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 SPLITMODEL_H 0008 #define SPLITMODEL_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 SplitModelPrivate; 0024 class KMM_MODELS_EXPORT SplitModel : public QAbstractTableModel 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 explicit SplitModel(QObject* parent = nullptr); 0030 virtual ~SplitModel(); 0031 void deepCopy(const SplitModel& right, bool revertSplitSign = false); 0032 0033 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 0034 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 0035 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 0036 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0037 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; 0038 Qt::ItemFlags flags(const QModelIndex& index) const override; 0039 0040 /** 0041 * Adds a single split @a t to the model 0042 */ 0043 void addSplit(const QString& transactionSplitId); 0044 0045 /** 0046 * Adds a single dummy split to the model which is used for 0047 * creation of new splits. 0048 */ 0049 void addEmptySplitEntry(); 0050 0051 /** 0052 * Remove the single dummy split to the model which is used for 0053 * creation of new splits from the model. 0054 */ 0055 void removeEmptySplitEntry(); 0056 0057 bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override; 0058 0059 /** 0060 * This method returns the string to be used for new split ids 0061 */ 0062 static QString newSplitId(); 0063 0064 /** 0065 * This method compares the @a id against the one provided 0066 * by newSplitId() and returns true if it is identical. 0067 */ 0068 static bool isNewSplitId(const QString& id); 0069 0070 // void removeSplit(const LedgerTransaction& t); 0071 0072 private: 0073 Q_DISABLE_COPY(SplitModel) 0074 Q_DECLARE_PRIVATE(SplitModel) 0075 const QScopedPointer<SplitModelPrivate> d_ptr; 0076 0077 }; 0078 #endif // SPLITMODEL_H 0079