summaryrefslogtreecommitdiffstats
path: root/profile-widget
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-08-16 19:10:10 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-08-23 05:16:38 -0700
commit360f07e4533d4ede7ba494724382fc8dbcb4649c (patch)
tree73a222ad3469e8a7fd085cb2671d12dac664aeac /profile-widget
parent5c4569247a31cf9f52238bd2b3f9c87b8f79933a (diff)
downloadsubsurface-360f07e4533d4ede7ba494724382fc8dbcb4649c.tar.gz
Cleanup: pass gasmix by value
In a previous commit, the get_gasmix_* functions were changed to return by value. For consistency, also pass gasmix by value. Note that on common 64-bit platforms struct gasmix is the size of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the same space on the stack. On 32-bit platforms, the stack use is probably doubled, but in return a dereference is avoided. Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an invasive change that going back to pointers is probably the least of our worries. This commit is a step in const-ifying input parameters (passing by value is the ultimate way of signaling that the input parameter will not be changed [unless there are references to said parameter]). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget')
-rw-r--r--profile-widget/diveeventitem.cpp16
-rw-r--r--profile-widget/diveeventitem.h6
-rw-r--r--profile-widget/diveprofileitem.cpp4
-rw-r--r--profile-widget/profilewidget2.cpp4
-rw-r--r--profile-widget/tankitem.cpp10
-rw-r--r--profile-widget/tankitem.h2
6 files changed, 21 insertions, 21 deletions
diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp
index 875954b37..64de02436 100644
--- a/profile-widget/diveeventitem.cpp
+++ b/profile-widget/diveeventitem.cpp
@@ -51,7 +51,7 @@ struct event *DiveEventItem::getEvent()
return internalEvent;
}
-void DiveEventItem::setEvent(struct event *ev, struct gasmix *lastgasmix)
+void DiveEventItem::setEvent(struct event *ev, struct gasmix lastgasmix)
{
if (!ev)
return;
@@ -63,7 +63,7 @@ void DiveEventItem::setEvent(struct event *ev, struct gasmix *lastgasmix)
recalculatePos(true);
}
-void DiveEventItem::setupPixmap(struct gasmix *lastgasmix)
+void DiveEventItem::setupPixmap(struct gasmix lastgasmix)
{
const IconMetrics& metrics = defaultIconMetrics();
#ifndef SUBSURFACE_MOBILE
@@ -94,13 +94,13 @@ void DiveEventItem::setupPixmap(struct gasmix *lastgasmix)
} else if (event_is_gaschange(internalEvent)) {
struct gasmix mix = get_gasmix_from_event(&displayed_dive, internalEvent);
struct icd_data icd_data;
- bool icd = isobaric_counterdiffusion(lastgasmix, &mix, &icd_data);
+ bool icd = isobaric_counterdiffusion(lastgasmix, mix, &icd_data);
if (mix.he.permille) {
if (icd)
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-trimix-ICD-icon"));
else
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-trimix-icon"));
- } else if (gasmix_is_air(&mix)) {
+ } else if (gasmix_is_air(mix)) {
if (icd)
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-air-ICD-icon"));
else
@@ -165,7 +165,7 @@ void DiveEventItem::setupPixmap(struct gasmix *lastgasmix)
#undef EVENT_PIXMAP_BIGGER
}
-void DiveEventItem::setupToolTipString(struct gasmix *lastgasmix)
+void DiveEventItem::setupToolTipString(struct gasmix lastgasmix)
{
// we display the event on screen - so translate
QString name = gettextFromC::tr(internalEvent->name);
@@ -177,12 +177,12 @@ void DiveEventItem::setupToolTipString(struct gasmix *lastgasmix)
struct gasmix mix = get_gasmix_from_event(&displayed_dive, internalEvent);
struct membuffer mb = {};
name += ": ";
- name += gasname(&mix);
+ name += gasname(mix);
/* Do we have an explicit cylinder index? Show it. */
if (internalEvent->gas.index >= 0)
name += tr(" (cyl. %1)").arg(internalEvent->gas.index + 1);
- bool icd = isobaric_counterdiffusion(lastgasmix, &mix, &icd_data);
+ bool icd = isobaric_counterdiffusion(lastgasmix, mix, &icd_data);
if (icd_data.dHe < 0) {
put_format(&mb, "\n%s %s:%+.3g%% %s:%+.3g%%%s%+.3g%%",
qPrintable(tr("ICD")),
@@ -192,7 +192,7 @@ void DiveEventItem::setupToolTipString(struct gasmix *lastgasmix)
name += QString::fromUtf8(mb.buffer, mb.len);
free_buffer(&mb);
}
- *lastgasmix = mix;
+ lastgasmix = mix;
} else if (same_string(internalEvent->name, "modechange")) {
name += QString(": %1").arg(gettextFromC::tr(divemode_text_ui[internalEvent->value]));
} else if (value) {
diff --git a/profile-widget/diveeventitem.h b/profile-widget/diveeventitem.h
index a3535f8aa..6547fa716 100644
--- a/profile-widget/diveeventitem.h
+++ b/profile-widget/diveeventitem.h
@@ -13,7 +13,7 @@ class DiveEventItem : public DivePixmapItem {
public:
DiveEventItem(QGraphicsItem *parent = 0);
~DiveEventItem();
- void setEvent(struct event *ev, struct gasmix *lastgasmix);
+ void setEvent(struct event *ev, struct gasmix lastgasmix);
struct event *getEvent();
void eventVisibilityChanged(const QString &eventName, bool visible);
void setVerticalAxis(DiveCartesianAxis *axis);
@@ -25,8 +25,8 @@ slots:
void recalculatePos(bool instant = false);
private:
- void setupToolTipString(struct gasmix *lastgasmix);
- void setupPixmap(struct gasmix *lastgasmix);
+ void setupToolTipString(struct gasmix lastgasmix);
+ void setupPixmap(struct gasmix lastgasmix);
DiveCartesianAxis *vAxis;
DiveCartesianAxis *hAxis;
DivePlotDataModel *dataModel;
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp
index 94fb787b1..5a359b3e8 100644
--- a/profile-widget/diveprofileitem.cpp
+++ b/profile-widget/diveprofileitem.cpp
@@ -413,8 +413,8 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
struct gasmix gasmix = { 0 };
struct event *ev = NULL;
int sec = dataModel->index(i, DivePlotDataModel::TIME).data().toInt();
- gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, &gasmix);
- int inert = 1000 - get_o2(&gasmix);
+ gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, gasmix);
+ int inert = 1000 - get_o2(gasmix);
mypen.setBrush(QBrush(ColorScale(value, inert)));
painter->setPen(mypen);
painter->drawLine(poly[i - 1], poly[i]);
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 9371047bd..4ea1f36d2 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -781,7 +781,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force, bool doClearPictures)
item->setHorizontalAxis(timeAxis);
item->setVerticalAxis(profileYAxis);
item->setModel(dataModel);
- item->setEvent(event, &lastgasmix);
+ item->setEvent(event, lastgasmix);
item->setZValue(2);
scene()->addItem(item);
eventItems.push_back(item);
@@ -1710,7 +1710,7 @@ void ProfileWidget2::changeGas()
tank = rx.cap(1).toInt() - 1; // we display the tank 1 based
} else {
qDebug() << "failed to parse tank number";
- tank = get_gasidx(&displayed_dive, &gasmix);
+ tank = get_gasidx(&displayed_dive, gasmix);
}
// add this both to the displayed dive and the current dive
add_gas_switch_event(current_dive, current_dc, seconds, tank);
diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp
index d1adae41c..5a8b8ca48 100644
--- a/profile-widget/tankitem.cpp
+++ b/profile-widget/tankitem.cpp
@@ -57,15 +57,15 @@ void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, str
modelDataChanged();
}
-void TankItem::createBar(qreal x, qreal w, struct gasmix *gas)
+void TankItem::createBar(qreal x, qreal w, struct gasmix gas)
{
// pick the right gradient, size, position and text
QGraphicsRectItem *rect = new QGraphicsRectItem(x, 0, w, height, this);
if (gasmix_is_air(gas))
rect->setBrush(air);
- else if (gas->he.permille)
+ else if (gas.he.permille)
rect->setBrush(trimix);
- else if (gas->o2.permille == 1000)
+ else if (gas.o2.permille == 1000)
rect->setBrush(oxygen);
else
rect->setBrush(nitrox);
@@ -112,14 +112,14 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&)
while (ev && (int)ev->time.seconds < last_entry->sec) {
width = hAxis->posAtValue(ev->time.seconds) - hAxis->posAtValue(startTime);
left = hAxis->posAtValue(startTime);
- createBar(left, width, &gasmix);
+ createBar(left, width, gasmix);
startTime = ev->time.seconds;
gasmix = get_gasmix_from_event(&displayed_dive, ev);
ev = get_next_event(ev->next, "gaschange");
}
width = hAxis->posAtValue(last_entry->sec) - hAxis->posAtValue(startTime);
left = hAxis->posAtValue(startTime);
- createBar(left, width, &gasmix);
+ createBar(left, width, gasmix);
}
void TankItem::setHorizontalAxis(DiveCartesianAxis *horizontal)
diff --git a/profile-widget/tankitem.h b/profile-widget/tankitem.h
index 8ccfcb5bb..433b1444f 100644
--- a/profile-widget/tankitem.h
+++ b/profile-widget/tankitem.h
@@ -25,7 +25,7 @@ public slots:
void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
private:
- void createBar(qreal x, qreal w, struct gasmix *gas);
+ void createBar(qreal x, qreal w, struct gasmix gas);
DivePlotDataModel *dataModel;
DiveCartesianAxis *hAxis;
struct dive diveCylinderStore;