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 <QString>
10#include <QModelIndex>
11#include <QDateTime>
12#include <QSettings>
13
14/* TRANSLATOR Marble::MapThemeSortFilterProxyModel */
15
16namespace Marble {
17
18MapThemeSortFilterProxyModel::MapThemeSortFilterProxyModel( QObject *parent )
19 : QSortFilterProxyModel( parent )
20{
21 // nothing to do
22}
23
24bool MapThemeSortFilterProxyModel::lessThan ( const QModelIndex & left, const QModelIndex & right ) const
25{
26 if( isFavorite( left ) ) {
27 if( !isFavorite( right ) ) {
28 return true;
29 }
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( filterRegExp() ) );
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 = QLatin1String("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 = QLatin1String("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 Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.