core: remove filterconstraint C boilerplate code

Since all code can now directly access C++ structures these
accessor functions were not necessary.

Split out the table from the filterconstraint source file
and include it directly into the divelog.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-08 18:54:23 +02:00 committed by bstoeger
parent 2bdcdab391
commit 91968ac579
20 changed files with 212 additions and 250 deletions

View file

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0
#include "filterpresetmodel.h"
#include "core/divelog.h"
#include "core/filterconstraint.h"
#include "core/filterpreset.h"
#include "core/filterpresettable.h"
#include "core/qthelper.h"
#include "core/subsurface-qt/divelistnotifier.h"
@ -26,13 +28,14 @@ FilterPresetModel *FilterPresetModel::instance()
QVariant FilterPresetModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= filter_presets_count())
if (index.row() < 0 || static_cast<size_t>(index.row()) >= divelog.filter_presets.size())
return QVariant();
const auto &filter_preset = divelog.filter_presets[index.row()];
switch (role) {
case Qt::DisplayRole:
if (index.column() == NAME)
return QString(filter_preset_name(index.row()).c_str());
return QString::fromStdString(filter_preset.name);
break;
case Qt::DecorationRole:
if (index.column() == REMOVE)
@ -52,7 +55,7 @@ QVariant FilterPresetModel::data(const QModelIndex &index, int role) const
int FilterPresetModel::rowCount(const QModelIndex &parent) const
{
return filter_presets_count();
return static_cast<int>(divelog.filter_presets.size());
}
void FilterPresetModel::reset()