Skip to content

Commit

Permalink
Translate brushs of image fills relativ to geometry bbox upper left p…
Browse files Browse the repository at this point in the history
…oint if rendering a map tile. Therefore it is assured, that the image pattern matches for adjacent tiles of the same scale
  • Loading branch information
mhugent committed Jan 5, 2016
1 parent 614c84f commit 15a8bc9
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 154 deletions.
4 changes: 4 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -107,6 +107,8 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
QgsDebugMsg( "Read project CRSID: " + QString::number( mProjectSrsId ) );
projectionSelector->setSelectedCrsId( mProjectSrsId );

mMapTileRenderingCheckBox->setChecked( mMapCanvas->mapSettings().testFlag( QgsMapSettings::RenderMapTile ) );

// see end of constructor for updating of projection selector

///////////////////////////////////////////////////////////
Expand Down Expand Up @@ -661,6 +663,8 @@ void QgsProjectProperties::apply()
mMapCanvas->setMapUnits( mapUnit );
mMapCanvas->setCrsTransformEnabled( cbxProjectionEnabled->isChecked() );

mMapCanvas->enableMapTileRendering( mMapTileRenderingCheckBox->isChecked() );

// Only change the projection if there is a node in the tree
// selected that has an srid. This prevents error if the user
// selects a top-level node rather than an actual coordinate
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsmapsettings.cpp
Expand Up @@ -596,6 +596,13 @@ void QgsMapSettings::readXML( QDomNode& theNode )
setRotation( rot );
}

//render map tile
QDomElement renderMapTileElem = theNode.firstChildElement( "rendermaptile" );
if ( !renderMapTileElem.isNull() )
{
setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == "1" ? true : false );
}

mDatumTransformStore.readXML( theNode );
}

Expand Down Expand Up @@ -626,5 +633,11 @@ void QgsMapSettings::writeXML( QDomNode& theNode, QDomDocument& theDoc )
theNode.appendChild( srsNode );
destinationCrs().writeXML( srsNode, theDoc );

//render map tile
QDomElement renderMapTileElem = theDoc.createElement( "rendermaptile" );
QDomText renderMapTileText = theDoc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
renderMapTileElem.appendChild( renderMapTileText );
theNode.appendChild( renderMapTileElem );

mDatumTransformStore.writeXML( theNode, theDoc );
}
1 change: 1 addition & 0 deletions src/core/qgsmapsettings.h
Expand Up @@ -136,6 +136,7 @@ class CORE_EXPORT QgsMapSettings
UseRenderingOptimization = 0x20, //!< Enable vector simplification and other rendering optimizations
DrawSelection = 0x40, //!< Whether vector selections should be shown in the rendered map
DrawSymbolBounds = 0x80, //!< Draw bounds of symbols (for debugging/testing)
RenderMapTile = 0x100, //!< Draw map such that there are no problems between adjacent tiles
// TODO: ignore scale-based visibility (overview)
};
Q_DECLARE_FLAGS( Flags, Flag )
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsrendercontext.cpp
Expand Up @@ -81,6 +81,7 @@ QgsRenderContext QgsRenderContext::fromMapSettings( const QgsMapSettings& mapSet
ctx.setSelectionColor( mapSettings.selectionColor() );
ctx.setFlag( DrawSelection, mapSettings.testFlag( QgsMapSettings::DrawSelection ) );
ctx.setFlag( DrawSymbolBounds, mapSettings.testFlag( QgsMapSettings::DrawSymbolBounds ) );
ctx.setFlag( RenderMapTile, mapSettings.testFlag( QgsMapSettings::RenderMapTile ) );
ctx.setRasterScaleFactor( 1.0 );
ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
ctx.setRendererScale( mapSettings.scale() );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsrendercontext.h
Expand Up @@ -58,6 +58,7 @@ class CORE_EXPORT QgsRenderContext
UseRenderingOptimization = 0x08, //!< Enable vector simplification and other rendering optimizations
DrawSelection = 0x10, //!< Whether vector selections should be shown in the rendered map
DrawSymbolBounds = 0x20, //!< Draw bounds of symbols (for debugging/testing)
RenderMapTile = 0x40, //!< Draw map such that there are no problems between adjacent tiles
};
Q_DECLARE_FLAGS( Flags, Flag )

Expand Down
10 changes: 10 additions & 0 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -1571,6 +1571,16 @@ void QgsImageFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPol
applyDataDefinedSettings( context );

p->setPen( QPen( Qt::NoPen ) );

if ( context.renderContext().testFlag( QgsRenderContext::RenderMapTile ) )
{
//transform brush to upper left corner of geometry bbox
QPointF leftCorner = points.boundingRect().topLeft();
QTransform leftCornerTransform = QTransform::fromTranslate( leftCorner.x(), leftCorner.y() );
mBrush.setTransform( leftCornerTransform );
}


if ( context.selected() )
{
QColor selColor = context.renderContext().selectionColor();
Expand Down
10 changes: 6 additions & 4 deletions src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -689,6 +689,8 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
bool deleteSegmentizedGeometry = false;
context.setGeometry( geom->geometry() );

bool tileMapRendering = context.testFlag( QgsRenderContext::RenderMapTile );

//convert curve types to normal point/line/polygon ones
if ( geom->geometry()->hasCurvedSegments() )
{
Expand Down Expand Up @@ -734,7 +736,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
QgsDebugMsg( "linestring can be drawn only with line symbol!" );
break;
}
_getLineString( pts, context, segmentizedGeometry->asWkb(), clipFeaturesToExtent() );
_getLineString( pts, context, segmentizedGeometry->asWkb(), !tileMapRendering && clipFeaturesToExtent() );
static_cast<QgsLineSymbolV2*>( this )->renderPolyline( pts, &feature, context, layer, selected );
}
break;
Expand All @@ -747,7 +749,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
QgsDebugMsg( "polygon can be drawn only with fill symbol!" );
break;
}
_getPolygon( pts, holes, context, segmentizedGeometry->asWkb(), clipFeaturesToExtent() );
_getPolygon( pts, holes, context, segmentizedGeometry->asWkb(), !tileMapRendering && clipFeaturesToExtent() );
static_cast<QgsFillSymbolV2*>( this )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : nullptr ), &feature, context, layer, selected );
}
break;
Expand Down Expand Up @@ -797,7 +799,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
{
context.setGeometry( geomCollection->geometryN( i ) );
}
ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, clipFeaturesToExtent() ) );
ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, !tileMapRendering && clipFeaturesToExtent() ) );
static_cast<QgsLineSymbolV2*>( this )->renderPolyline( pts, &feature, context, layer, selected );
}
}
Expand Down Expand Up @@ -828,7 +830,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
{
context.setGeometry( geomCollection->geometryN( i ) );
}
ptr = _getPolygon( pts, holes, context, ptr, clipFeaturesToExtent() );
ptr = _getPolygon( pts, holes, context, ptr, !tileMapRendering && clipFeaturesToExtent() );
static_cast<QgsFillSymbolV2*>( this )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : nullptr ), &feature, context, layer, selected );
}
break;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -314,6 +314,11 @@ void QgsMapCanvas::enableAntiAliasing( bool theFlag )
mMapOverview->enableAntiAliasing( theFlag );
} // anti aliasing

void QgsMapCanvas::enableMapTileRendering( bool theFlag )
{
mSettings.setFlag( QgsMapSettings::RenderMapTile, theFlag );
}

void QgsMapCanvas::useImageToRender( bool theFlag )
{
Q_UNUSED( theFlag );
Expand Down Expand Up @@ -1818,6 +1823,7 @@ void QgsMapCanvas::readProject( const QDomDocument & doc )
setExtent( tmpSettings.extent() );
setRotation( tmpSettings.rotation() );
mSettings.datumTransformStore() = tmpSettings.datumTransformStore();
enableMapTileRendering( tmpSettings.testFlag( QgsMapSettings::RenderMapTile ) );

clearExtentHistory(); // clear the extent history on project load
}
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -344,6 +344,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! true if antialising is enabled
bool antiAliasingEnabled() const { return mSettings.testFlag( QgsMapSettings::Antialiasing ); }

//! sets map tile rendering flag
void enableMapTileRendering( bool theFlag );

//! Select which Qt class to render with
//! @deprecated since 2.4 - does nothing because now we always render to QImage
Q_DECL_DEPRECATED void useImageToRender( bool theFlag );
Expand Down

0 comments on commit 15a8bc9

Please sign in to comment.