From 1a15462073d854674e4d745c6af0249a1d48452e Mon Sep 17 00:00:00 2001 From: Amit Chaudhuri Date: Thu, 18 Apr 2013 08:59:32 +0100 Subject: [PATCH] Use get_dive to populate divelistview with dives Add dives from dive_table to the model/view using the functions provided to extract the dives. We do not yet handle trips. Formatting of date/time, depth and duration need attention. Relies on earlier patch to delay Qt ui construction. We should look at the signals we publish to link to other widgets etc.. [Dirk Hohndel: use for_each_dive -- clean up some white space] Signed-off-by: Amit Chaudhuri Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index e81d9deab..de7bb5460 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "divelistview.h" #include "divetripmodel.h" @@ -28,31 +29,32 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()) * here we just use an empty string */ model = new DiveTripModel("",this); - if (model){ + if (model) { ui->ListWidget->setModel(model); } - /* add in dives here. - * we need to root to parent all top level dives + /* we need root to parent all top level dives * trips need more work as it complicates parent/child stuff. * - * We show how to obtain the root and add a demo dive - * - * Todo: work through integration with current list of dives/trips * Todo: look at alignment/format of e.g. duration in view + * */ DiveItem *dive = 0; DiveItem *root = model->itemForIndex(QModelIndex()); - if (root){ - dive = new DiveItem(1,QString("01/03/13"),14.2, 29.0,QString("Wraysbury"),root); - + if (root) { + int i; Q_UNUSED(dive) - qDebug("dive_table checks - number of dives is %d", dive_table.nr); - qDebug("# allocated dives = %d, pre-existing = %d", - dive_table.allocated, dive_table.preexisting); + struct dive *d; + qDebug("address of dive_table %p", &dive_table); + for_each_dive(i, d) { + dive = new DiveItem(d->number, + QDateTime::fromTime_t(d->when).toString(), + (float)d->maxdepth.mm/1000 , + (float)d->duration.seconds/60, + d->location, + root); + } } - - } void MainWindow::on_actionNew_triggered() @@ -63,7 +65,7 @@ void MainWindow::on_actionNew_triggered() void MainWindow::on_actionOpen_triggered() { QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter()); - if (filename.isEmpty()){ + if (filename.isEmpty()) { return; } @@ -295,7 +297,7 @@ bool MainWindow::askSaveChanges() QString message = ! existing_filename ? tr("You have unsaved changes\nWould you like to save those before closing the datafile?") : tr("You have unsaved changes to file: %1 \nWould you like to save those before closing the datafile?").arg(existing_filename); - if (QMessageBox::question(this, tr("Save Changes?"), message) == QMessageBox::Ok){ + if (QMessageBox::question(this, tr("Save Changes?"), message) == QMessageBox::Ok) { // WARNING: Port. // file_save(NULL,NULL); return true;