--- 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::TNUTRITION, QString> Fishes::getNutrition(QString name)
{
QSqlQuery query;
- QMap<QString, QString> nutrition;
+ QMap<TNUTRITION, QString> 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<QString, QString> i(nutrition);
- while (i.hasNext())
- {
- i.next();
- qDebug() << i.key() << ": " << i.value() << endl;
- }
+ return nutrition;
}
void Fishes::populate(TCATEGORIES cat)
--- 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<TNUTRITION, QString> getNutrition(QString name);
private:
void populate(TCATEGORIES cat);
--- 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 @@
</valuemap>
</data>
<data>
+ <variable>ProjectExplorer.Project.Target.1</variable>
+ <valuemap type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Symbian Device</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Target.S60DeviceTarget</value>
+ <value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">0</value>
+ <value key="ProjectExplorer.Target.ActiveRunConfiguration" type="int">0</value>
+ <valuemap key="ProjectExplorer.Target.BuildConfiguration.0" type="QVariantMap">
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">qmake</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
+ <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
+ </valuemap>
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
+ <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
+ <value type="QString">clean</value>
+ </valuelist>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Debug</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">C:\workspace\QtExamples\Seafood</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">13</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">6</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">false</value>
+ <valuelist key="Qt4ProjectManager.Qt4BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
+ </valuemap>
+ <valuemap key="ProjectExplorer.Target.BuildConfiguration.1" type="QVariantMap">
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">qmake</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
+ <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
+ </valuemap>
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
+ <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
+ <value type="QString">clean</value>
+ </valuelist>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Release</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString"></value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">3</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">6</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">false</value>
+ <valuelist key="Qt4ProjectManager.Qt4BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
+ </valuemap>
+ <value key="ProjectExplorer.Target.BuildConfigurationCount" type="int">2</value>
+ <valuemap key="ProjectExplorer.Target.RunConfiguration.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">SeafoodTabbed on Symbian Device</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.S60DeviceRunConfiguration</value>
+ <valuelist key="Qt4ProjectManager.S60DeviceRunConfiguration.CommandLineArguments" type="QVariantList"/>
+ <value key="Qt4ProjectManager.S60DeviceRunConfiguration.CustomKeyPath" type="QString"></value>
+ <value key="Qt4ProjectManager.S60DeviceRunConfiguration.CustomSignaturePath" type="QString"></value>
+ <value key="Qt4ProjectManager.S60DeviceRunConfiguration.ProFile" type="QString">SeafoodTabbed.pro</value>
+ <value key="Qt4ProjectManager.S60DeviceRunConfiguration.SerialPortName" type="QString"></value>
+ <value key="Qt4ProjectManager.S60DeviceRunConfiguration.SigningMode" type="int">0</value>
+ </valuemap>
+ <value key="ProjectExplorer.Target.RunConfigurationCount" type="int">1</value>
+ </valuemap>
+ </data>
+ <data>
<variable>ProjectExplorer.Project.TargetCount</variable>
- <value type="int">1</value>
+ <value type="int">2</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
--- 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 <QFile>
+#include <QtGlobal>
+ #include <QDebug>
#include <QIcon>
#include <QListWidget>
#include <QMessageBox>
@@ -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<Fishes::TNUTRITION, QString> 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);
}
}
--- 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 @@
<property name="geometry">
<rect>
<x>0</x>
- <y>0</y>
- <width>258</width>
- <height>242</height>
+ <y>10</y>
+ <width>221</width>
+ <height>351</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -54,7 +54,70 @@
</widget>
</item>
<item>
- <widget class="QTableWidget" name="tableWidget"/>
+ <widget class="QTableWidget" name="tableWidget">
+ <property name="autoScroll">
+ <bool>false</bool>
+ </property>
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ <property name="rowCount">
+ <number>6</number>
+ </property>
+ <property name="columnCount">
+ <number>2</number>
+ </property>
+ <attribute name="horizontalHeaderVisible">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="verticalHeaderVisible">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="verticalHeaderVisible">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="horizontalHeaderVisible">
+ <bool>false</bool>
+ </attribute>
+ <row/>
+ <row/>
+ <row/>
+ <row/>
+ <row/>
+ <row/>
+ <column/>
+ <column/>
+ <item row="0" column="0">
+ <property name="text">
+ <string>Calories</string>
+ </property>
+ </item>
+ <item row="1" column="0">
+ <property name="text">
+ <string>Total Fat</string>
+ </property>
+ </item>
+ <item row="2" column="0">
+ <property name="text">
+ <string>Total Protein</string>
+ </property>
+ </item>
+ <item row="3" column="0">
+ <property name="text">
+ <string>Omega-3</string>
+ </property>
+ </item>
+ <item row="4" column="0">
+ <property name="text">
+ <string>Cholesterol</string>
+ </property>
+ </item>
+ <item row="5" column="0">
+ <property name="text">
+ <string>Sodium</string>
+ </property>
+ </item>
+ </widget>
</item>
<item>
<widget class="QLabel" name="usda">
@@ -72,7 +135,7 @@
<x>0</x>
<y>0</y>
<width>361</width>
- <height>20</height>
+ <height>21</height>
</rect>
</property>
</widget>
--- 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