6#include <MarbleQuickItem.h>
11#include <QQuickWindow>
16#include "GeoDataDocument.h"
17#include "GeoDataRelation.h"
18#include "osm/OsmPlacemarkData.h"
19#include <AbstractFloatItem.h>
20#include <BookmarkManager.h>
21#include <GeoDataCoordinates.h>
22#include <GeoDataLatLonAltBox.h>
23#include <GeoDataLookAt.h>
24#include <GeoPainter.h>
25#include <MarbleAbstractPresenter.h>
26#include <MarbleInputHandler.h>
28#include <MarbleMath.h>
31#include <PluginManager.h>
32#include <PositionProviderPlugin.h>
33#include <PositionTracking.h>
34#include <RenderPlugin.h>
35#include <ReverseGeocodingRunnerManager.h>
36#include <StyleBuilder.h>
38#include <geodata/parser/GeoSceneTypes.h>
39#include <geodata/scene/GeoSceneDocument.h>
40#include <geodata/scene/GeoSceneLayer.h>
41#include <geodata/scene/GeoSceneMap.h>
42#include <geodata/scene/GeoSceneTextureTileDataset.h>
43#include <routing/Route.h>
44#include <routing/RoutingManager.h>
45#include <routing/RoutingModel.h>
50class QuickItemSelectionRubber :
public AbstractSelectionRubber
53 QuickItemSelectionRubber();
62 bool isVisible()
const override
66 const QRect &geometry()
const override
70 void setGeometry(
const QRect & )
override
80class MarbleQuickInputHandler :
public MarbleDefaultInputHandler
83 MarbleQuickInputHandler(MarbleAbstractPresenter *marblePresenter, MarbleQuickItem *marbleQuick)
84 : MarbleDefaultInputHandler(marblePresenter)
85 , m_marbleQuick(marbleQuick)
87 setInertialEarthRotationEnabled(
false);
90 bool acceptMouse()
override
97 (void)handlePinch(center, scale, state);
100 void handleMouseButtonPressAndHold(
const QPoint &position)
override
102 m_marbleQuick->reverseGeocoding(position);
106 void showLmbMenu(
int x,
int y)
override
108 m_marbleQuick->selectPlacemarkAt(x, y);
112 void showRmbMenu(
int x,
int y)
override
116 void openItemToolTip()
override
119 void setCursor(
const QCursor &cursor)
override
125 void installPluginEventFilter(RenderPlugin *)
override
132 return m_marbleQuick->layersEventFilter(o, e);
142 if (
event->touchPoints().count() > 1) {
146 if (
event->touchPoints().count() == 1) {
147 QTouchEvent::TouchPoint p =
event->touchPoints().at(0);
150 handleMouseEvent(&press);
153 handleMouseEvent(&move);
156 handleMouseEvent(&release);
162 AbstractSelectionRubber *selectionRubber()
override
164 return &m_selectionRubber;
167 MarbleQuickItem *m_marbleQuick;
168 QuickItemSelectionRubber m_selectionRubber;
172class MarbleQuickItemPrivate
175 explicit MarbleQuickItemPrivate(MarbleQuickItem *marble)
178 , m_presenter(&m_map)
179 , m_positionVisible(false)
180 , m_currentPosition(marble)
181 , m_inputHandler(&m_presenter, marble)
182 , m_placemarkDelegate(nullptr)
183 , m_placemarkItem(nullptr)
184 , m_placemark(nullptr)
185 , m_reverseGeocoding(&m_model)
186 , m_showScaleBar(false)
187 , m_enabledRelationTypes(GeoDataRelation::RouteFerry | GeoDataRelation::RouteTrain | GeoDataRelation::RouteSubway | GeoDataRelation::RouteTram
188 | GeoDataRelation::RouteBus | GeoDataRelation::RouteTrolleyBus | GeoDataRelation::RouteHiking)
189 , m_showPublicTransport(false)
190 , m_showOutdoorActivities(false)
192 , m_hoverEnabled(false)
193 , m_invertColorEnabled(false)
195 m_currentPosition.setName(
QObject::tr(
"Current Location"));
196 m_relationTypeConverter[QStringLiteral(
"road")] = GeoDataRelation::RouteRoad;
197 m_relationTypeConverter[QStringLiteral(
"detour")] = GeoDataRelation::RouteDetour;
198 m_relationTypeConverter[QStringLiteral(
"ferry")] = GeoDataRelation::RouteFerry;
199 m_relationTypeConverter[QStringLiteral(
"train")] = GeoDataRelation::RouteTrain;
200 m_relationTypeConverter[QStringLiteral(
"subway")] = GeoDataRelation::RouteSubway;
201 m_relationTypeConverter[QStringLiteral(
"tram")] = GeoDataRelation::RouteTram;
202 m_relationTypeConverter[QStringLiteral(
"bus")] = GeoDataRelation::RouteBus;
203 m_relationTypeConverter[QStringLiteral(
"trolley-bus")] = GeoDataRelation::RouteTrolleyBus;
204 m_relationTypeConverter[QStringLiteral(
"bicycle")] = GeoDataRelation::RouteBicycle;
205 m_relationTypeConverter[QStringLiteral(
"mountainbike")] = GeoDataRelation::RouteMountainbike;
206 m_relationTypeConverter[QStringLiteral(
"foot")] = GeoDataRelation::RouteFoot;
207 m_relationTypeConverter[QStringLiteral(
"hiking")] = GeoDataRelation::RouteHiking;
208 m_relationTypeConverter[QStringLiteral(
"horse")] = GeoDataRelation::RouteHorse;
209 m_relationTypeConverter[QStringLiteral(
"inline-skates")] = GeoDataRelation::RouteInlineSkates;
210 m_relationTypeConverter[QStringLiteral(
"downhill")] = GeoDataRelation::RouteSkiDownhill;
211 m_relationTypeConverter[QStringLiteral(
"ski-nordic")] = GeoDataRelation::RouteSkiNordic;
212 m_relationTypeConverter[QStringLiteral(
"skitour")] = GeoDataRelation::RouteSkitour;
213 m_relationTypeConverter[QStringLiteral(
"sled")] = GeoDataRelation::RouteSled;
216 void updateVisibleRoutes();
217 void changeBlending(
bool enabled,
const QString &blendingName);
218 void changeStyleBuilder(
bool invert);
221 friend class MarbleQuickItem;
224 Marble::MapTheme m_mapTheme;
225 MarbleAbstractPresenter m_presenter;
226 bool m_positionVisible;
227 Placemark m_currentPosition;
229 MarbleQuickInputHandler m_inputHandler;
232 Placemark *m_placemark;
233 ReverseGeocodingRunnerManager m_reverseGeocoding;
237 GeoDataRelation::RelationTypes m_enabledRelationTypes;
238 bool m_showPublicTransport;
239 bool m_showOutdoorActivities;
242 bool m_invertColorEnabled;
245MarbleQuickItem::MarbleQuickItem(
QQuickItem *parent)
247 , d(new MarbleQuickItemPrivate(this))
249 setOpaquePainting(
true);
251 qRegisterMetaType<Placemark *>(
"Placemark*");
252 d->m_map.setMapQualityForViewContext(NormalQuality, Animation);
254 for (AbstractFloatItem *item : d->m_map.floatItems()) {
256 item->setPosition(
QPointF(5.0, -10.0));
262 d->m_model.positionTracking()->setTrackVisible(
false);
263 d->m_mapTheme.setMap(
this);
266 connect(
this, &MarbleQuickItem::widthChanged,
this, &MarbleQuickItem::resizeMap);
267 connect(
this, &MarbleQuickItem::heightChanged,
this, &MarbleQuickItem::resizeMap);
268 connect(&d->m_map, &MarbleMap::visibleLatLonAltBoxChanged,
this, &MarbleQuickItem::updatePositionVisibility);
269 connect(&d->m_map, &MarbleMap::radiusChanged,
this, &MarbleQuickItem::radiusChanged);
270 connect(&d->m_map, &MarbleMap::radiusChanged,
this, &MarbleQuickItem::zoomChanged);
271 connect(&d->m_reverseGeocoding,
272 SIGNAL(reverseGeocodingFinished(GeoDataCoordinates, GeoDataPlacemark)),
274 SLOT(handleReverseGeocoding(GeoDataCoordinates, GeoDataPlacemark)));
275 connect(&d->m_map, &MarbleMap::visibleLatLonAltBoxChanged,
this, &MarbleQuickItem::handleVisibleLatLonAltBoxChanged);
276 connect(d->m_map.model(), &MarbleModel::workOfflineChanged,
this, &MarbleQuickItem::workOfflineChanged);
279 installEventFilter(&d->m_inputHandler);
282void MarbleQuickItem::resizeMap()
284 d->m_map.setSize(qMax(100,
int(width())), qMax(100,
int(height())));
286 updatePositionVisibility();
289void MarbleQuickItem::positionDataStatusChanged(PositionProviderStatus
status)
291 bool const positionAvailable =
status == PositionProviderStatusAvailable;
292 Q_EMIT positionAvailableChanged(positionAvailable);
293 updatePositionVisibility();
296void MarbleQuickItem::positionChanged(
const GeoDataCoordinates &, GeoDataAccuracy)
298 updatePositionVisibility();
301void MarbleQuickItem::updatePositionVisibility()
304 bool isVisible =
false;
305 if (positionAvailable()) {
307 bool globeHidesPoint;
308 bool const valid = d->m_map.viewport()->screenCoordinates(d->m_model.positionTracking()->currentLocation(), x, y, globeHidesPoint);
309 isVisible = valid && !globeHidesPoint;
312 if (isVisible != d->m_positionVisible) {
313 d->m_positionVisible = isVisible;
314 Q_EMIT positionVisibleChanged(isVisible);
318void MarbleQuickItem::updateCurrentPosition(
const GeoDataCoordinates &coordinates)
320 d->m_currentPosition.placemark().setCoordinate(coordinates);
321 Q_EMIT currentPositionChanged(&d->m_currentPosition);
324void MarbleQuickItem::updatePlacemarks()
326 if (!d->m_placemarkDelegate || !d->m_placemark) {
330 if (!d->m_placemarkItem) {
331 auto context =
new QQmlContext(qmlContext(d->m_placemarkDelegate));
332 QObject *component = d->m_placemarkDelegate->create(context);
333 d->m_placemarkItem = qobject_cast<QQuickItem *>(component);
334 if (d->m_placemarkItem) {
335 d->m_placemarkItem->setParentItem(
this);
345 const bool visible = d->m_map.viewport()->screenCoordinates(d->m_placemark->placemark().coordinate(), x, y);
346 d->m_placemarkItem->setVisible(visible);
348 d->m_placemarkItem->setProperty(
"xPos",
QVariant(x));
349 d->m_placemarkItem->setProperty(
"yPos",
QVariant(y));
353void MarbleQuickItem::handleReverseGeocoding(
const GeoDataCoordinates &coordinates,
const GeoDataPlacemark &placemark)
355 if (d->m_placemark && d->m_placemark->placemark().coordinate() == coordinates) {
356 d->m_placemark->setGeoDataPlacemark(placemark);
361void MarbleQuickItem::handleVisibleLatLonAltBoxChanged(
const GeoDataLatLonAltBox &latLonAltBox)
363 Q_UNUSED(latLonAltBox)
365 if (d->m_heading != d->m_map.heading()) {
366 d->m_heading = d->m_map.heading();
367 Q_EMIT headingChanged(d->m_heading);
369 Q_EMIT visibleLatLonAltBoxChanged();
370 Q_EMIT geoItemUpdateRequested();
373void MarbleQuickItem::paint(
QPainter *painter)
376 QRect rect = contentsBoundingRect().toRect();
380 GeoPainter geoPainter(paintDevice, d->m_map.viewport(), d->m_map.mapQuality());
389 geoPainter.scale(scale, scale);
393 d->m_map.paint(geoPainter, rect);
395 painter->
begin(paintDevice);
398void MarbleQuickItem::classBegin()
402void MarbleQuickItem::componentComplete()
406void Marble::MarbleQuickItem::MarbleQuickItem::hoverMoveEvent(
QHoverEvent *event)
408 if (d->m_hoverEnabled) {
409 Q_EMIT hoverPositionChanged(
event->pos());
414int MarbleQuickItem::mapWidth()
const
416 return d->m_map.width();
419int MarbleQuickItem::mapHeight()
const
421 return d->m_map.height();
424bool MarbleQuickItem::showFrameRate()
const
426 return d->m_map.showFrameRate();
429MarbleQuickItem::Projection MarbleQuickItem::projection()
const
431 return Projection(d->m_map.projection());
434QString MarbleQuickItem::mapThemeId()
const
436 return d->m_map.mapThemeId();
439Marble::MapTheme *MarbleQuickItem::mapTheme()
const
441 return &d->m_mapTheme;
444bool MarbleQuickItem::showAtmosphere()
const
446 return d->m_map.showAtmosphere();
449bool MarbleQuickItem::showCompass()
const
451 return d->m_map.showCompass();
454bool MarbleQuickItem::showClouds()
const
456 return d->m_map.showClouds();
459bool MarbleQuickItem::showCrosshairs()
const
461 return d->m_map.showCrosshairs();
464bool MarbleQuickItem::showGrid()
const
466 return d->m_map.showGrid();
469bool MarbleQuickItem::showOverviewMap()
const
471 return d->m_map.showOverviewMap();
474bool MarbleQuickItem::showOtherPlaces()
const
476 return d->m_map.showOtherPlaces();
479bool MarbleQuickItem::showScaleBar()
const
481 return d->m_showScaleBar;
484bool MarbleQuickItem::showBackground()
const
486 return d->m_map.showBackground();
489bool MarbleQuickItem::showPositionMarker()
const
492 for (
const RenderPlugin *plugin : std::as_const(plugins)) {
494 return plugin->visible();
500bool MarbleQuickItem::showPublicTransport()
const
502 return d->m_showPublicTransport;
505bool MarbleQuickItem::showOutdoorActivities()
const
507 return d->m_showOutdoorActivities;
510QString MarbleQuickItem::positionProvider()
const
512 if (d->m_model.positionTracking()->positionProviderPlugin()) {
513 return d->m_model.positionTracking()->positionProviderPlugin()->nameId();
519MarbleModel *MarbleQuickItem::model()
524const MarbleModel *MarbleQuickItem::model()
const
529MarbleMap *MarbleQuickItem::map()
534const MarbleMap *MarbleQuickItem::map()
const
539bool MarbleQuickItem::inertialGlobeRotation()
const
541 return d->m_inputHandler.inertialEarthRotationEnabled();
544bool MarbleQuickItem::animationViewContext()
const
546 return d->m_map.viewContext() ==
Animation;
549bool MarbleQuickItem::animationsEnabled()
const
551 return d->m_presenter.animationsEnabled();
556 return d->m_placemarkDelegate;
559void MarbleQuickItem::reverseGeocoding(
const QPoint &point)
562 d->m_map.viewport()->geoCoordinates(point.
x(), point.
y(), lon, lat);
563 auto const coordinates = GeoDataCoordinates(lon, lat, 0.0, GeoDataCoordinates::Degree);
564 delete d->m_placemarkItem;
565 d->m_placemarkItem =
nullptr;
566 delete d->m_placemark;
567 d->m_placemark =
new Placemark(
this);
568 d->m_placemark->placemark().setCoordinate(coordinates);
569 d->m_reverseGeocoding.reverseGeocoding(coordinates);
572bool MarbleQuickItem::hoverEnabled()
const
574 return d->m_hoverEnabled;
577void MarbleQuickItem::moveUp()
582void MarbleQuickItem::moveDown()
587void MarbleQuickItem::moveLeft()
592void MarbleQuickItem::moveRight()
597qreal MarbleQuickItem::speed()
const
599 return d->m_model.positionTracking()->speed();
602qreal MarbleQuickItem::angle()
const
604 bool routeExists = d->m_model.routingManager()->routingModel()->route().distance() != 0.0;
605 bool onRoute = !d->m_model.routingManager()->routingModel()->deviatedFromRoute();
606 if (routeExists && onRoute) {
607 GeoDataCoordinates curPoint = d->m_model.positionTracking()->positionProviderPlugin()->position();
608 return d->m_model.routingManager()->routingModel()->route().currentSegment().projectedDirection(curPoint);
610 return d->m_model.positionTracking()->direction();
614bool MarbleQuickItem::positionAvailable()
const
616 return d->m_model.positionTracking()->status() == PositionProviderStatusAvailable;
619bool MarbleQuickItem::positionVisible()
const
621 return d->m_positionVisible;
624qreal MarbleQuickItem::distanceFromPointToCurrentLocation(
const QPoint &position)
const
626 if (positionAvailable()) {
629 d->m_map.viewport()->geoCoordinates(position.
x(), position.
y(), lon1, lat1, GeoDataCoordinates::Radian);
631 GeoDataCoordinates currentCoordinates = d->m_model.positionTracking()->currentLocation();
632 qreal lon2 = currentCoordinates.longitude();
633 qreal lat2 = currentCoordinates.latitude();
635 return distanceSphere(lon1, lat1, lon2, lat2) * d->m_model.planetRadius();
640qreal MarbleQuickItem::angleFromPointToCurrentLocation(
const QPoint &position)
const
642 if (positionAvailable()) {
644 PositionTracking
const *positionTracking = d->m_model.positionTracking();
645 map()->viewport()->screenCoordinates(positionTracking->currentLocation(), x, y);
646 return atan2(y - position.
y(), x - position.
x()) * RAD2DEG;
651Placemark *MarbleQuickItem::currentPosition()
const
653 return &d->m_currentPosition;
656QPointF MarbleQuickItem::screenCoordinatesFromCoordinate(
Coordinate *coordinate)
const
659 bool globeHidesPoint;
660 bool const valid = d->m_map.viewport()->screenCoordinates(coordinate->
coordinates(), x, y, globeHidesPoint);
661 bool isVisible = valid && !globeHidesPoint;
665QPointF MarbleQuickItem::screenCoordinatesFromGeoDataCoordinates(
const GeoDataCoordinates &coordinates)
const
668 bool globeHidesPoint;
669 d->m_map.viewport()->screenCoordinates(coordinates, x, y, globeHidesPoint);
673bool MarbleQuickItem::screenCoordinatesFromGeoDataLineString(
const GeoDataLineString &lineString,
QList<QPolygonF *> &polygons)
const
675 return d->m_map.viewport()->screenCoordinates(lineString, polygons);
678bool MarbleQuickItem::screenCoordinatesToCoordinate(
const QPoint &point,
Coordinate *coordinate)
680 GeoDataCoordinates geoDataCoordinates;
681 bool success = screenCoordinatesToGeoDataCoordinates(point, geoDataCoordinates);
682 if (!qobject_cast<Coordinate *>(coordinate)) {
684 coordinate =
new Coordinate(geoDataCoordinates.longitude(), geoDataCoordinates.latitude(), 0,
nullptr);
688 coordinate->
setLongitude(geoDataCoordinates.longitude());
689 coordinate->
setLatitude(geoDataCoordinates.latitude());
695bool MarbleQuickItem::screenCoordinatesToGeoDataCoordinates(
const QPoint &point, GeoDataCoordinates &coordinates)
697 qreal lon = 0.0, lat = 0.0;
698 bool const valid = d->m_map.viewport()->geoCoordinates(point.
x(), point.
y(), lon, lat);
699 coordinates.setLongitude(lon);
700 coordinates.setLatitude(lat);
704void MarbleQuickItem::setRadius(
int radius)
706 d->m_map.setRadius(radius);
709void MarbleQuickItem::setHeading(qreal heading)
711 if (qFuzzyCompare(d->m_heading, heading))
714 d->m_map.setHeading(heading);
715 d->m_heading = heading;
717 Q_EMIT headingChanged(d->m_heading);
720void MarbleQuickItem::setHoverEnabled(
bool hoverEnabled)
722 if (d->m_hoverEnabled == hoverEnabled)
725 d->m_hoverEnabled = hoverEnabled;
727 setAcceptHoverEvents(hoverEnabled);
728 setFlag(ItemAcceptsInputMethod, hoverEnabled);
730 Q_EMIT hoverEnabledChanged(d->m_hoverEnabled);
733qreal MarbleQuickItem::centerLongitude()
const
735 return d->m_presenter.centerLongitude();
738qreal MarbleQuickItem::centerLatitude()
const
740 return d->m_presenter.centerLatitude();
743void MarbleQuickItem::setZoom(
int newZoom, FlyToMode mode)
745 d->m_presenter.setZoom(newZoom, mode);
748void MarbleQuickItem::setZoomToMaximumLevel()
750 d->m_presenter.setZoom(d->m_map.maximumZoom());
753void MarbleQuickItem::centerOn(
const GeoDataPlacemark &placemark,
bool animated)
755 d->m_presenter.centerOn(placemark, animated);
758void MarbleQuickItem::centerOn(
const GeoDataLatLonBox &box,
bool animated)
760 d->m_presenter.centerOn(box, animated);
763void MarbleQuickItem::centerOn(
const GeoDataCoordinates &coordinate)
765 GeoDataLookAt target = d->m_presenter.lookAt();
766 target.setCoordinates(coordinate);
767 d->m_presenter.flyTo(target, Automatic);
770void MarbleQuickItem::centerOn(qreal longitude, qreal latitude)
772 d->m_presenter.centerOn(longitude, latitude);
775void MarbleQuickItem::centerOnCoordinates(qreal longitude, qreal latitude)
777 centerOn(longitude, latitude);
780void MarbleQuickItem::centerOnCurrentPosition()
782 GeoDataCoordinates coordinates = d->m_model.positionTracking()->currentLocation();
783 if (coordinates == GeoDataCoordinates()) {
787 d->m_presenter.centerOn(coordinates,
true);
788 if (d->m_presenter.zoom() < 3000) {
789 d->m_presenter.setZoom(3500);
793void MarbleQuickItem::selectPlacemarkAt(
int x,
int y)
797 for (
auto feature : std::as_const(features)) {
798 if (
const auto placemark = geodata_cast<GeoDataPlacemark>(feature)) {
799 placemarks << placemark;
803 for (
auto placemark : std::as_const(placemarks)) {
804 if (d->m_placemark && placemark->coordinate() == d->m_placemark->placemark().coordinate()) {
805 d->m_placemark->deleteLater();
806 d->m_placemark =
nullptr;
808 if (d->m_placemark) {
809 d->m_placemark->deleteLater();
811 d->m_placemark =
new Placemark(
this);
812 d->m_placemark->setGeoDataPlacemark(*placemark);
814 delete d->m_placemarkItem;
815 d->m_placemarkItem =
nullptr;
820 if (d->m_placemark) {
821 d->m_placemark->deleteLater();
822 d->m_placemark =
nullptr;
823 delete d->m_placemarkItem;
824 d->m_placemarkItem =
nullptr;
829void MarbleQuickItem::goHome()
831 d->m_presenter.goHome();
834void MarbleQuickItem::zoomIn(FlyToMode mode)
836 d->m_presenter.zoomIn(mode);
839void MarbleQuickItem::zoomOut(FlyToMode mode)
841 d->m_presenter.zoomOut(mode);
844void MarbleQuickItem::handlePinchStarted(
const QPointF &point)
849void MarbleQuickItem::handlePinchFinished(
const QPointF &point)
854void MarbleQuickItem::handlePinchUpdated(
const QPointF &point, qreal scale)
856 scale = sqrt(sqrt(scale));
857 scale = qBound(
static_cast<qreal
>(0.5), scale,
static_cast<qreal
>(2.0));
861void MarbleQuickItem::setMapWidth(
int mapWidth)
863 if (d->m_map.width() == mapWidth) {
867 d->m_map.setSize(mapWidth, mapHeight());
868 Q_EMIT mapWidthChanged(mapWidth);
871void MarbleQuickItem::setMapHeight(
int mapHeight)
873 if (this->mapHeight() == mapHeight) {
877 d->m_map.setSize(mapWidth(), mapHeight);
878 Q_EMIT mapHeightChanged(mapHeight);
881void MarbleQuickItem::setShowFrameRate(
bool showFrameRate)
883 if (this->showFrameRate() == showFrameRate) {
887 d->m_map.setShowFrameRate(showFrameRate);
888 Q_EMIT showFrameRateChanged(showFrameRate);
891void MarbleQuickItem::setProjection(Projection projection)
893 if (this->projection() == projection) {
898 Q_EMIT projectionChanged(projection);
901void MarbleQuickItem::setMapThemeId(
const QString &mapThemeId)
903 if (this->mapThemeId() == mapThemeId) {
907 bool invertColor = invertColorEnabled();
909 bool const showCompass = d->m_map.showCompass();
910 bool const showOverviewMap = d->m_map.showOverviewMap();
911 bool const showOtherPlaces = d->m_map.showOtherPlaces();
912 bool const showGrid = d->m_map.showGrid();
914 d->m_map.setMapThemeId(mapThemeId);
917 d->m_map.setShowCompass(showCompass);
918 d->m_map.setShowOverviewMap(showOverviewMap);
919 d->m_map.setShowOtherPlaces(showOtherPlaces);
920 d->m_map.setShowGrid(showGrid);
921 d->m_map.setShowScaleBar(d->m_showScaleBar);
923 Q_EMIT mapThemeIdChanged(mapThemeId);
925 setInvertColorEnabled(invertColor);
928void MarbleQuickItem::setShowAtmosphere(
bool showAtmosphere)
930 if (this->showAtmosphere() == showAtmosphere) {
934 d->m_map.setShowAtmosphere(showAtmosphere);
935 Q_EMIT showAtmosphereChanged(showAtmosphere);
938void MarbleQuickItem::setShowCompass(
bool showCompass)
940 if (this->showCompass() == showCompass) {
944 d->m_map.setShowCompass(showCompass);
945 Q_EMIT showCompassChanged(showCompass);
948void MarbleQuickItem::setShowClouds(
bool showClouds)
950 if (this->showClouds() == showClouds) {
954 d->m_map.setShowClouds(showClouds);
955 Q_EMIT showCloudsChanged(showClouds);
958void MarbleQuickItem::setShowCrosshairs(
bool showCrosshairs)
960 if (this->showCrosshairs() == showCrosshairs) {
964 d->m_map.setShowCrosshairs(showCrosshairs);
965 Q_EMIT showCrosshairsChanged(showCrosshairs);
968void MarbleQuickItem::setShowGrid(
bool showGrid)
970 if (this->showGrid() == showGrid) {
974 d->m_map.setShowGrid(showGrid);
975 Q_EMIT showGridChanged(showGrid);
978void MarbleQuickItem::setShowOverviewMap(
bool showOverviewMap)
980 if (this->showOverviewMap() == showOverviewMap) {
984 d->m_map.setShowOverviewMap(showOverviewMap);
985 Q_EMIT showOverviewMapChanged(showOverviewMap);
988void MarbleQuickItem::setShowOtherPlaces(
bool showOtherPlaces)
990 if (this->showOtherPlaces() == showOtherPlaces) {
994 d->m_map.setShowOtherPlaces(showOtherPlaces);
995 Q_EMIT showOtherPlacesChanged(showOtherPlaces);
998void MarbleQuickItem::setShowScaleBar(
bool showScaleBar)
1000 if (d->m_showScaleBar == showScaleBar) {
1004 d->m_showScaleBar = showScaleBar;
1005 d->m_map.setShowScaleBar(d->m_showScaleBar);
1006 Q_EMIT showScaleBarChanged(showScaleBar);
1009void MarbleQuickItem::setShowBackground(
bool showBackground)
1011 if (this->showBackground() == showBackground) {
1015 d->m_map.setShowBackground(showBackground);
1016 Q_EMIT showBackgroundChanged(showBackground);
1019void MarbleQuickItem::setShowPositionMarker(
bool showPositionMarker)
1021 if (this->showPositionMarker() == showPositionMarker) {
1026 for (RenderPlugin *plugin : std::as_const(plugins)) {
1028 plugin->setVisible(showPositionMarker);
1033 Q_EMIT showPositionMarkerChanged(showPositionMarker);
1036void MarbleQuickItem::setShowPublicTransport(
bool enabled)
1038 if (d->m_showPublicTransport != enabled) {
1039 d->m_showPublicTransport = enabled;
1040 d->updateVisibleRoutes();
1041 Q_EMIT showPublicTransportChanged(enabled);
1045void MarbleQuickItem::setShowOutdoorActivities(
bool showOutdoorActivities)
1047 if (d->m_showOutdoorActivities != showOutdoorActivities) {
1048 d->m_showOutdoorActivities = showOutdoorActivities;
1049 d->updateVisibleRoutes();
1050 Q_EMIT showOutdoorActivitiesChanged(showOutdoorActivities);
1054void MarbleQuickItem::setPositionProvider(
const QString &positionProvider)
1057 if (d->m_model.positionTracking()->positionProviderPlugin()) {
1058 name = d->m_model.positionTracking()->positionProviderPlugin()->nameId();
1059 if (name == positionProvider) {
1064 if (positionProvider.
isEmpty()) {
1065 d->m_model.positionTracking()->setPositionProviderPlugin(
nullptr);
1070 for (
const PositionProviderPlugin *plugin : std::as_const(plugins)) {
1071 if (plugin->nameId() == positionProvider) {
1072 PositionProviderPlugin *newPlugin = plugin->newInstance();
1073 d->m_model.positionTracking()->setPositionProviderPlugin(newPlugin);
1074 connect(newPlugin, SIGNAL(statusChanged(PositionProviderStatus)),
this, SLOT(positionDataStatusChanged(PositionProviderStatus)));
1075 connect(newPlugin, SIGNAL(positionChanged(GeoDataCoordinates, GeoDataAccuracy)),
this, SLOT(updateCurrentPosition(GeoDataCoordinates)));
1076 connect(newPlugin, SIGNAL(positionChanged(GeoDataCoordinates, GeoDataAccuracy)),
this, SIGNAL(speedChanged()));
1077 connect(newPlugin, SIGNAL(positionChanged(GeoDataCoordinates, GeoDataAccuracy)),
this, SIGNAL(angleChanged()));
1078 Q_EMIT positionProviderChanged(positionProvider);
1084void MarbleQuickItem::setInertialGlobeRotation(
bool inertialGlobeRotation)
1086 if (inertialGlobeRotation == d->m_inputHandler.inertialEarthRotationEnabled()) {
1090 d->m_inputHandler.setInertialEarthRotationEnabled(inertialGlobeRotation);
1091 Q_EMIT inertialGlobeRotationChanged(inertialGlobeRotation);
1094void MarbleQuickItem::setAnimationViewContext(
bool animationViewContext)
1096 d->m_map.setViewContext(animationViewContext ? Animation : Still);
1098 Q_EMIT inertialGlobeRotationChanged(animationViewContext);
1101void MarbleQuickItem::setAnimationsEnabled(
bool animationsEnabled)
1103 if (d->m_presenter.animationsEnabled() == animationsEnabled)
1106 d->m_presenter.setAnimationsEnabled(animationsEnabled);
1107 Q_EMIT animationsEnabledChanged(d->m_presenter.animationsEnabled());
1110void MarbleQuickItem::setPluginSetting(
const QString &pluginId,
const QString &key,
const QString &value)
1112 for (RenderPlugin *plugin : d->m_map.renderPlugins()) {
1113 if (plugin->nameId() == pluginId) {
1114 plugin->setSetting(key, value);
1119void MarbleQuickItem::setPropertyEnabled(
const QString &property,
bool enabled)
1121 d->m_map.setPropertyValue(property, enabled);
1124bool MarbleQuickItem::isPropertyEnabled(
const QString &property)
const
1126 return d->m_map.propertyValue(property);
1129void MarbleQuickItem::setWorkOffline(
bool enabled)
1131 if (d->m_map.model()->workOffline() == enabled)
1135 d->m_map.model()->setWorkOffline(enabled);
1139void MarbleQuickItem::setInvertColorEnabled(
bool enabled,
const QString &blendingName)
1141 d->changeBlending(enabled, blendingName);
1143 d->changeStyleBuilder(enabled);
1145 if (d->m_invertColorEnabled == enabled)
1148 d->m_invertColorEnabled = enabled;
1150 Q_EMIT invertColorEnabledChanged(d->m_invertColorEnabled);
1153bool MarbleQuickItem::invertColorEnabled()
1155 return d->m_invertColorEnabled;
1158bool MarbleQuickItem::workOffline()
1160 return d->m_map.model()->workOffline();
1163void MarbleQuickItem::setShowRuntimeTrace(
bool showRuntimeTrace)
1165 d->m_map.setShowRuntimeTrace(showRuntimeTrace);
1169void MarbleQuickItem::setShowDebugPolygons(
bool showDebugPolygons)
1171 d->m_map.setShowDebugPolygons(showDebugPolygons);
1175void MarbleQuickItem::setShowDebugPlacemarks(
bool showDebugPlacemarks)
1177 d->m_map.setShowDebugPlacemarks(showDebugPlacemarks);
1181void MarbleQuickItem::setShowDebugBatches(
bool showDebugBatches)
1183 d->m_map.setShowDebugBatchRender(showDebugBatches);
1187void MarbleQuickItem::setPlacemarkDelegate(
QQmlComponent *placemarkDelegate)
1189 if (d->m_placemarkDelegate == placemarkDelegate) {
1193 delete d->m_placemarkItem;
1194 d->m_placemarkItem =
nullptr;
1195 d->m_placemarkDelegate = placemarkDelegate;
1196 Q_EMIT placemarkDelegateChanged(placemarkDelegate);
1199void MarbleQuickItem::loadSettings()
1202 settings.
beginGroup(QStringLiteral(
"MarbleQuickItem"));
1205 if (lat == 0.0 && lon == 0.0) {
1206 centerOnCurrentPosition();
1214 auto const defaultRelationTypes =
QStringList() << QStringLiteral(
"ferry") << QStringLiteral(
"train") << QStringLiteral(
"subway") << QStringLiteral(
"tram")
1215 << QStringLiteral(
"bus") << QStringLiteral(
"trolley-bus") << QStringLiteral(
"hiking");
1216 auto const visibleRelationTypes = settings.
value(QStringLiteral(
"visibleRelationTypes"), defaultRelationTypes).
toStringList();
1217 d->m_enabledRelationTypes = GeoDataRelation::UnknownType;
1218 for (
auto const &route : visibleRelationTypes) {
1219 d->m_enabledRelationTypes |= d->m_relationTypeConverter.value(route, GeoDataRelation::UnknownType);
1221 setShowPublicTransport(settings.
value(QStringLiteral(
"showPublicTransport"),
false).toBool());
1222 setShowOutdoorActivities(settings.
value(QStringLiteral(
"showOutdoorActivities"),
false).toBool());
1224 d->m_model.routingManager()->readSettings();
1225 d->m_model.bookmarkManager()->loadFile(QStringLiteral(
"bookmarks/bookmarks.kml"));
1226 d->m_model.bookmarkManager()->setShowBookmarks(
true);
1227 d->updateVisibleRoutes();
1230void MarbleQuickItem::writeSettings()
1233 settings.
beginGroup(QStringLiteral(
"MarbleQuickItem"));
1234 settings.
setValue(QStringLiteral(
"centerLon"),
QVariant(d->m_map.centerLongitude()));
1235 settings.
setValue(QStringLiteral(
"centerLat"),
QVariant(d->m_map.centerLatitude()));
1239 for (
auto iter = d->m_relationTypeConverter.cbegin(), end = d->m_relationTypeConverter.cend(); iter != end; ++iter) {
1240 relationConverter[iter.value()] = iter.
key();
1242 for (
auto iter = relationConverter.
cbegin(), end = relationConverter.
cend(); iter != end; ++iter) {
1243 if (d->m_enabledRelationTypes & iter.key()) {
1244 enabledRoutes << iter.
value();
1247 settings.
setValue(QStringLiteral(
"visibleRelationTypes"), enabledRoutes);
1248 settings.
setValue(QStringLiteral(
"showPublicTransport"), d->m_showPublicTransport);
1249 settings.
setValue(QStringLiteral(
"showOutdoorActivities"), d->m_showOutdoorActivities);
1252 d->m_model.routingManager()->writeSettings();
1255void MarbleQuickItem::reloadTiles()
1260void MarbleQuickItem::highlightRouteRelation(qint64 osmId,
bool enabled)
1262 d->m_map.highlightRouteRelation(osmId, enabled);
1265void MarbleQuickItem::setRelationTypeVisible(
const QString &relationType,
bool visible)
1267 auto const relation = d->m_relationTypeConverter.value(relationType, GeoDataRelation::UnknownType);
1269 d->m_enabledRelationTypes |= relation;
1271 d->m_enabledRelationTypes &= ~relation;
1273 d->updateVisibleRoutes();
1276bool MarbleQuickItem::isRelationTypeVisible(
const QString &relationType)
const
1278 auto const relation = d->m_relationTypeConverter.value(relationType, GeoDataRelation::UnknownType);
1279 return d->m_enabledRelationTypes & relation;
1282QObject *MarbleQuickItem::getEventFilter()
const
1284 return &d->m_inputHandler;
1289 d->m_inputHandler.pinch(center, scale, state);
1292MarbleInputHandler *MarbleQuickItem::inputHandler()
1294 return &d->m_inputHandler;
1297int MarbleQuickItem::radius()
const
1299 return d->m_map.radius();
1302qreal MarbleQuickItem::heading()
const
1304 return d->m_map.heading();
1307int MarbleQuickItem::zoom()
const
1309 return d->m_presenter.logzoom();
1312int MarbleQuickItem::minimumZoom()
const
1314 return d->m_presenter.minimumZoom();
1317int MarbleQuickItem::maximumZoom()
const
1319 return d->m_presenter.maximumZoom();
1327QuickItemSelectionRubber::QuickItemSelectionRubber()
1333void MarbleQuickItemPrivate::updateVisibleRoutes()
1335 GeoDataRelation::RelationTypes relationTypes = m_enabledRelationTypes;
1336 if (!m_showPublicTransport) {
1337 relationTypes &= ~GeoDataRelation::RouteTrain;
1338 relationTypes &= ~GeoDataRelation::RouteSubway;
1339 relationTypes &= ~GeoDataRelation::RouteTram;
1340 relationTypes &= ~GeoDataRelation::RouteBus;
1341 relationTypes &= ~GeoDataRelation::RouteTrolleyBus;
1343 if (!m_showOutdoorActivities) {
1344 relationTypes &= ~GeoDataRelation::RouteBicycle;
1345 relationTypes &= ~GeoDataRelation::RouteMountainbike;
1346 relationTypes &= ~GeoDataRelation::RouteFoot;
1347 relationTypes &= ~GeoDataRelation::RouteHiking;
1348 relationTypes &= ~GeoDataRelation::RouteHorse;
1349 relationTypes &= ~GeoDataRelation::RouteInlineSkates;
1350 relationTypes &= ~GeoDataRelation::RouteSkiDownhill;
1351 relationTypes &= ~GeoDataRelation::RouteSkiNordic;
1352 relationTypes &= ~GeoDataRelation::RouteSkitour;
1353 relationTypes &= ~GeoDataRelation::RouteSled;
1355 m_map.setVisibleRelationTypes(relationTypes);
1358void MarbleQuickItemPrivate::changeBlending(
bool enabled,
const QString &blendingName)
1360 GeoSceneDocument *mapTheme = m_map.model()->mapTheme();
1361 if (mapTheme ==
nullptr)
1364 GeoSceneMap *
map = mapTheme->map();
1368 GeoSceneTextureTileDataset *textureDataset =
nullptr;
1369 if (
map->hasTextureLayers()) {
1370 for (
auto layer :
map->layers()) {
1371 for (
auto dataset : layer->datasets()) {
1372 if (dataset->nodeType() == GeoSceneTypes::GeoSceneTextureTileType) {
1373 textureDataset =
dynamic_cast<GeoSceneTextureTileDataset *
>(dataset);
1378 if (textureDataset ==
nullptr)
1380 if (enabled && textureDataset->blending().isEmpty()) {
1381 textureDataset->setBlending(blendingName);
1382 m_map.clearVolatileTileCache();
1383 }
else if (!enabled && textureDataset->blending() == blendingName) {
1384 textureDataset->setBlending({});
1385 m_map.clearVolatileTileCache();
1390void MarbleQuickItemPrivate::changeStyleBuilder(
bool invert)
1392 GeoSceneDocument *mapTheme = m_map.model()->mapTheme();
1393 if (mapTheme ==
nullptr)
1396 GeoSceneMap *
map = mapTheme->map();
1400 if (
map->hasVectorLayers()) {
1401 auto styleBuilder =
const_cast<StyleBuilder *
>(m_map.styleBuilder());
1404 styleBuilder->setStyleEffect(InvertedEffect);
1406 styleBuilder->setStyleEffect(NoEffect);
1408 styleBuilder->reset();
1410 Q_EMIT m_map.model()->themeChanged(
QString());
1415#include "moc_MarbleQuickItem.cpp"
This file contains the headers for MarbleMap.
This file contains the headers for MarbleModel.
This file contains the headers for ViewportParams.
Represents a coordinate with the properties of a name and coordinates.
void setLatitude(qreal lat)
Change the latitude of the coordinate.
void setLongitude(qreal lon)
Change the longitude of the coordinate.
Marble::GeoDataCoordinates coordinates() const
Change the altitude of the coordinate.
Q_SCRIPTABLE CaptureState status()
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
void update(Part *part, const QByteArray &data, qint64 dataSize)
QString name(GameStandardAction id)
KIOCORE_EXPORT CopyJob * move(const QList< QUrl > &src, const QUrl &dest, JobFlags flags=DefaultFlags)
std::vector< Feature > features(QStringView coachNumber, QStringView coachClassification)
QAction * zoom(const QObject *recvr, const char *slot, QObject *parent)
Binds a QML item to a specific geodetic location in screen coordinates.
@ Linear
Linear interpolation of lon, lat and distance to ground.
@ Animation
animated view (e.g. while rotating the globe)
Projection
This enum is used to choose the projection shown in the view.
qreal distanceSphere(qreal lon1, qreal lat1, qreal lon2, qreal lat2)
This method calculates the shortest distance between two points on a sphere.
void setObjectOwnership(QObject *object, ObjectOwnership ownership)
T value(qsizetype i) const const
const_iterator cbegin() const const
const_iterator cend() const const
Key key(const T &value, const Key &defaultKey) const const
virtual bool event(QEvent *e)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool begin(QPaintDevice *device)
QPaintDevice * device() const const
virtual void hoverMoveEvent(QHoverEvent *event)
void setCursor(const QCursor &cursor)
void beginGroup(QAnyStringView prefix)
void setValue(QAnyStringView key, const QVariant &value)
QVariant value(QAnyStringView key) const const
bool isEmpty() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QVariant fromValue(T &&value)
double toDouble(bool *ok) const const
int toInt(bool *ok) const const
QStringList toStringList() const const