Skip to content

Commit 15a8bc9

Browse files
committedJan 5, 2016
Translate brushs of image fills relativ to geometry bbox upper left point if rendering a map tile. Therefore it is assured, that the image pattern matches for adjacent tiles of the same scale
1 parent 614c84f commit 15a8bc9

10 files changed

+103
-154
lines changed
 

‎src/app/qgsprojectproperties.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
107107
QgsDebugMsg( "Read project CRSID: " + QString::number( mProjectSrsId ) );
108108
projectionSelector->setSelectedCrsId( mProjectSrsId );
109109

110+
mMapTileRenderingCheckBox->setChecked( mMapCanvas->mapSettings().testFlag( QgsMapSettings::RenderMapTile ) );
111+
110112
// see end of constructor for updating of projection selector
111113

112114
///////////////////////////////////////////////////////////
@@ -661,6 +663,8 @@ void QgsProjectProperties::apply()
661663
mMapCanvas->setMapUnits( mapUnit );
662664
mMapCanvas->setCrsTransformEnabled( cbxProjectionEnabled->isChecked() );
663665

666+
mMapCanvas->enableMapTileRendering( mMapTileRenderingCheckBox->isChecked() );
667+
664668
// Only change the projection if there is a node in the tree
665669
// selected that has an srid. This prevents error if the user
666670
// selects a top-level node rather than an actual coordinate

‎src/core/qgsmapsettings.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,13 @@ void QgsMapSettings::readXML( QDomNode& theNode )
596596
setRotation( rot );
597597
}
598598

599+
//render map tile
600+
QDomElement renderMapTileElem = theNode.firstChildElement( "rendermaptile" );
601+
if ( !renderMapTileElem.isNull() )
602+
{
603+
setFlag( QgsMapSettings::RenderMapTile, renderMapTileElem.text() == "1" ? true : false );
604+
}
605+
599606
mDatumTransformStore.readXML( theNode );
600607
}
601608

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

636+
//render map tile
637+
QDomElement renderMapTileElem = theDoc.createElement( "rendermaptile" );
638+
QDomText renderMapTileText = theDoc.createTextNode( testFlag( QgsMapSettings::RenderMapTile ) ? "1" : "0" );
639+
renderMapTileElem.appendChild( renderMapTileText );
640+
theNode.appendChild( renderMapTileElem );
641+
629642
mDatumTransformStore.writeXML( theNode, theDoc );
630643
}

‎src/core/qgsmapsettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class CORE_EXPORT QgsMapSettings
136136
UseRenderingOptimization = 0x20, //!< Enable vector simplification and other rendering optimizations
137137
DrawSelection = 0x40, //!< Whether vector selections should be shown in the rendered map
138138
DrawSymbolBounds = 0x80, //!< Draw bounds of symbols (for debugging/testing)
139+
RenderMapTile = 0x100, //!< Draw map such that there are no problems between adjacent tiles
139140
// TODO: ignore scale-based visibility (overview)
140141
};
141142
Q_DECLARE_FLAGS( Flags, Flag )

‎src/core/qgsrendercontext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ QgsRenderContext QgsRenderContext::fromMapSettings( const QgsMapSettings& mapSet
8181
ctx.setSelectionColor( mapSettings.selectionColor() );
8282
ctx.setFlag( DrawSelection, mapSettings.testFlag( QgsMapSettings::DrawSelection ) );
8383
ctx.setFlag( DrawSymbolBounds, mapSettings.testFlag( QgsMapSettings::DrawSymbolBounds ) );
84+
ctx.setFlag( RenderMapTile, mapSettings.testFlag( QgsMapSettings::RenderMapTile ) );
8485
ctx.setRasterScaleFactor( 1.0 );
8586
ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
8687
ctx.setRendererScale( mapSettings.scale() );

‎src/core/qgsrendercontext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class CORE_EXPORT QgsRenderContext
5858
UseRenderingOptimization = 0x08, //!< Enable vector simplification and other rendering optimizations
5959
DrawSelection = 0x10, //!< Whether vector selections should be shown in the rendered map
6060
DrawSymbolBounds = 0x20, //!< Draw bounds of symbols (for debugging/testing)
61+
RenderMapTile = 0x40, //!< Draw map such that there are no problems between adjacent tiles
6162
};
6263
Q_DECLARE_FLAGS( Flags, Flag )
6364

‎src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,16 @@ void QgsImageFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPol
15711571
applyDataDefinedSettings( context );
15721572

15731573
p->setPen( QPen( Qt::NoPen ) );
1574+
1575+
if ( context.renderContext().testFlag( QgsRenderContext::RenderMapTile ) )
1576+
{
1577+
//transform brush to upper left corner of geometry bbox
1578+
QPointF leftCorner = points.boundingRect().topLeft();
1579+
QTransform leftCornerTransform = QTransform::fromTranslate( leftCorner.x(), leftCorner.y() );
1580+
mBrush.setTransform( leftCornerTransform );
1581+
}
1582+
1583+
15741584
if ( context.selected() )
15751585
{
15761586
QColor selColor = context.renderContext().selectionColor();

‎src/core/symbology-ng/qgssymbolv2.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
689689
bool deleteSegmentizedGeometry = false;
690690
context.setGeometry( geom->geometry() );
691691

692+
bool tileMapRendering = context.testFlag( QgsRenderContext::RenderMapTile );
693+
692694
//convert curve types to normal point/line/polygon ones
693695
if ( geom->geometry()->hasCurvedSegments() )
694696
{
@@ -734,7 +736,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
734736
QgsDebugMsg( "linestring can be drawn only with line symbol!" );
735737
break;
736738
}
737-
_getLineString( pts, context, segmentizedGeometry->asWkb(), clipFeaturesToExtent() );
739+
_getLineString( pts, context, segmentizedGeometry->asWkb(), !tileMapRendering && clipFeaturesToExtent() );
738740
static_cast<QgsLineSymbolV2*>( this )->renderPolyline( pts, &feature, context, layer, selected );
739741
}
740742
break;
@@ -747,7 +749,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
747749
QgsDebugMsg( "polygon can be drawn only with fill symbol!" );
748750
break;
749751
}
750-
_getPolygon( pts, holes, context, segmentizedGeometry->asWkb(), clipFeaturesToExtent() );
752+
_getPolygon( pts, holes, context, segmentizedGeometry->asWkb(), !tileMapRendering && clipFeaturesToExtent() );
751753
static_cast<QgsFillSymbolV2*>( this )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : nullptr ), &feature, context, layer, selected );
752754
}
753755
break;
@@ -797,7 +799,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
797799
{
798800
context.setGeometry( geomCollection->geometryN( i ) );
799801
}
800-
ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, clipFeaturesToExtent() ) );
802+
ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, !tileMapRendering && clipFeaturesToExtent() ) );
801803
static_cast<QgsLineSymbolV2*>( this )->renderPolyline( pts, &feature, context, layer, selected );
802804
}
803805
}
@@ -828,7 +830,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
828830
{
829831
context.setGeometry( geomCollection->geometryN( i ) );
830832
}
831-
ptr = _getPolygon( pts, holes, context, ptr, clipFeaturesToExtent() );
833+
ptr = _getPolygon( pts, holes, context, ptr, !tileMapRendering && clipFeaturesToExtent() );
832834
static_cast<QgsFillSymbolV2*>( this )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : nullptr ), &feature, context, layer, selected );
833835
}
834836
break;

‎src/gui/qgsmapcanvas.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ void QgsMapCanvas::enableAntiAliasing( bool theFlag )
314314
mMapOverview->enableAntiAliasing( theFlag );
315315
} // anti aliasing
316316

317+
void QgsMapCanvas::enableMapTileRendering( bool theFlag )
318+
{
319+
mSettings.setFlag( QgsMapSettings::RenderMapTile, theFlag );
320+
}
321+
317322
void QgsMapCanvas::useImageToRender( bool theFlag )
318323
{
319324
Q_UNUSED( theFlag );
@@ -1818,6 +1823,7 @@ void QgsMapCanvas::readProject( const QDomDocument & doc )
18181823
setExtent( tmpSettings.extent() );
18191824
setRotation( tmpSettings.rotation() );
18201825
mSettings.datumTransformStore() = tmpSettings.datumTransformStore();
1826+
enableMapTileRendering( tmpSettings.testFlag( QgsMapSettings::RenderMapTile ) );
18211827

18221828
clearExtentHistory(); // clear the extent history on project load
18231829
}

‎src/gui/qgsmapcanvas.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
344344
//! true if antialising is enabled
345345
bool antiAliasingEnabled() const { return mSettings.testFlag( QgsMapSettings::Antialiasing ); }
346346

347+
//! sets map tile rendering flag
348+
void enableMapTileRendering( bool theFlag );
349+
347350
//! Select which Qt class to render with
348351
//! @deprecated since 2.4 - does nothing because now we always render to QImage
349352
Q_DECL_DEPRECATED void useImageToRender( bool theFlag );

0 commit comments

Comments
 (0)