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