From 605e1e19ed0c52a16580c95e36ae79e71b539351 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 17 Aug 2018 00:58:30 +0200 Subject: Cleanup: const-ify functions taking pointers to events This is another entry in the series to make more things "const-clean" with the ultimate goal of merge_dive() take const pointers. This concerns functions taking pointers to events and the fallout from making these const. The somewhat debatable part of this commit might be that get_next_event() is split in a two distinct (const and non-const) versions with different names, since C doesn't allow overloading. The linker should recognize that these functions are identical and remove one of them. Signed-off-by: Berthold Stoeger --- profile-widget/diveprofileitem.cpp | 2 +- profile-widget/profilewidget2.cpp | 4 ++-- profile-widget/tankitem.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'profile-widget') diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 5a359b3e8..932586f12 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -411,7 +411,7 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem if (i < poly.count()) { double value = dataModel->index(i, vDataColumn).data().toDouble(); struct gasmix gasmix = { 0 }; - struct event *ev = NULL; + const 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); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 4ea1f36d2..a40908e5c 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -1452,7 +1452,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) action->setData(event->globalPos()); QAction *splitAction = m.addAction(tr("Split dive into two"), this, SLOT(splitDive())); splitAction->setData(event->globalPos()); - struct event *ev = NULL; + const struct event *ev = NULL; enum divemode_t divemode = UNDEF_COMP_TYPE; QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos())); QString gas = action->text(); @@ -1695,7 +1695,7 @@ void ProfileWidget2::changeGas() // if there is a gas change at this time stamp, remove it before adding the new one struct event *gasChangeEvent = current_dc->events; - while ((gasChangeEvent = get_next_event(gasChangeEvent, "gaschange")) != NULL) { + while ((gasChangeEvent = get_next_event_mutable(gasChangeEvent, "gaschange")) != NULL) { if (gasChangeEvent->time.seconds == seconds) { remove_event(gasChangeEvent); gasChangeEvent = current_dc->events; diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp index 5a8b8ca48..2bbcdc1a7 100644 --- a/profile-widget/tankitem.cpp +++ b/profile-widget/tankitem.cpp @@ -108,7 +108,7 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&) int startTime = 0; // work through all the gas changes and add the rectangle for each gas while it was used - struct event *ev = get_next_event(dc->events, "gaschange"); + const struct event *ev = get_next_event(dc->events, "gaschange"); while (ev && (int)ev->time.seconds < last_entry->sec) { width = hAxis->posAtValue(ev->time.seconds) - hAxis->posAtValue(startTime); left = hAxis->posAtValue(startTime); -- cgit v1.2.3-70-g09d2