Marble

TreeViewDecoratorModel.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2014 Levente Kurusa <levex@linux.com>
4
5#include "TreeViewDecoratorModel.h"
6#include "MarbleDebug.h"
7#include "GeoDataFolder.h"
8#include "GeoDataObject.h"
9#include "GeoDataContainer.h"
10#include "GeoDataStyle.h"
11#include "GeoDataListStyle.h"
12#include "GeoDataItemIcon.h"
13#include "GeoDataGeometry.h"
14#include "MarblePlacemarkModel.h"
15
16#include <QImage>
17
18namespace Marble
19{
20
21TreeViewDecoratorModel::TreeViewDecoratorModel( QObject *parent ) :
22 QSortFilterProxyModel( parent )
23{
24 // nothing to do
25}
26
27bool TreeViewDecoratorModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
28{
29 QModelIndex rowIndex = sourceModel()->index( sourceRow, 0, sourceParent );
30
31 const GeoDataObject* object = qvariant_cast<GeoDataObject*>( rowIndex.data( MarblePlacemarkModel::ObjectPointerRole ) );
32 const GeoDataObject* parent = object->parent();
33 if (const auto container = dynamic_cast<const GeoDataContainer *>(parent)) {
34 if ( container->style()->listStyle().listItemType() == GeoDataListStyle::CheckHideChildren ) {
35 return false;
36 }
37 }
38
39 return QSortFilterProxyModel::filterAcceptsRow( sourceRow, sourceParent );
40}
41
42QVariant TreeViewDecoratorModel::data( const QModelIndex &proxyIndex, int role) const
43{
44 if ( role != Qt::DecorationRole || proxyIndex.column() != 0 ) {
45 if (proxyIndex.column() == 1) {
46 return QSortFilterProxyModel::data(proxyIndex, role).toString().remove("GeoData");
47 }
48 else {
49 return QSortFilterProxyModel::data(proxyIndex, role);
50 }
51 }
52
53 GeoDataObject *object = qvariant_cast<GeoDataObject *>( QSortFilterProxyModel::data(proxyIndex, MarblePlacemarkModel::ObjectPointerRole));
54 if ( !object ) {
55 return QSortFilterProxyModel::data(proxyIndex, role);
56 }
57
58 GeoDataFolder *folder = dynamic_cast<GeoDataFolder *>( object );
59
60 if (folder) {
61 bool const expandedState = m_expandedRows.contains( QPersistentModelIndex( proxyIndex ) );
62
63 for (GeoDataItemIcon *icon: folder->style()->listStyle().itemIconList()) {
64 if ( ! expandedState ) {
65 if ( icon->state() == GeoDataItemIcon::Closed ) {
66 return icon->icon();
67 }
68 } else {
69 if ( icon->state() == GeoDataItemIcon::Open ) {
70 return icon->icon();
71 }
72 }
73 }
74 }
75
76 return QSortFilterProxyModel::data(proxyIndex, role);
77}
78
79void TreeViewDecoratorModel::trackExpandedState( const QModelIndex &index )
80{
81 m_expandedRows << QPersistentModelIndex( index );
82}
83
84void TreeViewDecoratorModel::trackCollapsedState( const QModelIndex &index )
85{
86 m_expandedRows.removeAll( QPersistentModelIndex( index ));
87}
88
89}
90#include "moc_TreeViewDecoratorModel.cpp"
91
Binds a QML item to a specific geodetic location in screen coordinates.
int column() const const
QVariant data(int role) const const
virtual QVariant data(const QModelIndex &index, int role) const const override
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
DecorationRole
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.