mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
filter: add (very primitive) filterpresetmodel
Implement a trivial model to provide the filter preset names to the UI. Sadly, for now this features the QWidget/QML column / name dichotomy. However, in this simple case that shouldn't be too much of an issue. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
937fdb500b
commit
536fc05dd6
4 changed files with 93 additions and 0 deletions
59
qt-models/filterpresetmodel.cpp
Normal file
59
qt-models/filterpresetmodel.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "filterpresetmodel.h"
|
||||
#include "core/filterconstraint.h"
|
||||
#include "core/filterpreset.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
|
||||
FilterPresetModel::FilterPresetModel()
|
||||
{
|
||||
setHeaderDataStrings(QStringList{ "", tr("Name") });
|
||||
connect(&diveListNotifier, &DiveListNotifier::dataReset, this, &FilterPresetModel::reset);
|
||||
}
|
||||
|
||||
FilterPresetModel::~FilterPresetModel()
|
||||
{
|
||||
}
|
||||
|
||||
FilterPresetModel *FilterPresetModel::instance()
|
||||
{
|
||||
static FilterPresetModel self;
|
||||
return &self;
|
||||
}
|
||||
|
||||
QVariant FilterPresetModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= filter_presets_count())
|
||||
return QVariant();
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
if (index.column() == NAME)
|
||||
return filter_preset_name_qstring(index.row());
|
||||
break;
|
||||
case Qt::DecorationRole:
|
||||
if (index.column() == REMOVE)
|
||||
return trashIcon();
|
||||
break;
|
||||
case Qt::SizeHintRole:
|
||||
if (index.column() == REMOVE)
|
||||
return trashIcon().size();
|
||||
break;
|
||||
case Qt::ToolTipRole:
|
||||
if (index.column() == REMOVE)
|
||||
return tr("Clicking here will remove this filter set.");
|
||||
break;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int FilterPresetModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return filter_presets_count();
|
||||
}
|
||||
|
||||
void FilterPresetModel::reset()
|
||||
{
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue