Marble

MapThemeSortFilterProxyModel.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2008 Claudiu Covaci <claudiu.covaci@gmail.com>
4// SPDX-FileCopyrightText: 2009 Torsten Rahn <tackat@kde.org>
5//
6
7#include "MapThemeSortFilterProxyModel.h"
8
9#include <QDateTime>
10#include <QModelIndex>
11#include <QSettings>
12#include <QString>
13
14/* TRANSLATOR Marble::MapThemeSortFilterProxyModel */
15
16namespace Marble
17{
18
19MapThemeSortFilterProxyModel::MapThemeSortFilterProxyModel(QObject *parent)
20 : QSortFilterProxyModel(parent)
21{
22 // nothing to do
23}
24
25bool MapThemeSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
26{
27 if (isFavorite(left)) {
28 if (!isFavorite(right)) {
29 return true;
30 }
31 } else {
32 if (isFavorite(right)) {
33 return false;
34 }
35 }
36 return sourceModel()->data(left).toString() < sourceModel()->data(right).toString();
37}
38
39bool MapThemeSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
40{
41 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
42 return (sourceModel()->data(index, Qt::UserRole + 1).toString().contains(filterRegularExpression()));
43}
44
45bool MapThemeSortFilterProxyModel::isFavorite(const QModelIndex &index)
46{
47 const QAbstractItemModel *model = index.model();
48 QModelIndex columnIndex = model->index(index.row(), 0, QModelIndex());
49 QString const key = QLatin1StringView("Favorites/") + model->data(columnIndex).toString();
50 return QSettings().contains(key);
51}
52
53QDateTime MapThemeSortFilterProxyModel::favoriteDateTime(const QModelIndex &index)
54{
55 const QAbstractItemModel *model = index.model();
56 QModelIndex columnIndex = model->index(index.row(), 0, QModelIndex());
57 QString const key = QLatin1StringView("Favorites/") + model->data(columnIndex).toString();
58 return QSettings().value(key).toDateTime();
59}
60
61}
62
63#include "moc_MapThemeSortFilterProxyModel.cpp"
char * toString(const EngineQuery &query)
Binds a QML item to a specific geodetic location in screen coordinates.
virtual QVariant data(const QModelIndex &index, int role) const const=0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
const QAbstractItemModel * model() const const
int row() const const
bool contains(QAnyStringView key) const const
QVariant value(QAnyStringView key) const const
virtual QVariant data(const QModelIndex &index, int role) const const override
QChar * data()
UserRole
QDateTime toDateTime() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:14:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.