Seafood/mainwindow.cpp
changeset 10 79eeacfd15ff
parent 7 7ee47a65f1ad
child 11 f3dbeee07821
--- a/Seafood/mainwindow.cpp	Fri Mar 26 15:19:41 2010 -0700
+++ b/Seafood/mainwindow.cpp	Fri Mar 26 15:22:34 2010 -0700
@@ -18,36 +18,48 @@
 {
     ui->setupUi(this);
     setContextMenuPolicy(Qt::NoContextMenu);
-    Fishes *f = new Fishes();
+    this->fishDb = new Fishes(this);
 
     this->stackedWidget = new QStackedWidget;
 
+    // lists of fish
     this->tabWidget = new QTabWidget;
-    // QIcon icon = new QIcon(":/database/icons/weather-sunny.svg");
-    // this->tabWidget->setTabIcon(1, icon);
 
     this->bestList = new QListWidget;
-    this->bestList->addItems(f->GetBest());
+    this->bestList->addItems(this->fishDb->GetBest());
     this->tabWidget->addTab(this->bestList, "best");
 
     this->okList = new QListWidget;
-    this->okList->addItems(f->GetOK());
+    this->okList->addItems(this->fishDb->GetOK());
     this->tabWidget->addTab(this->okList, "ok");
 
     this->worstList = new QListWidget;
-    this->worstList->addItems(f->GetWorst());
+    this->worstList->addItems(this->fishDb->GetWorst());
     this->tabWidget->addTab(this->worstList, "worst");
 
+    this->index = EBestList;
+
+    connect(this->tabWidget, SIGNAL(currentChanged(int)),
+            this, SLOT(setCurrentList(int)));
+
     this->stackedWidget->addWidget(tabWidget); // associated with EListPage
 
+    // Eco details
+
     this->ecoDetails = new QWebView;
     this->ecoDetails->setHtml("<html><title>Eco Details</title><ul><li>not yet implemented</li></ul></html>");
 
     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()
@@ -81,8 +93,7 @@
 
 void MainWindow::displayVersion()
 {
-//    QMessageBox::information(this,"Qt Version", qVersion());
-     QMessageBox::information(this,"selected item", "NYI");
+    QMessageBox::information(this,"Qt Version", qVersion());
 }
 
 void MainWindow::displayNutrition()
@@ -92,6 +103,23 @@
 
 void MainWindow::displayEcoDetails()
 {
+
+    QString selectedName;
+    switch (this->index)
+    {
+    case EBestList:
+        selectedName = this->bestList->currentItem()->text();
+        break;
+    case EOkList:
+        selectedName = this->okList->currentItem()->text();
+        break;
+    case EWorstList:
+        selectedName = this->worstList->currentItem()->text();
+        break;
+    }
+
+    this->ecoDetails->setHtml( this->fishDb->getEcoDetails(selectedName));
+
     this->stackedWidget->setCurrentIndex(MainWindow::EEcoPage);
 }
 
@@ -114,6 +142,24 @@
 
 }
 
+void MainWindow::setCurrentList(int l)
+{
+    switch (l)
+    {
+    case 0:
+        this->index = EBestList;
+        break;
+    case 1:
+        this->index = EOkList;
+        break;
+    case 2:
+        this->index = EWorstList;
+        break;
+    }
+
+
+}
+
 void MainWindow::changeEvent(QEvent *e)
 {
     QMainWindow::changeEvent(e);