mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Added the code to show the cylinders from a dive.
i Added the code to show the cylinders from a dive, this code also already permits additions from the interface, so the user can click 'add' and insert what he wants there. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
246fbd0333
commit
126bc8cfa3
4 changed files with 44 additions and 28 deletions
8
dive.h
8
dive.h
|
@ -155,10 +155,10 @@ typedef struct {
|
|||
const char *description; /* "integrated", "belt", "ankle" */
|
||||
} weightsystem_t;
|
||||
|
||||
extern gboolean cylinder_nodata(cylinder_t *cyl);
|
||||
extern gboolean cylinder_none(void *_data);
|
||||
extern gboolean no_weightsystems(weightsystem_t *ws);
|
||||
extern gboolean weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2);
|
||||
extern bool cylinder_nodata(cylinder_t *cyl);
|
||||
extern bool cylinder_none(void *_data);
|
||||
extern bool no_weightsystems(weightsystem_t *ws);
|
||||
extern bool weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2);
|
||||
|
||||
extern int get_pressure_units(unsigned int mb, const char **units);
|
||||
extern double get_depth_units(unsigned int mm, int *frac, const char **units);
|
||||
|
|
|
@ -202,6 +202,7 @@ void MainTab::updateDiveInfo(int dive)
|
|||
ui->averageTimeAllText->setText(get_time_string(seconds, 0));
|
||||
ui->longestAllText->setText(get_time_string(stats_selection.longest_time.seconds, 0));
|
||||
ui->shortestAllText->setText(get_time_string(stats_selection.shortest_time.seconds, 0));
|
||||
cylindersModel->setDive(d);
|
||||
} else {
|
||||
/* make the fields read-only */
|
||||
ui->location->setReadOnly(true);
|
||||
|
@ -226,6 +227,7 @@ void MainTab::updateDiveInfo(int dive)
|
|||
ui->airTemperatureText->clear();
|
||||
ui->gasUsedText->clear();
|
||||
ui->airPressureText->clear();
|
||||
cylindersModel->clear();
|
||||
}
|
||||
/* statisticsTab*/
|
||||
/* we can access the stats_selection struct, but how do we ensure the relevant dives are selected
|
||||
|
@ -292,7 +294,6 @@ void MainTab::on_delWeight_clicked()
|
|||
|
||||
void MainTab::reload()
|
||||
{
|
||||
cylindersModel->update();
|
||||
}
|
||||
|
||||
void MainTab::on_editAccept_clicked(bool edit)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
extern struct tank_info tank_info[100];
|
||||
|
||||
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent)
|
||||
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent), current(0), rows(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
|
|||
if (!index.isValid() || index.row() >= MAX_CYLINDERS)
|
||||
return ret;
|
||||
|
||||
cylinder_t& cyl = current_dive->cylinder[index.row()];
|
||||
cylinder_t& cyl = current->cylinder[index.row()];
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch(index.column()) {
|
||||
|
@ -94,49 +94,64 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
|
|||
|
||||
int CylindersModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return usedRows[current_dive];
|
||||
return rows;
|
||||
}
|
||||
|
||||
void CylindersModel::add(cylinder_t* cyl)
|
||||
{
|
||||
if (usedRows[current_dive] >= MAX_CYLINDERS) {
|
||||
free(cyl);
|
||||
if (rows >= MAX_CYLINDERS) {
|
||||
return;
|
||||
}
|
||||
|
||||
int row = usedRows[current_dive];
|
||||
int row = rows;
|
||||
|
||||
cylinder_t& cylinder = current_dive->cylinder[row];
|
||||
cylinder_t& cylinder = current->cylinder[row];
|
||||
|
||||
cylinder.end.mbar = cyl->end.mbar;
|
||||
cylinder.start.mbar = cyl->start.mbar;
|
||||
cylinder.type.description = strdup(cyl->type.description);
|
||||
cylinder.type.size = cyl->type.size;
|
||||
cylinder.type.workingpressure = cyl->type.workingpressure;
|
||||
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
usedRows[current_dive]++;
|
||||
rows++;
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void CylindersModel::update()
|
||||
{
|
||||
if (usedRows[current_dive] > 0) {
|
||||
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||
endRemoveRows();
|
||||
}
|
||||
if (usedRows[current_dive] > 0) {
|
||||
beginInsertRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||
endInsertRows();
|
||||
}
|
||||
setDive(current);
|
||||
}
|
||||
|
||||
void CylindersModel::clear()
|
||||
{
|
||||
if (usedRows[current_dive] > 0) {
|
||||
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||
usedRows[current_dive] = 0;
|
||||
if (rows > 0) {
|
||||
beginRemoveRows(QModelIndex(), 0, rows-1);
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
|
||||
void CylindersModel::setDive(dive* d)
|
||||
{
|
||||
if (current)
|
||||
clear();
|
||||
|
||||
int amount = 0;
|
||||
for(int i = 0; i < MAX_CYLINDERS; i++){
|
||||
cylinder_t& cylinder = current_dive->cylinder[i];
|
||||
qDebug() << QString(cylinder.type.description);
|
||||
if (!cylinder.type.description){
|
||||
amount = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
beginInsertRows(QModelIndex(), 0, amount-1);
|
||||
rows = amount;
|
||||
current = d;
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void WeightModel::clear()
|
||||
{
|
||||
if (usedRows[current_dive] > 0) {
|
||||
|
|
|
@ -49,11 +49,11 @@ public:
|
|||
void add(cylinder_t *cyl);
|
||||
void clear();
|
||||
void update();
|
||||
void setDive(struct dive *d);
|
||||
|
||||
private:
|
||||
/* 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<struct dive *, int> usedRows;
|
||||
struct dive *current;
|
||||
int rows;
|
||||
};
|
||||
|
||||
/* Encapsulation of the Weight Model, that represents
|
||||
|
|
Loading…
Reference in a new issue