KOSMIndoorMap

floorlevelmodel.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "floorlevelmodel.h"
8 
9 #include <KOSMIndoorMap/MapData>
10 
11 using namespace KOSMIndoorMap;
12 
13 FloorLevelModel::FloorLevelModel(QObject *parent)
14  : QAbstractListModel(parent)
15 {
16  connect(this, &QAbstractItemModel::modelReset, this, &FloorLevelModel::contentChanged);
17 }
18 
19 FloorLevelModel::~FloorLevelModel() = default;
20 
21 void 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  }
32  endResetModel();
33 }
34 
35 int FloorLevelModel::rowCount(const QModelIndex &parent) const
36 {
37  if (parent.isValid()) {
38  return 0;
39  }
40  return m_level.size();
41 }
42 
43 QVariant 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 
59 int 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 
69 int FloorLevelModel::levelForRow(int row) const
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 
113 bool 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 
134 {
135  return rowCount() > 1;
136 }
OSM-based multi-floor indoor maps for buildings.
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 QString name(int level) const
Returns the name for the floor level.
bool isValid() const const
Q_INVOKABLE int levelForRow(int row) const
Maps a row index to a floor level.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
DisplayRole
Raw OSM map data, separated by levels.
Definition: mapdata.h:59
int row() const const
QVariant fromValue(const T &value)
Q_INVOKABLE bool hasFloorLevelBelow(int level) const
Returns true when we can still go further down.
bool hasFloorLevels() const
We have more than the base/outdoor floor levels.
Q_INVOKABLE bool hasFloorLevelAbove(int level) const
Returns true when we can still go further up.
Q_INVOKABLE bool hasName(int level) const
Returns whether the given floor level has an explicit name obtained from the OSM data.
Q_INVOKABLE int floorLevelAbove(int level) const
Returns the floor level above level.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:04:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.