Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/models/models.cpp
Show All 25 Lines | |||||
26 | 26 | | |||
27 | // ---------------------------------------------------------------------------- | 27 | // ---------------------------------------------------------------------------- | ||
28 | // KDE Includes | 28 | // KDE Includes | ||
29 | 29 | | |||
30 | // ---------------------------------------------------------------------------- | 30 | // ---------------------------------------------------------------------------- | ||
31 | // Project Includes | 31 | // Project Includes | ||
32 | 32 | | |||
33 | #include "accountsmodel.h" | 33 | #include "accountsmodel.h" | ||
34 | #include "onlinejobmodel.h" | | |||
35 | #include "ledgermodel.h" | 34 | #include "ledgermodel.h" | ||
36 | #include "costcentermodel.h" | 35 | #include "costcentermodel.h" | ||
37 | #include "payeesmodel.h" | 36 | #include "payeesmodel.h" | ||
38 | #include "equitiesmodel.h" | 37 | #include "equitiesmodel.h" | ||
39 | #include "securitiesmodel.h" | 38 | #include "securitiesmodel.h" | ||
40 | 39 | | |||
41 | #ifdef KMM_MODELTEST | 40 | #ifdef KMM_MODELTEST | ||
42 | #include "modeltest.h" | 41 | #include "modeltest.h" | ||
43 | #endif | 42 | #endif | ||
44 | 43 | | |||
45 | Q_GLOBAL_STATIC(Models, models); | 44 | Q_GLOBAL_STATIC(Models, models); | ||
46 | 45 | | |||
47 | struct Models::Private { | 46 | struct Models::Private { | ||
48 | Private() | 47 | Private() | ||
49 | : m_accountsModel(0) | 48 | : m_accountsModel(0) | ||
50 | , m_institutionsModel(0) | 49 | , m_institutionsModel(0) | ||
51 | , m_onlineJobModel(0) | | |||
52 | , m_ledgerModel(0) | 50 | , m_ledgerModel(0) | ||
53 | , m_costCenterModel(0) | 51 | , m_costCenterModel(0) | ||
54 | , m_payeesModel(0) | 52 | , m_payeesModel(0) | ||
55 | , m_equitiesModel(0) | 53 | , m_equitiesModel(0) | ||
56 | , m_securitiesModel(0) | 54 | , m_securitiesModel(0) | ||
57 | {} | 55 | {} | ||
58 | 56 | | |||
59 | AccountsModel *m_accountsModel; | 57 | AccountsModel *m_accountsModel; | ||
60 | InstitutionsModel *m_institutionsModel; | 58 | InstitutionsModel *m_institutionsModel; | ||
61 | onlineJobModel *m_onlineJobModel; | | |||
62 | LedgerModel *m_ledgerModel; | 59 | LedgerModel *m_ledgerModel; | ||
63 | CostCenterModel *m_costCenterModel; | 60 | CostCenterModel *m_costCenterModel; | ||
64 | PayeesModel *m_payeesModel; | 61 | PayeesModel *m_payeesModel; | ||
65 | EquitiesModel *m_equitiesModel; | 62 | EquitiesModel *m_equitiesModel; | ||
66 | SecuritiesModel *m_securitiesModel; | 63 | SecuritiesModel *m_securitiesModel; | ||
67 | }; | 64 | }; | ||
68 | 65 | | |||
69 | 66 | | |||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 108 | if (!d->m_institutionsModel) { | |||
112 | d->m_institutionsModel = new InstitutionsModel(this); | 109 | d->m_institutionsModel = new InstitutionsModel(this); | ||
113 | #ifdef KMM_MODELTEST | 110 | #ifdef KMM_MODELTEST | ||
114 | new ModelTest(d->m_institutionsModel, Models::instance()); | 111 | new ModelTest(d->m_institutionsModel, Models::instance()); | ||
115 | #endif | 112 | #endif | ||
116 | } | 113 | } | ||
117 | return d->m_institutionsModel; | 114 | return d->m_institutionsModel; | ||
118 | } | 115 | } | ||
119 | 116 | | |||
120 | onlineJobModel* Models::onlineJobsModel() | | |||
121 | { | | |||
122 | if (!d->m_onlineJobModel) { | | |||
123 | d->m_onlineJobModel = new onlineJobModel(this); | | |||
124 | #ifdef KMM_MODELTEST | | |||
125 | /// @todo using the ModelTest feature on the onlineJobModel crashes. Need to fix. | | |||
126 | // new ModelTest(d->m_onlineJobModel, Models::instance()); | | |||
127 | #endif | | |||
128 | } | | |||
129 | return d->m_onlineJobModel; | | |||
130 | } | | |||
131 | | ||||
132 | #ifdef ENABLE_UNFINISHEDFEATURES | 117 | #ifdef ENABLE_UNFINISHEDFEATURES | ||
133 | /** | 118 | /** | ||
134 | * This is the function to get a reference to the core @ref LedgerModel. | 119 | * This is the function to get a reference to the core @ref LedgerModel. | ||
135 | * The returned object is owned by this object so don't delete it. It creates the | 120 | * The returned object is owned by this object so don't delete it. It creates the | ||
136 | * model on the first access to it. | 121 | * model on the first access to it. | ||
137 | */ | 122 | */ | ||
138 | LedgerModel* Models::ledgerModel() | 123 | LedgerModel* Models::ledgerModel() | ||
139 | { | 124 | { | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 200 | { | |||
225 | return QModelIndex(); | 210 | return QModelIndex(); | ||
226 | 211 | | |||
227 | } | 212 | } | ||
228 | 213 | | |||
229 | void Models::fileOpened() | 214 | void Models::fileOpened() | ||
230 | { | 215 | { | ||
231 | accountsModel()->AccountsModel::load(); | 216 | accountsModel()->AccountsModel::load(); | ||
232 | institutionsModel()->InstitutionsModel::load(); | 217 | institutionsModel()->InstitutionsModel::load(); | ||
233 | onlineJobsModel()->load(); | | |||
234 | costCenterModel()->load(); | 218 | costCenterModel()->load(); | ||
235 | #ifdef ENABLE_UNFINISHEDFEATURES | 219 | #ifdef ENABLE_UNFINISHEDFEATURES | ||
236 | ledgerModel()->load(); | 220 | ledgerModel()->load(); | ||
237 | #endif | 221 | #endif | ||
238 | payeesModel()->load(); | 222 | payeesModel()->load(); | ||
239 | equitiesModel()->load(); | 223 | equitiesModel()->load(); | ||
240 | securitiesModel()->load(); | 224 | securitiesModel()->load(); | ||
241 | 225 | | |||
242 | emit modelsLoaded(); | 226 | emit modelsLoaded(); | ||
243 | } | 227 | } | ||
244 | 228 | | |||
245 | void Models::fileClosed() | 229 | void Models::fileClosed() | ||
246 | { | 230 | { | ||
247 | // TODO: make this cleaner in the future, for now just clear the accounts model before the file is closed | 231 | // TODO: make this cleaner in the future, for now just clear the accounts model before the file is closed | ||
248 | // to avoid any uncaught KMyMoneyExceptions while using the account objects from this model after the file has been closed | 232 | // to avoid any uncaught KMyMoneyExceptions while using the account objects from this model after the file has been closed | ||
249 | accountsModel()->removeRows(0, accountsModel()->rowCount()); | 233 | accountsModel()->removeRows(0, accountsModel()->rowCount()); | ||
250 | institutionsModel()->removeRows(0, institutionsModel()->rowCount()); | 234 | institutionsModel()->removeRows(0, institutionsModel()->rowCount()); | ||
251 | onlineJobsModel()->unload(); | | |||
252 | #ifdef ENABLE_UNFINISHEDFEATURES | 235 | #ifdef ENABLE_UNFINISHEDFEATURES | ||
253 | ledgerModel()->unload(); | 236 | ledgerModel()->unload(); | ||
254 | #endif | 237 | #endif | ||
255 | costCenterModel()->unload(); | 238 | costCenterModel()->unload(); | ||
256 | payeesModel()->unload(); | 239 | payeesModel()->unload(); | ||
257 | equitiesModel()->removeRows(0, equitiesModel()->rowCount()); | 240 | equitiesModel()->removeRows(0, equitiesModel()->rowCount()); | ||
258 | securitiesModel()->removeRows(0, securitiesModel()->rowCount()); | 241 | securitiesModel()->removeRows(0, securitiesModel()->rowCount()); | ||
259 | } | 242 | } |