KOSMIndoorMap

floorlevelmodel.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "floorlevelmodel.h"
8
9#include <KOSMIndoorMap/MapData>
10
11using namespace KOSMIndoorMap;
12
13FloorLevelModel::FloorLevelModel(QObject *parent)
14 : QAbstractListModel(parent)
15{
16 connect(this, &QAbstractItemModel::modelReset, this, &FloorLevelModel::contentChanged);
17}
18
19FloorLevelModel::~FloorLevelModel() = default;
20
21void FloorLevelModel::setMapData(MapData *data)
22{
24 m_level.clear();
25 if (data) {
26 for (const auto &l : data->levelMap()) {
27 if (l.first.isFullLevel()) {
28 m_level.push_back(l.first);
29 }
30 }
31 }
33}
34
35int FloorLevelModel::rowCount(const QModelIndex &parent) const
36{
37 if (parent.isValid()) {
38 return 0;
39 }
40 return m_level.size();
41}
42
43QVariant FloorLevelModel::data(const QModelIndex &index, int role) const
44{
45 if (!index.isValid()) {
46 return {};
47 }
48
49 switch (role) {
50 case Qt::DisplayRole:
51 return m_level[index.row()].name();
52 case MapLevelRole:
53 return QVariant::fromValue(m_level[index.row()]);
54 }
55
56 return {};
57}
58
59int FloorLevelModel::rowForLevel(int level) const
60{
61 for (auto it = m_level.begin(); it != m_level.end(); ++it) {
62 if ((*it).numericLevel() == level) {
63 return std::distance(m_level.begin(), it);
64 }
65 }
66 return -1;
67}
68
70{
71 return m_level[row].numericLevel();
72}
73
75{
76 if (m_level.empty()) {
77 return false;
78 }
79 return m_level.back().numericLevel() != level;
80}
81
83{
84 for (auto it = m_level.begin(); it != m_level.end(); ++it) {
85 if ((*it).numericLevel() == level && std::next(it) != m_level.end()) {
86 ++it;
87 return (*it).numericLevel();
88 }
89 }
90 return 0;
91}
92
94{
95 if (m_level.empty()) {
96 return false;
97 }
98
99 return m_level.front().numericLevel() != level;
100}
101
103{
104 for (auto it = std::next(m_level.begin()); it != m_level.end(); ++it) {
105 if ((*it).numericLevel() == level) {
106 --it;
107 return (*it).numericLevel();
108 }
109 }
110 return 0;
111}
112
113bool FloorLevelModel::hasName(int level) const
114{
115 for (auto it = m_level.begin(); it != m_level.end(); ++it) {
116 if ((*it).numericLevel() == level) {
117 return (*it).hasName();
118 }
119 }
120 return false;
121}
122
124{
125 for (auto it = m_level.begin(); it != m_level.end(); ++it) {
126 if ((*it).numericLevel() == level) {
127 return (*it).name();
128 }
129 }
130 return {};
131}
132
133bool FloorLevelModel::hasFloorLevels() const
134{
135 return rowCount() > 1;
136}
137
138#include "moc_floorlevelmodel.cpp"
Q_INVOKABLE QString name(int level) const
Returns the name for the floor level.
Q_INVOKABLE bool hasFloorLevelBelow(int level) const
Returns true when we can still go further down.
Q_INVOKABLE int levelForRow(int row) const
Maps a row index to a floor level.
Q_INVOKABLE bool hasFloorLevelAbove(int level) const
Returns true when we can still go further up.
Q_INVOKABLE int floorLevelAbove(int level) const
Returns the floor level above level.
Q_INVOKABLE int rowForLevel(int level) const
Maps a floor level to a model row index.
Q_INVOKABLE int floorLevelBelow(int level) const
Returns the floor level below level.
Q_INVOKABLE bool hasName(int level) const
Returns whether the given floor level has an explicit name obtained from the OSM data.
Raw OSM map data, separated by levels.
Definition mapdata.h:60
OSM-based multi-floor indoor maps for buildings.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
bool isValid() const const
int row() const const
QObject * parent() const const
DisplayRole
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:55 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.