本文整理汇总了C++中MyMoneyFile::modifyAccount方法的典型用法代码示例。如果您正苦于以下问题:C++ MyMoneyFile::modifyAccount方法的具体用法?C++ MyMoneyFile::modifyAccount怎么用?C++ MyMoneyFile::modifyAccount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyMoneyFile
的用法示例。
在下文中一共展示了MyMoneyFile::modifyAccount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createAccount
void CsvUtil::createAccount(MyMoneyAccount& newAccount, MyMoneyAccount& parentAccount, MyMoneyAccount& brokerageAccount, MyMoneyMoney openingBal)
{
MyMoneyFile* file = MyMoneyFile::instance();
// make sure we have a currency. If none is assigned, we assume base currency
if (newAccount.currencyId().isEmpty())
newAccount.setCurrencyId(file->baseCurrency().id());
MyMoneyFileTransaction ft;
try {
int pos;
// check for ':' in the name and use it as separator for a hierarchy
while ((pos = newAccount.name().indexOf(MyMoneyFile::AccountSeperator)) != -1) {
QString part = newAccount.name().left(pos);
QString remainder = newAccount.name().mid(pos + 1);
const MyMoneyAccount& existingAccount = file->subAccountByName(parentAccount, part);
if (existingAccount.id().isEmpty()) {
newAccount.setName(part);
file->addAccount(newAccount, parentAccount);
parentAccount = newAccount;
} else {
parentAccount = existingAccount;
}
newAccount.setParentAccountId(QString()); // make sure, there's no parent
newAccount.clearId(); // and no id set for adding
newAccount.removeAccountIds(); // and no sub-account ids
newAccount.setName(remainder);
}
const MyMoneySecurity& sec = file->security(newAccount.currencyId());
// Check the opening balance
if (openingBal.isPositive() && newAccount.accountGroup() == MyMoneyAccount::Liability) {
QString message = i18n("This account is a liability and if the "
"opening balance represents money owed, then it should be negative. "
"Negate the amount?\n\n"
"Please click Yes to change the opening balance to %1,\n"
"Please click No to leave the amount as %2,\n"
"Please click Cancel to abort the account creation."
, MyMoneyUtils::formatMoney(-openingBal, newAccount, sec)
, MyMoneyUtils::formatMoney(openingBal, newAccount, sec));
int ans = KMessageBox::questionYesNoCancel(0, message);
if (ans == KMessageBox::Yes) {
openingBal = -openingBal;
} else if (ans == KMessageBox::Cancel)
return;
}
file->addAccount(newAccount, parentAccount);
if (newAccount.accountType() == MyMoneyAccount::Investment
&& !brokerageAccount.name().isEmpty()) {
file->addAccount(brokerageAccount, parentAccount);
// set a link from the investment account to the brokerage account
file->modifyAccount(newAccount);
file->createOpeningBalanceTransaction(brokerageAccount, openingBal);
} else
file->createOpeningBalanceTransaction(newAccount, openingBal);
ft.commit();
} catch (const MyMoneyException &e) {
KMessageBox::information(0, i18n("Unable to add account: %1", e.what()));
}
}
示例2: createObjects
void KNewInvestmentWizard::createObjects(const QString& parentId)
{
MyMoneyFile* file = MyMoneyFile::instance();
QValueList<MyMoneySecurity> list = MyMoneyFile::instance()->securityList();
QValueList<MyMoneySecurity>::ConstIterator it;
MyMoneySecurity::eSECURITYTYPE type = KMyMoneyUtils::stringToSecurity(m_securityType->currentText());
MyMoneyFileTransaction ft;
try {
// update all relevant attributes only, if we create a stock
// account and the security is unknown or we modifiy the security
MyMoneySecurity newSecurity(m_security);
newSecurity.setName(m_investmentName->text());
newSecurity.setTradingSymbol(m_investmentSymbol->text());
newSecurity.setTradingMarket(m_tradingMarket->currentText());
newSecurity.setSmallestAccountFraction(m_fraction->value());
newSecurity.setTradingCurrency(m_tradingCurrencyEdit->security().id());
newSecurity.setSecurityType(type);
newSecurity.deletePair("kmm-online-source");
newSecurity.deletePair("kmm-online-quote-system");
newSecurity.deletePair("kmm-online-factor");
newSecurity.deletePair("kmm-security-id");
if(!m_onlineSourceCombo->currentText().isEmpty()) {
if (m_useFinanceQuote->isChecked()) {
FinanceQuoteProcess p;
newSecurity.setValue("kmm-online-quote-system", "Finance::Quote");
newSecurity.setValue("kmm-online-source", p.crypticName(m_onlineSourceCombo->currentText()));
}else{
newSecurity.setValue("kmm-online-source", m_onlineSourceCombo->currentText());
}
}
if(m_onlineFactor->isEnabled() && (m_onlineFactor->value() != MyMoneyMoney(1,1)))
newSecurity.setValue("kmm-online-factor", m_onlineFactor->value().toString());
if(!m_investmentIdentification->text().isEmpty())
newSecurity.setValue("kmm-security-id", m_investmentIdentification->text());
if(m_security.id().isEmpty() || newSecurity != m_security) {
m_security = newSecurity;
// add or update it
if(m_security.id().isEmpty()) {
file->addSecurity(m_security);
} else {
file->modifySecurity(m_security);
}
}
if(m_createAccount) {
// now that the security exists, we can add the account to store it
m_account.setName(m_investmentName->text());
if(m_account.accountType() == MyMoneyAccount::UnknownAccountType)
m_account.setAccountType(MyMoneyAccount::Stock);
m_account.setCurrencyId(m_security.id());
switch(m_priceMode->currentItem()) {
case 0:
m_account.deletePair("priceMode");
break;
case 1:
case 2:
m_account.setValue("priceMode", QString("%1").arg(m_priceMode->currentItem()));
break;
}
if(m_account.id().isEmpty()) {
MyMoneyAccount parent = file->account(parentId);
file->addAccount(m_account, parent);
} else
file->modifyAccount(m_account);
}
ft.commit();
} catch(MyMoneyException* e) {
KMessageBox::detailedSorry(0, i18n("Unable to create all objects for the investment"), QString("%1 caugt in %2:%3").arg(e->what()).arg(e->file()).arg(e->line()));
delete e;
}
}