本文整理汇总了C++中MyMoneySecurity::tradingCurrency方法的典型用法代码示例。如果您正苦于以下问题:C++ MyMoneySecurity::tradingCurrency方法的具体用法?C++ MyMoneySecurity::tradingCurrency怎么用?C++ MyMoneySecurity::tradingCurrency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyMoneySecurity
的用法示例。
在下文中一共展示了MyMoneySecurity::tradingCurrency方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deepCurrencyPrice
MyMoneyMoney ReportAccount::deepCurrencyPrice(const QDate& date, bool exactDate) const
{
DEBUG_ENTER(Q_FUNC_INFO);
MyMoneyMoney result(1, 1);
MyMoneyFile* file = MyMoneyFile::instance();
MyMoneySecurity undersecurity = file->security(currencyId());
if (! undersecurity.isCurrency()) {
const MyMoneyPrice &price = file->price(undersecurity.id(), undersecurity.tradingCurrency(), date, exactDate);
if (price.isValid()) {
result = price.rate(undersecurity.tradingCurrency());
DEBUG_OUTPUT(QString("Converting under %1 to deep %2, price on %3 is %4")
.arg(undersecurity.name())
.arg(file->security(undersecurity.tradingCurrency()).name())
.arg(date.toString())
.arg(result.toDouble()));
} else {
DEBUG_OUTPUT(QString("No price to convert under %1 to deep %2 on %3")
.arg(undersecurity.name())
.arg(file->security(undersecurity.tradingCurrency()).name())
.arg(date.toString()));
result = MyMoneyMoney();
}
}
return result;
}
示例2: price
MyMoneyPrice KEquityPriceUpdateDlg::price(const QString& id) const
{
MyMoneyPrice price;
QTreeWidgetItem* item = 0;
QList<QTreeWidgetItem*> foundItems = lvEquityList->findItems(id, Qt::MatchExactly, ID_COL);
if (! foundItems.empty())
item = foundItems.at(0);
if (item) {
MyMoneyMoney rate(item->text(PRICE_COL));
if (!rate.isZero()) {
QString id = item->text(ID_COL).toUtf8();
// if the ID has a space, then this is TWO ID's, so it's a currency quote
if (id.contains(" ")) {
QStringList ids = id.split(' ', QString::SkipEmptyParts);
QString fromid = ids[0].toUtf8();
QString toid = ids[1].toUtf8();
price = MyMoneyPrice(fromid, toid, QDate().fromString(item->text(DATE_COL), Qt::ISODate), rate, item->text(SOURCE_COL));
} else
// otherwise, it's a security quote
{
MyMoneySecurity security = MyMoneyFile::instance()->security(id);
price = MyMoneyPrice(id, security.tradingCurrency(), QDate().fromString(item->text(DATE_COL), Qt::ISODate), rate, item->text(SOURCE_COL));
}
}
}
return price;
}
示例3: updateBudget
void KMyMoneyAccountTreeForecastItem::updateBudget()
{
MyMoneySecurity currency;
MyMoneyMoney tAmountMM;
MyMoneyFile* file = MyMoneyFile::instance();
int it_c = 1; // iterator for the columns of the listview
QDate forecastDate = m_forecast.forecastStartDate();
if(m_account.isInvest()) {
MyMoneySecurity underSecurity = file->security(m_account.currencyId());
currency = file->security(underSecurity.tradingCurrency());
} else {
currency = file->security(m_account.currencyId());
}
//iterate columns
for(; forecastDate <= m_forecast.forecastEndDate(); forecastDate = forecastDate.addMonths(1), ++it_c) {
MyMoneyMoney amountMM;
amountMM = m_forecast.forecastBalance(m_account,forecastDate);
if(m_account.accountType() == MyMoneyAccount::Expense)
amountMM = -amountMM;
tAmountMM += amountMM;
setAmount(it_c, amountMM);
setValue(it_c, amountMM, forecastDate);
showAmount(it_c, amountMM, currency);
}
//set total column
setAmount(it_c, tAmountMM);
setValue(it_c, tAmountMM, m_forecast.forecastEndDate());
showAmount(it_c, tAmountMM, currency);
}
示例4: updateDetailed
void KMyMoneyAccountTreeForecastItem::updateDetailed()
{
QString amount;
QString vAmount;
MyMoneyMoney vAmountMM;
MyMoneyFile* file = MyMoneyFile::instance();
MyMoneySecurity currency;
if(m_account.isInvest()) {
MyMoneySecurity underSecurity = file->security(m_account.currencyId());
currency = file->security(underSecurity.tradingCurrency());
} else {
currency = file->security(m_account.currencyId());
}
int it_c = 1; // iterator for the columns of the listview
for(QDate forecastDate = QDate::currentDate(); forecastDate <= m_forecast.forecastEndDate(); ++it_c, forecastDate = forecastDate.addDays(1)) {
MyMoneyMoney amountMM = m_forecast.forecastBalance(m_account, forecastDate);
//calculate the balance in base currency for the total row
setAmount(it_c, amountMM);
setValue(it_c, amountMM, forecastDate);
showAmount(it_c, amountMM, currency);
}
//calculate and add variation per cycle
vAmountMM = m_forecast.accountTotalVariation(m_account);
setAmount(it_c, vAmountMM);
setValue(it_c, vAmountMM, m_forecast.forecastEndDate());
showAmount(it_c, vAmountMM, currency);
}
示例5: addInvestment
void KEquityPriceUpdateDlg::addInvestment(const MyMoneySecurity& inv)
{
MyMoneyFile* file = MyMoneyFile::instance();
QString symbol = inv.tradingSymbol();
QString id = inv.id();
// Check that the pair does not already exist
if (lvEquityList->findItems(id, Qt::MatchExactly, ID_COL).empty()) {
// check that the security is still in use
QList<MyMoneyAccount>::const_iterator it_a;
QList<MyMoneyAccount> list;
file->accountList(list);
for (it_a = list.constBegin(); it_a != list.constEnd(); ++it_a) {
if ((*it_a).isInvest()
&& ((*it_a).currencyId() == inv.id())
&& !(*it_a).isClosed())
break;
}
// if it is in use, it_a is not equal to list.end()
if (it_a != list.constEnd()) {
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText(SYMBOL_COL, symbol);
item->setText(NAME_COL, inv.name());
MyMoneySecurity currency = file->currency(inv.tradingCurrency());
const MyMoneyPrice &pr = file->price(id.toUtf8(), inv.tradingCurrency());
if (pr.isValid()) {
item->setText(PRICE_COL, pr.rate(currency.id()).formatMoney(currency.tradingSymbol(), KMyMoneyGlobalSettings::pricePrecision()));
item->setText(DATE_COL, pr.date().toString(Qt::ISODate));
}
item->setText(ID_COL, id);
if (inv.value("kmm-online-quote-system") == "Finance::Quote")
item->setText(SOURCE_COL, QString("Finance::Quote %1").arg(inv.value("kmm-online-source")));
else
item->setText(SOURCE_COL, inv.value("kmm-online-source"));
lvEquityList->invisibleRootItem()->addChild(item);
// If this investment is denominated in a foreign currency, ensure that
// the appropriate price pair is also on the list
if (currency.id() != file->baseCurrency().id()) {
addPricePair(MyMoneySecurityPair(currency.id(), file->baseCurrency().id()));
}
}
}
}
示例6: loadAccounts
void KForecastView::loadAccounts(MyMoneyForecast& forecast, const MyMoneyAccount& account, QTreeWidgetItem* parentItem, int forecastType)
{
QMap<QString, QString> nameIdx;
QStringList accList;
MyMoneyFile* file = MyMoneyFile::instance();
QTreeWidgetItem *forecastItem = 0;
//Get all accounts of the right type to calculate forecast
accList = account.accountList();
if (accList.size() == 0)
return;
QStringList::ConstIterator accList_t;
for (accList_t = accList.constBegin(); accList_t != accList.constEnd(); ++accList_t) {
MyMoneyAccount subAccount = file->account(*accList_t);
//only add the account if it is a forecast account or the parent of a forecast account
if (includeAccount(forecast, subAccount)) {
nameIdx[subAccount.id()] = subAccount.id();
}
}
QMap<QString, QString>::ConstIterator it_nc;
for (it_nc = nameIdx.constBegin(); it_nc != nameIdx.constEnd(); ++it_nc) {
const MyMoneyAccount subAccount = file->account(*it_nc);
MyMoneySecurity currency;
if (subAccount.isInvest()) {
MyMoneySecurity underSecurity = file->security(subAccount.currencyId());
currency = file->security(underSecurity.tradingCurrency());
} else {
currency = file->security(subAccount.currencyId());
}
forecastItem = new QTreeWidgetItem(parentItem);
forecastItem->setText(0, subAccount.name());
forecastItem->setIcon(0, subAccount.accountPixmap());
forecastItem->setData(0, ForecastRole, QVariant::fromValue(forecast));
forecastItem->setData(0, AccountRole, QVariant::fromValue(subAccount));
forecastItem->setExpanded(true);
switch (forecastType) {
case eSummary:
updateSummary(forecastItem);
break;
case eDetailed:
updateDetailed(forecastItem);
break;
case eBudget:
updateBudget(forecastItem);
break;
default:
break;
}
loadAccounts(forecast, subAccount, forecastItem, forecastType);
}
}
示例7: doFutureScheduledForecast
void MyMoneyForecast::doFutureScheduledForecast(void)
{
MyMoneyFile* file = MyMoneyFile::instance();
if(isIncludingFutureTransactions())
addFutureTransactions();
if(isIncludingScheduledTransactions())
addScheduledTransactions();
//do not show accounts with no transactions
if(!isIncludingUnusedAccounts())
purgeForecastAccountsList(m_accountList);
//adjust value of investments to deep currency
QMap<QString, QString>::ConstIterator it_n;
for ( it_n = m_nameIdx.begin(); it_n != m_nameIdx.end(); ++it_n ) {
MyMoneyAccount acc = file->account ( *it_n );
if ( acc.isInvest() ) {
//get the id of the security for that account
MyMoneySecurity undersecurity = file->security ( acc.currencyId() );
//only do it if the security is not an actual currency
if ( ! undersecurity.isCurrency() )
{
//set the default value
MyMoneyMoney rate = MyMoneyMoney ( 1, 1 );
MyMoneyPrice price;
for (QDate it_day = QDate::currentDate(); it_day <= forecastEndDate(); ) {
//get the price for the tradingCurrency that day
price = file->price ( undersecurity.id(), undersecurity.tradingCurrency(), it_day );
if ( price.isValid() )
{
rate = price.rate ( undersecurity.tradingCurrency() );
}
//value is the amount of shares multiplied by the rate of the deep currency
m_accountList[acc.id() ][it_day] = m_accountList[acc.id() ][it_day] * rate;
it_day = it_day.addDays(1);
}
}
}
}
}
示例8:
/**
* Set the values based on the @param security
*/
void KInvestmentDetailsWizardPage::init2(const MyMoneySecurity& security)
{
MyMoneySecurity tradingCurrency = MyMoneyFile::instance()->currency(security.tradingCurrency());
m_investmentSymbol->setText(security.tradingSymbol());
m_tradingMarket->setCurrentIndex(m_tradingMarket->findText(security.tradingMarket(), Qt::MatchExactly));
m_fraction->setValue(MyMoneyMoney(security.smallestAccountFraction(), 1));
m_tradingCurrencyEdit->setSecurity(tradingCurrency);
m_investmentIdentification->setText(security.value("kmm-security-id"));
}
示例9: KListViewItem
KInvestmentListItem::KInvestmentListItem(KListView* parent, const MyMoneyAccount& account)
: KListViewItem(parent)
{
bColumn5Negative = false;
bColumn6Negative = false;
bColumn7Negative = false;
bColumn8Negative = false;
bColumn9Negative = false;
m_account = account;
m_listView = parent;
MyMoneySecurity security;
MyMoneyFile* file = MyMoneyFile::instance();
security = file->security(m_account.currencyId());
m_tradingCurrency = file->security(security.tradingCurrency());
int prec = MyMoneyMoney::denomToPrec(m_tradingCurrency.smallestAccountFraction());
QValueList<MyMoneyTransaction> transactionList;
// FIXME PRICE
// equity_price_history history = equity.priceHistory();
//column 0 (COLUMN_NAME_INDEX) is the name of the stock
setText(COLUMN_NAME_INDEX, m_account.name());
//column 1 (COLUMN_SYMBOL_INDEX) is the ticker symbol
setText(COLUMN_SYMBOL_INDEX, security.tradingSymbol());
//column 2 is the net value (price * quantity owned)
MyMoneyPrice price = file->price(m_account.currencyId(), m_tradingCurrency.id());
if(price.isValid()) {
setText(COLUMN_VALUE_INDEX, (file->balance(m_account.id()) * price.rate(m_tradingCurrency.id())).formatMoney(m_tradingCurrency.tradingSymbol(), prec));
} else {
setText(COLUMN_VALUE_INDEX, "---");
}
//column 3 (COLUMN_QUANTITY_INDEX) is the quantity of shares owned
prec = MyMoneyMoney::denomToPrec(security.smallestAccountFraction());
setText(COLUMN_QUANTITY_INDEX, file->balance(m_account.id()).formatMoney("", prec));
//column 4 is the current price
// Get the price precision from the configuration
prec = KMyMoneyGlobalSettings::pricePrecision();
// prec = MyMoneyMoney::denomToPrec(m_tradingCurrency.smallestAccountFraction());
if(price.isValid()) {
setText(COLUMN_PRICE_INDEX, price.rate(m_tradingCurrency.id()).formatMoney(m_tradingCurrency.tradingSymbol(), prec));
} else {
setText(COLUMN_PRICE_INDEX, "---");
}
}
示例10: currency
/**
* Fetch the trading currency of this account's currency
*
* @return The account's currency trading currency
*/
MyMoneySecurity ReportAccount::currency() const
{
MyMoneyFile* file = MyMoneyFile::instance();
// First, get the deep currency
MyMoneySecurity deepcurrency = file->security(currencyId());
if (! deepcurrency.isCurrency())
deepcurrency = file->security(deepcurrency.tradingCurrency());
// Return the deep currency's ID
return deepcurrency;
}
示例11: addPricePair
void KEquityPriceUpdateDlg::addPricePair(const MyMoneySecurityPair& pair, bool dontCheckExistance)
{
MyMoneyFile* file = MyMoneyFile::instance();
QString symbol = QString("%1 > %2").arg(pair.first, pair.second);
QString id = QString("%1 %2").arg(pair.first, pair.second);
// Check that the pair does not already exist
if (lvEquityList->findItems(id, Qt::MatchExactly, ID_COL).empty()) {
const MyMoneyPrice &pr = file->price(pair.first, pair.second);
if (pr.source() != "KMyMoney") {
bool keep = true;
if ((pair.first == file->baseCurrency().id())
|| (pair.second == file->baseCurrency().id())) {
const QString& foreignCurrency = file->foreignCurrency(pair.first, pair.second);
// check that the foreign currency is still in use
QList<MyMoneyAccount>::const_iterator it_a;
QList<MyMoneyAccount> list;
file->accountList(list);
for (it_a = list.constBegin(); !dontCheckExistance && it_a != list.constEnd(); ++it_a) {
// if it's an account denominated in the foreign currency
// keep it
if (((*it_a).currencyId() == foreignCurrency)
&& !(*it_a).isClosed())
break;
// if it's an investment traded in the foreign currency
// keep it
if ((*it_a).isInvest() && !(*it_a).isClosed()) {
MyMoneySecurity sec = file->security((*it_a).currencyId());
if (sec.tradingCurrency() == foreignCurrency)
break;
}
}
// if it is in use, it_a is not equal to list.end()
if (it_a == list.constEnd() && !dontCheckExistance)
keep = false;
}
if (keep) {
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText(SYMBOL_COL, symbol);
item->setText(NAME_COL, i18n("%1 units in %2", pair.first, pair.second));
if (pr.isValid()) {
item->setText(PRICE_COL, pr.rate(pair.second).formatMoney(file->currency(pair.second).tradingSymbol(), KMyMoneyGlobalSettings::pricePrecision()));
item->setText(DATE_COL, pr.date().toString(Qt::ISODate));
}
item->setText(ID_COL, id);
item->setText(SOURCE_COL, "Yahoo Currency"); // This string value should not be localized
lvEquityList->invisibleRootItem()->addChild(item);
}
}
}
}
示例12: updateSummary
void KForecastView::updateSummary(QTreeWidgetItem *item)
{
MyMoneyMoney amountMM;
int it_c = 1; // iterator for the columns of the listview
MyMoneyFile* file = MyMoneyFile::instance();
int daysToBeginDay;
MyMoneyForecast forecast = item->data(0, ForecastRole).value<MyMoneyForecast>();
if (QDate::currentDate() < forecast.beginForecastDate()) {
daysToBeginDay = QDate::currentDate().daysTo(forecast.beginForecastDate());
} else {
daysToBeginDay = forecast.accountsCycle();
}
MyMoneyAccount account = item->data(0, AccountRole).value<MyMoneyAccount>();
MyMoneySecurity currency;
if (account.isInvest()) {
MyMoneySecurity underSecurity = file->security(account.currencyId());
currency = file->security(underSecurity.tradingCurrency());
} else {
currency = file->security(account.currencyId());
}
//add current balance column
QDate summaryDate = QDate::currentDate();
amountMM = forecast.forecastBalance(account, summaryDate);
//calculate the balance in base currency for the total row
setAmount(item, it_c, amountMM);
setValue(item, it_c, amountMM, summaryDate);
showAmount(item, it_c, amountMM, currency);
it_c++;
//iterate through all other columns
for (QDate summaryDate = QDate::currentDate().addDays(daysToBeginDay); summaryDate <= forecast.forecastEndDate(); summaryDate = summaryDate.addDays(forecast.accountsCycle()), ++it_c) {
amountMM = forecast.forecastBalance(account, summaryDate);
//calculate the balance in base currency for the total row
setAmount(item, it_c, amountMM);
setValue(item, it_c, amountMM, summaryDate);
showAmount(item, it_c, amountMM, currency);
}
//calculate and add variation per cycle
setNegative(item, forecast.accountTotalVariation(account).isNegative());
setAmount(item, it_c, forecast.accountTotalVariation(account));
setValue(item, it_c, forecast.accountTotalVariation(account), forecast.forecastEndDate());
showAmount(item, it_c, forecast.accountTotalVariation(account), currency);
}
示例13: storePrices
void KEquityPriceUpdateDlg::storePrices()
{
// update the new prices into the equities
MyMoneyFile* file = MyMoneyFile::instance();
QList<MyMoneySecurity> equities = file->securityList();
QTreeWidgetItem* item = 0;
MyMoneyFileTransaction ft;
QString name;
try {
for (int i = 0; i < lvEquityList->invisibleRootItem()->childCount(); ++i) {
item = lvEquityList->invisibleRootItem()->child(i);
// turn on signals before we modify the last entry in the list
MyMoneyFile::instance()->blockSignals(i < lvEquityList->invisibleRootItem()->childCount() - 1);
MyMoneyMoney rate(item->text(PRICE_COL));
if (!rate.isZero()) {
QString id = item->text(ID_COL).toUtf8();
// if the ID has a space, then this is TWO ID's, so it's a currency quote
if (QString(id).contains(" ")) {
QStringList ids = id.split(' ', QString::SkipEmptyParts);
QString fromid = ids[0].toUtf8();
QString toid = ids[1].toUtf8();
name = QString("%1 --> %2").arg(fromid).arg(toid);
MyMoneyPrice price(fromid, toid, QDate().fromString(item->text(DATE_COL), Qt::ISODate), rate, item->text(SOURCE_COL));
file->addPrice(price);
} else
// otherwise, it's a security quote
{
MyMoneySecurity security = MyMoneyFile::instance()->security(id);
name = security.name();
MyMoneyPrice price(id, security.tradingCurrency(), QDate().fromString(item->text(DATE_COL), Qt::ISODate), rate, item->text(SOURCE_COL));
// TODO (Ace) Better handling of the case where there is already a price
// for this date. Currently, it just overrides the old value. Really it
// should check to see if the price is the same and prompt the user.
MyMoneyFile::instance()->addPrice(price);
}
}
}
ft.commit();
} catch (const MyMoneyException &) {
qDebug("Unable to add price information for %s", qPrintable(name));
}
}
示例14: if
QList<MyMoneyPrice> KForecastView::getAccountPrices(const MyMoneyAccount& acc)
{
MyMoneyFile* file = MyMoneyFile::instance();
QList<MyMoneyPrice> prices;
MyMoneySecurity security = file->baseCurrency();
try {
if (acc.isInvest()) {
security = file->security(acc.currencyId());
if (security.tradingCurrency() != file->baseCurrency().id()) {
MyMoneySecurity sec = file->security(security.tradingCurrency());
prices += file->price(sec.id(), file->baseCurrency().id());
}
} else if (acc.currencyId() != file->baseCurrency().id()) {
if (acc.currencyId() != file->baseCurrency().id()) {
security = file->security(acc.currencyId());
prices += file->price(acc.currencyId(), file->baseCurrency().id());
}
}
} catch (const MyMoneyException &e) {
qDebug() << Q_FUNC_INFO << " caught exception while adding " << acc.name() << "[" << acc.id() << "]: " << e.what();
}
return prices;
}
示例15: updateBudget
void KForecastView::updateBudget(QTreeWidgetItem *item)
{
MyMoneySecurity currency;
MyMoneyMoney tAmountMM;
MyMoneyForecast forecast = item->data(0, ForecastRole).value<MyMoneyForecast>();
MyMoneyFile* file = MyMoneyFile::instance();
int it_c = 1; // iterator for the columns of the listview
QDate forecastDate = forecast.forecastStartDate();
MyMoneyAccount account = item->data(0, AccountRole).value<MyMoneyAccount>();
if (account.isInvest()) {
MyMoneySecurity underSecurity = file->security(account.currencyId());
currency = file->security(underSecurity.tradingCurrency());
} else {
currency = file->security(account.currencyId());
}
//iterate columns
for (; forecastDate <= forecast.forecastEndDate(); forecastDate = forecastDate.addMonths(1), ++it_c) {
MyMoneyMoney amountMM;
amountMM = forecast.forecastBalance(account, forecastDate);
if (account.accountType() == MyMoneyAccount::Expense)
amountMM = -amountMM;
tAmountMM += amountMM;
setAmount(item, it_c, amountMM);
setValue(item, it_c, amountMM, forecastDate);
showAmount(item, it_c, amountMM, currency);
}
//set total column
setAmount(item, it_c, tAmountMM);
setValue(item, it_c, tAmountMM, forecast.forecastEndDate());
showAmount(item, it_c, tAmountMM, currency);
}