Skip to content
Permalink
Browse files

Merge pull request #2666 from mhugent/symbology_brush_transform

Symbology brush transform
  • Loading branch information
mhugent committed Jan 19, 2016
2 parents 69cb0c4 + aa3e550 commit f4bdaad59f38c6688710318871f1524d4b17116a
@@ -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;

@@ -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;

@@ -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/;
@@ -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

///////////////////////////////////////////////////////////
@@ -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
@@ -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 );
}

@@ -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 );
}
@@ -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 )
@@ -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() );
@@ -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 )

@@ -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();
@@ -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 )
{
@@ -1606,6 +1612,8 @@ void QgsImageFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPol
}
}
}

mBrush.setTransform( bkTransform );
}

bool QgsImageFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
@@ -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() )
{
@@ -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;
@@ -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;
@@ -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 );
}
}
@@ -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;
@@ -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 );
@@ -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
}
@@ -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 );

0 comments on commit f4bdaad

Please sign in to comment.
You can’t perform that action at this time.