Marble

MapThemeModel.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org>
4//
5
6#include "MapThemeModel.h"
7
8#include "MapThemeManager.h"
9#include "GeoSceneDocument.h"
10#include "GeoSceneHead.h"
11#include "GeoSceneZoom.h"
12
13#include <QModelIndex>
14#include <QDebug>
15#include <QStandardItemModel>
16
17MapThemeModel::MapThemeModel( QObject *parent ) : QSortFilterProxyModel( parent ),
18 m_themeManager( new Marble::MapThemeManager( this ) ), m_mapThemeFilters( MapThemeModel::AnyTheme )
19{
20 setSourceModel( m_themeManager->mapThemeModel() );
21 handleChangedThemes();
22 connect( m_themeManager, SIGNAL(themesChanged()), this, SLOT(handleChangedThemes()) );
23
24 QHash<int,QByteArray> roleNames;
25 roleNames[ Qt::DisplayRole ] = "display";
26 roleNames[ Qt::DecorationRole ] = "icon";
27 roleNames[ Qt::UserRole + 1 ] = "mapThemeId";
28 m_roleNames = roleNames;
29}
30
31int MapThemeModel::count() const
32{
33 return rowCount();
34}
35
36QHash<int, QByteArray> MapThemeModel::roleNames() const
37{
38 return m_roleNames;
39}
40
41QString MapThemeModel::name( const QString &id ) const
42{
43 for ( int i=0; i<rowCount(); ++i ) {
44 if ( data( index( i, 0, QModelIndex() ), Qt::UserRole + 1 ).toString() == id ) {
45 return data( index( i, 0, QModelIndex() ) ).toString();
46 }
47 }
48 return QString();
49}
50
51int MapThemeModel::indexOf( const QString &id ) const
52{
53 for ( int i=0; i<rowCount(); ++i ) {
54 if ( data( index( i, 0, QModelIndex() ), Qt::UserRole + 1 ).toString() == id ) {
55 return i;
56 }
57 }
58 return -1;
59}
60
61MapThemeModel::MapThemeFilters MapThemeModel::mapThemeFilter() const
62{
63 return m_mapThemeFilters;
64}
65
66void MapThemeModel::setMapThemeFilter( MapThemeFilters filters )
67{
68 if ( filters != m_mapThemeFilters ) {
69 m_mapThemeFilters = filters;
70 emit mapThemeFilterChanged();
71 }
72}
73
74bool MapThemeModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
75{
76 QModelIndex const index = sourceModel()->index( sourceRow, 0, sourceParent );
77 QString const themeId = index.data( Qt::UserRole + 1 ).toString();
78 if ( m_mapThemeFilters & MapThemeModel::HighZoom && m_streetMapThemeIds.contains( themeId ) ) {
79 return false;
80 }
81
82 if ( m_mapThemeFilters & MapThemeModel::LowZoom && !m_streetMapThemeIds.contains( themeId ) ) {
83 return false;
84 }
85
86 if ( m_mapThemeFilters & MapThemeModel::Terrestrial && themeId.startsWith( QLatin1String( "earth/" ) ) ) {
87 return false;
88 }
89
90 if ( m_mapThemeFilters & MapThemeModel::Extraterrestrial && !themeId.startsWith( QLatin1String( "earth/" ) ) ) {
91 return false;
92 }
93
94 return true;
95}
96
97void MapThemeModel::handleChangedThemes()
98{
99 /** @todo Extend .dgml spec by categories to simplify this
100 * The map theme model items should specify the planet and a set of
101 * categories/tags (arbitrary strings) to simplify filtering for specific
102 * map theme properties.
103 * E.g. the item for earth/openstreetmap/openstreetmap.dgml should have
104 * the planet set to earth and categories/tags like "OpenStreetMap, street map"
105 */
106
107 m_streetMapThemeIds.clear();
108 QStringList const themes = m_themeManager->mapThemeIds();
109 for( const QString &theme: themes ) {
111 if ( document && document->head()->zoom()->maximum() > 3000 ) {
112 m_streetMapThemeIds << document->head()->mapThemeId();
113 delete document;
114 }
115 }
116
119}
120
121#include "moc_MapThemeModel.cpp"
Provides access to all map themes installed locally.
A container for features parsed from the DGML file.
QStringList mapThemeIds() const
Returns a list of all locally available map theme IDs.
static GeoSceneDocument * loadMapTheme(const QString &mapThemeStringID)
Returns the map theme as a GeoSceneDocument object.
Binds a QML item to a specific geodetic location in screen coordinates.
void clear()
bool contains(const AT &value) const const
QVariant data(int role) const const
T qobject_cast(QObject *object)
virtual QVariant data(const QModelIndex &index, int role) const const override
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
virtual int rowCount(const QModelIndex &parent) const const override
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
DisplayRole
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
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:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.