• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
MapThemeSortFilterProxyModel.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2008 Claudiu Covaci <claudiu.covaci@gmail.com>
9 // Copyright 2009 Torsten Rahn <tackat@kde.org>
10 //
11 
12 #include "MapThemeSortFilterProxyModel.h"
13 
14 #include <QString>
15 #include <QModelIndex>
16 #include <QDateTime>
17 #include <QSettings>
18 
19 /* TRANSLATOR Marble::MapThemeSortFilterProxyModel */
20 
21 namespace Marble {
22 
23 MapThemeSortFilterProxyModel::MapThemeSortFilterProxyModel( QObject *parent )
24  : QSortFilterProxyModel( parent )
25 {
26  // nothing to do
27 }
28 
29 bool MapThemeSortFilterProxyModel::lessThan ( const QModelIndex & left, const QModelIndex & right ) const
30 {
31  if( isFavorite( left ) ) {
32  if( !isFavorite( right ) ) {
33  return true;
34  }
35  }
36  else {
37  if( isFavorite( right ) ) {
38  return false;
39  }
40  }
41  if( isFavorite( left ) && isFavorite( right ) ) {
42  if( favoriteDateTime( left ) != favoriteDateTime( right ) ) {
43  return favoriteDateTime( left ) > favoriteDateTime( right );
44  }
45  }
46  return sourceModel()->data( left ).toString() < sourceModel()->data( right ).toString();;
47 }
48 
49 bool MapThemeSortFilterProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
50  {
51  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
52  return (sourceModel()->data( index, Qt::UserRole + 1 ).toString().contains( filterRegExp() ) );
53  }
54 
55 bool MapThemeSortFilterProxyModel::isFavorite( const QModelIndex& index )
56 {
57  const QAbstractItemModel *model = index.model();
58  QModelIndex columnIndex = model->index( index.row(), 0, QModelIndex() );
59  QString const key = "Favorites/" + model->data( columnIndex ).toString();
60  return QSettings().contains( key );
61 }
62 
63 QDateTime MapThemeSortFilterProxyModel::favoriteDateTime( const QModelIndex& index )
64 {
65  const QAbstractItemModel *model = index.model();
66  QModelIndex columnIndex = model->index( index.row(), 0, QModelIndex() );
67  QString const key = "Favorites/" + model->data( columnIndex ).toString();
68  return QSettings().value( key ).toDateTime();
69 }
70 
71 }
72 
73 #include "MapThemeSortFilterProxyModel.moc"
QSortFilterProxyModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QModelIndex
QAbstractItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
QVariant::toDateTime
QDateTime toDateTime() const
Marble::MapThemeSortFilterProxyModel::filterAcceptsRow
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
Definition: MapThemeSortFilterProxyModel.cpp:49
Marble::MapThemeSortFilterProxyModel::lessThan
bool lessThan(const QModelIndex &left, const QModelIndex &right) const
Definition: MapThemeSortFilterProxyModel.cpp:29
QObject
QSettings::contains
bool contains(const QString &key) const
QModelIndex::row
int row() const
QAbstractItemModel::data
virtual QVariant data(const QModelIndex &index, int role) const =0
QString
QSettings
MapThemeSortFilterProxyModel.h
QSortFilterProxyModel
QSettings::value
QVariant value(const QString &key, const QVariant &defaultValue) const
QAbstractProxyModel::sourceModel
QAbstractItemModel * sourceModel() const
QModelIndex::model
const QAbstractItemModel * model() const
QAbstractItemModel
QVariant::toString
QString toString() const
Marble::MapThemeSortFilterProxyModel::MapThemeSortFilterProxyModel
MapThemeSortFilterProxyModel(QObject *parent=0)
Definition: MapThemeSortFilterProxyModel.cpp:23
QSortFilterProxyModel::data
virtual QVariant data(const QModelIndex &index, int role) const
QDateTime
QSortFilterProxyModel::filterRegExp
QRegExp filterRegExp() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal