Merge branch 'NicolasMerge' into devel
This commit is contained in:
commit
50f7560033
1 changed files with 16 additions and 18 deletions
|
@ -41,18 +41,8 @@ void PriceUpdater::updatePrices()
|
||||||
*/
|
*/
|
||||||
void PriceUpdater::downloadFinished()
|
void PriceUpdater::downloadFinished()
|
||||||
{
|
{
|
||||||
QMap<QString, DecklistCardNode *> cmap;
|
|
||||||
InnerDecklistNode *listRoot = deck->getRoot();
|
|
||||||
for (int i = 0; i < listRoot->size(); i++) {
|
|
||||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
|
||||||
for (int j = 0; j < currentZone->size(); j++) {
|
|
||||||
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
|
||||||
if (!currentCard)
|
|
||||||
continue;
|
|
||||||
cmap.insert(currentCard->getName().toLower(), currentCard);
|
|
||||||
currentCard->setPrice(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
||||||
QByteArray result = reply->readAll();
|
QByteArray result = reply->readAll();
|
||||||
|
@ -60,21 +50,29 @@ void PriceUpdater::downloadFinished()
|
||||||
QScriptEngine engine;
|
QScriptEngine engine;
|
||||||
sc = engine.evaluate("value = " + result);
|
sc = engine.evaluate("value = " + result);
|
||||||
|
|
||||||
|
QMap<QString, float> cardsPrice;
|
||||||
|
|
||||||
if (sc.property("cards").isArray()) {
|
if (sc.property("cards").isArray()) {
|
||||||
QScriptValueIterator it(sc.property("cards"));
|
QScriptValueIterator it(sc.property("cards"));
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
QString name = it.value().property("name").toString().toLower();
|
QString name = it.value().property("name").toString().toLower();
|
||||||
float price = it.value().property("average").toString().toFloat();
|
float price = it.value().property("average").toString().toFloat();
|
||||||
DecklistCardNode *c = cmap[name];
|
cardsPrice.insert(name, price);
|
||||||
if (!c)
|
|
||||||
continue;
|
|
||||||
if (c->getPrice() == 0 || c->getPrice() > price) {
|
|
||||||
c->setPrice(price);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InnerDecklistNode *listRoot = deck->getRoot();
|
||||||
|
for (int i = 0; i < listRoot->size(); i++) {
|
||||||
|
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||||
|
for (int j = 0; j < currentZone->size(); j++) {
|
||||||
|
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||||
|
if (!currentCard)
|
||||||
|
continue;
|
||||||
|
currentCard->setPrice(cardsPrice[currentCard->getName().toLower()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
deleteLater();
|
deleteLater();
|
||||||
emit finishedUpdate();
|
emit finishedUpdate();
|
||||||
|
|
Loading…
Reference in a new issue