# HG changeset patch # User John Kern # Date 1270780312 25200 # Node ID 0f80a0f3947595ee3cd3a462e30a844f981832c6 # Parent a16afe3df8c9be0fb5cea00b259774d7389e3dc1 populate the nutrition table diff -r a16afe3df8c9 -r 0f80a0f39475 Seafood/Fishes.cpp --- a/Seafood/Fishes.cpp Tue Apr 06 08:02:52 2010 -0700 +++ b/Seafood/Fishes.cpp Thu Apr 08 19:31:52 2010 -0700 @@ -85,10 +85,10 @@ return detailsInHtml; } -void Fishes::getNutrition(QString name) +QMap Fishes::getNutrition(QString name) { QSqlQuery query; - QMap nutrition; + QMap nutrition; query.prepare("select calories,fat,protein,omega3,cholesterol,sodium from fish where name = :name "); query.bindValue(":name",name); @@ -100,19 +100,14 @@ } query.next(); - nutrition["Calories"] = query.value(0).toString(); - nutrition["Total Fat"] = query.value(1).toString(); - nutrition["Total Protein"] = query.value(2).toString(); - nutrition["Omega-3"] = query.value(3).toString(); - nutrition["Cholesterol"] = query.value(4).toString(); - nutrition["Sodium"] = query.value(5).toString(); + nutrition[ECalories] = query.value(0).toString(); + nutrition[ETotalFat] = query.value(1).toString(); + nutrition[ETotalProtein] = query.value(2).toString(); + nutrition[EOmega3] = query.value(3).toString(); + nutrition[ECholesterol] = query.value(4).toString(); + nutrition[ESodium] = query.value(5).toString(); - QMapIterator i(nutrition); - while (i.hasNext()) - { - i.next(); - qDebug() << i.key() << ": " << i.value() << endl; - } + return nutrition; } void Fishes::populate(TCATEGORIES cat) diff -r a16afe3df8c9 -r 0f80a0f39475 Seafood/Fishes.h --- a/Seafood/Fishes.h Tue Apr 06 08:02:52 2010 -0700 +++ b/Seafood/Fishes.h Thu Apr 08 19:31:52 2010 -0700 @@ -10,13 +10,15 @@ public: Fishes(QObject *parent=0); enum TCATEGORIES {EPresentBest=0, EPresentOK, EPresentWorst}; + enum TNUTRITION {ECalories = 0, ETotalFat, ETotalProtein, + EOmega3, ECholesterol, ESodium, EMaxNutrients }; const QStringList getBest(); const QStringList getOK(); const QStringList getWorst(); QString getEcoDetails(QString name); - void getNutrition(QString name); + QMap getNutrition(QString name); private: void populate(TCATEGORIES cat); diff -r a16afe3df8c9 -r 0f80a0f39475 Seafood/SeafoodTabbed.pro.user --- a/Seafood/SeafoodTabbed.pro.user Tue Apr 06 08:02:52 2010 -0700 +++ b/Seafood/SeafoodTabbed.pro.user Thu Apr 08 19:31:52 2010 -0700 @@ -103,8 +103,97 @@ + ProjectExplorer.Project.Target.1 + + Symbian Device + Qt4ProjectManager.Target.S60DeviceTarget + 0 + 0 + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + C:\workspace\QtExamples\Seafood + false + 13 + 6 + false + + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + false + 3 + 6 + false + + + 2 + + SeafoodTabbed on Symbian Device + Qt4ProjectManager.S60DeviceRunConfiguration + + + + SeafoodTabbed.pro + + 0 + + 1 + + + ProjectExplorer.Project.TargetCount - 1 + 2 ProjectExplorer.Project.Updater.FileVersion diff -r a16afe3df8c9 -r 0f80a0f39475 Seafood/mainwindow.cpp --- a/Seafood/mainwindow.cpp Tue Apr 06 08:02:52 2010 -0700 +++ b/Seafood/mainwindow.cpp Thu Apr 08 19:31:52 2010 -0700 @@ -1,4 +1,6 @@ #include +#include + #include #include #include #include @@ -52,14 +54,9 @@ this->stackedWidget->addWidget(this->ecoDetails); // associated with EEcoPage // Nutrition page - // this->model = new QSqlQueryModel; - // this->model-> this->stackedWidget->addWidget(ui->centralWidget); // associated with ENutritionPage - setCentralWidget(stackedWidget); - - } MainWindow::~MainWindow() @@ -146,8 +143,31 @@ if (selectedName.isEmpty()) { QMessageBox::information(this,"warning","select an item from list." ); } else { - // this->ecoDetails->setHtml( this->fishDb->getNutrition(selectedName)); - this->fishDb->getNutrition(selectedName); + + QMap nutrition (this->fishDb->getNutrition(selectedName)); + + const int COLUMN = 1; + int row=0; + + QTableWidgetItem *newItem; + newItem = new QTableWidgetItem(nutrition[Fishes::ECalories] ); + this->ui->tableWidget->setItem(row++,COLUMN, newItem); + + newItem = new QTableWidgetItem(nutrition[Fishes::ETotalFat] ); + this->ui->tableWidget->setItem(row++,COLUMN, newItem); + + newItem = new QTableWidgetItem(nutrition[Fishes::ETotalProtein] ); + this->ui->tableWidget->setItem(row++,COLUMN, newItem); + + newItem = new QTableWidgetItem(nutrition[Fishes::EOmega3] ); + this->ui->tableWidget->setItem(row++,COLUMN, newItem); + + newItem = new QTableWidgetItem(nutrition[Fishes::ECholesterol] ); + this->ui->tableWidget->setItem(row++,COLUMN, newItem); + + newItem = new QTableWidgetItem(nutrition[Fishes::ESodium] ); + this->ui->tableWidget->setItem(row,COLUMN, newItem); + this->stackedWidget->setCurrentIndex(MainWindow::ENutritionPage); } } diff -r a16afe3df8c9 -r 0f80a0f39475 Seafood/mainwindow.ui --- a/Seafood/mainwindow.ui Tue Apr 06 08:02:52 2010 -0700 +++ b/Seafood/mainwindow.ui Thu Apr 08 19:31:52 2010 -0700 @@ -18,9 +18,9 @@ 0 - 0 - 258 - 242 + 10 + 221 + 351 @@ -54,7 +54,70 @@ - + + + false + + + QAbstractItemView::NoEditTriggers + + + 6 + + + 2 + + + false + + + false + + + false + + + false + + + + + + + + + + + + Calories + + + + + Total Fat + + + + + Total Protein + + + + + Omega-3 + + + + + Cholesterol + + + + + Sodium + + + @@ -72,7 +135,7 @@ 0 0 361 - 20 + 21 diff -r a16afe3df8c9 -r 0f80a0f39475 Seafood/ui_mainwindow.h --- a/Seafood/ui_mainwindow.h Tue Apr 06 08:02:52 2010 -0700 +++ b/Seafood/ui_mainwindow.h Thu Apr 08 19:31:52 2010 -0700 @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading UI file 'mainwindow.ui' ** -** Created: Thu Apr 1 11:35:19 2010 +** Created: Thu Apr 8 19:28:20 2010 ** by: Qt User Interface Compiler version 4.6.2 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! @@ -51,7 +51,7 @@ centralWidget->setObjectName(QString::fromUtf8("centralWidget")); layoutWidget = new QWidget(centralWidget); layoutWidget->setObjectName(QString::fromUtf8("layoutWidget")); - layoutWidget->setGeometry(QRect(0, 0, 258, 242)); + layoutWidget->setGeometry(QRect(0, 10, 221, 351)); verticalLayout = new QVBoxLayout(layoutWidget); verticalLayout->setSpacing(6); verticalLayout->setContentsMargins(11, 11, 11, 11); @@ -79,7 +79,29 @@ verticalLayout->addWidget(amountServing); tableWidget = new QTableWidget(layoutWidget); + if (tableWidget->columnCount() < 2) + tableWidget->setColumnCount(2); + if (tableWidget->rowCount() < 6) + tableWidget->setRowCount(6); + QTableWidgetItem *__qtablewidgetitem = new QTableWidgetItem(); + tableWidget->setItem(0, 0, __qtablewidgetitem); + QTableWidgetItem *__qtablewidgetitem1 = new QTableWidgetItem(); + tableWidget->setItem(1, 0, __qtablewidgetitem1); + QTableWidgetItem *__qtablewidgetitem2 = new QTableWidgetItem(); + tableWidget->setItem(2, 0, __qtablewidgetitem2); + QTableWidgetItem *__qtablewidgetitem3 = new QTableWidgetItem(); + tableWidget->setItem(3, 0, __qtablewidgetitem3); + QTableWidgetItem *__qtablewidgetitem4 = new QTableWidgetItem(); + tableWidget->setItem(4, 0, __qtablewidgetitem4); + QTableWidgetItem *__qtablewidgetitem5 = new QTableWidgetItem(); + tableWidget->setItem(5, 0, __qtablewidgetitem5); tableWidget->setObjectName(QString::fromUtf8("tableWidget")); + tableWidget->setAutoScroll(false); + tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); + tableWidget->setRowCount(6); + tableWidget->setColumnCount(2); + tableWidget->horizontalHeader()->setVisible(false); + tableWidget->verticalHeader()->setVisible(false); verticalLayout->addWidget(tableWidget); @@ -91,7 +113,7 @@ MainWindow->setCentralWidget(centralWidget); menuBar = new QMenuBar(MainWindow); menuBar->setObjectName(QString::fromUtf8("menuBar")); - menuBar->setGeometry(QRect(0, 0, 361, 20)); + menuBar->setGeometry(QRect(0, 0, 361, 21)); MainWindow->setMenuBar(menuBar); mainToolBar = new QToolBar(MainWindow); mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); @@ -110,6 +132,23 @@ MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8)); header->setText(QApplication::translate("MainWindow", "Nutrition information", 0, QApplication::UnicodeUTF8)); amountServing->setText(QApplication::translate("MainWindow", " Amount per serving", 0, QApplication::UnicodeUTF8)); + + const bool __sortingEnabled = tableWidget->isSortingEnabled(); + tableWidget->setSortingEnabled(false); + QTableWidgetItem *___qtablewidgetitem = tableWidget->item(0, 0); + ___qtablewidgetitem->setText(QApplication::translate("MainWindow", "Calories", 0, QApplication::UnicodeUTF8)); + QTableWidgetItem *___qtablewidgetitem1 = tableWidget->item(1, 0); + ___qtablewidgetitem1->setText(QApplication::translate("MainWindow", "Total Fat", 0, QApplication::UnicodeUTF8)); + QTableWidgetItem *___qtablewidgetitem2 = tableWidget->item(2, 0); + ___qtablewidgetitem2->setText(QApplication::translate("MainWindow", "Total Protein", 0, QApplication::UnicodeUTF8)); + QTableWidgetItem *___qtablewidgetitem3 = tableWidget->item(3, 0); + ___qtablewidgetitem3->setText(QApplication::translate("MainWindow", "Omega-3", 0, QApplication::UnicodeUTF8)); + QTableWidgetItem *___qtablewidgetitem4 = tableWidget->item(4, 0); + ___qtablewidgetitem4->setText(QApplication::translate("MainWindow", "Cholesterol", 0, QApplication::UnicodeUTF8)); + QTableWidgetItem *___qtablewidgetitem5 = tableWidget->item(5, 0); + ___qtablewidgetitem5->setText(QApplication::translate("MainWindow", "Sodium", 0, QApplication::UnicodeUTF8)); + tableWidget->setSortingEnabled(__sortingEnabled); + usda->setText(QApplication::translate("MainWindow", "Source: USDA", 0, QApplication::UnicodeUTF8)); } // retranslateUi