diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-10-27 18:08:07 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-10-27 12:42:21 -0700 |
commit | a7067937b0ee805f20f62b138dae7b260d20c426 (patch) | |
tree | e913bebb9396a75f190ed8bd26708d63c9cd1e0c /profile-widget | |
parent | bc11097dedd456506013caba5e886a0df4c74ead (diff) | |
download | subsurface-a7067937b0ee805f20f62b138dae7b260d20c426.tar.gz |
Profile: don't copy plot data for tank-bar
The whole plot info data was copied only so that the time of the
last item could be determined later. Instead, simply store the
timestamp.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget')
-rw-r--r-- | profile-widget/tankitem.cpp | 32 | ||||
-rw-r--r-- | profile-widget/tankitem.h | 3 |
2 files changed, 17 insertions, 18 deletions
diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp index 02b1d57d7..504d35a9e 100644 --- a/profile-widget/tankitem.cpp +++ b/profile-widget/tankitem.cpp @@ -7,9 +7,7 @@ TankItem::TankItem(QObject *parent) : QObject(parent), - QGraphicsRectItem(), - pInfoEntry(0), - pInfoNr(0) + plotEndTime(-1) { height = 3; QColor red(PERSIANRED1); @@ -35,14 +33,19 @@ TankItem::TankItem(QObject *parent) : void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, struct dive *d) { - free(pInfoEntry); - // the plotInfo and dive structures passed in could become invalid before we stop using them, - // so copy the data that we need - int size = plotInfo->nr * sizeof(plotInfo->entry[0]); - pInfoEntry = (struct plot_data *)malloc(size); - pInfoNr = plotInfo->nr; - memcpy(pInfoEntry, plotInfo->entry, size); + // If there is nothing to plot, quit early. + if (plotInfo->nr <= 0) { + plotEndTime = -1; + return; + } + + // Find correct end of the dive plot for correct end of the tankbar. + struct plot_data *last_entry = &plotInfo->entry[plotInfo->nr - 1]; + plotEndTime = last_entry->sec; + + // Stay informed of changes to the tanks. connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(modelDataChanged(QModelIndex, QModelIndex)), Qt::UniqueConnection); + modelDataChanged(); } @@ -77,16 +80,13 @@ void TankItem::createBar(int startTime, int stopTime, struct gasmix gas) void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&) { // We don't have enougth data to calculate things, quit. - if (!pInfoEntry || !pInfoNr) + if (plotEndTime < 0) return; // remove the old rectangles qDeleteAll(rects); rects.clear(); - // Find correct end of the dive plot for correct end of the tankbar - struct plot_data *last_entry = &pInfoEntry[pInfoNr-1]; - // get the information directly from the displayed_dive (the dc always exists) struct divecomputer *dc = get_dive_dc(&displayed_dive, dc_number); @@ -97,13 +97,13 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&) // work through all the gas changes and add the rectangle for each gas while it was used const struct event *ev = get_next_event(dc->events, "gaschange"); - while (ev && (int)ev->time.seconds < last_entry->sec) { + while (ev && (int)ev->time.seconds < plotEndTime) { createBar(startTime, ev->time.seconds, gasmix); startTime = ev->time.seconds; gasmix = get_gasmix_from_event(&displayed_dive, ev); ev = get_next_event(ev->next, "gaschange"); } - createBar(startTime, last_entry->sec, gasmix); + createBar(startTime, plotEndTime, gasmix); } void TankItem::setHorizontalAxis(DiveCartesianAxis *horizontal) diff --git a/profile-widget/tankitem.h b/profile-widget/tankitem.h index 4eb5710d6..545f9ad9c 100644 --- a/profile-widget/tankitem.h +++ b/profile-widget/tankitem.h @@ -26,8 +26,7 @@ public slots: private: void createBar(int startTime, int stopTime, struct gasmix gas); DiveCartesianAxis *hAxis; - struct plot_data *pInfoEntry; - int pInfoNr; + int plotEndTime; qreal height; QBrush air, nitrox, oxygen, trimix; QList<QGraphicsRectItem *> rects; |