diff --git a/src/map-quick/osmelement.cpp b/src/map-quick/osmelement.cpp index f442e74..d39934a 100644 --- a/src/map-quick/osmelement.cpp +++ b/src/map-quick/osmelement.cpp @@ -1,44 +1,65 @@ /* Copyright (C) 2020 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "osmelement.h" using namespace KOSMIndoorMap; OSMElement::OSMElement() = default; OSMElement::OSMElement(OSM::Element e) : m_element(e) { } OSMElement::~OSMElement() = default; bool OSMElement::isNull() const { return m_element.type() == OSM::Type::Null; } QString OSMElement::name() const { // TODO read localized value return m_element.tagValue("name"); } +// TODO generalize for *:wikipedia tags +QUrl OSMElement::wikipediaUrl() const +{ + // TODO read localized value + const auto wp = m_element.tagValue("wikipedia"); + if (wp.isEmpty()) { + return {}; + } + + const auto idx = wp.indexOf(QLatin1Char(':')); + if (idx < 0) { + return {}; + } + + QUrl url; + url.setScheme(QStringLiteral("https")); + url.setHost(wp.leftRef(idx) + QLatin1String(".wikipedia.org")); + url.setPath(QLatin1String("/wiki/") + wp.midRef(idx + 1)); + return url; +} + QString OSMElement::tagValue(const QString &key) const { return m_element.tagValue(key.toUtf8().constData()); } diff --git a/src/map-quick/osmelement.h b/src/map-quick/osmelement.h index a96ba74..baf3e95 100644 --- a/src/map-quick/osmelement.h +++ b/src/map-quick/osmelement.h @@ -1,51 +1,55 @@ /* Copyright (C) 2020 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef KOSMINDOORMAP_OSMELEMENT_H #define KOSMINDOORMAP_OSMELEMENT_H #include #include +#include namespace KOSMIndoorMap { /** QML wrapper around an OSM element. */ class OSMElement { Q_GADGET Q_PROPERTY(bool isNull READ isNull) Q_PROPERTY(QString name READ name) + /** Assembled URL from the "wikipedia" tag value. */ + Q_PROPERTY(QUrl wikipediaUrl READ wikipediaUrl) public: OSMElement(); explicit OSMElement(OSM::Element e); ~OSMElement(); bool isNull() const; QString name() const; + QUrl wikipediaUrl() const; Q_INVOKABLE QString tagValue(const QString &key) const; private: OSM::Element m_element; }; } Q_DECLARE_METATYPE(KOSMIndoorMap::OSMElement) #endif // KOSMINDOORMAP_OSMELEMENT_H diff --git a/tests/indoormap.qml b/tests/indoormap.qml index 9d82654..5ebcdce 100644 --- a/tests/indoormap.qml +++ b/tests/indoormap.qml @@ -1,122 +1,146 @@ /* Copyright (C) 2020 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.12 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.1 as QQC2 import org.kde.kirigami 2.0 as Kirigami import org.kde.kosmindoormap 1.0 Kirigami.ApplicationWindow { title: "OSM Indoor Map QML Test" pageStack.initialPage: Kirigami.Page { title: "Indoor Map View" actions { left: Kirigami.Action { iconName: "go-down-symbolic" enabled: map.floorLevels.hasFloorLevelBelow(map.view.floorLevel) onTriggered: map.view.floorLevel = map.floorLevels.floorLevelBelow(map.view.floorLevel) } right: Kirigami.Action { iconName: "go-up-symbolic" enabled: map.floorLevels.hasFloorLevelAbove(map.view.floorLevel) onTriggered: map.view.floorLevel = map.floorLevels.floorLevelAbove(map.view.floorLevel) } contextualActions: [ Kirigami.Action { text: "Light Style" onTriggered: map.styleSheet = ":/org.kde.kosmindoormap/assets/css/breeze-light.mapcss" }, Kirigami.Action { text: "Dark Style" onTriggered: map.styleSheet = ":/org.kde.kosmindoormap/assets/css/breeze-dark.mapcss" }, Kirigami.Action { text: "Diagnostic View" onTriggered: map.styleSheet = ":/org.kde.kosmindoormap/assets/css/diagnostic.mapcss" } ] } header: RowLayout { QQC2.Label { text: "Floor Level:" } QQC2.ComboBox { id: floorLevelCombo model: map.floorLevels textRole: "display" Component.onCompleted: currentIndex = map.floorLevels.rowForLevel(map.view.floorLevel); onCurrentIndexChanged: if (currentIndex >= 0) { map.view.floorLevel = map.floorLevels.levelForRow(currentIndex); } } Connections { target: map.view onFloorLevelChanged: floorLevelCombo.currentIndex = map.floorLevels.rowForLevel(map.view.floorLevel); } QQC2.Label { text: "Coordinate:" } QQC2.TextField { id: coordInput placeholderText: "map coordinates" text: "49.44572, 11.08196" } QQC2.Button { text: "x" onClicked: coordInput.text = "" } QQC2.Button { text: ">" onClicked: { var c = coordInput.text.match(/(.*)[,;/ ]+(.*)/); var lat = c[1]; var lon = c[2]; map.mapLoader.loadForCoordinate(lat, lon); } } } Kirigami.OverlaySheet { id: elementDetailsSheet property var element header: Kirigami.Heading { text: elementDetailsSheet.element.name } ColumnLayout { QQC2.Label { + visible: text != "" text: elementDetailsSheet.element.tagValue("description"); } + QQC2.Label { + visible: text != "" + text: elementDetailsSheet.element.tagValue("amenity") + elementDetailsSheet.element.tagValue("shop") + elementDetailsSheet.element.tagValue("tourism") + elementDetailsSheet.element.tagValue("office") + } + QQC2.Label { + visible: text != "" + text: elementDetailsSheet.element.tagValue("opening_hours"); + } + QQC2.Label { + visible: elementDetailsSheet.element.tagValue("website") != "" + text: "" + elementDetailsSheet.element.tagValue("website") + "" + onLinkActivated: Qt.openUrlExternally(link) + } + QQC2.Label { + visible: elementDetailsSheet.element.wikipediaUrl != "" + text: "Wikipedia" + onLinkActivated: Qt.openUrlExternally(link) + } + QQC2.Label { + text: elementDetailsSheet.element.tagValue("addr:street") + " " + elementDetailsSheet.element.tagValue("addr:housenumber") + + "\n" + elementDetailsSheet.element.tagValue("addr:postcode") + " " + elementDetailsSheet.element.tagValue("addr:city") + + "\n" + elementDetailsSheet.element.tagValue("addr:country"); + } } } IndoorMap { id: map anchors.fill: parent styleSheet: ":/org.kde.kosmindoormap/assets/css/breeze-light.mapcss" Component.onCompleted: { map.mapLoader.loadForCoordinate(49.44572, 11.08196); } onElementPicked: { elementDetailsSheet.element = element; elementDetailsSheet.sheetOpen = true; } } } }