aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-22 10:02:28 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-22 10:12:15 -0700
commit56c58bdd24451352e1f2a538c145f865b2546ac2 (patch)
treed34ad1da063dc337161d3e4d988ae5016fbdfc30
parentd6bee060afaaf54b731c1e27b130089ebb5a9e40 (diff)
downloadsubsurface-56c58bdd24451352e1f2a538c145f865b2546ac2.tar.gz
Actually remove cylinders and weightsystems from the data structures
The UI had only stubbed this code out. This adds the implementation of the helpers and calls them. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.h14
-rw-r--r--equipment.c19
-rw-r--r--qt-ui/models.cpp9
3 files changed, 34 insertions, 8 deletions
diff --git a/dive.h b/dive.h
index d16d2445a..968804581 100644
--- a/dive.h
+++ b/dive.h
@@ -155,12 +155,6 @@ typedef struct {
const char *description; /* "integrated", "belt", "ankle" */
} weightsystem_t;
-extern bool cylinder_nodata(cylinder_t *cyl);
-extern bool cylinder_none(void *_data);
-extern bool weightsystem_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);
extern double get_volume_units(unsigned int ml, int *frac, const char **units);
@@ -743,6 +737,14 @@ struct tank_info {
int cuft, ml, psi, bar;
};
+extern bool cylinder_nodata(cylinder_t *cyl);
+extern bool cylinder_none(void *_data);
+extern bool weightsystem_none(void *_data);
+extern bool no_weightsystems(weightsystem_t *ws);
+extern bool weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2);
+extern void remove_cylinder(struct dive *dive, int idx);
+extern void remove_weightsystem(struct dive *dive, int idx);
+
#ifdef __cplusplus
}
#endif
diff --git a/equipment.c b/equipment.c
index 5f858f41d..2c17b985e 100644
--- a/equipment.c
+++ b/equipment.c
@@ -1267,7 +1267,26 @@ static void add_cb(GtkWidget *w, int w_idx)
cylinder_list[w_idx].max_index++;
gtk_widget_set_sensitive(cylinder_list[w_idx].add, cylinder_list[w_idx].max_index < MAX_CYLINDERS);
}
+#endif /* USE_GTK_UI */
+void remove_cylinder(struct dive *dive, int idx)
+{
+ cylinder_t *cyl = dive->cylinder + idx;
+ int nr = MAX_CYLINDERS - idx - 1;
+ memmove(cyl, cyl + 1, nr * sizeof(*cyl));
+ memset(cyl + nr, 0, sizeof(*cyl));
+}
+
+void remove_weightsystem(struct dive *dive, int idx)
+{
+ weightsystem_t *ws = dive->weightsystem + idx;
+ int nr = MAX_WEIGHTSYSTEMS - idx - 1;
+ memmove(ws, ws + 1, nr * sizeof(*ws));
+ memset(ws + nr, 0, sizeof(*ws));
+}
+
+
+#if USE_GTK_UI
static void del_cb(GtkButton *button, int w_idx)
{
int index, nr;
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 360058dfd..ee1ae78ac 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -6,6 +6,7 @@
*/
#include "models.h"
#include "../helpers.h"
+#include "../dive.h"
#include <QCoreApplication>
#include <QDebug>
#include <QColor>
@@ -226,7 +227,9 @@ void CylindersModel::remove(const QModelIndex& index)
return;
}
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
- // Remove code should be here.
+ rows--;
+ remove_cylinder(current, index.row());
+ mark_divelist_changed(TRUE);
endRemoveRows();
}
@@ -236,7 +239,9 @@ void WeightModel::remove(const QModelIndex& index)
return;
}
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
- // Remove code should be here.
+ rows--;
+ remove_weightsystem(current, index.row());
+ mark_divelist_changed(TRUE);
endRemoveRows();
}