1 /* 2 * Copyright 2009-2015 Cristian Oneț <onet.cristian@gmail.com> 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 MODELS_H 19 #define MODELS_H 20 21 #include <config-kmymoney.h> 22 #include "kmm_models_export.h" 23 24 // ---------------------------------------------------------------------------- 25 // QT Includes 26 27 #include <QObject> 28 #include <QModelIndex> 29 30 // ---------------------------------------------------------------------------- 31 // KDE Includes 32 33 // ---------------------------------------------------------------------------- 34 // Project Includes 35 36 /** 37 * Forward declarations for the returned models. 38 */ 39 class AccountsModel; 40 class InstitutionsModel; 41 #ifdef ENABLE_UNFINISHEDFEATURES 42 class LedgerModel; 43 #endif 44 class CostCenterModel; 45 class PayeesModel; 46 class EquitiesModel; 47 class SecuritiesModel; 48 49 /** 50 * This object is the owner and maintainer of all the core models of KMyMoney. 51 * It's a singleton so the instance should be accessed in the following way: 52 * 53 * @code 54 * Models *models = Models::instance(); 55 * AccountsModel *accountsModel = models->accountsModel(); 56 * @endcode 57 * 58 * In order for the data synchronization between the @ref MyMoneyFile and the 59 * models managed by this object to work, the @ref MyMoneyFile::dataChanged 60 * signal must be connected to this object's @ref fileClosed slot. 61 * 62 * @author Cristian Onet 2010 63 * 64 */ 65 class KMM_MODELS_EXPORT Models : public QObject 66 { 67 Q_OBJECT 68 69 public: 70 Models(); 71 ~Models(); 72 73 /** 74 * This is the function to access the Models object. 75 * It returns a pointer to the single instance of the object. 76 */ 77 static Models* instance(); 78 79 AccountsModel* accountsModel(); 80 InstitutionsModel* institutionsModel(); 81 #ifdef ENABLE_UNFINISHEDFEATURES 82 LedgerModel* ledgerModel(); 83 #endif 84 CostCenterModel* costCenterModel(); 85 PayeesModel* payeesModel(); 86 EquitiesModel* equitiesModel(); 87 SecuritiesModel* securitiesModel(); 88 89 /** 90 * returns the index of an item the @a model based on the @a id of role @a role. 91 */ 92 static QModelIndex indexById(QAbstractItemModel* model, int role, const QString& id); 93 94 public Q_SLOTS: 95 /** 96 * This slot is used to notify the models that the data has been loaded and ready to use. 97 * @ref MyMoneyFile. 98 */ 99 void fileOpened(); 100 101 /** 102 * This slot is used to notify the models that the data has been unloaded. 103 * @ref MyMoneyFile. 104 */ 105 void fileClosed(); 106 107 Q_SIGNALS: 108 void modelsLoaded(); 109 110 private: 111 112 /** 113 * This class defines a singleton. 114 */ 115 Models(const Models&); 116 /** 117 * This class defines a singleton. 118 */ 119 Models& operator=(Models&); 120 121 private: 122 struct Private; 123 Private* const d; 124 }; 125 126 #endif // MODELS_H 127 128