diff --git a/src/lib/marble/graphicsview/GeoGraphicsItem.cpp b/src/lib/marble/graphicsview/GeoGraphicsItem.cpp index 9c87cc287..a70130b92 100644 --- a/src/lib/marble/graphicsview/GeoGraphicsItem.cpp +++ b/src/lib/marble/graphicsview/GeoGraphicsItem.cpp @@ -1,216 +1,225 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2009 Bastian Holst // // Self #include "GeoGraphicsItem.h" #include "GeoGraphicsItem_p.h" #include "GeoDataTypes.h" #include "GeoDataPlacemark.h" // Qt #include "MarbleDebug.h" #include using namespace Marble; GeoGraphicsItem::GeoGraphicsItem( const GeoDataFeature *feature ) : d( new GeoGraphicsItemPrivate( feature ) ) { setFlag( ItemIsVisible, true ); } GeoGraphicsItem::~GeoGraphicsItem() { delete d; } bool GeoGraphicsItem::visible() const { return d->m_flags & ItemIsVisible; } void GeoGraphicsItem::setVisible( bool visible ) { setFlag( ItemIsVisible, visible ); } GeoGraphicsItem::GeoGraphicsItemFlags GeoGraphicsItem::flags() const { return d->m_flags; } void GeoGraphicsItem::setFlag( GeoGraphicsItemFlag flag, bool enabled ) { if( enabled ) { d->m_flags = d->m_flags | flag; } else { d->m_flags = d->m_flags & ~flag; } } void GeoGraphicsItem::setFlags( GeoGraphicsItemFlags flags ) { d->m_flags = flags; } const GeoDataFeature* GeoGraphicsItem::feature() const { return d->m_feature; } void GeoGraphicsItem::setHighlightStyle( const GeoDataStyle::ConstPtr &highlightStyle) { /** * Delete any previously set style * and assign the new style @highlightStyle */ d->m_highlightStyle = highlightStyle; } GeoDataStyle::ConstPtr GeoGraphicsItem::style() const { /** * m_isHighlight is set true when the item is * supposed to be colored highlighted */ if ( d->m_highlighted && d->m_highlightStyle ) { return d->m_highlightStyle; } if (!d->m_style) { if (d->m_feature->nodeType() == GeoDataTypes::GeoDataPlacemarkType) { const GeoDataPlacemark *placemark = static_cast(d->m_feature); auto styling = StyleParameters(placemark, d->m_renderContext.tileLevel()); - for (auto relation: d->m_relations) { + QVector relations; + std::copy_if(d->m_relations.begin(), d->m_relations.end(), std::back_inserter(relations), + [](const GeoDataRelation * relation) { + return relation->isVisible(); + }); + std::sort(relations.begin(), relations.end(), + [](const GeoDataRelation * a, const GeoDataRelation * b) { + return *a < *b; + }); + for (auto relation: relations) { if (relation->isVisible()) { styling.relation = relation; break; } } d->m_style = d->m_styleBuilder->createStyle(styling); } else { d->m_style = d->m_feature->style(); } } return d->m_style; } void GeoGraphicsItem::setStyleBuilder(const StyleBuilder *styleBuilder) { d->m_styleBuilder = styleBuilder; } void GeoGraphicsItem::resetStyle() { d->m_style = GeoDataStyle::ConstPtr(); } qreal GeoGraphicsItem::zValue() const { return d->m_zValue; } void GeoGraphicsItem::setZValue( qreal z ) { d->m_zValue = z; } void GeoGraphicsItem::setHighlighted( bool highlight ) { d->m_highlighted = highlight; } bool GeoGraphicsItem::isHighlighted() const { return d->m_highlighted; } QStringList GeoGraphicsItem::paintLayers() const { return d->m_paintLayers; } void GeoGraphicsItem::setPaintLayers(const QStringList &paintLayers) { d->m_paintLayers = paintLayers; } void GeoGraphicsItem::setRenderContext(const RenderContext &renderContext) { if (renderContext != d->m_renderContext) { d->m_renderContext = renderContext; d->m_style = GeoDataStyle::ConstPtr(); } } bool GeoGraphicsItem::contains(const QPoint &, const ViewportParams *) const { return false; } void GeoGraphicsItem::setRelations(const QSet &relations) { d->m_relations = relations; d->m_style = GeoDataStyle::ConstPtr(); } int GeoGraphicsItem::minZoomLevel() const { return d->m_minZoomLevel; } void GeoGraphicsItem::setMinZoomLevel(int zoomLevel) { d->m_minZoomLevel = zoomLevel; } bool GeoGraphicsItem::zValueLessThan(GeoGraphicsItem *one, GeoGraphicsItem *two) { return one->d->m_zValue < two->d->m_zValue; } bool GeoGraphicsItem::styleLessThan(GeoGraphicsItem *one, GeoGraphicsItem *two) { return reinterpret_cast(one->d->m_style.data()) < reinterpret_cast(two->d->m_style.data()); } bool GeoGraphicsItem::zValueAndStyleLessThan(GeoGraphicsItem *one, GeoGraphicsItem *two) { if (one->d->m_zValue == two->d->m_zValue) { return reinterpret_cast(one->d->m_style.data()) < reinterpret_cast(two->d->m_style.data()); } return one->d->m_zValue < two->d->m_zValue; } bool RenderContext::operator==(const RenderContext &other) const { return m_tileLevel == other.m_tileLevel; } bool RenderContext::operator!=(const RenderContext &other) const { return !operator==(other); } int RenderContext::tileLevel() const { return m_tileLevel; } RenderContext::RenderContext(int tileLevel) : m_tileLevel(tileLevel) { // nothing to do }