mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
Rename getDiveById to get_dive_by_id to keep current c code organized.
This commit renames getDiveById to get_dive_by_id, and it also removes the Q_ASSERTS and if(!dive) return that the callers of this function were calling. If it has a Q_ASSERT this means that the dive must exist, so checking for nullness was bogus too. I've changed the assert (done in a silly C-Way. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
e1971e9425
commit
e0c0ac5d5c
5 changed files with 21 additions and 28 deletions
8
dive.h
8
dive.h
|
@ -436,7 +436,7 @@ static inline struct dive *get_dive_by_uemis_diveid(uint32_t diveid, uint32_t de
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static inline struct dive *getDiveById(int id)
|
||||
static inline struct dive *get_dive_by_diveid(int id)
|
||||
{
|
||||
int i;
|
||||
struct dive *dive = NULL;
|
||||
|
@ -445,6 +445,12 @@ static inline struct dive *getDiveById(int id)
|
|||
if (dive->id == id)
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if(dive == NULL){
|
||||
fprintf(stderr, "Invalid id %x passed to get_dive_by_diveid, try to fix the code\n", id);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
return dive;
|
||||
}
|
||||
|
||||
|
|
|
@ -1056,7 +1056,7 @@ static int nitrox_sort_value(struct dive *dive)
|
|||
QVariant DiveItem::data(int column, int role) const
|
||||
{
|
||||
QVariant retVal;
|
||||
struct dive *dive = getDiveById(diveId);
|
||||
struct dive *dive = get_dive_by_diveid(diveId);
|
||||
|
||||
switch (role) {
|
||||
case Qt::TextAlignmentRole:
|
||||
|
@ -1203,8 +1203,7 @@ bool DiveItem::setData(const QModelIndex &index, const QVariant &value, int role
|
|||
if (d->number == v)
|
||||
return false;
|
||||
}
|
||||
d = getDiveById(diveId);
|
||||
Q_ASSERT(d != NULL);
|
||||
d = get_dive_by_diveid(diveId);
|
||||
d->number = value.toInt();
|
||||
mark_divelist_changed(true);
|
||||
return true;
|
||||
|
@ -1212,8 +1211,7 @@ bool DiveItem::setData(const QModelIndex &index, const QVariant &value, int role
|
|||
|
||||
QString DiveItem::displayDate() const
|
||||
{
|
||||
struct dive *dive = getDiveById(diveId);
|
||||
Q_ASSERT(dive != NULL);
|
||||
struct dive *dive = get_dive_by_diveid(diveId);
|
||||
return get_dive_date_string(dive->when);
|
||||
}
|
||||
|
||||
|
@ -1221,8 +1219,7 @@ QString DiveItem::displayDepth() const
|
|||
{
|
||||
QString fract, str;
|
||||
const int scale = 1000;
|
||||
struct dive *dive = getDiveById(diveId);
|
||||
Q_ASSERT(dive != NULL);
|
||||
struct dive *dive = get_dive_by_diveid(diveId);
|
||||
if (get_units()->length == units::METERS) {
|
||||
fract = QString::number((unsigned)(dive->maxdepth.mm % scale) / 100);
|
||||
str = QString("%1.%2").arg((unsigned)(dive->maxdepth.mm / scale)).arg(fract, 1, QChar('0'));
|
||||
|
@ -1236,8 +1233,7 @@ QString DiveItem::displayDepth() const
|
|||
QString DiveItem::displayDuration() const
|
||||
{
|
||||
int hrs, mins, secs;
|
||||
struct dive *dive = getDiveById(diveId);
|
||||
Q_ASSERT(dive != NULL);
|
||||
struct dive *dive = get_dive_by_diveid(diveId);
|
||||
secs = dive->duration.seconds % 60;
|
||||
mins = dive->duration.seconds / 60;
|
||||
hrs = mins / 60;
|
||||
|
@ -1255,8 +1251,7 @@ QString DiveItem::displayDuration() const
|
|||
QString DiveItem::displayTemperature() const
|
||||
{
|
||||
QString str;
|
||||
struct dive *dive = getDiveById(diveId);
|
||||
Q_ASSERT(dive != NULL);
|
||||
struct dive *dive = get_dive_by_diveid(diveId);
|
||||
if (!dive->watertemp.mkelvin)
|
||||
return str;
|
||||
if (get_units()->temperature == units::CELSIUS)
|
||||
|
@ -1269,8 +1264,7 @@ QString DiveItem::displayTemperature() const
|
|||
QString DiveItem::displaySac() const
|
||||
{
|
||||
QString str;
|
||||
struct dive *dive = getDiveById(diveId);
|
||||
Q_ASSERT(dive != NULL);
|
||||
struct dive *dive = get_dive_by_diveid(diveId);
|
||||
if (get_units()->volume == units::LITER)
|
||||
str = QString::number(dive->sac / 1000.0, 'f', 1).append(tr(" l/min"));
|
||||
else
|
||||
|
@ -1286,8 +1280,7 @@ QString DiveItem::displayWeight() const
|
|||
|
||||
int DiveItem::weight() const
|
||||
{
|
||||
struct dive *dive = getDiveById(diveId);
|
||||
Q_ASSERT(dive != 0);
|
||||
struct dive *dive = get_dive_by_diveid(diveId);
|
||||
weight_t tw = { total_weight(dive) };
|
||||
return tw.grams;
|
||||
}
|
||||
|
@ -1907,8 +1900,7 @@ QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole: {
|
||||
struct dive *dive = getDiveById(diveId);
|
||||
Q_ASSERT(dive != NULL);
|
||||
struct dive *dive = get_dive_by_diveid(diveId);
|
||||
struct DiveItem di;
|
||||
di.diveId = diveId;
|
||||
|
||||
|
|
|
@ -178,9 +178,7 @@ void DivePlotDataModel::emitDataChanged()
|
|||
|
||||
void DivePlotDataModel::calculateDecompression()
|
||||
{
|
||||
struct dive *d = getDiveById(id());
|
||||
if (!d)
|
||||
return;
|
||||
struct dive *d = get_dive_by_diveid(id());
|
||||
struct divecomputer *dc = select_dc(d);
|
||||
init_decompression(d);
|
||||
calculate_deco_information(d, dc, &pInfo, false);
|
||||
|
|
|
@ -427,8 +427,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
|
|||
int last_pressure[MAX_CYLINDERS] = { 0, };
|
||||
int last_time[MAX_CYLINDERS] = { 0, };
|
||||
struct plot_data *entry;
|
||||
struct dive *dive = getDiveById(dataModel->id());
|
||||
Q_ASSERT(dive != NULL);
|
||||
struct dive *dive = get_dive_by_diveid(dataModel->id());
|
||||
|
||||
cyl = -1;
|
||||
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
|
||||
|
@ -490,9 +489,7 @@ void DiveGasPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte
|
|||
QPen pen;
|
||||
pen.setCosmetic(true);
|
||||
pen.setWidth(2);
|
||||
struct dive *d = getDiveById(dataModel->id());
|
||||
if (!d)
|
||||
return;
|
||||
struct dive *d = get_dive_by_diveid(dataModel->id());
|
||||
struct plot_data *entry = dataModel->data().entry;
|
||||
Q_FOREACH(const QPolygonF & poly, polygons) {
|
||||
for (int i = 1, count = poly.count(); i < count; i++, entry++) {
|
||||
|
|
|
@ -227,7 +227,7 @@ void ProfileWidget2::replot()
|
|||
{
|
||||
int diveId = dataModel->id();
|
||||
dataModel->clear();
|
||||
plotDives(QList<dive *>() << getDiveById(diveId));
|
||||
plotDives(QList<dive *>() << get_dive_by_diveid(diveId));
|
||||
}
|
||||
|
||||
void ProfileWidget2::setupItemSizes()
|
||||
|
@ -808,7 +808,7 @@ void ProfileWidget2::changeGas()
|
|||
int diveId = dataModel->id();
|
||||
int o2, he;
|
||||
int seconds = timeAxis->valueAt(scenePos);
|
||||
struct dive *d = getDiveById(diveId);
|
||||
struct dive *d = get_dive_by_diveid(diveId);
|
||||
|
||||
validate_gas(gas.toUtf8().constData(), &o2, &he);
|
||||
add_gas_switch_event(d, get_dive_dc(d, diveComputer), seconds, get_gasidx(d, o2, he));
|
||||
|
|
Loading…
Reference in a new issue