예제 #1
0
Dish* Ingridients::readDish(const QJsonObject& json) {
    PRINT_DEBUG("Reading new dish");

    QJsonArray itemsList = json["items"].toArray();
    Food* newFood = readFood(itemsList[0].toObject()["food"].toObject());
    Dish* newDish = new Dish(json["name"].toString().toStdString(), newFood,
                             itemsList[0].toObject()["amount"].toInt());

    avaliableItems.push_back(newFood);
    newFood->addItemList(&avaliableItems);

    for ( int index = 1; index < itemsList.size(); index++ ) {
        newFood = readFood(itemsList[index].toObject()["food"].toObject());
        newDish->addFood(newFood, itemsList[index].toObject()["amount"].toInt());
        std::list<Item*>::iterator it;

        for ( it = avaliableItems.begin(); ; it++ ) {
            if ( !(*it)->getName().compare(newFood->getName()) ) {
                delete newFood;

                break;
            } else if ( it == avaliableItems.end() ) {
                avaliableItems.push_back(newFood);
                newFood->addItemList(&avaliableItems);
            }
        }
    }

    return newDish;
}
예제 #2
0
void Ingridients::loadFood(const QJsonArray& jsonArray) {
    PRINT_DEBUG("Loading food");

    for ( int i = 0; i < jsonArray.size(); i++ ) {
        Food* newFood = readFood(jsonArray[i].toObject());
        std::list<Item*>::iterator it;

        for ( it = avaliableItems.begin(); ; it++ ) {
            if ( !(*it)->getName().compare(newFood->getName()) ) {
                delete newFood;

                break;
            } else if ( it == avaliableItems.end() ) {
                avaliableItems.push_back(newFood);
                newFood->addItemList(&avaliableItems);
            }
        }
    }
}