2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/filtermodels.h"
|
|
|
|
#include "core/display.h"
|
2018-08-28 18:44:11 +00:00
|
|
|
#include "core/qthelper.h"
|
2019-05-31 14:09:14 +00:00
|
|
|
#include "core/trip.h"
|
2018-05-11 15:25:41 +00:00
|
|
|
#include "core/subsurface-string.h"
|
2020-02-03 18:33:06 +00:00
|
|
|
#include "core/subsurface-qt/divelistnotifier.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/divetripmodel.h"
|
2016-07-09 19:45:55 +00:00
|
|
|
|
2018-10-21 16:00:02 +00:00
|
|
|
MultiFilterSortModel *MultiFilterSortModel::instance()
|
2018-09-06 07:52:02 +00:00
|
|
|
{
|
2018-10-21 16:00:02 +00:00
|
|
|
static MultiFilterSortModel self;
|
|
|
|
return &self;
|
2017-11-26 21:21:58 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 17:13:55 +00:00
|
|
|
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent)
|
2014-11-13 18:31:03 +00:00
|
|
|
{
|
2019-12-09 14:37:26 +00:00
|
|
|
resetModel(DiveTripModelBase::TREE);
|
2018-10-29 13:56:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 09:06:11 +00:00
|
|
|
void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout)
|
2018-10-29 13:56:48 +00:00
|
|
|
{
|
2019-12-09 14:37:26 +00:00
|
|
|
if (layout == DiveTripModelBase::TREE)
|
|
|
|
model.reset(new DiveTripModelTree);
|
|
|
|
else
|
|
|
|
model.reset(new DiveTripModelList);
|
|
|
|
|
|
|
|
setSourceModel(model.get());
|
|
|
|
connect(model.get(), &DiveTripModelBase::selectionChanged, this, &MultiFilterSortModel::selectionChangedSlot);
|
|
|
|
connect(model.get(), &DiveTripModelBase::currentDiveChanged, this, &MultiFilterSortModel::currentDiveChangedSlot);
|
|
|
|
model->initSelection();
|
2019-11-27 20:55:37 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 14:22:02 +00:00
|
|
|
void MultiFilterSortModel::clear()
|
|
|
|
{
|
2019-12-09 14:37:26 +00:00
|
|
|
model->clear();
|
2019-12-09 14:22:02 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 20:55:37 +00:00
|
|
|
// Translate selection into local indexes and re-emit signal
|
|
|
|
void MultiFilterSortModel::selectionChangedSlot(const QVector<QModelIndex> &indexes)
|
|
|
|
{
|
|
|
|
QVector<QModelIndex> indexesLocal;
|
|
|
|
indexesLocal.reserve(indexes.size());
|
|
|
|
for (const QModelIndex &index: indexes) {
|
|
|
|
QModelIndex local = mapFromSource(index);
|
|
|
|
if (local.isValid())
|
|
|
|
indexesLocal.push_back(local);
|
|
|
|
}
|
|
|
|
emit selectionChanged(indexesLocal);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Translate current dive into local indexes and re-emit signal
|
|
|
|
void MultiFilterSortModel::currentDiveChangedSlot(QModelIndex index)
|
|
|
|
{
|
|
|
|
QModelIndex local = mapFromSource(index);
|
|
|
|
if (local.isValid())
|
|
|
|
emit currentDiveChanged(mapFromSource(index));
|
2014-11-13 18:31:03 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 18:16:25 +00:00
|
|
|
bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
|
|
|
{
|
2020-02-10 18:34:55 +00:00
|
|
|
return true;
|
2014-11-13 18:31:03 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 19:17:53 +00:00
|
|
|
bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const
|
|
|
|
{
|
|
|
|
// Hand sorting down to the source model.
|
2019-12-09 14:37:26 +00:00
|
|
|
return model->lessThan(i1, i2);
|
2018-10-29 19:17:53 +00:00
|
|
|
}
|