15GateModel::GateModel(
QObject *parent)
20GateModel::~GateModel() =
default;
22MapData GateModel::mapData()
const
27void GateModel::setMapData(
const MapData &data)
36 if (!m_data.isEmpty()) {
37 m_tagKeys.mxArrival = m_data.dataSet().
makeTagKey(
"mx:arrival");
38 m_tagKeys.mxDeparture = m_data.dataSet().
makeTagKey(
"mx:departure");
46bool GateModel::isEmpty()
const
48 return rowCount() == 0;
51int GateModel::rowCount(
const QModelIndex &parent)
const
57 return m_gates.size();
66 const auto &gate = m_gates[
index.
row()];
71 return QPointF(gate.node.coordinate.lonF(), gate.node.coordinate.latF());
77 return index.
row() == m_arrivalGateRow;
78 case DepartureGateRole:
79 return index.
row() == m_departureGateRow;
80 case HiddenElementRole:
90 n.insert(CoordinateRole,
"coordinate");
91 n.insert(ElementRole,
"osmElement");
92 n.insert(LevelRole,
"level");
93 n.insert(ArrivalGateRole,
"isArrivalGate");
94 n.insert(DepartureGateRole,
"isDepartureGate");
95 n.insert(HiddenElementRole,
"hiddenElement");
99void GateModel::populateModel()
101 const auto aerowayKey = m_data.dataSet().
tagKey(
"aeroway");
102 if (aerowayKey.isNull()) {
106 for (
auto it = m_data.levelMap().begin(); it != m_data.levelMap().end(); ++it) {
107 for (
const auto &e : (*it).second) {
108 if (e.type() != OSM::Type::Node || e.tagValue(aerowayKey) !=
"gate") {
112 const auto l = e.tagValue(
"ref").split(
';');
113 for (
const auto &n : l) {
120 gate.sourceElement = e;
121 gate.node = *e.node();
124 gate.level = (*it).first.numericLevel();
125 m_gates.push_back(gate);
132 c.setIgnorePunctuation(
true);
134 std::sort(m_gates.begin(), m_gates.end(), [&c](
const auto &lhs,
const auto &rhs) {
135 return c.compare(lhs.name, rhs.name) < 0;
138 qDebug() << m_gates.size() <<
"gates found";
143 m_arrivalGate = name;
147void GateModel::setDepartureGate(
const QString &name)
149 m_departureGate = name;
155 return m_arrivalGateRow;
158int GateModel::departureGateRow()
const
160 return m_departureGateRow;
163void GateModel::matchGates()
165 setGateTag(m_arrivalGateRow, m_tagKeys.mxArrival,
false);
166 m_arrivalGateRow = matchGate(m_arrivalGate);
167 setGateTag(m_arrivalGateRow, m_tagKeys.mxArrival,
true);
169 setGateTag(m_departureGateRow, m_tagKeys.mxDeparture,
false);
170 m_departureGateRow = matchGate(m_departureGate);
171 setGateTag(m_departureGateRow, m_tagKeys.mxDeparture,
true);
173 Q_EMIT gateIndexChanged();
174 if (m_arrivalGateRow >= 0) {
177 if (m_departureGateRow >= 0) {
182int GateModel::matchGate(
const QString &name)
const
184 if (name.isEmpty()) {
189 for (
const auto &g : m_gates) {
190 if (g.name == name) {
199void GateModel::setGateTag(
int idx,
OSM::TagKey key,
bool enabled)
208#include "moc_gatemodel.cpp"
Q_INVOKABLE void setArrivalGate(const QString &name)
Match arrival/departure gates against what we found in the map data.
int arrivalGateRow
Row indexes of the matched arrival/departure gates, if found and/or set, otherwise -1.
Raw OSM map data, separated by levels.
TagKey tagKey(const char *keyName) const
Look up a tag key for the given tag name, if it exists.
Id nextInternalId() const
Create a unique id for internal use (ie.
TagKey makeTagKey(const char *keyName, StringMemory keyMemOpt=StringMemory::Transient)
Create a tag key for the given tag name.
A reference to any of OSM::Node/OSM::Way/OSM::Relation.
OSM-based multi-floor indoor maps for buildings.
void setTagValue(Elem &elem, TagKey key, QByteArray &&value)
Inserts a new tag, or updates an existing one.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
virtual QHash< int, QByteArray > roleNames() const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
void setNumericMode(bool on)
bool isValid() const const
QObject * parent() const const
QString fromUtf8(QByteArrayView str)
QByteArray toUtf8() const const
QVariant fromValue(T &&value)