Marble

TreeViewDecoratorModel.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2014 Levente Kurusa <[email protected]>
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 
18 namespace Marble
19 {
20 
21 TreeViewDecoratorModel::TreeViewDecoratorModel( QObject *parent ) :
22  QSortFilterProxyModel( parent )
23 {
24  // nothing to do
25 }
26 
27 bool 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 
42 QVariant 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 
79 void TreeViewDecoratorModel::trackExpandedState( const QModelIndex &index )
80 {
81  m_expandedRows << QPersistentModelIndex( index );
82 }
83 
84 void TreeViewDecoratorModel::trackCollapsedState( const QModelIndex &index )
85 {
86  m_expandedRows.removeAll( QPersistentModelIndex( index ));
87 }
88 
89 }
90 #include "moc_TreeViewDecoratorModel.cpp"
91 
DecorationRole
int column() const const
@ ObjectPointerRole
The pointer to a specific object.
QVariant data(int role) const const
Binds a QML item to a specific geodetic location in screen coordinates.
QString & remove(int position, int n)
virtual QVariant data(const QModelIndex &index, int role) const const override
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const const
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:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.