Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/models/equitiesmodel.cpp
Show First 20 Lines • Show All 253 Lines • ▼ Show 20 Line(s) | |||||
254 | } | 254 | } | ||
255 | 255 | | |||
256 | /** | 256 | /** | ||
257 | * Notify the model that an object has been modified. An action is performed only if the object is an account. | 257 | * Notify the model that an object has been modified. An action is performed only if the object is an account. | ||
258 | * | 258 | * | ||
259 | */ | 259 | */ | ||
260 | void EquitiesModel::slotObjectModified(eMyMoney::File::Object objType, const MyMoneyObject * const obj) | 260 | void EquitiesModel::slotObjectModified(eMyMoney::File::Object objType, const MyMoneyObject * const obj) | ||
261 | { | 261 | { | ||
262 | const MyMoneyAccount *acc; | 262 | MyMoneyAccount acc; | ||
263 | QStandardItem *itAcc; | 263 | QStandardItem *itAcc; | ||
264 | switch (objType) { | 264 | switch (objType) { | ||
265 | case eMyMoney::File::Object::Account: | 265 | case eMyMoney::File::Object::Account: | ||
266 | { | 266 | { | ||
267 | auto tmpAcc = dynamic_cast<const MyMoneyAccount * const>(obj); | 267 | auto tmpAcc = dynamic_cast<const MyMoneyAccount * const>(obj); | ||
268 | if (!tmpAcc || tmpAcc->accountType() != eMyMoney::Account::Type::Stock) | 268 | if (!tmpAcc || tmpAcc->accountType() != eMyMoney::Account::Type::Stock) | ||
269 | return; | 269 | return; | ||
270 | acc = tmpAcc; | 270 | acc = MyMoneyAccount(*tmpAcc); | ||
271 | itAcc = d->itemFromId(this, acc->id(), Role::EquityID); | 271 | itAcc = d->itemFromId(this, acc.id(), Role::EquityID); | ||
272 | break; | 272 | break; | ||
273 | } | 273 | } | ||
274 | case eMyMoney::File::Object::Security: | 274 | case eMyMoney::File::Object::Security: | ||
275 | { | 275 | { | ||
276 | auto sec = dynamic_cast<const MyMoneySecurity * const>(obj); | 276 | auto sec = dynamic_cast<const MyMoneySecurity * const>(obj); | ||
277 | itAcc = d->itemFromId(this, sec->id(), Role::SecurityID); | 277 | itAcc = d->itemFromId(this, sec->id(), Role::SecurityID); | ||
278 | if (!itAcc) | 278 | if (!itAcc) | ||
279 | return; | 279 | return; | ||
280 | const auto idAcc = itAcc->data(Role::EquityID).toString(); | 280 | const auto idAcc = itAcc->data(Role::EquityID).toString(); | ||
281 | acc = &d->m_file->account(idAcc); | 281 | acc = d->m_file->account(idAcc); | ||
282 | break; | 282 | break; | ||
283 | } | 283 | } | ||
284 | default: | 284 | default: | ||
285 | return; | 285 | return; | ||
286 | } | 286 | } | ||
287 | 287 | | |||
288 | auto itParentAcc = d->itemFromId(this, acc->parentAccountId(), Role::InvestmentID); | 288 | auto itParentAcc = d->itemFromId(this, acc.parentAccountId(), Role::InvestmentID); | ||
289 | 289 | | |||
290 | auto modelID = itParentAcc->data(Role::InvestmentID).toString(); // get parent account from model | 290 | auto modelID = itParentAcc->data(Role::InvestmentID).toString(); // get parent account from model | ||
291 | if (modelID == acc->parentAccountId()) { // and if it matches with those from file then modify only | 291 | if (modelID == acc.parentAccountId()) { // and if it matches with those from file then modify only | ||
292 | d->setAccountData(itParentAcc, itAcc->row(), *acc, d->m_columns); | 292 | d->setAccountData(itParentAcc, itAcc->row(), acc, d->m_columns); | ||
293 | } else { // and if not then reparent | 293 | } else { // and if not then reparent | ||
294 | slotObjectRemoved(eMyMoney::File::Object::Account, acc->id()); | 294 | slotObjectRemoved(eMyMoney::File::Object::Account, acc.id()); | ||
295 | slotObjectAdded(eMyMoney::File::Object::Account, obj); | 295 | slotObjectAdded(eMyMoney::File::Object::Account, obj); | ||
296 | } | 296 | } | ||
297 | } | 297 | } | ||
298 | 298 | | |||
299 | /** | 299 | /** | ||
300 | * Notify the model that an object has been removed. An action is performed only if the object is an account. | 300 | * Notify the model that an object has been removed. An action is performed only if the object is an account. | ||
301 | * | 301 | * | ||
302 | */ | 302 | */ | ||
▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines |