本文整理汇总了C++中DateRange::interval方法的典型用法代码示例。如果您正苦于以下问题:C++ DateRange::interval方法的具体用法?C++ DateRange::interval怎么用?C++ DateRange::interval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateRange
的用法示例。
在下文中一共展示了DateRange::interval方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: function
void
GUIWidget::downloadHistory ()
{
_log->clear();
setEnabled(FALSE);
_okButton->setEnabled(FALSE);
_cancelButton->setEnabled(TRUE);
DateRange dr;
QDateTime ed = QDateTime::currentDateTime();
QDateTime sd = dr.interval(ed, _range->currentIndex());
_timer->start(100);
YahooHistoryDownload function(this);
connect(&function, SIGNAL(signalMessage(QString)), _log, SLOT(append(const QString &)));
connect(_cancelButton, SIGNAL(clicked()), &function, SLOT(stop()));
function.download(_symbolButton->files(), sd, ed);
_timer->stop();
setEnabled(TRUE);
_okButton->setEnabled(TRUE);
_cancelButton->setEnabled(FALSE);
}
示例2: downloadHistory
void GUIWidget::downloadHistory ()
{
_log->clear();
setEnabled(FALSE);
_okButton->setEnabled(FALSE);
DateRange dr;
QDateTime ed = QDateTime::currentDateTime();
QDateTime sd = dr.interval(ed, DateRange::_YEAR5);
_timer->start(100);
NetfondsHistoryDownload function(this);
connect(&function, SIGNAL(signalMessage(QString)), _log, SLOT(append(const QString &)));
function.download(getTickers()); //, sd, ed);
_timer->stop();
setEnabled(TRUE);
_okButton->setEnabled(TRUE);
}
示例3: getBars
int Database::getBars (Bars *bd)
{
if (! bd)
return 0;
int length = bd->barLength();
if (length == -1)
{
qDebug() << "Database::getBars: invalid length";
return 0;
}
if (! getSymbol(bd))
return 0;
if (! init())
return 0;
// get last date in db
QDateTime endDate = getMaxDate(bd);
if (! endDate.isValid())
return 0;
DateRange dr;
//Don't bother to load less the all values into memory
//All computers are bound to be able handle this in year 2012
//If ever porting to a mobile device, change at that point
//bd->plotRange()
QDateTime startDate = dr.interval(endDate, DateRange::_ALL);
if (! startDate.isValid())
{
qDebug() << "Database::getBars: invalid range";
return 0;
}
QSqlQuery q(_db);
QString s = "SELECT date,open,high,low,close,volume";
s.append(" FROM " + bd->table());
s.append(" WHERE date >=" + startDate.toString("yyyyMMddHHmmss"));
s.append(" AND date <=" + endDate.toString("yyyyMMddHHmmss"));
s.append(" ORDER BY date ASC");
q.exec(s);
if (q.lastError().isValid())
{
qDebug() << "Database::getBars:" + q.lastError().text();
qDebug() << s;
return 0;
}
BarType bt;
BarLength bl;
QDateTime isDate, ieDate;
CBar *bar = 0;
while (q.next())
{
QDateTime lastDate = QDateTime::fromString(q.value(0).toString(), "yyyyMMddHHmmss");
// is date greater than current bar range?
if (lastDate >= ieDate || ! bar)
{
// save old bar
if (bar)
bd->setBar(bd->bars(), bar);
// create new bar
bl.interval(lastDate, bd->barLength(), isDate, ieDate);
bar = new CBar;
bar->setDate(lastDate);
bar->set(bt.indexToString(BarType::_OPEN), q.value(1).toDouble());
bar->set(bt.indexToString(BarType::_HIGH), q.value(2).toDouble());
bar->set(bt.indexToString(BarType::_LOW), q.value(3).toDouble());
bar->set(bt.indexToString(BarType::_CLOSE), q.value(4).toDouble());
bar->set(bt.indexToString(BarType::_VOLUME), q.value(5).toDouble());
}
else
{
double v = q.value(2).toDouble();
double v2;
bar->get(bt.indexToString(BarType::_HIGH), v2);
if (v > v2)
bar->set(bt.indexToString(BarType::_HIGH), v);
v = q.value(3).toDouble();
bar->get(bt.indexToString(BarType::_LOW), v2);
if (v < v2)
bar->set(bt.indexToString(BarType::_LOW), v);
bar->set(bt.indexToString(BarType::_CLOSE), q.value(4).toDouble());
v = q.value(5).toDouble();
bar->get(bt.indexToString(BarType::_VOLUME), v2);
v += v2;
bar->set(bt.indexToString(BarType::_VOLUME), v);
}
}
// save any left over bar
if (bar)
bd->setBar(bd->bars(), bar);
//.........这里部分代码省略.........
示例4: q
int
DBStock::getBars (PluginData *pd)
{
if (! init())
return 0;
if (! pd->bars)
return 0;
Bars *bd = pd->bars;
// get last date in db
QDateTime endDate = getMaxDate(bd);
if (! endDate.isValid())
return 0;
DateRange dr;
QDateTime startDate = dr.interval(endDate, bd->range());
if (! startDate.isValid())
{
qDebug() << "DBStock::getBars: invalid range";
return 0;
}
QSqlQuery q(_db);
QString s = "SELECT date,open,high,low,close,volume";
s.append(" FROM " + bd->table());
s.append(" WHERE date >=" + startDate.toString("yyyyMMddHHmmss"));
s.append(" AND date <=" + endDate.toString("yyyyMMddHHmmss"));
s.append(" ORDER BY date ASC");
q.exec(s);
if (q.lastError().isValid())
{
qDebug() << "DBStock::getBars:" + q.lastError().text();
qDebug() << s;
return 0;
}
BarType bt;
BarLength bl;
QDateTime isDate, ieDate;
CBar *bar = 0;
while (q.next())
{
QDateTime lastDate = QDateTime::fromString(q.value(0).toString(), "yyyyMMddHHmmss");
// is date greater than current bar range?
if (lastDate >= ieDate || ! bar)
{
// save old bar
if (bar)
bd->setBar(bd->bars(), bar);
// create new bar
bl.interval(lastDate, bd->length(), isDate, ieDate);
bar = new CBar;
bar->setDate(lastDate);
bar->set(bt.indexToString(BarType::_OPEN), q.value(1).toDouble());
bar->set(bt.indexToString(BarType::_HIGH), q.value(2).toDouble());
bar->set(bt.indexToString(BarType::_LOW), q.value(3).toDouble());
bar->set(bt.indexToString(BarType::_CLOSE), q.value(4).toDouble());
bar->set(bt.indexToString(BarType::_VOLUME), q.value(5).toDouble());
}
else
{
double v = q.value(2).toDouble();
double v2;
bar->get(bt.indexToString(BarType::_HIGH), v2);
if (v > v2)
bar->set(bt.indexToString(BarType::_HIGH), v);
v = q.value(3).toDouble();
bar->get(bt.indexToString(BarType::_LOW), v2);
if (v < v2)
bar->set(bt.indexToString(BarType::_LOW), v);
bar->set(bt.indexToString(BarType::_CLOSE), q.value(4).toDouble());
v = q.value(5).toDouble();
bar->get(bt.indexToString(BarType::_VOLUME), v2);
v += v2;
bar->set(bt.indexToString(BarType::_VOLUME), v);
}
}
// save any left over bar
if (bar)
bd->setBar(bd->bars(), bar);
return 1;
}