Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/models/equitiesmodel.cpp
Context not available. | |||||
28 | // ---------------------------------------------------------------------------- | 28 | // ---------------------------------------------------------------------------- | ||
---|---|---|---|---|---|
29 | // Project Includes | 29 | // Project Includes | ||
30 | 30 | | |||
31 | #include "mymoneyfile.h" | ||||
32 | #include "mymoneyaccount.h" | ||||
33 | #include "mymoneysecurity.h" | ||||
34 | #include "mymoneyprice.h" | ||||
35 | | ||||
31 | class EquitiesModel::Private | 36 | class EquitiesModel::Private | ||
32 | { | 37 | { | ||
33 | public: | 38 | public: | ||
Context not available. | |||||
84 | cell->setData(account.currencyId(), Role::SecurityID); | 89 | cell->setData(account.currencyId(), Role::SecurityID); | ||
85 | } | 90 | } | ||
86 | 91 | | |||
87 | if (account.accountType() == MyMoneyAccount::Investment) // investments accounts are not meant to be displayed, so stop here | 92 | if (account.accountType() == eMyMoney::Account::Investment) // investments accounts are not meant to be displayed, so stop here | ||
88 | return; | 93 | return; | ||
89 | 94 | | |||
90 | // Symbol | 95 | // Symbol | ||
Context not available. | |||||
206 | QList<MyMoneyAccount> accList; | 211 | QList<MyMoneyAccount> accList; | ||
207 | d->m_file->accountList(accList); // get all available accounts | 212 | d->m_file->accountList(accList); // get all available accounts | ||
208 | foreach (const auto acc, accList) | 213 | foreach (const auto acc, accList) | ||
209 | if (acc.accountType() == MyMoneyAccount::Investment) // but add only investment accounts (and its children) to the model | 214 | if (acc.accountType() == eMyMoney::Account::Investment) // but add only investment accounts (and its children) to the model | ||
210 | d->loadInvestmentAccount(rootItem, acc); | 215 | d->loadInvestmentAccount(rootItem, acc); | ||
211 | 216 | | |||
212 | this->blockSignals(false); | 217 | this->blockSignals(false); | ||
Context not available. | |||||
216 | * Notify the model that an object has been added. An action is performed only if the object is an account. | 221 | * Notify the model that an object has been added. An action is performed only if the object is an account. | ||
217 | * | 222 | * | ||
218 | */ | 223 | */ | ||
219 | void EquitiesModel::slotObjectAdded(MyMoneyFile::notificationObjectT objType, const MyMoneyObject * const obj) | 224 | void EquitiesModel::slotObjectAdded(eMyMoney::File::Object objType, const MyMoneyObject * const obj) | ||
220 | { | 225 | { | ||
221 | // check whether change is about accounts | 226 | // check whether change is about accounts | ||
222 | if (objType != MyMoneyFile::notifyAccount) | 227 | if (objType != eMyMoney::File::Object::Account) | ||
223 | return; | 228 | return; | ||
224 | 229 | | |||
225 | // check whether change is about either investment or stock account | 230 | // check whether change is about either investment or stock account | ||
226 | const auto acc = dynamic_cast<const MyMoneyAccount * const>(obj); | 231 | const auto acc = dynamic_cast<const MyMoneyAccount * const>(obj); | ||
227 | if (!acc || | 232 | if (!acc || | ||
228 | (acc->accountType() != MyMoneyAccount::Investment && | 233 | (acc->accountType() != eMyMoney::Account::Investment && | ||
229 | acc->accountType() != MyMoneyAccount::Stock)) | 234 | acc->accountType() != eMyMoney::Account::Stock)) | ||
230 | return; | 235 | return; | ||
231 | auto itAcc = d->itemFromId(this, acc->id(), Role::EquityID); | 236 | auto itAcc = d->itemFromId(this, acc->id(), Role::EquityID); | ||
232 | 237 | | |||
233 | QStandardItem *itParentAcc; | 238 | QStandardItem *itParentAcc; | ||
234 | if (acc->accountType() == MyMoneyAccount::Investment) // if it's investment account then its parent is root item | 239 | if (acc->accountType() == eMyMoney::Account::Investment) // if it's investment account then its parent is root item | ||
235 | itParentAcc = invisibleRootItem(); | 240 | itParentAcc = invisibleRootItem(); | ||
236 | else // otherwise it's stock account and its parent is investment account | 241 | else // otherwise it's stock account and its parent is investment account | ||
237 | itParentAcc = d->itemFromId(this, acc->parentAccountId(), Role::InvestmentID); | 242 | itParentAcc = d->itemFromId(this, acc->parentAccountId(), Role::InvestmentID); | ||
Context not available. | |||||
250 | * Notify the model that an object has been modified. An action is performed only if the object is an account. | 255 | * Notify the model that an object has been modified. An action is performed only if the object is an account. | ||
251 | * | 256 | * | ||
252 | */ | 257 | */ | ||
253 | void EquitiesModel::slotObjectModified(MyMoneyFile::notificationObjectT objType, const MyMoneyObject * const obj) | 258 | void EquitiesModel::slotObjectModified(eMyMoney::File::Object objType, const MyMoneyObject * const obj) | ||
254 | { | 259 | { | ||
255 | const MyMoneyAccount *acc; | 260 | const MyMoneyAccount *acc; | ||
256 | QStandardItem *itAcc; | 261 | QStandardItem *itAcc; | ||
257 | switch (objType) { | 262 | switch (objType) { | ||
258 | case MyMoneyFile::notifyAccount: | 263 | case eMyMoney::File::Object::Account: | ||
259 | { | 264 | { | ||
260 | auto tmpAcc = dynamic_cast<const MyMoneyAccount * const>(obj); | 265 | auto tmpAcc = dynamic_cast<const MyMoneyAccount * const>(obj); | ||
261 | if (!tmpAcc || tmpAcc->accountType() != MyMoneyAccount::Stock) | 266 | if (!tmpAcc || tmpAcc->accountType() != eMyMoney::Account::Stock) | ||
262 | return; | 267 | return; | ||
263 | acc = tmpAcc; | 268 | acc = tmpAcc; | ||
264 | itAcc = d->itemFromId(this, acc->id(), Role::EquityID); | 269 | itAcc = d->itemFromId(this, acc->id(), Role::EquityID); | ||
265 | break; | 270 | break; | ||
266 | } | 271 | } | ||
267 | case MyMoneyFile::notifySecurity: | 272 | case eMyMoney::File::Object::Security: | ||
268 | { | 273 | { | ||
269 | auto sec = dynamic_cast<const MyMoneySecurity * const>(obj); | 274 | auto sec = dynamic_cast<const MyMoneySecurity * const>(obj); | ||
270 | itAcc = d->itemFromId(this, sec->id(), Role::SecurityID); | 275 | itAcc = d->itemFromId(this, sec->id(), Role::SecurityID); | ||
Context not available. | |||||
284 | if (modelID == acc->parentAccountId()) { // and if it matches with those from file then modify only | 289 | if (modelID == acc->parentAccountId()) { // and if it matches with those from file then modify only | ||
285 | d->setAccountData(itParentAcc, itAcc->row(), *acc, d->m_columns); | 290 | d->setAccountData(itParentAcc, itAcc->row(), *acc, d->m_columns); | ||
286 | } else { // and if not then reparent | 291 | } else { // and if not then reparent | ||
287 | slotObjectRemoved(MyMoneyFile::notifyAccount, acc->id()); | 292 | slotObjectRemoved(eMyMoney::File::Object::Account, acc->id()); | ||
288 | slotObjectAdded(MyMoneyFile::notifyAccount, obj); | 293 | slotObjectAdded(eMyMoney::File::Object::Account, obj); | ||
289 | } | 294 | } | ||
290 | } | 295 | } | ||
291 | 296 | | |||
Context not available. | |||||
293 | * Notify the model that an object has been removed. An action is performed only if the object is an account. | 298 | * Notify the model that an object has been removed. An action is performed only if the object is an account. | ||
294 | * | 299 | * | ||
295 | */ | 300 | */ | ||
296 | void EquitiesModel::slotObjectRemoved(MyMoneyFile::notificationObjectT objType, const QString& id) | 301 | void EquitiesModel::slotObjectRemoved(eMyMoney::File::Object objType, const QString& id) | ||
297 | { | 302 | { | ||
298 | if (objType != MyMoneyFile::notifyAccount) | 303 | if (objType != eMyMoney::File::Object::Account) | ||
299 | return; | 304 | return; | ||
300 | 305 | | |||
301 | const auto indexList = match(index(0, 0), Role::EquityID, id, -1, Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive)); | 306 | const auto indexList = match(index(0, 0), Role::EquityID, id, -1, Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive)); | ||
Context not available. | |||||
308 | */ | 313 | */ | ||
309 | void EquitiesModel::slotBalanceOrValueChanged(const MyMoneyAccount &account) | 314 | void EquitiesModel::slotBalanceOrValueChanged(const MyMoneyAccount &account) | ||
310 | { | 315 | { | ||
311 | if (account.accountType() != MyMoneyAccount::Stock) | 316 | if (account.accountType() != eMyMoney::Account::Stock) | ||
312 | return; | 317 | return; | ||
313 | 318 | | |||
314 | const auto itAcc = d->itemFromId(this, account.id(), Role::EquityID); | 319 | const auto itAcc = d->itemFromId(this, account.id(), Role::EquityID); | ||
Context not available. | |||||
415 | acc.isClosed()) | 420 | acc.isClosed()) | ||
416 | return false; | 421 | return false; | ||
417 | if (d->m_hideZeroBalanceAccounts && | 422 | if (d->m_hideZeroBalanceAccounts && | ||
418 | acc.accountType() != MyMoneyAccount::Investment && acc.balance().isZero()) // we should never hide investment account because all underlaying stocks will be hidden as well | 423 | acc.accountType() != eMyMoney::Account::Investment && acc.balance().isZero()) // we should never hide investment account because all underlaying stocks will be hidden as well | ||
419 | return false; | 424 | return false; | ||
420 | } | 425 | } | ||
421 | return true; | 426 | return true; | ||
Context not available. |