diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-04-13 10:17:59 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-04-13 14:08:16 -0700 |
commit | 92397a2bad3d1a2bc261dee67d230e3caa13b8d8 (patch) | |
tree | 32d54729f32bd6b2f1be2eacf27717dd3bede5a0 /qt-ui | |
parent | 76f71b4ca07dbef1069aec3db1138c199927b1bb (diff) | |
download | subsurface-92397a2bad3d1a2bc261dee67d230e3caa13b8d8.tar.gz |
Started the real code on the Qt Interface.
1 - Open File already open files, it tries to not break the Gtk version,
but some methods on the GTK version still need to be called inside Qt
because the code is too tight-coupled.
2 - Close file already close files, same comments for the open file dialog
applies here.
3 - The code for adding new cylinders in the cylinder dialog is done,
already works and it's integrated with the system. There's a need to
implement the edit and delete now, but it will be easyer since I'm
starting to not get lost on the code.
4 - Some functions that were used to convert unities have been moved to
convert.h ( can be changed later, put there because it's easyer to
find something that converts in a convert.h =p ) because they were
static functions that operated in the GTK version but I need those
functions in the Qt version too.
[Dirk Hohndel: lots and lots of whitespace and coding style changes]
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/addcylinderdialog.cpp | 48 | ||||
-rw-r--r-- | qt-ui/addcylinderdialog.h | 24 | ||||
-rw-r--r-- | qt-ui/addcylinderdialog.ui | 303 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 68 | ||||
-rw-r--r-- | qt-ui/maintab.h | 17 | ||||
-rw-r--r-- | qt-ui/maintab.ui | 12 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 107 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 3 | ||||
-rw-r--r-- | qt-ui/models.cpp | 175 | ||||
-rw-r--r-- | qt-ui/models.h | 44 |
10 files changed, 791 insertions, 10 deletions
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 |