mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-12 13:16:16 +00:00
Added the code that will load and populate the Tank Info
Added the code that will load and populate the Tank Info ComboBox that`s used by the user to select the Cylinder description. Code curerntly implements more than the GTK version since the GTK version of it was a plain-list, this one is a table based model that can be used in ListViews ( like we use now in the ComboBox ) but also in TableViews ( if there`s a need in the future to see everything that`s catalogued in the Tank Info struct. ) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
db180bf46e
commit
115ee47bfc
7 changed files with 143 additions and 7 deletions
2
Makefile
2
Makefile
|
@ -149,7 +149,7 @@ ifneq (,$(filter $(UNAME),linux kfreebsd gnu))
|
||||||
GCONF2CFLAGS = $(shell $(PKGCONFIG) --cflags gconf-2.0)
|
GCONF2CFLAGS = $(shell $(PKGCONFIG) --cflags gconf-2.0)
|
||||||
OSSUPPORT = linux
|
OSSUPPORT = linux
|
||||||
OSSUPPORT_CFLAGS = $(GTKCFLAGS) $(GCONF2CFLAGS)
|
OSSUPPORT_CFLAGS = $(GTKCFLAGS) $(GCONF2CFLAGS)
|
||||||
ifneq ($(findstring reduce_relocations, $(shell $(PKGCONFIG) --variable qt_config $(QT_CORE))),)
|
ifneq ($(filter reduce_relocations, $(shell $(PKGCONFIG) --variable qt_config $(QT_CORE))), )
|
||||||
CXXFLAGS += -fPIE
|
CXXFLAGS += -fPIE
|
||||||
endif
|
endif
|
||||||
else ifeq ($(UNAME), darwin)
|
else ifeq ($(UNAME), darwin)
|
||||||
|
|
13
dive.h
13
dive.h
|
@ -697,6 +697,19 @@ void get_gas_string(int o2, int he, char *buf, int len);
|
||||||
|
|
||||||
struct event *get_next_event(struct event *event, char *name);
|
struct event *get_next_event(struct event *event, char *name);
|
||||||
|
|
||||||
|
|
||||||
|
/* this struct holds the information that
|
||||||
|
* describes the cylinders of air.
|
||||||
|
* it is a global variable initialized in equipment.c
|
||||||
|
* used to fill the combobox in the add/edit cylinder
|
||||||
|
* dialog
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct tank_info {
|
||||||
|
const char *name;
|
||||||
|
int cuft, ml, psi, bar;
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef DEBUGFILE
|
#ifdef DEBUGFILE
|
||||||
extern char *debugfilename;
|
extern char *debugfilename;
|
||||||
extern FILE *debugfile;
|
extern FILE *debugfile;
|
||||||
|
|
|
@ -790,10 +790,7 @@ static void record_weightsystem_changes(weightsystem_t *ws, struct ws_widget *we
|
||||||
* we should pick up any other names from the dive
|
* we should pick up any other names from the dive
|
||||||
* logs directly.
|
* logs directly.
|
||||||
*/
|
*/
|
||||||
static struct tank_info {
|
struct tank_info tank_info[100] = {
|
||||||
const char *name;
|
|
||||||
int cuft, ml, psi, bar;
|
|
||||||
} tank_info[100] = {
|
|
||||||
/* Need an empty entry for the no-cylinder case */
|
/* Need an empty entry for the no-cylinder case */
|
||||||
{ "", },
|
{ "", },
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,13 @@
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDoubleSpinBox>
|
#include <QDoubleSpinBox>
|
||||||
#include "../conversions.h"
|
#include "../conversions.h"
|
||||||
|
#include "models.h"
|
||||||
|
|
||||||
AddCylinderDialog::AddCylinderDialog(QWidget *parent) : ui(new Ui::AddCylinderDialog())
|
AddCylinderDialog::AddCylinderDialog(QWidget *parent) : ui(new Ui::AddCylinderDialog())
|
||||||
|
, tankInfoModel(new TankInfoModel())
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
ui->cylinderType->setModel(tankInfoModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddCylinderDialog::setCylinder(cylinder_t *cylinder)
|
void AddCylinderDialog::setCylinder(cylinder_t *cylinder)
|
||||||
|
|
|
@ -14,6 +14,8 @@ namespace Ui{
|
||||||
class AddCylinderDialog;
|
class AddCylinderDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TankInfoModel;
|
||||||
|
|
||||||
class AddCylinderDialog : public QDialog{
|
class AddCylinderDialog : public QDialog{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -24,6 +26,7 @@ public:
|
||||||
private:
|
private:
|
||||||
Ui::AddCylinderDialog *ui;
|
Ui::AddCylinderDialog *ui;
|
||||||
cylinder_t *currentCylinder;
|
cylinder_t *currentCylinder;
|
||||||
|
TankInfoModel *tankInfoModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
101
qt-ui/models.cpp
101
qt-ui/models.cpp
|
@ -7,6 +7,8 @@
|
||||||
#include "models.h"
|
#include "models.h"
|
||||||
#include "../dive.h"
|
#include "../dive.h"
|
||||||
|
|
||||||
|
extern struct tank_info tank_info[100];
|
||||||
|
|
||||||
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent)
|
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -179,3 +181,102 @@ void WeightModel::add(weight_t* weight)
|
||||||
void WeightModel::update()
|
void WeightModel::update()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TankInfoModel::add(const QString& description)
|
||||||
|
{
|
||||||
|
// When the user `creates` a new one on the combobox.
|
||||||
|
// for now, empty till dirk cleans the GTK code.
|
||||||
|
}
|
||||||
|
|
||||||
|
void TankInfoModel::clear()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int TankInfoModel::columnCount(const QModelIndex& parent) const
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant TankInfoModel::data(const QModelIndex& index, int role) const
|
||||||
|
{
|
||||||
|
QVariant ret;
|
||||||
|
if (!index.isValid()) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
struct tank_info *info = &tank_info[index.row()];
|
||||||
|
|
||||||
|
int ml = info->ml;
|
||||||
|
|
||||||
|
int bar = ((info->psi) ? psi_to_bar(info->psi) : info->bar) * 1000 + 0.5;
|
||||||
|
|
||||||
|
if (info->cuft) {
|
||||||
|
double airvolume = cuft_to_l(info->cuft) * 1000.0;
|
||||||
|
ml = airvolume / bar_to_atm(bar) + 0.5;
|
||||||
|
}
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
switch(index.column()) {
|
||||||
|
case BAR: ret = bar;
|
||||||
|
break;
|
||||||
|
case ML: ret = ml;
|
||||||
|
break;
|
||||||
|
case DESCRIPTION:
|
||||||
|
ret = QString(info->name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant TankInfoModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
QVariant ret;
|
||||||
|
|
||||||
|
if (orientation != Qt::Horizontal)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
switch(section) {
|
||||||
|
case BAR:
|
||||||
|
ret = tr("Bar");
|
||||||
|
break;
|
||||||
|
case ML:
|
||||||
|
ret = tr("Ml");
|
||||||
|
break;
|
||||||
|
case DESCRIPTION:
|
||||||
|
ret = tr("Description");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TankInfoModel::rowCount(const QModelIndex& parent) const
|
||||||
|
{
|
||||||
|
return rows+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TankInfoModel::TankInfoModel() : QAbstractTableModel(), rows(-1)
|
||||||
|
{
|
||||||
|
struct tank_info *info = tank_info;
|
||||||
|
for (info = tank_info ; info->name; info++, rows++);
|
||||||
|
|
||||||
|
if (rows > -1) {
|
||||||
|
beginInsertRows(QModelIndex(), 0, rows);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TankInfoModel::update()
|
||||||
|
{
|
||||||
|
if(rows > -1) {
|
||||||
|
beginRemoveRows(QModelIndex(), 0, rows);
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
|
struct tank_info *info = tank_info;
|
||||||
|
for (info = tank_info ; info->name; info++, rows++);
|
||||||
|
|
||||||
|
if (rows > -1) {
|
||||||
|
beginInsertRows(QModelIndex(), 0, rows);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,26 @@
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
#include "../dive.h"
|
#include "../dive.h"
|
||||||
|
|
||||||
|
/* Encapsulates the tank_info global variable
|
||||||
|
* to show on Qt`s Model View System.*/
|
||||||
|
class TankInfoModel : public QAbstractTableModel {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum { DESCRIPTION, ML, BAR};
|
||||||
|
TankInfoModel();
|
||||||
|
|
||||||
|
/*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(const QString& description);
|
||||||
|
void clear();
|
||||||
|
void update();
|
||||||
|
private:
|
||||||
|
int rows;
|
||||||
|
};
|
||||||
|
|
||||||
class CylindersModel : public QAbstractTableModel {
|
class CylindersModel : public QAbstractTableModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue