本文整理汇总了C++中MyMoneyFile::addPrice方法的典型用法代码示例。如果您正苦于以下问题:C++ MyMoneyFile::addPrice方法的具体用法?C++ MyMoneyFile::addPrice怎么用?C++ MyMoneyFile::addPrice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyMoneyFile
的用法示例。
在下文中一共展示了MyMoneyFile::addPrice方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makePrice
void makePrice(const QString& _currencyid, const QDate& _date, const MyMoneyMoney& _price )
{
MyMoneyFileTransaction ft;
MyMoneyFile* file = MyMoneyFile::instance();
MyMoneySecurity curr = file->currency(_currencyid);
MyMoneyPrice price(_currencyid, file->baseCurrency().id(), _date, _price, "test");
file->addPrice(price);
ft.commit();
}
示例2: makeEquityPrice
void makeEquityPrice(const QString& _id, const QDate& _date, const MyMoneyMoney& _price )
{
MyMoneyFile* file = MyMoneyFile::instance();
MyMoneyFileTransaction ft;
QString basecurrencyid = file->baseCurrency().id();
MyMoneyPrice price = file->price( _id, basecurrencyid, _date, true );
if ( !price.isValid() )
{
MyMoneyPrice newprice( _id, basecurrencyid, _date, _price, "test" );
file->addPrice(newprice);
}
ft.commit();
}
示例3: 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));
}
}
示例4: init
void InvTransactionHelper::init( const QDate& _date, const QString& _action, MyMoneyMoney _shares, MyMoneyMoney _price, const QString& _stockaccountid, const QString& _transferid, const QString& _categoryid )
{
MyMoneyFile* file = MyMoneyFile::instance();
MyMoneyAccount stockaccount = file->account(_stockaccountid);
MyMoneyMoney value = _shares * _price;
setPostDate(_date);
setCommodity("USD");
MyMoneySplit s1;
s1.setValue(value);
s1.setAccountId(_stockaccountid);
if ( _action == MyMoneySplit::ActionReinvestDividend )
{
s1.setShares(_shares);
s1.setAction(MyMoneySplit::ActionReinvestDividend);
MyMoneySplit s2;
s2.setAccountId(_categoryid);
s2.setShares(-value);
s2.setValue(-value);
addSplit(s2);
}
else if ( _action == MyMoneySplit::ActionDividend || _action == MyMoneySplit::ActionYield )
{
s1.setAccountId(_categoryid);
s1.setShares(-value);
s1.setValue(-value);
// Split 2 will be the zero-amount investment split that serves to
// mark this transaction as a cash dividend and note which stock account
// it belongs to.
MyMoneySplit s2;
s2.setValue(0);
s2.setShares(0);
s2.setAction(_action);
s2.setAccountId(_stockaccountid);
addSplit(s2);
MyMoneySplit s3;
s3.setAccountId(_transferid);
s3.setShares(value);
s3.setValue(value);
addSplit(s3);
}
else if ( _action == MyMoneySplit::ActionBuyShares )
{
s1.setShares(_shares);
s1.setAction(MyMoneySplit::ActionBuyShares);
MyMoneySplit s3;
s3.setAccountId(_transferid);
s3.setShares(-value);
s3.setValue(-value);
addSplit(s3);
}
addSplit(s1);
//kdDebug(2) << "created transaction, now adding..." << endl;
MyMoneyFileTransaction ft;
file->addTransaction(*this);
//kdDebug(2) << "updating price..." << endl;
// update the price, while we're here
QString stockid = stockaccount.currencyId();
QString basecurrencyid = file->baseCurrency().id();
MyMoneyPrice price = file->price( stockid, basecurrencyid, _date, true );
if ( !price.isValid() )
{
MyMoneyPrice newprice( stockid, basecurrencyid, _date, _price, "test" );
file->addPrice(newprice);
}
ft.commit();
//kdDebug(2) << "successfully added " << id() << endl;
}