Skip to content

Commit

Permalink
Merge pull request #2666 from mhugent/symbology_brush_transform
Browse files Browse the repository at this point in the history
Symbology brush transform
  • Loading branch information
mhugent committed Jan 19, 2016
2 parents 69cb0c4 + aa3e550 commit f4bdaad
Show file tree
Hide file tree
Showing 21 changed files with 1,301 additions and 163 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsmapsettings.sip
Expand Up @@ -89,7 +89,7 @@ class QgsMapSettings
UseRenderingOptimization, //!< Enable vector simplification and other rendering optimizations
DrawSelection, //!< Whether vector selections should be shown in the rendered map
DrawSymbolBounds, //!< Draw bounds of symbols (for debugging/testing)
// TODO: ignore scale-based visibility (overview)
RenderMapTile
};
typedef QFlags<QgsMapSettings::Flag> Flags;

Expand Down
1 change: 1 addition & 0 deletions python/core/qgsrendercontext.sip
Expand Up @@ -19,6 +19,7 @@ class QgsRenderContext
UseRenderingOptimization, //!< Enable vector simplification and other rendering optimizations
DrawSelection, //!< Whether vector selections should be shown in the rendered map
DrawSymbolBounds, //!< Draw bounds of symbols (for debugging/testing)
RenderMapTile
};
typedef QFlags<QgsRenderContext::Flag> Flags;

Expand Down
3 changes: 3 additions & 0 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -281,6 +281,9 @@ class QgsMapCanvas : QGraphicsView
//! true if antialising is enabled
bool antiAliasingEnabled() const;

//! 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
void useImageToRender( bool theFlag ) /Deprecated/;
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -111,6 +111,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 @@ -736,6 +738,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
24 changes: 16 additions & 8 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -1571,6 +1571,17 @@ void QgsImageFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPol
applyDataDefinedSettings( context );

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

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

if ( context.selected() )
{
QColor selColor = context.renderContext().selectionColor();
Expand All @@ -1581,18 +1592,13 @@ void QgsImageFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPol
_renderPolygon( p, points, rings, context );
}

if ( qgsDoubleNear( mNextAngle, 0.0 ) )
{
p->setBrush( mBrush );
}
else
if ( !qgsDoubleNear( mNextAngle, 0.0 ) )
{
QTransform t = mBrush.transform();
t.rotate( mNextAngle );
QBrush rotatedBrush = mBrush;
rotatedBrush.setTransform( t );
p->setBrush( rotatedBrush );
mBrush.setTransform( t );
}
p->setBrush( mBrush );
_renderPolygon( p, points, rings, context );
if ( mOutline )
{
Expand All @@ -1606,6 +1612,8 @@ void QgsImageFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPol
}
}
}

mBrush.setTransform( bkTransform );
}

bool QgsImageFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
Expand Down
10 changes: 6 additions & 4 deletions src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -699,6 +699,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 @@ -748,7 +750,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 @@ -761,7 +763,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 @@ -815,7 +817,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 @@ -848,7 +850,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 @@ -315,6 +315,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 @@ -1865,6 +1870,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 @@ -358,6 +358,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 f4bdaad

Please sign in to comment.