File indexing completed on 2024-04-28 15:15:48

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2008 Claudiu Covaci <claudiu.covaci@gmail.com>
0004 // SPDX-FileCopyrightText: 2009 Torsten Rahn <tackat@kde.org>
0005 //
0006 
0007 #include "MapThemeSortFilterProxyModel.h"
0008 
0009 #include <QString>
0010 #include <QModelIndex>
0011 #include <QDateTime>
0012 #include <QSettings>
0013 
0014 /* TRANSLATOR Marble::MapThemeSortFilterProxyModel */
0015 
0016 namespace Marble {
0017 
0018 MapThemeSortFilterProxyModel::MapThemeSortFilterProxyModel( QObject *parent )
0019     : QSortFilterProxyModel( parent )
0020 {
0021     // nothing to do
0022 }
0023 
0024 bool MapThemeSortFilterProxyModel::lessThan ( const QModelIndex & left, const QModelIndex & right ) const
0025 {
0026     if( isFavorite( left ) ) {
0027         if( !isFavorite( right ) ) {
0028             return true;
0029         }
0030     }
0031     else {
0032         if( isFavorite( right ) ) {
0033             return false;
0034         }
0035     }
0036     return sourceModel()->data( left ).toString() < sourceModel()->data( right ).toString();
0037 }
0038 
0039 bool MapThemeSortFilterProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
0040  {
0041      QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
0042      return (sourceModel()->data( index, Qt::UserRole + 1 ).toString().contains( filterRegExp() ) );
0043  }
0044  
0045 bool MapThemeSortFilterProxyModel::isFavorite( const QModelIndex& index )
0046 {
0047     const QAbstractItemModel *model = index.model();
0048     QModelIndex columnIndex = model->index( index.row(), 0, QModelIndex() );
0049     QString const key = QLatin1String("Favorites/") + model->data(columnIndex).toString();
0050     return QSettings().contains( key );
0051 }
0052 
0053 QDateTime MapThemeSortFilterProxyModel::favoriteDateTime( const QModelIndex& index )
0054 {
0055     const QAbstractItemModel *model = index.model();
0056     QModelIndex columnIndex = model->index( index.row(), 0, QModelIndex() );
0057     QString const key = QLatin1String("Favorites/") + model->data(columnIndex).toString();
0058     return QSettings().value( key ).toDateTime();
0059 }
0060 
0061 }
0062 
0063 #include "moc_MapThemeSortFilterProxyModel.cpp"