Marble

MapThemeSortFilterProxyModel.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2008 Claudiu Covaci <[email protected]>
4 // SPDX-FileCopyrightText: 2009 Torsten Rahn <[email protected]>
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 
16 namespace Marble {
17 
18 MapThemeSortFilterProxyModel::MapThemeSortFilterProxyModel( QObject *parent )
19  : QSortFilterProxyModel( parent )
20 {
21  // nothing to do
22 }
23 
24 bool 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 
39 bool 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 
45 bool 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 
53 QDateTime 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"
UserRole
virtual QVariant data(const QModelIndex &index, int role) const const=0
QVariant value(const QString &key, const QVariant &defaultValue) const const
bool contains(const QString &key) const const
Binds a QML item to a specific geodetic location in screen coordinates.
int row() const const
QDateTime toDateTime() const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual QVariant data(const QModelIndex &index, int role) const const override
QChar * data()
const QAbstractItemModel * model() const const
char * toString(const EngineQuery &query)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Oct 2 2023 03:52:09 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.