• 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
TreeViewDecoratorModel.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 2014 Levente Kurusa <levex@linux.com>
9 
10 #include "TreeViewDecoratorModel.h"
11 #include "MarbleDebug.h"
12 #include "GeoDataFolder.h"
13 #include "GeoDataTypes.h"
14 #include "GeoDataObject.h"
15 #include "GeoDataContainer.h"
16 #include "GeoDataStyle.h"
17 #include "GeoDataTour.h"
18 #include "MarblePlacemarkModel.h"
19 
20 namespace Marble
21 {
22 
23 TreeViewDecoratorModel::TreeViewDecoratorModel( QObject *parent ) :
24  QSortFilterProxyModel( parent )
25 {
26  // nothing to do
27 }
28 
29 bool TreeViewDecoratorModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
30 {
31  QModelIndex rowIndex = sourceModel()->index( sourceRow, 0, sourceParent );
32 
33  GeoDataObject* object = qvariant_cast<GeoDataObject*>( rowIndex.data( MarblePlacemarkModel::ObjectPointerRole ) );
34  GeoDataObject* parent = object->parent();
35  if ( parent->nodeType() == GeoDataTypes::GeoDataFolderType ||
36  parent->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
37  GeoDataContainer *container = static_cast<GeoDataContainer *>( parent );
38  if ( container->style()->listStyle().listItemType() == GeoDataListStyle::CheckHideChildren ) {
39  return false;
40  }
41  }
42 
43  return QSortFilterProxyModel::filterAcceptsRow( sourceRow, sourceParent );
44 }
45 
46 QVariant TreeViewDecoratorModel::data( const QModelIndex &proxyIndex, int role) const
47 {
48  if ( role != Qt::DecorationRole || proxyIndex.column() != 0 ) {
49  return QSortFilterProxyModel::data(proxyIndex, role);
50  }
51 
52  GeoDataObject *object = qvariant_cast<GeoDataObject *>( QSortFilterProxyModel::data(proxyIndex, MarblePlacemarkModel::ObjectPointerRole));
53  if ( !object ) {
54  return QSortFilterProxyModel::data(proxyIndex, role);
55  }
56 
57  if ( object->nodeType() != GeoDataTypes::GeoDataFolderType ) {
58  return QSortFilterProxyModel::data(proxyIndex, role);
59  }
60 
61  GeoDataFolder *folder = static_cast<GeoDataFolder *>( object );
62 
63  bool const expandedState = m_expandedRows.contains( QPersistentModelIndex( proxyIndex ) );
64 
65  foreach (GeoDataItemIcon *icon, folder->style()->listStyle().itemIconList()) {
66  if ( ! expandedState ) {
67  if ( icon->state() == GeoDataItemIcon::Closed ) {
68  return icon->icon();
69  }
70  } else {
71  if ( icon->state() == GeoDataItemIcon::Open ) {
72  return icon->icon();
73  }
74  }
75  }
76 
77  return QSortFilterProxyModel::data(proxyIndex, role);
78 }
79 
80 void TreeViewDecoratorModel::trackExpandedState( const QModelIndex &index )
81 {
82  m_expandedRows << QPersistentModelIndex( index );
83 }
84 
85 void TreeViewDecoratorModel::trackCollapsedState( const QModelIndex &index )
86 {
87  m_expandedRows.removeAll( QPersistentModelIndex( index ));
88 }
89 
90 }
91 #include "TreeViewDecoratorModel.moc"
92 
QModelIndex
QAbstractItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
Marble::TreeViewDecoratorModel::data
QVariant data(const QModelIndex &proxyIndex, int role=Qt::DisplayRole) const
Definition: TreeViewDecoratorModel.cpp:46
GeoDataContainer.h
Marble::GeoDataItemIcon
Definition: GeoDataItemIcon.h:24
Marble::GeoDataItemIcon::icon
QImage icon() const
Definition: GeoDataItemIcon.cpp:99
Marble::GeoDataObject
A base class for all geodata objects.
Definition: GeoDataObject.h:48
Marble::GeoDataTypes::GeoDataDocumentType
const char * GeoDataDocumentType
Definition: GeoDataTypes.cpp:38
GeoDataStyle.h
Marble::GeoDataContainer
A base class that can hold GeoDataFeatures.
Definition: GeoDataContainer.h:47
Marble::GeoDataFeature::style
const GeoDataStyle * style() const
Return the style assigned to the placemark, or a default style if none has been set.
Definition: GeoDataFeature.cpp:709
Marble::TreeViewDecoratorModel::trackCollapsedState
void trackCollapsedState(const QModelIndex &index)
Definition: TreeViewDecoratorModel.cpp:85
Marble::MarblePlacemarkModel::ObjectPointerRole
The pointer to a specific object.
Definition: MarblePlacemarkModel.h:62
MarbleDebug.h
Marble::GeoDataObject::nodeType
virtual const char * nodeType() const =0
Provides type information for downcasting a GeoNode.
TreeViewDecoratorModel.h
Marble::GeoDataListStyle::itemIconList
QVector< GeoDataItemIcon * > itemIconList() const
Definition: GeoDataListStyle.cpp:110
QObject
QList::removeAll
int removeAll(const T &value)
GeoDataObject.h
Marble::GeoDataTypes::GeoDataFolderType
const char * GeoDataFolderType
Definition: GeoDataTypes.cpp:42
MarblePlacemarkModel.h
Marble::GeoDataFolder
Definition: GeoDataFolder.h:50
QSortFilterProxyModel
QList::contains
bool contains(const T &value) const
GeoDataFolder.h
QSortFilterProxyModel::filterAcceptsRow
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
QPersistentModelIndex
QAbstractProxyModel::sourceModel
QAbstractItemModel * sourceModel() const
Marble::TreeViewDecoratorModel::TreeViewDecoratorModel
TreeViewDecoratorModel(QObject *parent=0)
Definition: TreeViewDecoratorModel.cpp:23
Marble::GeoDataListStyle::CheckHideChildren
Definition: GeoDataListStyle.h:49
QModelIndex::data
QVariant data(int role) const
Marble::GeoDataListStyle::listItemType
ListItemType listItemType() const
Definition: GeoDataListStyle.cpp:90
QModelIndex::column
int column() const
Marble::TreeViewDecoratorModel::filterAcceptsRow
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
Definition: TreeViewDecoratorModel.cpp:29
Marble::GeoDataStyle::listStyle
GeoDataListStyle & listStyle()
Return the list style of this style.
Definition: GeoDataStyle.cpp:183
GeoDataTypes.h
QObject::parent
QObject * parent() const
Marble::GeoDataItemIcon::Closed
Definition: GeoDataItemIcon.h:43
Marble::GeoDataItemIcon::state
ItemIconStates state() const
Definition: GeoDataItemIcon.cpp:74
GeoDataTour.h
Marble::GeoDataItemIcon::Open
Definition: GeoDataItemIcon.h:42
QSortFilterProxyModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Marble::TreeViewDecoratorModel::trackExpandedState
void trackExpandedState(const QModelIndex &index)
Definition: TreeViewDecoratorModel.cpp:80
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 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