Commit f847505b authored by Dennis Nienhüser's avatar Dennis Nienhüser

Use tile zoom level consistently

Previously an approximate one was guessed at several places based
on viewport size and an assumed vector tile size of 256 pixel
parent e109101b
......@@ -207,6 +207,9 @@ MarbleMapPrivate::MarbleMapPrivate( MarbleMap *parent, MarbleModel *model ) :
QObject::connect( &m_geometryLayer, SIGNAL(repaintNeeded()),
parent, SIGNAL(repaintNeeded()));
QObject::connect(&m_vectorTileLayer, SIGNAL(tileLevelChanged(int)), &m_geometryLayer, SLOT(setTileLevel(int)));
QObject::connect(&m_vectorTileLayer, SIGNAL(tileLevelChanged(int)), &m_placemarkLayer, SLOT(setTileLevel(int)));
QObject::connect(&m_textureLayer, SIGNAL(tileLevelChanged(int)), &m_placemarkLayer, SLOT(setTileLevel(int)));
/*
* Slot handleHighlight finds all placemarks
......
......@@ -288,10 +288,8 @@ void PlacemarkLayout::resetCacheData()
emit repaintNeeded();
}
QSet<TileId> PlacemarkLayout::visibleTiles( const ViewportParams *viewport )
QSet<TileId> PlacemarkLayout::visibleTiles( const ViewportParams *viewport, int zoomLevel ) const
{
int zoomLevel = qLn( viewport->radius()/64.0 ) / qLn( 2.0 );
/*
* rely on m_placemarkCache to find the placemarks for the tiles which
* matter. The top level tiles have the more popular placemarks,
......@@ -340,7 +338,7 @@ QSet<TileId> PlacemarkLayout::visibleTiles( const ViewportParams *viewport )
return tileIdSet;
}
QVector<VisiblePlacemark *> PlacemarkLayout::generateLayout( const ViewportParams *viewport )
QVector<VisiblePlacemark *> PlacemarkLayout::generateLayout( const ViewportParams *viewport, int tileLevel )
{
m_runtimeTrace.clear();
if ( m_placemarkModel->rowCount() <= 0 )
......@@ -398,7 +396,7 @@ QVector<VisiblePlacemark *> PlacemarkLayout::generateLayout( const ViewportParam
const QItemSelection selection = m_selectionModel->selection();
QList<const GeoDataPlacemark*> placemarkList;
foreach ( const TileId &tileId, visibleTiles( viewport ) ) {
foreach ( const TileId &tileId, visibleTiles( viewport, tileLevel ) ) {
placemarkList += m_placemarkCache.value( tileId );
}
std::sort(placemarkList.begin(), placemarkList.end(), GeoDataPlacemark::placemarkLayoutOrderCompare);
......
......@@ -72,7 +72,7 @@ class PlacemarkLayout : public QObject
/**
* @reimp
*/
QVector<VisiblePlacemark *> generateLayout( const ViewportParams *viewport );
QVector<VisiblePlacemark *> generateLayout(const ViewportParams *viewport , int tileLevel);
/**
* Returns a list of model indexes that are at position @p pos.
......@@ -115,7 +115,7 @@ class PlacemarkLayout : public QObject
void styleReset();
static QSet<TileId> visibleTiles( const ViewportParams *viewport );
QSet<TileId> visibleTiles( const ViewportParams *viewport, int tileLevel ) const;
bool layoutPlacemark(const GeoDataPlacemark *placemark, const GeoDataCoordinates &coordinates, qreal x, qreal y, bool selected );
/**
......
......@@ -58,9 +58,10 @@ const GeoDataLatLonAltBox& AbstractGeoPolygonGraphicsItem::latLonAltBox() const
return m_ring->latLonAltBox();
}
void AbstractGeoPolygonGraphicsItem::paint( GeoPainter* painter, const ViewportParams* viewport, const QString &layer )
void AbstractGeoPolygonGraphicsItem::paint( GeoPainter* painter, const ViewportParams* viewport, const QString &layer, int tileZoomLevel)
{
Q_UNUSED(layer);
Q_UNUSED(tileZoomLevel);
painter->save();
configurePainter(painter, viewport);
......
......@@ -34,7 +34,7 @@ protected:
public:
virtual const GeoDataLatLonAltBox& latLonAltBox() const;
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer);
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer, int tileZoomLevel);
protected:
QPen configurePainter(GeoPainter* painter, const ViewportParams *viewport);
......
......@@ -207,8 +207,9 @@ QVector<BuildingGeoPolygonGraphicsItem::NamedEntry> BuildingGeoPolygonGraphicsIt
return entries;
}
void BuildingGeoPolygonGraphicsItem::paint(GeoPainter* painter, const ViewportParams* viewport, const QString &layer)
void BuildingGeoPolygonGraphicsItem::paint(GeoPainter* painter, const ViewportParams* viewport, const QString &layer, int tileZoomLevel)
{
Q_UNUSED(tileZoomLevel);
if (layer.endsWith(QLatin1String("/frame"))) {
Q_ASSERT(m_cachedOuterPolygons.isEmpty());
Q_ASSERT(m_cachedInnerPolygons.isEmpty());
......
......@@ -26,7 +26,7 @@ public:
explicit BuildingGeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataLinearRing *ring);
public:
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer);
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer, int tileZoomLevel);
private:
struct NamedEntry {
......
......@@ -119,9 +119,8 @@ const GeoDataLatLonAltBox& GeoLineStringGraphicsItem::latLonAltBox() const
return m_renderLineString->latLonAltBox();
}
void GeoLineStringGraphicsItem::paint(GeoPainter* painter, const ViewportParams* viewport , const QString &layer)
void GeoLineStringGraphicsItem::paint(GeoPainter* painter, const ViewportParams* viewport , const QString &layer, int tileLevel)
{
int const tileLevel = qLn( viewport->radius() / 64.0 ) / qLn( 2.0 );
setRenderContext(RenderContext(tileLevel));
if (layer.endsWith(QLatin1String("/outline"))) {
......
......@@ -34,7 +34,7 @@ public:
virtual const GeoDataLatLonAltBox& latLonAltBox() const;
void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer);
void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer, int tileZoomLevel);
private:
void paintOutline(GeoPainter *painter, const ViewportParams *viewport);
......
......@@ -31,9 +31,10 @@ GeoPhotoGraphicsItem::GeoPhotoGraphicsItem( const GeoDataFeature *feature )
}
}
void GeoPhotoGraphicsItem::paint(GeoPainter* painter, const ViewportParams* viewport , const QString &layer)
void GeoPhotoGraphicsItem::paint(GeoPainter* painter, const ViewportParams* viewport , const QString &layer, int tileZoomLevel)
{
Q_UNUSED(layer);
Q_UNUSED(tileZoomLevel);
/* The code below loads the image lazily (only
* when it will actually be displayed). Once it was
* loaded but moves out of the viewport, it is unloaded
......
......@@ -29,7 +29,7 @@ public:
GeoDataPoint point() const;
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer);
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer, int tileZoomLevel);
virtual const GeoDataLatLonAltBox& latLonAltBox() const;
......
......@@ -28,10 +28,11 @@ GeoPointGraphicsItem::GeoPointGraphicsItem(const GeoDataPlacemark *placemark, co
}
}
void GeoPointGraphicsItem::paint(GeoPainter* painter, const ViewportParams* viewport , const QString &layer)
void GeoPointGraphicsItem::paint(GeoPainter* painter, const ViewportParams* viewport , const QString &layer, int tileLevel)
{
Q_UNUSED(viewport);
Q_UNUSED(layer);
Q_UNUSED(tileLevel);
painter->drawPoint(*m_point);
}
......
......@@ -25,7 +25,7 @@ class MARBLE_EXPORT GeoPointGraphicsItem : public GeoGraphicsItem
public:
explicit GeoPointGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataPoint *point);
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer);
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer, int tileLevel);
virtual const GeoDataLatLonAltBox& latLonAltBox() const;
......
......@@ -34,11 +34,12 @@ void GeoTrackGraphicsItem::setTrack( const GeoDataTrack* track )
update();
}
void GeoTrackGraphicsItem::paint(GeoPainter *painter, const ViewportParams *viewport , const QString &layer)
void GeoTrackGraphicsItem::paint(GeoPainter *painter, const ViewportParams *viewport , const QString &layer, int tileZoomLevel)
{
Q_UNUSED(layer);
Q_UNUSED(tileZoomLevel);
update();
GeoLineStringGraphicsItem::paint(painter, viewport, layer);
GeoLineStringGraphicsItem::paint(painter, viewport, layer, tileZoomLevel);
}
void GeoTrackGraphicsItem::update()
......
......@@ -25,7 +25,7 @@ class MARBLE_EXPORT GeoTrackGraphicsItem : public GeoLineStringGraphicsItem
public:
explicit GeoTrackGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataTrack *track);
virtual void paint(GeoPainter *painter, const ViewportParams *viewport, const QString &layer);
virtual void paint(GeoPainter *painter, const ViewportParams *viewport, const QString &layer, int tileZoomLevel);
private:
void setTrack(const GeoDataTrack *track);
......
......@@ -134,7 +134,7 @@ class MARBLE_EXPORT GeoGraphicsItem
* Note that depending on the projection and zoom level, the item may be visible more than once,
* which is taken care of by GeoPainter.
*/
virtual void paint(GeoPainter *painter, const ViewportParams *viewport, const QString &layer) = 0;
virtual void paint(GeoPainter *painter, const ViewportParams *viewport, const QString &layer, int tileZoomLevel) = 0;
void setHighlighted( bool highlight );
......
......@@ -88,11 +88,13 @@ public:
QList<ScreenOverlayGraphicsItem*> m_items;
QHash<qint64,OsmLineStringItems> m_osmLineStringItems;
int m_tileLevel;
};
GeometryLayerPrivate::GeometryLayerPrivate(const QAbstractItemModel *model, const StyleBuilder *styleBuilder) :
m_model(model),
m_styleBuilder(styleBuilder)
m_styleBuilder(styleBuilder),
m_tileLevel(0)
{
}
......@@ -136,7 +138,7 @@ bool GeometryLayer::render( GeoPainter *painter, ViewportParams *viewport,
painter->save();
const int maxZoomLevel = qMin<int>(qMax<int>(qLn(viewport->radius()*4/256)/qLn(2.0), 1), d->m_styleBuilder->maximumZoomLevel());
const int maxZoomLevel = qMin(d->m_tileLevel, d->m_styleBuilder->maximumZoomLevel());
QList<GeoGraphicsItem*> items = d->m_scene.items( viewport->viewLatLonAltBox(), maxZoomLevel );
typedef QPair<QString, GeoGraphicsItem*> LayerItem;
......@@ -181,12 +183,12 @@ bool GeometryLayer::render( GeoPainter *painter, ViewportParams *viewport,
std::stable_sort(layerItems.negative.begin(), layerItems.negative.end(), GeoGraphicsItem::zValueLessThan);
// The idea here is that layerItems.null has most items and needs not to be sorted => faster
std::stable_sort(layerItems.positive.begin(), layerItems.positive.end(), GeoGraphicsItem::zValueLessThan);
foreach(auto item, layerItems.negative) { item->paint(painter, viewport, layer); }
foreach(auto item, layerItems.null) { item->paint(painter, viewport, layer); }
foreach(auto item, layerItems.positive) { item->paint(painter, viewport, layer); }
foreach(auto item, layerItems.negative) { item->paint(painter, viewport, layer, d->m_tileLevel); }
foreach(auto item, layerItems.null) { item->paint(painter, viewport, layer, d->m_tileLevel); }
foreach(auto item, layerItems.positive) { item->paint(painter, viewport, layer, d->m_tileLevel); }
}
foreach(const auto & item, defaultLayer) {
item.second->paint(painter, viewport, item.first);
item.second->paint(painter, viewport, item.first, d->m_tileLevel);
}
foreach( ScreenOverlayGraphicsItem* item, d->m_items ) {
......@@ -196,7 +198,7 @@ bool GeometryLayer::render( GeoPainter *painter, ViewportParams *viewport,
painter->restore();
d->m_runtimeTrace = QStringLiteral("Geometries: %1 Zoom: %2")
.arg( items.size() )
.arg( maxZoomLevel );
.arg( d->m_tileLevel );
return true;
}
......@@ -437,9 +439,14 @@ void GeometryLayer::resetCacheData()
emit repaintNeeded();
}
void GeometryLayer::setTileLevel(int tileLevel)
{
d->m_tileLevel = tileLevel;
}
QVector<const GeoDataFeature*> GeometryLayer::whichFeatureAt(const QPoint &curpos, const ViewportParams *viewport)
{
const int maxZoom = qMin<int>(qMax<int>(qLn(viewport->radius()*4/256)/qLn(2.0), 1), d->m_styleBuilder->maximumZoomLevel());
const int maxZoom = qMin<int>(d->m_tileLevel, d->m_styleBuilder->maximumZoomLevel());
QVector<const GeoDataFeature*> result;
foreach ( GeoGraphicsItem * item, d->m_scene.items( viewport->viewLatLonAltBox(), maxZoom ) ) {
if ( item->feature()->nodeType() == GeoDataTypes::GeoDataPhotoOverlayType ) {
......@@ -477,7 +484,7 @@ QVector<const GeoDataFeature *> GeometryLayer::whichBuildingAt(const QPoint &cur
}
GeoDataCoordinates const coordinates = GeoDataCoordinates(lon, lat);
const int maxZoom = qMin<int>(qMax<int>(qLn(viewport->radius()*4/256)/qLn(2.0), 1), d->m_styleBuilder->maximumZoomLevel());
const int maxZoom = qMin<int>(d->m_tileLevel, d->m_styleBuilder->maximumZoomLevel());
foreach ( GeoGraphicsItem * item, d->m_scene.items( viewport->viewLatLonAltBox(), maxZoom ) ) {
if (item->feature()->nodeType() == GeoDataTypes::GeoDataPlacemarkType) {
const GeoDataPlacemark* placemark = static_cast<const GeoDataPlacemark*>(item->feature());
......
......@@ -56,6 +56,7 @@ public Q_SLOTS:
void addPlacemarks( const QModelIndex& index, int first, int last );
void removePlacemarks( const QModelIndex& index, int first, int last );
void resetCacheData();
void setTileLevel(int tileLevel);
/**
* Finds all placemarks that contain the clicked point.
......
......@@ -36,7 +36,8 @@ PlacemarkLayer::PlacemarkLayer(QAbstractItemModel *placemarkModel,
QObject *parent ) :
QObject( parent ),
m_layout( placemarkModel, selectionModel, clock, styleBuilder ),
m_debugModeEnabled(false)
m_debugModeEnabled(false),
m_tileLevel(0)
{
m_useXWorkaround = testXBug();
mDebug() << "Use workaround: " << ( m_useXWorkaround ? "1" : "0" );
......@@ -64,7 +65,7 @@ bool PlacemarkLayer::render( GeoPainter *geoPainter, ViewportParams *viewport,
Q_UNUSED( renderPos )
Q_UNUSED( layer )
QVector<VisiblePlacemark*> visiblePlacemarks = m_layout.generateLayout( viewport );
QVector<VisiblePlacemark*> visiblePlacemarks = m_layout.generateLayout( viewport, m_tileLevel );
// draw placemarks less important first
QVector<VisiblePlacemark*>::const_iterator visit = visiblePlacemarks.constEnd();
QVector<VisiblePlacemark*>::const_iterator itEnd = visiblePlacemarks.constBegin();
......@@ -248,6 +249,11 @@ void PlacemarkLayer::requestStyleReset()
m_layout.requestStyleReset();
}
void PlacemarkLayer::setTileLevel(int tileLevel)
{
m_tileLevel = tileLevel;
}
// Test if there a bug in the X server which makes
// text fully transparent if it gets written on
......
......@@ -101,6 +101,7 @@ class PlacemarkLayer : public QObject, public LayerInterface
void setShowMaria( bool show );
void requestStyleReset();
void setTileLevel(int tileLevel);
Q_SIGNALS:
void repaintNeeded();
......@@ -111,6 +112,7 @@ class PlacemarkLayer : public QObject, public LayerInterface
PlacemarkLayout m_layout;
bool m_debugModeEnabled;
int m_tileLevel;
};
}
......
......@@ -238,14 +238,14 @@ const QList<QActionGroup*> *AnnotatePlugin::actionGroups() const
return &m_actions;
}
bool AnnotatePlugin::render( GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer )
bool AnnotatePlugin::render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer)
{
Q_UNUSED( renderPos );
Q_UNUSED( layer );
QListIterator<SceneGraphicsItem*> iter( m_graphicsItems );
while ( iter.hasNext() ) {
iter.next()->paint( painter, viewport, "Annotation" );
iter.next()->paint( painter, viewport, "Annotation", -1 );
}
return true;
......
......@@ -59,9 +59,10 @@ AreaAnnotation::~AreaAnnotation()
delete m_animation;
}
void AreaAnnotation::paint(GeoPainter *painter, const ViewportParams *viewport , const QString &layer)
void AreaAnnotation::paint(GeoPainter *painter, const ViewportParams *viewport , const QString &layer, int tileZoomLevel)
{
Q_UNUSED(layer);
Q_UNUSED(tileZoomLevel);
m_viewport = viewport;
Q_ASSERT( placemark()->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType );
......
......@@ -43,7 +43,7 @@ public:
* @brief Paints the nodes on the screen and updates the regions which correspond
* to each node using the given GeoPainter.
*/
virtual void paint( GeoPainter *painter, const ViewportParams *viewport, const QString &layer );
virtual void paint( GeoPainter *painter, const ViewportParams *viewport, const QString &layer, int tileZoomLevel );
/**
* @brief Returns true if the given QPoint is contained by the current polygon. Note
......
......@@ -100,9 +100,10 @@ GroundOverlayFrame::GroundOverlayFrame( GeoDataPlacemark *placemark,
setPaintLayers(QStringList() << "GroundOverlayFrame");
}
void GroundOverlayFrame::paint(GeoPainter *painter, const ViewportParams *viewport , const QString &layer)
void GroundOverlayFrame::paint(GeoPainter *painter, const ViewportParams *viewport , const QString &layer, int tileZoomLevel)
{
Q_UNUSED(layer);
Q_UNUSED(tileZoomLevel);
m_viewport = viewport;
m_regionList.clear();
......
......@@ -56,7 +56,7 @@ public:
virtual const char *graphicType() const;
protected:
virtual void paint( GeoPainter *painter, const ViewportParams *viewport, const QString &layer );
virtual void paint( GeoPainter *painter, const ViewportParams *viewport, const QString &layer, int tileZoomLevel );
virtual bool mousePressEvent( QMouseEvent *event );
virtual bool mouseMoveEvent( QMouseEvent *event );
virtual bool mouseReleaseEvent( QMouseEvent *event );
......
......@@ -51,10 +51,11 @@ PlacemarkTextAnnotation::~PlacemarkTextAnnotation()
// nothing to do
}
void PlacemarkTextAnnotation::paint( GeoPainter *painter, const ViewportParams *viewport, const QString &layer )
void PlacemarkTextAnnotation::paint(GeoPainter *painter, const ViewportParams *viewport, const QString &layer , int tileZoomLevel)
{
Q_UNUSED(layer);
Q_UNUSED( painter );
Q_UNUSED(tileZoomLevel);
m_viewport = viewport;
GeoDataStyle::Ptr newStyle(new GeoDataStyle(*placemark()->style()));
......
......@@ -25,7 +25,7 @@ public:
explicit PlacemarkTextAnnotation( GeoDataPlacemark *placemark );
~PlacemarkTextAnnotation();
virtual void paint(GeoPainter *painter, const ViewportParams *viewport, const QString &layer);
virtual void paint(GeoPainter *painter, const ViewportParams *viewport, const QString &layer, int tileZoomLevel);
virtual bool containsPoint( const QPoint &eventPos ) const;
......
......@@ -58,9 +58,10 @@ PolylineAnnotation::~PolylineAnnotation()
delete m_animation;
}
void PolylineAnnotation::paint(GeoPainter *painter, const ViewportParams *viewport , const QString &layer)
void PolylineAnnotation::paint(GeoPainter *painter, const ViewportParams *viewport , const QString &layer, int tileZoomLevel)
{
Q_UNUSED(layer);
Q_UNUSED(tileZoomLevel);
m_viewport = viewport;
Q_ASSERT( placemark()->geometry()->nodeType() == GeoDataTypes::GeoDataLineStringType );
......
......@@ -36,7 +36,7 @@ public:
* @brief Paints the nodes on the screen and updates the regions which correspond
* to each node using the given GeoPainter.
*/
virtual void paint( GeoPainter *painter, const ViewportParams *viewport, const QString &layer );
virtual void paint( GeoPainter *painter, const ViewportParams *viewport, const QString &layer , int tileZoomLevel);
/**
* @brief Returns true if either the polyline's associated region or one of its nodes
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment