Пример #1
0
Food Food::parseElement( const QDomElement &element, bool *ok )
{
  if ( element.tagName() != "food" ) {
    qCritical() << "Expected 'food', got '" <<element.tagName() << "'.";
    if ( ok ) *ok = false;
    return Food();
  }

  Food result = Food();

  QDomNode n;
  for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    QDomElement e = n.toElement();
    if ( e.tagName() == "name" ) {
      result.setName( e.text() );
    }
    else if ( e.tagName() == "taste" ) {
      result.setTaste( e.text() );
    }
  }


  if ( ok ) *ok = true;
  return result;
}
Пример #2
0
void AdminWindow::populateFoodList()
{
    listFood = new QListWidget();


    QWidget *widget = new QWidget();
    QVBoxLayout *layout = new QVBoxLayout();

    QSqlQuery query;
    query.prepare("SELECT * FROM Foods");
    bool r = query.exec();
    if(r == true)
    {
        while(query.next())
        {
          //  qDebug()<<"Food Selected: "<<query.record().value("name").toString();
            //======================
            QListWidgetItem* item = new QListWidgetItem();
            item->setSizeHint(QSize(0,60));



            FoodRow *catagory = new FoodRow();
            Food *food = new Food();
            food->setName(query.record().value("Name").toString());
            food->setCatagroy(query.record().value("Catagory").toString());
            food->setPrice(query.record().value("Price").toFloat());



            catagory->SetFood(food);
            layout->addWidget(catagory);


            connect(catagory, SIGNAL(signal_foodRemoved(QString)), this, SLOT(onFoodRemoved(QString)));
            connect(catagory, SIGNAL(signal_foodEdited(Food*)), this, SLOT(onFoodEdited(Food*)));


        }



        widget->setLayout(layout);
        ui->scrollArea_FoodAdd->setWidget(widget);



    }
}