Marble

BranchFilterProxyModel.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
4// SPDX-FileCopyrightText: 2012 Thibaut Gridel <tgridel@free.fr>
5
6#include "BranchFilterProxyModel.h"
7
8#include "GeoDataContainer.h"
9#include "GeoDataTreeModel.h"
10#include "MarblePlacemarkModel.h"
11
12namespace Marble
13{
14
15BranchFilterProxyModel::BranchFilterProxyModel(QObject *parent)
16 : QSortFilterProxyModel(parent)
17 , m_treeModel(nullptr)
18{
19 // nothing to do
20}
21
22/// sets the folder index for which we want to see bookmarks
23void BranchFilterProxyModel::setBranchIndex(GeoDataTreeModel *treeModel, const QModelIndex &index)
24{
25 Q_ASSERT(index.isValid());
26 Q_ASSERT(index.model() == treeModel);
27 m_treeModel = treeModel;
28 m_branchIndex = index;
29 invalidateFilter();
30}
31
32/// determines if such row should be filtered.
33/// Beware, all parents of our folder must be accepted as well
34bool BranchFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
35{
36 if (!m_treeModel || !m_branchIndex.isValid()) {
37 return true;
38 }
39
40 Q_ASSERT(m_treeModel == sourceModel());
41 if (sourceParent.isValid()) {
42 Q_ASSERT(sourceParent.model() == m_treeModel);
43 }
44 QModelIndex rowIndex = sourceModel()->index(sourceRow, 0, sourceParent);
45 Q_ASSERT(rowIndex.isValid());
46
47 // return true for all non folder children of m_branchIndex
48 if (sourceParent == m_branchIndex) {
49 auto obj = qvariant_cast<GeoDataObject *>(rowIndex.data(MarblePlacemarkModel::ObjectPointerRole));
50 return !dynamic_cast<const GeoDataContainer *>(obj);
51 }
52
53 // return true if rowIndex is a parent of m_branchIndex
54 QModelIndex tmpIndex = m_branchIndex;
55 while (tmpIndex.isValid() && tmpIndex != rowIndex) {
56 tmpIndex = tmpIndex.parent();
57 }
58 return tmpIndex == rowIndex;
59}
60
61}
Binds a QML item to a specific geodetic location in screen coordinates.
QVariant data(int role) const const
bool isValid() const const
const QAbstractItemModel * model() const const
QModelIndex parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.