From ff653f721c01b98587236c0b4e0cf662cb3a33a6 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 27 Jun 2019 07:52:15 +0200 Subject: Cylinders: dynamically allocate cylinder arrays When keeping track of cylinder related data, the code was using static arrays of MAX_CYLINDERS length. If we want to use dynamically sized cylinder arrays, these have to be dynamically allocated. In C++ code, this is trivial: simply replace the C-style arrays by std::vector<>. Don't use QVector, as no reference counting or COW semantics are needed here. These are purely local and unshared arrays. Signed-off-by: Berthold Stoeger --- profile-widget/diveprofileitem.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'profile-widget/diveprofileitem.cpp') diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 521e3fb82..da3028ebb 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -659,9 +659,9 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo if (!shouldCalculateStuff(topLeft, bottomRight)) return; - int plotted_cyl[MAX_CYLINDERS] = { false, }; - int last_plotted[MAX_CYLINDERS] = { 0, }; - QPolygonF poly[MAX_CYLINDERS]; + std::vector plotted_cyl(MAX_CYLINDERS, false); + std::vector last_plotted(MAX_CYLINDERS, 0); + std::vector poly(MAX_CYLINDERS); QPolygonF boundingPoly; polygons.clear(); @@ -707,9 +707,9 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo qDeleteAll(texts); texts.clear(); - int seen_cyl[MAX_CYLINDERS] = { false, }; - int last_pressure[MAX_CYLINDERS] = { 0, }; - int last_time[MAX_CYLINDERS] = { 0, }; + std::vector seen_cyl(MAX_CYLINDERS, false); + std::vector last_pressure(MAX_CYLINDERS, 0); + std::vector last_time(MAX_CYLINDERS, 0); // These are offset values used to print the gas lables and pressures on a // dive profile at appropriate Y-coordinates. We alternate aligning the @@ -720,7 +720,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo // pressures. QFlags alignVar = Qt::AlignTop; - QFlags align[MAX_CYLINDERS]; + std::vector> align(MAX_CYLINDERS); double axisRange = (vAxis->maximum() - vAxis->minimum())/1000; // Convert axis pressure range to bar double axisLog = log10(log10(axisRange)); -- cgit v1.2.3-70-g09d2