Correctly use the weightsystem_none / cylinder_none helpers

Plus a couple of minor formatting changes

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-05-21 11:29:21 -07:00
parent e7b84233af
commit 19586081ed
3 changed files with 14 additions and 16 deletions

1
dive.h
View file

@ -157,6 +157,7 @@ typedef struct {
extern bool cylinder_nodata(cylinder_t *cyl); extern bool cylinder_nodata(cylinder_t *cyl);
extern bool cylinder_none(void *_data); extern bool cylinder_none(void *_data);
extern bool weightsystem_none(void *_data);
extern bool no_weightsystems(weightsystem_t *ws); extern bool no_weightsystems(weightsystem_t *ws);
extern bool weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2); extern bool weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2);

View file

@ -513,7 +513,7 @@ static gboolean description_equal(const char *desc1, const char *desc2)
(desc1 && desc2 && strcmp(desc1, desc2) == 0)); (desc1 && desc2 && strcmp(desc1, desc2) == 0));
} }
static gboolean weightsystem_none(void *_data) gboolean weightsystem_none(void *_data)
{ {
weightsystem_t *ws = _data; weightsystem_t *ws = _data;
return !ws->weight.grams && !ws->description; return !ws->weight.grams && !ws->description;

View file

@ -136,10 +136,10 @@ void CylindersModel::setDive(dive* d)
if (current) if (current)
clear(); clear();
int amount = 0; int amount = MAX_CYLINDERS;
for(int i = 0; i < MAX_CYLINDERS; i++){ for(int i = 0; i < MAX_CYLINDERS; i++){
cylinder_t& cylinder = d->cylinder[i]; cylinder_t *cylinder = &d->cylinder[i];
if (!cylinder.type.description){ if (cylinder_none(cylinder)) {
amount = i; amount = i;
break; break;
} }
@ -217,9 +217,8 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r
void WeightModel::add(weightsystem_t* weight) void WeightModel::add(weightsystem_t* weight)
{ {
if (rows >= MAX_WEIGHTSYSTEMS) { if (rows >= MAX_WEIGHTSYSTEMS)
return; return;
}
int row = rows; int row = rows;
@ -243,10 +242,10 @@ void WeightModel::setDive(dive* d)
if (current) if (current)
clear(); clear();
int amount = 0; int amount = MAX_WEIGHTSYSTEMS;
for(int i = 0; i < MAX_WEIGHTSYSTEMS; i++) { for(int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
weightsystem_t& weightsystem = d->weightsystem[i]; weightsystem_t *weightsystem = &d->weightsystem[i];
if (!weightsystem.description){ if (weightsystem_none(weightsystem)) {
amount = i; amount = i;
break; break;
} }
@ -528,13 +527,11 @@ QVariant DiveItem::data(int column, int role) const
break; break;
} }
if(role == STAR_ROLE){ if (role == STAR_ROLE)
retVal = dive->rating; retVal = dive->rating;
}
if(role == DIVE_ROLE){ if (role == DIVE_ROLE)
retVal = QVariant::fromValue<void*>(dive); retVal = QVariant::fromValue<void*>(dive);
}
return retVal; return retVal;
} }