1 /* 2 * Copyright 2014-2015 Christian Dávid <christian-david@web.de> 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License as 6 * published by the Free Software Foundation; either version 2 of 7 * the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef PAYEEIDENTIFIERCONTAINERMODEL_H 19 #define PAYEEIDENTIFIERCONTAINERMODEL_H 20 21 #include "kmm_models_export.h" 22 23 #include <QAbstractListModel> 24 #include <QSharedPointer> 25 26 #include "mymoney/payeeidentifiermodel.h" 27 #include "mymoney/mymoneypayeeidentifiercontainer.h" 28 #include "payeeidentifier/payeeidentifier.h" 29 30 /** 31 * @brief Model for MyMoneyPayeeIdentifierContainer 32 * 33 * Changes the user does have internal effect only. 34 * 35 * @see payeeIdentifierModel 36 */ 37 class MyMoneyPayeeIdentifierContainer; 38 class payeeIdentifier; 39 class KMM_MODELS_EXPORT payeeIdentifierContainerModel : public QAbstractListModel 40 { 41 Q_OBJECT 42 43 public: 44 /** 45 * @brief Roles for this model 46 * 47 * They are equal to payeeIdentifierModel::roles 48 */ 49 enum roles { 50 payeeIdentifierType = payeeIdentifierModel::payeeIdentifierType, /**< type of payeeIdentifier */ 51 payeeIdentifier = payeeIdentifierModel::payeeIdentifier /**< actual payeeIdentifier */ 52 }; 53 54 explicit payeeIdentifierContainerModel(QObject* parent = 0); 55 56 QVariant data(const QModelIndex& index, int role) const final override; 57 58 /** 59 * This model only supports to edit payeeIdentifier role with a QVariant of type 60 * payeeIdentifier. 61 */ 62 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) final override; 63 64 Qt::ItemFlags flags(const QModelIndex& index) const final override; 65 66 int rowCount(const QModelIndex& parent) const final override; 67 68 bool insertRows(int row, int count, const QModelIndex& parent) final override; 69 bool removeRows(int row, int count, const QModelIndex& parent) final override; 70 71 /** 72 * @brief Set source of data 73 * 74 * This makes the model editable. 75 */ 76 void setSource(MyMoneyPayeeIdentifierContainer data); 77 78 /** @brief Get stored data */ 79 QList< ::payeeIdentifier > identifiers() const; 80 81 public Q_SLOTS: 82 /** 83 * @brief Removes all data from the model 84 * 85 * The model is not editable afterwards. 86 */ 87 void closeSource(); 88 89 private: 90 /** @internal 91 * The use of a shared pointer makes this future prof. Because using identifier() causes 92 * some unnecessary work. 93 */ 94 QSharedPointer<MyMoneyPayeeIdentifierContainer> m_data; 95 }; 96 97 #endif // PAYEEIDENTIFIERCONTAINERMODEL_H 98