core: turn C dive-table into an owning table

This is a humongous commit, because it touches all parts of the
code. It removes the last user of our horrible TABLE macros, which
simulate std::vector<> in a very clumsy way.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-07 10:25:09 +02:00 committed by bstoeger
parent f00c30ad4a
commit b95ac3f79c
73 changed files with 1030 additions and 1230 deletions

View file

@ -755,9 +755,9 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
bottom = first_selected_dive();
}
}
if (is_trip_before_after(top, (currentOrder == Qt::AscendingOrder)))
if (divelog.is_trip_before_after(top, (currentOrder == Qt::AscendingOrder)))
popup.addAction(tr("Add dive(s) to trip immediately above","",amount_selected), this, &DiveListView::addToTripAbove);
if (is_trip_before_after(bottom, (currentOrder == Qt::DescendingOrder)))
if (divelog.is_trip_before_after(bottom, (currentOrder == Qt::DescendingOrder)))
popup.addAction(tr("Add dive(s) to trip immediately below","",amount_selected), this, &DiveListView::addToTripBelow);
}
}

View file

@ -465,7 +465,7 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
qPrefDiveComputer::set_device(data->devName());
// before we start, remember where the dive_table ended
previousLast = divelog.dives->nr;
previousLast = static_cast<int>(divelog.dives.size());
diveImportedModel->startDownload();
// FIXME: We should get the _actual_ device info instead of whatever

View file

@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include "findmovedimagesdialog.h"
#include "core/divelog.h"
#include "core/divelist.h"
#include "core/picture.h"
#include "core/qthelper.h"
#include "desktop-widgets/divelistview.h" // TODO: used for lastUsedImageDir()
@ -184,12 +186,12 @@ void FindMovedImagesDialog::on_scanButton_clicked()
// We have to collect the names of the image filenames in the main thread
bool onlySelected = ui.onlySelectedDives->isChecked();
QVector<QString> imagePaths;
int i;
struct dive *dive;
for_each_dive (i, dive)
if (!onlySelected || dive->selected)
for (auto &dive: divelog.dives) {
if (!onlySelected || dive->selected) {
for (auto &picture: dive->pictures)
imagePaths.append(QString::fromStdString(picture.filename));
}
}
stopScanning = 0;
QFuture<QVector<Match>> future = QtConcurrent::run(
// Note that we capture everything but "this" by copy to avoid dangling references.

View file

@ -430,7 +430,7 @@ void MainWindow::on_actionCloudstorageopen_triggered()
// Return whether saving to cloud is OK. If it isn't, show an error return false.
static bool saveToCloudOK()
{
if (!divelog.dives->nr) {
if (divelog.dives.empty()) {
report_error("%s", qPrintable(gettextFromC::tr("Don't save an empty log to the cloud")));
return false;
}

View file

@ -1,7 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
#include "printer.h"
#include "templatelayout.h"
#include "core/dive.h" // for get_dive_by_uniq_id()
#include "core/divelist.h"
#include "core/divelog.h"
#include "core/selection.h"
#include "core/statistics.h"
#include "core/qthelper.h"
@ -129,7 +130,7 @@ void Printer::render(int pages)
// dive id field should be dive_{{dive_no}} se we remove the first 5 characters
QString diveIdString = collection.at(elemNo).attribute("id");
int diveId = diveIdString.remove(0, 5).toInt(0, 10);
putProfileImage(collection.at(elemNo).geometry(), viewPort, &painter, get_dive_by_uniq_id(diveId), profile.get());
putProfileImage(collection.at(elemNo).geometry(), viewPort, &painter, divelog.dives.get_by_uniq_id(diveId), profile.get());
elemNo++;
}
@ -160,10 +161,8 @@ std::vector<dive *> Printer::getDives() const
return getDiveSelection();
} else {
std::vector<dive *> res;
int i;
struct dive *dive;
for_each_dive (i, dive)
res.push_back(dive);
for (auto &d: divelog.dives)
res.push_back(d.get());
return res;
}
}

View file

@ -31,12 +31,10 @@ void RenumberDialog::buttonClicked(QAbstractButton *button)
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
// we remember a list from dive uuid to a new number
QVector<QPair<dive *, int>> renumberedDives;
int i;
int newNr = ui.spinBox->value();
struct dive *d;
for_each_dive (i, d) {
for (auto &d: divelog.dives) {
if (!selectedOnly || d->selected)
renumberedDives.append({ d, newNr++ });
renumberedDives.append({ d.get(), newNr++ });
}
Command::renumberDives(renumberedDives);
}