mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Merge branch 'Qt' into RenderStarsOnTable
This commit is contained in:
commit
e5ad47e459
12 changed files with 342 additions and 56 deletions
2
Makefile
2
Makefile
|
@ -31,6 +31,7 @@ EXTRA_FLAGS = $(QTCXXFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) \
|
||||||
|
|
||||||
HEADERS = \
|
HEADERS = \
|
||||||
qt-ui/addcylinderdialog.h \
|
qt-ui/addcylinderdialog.h \
|
||||||
|
qt-ui/addweightsystemdialog.h \
|
||||||
qt-ui/divelistview.h \
|
qt-ui/divelistview.h \
|
||||||
qt-ui/maintab.h \
|
qt-ui/maintab.h \
|
||||||
qt-ui/mainwindow.h \
|
qt-ui/mainwindow.h \
|
||||||
|
@ -70,6 +71,7 @@ SOURCES = \
|
||||||
webservice.c \
|
webservice.c \
|
||||||
qt-gui.cpp \
|
qt-gui.cpp \
|
||||||
qt-ui/addcylinderdialog.cpp \
|
qt-ui/addcylinderdialog.cpp \
|
||||||
|
qt-ui/addweightsystemdialog.cpp \
|
||||||
qt-ui/divelistview.cpp \
|
qt-ui/divelistview.cpp \
|
||||||
qt-ui/maintab.cpp \
|
qt-ui/maintab.cpp \
|
||||||
qt-ui/mainwindow.cpp \
|
qt-ui/mainwindow.cpp \
|
||||||
|
|
39
qt-ui/addweightsystemdialog.cpp
Normal file
39
qt-ui/addweightsystemdialog.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* addweightsystemdialog.cpp
|
||||||
|
*
|
||||||
|
* classes for the add weightsystem dialog of Subsurface
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "addweightsystemdialog.h"
|
||||||
|
#include "ui_addweightsystemdialog.h"
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QDoubleSpinBox>
|
||||||
|
#include "../conversions.h"
|
||||||
|
#include "models.h"
|
||||||
|
|
||||||
|
AddWeightsystemDialog::AddWeightsystemDialog(QWidget *parent) : ui(new Ui::AddWeightsystemDialog())
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
currentWeightsystem = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddWeightsystemDialog::setWeightsystem(weightsystem_t *ws)
|
||||||
|
{
|
||||||
|
currentWeightsystem = ws;
|
||||||
|
|
||||||
|
ui->description->insert(QString(ws->description));
|
||||||
|
if (get_units()->weight == units::KG)
|
||||||
|
ui->weight->setValue(ws->weight.grams / 1000);
|
||||||
|
else
|
||||||
|
ui->weight->setValue(grams_to_lbs(ws->weight.grams));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddWeightsystemDialog::updateWeightsystem()
|
||||||
|
{
|
||||||
|
currentWeightsystem->description = strdup(ui->description->text().toUtf8().data());
|
||||||
|
if (get_units()->weight == units::KG)
|
||||||
|
currentWeightsystem->weight.grams = ui->weight->value() * 1000;
|
||||||
|
else
|
||||||
|
currentWeightsystem->weight.grams = lbs_to_grams(ui->weight->value());
|
||||||
|
}
|
||||||
|
|
30
qt-ui/addweightsystemdialog.h
Normal file
30
qt-ui/addweightsystemdialog.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* addweightsystemdialog.h
|
||||||
|
*
|
||||||
|
* header file for the add weightsystem dialog of Subsurface
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef ADDWEIGHTSYSTEMDIALOG_H
|
||||||
|
#define ADDWEIGHTSYSTEMDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include "../dive.h"
|
||||||
|
|
||||||
|
namespace Ui{
|
||||||
|
class AddWeightsystemDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddWeightsystemDialog : public QDialog{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit AddWeightsystemDialog(QWidget* parent = 0);
|
||||||
|
void setWeightsystem(weightsystem_t *ws);
|
||||||
|
void updateWeightsystem();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::AddWeightsystemDialog *ui;
|
||||||
|
weightsystem_t *currentWeightsystem;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
109
qt-ui/addweightsystemdialog.ui
Normal file
109
qt-ui/addweightsystemdialog.ui
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AddWeightsystemDialog</class>
|
||||||
|
<widget class="QDialog" name="AddWeightsystemDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>408</width>
|
||||||
|
<height>186</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>Weightsystem</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<property name="fieldGrowthPolicy">
|
||||||
|
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
||||||
|
</property>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Description</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Weight</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QSpinBox" name="weight">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="inputMethodHints">
|
||||||
|
<set>Qt::ImhFormattedNumbersOnly</set>
|
||||||
|
</property>
|
||||||
|
<property name="accelerated">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="description"/>
|
||||||
|
</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>AddWeightsystemDialog</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>AddWeightsystemDialog</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>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
|
@ -7,6 +7,7 @@
|
||||||
#include "maintab.h"
|
#include "maintab.h"
|
||||||
#include "ui_maintab.h"
|
#include "ui_maintab.h"
|
||||||
#include "addcylinderdialog.h"
|
#include "addcylinderdialog.h"
|
||||||
|
#include "addweightsystemdialog.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
|
@ -61,6 +62,9 @@ void MainTab::clearStats()
|
||||||
|
|
||||||
void MainTab::on_addCylinder_clicked()
|
void MainTab::on_addCylinder_clicked()
|
||||||
{
|
{
|
||||||
|
if (cylindersModel->rowCount() >= MAX_CYLINDERS)
|
||||||
|
return;
|
||||||
|
|
||||||
AddCylinderDialog dialog(this);
|
AddCylinderDialog dialog(this);
|
||||||
cylinder_t *newCylinder = (cylinder_t*) malloc(sizeof(cylinder_t));
|
cylinder_t *newCylinder = (cylinder_t*) malloc(sizeof(cylinder_t));
|
||||||
newCylinder->type.description = "";
|
newCylinder->type.description = "";
|
||||||
|
@ -83,6 +87,33 @@ void MainTab::on_delCylinder_clicked()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainTab::on_addWeight_clicked()
|
||||||
|
{
|
||||||
|
if (weightModel->rowCount() >= MAX_WEIGHTSYSTEMS)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AddWeightsystemDialog dialog(this);
|
||||||
|
weightsystem_t newWeightsystem;
|
||||||
|
newWeightsystem.description = "";
|
||||||
|
newWeightsystem.weight.grams = 0;
|
||||||
|
|
||||||
|
dialog.setWeightsystem(&newWeightsystem);
|
||||||
|
int result = dialog.exec();
|
||||||
|
if (result == QDialog::Rejected)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dialog.updateWeightsystem();
|
||||||
|
weightModel->add(&newWeightsystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainTab::on_editWeight_clicked()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainTab::on_delWeight_clicked()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void MainTab::reload()
|
void MainTab::reload()
|
||||||
{
|
{
|
||||||
cylindersModel->update();
|
cylindersModel->update();
|
||||||
|
|
|
@ -31,6 +31,9 @@ public Q_SLOTS:
|
||||||
void on_addCylinder_clicked();
|
void on_addCylinder_clicked();
|
||||||
void on_editCylinder_clicked();
|
void on_editCylinder_clicked();
|
||||||
void on_delCylinder_clicked();
|
void on_delCylinder_clicked();
|
||||||
|
void on_addWeight_clicked();
|
||||||
|
void on_editWeight_clicked();
|
||||||
|
void on_delWeight_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainTab *ui;
|
Ui::MainTab *ui;
|
||||||
|
|
|
@ -152,14 +152,14 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_4">
|
<widget class="QPushButton" name="editWeight">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Edit</string>
|
<string>Edit</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_5">
|
<widget class="QPushButton" name="addWeight">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add</string>
|
<string>Add</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -179,7 +179,7 @@
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_6">
|
<widget class="QPushButton" name="delWeight">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Delete</string>
|
<string>Delete</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QCloseEvent>
|
||||||
|
|
||||||
#include "divelistview.h"
|
#include "divelistview.h"
|
||||||
#include "starwidget.h"
|
#include "starwidget.h"
|
||||||
|
@ -31,6 +33,7 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()),
|
||||||
ui->ListWidget->setModel(sortModel);
|
ui->ListWidget->setModel(sortModel);
|
||||||
|
|
||||||
setWindowIcon(QIcon(":subsurface-icon"));
|
setWindowIcon(QIcon(":subsurface-icon"));
|
||||||
|
readSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionNew_triggered()
|
void MainWindow::on_actionNew_triggered()
|
||||||
|
@ -41,9 +44,8 @@ void MainWindow::on_actionNew_triggered()
|
||||||
void MainWindow::on_actionOpen_triggered()
|
void MainWindow::on_actionOpen_triggered()
|
||||||
{
|
{
|
||||||
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter());
|
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter());
|
||||||
if (filename.isEmpty()) {
|
if (filename.isEmpty())
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Needed to convert to char*
|
// Needed to convert to char*
|
||||||
QByteArray fileNamePtr = filename.toLocal8Bit();
|
QByteArray fileNamePtr = filename.toLocal8Bit();
|
||||||
|
@ -54,15 +56,13 @@ void MainWindow::on_actionOpen_triggered()
|
||||||
parse_file(fileNamePtr.data(), &error);
|
parse_file(fileNamePtr.data(), &error);
|
||||||
set_filename(fileNamePtr.data(), TRUE);
|
set_filename(fileNamePtr.data(), TRUE);
|
||||||
|
|
||||||
if (error != NULL)
|
if (error != NULL) {
|
||||||
{
|
|
||||||
QMessageBox::warning(this, "Error", error->message);
|
QMessageBox::warning(this, "Error", error->message);
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
error = NULL;
|
error = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//WARNING: Port This method to Qt
|
process_dives(FALSE, FALSE);
|
||||||
report_dives(FALSE, FALSE);
|
|
||||||
|
|
||||||
ui->InfoWidget->reload();
|
ui->InfoWidget->reload();
|
||||||
|
|
||||||
|
@ -84,15 +84,12 @@ void MainWindow::on_actionSaveAs_triggered()
|
||||||
void MainWindow::on_actionClose_triggered()
|
void MainWindow::on_actionClose_triggered()
|
||||||
{
|
{
|
||||||
if (unsaved_changes() && (askSaveChanges() == FALSE))
|
if (unsaved_changes() && (askSaveChanges() == FALSE))
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* free the dives and trips */
|
/* free the dives and trips */
|
||||||
while (dive_table.nr)
|
while (dive_table.nr)
|
||||||
{
|
|
||||||
delete_single_dive(0);
|
delete_single_dive(0);
|
||||||
}
|
|
||||||
mark_divelist_changed(FALSE);
|
mark_divelist_changed(FALSE);
|
||||||
|
|
||||||
/* clear the selection and the statistics */
|
/* clear the selection and the statistics */
|
||||||
|
@ -139,6 +136,8 @@ void MainWindow::on_actionPreferences_triggered()
|
||||||
void MainWindow::on_actionQuit_triggered()
|
void MainWindow::on_actionQuit_triggered()
|
||||||
{
|
{
|
||||||
qDebug("actionQuit");
|
qDebug("actionQuit");
|
||||||
|
if (unsaved_changes() && (askSaveChanges() == FALSE))
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionDownloadDC_triggered()
|
void MainWindow::on_actionDownloadDC_triggered()
|
||||||
|
@ -285,3 +284,36 @@ bool MainWindow::askSaveChanges()
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::readSettings()
|
||||||
|
{
|
||||||
|
QSettings settings("hohndel.org","subsurface");
|
||||||
|
|
||||||
|
settings.beginGroup("MainWindow");
|
||||||
|
QSize sz = settings.value("size").value<QSize>();
|
||||||
|
resize(sz);
|
||||||
|
ui->mainSplitter->restoreState(settings.value("mainSplitter").toByteArray());
|
||||||
|
ui->infoProfileSplitter->restoreState(settings.value("infoProfileSplitter").toByteArray());
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::writeSettings()
|
||||||
|
{
|
||||||
|
QSettings settings("hohndel.org","subsurface");
|
||||||
|
settings.beginGroup("MainWindow");
|
||||||
|
settings.setValue("size",size());
|
||||||
|
settings.setValue("mainSplitter", ui->mainSplitter->saveState());
|
||||||
|
settings.setValue("infoProfileSplitter", ui->infoProfileSplitter->saveState());
|
||||||
|
settings.endGroup();
|
||||||
|
/* other groups here; avoid '/' and '\' in keys with setValue(...) please */
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
|
if (unsaved_changes() && (askSaveChanges() == FALSE)) {
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event->accept();
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
|
|
@ -66,12 +66,17 @@ private Q_SLOTS:
|
||||||
void on_actionAboutSubsurface_triggered();
|
void on_actionAboutSubsurface_triggered();
|
||||||
void on_actionUserManual_triggered();
|
void on_actionUserManual_triggered();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void closeEvent(QCloseEvent *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
DiveTripModel *model;
|
DiveTripModel *model;
|
||||||
QSortFilterProxyModel *sortModel;
|
QSortFilterProxyModel *sortModel;
|
||||||
QString filter();
|
QString filter();
|
||||||
bool askSaveChanges();
|
bool askSaveChanges();
|
||||||
|
void readSettings();
|
||||||
|
void writeSettings();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSplitter" name="splitter_3">
|
<widget class="QSplitter" name="mainSplitter">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QSplitter" name="splitter_2">
|
<widget class="QSplitter" name="infoProfileSplitter">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@ -34,13 +34,6 @@
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QSplitter" name="splitter">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
@ -49,7 +42,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>763</width>
|
<width>763</width>
|
||||||
<height>25</height>
|
<height>20</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
|
|
|
@ -60,9 +60,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
|
||||||
if (!index.isValid() || index.row() >= MAX_CYLINDERS) {
|
if (!index.isValid() || index.row() >= MAX_CYLINDERS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
cylinder_t& cyl = current_dive->cylinder[index.row()];
|
||||||
struct dive *d = get_dive(selected_dive);
|
|
||||||
cylinder_t& cyl = d->cylinder[index.row()];
|
|
||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
switch(index.column()) {
|
switch(index.column()) {
|
||||||
|
@ -94,67 +92,93 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
int CylindersModel::rowCount(const QModelIndex& parent) const
|
int CylindersModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return usedRows[currentDive];
|
return usedRows[current_dive];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CylindersModel::add(cylinder_t* cyl)
|
void CylindersModel::add(cylinder_t* cyl)
|
||||||
{
|
{
|
||||||
if (usedRows[currentDive] >= MAX_CYLINDERS) {
|
if (usedRows[current_dive] >= MAX_CYLINDERS) {
|
||||||
free(cyl);
|
free(cyl);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int row = usedRows[currentDive];
|
int row = usedRows[current_dive];
|
||||||
|
|
||||||
cylinder_t& cylinder = currentDive->cylinder[row];
|
cylinder_t& cylinder = current_dive->cylinder[row];
|
||||||
|
|
||||||
cylinder.end.mbar = cyl->end.mbar;
|
cylinder.end.mbar = cyl->end.mbar;
|
||||||
cylinder.start.mbar = cyl->start.mbar;
|
cylinder.start.mbar = cyl->start.mbar;
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
usedRows[currentDive]++;
|
usedRows[current_dive]++;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CylindersModel::update()
|
void CylindersModel::update()
|
||||||
{
|
{
|
||||||
if (usedRows[currentDive] > 0) {
|
if (usedRows[current_dive] > 0) {
|
||||||
beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
if (usedRows[current_dive] > 0) {
|
||||||
currentDive = get_dive(selected_dive);
|
beginInsertRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||||
if (usedRows[currentDive] > 0) {
|
|
||||||
beginInsertRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CylindersModel::clear()
|
void CylindersModel::clear()
|
||||||
{
|
{
|
||||||
if (usedRows[currentDive] > 0) {
|
if (usedRows[current_dive] > 0) {
|
||||||
beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||||
usedRows[currentDive] = 0;
|
usedRows[current_dive] = 0;
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeightModel::clear()
|
void WeightModel::clear()
|
||||||
{
|
{
|
||||||
|
if (usedRows[current_dive] > 0) {
|
||||||
|
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||||
|
usedRows[current_dive] = 0;
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int WeightModel::columnCount(const QModelIndex& parent) const
|
int WeightModel::columnCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return 0;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant WeightModel::data(const QModelIndex& index, int role) const
|
QVariant WeightModel::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
return QVariant();
|
QVariant ret;
|
||||||
|
if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
weightsystem_t *ws = ¤t_dive->weightsystem[index.row()];
|
||||||
|
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
switch(index.column()) {
|
||||||
|
case TYPE:
|
||||||
|
ret = QString(ws->description);
|
||||||
|
break;
|
||||||
|
case WEIGHT:
|
||||||
|
if (get_units()->weight == units::KG) {
|
||||||
|
int gr = ws->weight.grams % 1000;
|
||||||
|
int kg = ws->weight.grams / 1000;
|
||||||
|
ret = QString("%1.%2").arg(kg).arg((unsigned)(gr + 500) / 100);
|
||||||
|
} else {
|
||||||
|
ret = QString("%1").arg((unsigned)(grams_to_lbs(ws->weight.grams) + 0.5));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WeightModel::rowCount(const QModelIndex& parent) const
|
int WeightModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return rows;
|
return usedRows[current_dive];
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
@ -164,19 +188,36 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(section) {
|
if (role == Qt::DisplayRole) {
|
||||||
case TYPE:
|
switch(section) {
|
||||||
ret = tr("Type");
|
case TYPE:
|
||||||
break;
|
ret = tr("Type");
|
||||||
case WEIGHT:
|
break;
|
||||||
ret = tr("Weight");
|
case WEIGHT:
|
||||||
break;
|
ret = tr("Weight");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeightModel::add(weight_t* weight)
|
void WeightModel::add(weightsystem_t* weight)
|
||||||
{
|
{
|
||||||
|
if (usedRows[current_dive] >= MAX_WEIGHTSYSTEMS) {
|
||||||
|
free(weight);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int row = usedRows[current_dive];
|
||||||
|
|
||||||
|
weightsystem_t *ws = ¤t_dive->weightsystem[row];
|
||||||
|
|
||||||
|
ws->description = weight->description;
|
||||||
|
ws->weight.grams = weight->weight.grams;
|
||||||
|
|
||||||
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
|
usedRows[current_dive]++;
|
||||||
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeightModel::update()
|
void WeightModel::update()
|
||||||
|
|
|
@ -50,28 +50,29 @@ public:
|
||||||
void clear();
|
void clear();
|
||||||
void update();
|
void update();
|
||||||
private:
|
private:
|
||||||
dive *currentDive;
|
|
||||||
|
|
||||||
/* Since the dive doesn`t stores the number of cylinders that
|
/* Since the dive doesn`t stores the number of cylinders that
|
||||||
* it has ( max 8 ) and since I don`t want to make a
|
* it has ( max 8 ) and since I don`t want to make a
|
||||||
* model-for-each-dive, let`s hack this here instead. */
|
* model-for-each-dive, let`s hack this here instead. */
|
||||||
QMap<dive*, int> usedRows;
|
QMap<struct dive *, int> usedRows;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Encapsulation of the Weight Model, that represents
|
/* Encapsulation of the Weight Model, that represents
|
||||||
* the current weights on a dive. */
|
* the current weights on a dive. */
|
||||||
class WeightModel : public QAbstractTableModel {
|
class WeightModel : public QAbstractTableModel {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
enum Column {TYPE, WEIGHT};
|
enum Column {TYPE, WEIGHT};
|
||||||
/*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
/*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
/*reimp*/ int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
/*reimp*/ int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
/*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
/*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||||
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
|
|
||||||
void add(weight_t *weight);
|
void add(weightsystem_t *weight);
|
||||||
void clear();
|
void clear();
|
||||||
void update();
|
void update();
|
||||||
private:
|
private:
|
||||||
int rows;
|
/* Remember the number of rows in a dive */
|
||||||
|
QMap<struct dive *, int> usedRows;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! An AbstractItemModel for recording dive trip information such as a list of dives.
|
/*! An AbstractItemModel for recording dive trip information such as a list of dives.
|
||||||
|
|
Loading…
Add table
Reference in a new issue