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 "GeoDataContainer.h"
7#include "GeoDataFolder.h"
8#include "GeoDataGeometry.h"
9#include "GeoDataItemIcon.h"
10#include "GeoDataListStyle.h"
11#include "GeoDataObject.h"
12#include "GeoDataStyle.h"
13#include "MarbleDebug.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(QStringLiteral("GeoData"));
47 } else {
48 return QSortFilterProxyModel::data(proxyIndex, role);
49 }
50 }
51
52 auto object = qvariant_cast<GeoDataObject *>(QSortFilterProxyModel::data(proxyIndex, MarblePlacemarkModel::ObjectPointerRole));
53 if (!object) {
54 return QSortFilterProxyModel::data(proxyIndex, role);
55 }
56
57 auto folder = dynamic_cast<GeoDataFolder *>(object);
58
59 if (folder) {
60 bool const expandedState = m_expandedRows.contains(QPersistentModelIndex(proxyIndex));
61
62 for (GeoDataItemIcon *icon : folder->style()->listStyle().itemIconList()) {
63 if (!expandedState) {
64 if (icon->state() == GeoDataItemIcon::Closed) {
65 return icon->icon();
66 }
67 } else {
68 if (icon->state() == GeoDataItemIcon::Open) {
69 return icon->icon();
70 }
71 }
72 }
73 }
74
75 return QSortFilterProxyModel::data(proxyIndex, role);
76}
77
78void TreeViewDecoratorModel::trackExpandedState(const QModelIndex &index)
79{
80 m_expandedRows << QPersistentModelIndex(index);
81}
82
83void TreeViewDecoratorModel::trackCollapsedState(const QModelIndex &index)
84{
85 m_expandedRows.removeAll(QPersistentModelIndex(index));
86}
87
88}
89#include "moc_TreeViewDecoratorModel.cpp"
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 Mon Nov 4 2024 16:37:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.