本文整理汇总了C++中QMap::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ QMap::empty方法的具体用法?C++ QMap::empty怎么用?C++ QMap::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMap
的用法示例。
在下文中一共展示了QMap::empty方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addRemoveMakefileam
//.........这里部分代码省略.........
int len = newLine.length();
bool added = false;
QValueList<QString> keys = ourRhs->keys();
for (uint count = 0; count < keys.size(); count++)
{
// if out entry is true, add it..
if ((*ourRhs)[keys[count]])
{
added = true;
len += keys[count].length() + 1;
if (len > 80)
{
newLine += "\\\n\t";
len = 8;
}
newLine += keys[count];
newLine += ' ';
// set our value so we don't add it again.
(*ourRhs)[keys[count]] = false;
}
}
// only print it out if there was a value to add..
if (added)
{
newLine.setLength(newLine.length() - 1);
outs << newLine << endl;
}
}
else
{
// we are removing our interested values from this line
// special case - no values, remove the line..
if (!ourRhs->empty())
{
// check if any of these values are down to remove.
QString newLine(lhs);
if (seenLhs.find(lhs) == seenLhs.end())
{
newLine += " = ";
seenLhs[lhs] = "";
}
else
{
newLine += " += ";
}
int len = newLine.length();
bool added = false;
for (QStringList::Iterator posIter = bits.begin(); posIter != bits.end();posIter++)
{
QMap<QString, bool>::iterator findEntry = ourRhs->find(*posIter);
if (findEntry == ourRhs->end())
{
// we do not want to remove it..
added = true;
len += (*posIter).length() + 1;
if (len > 80)
{
newLine += "\\\n\t";
len = 8;
}
newLine += (*posIter);
newLine += ' ';
}
// else we have this value in our 'to remove list', so don't add it.
示例2: bestRateOrder
Order changeTrendAgent::bestRateOrder()
{
QMap<double, Order> bestOrders;
for(int i = 2; i <= STOKS_NUMBER; ++i)
{
double diffForSell = m_stocksInfo[i].lowestPrice(m_lowestBuyTime) - m_stocksInfo[i].greatestPrice(m_greatestBuyTime);
if(m_store.contains(i) && m_stocksInfo[i].lastPrice() && diffForSell > 0.001 &&
( (m_stocksInfo[i].getBestSellPrice()*1.005 <= m_store.getMoney() && m_stocksInfo[i].getBestSellPrice()) ||
(m_stocksInfo[i].lastPrice() <= m_store.getMoney()) ) )
{
bestOrders.insertMulti(diffForSell, Order(Order::SELL, i, 0, 0));
}
double diffForBuy = m_stocksInfo[i].lowestPrice(m_lowestSellTime) - m_stocksInfo[i].greatestPrice(m_greatestSellTime);
if( m_stocksInfo[i].lastPrice() && diffForBuy > 0.001 &&
( (m_stocksInfo[i].getBestBuyPrice()*1.025 <= m_store.getMoney() && m_stocksInfo[i].getBestBuyPrice()) ||
(m_stocksInfo[i].lastPrice() <= m_store.getMoney()) ))
{
bestOrders.insertMulti(diffForBuy, Order(Order::BUY, i, 0, 0));
}
}
if(bestOrders.empty())
return Order();
QMutableMapIterator<double, Order> i(bestOrders);
while (i.hasNext()) {
i.next();
if((1.0*qrand())/RAND_MAX < m_bestChooseChance)
{
Order order = i.value();
qint32 price;
if(m_stocksInfo[order.getStockId()].getBestSellPrice() && m_stocksInfo[order.getStockId()].getBestBuyPrice())
{
if(order.getTransactionType() == Order::SELL)
{
price = m_stocksInfo[order.getStockId()].getBestSellPrice()*(1.005 - (0.03*qrand())/RAND_MAX);
}
else
{
price = m_stocksInfo[order.getStockId()].getBestBuyPrice()*(0.095 + (0.03*qrand())/RAND_MAX);
}
}
else price = m_stocksInfo[order.getStockId()].lastPrice();
if(!price)
continue;
order.setPrice(price);
qint32 maxAmount = m_store.getMoney()/price;
double rand = (1.0*qrand())/RAND_MAX;
qint32 amount = 3 + qrand()%13;
if(rand > 0.45 && rand < 0.88)
amount = 16 + qrand()%35;
else if(rand >= 0.88)
amount = 51 + qrand()%75;
if(maxAmount)
amount %= maxAmount;
order.setAmount(amount);
if(order.getAmount()&& order.getPrice())
return order;
}
}
Order order = i.value();
qint32 price;
if(m_stocksInfo[order.getStockId()].getBestSellPrice() && m_stocksInfo[order.getStockId()].getBestBuyPrice())
{
if(order.getTransactionType() == Order::SELL)
{
price = m_stocksInfo[order.getStockId()].getBestSellPrice()*(1.005 - (0.03*qrand())/RAND_MAX);
}
else
{
price = m_stocksInfo[order.getStockId()].getBestBuyPrice()*(0.095 + (0.03*qrand())/RAND_MAX);
}
}
else price = m_stocksInfo[order.getStockId()].lastPrice();
if(!price)
return Order();
order.setPrice(price);
qint32 maxAmount = m_store.getMoney()/price;
double rand = (1.0*qrand())/RAND_MAX;
qint32 amount = 3 + qrand()%13;
if(rand > 0.45 && rand < 0.88)
amount = 16 + qrand()%35;
else if(rand >= 0.88)
amount = 51 + qrand()%75;
if(maxAmount)
amount %= maxAmount;
order.setAmount(amount);
if(order.getAmount()&& order.getPrice())
return order;
else return Order();
}
示例3: AudioOutputPulseAudio
AudioOutput *AudioOutput::OpenAudio(AudioSettings &settings,
bool willsuspendpa)
{
QString &main_device = settings.main_device;
AudioOutput *ret = NULL;
// Don't suspend Pulse if unnecessary. This can save 100mS
if (settings.format == FORMAT_NONE || settings.channels <= 0)
willsuspendpa = false;
#ifdef USING_PULSE
bool pulsestatus = false;
#else
{
static bool warned = false;
if (!warned && IsPulseAudioRunning())
{
warned = true;
LOG(VB_GENERAL, LOG_WARNING,
"WARNING: ***Pulse Audio is running***");
}
}
#endif
settings.FixPassThrough();
if (main_device.startsWith("PulseAudio:"))
{
#ifdef USING_PULSEOUTPUT
return new AudioOutputPulseAudio(settings);
#else
LOG(VB_GENERAL, LOG_ERR, "Audio output device is set to PulseAudio "
"but PulseAudio support is not compiled in!");
return NULL;
#endif
}
else if (main_device.startsWith("NULL"))
{
return new AudioOutputNULL(settings);
}
#ifdef USING_PULSE
if (willsuspendpa)
{
bool ispulse = false;
#ifdef USING_ALSA
// Check if using ALSA, that the device doesn't contain the word
// "pulse" in its hint
if (main_device.startsWith("ALSA:"))
{
QString device_name = main_device;
device_name.remove(0, 5);
QMap<QString, QString> *alsadevs =
AudioOutputALSA::GetDevices("pcm");
if (!alsadevs->empty() && alsadevs->contains(device_name))
{
if (alsadevs->value(device_name).contains("pulse",
Qt::CaseInsensitive))
{
ispulse = true;
}
}
delete alsadevs;
}
#endif
if (main_device.contains("pulse", Qt::CaseInsensitive))
{
ispulse = true;
}
if (!ispulse)
{
pulsestatus = PulseHandler::Suspend(PulseHandler::kPulseSuspend);
}
}
#endif
if (main_device.startsWith("ALSA:"))
{
#ifdef USING_ALSA
settings.TrimDeviceType();
ret = new AudioOutputALSA(settings);
#else
LOG(VB_GENERAL, LOG_ERR, "Audio output device is set to an ALSA device "
"but ALSA support is not compiled in!");
#endif
}
else if (main_device.startsWith("JACK:"))
{
#ifdef USING_JACK
settings.TrimDeviceType();
ret = new AudioOutputJACK(settings);
#else
LOG(VB_GENERAL, LOG_ERR, "Audio output device is set to a JACK device "
"but JACK support is not compiled in!");
#endif
}
else if (main_device.startsWith("DirectX:"))
{
#ifdef _WIN32
//.........这里部分代码省略.........
示例4: loadFile
CC_FILE_ERROR PhotoScanFilter::loadFile(const QString& filename,
ccHObject& container,
LoadParameters& parameters)
{
QuaZip zip(filename);
if (!zip.open(QuaZip::mdUnzip))
{
//failed to open or read the zip file
return CC_FERR_READING;
}
QStringList fileList = zip.getFileNameList();
if (fileList.isEmpty())
{
//empty archive?
return CC_FERR_NO_LOAD;
}
static const QString s_defaultXMLFilename("doc.xml");
if (!fileList.contains(s_defaultXMLFilename))
{
//empty archive?
ccLog::Warning(QString("[Photoscan] Couldn't find '%1' in Photoscan archive").arg(s_defaultXMLFilename));
return CC_FERR_NO_LOAD;
}
//look for the XML file
if (!zip.setCurrentFile(s_defaultXMLFilename))
{
ccLog::Warning(QString("[Photoscan] Failed to locate '%1' in the Photoscan archive").arg(s_defaultXMLFilename));
return CC_FERR_MALFORMED_FILE;
}
//decompress the XML file
QuaZipFile zipXML(&zip);
if (!zipXML.open(QFile::ReadOnly))
{
ccLog::Warning(QString("[Photoscan] Failed to extract '%1' from Photoscan archive").arg(s_defaultXMLFilename));
return CC_FERR_NO_LOAD;
}
QXmlStreamReader stream(&zipXML);
//expected: "document"
if (!stream.readNextStartElement() || stream.name() != "document")
{
return CC_FERR_MALFORMED_FILE;
}
std::vector<Sections> sections;
sections.push_back(DOCUMENT);
QMap<int, ccCameraSensor*> sensors;
QMap<int, CameraDesc> cameras;
QList<CloudDesc> clouds;
QList<MeshDesc> meshes;
ccGLMatrixd globalTransform;
bool hasGlobalTransform = false;
while (true)
{
if (!stream.readNextStartElement())
{
//end of section?
if (!sections.empty())
{
ccLog::PrintDebug(" < " + stream.name().toString() + QString(" [%1]").arg(ToName(sections.back())));
sections.pop_back();
//stream.skipCurrentElement();
continue;
}
else
{
//end of file
break;
}
}
ccLog::PrintDebug(" > " + stream.name().toString());
switch (sections.back())
{
case DOCUMENT:
if (stream.name() == "chunks")
{
sections.push_back(CHUNKS);
}
else
{
//not handled
stream.skipCurrentElement();
}
break;
case CHUNKS:
if (stream.name() == "chunk")
{
sections.push_back(CHUNK);
}
//.........这里部分代码省略.........
示例5: file
QMap<QString, Utente *> *FileManager::caricaUtenti() const {
QMap<QString, Utente*>* lista = new QMap<QString, Utente*>();
QXmlStreamReader rxml;
QFile file(_fileNameUtenti);
if (file.open(QFile::ReadOnly | QFile::Text))
{
rxml.setDevice(&file);
rxml.readNext();
QString username, password, nome, cognome, tipo;
bool isAdmin = false;
bool utenteAperto = false;
while(!rxml.atEnd())
{
if(rxml.isStartElement())
{
if(rxml.name() == "Utenti")
rxml.readNext();
else if(rxml.name() == "Utente")
{
utenteAperto = true;
while(!rxml.atEnd())
{
if(rxml.isEndElement())
{
if(utenteAperto)
{
if(tipo == "1")
{
lista->insert(username,
(new UtenteBasic(username, password, isAdmin))
->setNome(nome)->setCognome(cognome));
}
else if(tipo == "2")
{
lista->insert(username,
(new UtenteBusiness(username, password, isAdmin))
->setNome(nome)->setCognome(cognome));
}
else
{
lista->insert(username,
(new UtenteExecutive(username, password, isAdmin))
->setNome(nome)->setCognome(cognome));
}
utenteAperto = false;
}
rxml.readNext();
break;
}
else if(rxml.isCharacters())
rxml.readNext();
else if(rxml.isStartElement())
{
if(rxml.name() == "Username")
username = rxml.readElementText();
else if(rxml.name() == "Password")
password = rxml.readElementText();
else if(rxml.name() == "Tipo")
tipo = rxml.readElementText();
else if(rxml.name() == "IsAdmin")
isAdmin = rxml.readElementText() == "true" ? true : false;
else if(rxml.name() == "Nome")
nome = rxml.readElementText();
else if(rxml.name() == "Cognome")
cognome = rxml.readElementText();
rxml.readNext();
}
else
rxml.readNext();
}
}
}
else
rxml.readNext();
}
file.close();
}
if(lista->empty())
lista->insert("matteo",
(new UtenteExecutive("matteo", "matteo", true))
->setNome("Matteo")->setCognome("Bortolazzo"));
return lista;
}
示例6: tr
void
BestIntervalDialog::findClicked()
{
const RideFile *ride = mainWindow->currentRide();
if (!ride) {
QMessageBox::critical(this, tr("Select Ride"), tr("No ride selected!"));
return;
}
int maxIntervals = (int) countSpinBox->value();
double windowSizeSecs = (hrsSpinBox->value() * 3600.0
+ minsSpinBox->value() * 60.0
+ secsSpinBox->value());
if (windowSizeSecs == 0.0) {
QMessageBox::critical(this, tr("Bad Interval Length"),
tr("Interval length must be greater than zero!"));
return;
}
QList<const RideFilePoint*> window;
QMap<double,double> bests;
double secsDelta = ride->recIntSecs();
int expectedSamples = (int) floor(windowSizeSecs / secsDelta);
double totalWatts = 0.0;
foreach (const RideFilePoint *point, ride->dataPoints()) {
while (!window.empty()
&& (point->secs >= window.first()->secs + windowSizeSecs)) {
totalWatts -= window.first()->watts;
window.takeFirst();
}
totalWatts += point->watts;
window.append(point);
int divisor = std::max(window.size(), expectedSamples);
double avg = totalWatts / divisor;
bests.insertMulti(avg, point->secs);
}
QMap<double,double> results;
while (!bests.empty() && maxIntervals--) {
QMutableMapIterator<double,double> j(bests);
j.toBack();
j.previous();
double secs = j.value();
results.insert(j.value() - windowSizeSecs, j.key());
j.remove();
while (j.hasPrevious()) {
j.previous();
if (abs(secs - j.value()) < windowSizeSecs)
j.remove();
}
}
QString resultsHtml =
"<center>"
"<table width=\"80%\">"
"<tr><td align=\"center\">Start Time</td>"
" <td align=\"center\">Average Power</td></tr>";
QMapIterator<double,double> j(results);
while (j.hasNext()) {
j.next();
double secs = j.key();
double mins = ((int) secs) / 60;
secs = secs - mins * 60.0;
double hrs = ((int) mins) / 60;
mins = mins - hrs * 60.0;
QString row =
"<tr><td align=\"center\">%1:%2:%3</td>"
" <td align=\"center\">%4</td></tr>";
row = row.arg(hrs, 0, 'f', 0);
row = row.arg(mins, 2, 'f', 0, QLatin1Char('0'));
row = row.arg(secs, 2, 'f', 0, QLatin1Char('0'));
row = row.arg(j.value(), 0, 'f', 0, QLatin1Char('0'));
resultsHtml += row;
}
resultsHtml += "</table></center>";
resultsText->setHtml(resultsHtml);
}
示例7:
const QMap<QString, QChar> &
Translator::namedEntities()
{
static QMap<QString, QChar> entities;
if(entities.empty()) {
entities["quot"] = 34;
entities["amp"] = 38;
entities["lt"] = 60;
entities["gt"] = 62;
entities["oelig"] = 338;
entities["oelig"] = 339;
entities["scaron"] = 352;
entities["scaron"] = 353;
entities["yuml"] = 376;
entities["circ"] = 710;
entities["tilde"] = 732;
entities["ensp"] = 8194;
entities["emsp"] = 8195;
entities["thinsp"] = 8201;
entities["zwnj"] = 8204;
entities["zwj"] = 8205;
entities["lrm"] = 8206;
entities["rlm"] = 8207;
entities["ndash"] = 8211;
entities["mdash"] = 8212;
entities["lsquo"] = 8216;
entities["rsquo"] = 8217;
entities["sbquo"] = 8218;
entities["ldquo"] = 8220;
entities["rdquo"] = 8221;
entities["bdquo"] = 8222;
entities["dagger"] = 8224;
entities["dagger"] = 8225;
entities["permil"] = 8240;
entities["lsaquo"] = 8249;
entities["rsaquo"] = 8250;
entities["euro"] = 8364;
entities["fnof"] = 402;
entities["alpha"] = 913;
entities["beta"] = 914;
entities["gamma"] = 915;
entities["delta"] = 916;
entities["epsilon"] = 917;
entities["zeta"] = 918;
entities["eta"] = 919;
entities["theta"] = 920;
entities["iota"] = 921;
entities["kappa"] = 922;
entities["lambda"] = 923;
entities["mu"] = 924;
entities["nu"] = 925;
entities["xi"] = 926;
entities["omicron"] = 927;
entities["pi"] = 928;
entities["rho"] = 929;
entities["sigma"] = 931;
entities["tau"] = 932;
entities["upsilon"] = 933;
entities["phi"] = 934;
entities["chi"] = 935;
entities["psi"] = 936;
entities["omega"] = 937;
entities["alpha"] = 945;
entities["beta"] = 946;
entities["gamma"] = 947;
entities["delta"] = 948;
entities["epsilon"] = 949;
entities["zeta"] = 950;
entities["eta"] = 951;
entities["theta"] = 952;
entities["iota"] = 953;
entities["kappa"] = 954;
entities["lambda"] = 955;
entities["mu"] = 956;
entities["nu"] = 957;
entities["xi"] = 958;
entities["omicron"] = 959;
entities["pi"] = 960;
entities["rho"] = 961;
entities["sigmaf"] = 962;
entities["sigma"] = 963;
entities["tau"] = 964;
entities["upsilon"] = 965;
entities["phi"] = 966;
entities["chi"] = 967;
entities["psi"] = 968;
entities["omega"] = 969;
entities["thetasym"] = 977;
entities["upsih"] = 978;
entities["piv"] = 982;
entities["bull"] = 8226;
entities["hellip"] = 8230;
entities["prime"] = 8242;
entities["prime"] = 8243;
entities["oline"] = 8254;
entities["frasl"] = 8260;
entities["weierp"] = 8472;
entities["image"] = 8465;
entities["real"] = 8476;
entities["trade"] = 8482;
//.........这里部分代码省略.........
示例8: AudioOutputPulseAudio
AudioOutput *AudioOutput::OpenAudio(AudioSettings &settings,
bool willsuspendpa)
{
QString &main_device = settings.main_device;
AudioOutput *ret = NULL;
#ifdef USING_PULSE
bool pulsestatus = false;
#else
{
static bool warned = false;
if (!warned && IsPulseAudioRunning())
{
warned = true;
VERBOSE(VB_IMPORTANT, "WARNING: ***Pulse Audio is running***");
}
}
#endif
settings.FixPassThrough();
if (main_device.startsWith("PulseAudio:"))
{
#ifdef USING_PULSEOUTPUT
return new AudioOutputPulseAudio(settings);
#else
VERBOSE(VB_IMPORTANT, "Audio output device is set to PulseAudio "
"but PulseAudio support is not compiled in!");
return NULL;
#endif
}
else if (main_device.startsWith("NULL"))
{
return new AudioOutputNULL(settings);
}
#ifdef USING_PULSE
if (willsuspendpa)
{
bool ispulse = false;
#ifdef USE_ALSA
// Check if using ALSA, that the device doesn't contain the word
// "pulse" in its hint
if (main_device.startsWith("ALSA:"))
{
QString device_name = main_device;
device_name.remove(0, 5);
QMap<QString, QString> *alsadevs =
AudioOutputALSA::GetALSADevices("pcm");
if (!alsadevs->empty() && alsadevs->contains(device_name))
{
if (alsadevs->value(device_name).contains("pulse",
Qt::CaseInsensitive))
{
ispulse = true;
}
}
delete alsadevs;
}
#endif
if (main_device.contains("pulse", Qt::CaseInsensitive))
{
ispulse = true;
}
if (!ispulse)
{
pulsestatus = PulseHandler::Suspend(PulseHandler::kPulseSuspend);
}
}
#endif
if (main_device.startsWith("ALSA:"))
{
#ifdef USE_ALSA
settings.TrimDeviceType();
ret = new AudioOutputALSA(settings);
#else
VERBOSE(VB_IMPORTANT, "Audio output device is set to an ALSA device "
"but ALSA support is not compiled in!");
#endif
}
else if (main_device.startsWith("JACK:"))
{
#ifdef USE_JACK
settings.TrimDeviceType();
ret = new AudioOutputJACK(settings);
#else
VERBOSE(VB_IMPORTANT, "Audio output device is set to a JACK device "
"but JACK support is not compiled in!");
#endif
}
else if (main_device.startsWith("DirectX:"))
{
#ifdef USING_MINGW
ret = new AudioOutputDX(settings);
#else
VERBOSE(VB_IMPORTANT, "Audio output device is set to DirectX device "
"but DirectX support is not compiled in!");
#endif
//.........这里部分代码省略.........
示例9: bestRateOrder
Order TrendFollowerAgent::bestRateOrder()
{
QMap<double, Order> bestOrders;
for(int i = 2; i <= STOKS_NUMBER; ++i)
{
if(m_store.contains(i) && m_stocksInfo[i].lastPrice() &&
( (m_stocksInfo[i].getBestSellPrice()*1.005 <= m_store.getMoney() && m_stocksInfo[i].getBestSellPrice()) ||
(m_stocksInfo[i].lastPrice() <= m_store.getMoney()) ) )
{
double upTrendValue1 = m_stocksInfo[i].trendValue(m_upTrendTime);
double upTrendValue2 = 2*m_stocksInfo[i].trendValue(m_upTrendTime/2);
double upTrendValue = 0;
if(upTrendValue1 && upTrendValue2)
upTrendValue = - 1.0/upTrendValue1 - 1.0/upTrendValue2;
bestOrders.insertMulti(upTrendValue, Order(Order::SELL, i, 0, 0));
}
double downTrendValue = - m_stocksInfo[i].trendValue(m_downTrendTime) - 2*m_stocksInfo[i].trendValue(m_downTrendTime/2);
if( m_stocksInfo[i].lastPrice() &&
( (m_stocksInfo[i].getBestBuyPrice()*1.025 <= m_store.getMoney() && m_stocksInfo[i].getBestBuyPrice()) ||
(m_stocksInfo[i].lastPrice() <= m_store.getMoney()) ))
{
bestOrders.insertMulti(downTrendValue, Order(Order::BUY, i, 0, 0));
}
}
if(bestOrders.empty())
return Order();
QMutableMapIterator<double, Order> i(bestOrders);
while (i.hasNext()) {
i.next();
if((1.0*qrand())/RAND_MAX < m_bestChooseChance)
{
Order order = i.value();
qint32 price;
if(m_stocksInfo[order.getStockId()].getBestSellPrice() && m_stocksInfo[order.getStockId()].getBestBuyPrice())
{
if(order.getTransactionType() == Order::SELL)
{
price = m_stocksInfo[order.getStockId()].getBestSellPrice()*(1.005 - (0.03*qrand())/RAND_MAX);
}
else
{
price = m_stocksInfo[order.getStockId()].getBestBuyPrice()*(0.095 + (0.03*qrand())/RAND_MAX);
}
}
else price = m_stocksInfo[order.getStockId()].lastPrice();
if(!price)
continue;
order.setPrice(price);
qint32 maxAmount = m_store.getMoney()/price;
qint32 amount = pow(pow(std::min(-i.key()/3.0, 1.075), 25.0 + qrand()%10), 2.0 + static_cast<double>(qrand())/RAND_MAX) *
(1 + static_cast<double>(2*qrand())/RAND_MAX) + 2 + qrand() % 5;
if(maxAmount)
amount %= maxAmount;
order.setAmount(amount);
if(order.getAmount()&& order.getPrice())
return order;
}
}
Order order = i.value();
qint32 price;
if(m_stocksInfo[order.getStockId()].getBestSellPrice() && m_stocksInfo[order.getStockId()].getBestBuyPrice())
{
if(order.getTransactionType() == Order::SELL)
{
price = m_stocksInfo[order.getStockId()].getBestSellPrice()*(1.005 - (0.03*qrand())/RAND_MAX);
}
else
{
price = m_stocksInfo[order.getStockId()].getBestBuyPrice()*(0.095 + (0.03*qrand())/RAND_MAX);
}
}
else price = m_stocksInfo[order.getStockId()].lastPrice();
if(!price)
return Order();
order.setPrice(price);
qint32 maxAmount = m_store.getMoney()/price;
qint32 amount = pow(pow(std::min(-i.key()/3.0, 1.075), 25.0 + qrand()%10), 2.0 + static_cast<double>(qrand())/RAND_MAX) *
(1 + static_cast<double>(2*qrand())/RAND_MAX) + 2 + qrand() % 5;
if(maxAmount)
amount %= maxAmount;
order.setAmount(amount);
if(order.getAmount()&& order.getPrice())
return order;
else return Order();
}
示例10: importStart
//.........这里部分代码省略.........
}
else
var = QVariant(value);
break;
}
default: // Nothing
var = QVariant(QString::null);
}
}
else
var = QVariant(value);
break;
}
case CSVMapField::Action_UseEmptyString:
{
var = QVariant(QString(""));
break;
}
case CSVMapField::Action_UseAlternateValue:
{
var = QVariant(fields.at(i).valueAlt());
break;
}
case CSVMapField::Action_UseNull:
{
var = QVariant(QString::null);
break;
}
default:
continue;
}
label = ":" + fields.at(i).name();
if(!values.empty())
{
front += ", ";
back += ", ";
}
values.insert(label, var);
front += fields.at(i).name();
back += label;
}
if(values.empty())
{
ignored++;
errMsg = QString("IGNORED Record %1: There are no columns to insert").arg(current+1);
errorList.append(errMsg);
continue;
}
front += ") ";
back += ")";
query += front + back;
QSqlQuery qry;
qry.prepare(query);
QMap<QString,QVariant>::iterator vit;
for(vit = values.begin(); vit != values.end(); ++vit)
qry.bindValue(vit.key(), vit.value());
if(!qry.exec())
{
if(usetransaction) QSqlQuery sprollback("ROLLBACK TO SAVEPOINT csvinsert;");
error++;
errMsg = QString("ERROR Record %1: %2").arg(current+1).arg(qry.lastError().text());
示例11: extractUserDetails
GroupWise::ContactDetails PollSearchResultsTask::extractUserDetails( Field::FieldList & fields )
{
ContactDetails cd;
cd.status = GroupWise::Invalid;
cd.archive = false;
// read the supplied fields, set metadata and status.
Field::SingleField * sf;
if ( ( sf = fields.findSingleField ( Field::NM_A_SZ_AUTH_ATTRIBUTE ) ) )
cd.authAttribute = sf->value().toString();
if ( ( sf = fields.findSingleField ( Field::NM_A_SZ_DN ) ) )
cd.dn =sf->value().toString().toLower(); // HACK: lowercased DN
if ( ( sf = fields.findSingleField ( Field::KOPETE_NM_USER_DETAILS_CN ) ) )
cd.cn = sf->value().toString();
if ( ( sf = fields.findSingleField ( Field::KOPETE_NM_USER_DETAILS_GIVEN_NAME ) ) )
cd.givenName = sf->value().toString();
if ( ( sf = fields.findSingleField ( Field::KOPETE_NM_USER_DETAILS_SURNAME ) ) )
cd.surname = sf->value().toString();
if ( ( sf = fields.findSingleField ( Field::KOPETE_NM_USER_DETAILS_FULL_NAME ) ) )
cd.fullName = sf->value().toString();
if ( ( sf = fields.findSingleField ( Field::KOPETE_NM_USER_DETAILS_ARCHIVE_FLAG ) ) )
cd.archive = ( sf->value().toInt() == 1 );
if ( ( sf = fields.findSingleField ( Field::NM_A_SZ_STATUS ) ) )
cd.status = sf->value().toInt();
if ( ( sf = fields.findSingleField ( Field::NM_A_SZ_MESSAGE_BODY ) ) )
cd.awayMessage = sf->value().toString();
Field::MultiField * mf;
QMap< QString, QVariant > propMap;
if ( ( mf = fields.findMultiField ( Field::NM_A_FA_INFO_DISPLAY_ARRAY ) ) )
{
Field::FieldList fl = mf->fields();
const Field::FieldListIterator end = fl.end();
for ( Field::FieldListIterator it = fl.begin(); it != end; ++it )
{
// assumes each property only present once
// check in logintask.cpp and if it's a multi field,
// get the value of this instance, check if it's already in the property map and append if found.
Field::SingleField * propField = dynamic_cast<Field::SingleField *>( *it );
if ( propField )
{
QString propName = propField->tag();
QString propValue = propField->value().toString();
propMap.insert( propName, propValue );
}
else
{
Field::MultiField * propList = dynamic_cast<Field::MultiField*>( *it );
if ( propList )
{
QString parentName = propList->tag();
Field::FieldList propFields = propList->fields();
const Field::FieldListIterator end = propFields.end();
for ( Field::FieldListIterator it = propFields.begin(); it != end; ++it )
{
propField = dynamic_cast<Field::SingleField *>( *it );
if ( propField )
{
QString propValue = propField->value().toString();
QString contents = propMap[ propField->tag() ].toString();
if ( !contents.isEmpty() )
contents.append( ", " );
contents.append( propField->value().toString());
propMap.insert( propField->tag(), contents );
}
}
}
}
}
}
if ( !propMap.empty() )
{
cd.properties = propMap;
}
return cd;
}