summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--conversions.h16
-rw-r--r--equipment.c6
-rw-r--r--qt-gui.cpp8
-rw-r--r--qt-ui/addcylinderdialog.cpp48
-rw-r--r--qt-ui/addcylinderdialog.h24
-rw-r--r--qt-ui/addcylinderdialog.ui303
-rw-r--r--qt-ui/maintab.cpp68
-rw-r--r--qt-ui/maintab.h17
-rw-r--r--qt-ui/maintab.ui12
-rw-r--r--qt-ui/mainwindow.cpp107
-rw-r--r--qt-ui/mainwindow.h3
-rw-r--r--qt-ui/models.cpp175
-rw-r--r--qt-ui/models.h44
14 files changed, 823 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 9e8e69b2d..81e3648c9 100644
--- a/Makefile
+++ b/Makefile
@@ -177,13 +177,15 @@ ifneq ($(strip $(LIBXSLT)),)
XSLT=-DXSLT='"$(XSLTDIR)"'
endif
-LIBS = $(LIBQT) $(LIBXML2) $(LIBXSLT) $(LIBSQLITE3) $(LIBGTK) $(LIBGCONF2) $(LIBDIVECOMPUTER) $(EXTRALIBS) $(LIBZIP) -lpthread -lm $(LIBOSMGPSMAP) $(LIBSOUP) $(LIBWINSOCK)
+LIBS = $(LIBQT) $(LIBXML2) $(LIBXSLT) $(LIBSQLITE3) $(LIBGTK) $(LIBGCONF2) $(LIBDIVECOMPUTER) \
+ $(EXTRALIBS) $(LIBZIP) -lpthread -lm $(LIBOSMGPSMAP) $(LIBSOUP) $(LIBWINSOCK)
MSGLANGS=$(notdir $(wildcard po/*.po))
MSGOBJS=$(addprefix share/locale/,$(MSGLANGS:.po=.UTF-8/LC_MESSAGES/subsurface.mo))
-QTOBJS = qt-ui/maintab.o qt-ui/mainwindow.o qt-ui/plotareascene.o qt-ui/divelistview.o qt-ui/divetripmodel.o
+QTOBJS = qt-ui/maintab.o qt-ui/mainwindow.o qt-ui/plotareascene.o qt-ui/divelistview.o \
+ qt-ui/divetripmodel.o qt-ui/addcylinderdialog.o qt-ui/models.o
OBJS = main.o dive.o time.o profile.o info.o equipment.o divelist.o divelist-gtk.o deco.o \
planner.o planner-gtk.o \
diff --git a/conversions.h b/conversions.h
new file mode 100644
index 000000000..f59fcc96b
--- /dev/null
+++ b/conversions.h
@@ -0,0 +1,16 @@
+/*
+ * conversions.h
+ *
+ * Helpers to convert between different units
+ *
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void convert_volume_pressure(int ml, int mbar, double *v, double *p);
+int convert_pressure(int mbar, double *p);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/equipment.c b/equipment.c
index 2d90f7a52..a1d156f94 100644
--- a/equipment.c
+++ b/equipment.c
@@ -18,6 +18,7 @@
#include "display.h"
#include "display-gtk.h"
#include "divelist.h"
+#include "conversions.h"
static GtkListStore *cylinder_model, *weightsystem_model;
@@ -70,7 +71,7 @@ struct ws_widget {
};
/* we want bar - so let's not use our unit functions */
-static int convert_pressure(int mbar, double *p)
+int convert_pressure(int mbar, double *p)
{
int decimals = 1;
double pressure;
@@ -86,7 +87,7 @@ static int convert_pressure(int mbar, double *p)
return decimals;
}
-static void convert_volume_pressure(int ml, int mbar, double *v, double *p)
+void convert_volume_pressure(int ml, int mbar, double *v, double *p)
{
double volume, pressure;
@@ -724,6 +725,7 @@ static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl
/*
* Also, insert it into the model if it doesn't already exist
*/
+ // WARNING: GTK-Specific Code.
add_cylinder(cylinder, desc, ml, mbar);
}
diff --git a/qt-gui.cpp b/qt-gui.cpp
index e667e97bf..745457763 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -126,6 +126,7 @@ static void on_info_bar_response(GtkWidget *widget, gint response,
void report_error(GError* error)
{
+ qDebug("Warning: Calling GTK-Specific Code.");
if (error == NULL)
{
return;
@@ -253,6 +254,8 @@ static void file_save(GtkWidget *w, gpointer data)
static gboolean ask_save_changes()
{
+ //WARNING: Porting to Qt
+ qDebug("This method is being ported to Qt, please, stop using it. ");
GtkWidget *dialog, *label, *content;
gboolean quit = TRUE;
dialog = gtk_dialog_new_with_buttons(_("Save Changes?"),
@@ -291,6 +294,7 @@ static gboolean ask_save_changes()
static void file_close(GtkWidget *w, gpointer data)
{
+ qDebug("Calling an already ported-to-qt Gtk method");
if (unsaved_changes())
if (ask_save_changes() == FALSE)
return;
@@ -319,8 +323,12 @@ static void file_close(GtkWidget *w, gpointer data)
show_dive_info(NULL);
}
+//#####################################################################
+//###### ALREAADY PORTED TO Qt. DELETE ME WHEN NOT MORE USERFUL. #
+//#####################################################################
static void file_open(GtkWidget *w, gpointer data)
{
+ qDebug("Calling an already ported-to-qt Gtk method.");
GtkWidget *dialog;
GtkFileFilter *filter;
const char *current_default;
diff --git a/qt-ui/addcylinderdialog.cpp b/qt-ui/addcylinderdialog.cpp
new file mode 100644
index 000000000..6f2294a25
--- /dev/null
+++ b/qt-ui/addcylinderdialog.cpp
@@ -0,0 +1,48 @@
+#include "addcylinderdialog.h"
+#include "ui_addcylinderdialog.h"
+#include <QComboBox>
+#include <QDoubleSpinBox>
+#include "../conversions.h"
+
+
+AddCylinderDialog::AddCylinderDialog(QWidget *parent) : ui(new Ui::AddCylinderDialog())
+{
+ ui->setupUi(this);
+}
+
+void AddCylinderDialog::setCylinder(cylinder_t *cylinder)
+{
+ double volume, pressure;
+ int index;
+
+ currentCylinder = cylinder;
+ convert_volume_pressure(cylinder->type.size.mliter, cylinder->type.workingpressure.mbar, &volume, &pressure);
+
+ index = ui->cylinderType->findText(QString(cylinder->type.description));
+ ui->cylinderType->setCurrentIndex(index);
+ ui->size->setValue(volume);
+ ui->pressure->setValue(pressure);
+
+ ui->o2percent->setValue(cylinder->gasmix.o2.permille / 10.0);
+ ui->hepercent->setValue(cylinder->gasmix.he.permille / 10.0);
+
+ convert_pressure(cylinder->start.mbar, &pressure);
+ ui->start->setValue(pressure);
+
+ convert_pressure(cylinder->end.mbar, &pressure);
+ ui->end->setValue(pressure);
+}
+
+void AddCylinderDialog::updateCylinder()
+{
+ QByteArray description = ui->cylinderType->currentText().toLocal8Bit();
+
+ currentCylinder->type.description = description.data();
+ currentCylinder->type.size.mliter = ui->size->value();
+ currentCylinder->type.workingpressure.mbar = ui->pressure->value();
+ currentCylinder->gasmix.o2.permille = ui->o2percent->value();
+ currentCylinder->gasmix.he.permille = ui->hepercent->value();
+ currentCylinder->start.mbar = ui->start->value();
+ currentCylinder->end.mbar = ui->end->value();
+}
+
diff --git a/qt-ui/addcylinderdialog.h b/qt-ui/addcylinderdialog.h
new file mode 100644
index 000000000..b32494c05
--- /dev/null
+++ b/qt-ui/addcylinderdialog.h
@@ -0,0 +1,24 @@
+#ifndef ADDCYLINDERDIALOG_H
+#define ADDCYLINDERDIALOG_H
+
+#include <QDialog>
+#include "../dive.h"
+
+namespace Ui{
+ class AddCylinderDialog;
+}
+
+class AddCylinderDialog : public QDialog{
+ Q_OBJECT
+public:
+ explicit AddCylinderDialog(QWidget* parent = 0);
+ void setCylinder(cylinder_t *cylinder);
+ void updateCylinder();
+
+private:
+ Ui::AddCylinderDialog *ui;
+ cylinder_t *currentCylinder;
+};
+
+
+#endif
diff --git a/qt-ui/addcylinderdialog.ui b/qt-ui/addcylinderdialog.ui
new file mode 100644
index 000000000..8bb0428b7
--- /dev/null
+++ b/qt-ui/addcylinderdialog.ui
@@ -0,0 +1,303 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>AddCylinderDialog</class>
+ <widget class="QDialog" name="AddCylinderDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>408</width>
+ <height>298</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" rowspan="2">
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Cylinder</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::ExpandingFieldsGrow</enum>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Type</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="cylinderType">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Size</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QDoubleSpinBox" name="size">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Pressure</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QSpinBox" name="pressure">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="title">
+ <string>Pressure</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout_2">
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Start</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>End</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QSpinBox" name="start">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QSpinBox" name="end">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="checkBox">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QGroupBox" name="groupBox_3">
+ <property name="title">
+ <string>Gas Mix</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout_3">
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>O2%</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QDoubleSpinBox" name="o2percent">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>He%</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QDoubleSpinBox" name="hepercent">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="checkBox_2">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="2" column="0" colspan="2">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>AddCylinderDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>269</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>260</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>AddCylinderDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>290</x>
+ <y>269</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>260</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>checkBox</sender>
+ <signal>clicked(bool)</signal>
+ <receiver>start</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>216</x>
+ <y>46</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>280</x>
+ <y>66</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>checkBox</sender>
+ <signal>clicked(bool)</signal>
+ <receiver>end</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>226</x>
+ <y>48</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>268</x>
+ <y>100</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>checkBox_2</sender>
+ <signal>clicked(bool)</signal>
+ <receiver>o2percent</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>214</x>
+ <y>165</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>260</x>
+ <y>190</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>checkBox_2</sender>
+ <signal>clicked(bool)</signal>
+ <receiver>hepercent</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>228</x>
+ <y>165</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>262</x>
+ <y>216</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index c630965d2..b957fd1c7 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -1,8 +1,74 @@
#include "maintab.h"
#include "ui_maintab.h"
+#include "addcylinderdialog.h"
+
+#include <QLabel>
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
- ui(new Ui::MainTab())
+ ui(new Ui::MainTab()),
+ weightModel(new WeightModel()),
+ cylindersModel(new CylindersModel())
{
ui->setupUi(this);
+ ui->cylinders->setModel(cylindersModel);
+ ui->weights->setModel(weightModel);
+}
+
+void MainTab::clearEquipment()
+{
+}
+
+void MainTab::clearInfo()
+{
+ QList<QLabel*> labels;
+ labels << ui->sac << ui->otu << ui->oxygenhelium << ui->gasused
+ << ui->date << ui->divetime << ui->surfinterval
+ << ui->maxdepth << ui->avgdepth << ui->visibility
+ << ui->watertemperature << ui->airtemperature << ui->airpress;
+
+ Q_FOREACH(QLabel *l, labels){
+ l->setText(QString());
+ }
+}
+
+void MainTab::clearStats()
+{
+ QList<QLabel*> labels;
+ labels << ui->maxdepth_2 << ui->mindepth << ui->avgdepth
+ << ui->maxsac << ui->minsac << ui->avgsac
+ << ui->dives << ui->maxtemp << ui->mintemp << ui->avgtemp
+ << ui->totaltime << ui->avgtime << ui->longestdive << ui->shortestdive;
+
+ Q_FOREACH(QLabel *l, labels){
+ l->setText(QString());
+ }
+}
+
+void MainTab::on_addCylinder_clicked()
+{
+ AddCylinderDialog dialog(this);
+ cylinder_t *newCylinder = (cylinder_t*) malloc(sizeof(cylinder_t));
+ newCylinder->type.description = "";
+
+ dialog.setCylinder(newCylinder);
+ int result = dialog.exec();
+ if (result == QDialog::Rejected){
+ return;
+ }
+
+ dialog.updateCylinder();
+ cylindersModel->add(newCylinder);
+}
+
+void MainTab::on_editCylinder_clicked()
+{
+}
+
+void MainTab::on_delCylinder_clicked()
+{
+}
+
+void MainTab::reload()
+{
+ cylindersModel->update();
}
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 40904ab12..0e9f285ac 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -2,6 +2,9 @@
#define MAINTAB_H
#include <QTabWidget>
+#include <QDialog>
+
+#include "models.h"
namespace Ui
{
@@ -13,8 +16,20 @@ class MainTab : public QTabWidget
Q_OBJECT
public:
MainTab(QWidget *parent);
+ void clearStats();
+ void clearInfo();
+ void clearEquipment();
+ void reload();
+
+public Q_SLOTS:
+ void on_addCylinder_clicked();
+ void on_editCylinder_clicked();
+ void on_delCylinder_clicked();
+
private:
Ui::MainTab *ui;
+ WeightModel *weightModel;
+ CylindersModel *cylindersModel;
};
-#endif \ No newline at end of file
+#endif
diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui
index 7432dc466..0f46d91a5 100644
--- a/qt-ui/maintab.ui
+++ b/qt-ui/maintab.ui
@@ -14,7 +14,7 @@
<string>TabWidget</string>
</property>
<property name="currentIndex">
- <number>0</number>
+ <number>2</number>
</property>
<widget class="QWidget" name="infoTab">
<attribute name="title">
@@ -390,19 +390,19 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <widget class="QTableView" name="tableView"/>
+ <widget class="QTableView" name="cylinders"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
- <widget class="QPushButton" name="pushButton">
+ <widget class="QPushButton" name="editCylinder">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
- <widget class="QPushButton" name="pushButton_2">
+ <widget class="QPushButton" name="addCylinder">
<property name="text">
<string>Add</string>
</property>
@@ -422,7 +422,7 @@
</spacer>
</item>
<item>
- <widget class="QPushButton" name="pushButton_3">
+ <widget class="QPushButton" name="delCylinder">
<property name="text">
<string>Delete</string>
</property>
@@ -438,7 +438,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
- <widget class="QTableView" name="tableView_2"/>
+ <widget class="QTableView" name="weights"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 03f6b6ca6..fdc823d9c 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -2,11 +2,19 @@
#include "ui_mainwindow.h"
#include <QVBoxLayout>
+#include <QFileDialog>
+#include <QMessageBox>
#include <QtDebug>
#include "divelistview.h"
#include "divetripmodel.h"
+#include "glib.h"
+#include "../dive.h"
+#include "../divelist.h"
+#include "../pref.h"
+
+
MainWindow::MainWindow() : ui(new Ui::MainWindow())
{
ui->setupUi(this);
@@ -45,7 +53,31 @@ void MainWindow::on_actionNew_triggered()
void MainWindow::on_actionOpen_triggered()
{
- qDebug("actionOpen");
+ QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter());
+ if (filename.isEmpty()){
+ return;
+ }
+
+ // Needed to convert to char*
+ QByteArray fileNamePtr = filename.toLocal8Bit();
+
+ on_actionClose_triggered();
+
+ GError *error = NULL;
+ parse_file(fileNamePtr.data(), &error);
+ set_filename(fileNamePtr.data(), TRUE);
+
+ if (error != NULL)
+ {
+ QMessageBox::warning(this, "Error", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+
+ //WARNING: Port This method to Qt
+ report_dives(FALSE, FALSE);
+
+ ui->InfoWidget->reload();
}
void MainWindow::on_actionSave_triggered()
@@ -59,7 +91,37 @@ void MainWindow::on_actionSaveAs_triggered()
}
void MainWindow::on_actionClose_triggered()
{
- qDebug("actionClose");
+ if (unsaved_changes() && (askSaveChanges() == FALSE))
+ {
+ return;
+ }
+
+ /* free the dives and trips */
+ while (dive_table.nr)
+ {
+ delete_single_dive(0);
+ }
+ mark_divelist_changed(FALSE);
+
+ /* clear the selection and the statistics */
+ selected_dive = 0;
+
+ //WARNING: Port this to Qt.
+ //process_selected_dives();
+
+ ui->InfoWidget->clearStats();
+ ui->InfoWidget->clearInfo();
+ ui->InfoWidget->clearEquipment();
+
+ clear_events();
+ show_dive_stats(NULL);
+
+ /* redraw the screen */
+ //WARNING: Port this to Qt.
+ dive_list_update_dives();
+
+ // WARNING? Port this to Qt.
+ show_dive_info(NULL);
}
void MainWindow::on_actionImport_triggered()
@@ -190,3 +252,44 @@ void MainWindow::on_actionUserManual_triggered()
{
qDebug("actionUserManual");
}
+
+QString MainWindow::filter()
+{
+ QString f;
+ f += "ALL ( *.xml *.XML *.uddf *.udcf *.UDFC *.jlb *.JLB ";
+#ifdef LIBZIP
+ f += "*.sde *.SDE *.dld *.DLD ";
+#endif
+#ifdef SQLITE3
+ f += "*.db";
+#endif
+ f += ");;";
+
+ f += "XML (*.xml *.XML);;";
+ f += "UDDF (*.uddf);;";
+ f += "UDCF (*.udcf *.UDCF);;";
+ f += "JLB (*.jlb *.JLB);;";
+
+#ifdef LIBZIP
+ f += "SDE (*.sde *.SDE);;";
+ f += "DLD (*.dld *.DLD);;";
+#endif
+#ifdef SQLITE3
+ f += "DB (*.db)";
+#endif
+
+ return f;
+}
+
+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){
+ // WARNING: Port.
+ // file_save(NULL,NULL);
+ return true;
+ }
+ return false;
+}
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index 662d07cc5..34acf2b67 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -62,6 +62,9 @@ private Q_SLOTS:
private:
Ui::MainWindow *ui;
DiveTripModel *model;
+ QString filter();
+ bool askSaveChanges();
+
};
#endif
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
new file mode 100644
index 000000000..dac1c7215
--- /dev/null
+++ b/qt-ui/models.cpp
@@ -0,0 +1,175 @@
+#include "models.h"
+#include "../dive.h"
+
+CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent)
+{
+}
+
+QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ QVariant ret;
+ if (orientation == Qt::Vertical) {
+ return ret;
+ }
+
+ if (role == Qt::DisplayRole) {
+ switch(section) {
+ case TYPE:
+ ret = tr("Type");
+ break;
+ case SIZE:
+ ret = tr("Size");
+ break;
+ case MAXPRESS:
+ ret = tr("MaxPress");
+ break;
+ case START:
+ ret = tr("Start");
+ break;
+ case END:
+ ret = tr("End");
+ break;
+ case O2:
+ ret = tr("O2%");
+ break;
+ case HE:
+ ret = tr("He%");
+ break;
+ }
+ }
+ return ret;
+}
+
+int CylindersModel::columnCount(const QModelIndex& parent) const
+{
+ return 7;
+}
+
+QVariant CylindersModel::data(const QModelIndex& index, int role) const
+{
+ QVariant ret;
+ if (!index.isValid() || index.row() >= MAX_CYLINDERS) {
+ return ret;
+ }
+
+ dive *d = get_dive(selected_dive);
+ cylinder_t& cyl = d->cylinder[index.row()];
+
+ if (role == Qt::DisplayRole) {
+ switch(index.column()) {
+ case TYPE:
+ ret = QString(cyl.type.description);
+ break;
+ case SIZE:
+ ret = cyl.type.size.mliter;
+ break;
+ case MAXPRESS:
+ ret = cyl.type.workingpressure.mbar;
+ break;
+ case START:
+ ret = cyl.start.mbar;
+ break;
+ case END:
+ ret = cyl.end.mbar;
+ break;
+ case O2:
+ ret = cyl.gasmix.o2.permille;
+ break;
+ case HE:
+ ret = cyl.gasmix.he.permille;
+ break;
+ }
+ }
+ return ret;
+}
+
+int CylindersModel::rowCount(const QModelIndex& parent) const
+{
+ return usedRows[currentDive];
+}
+
+void CylindersModel::add(cylinder_t* cyl)
+{
+ if (usedRows[currentDive] >= MAX_CYLINDERS) {
+ free(cyl);
+ }
+
+ int row = usedRows[currentDive];
+
+ cylinder_t& cylinder = currentDive->cylinder[row];
+
+ cylinder.end.mbar = cyl->end.mbar;
+ cylinder.start.mbar = cyl->start.mbar;
+
+ beginInsertRows(QModelIndex(), row, row);
+ usedRows[currentDive]++;
+ endInsertRows();
+}
+
+void CylindersModel::update()
+{
+ if (usedRows[currentDive] > 0) {
+ beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
+ endRemoveRows();
+ }
+
+ currentDive = get_dive(selected_dive);
+ if (usedRows[currentDive] > 0) {
+ beginInsertRows(QModelIndex(), 0, usedRows[currentDive]-1);
+ endInsertRows();
+ }
+}
+
+void CylindersModel::clear()
+{
+ if (usedRows[currentDive] > 0) {
+ beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
+ usedRows[currentDive] = 0;
+ endRemoveRows();
+ }
+}
+
+void WeightModel::clear()
+{
+}
+
+int WeightModel::columnCount(const QModelIndex& parent) const
+{
+ return 0;
+}
+
+QVariant WeightModel::data(const QModelIndex& index, int role) const
+{
+ return QVariant();
+}
+
+int WeightModel::rowCount(const QModelIndex& parent) const
+{
+ return rows;
+}
+
+QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ QVariant ret;
+ if (orientation == Qt::Vertical) {
+ return ret;
+ }
+
+ switch(section){
+ case TYPE:
+ ret = tr("Type");
+ break;
+ case WEIGHT:
+ ret = tr("Weight");
+ break;
+ }
+ return ret;
+}
+
+void WeightModel::add(weight_t* weight)
+{
+}
+
+void WeightModel::update()
+{
+}
diff --git a/qt-ui/models.h b/qt-ui/models.h
new file mode 100644
index 000000000..0d0c7b41d
--- /dev/null
+++ b/qt-ui/models.h
@@ -0,0 +1,44 @@
+#ifndef MODELS_H
+#define MODELS_H
+
+#include <QAbstractTableModel>
+#include "../dive.h"
+
+class CylindersModel : public QAbstractTableModel {
+Q_OBJECT
+public:
+ enum {TYPE, SIZE, MAXPRESS, START, END, O2, HE};
+
+ explicit CylindersModel(QObject* parent = 0);
+ /*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+ /*reimp*/ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ /*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ /*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+
+ void add(cylinder_t *cyl);
+ void clear();
+ void update();
+private:
+ dive *currentDive;
+
+ /* Since the dive doesn`t stores the number of cylinders that
+ * it has ( max 8 ) and since I don`t want to make a
+ * model-for-each-dive, let`s hack this here instead. */
+ QMap<dive*, int> usedRows;
+};
+
+class WeightModel : public QAbstractTableModel {
+ enum{TYPE, WEIGHT};
+ /*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+ /*reimp*/ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ /*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ /*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+
+ void add(weight_t *weight);
+ void clear();
+ void update();
+private:
+ int rows;
+};
+
+#endif