[QGIS Commit] r14855 - in trunk/qgis: python/core
src/core/symbology-ng src/gui/symbology-ng
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Dec 6 17:14:50 EST 2010
Author: wonder
Date: 2010-12-06 14:14:50 -0800 (Mon, 06 Dec 2010)
New Revision: 14855
Modified:
trunk/qgis/python/core/symbology-ng-core.sip
trunk/qgis/src/core/symbology-ng/qgssymbollayerv2.cpp
trunk/qgis/src/core/symbology-ng/qgssymbollayerv2.h
trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp
trunk/qgis/src/core/symbology-ng/qgssymbolv2.h
trunk/qgis/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp
Log:
[FEATURE] Allow the line symbol layers to be used for outline of polygon (fill) symbols
Modified: trunk/qgis/python/core/symbology-ng-core.sip
===================================================================
--- trunk/qgis/python/core/symbology-ng-core.sip 2010-12-06 21:56:55 UTC (rev 14854)
+++ trunk/qgis/python/core/symbology-ng-core.sip 2010-12-06 22:14:50 UTC (rev 14855)
@@ -565,6 +565,9 @@
public:
virtual void renderPolyline(const QPolygonF& points, QgsSymbolV2RenderContext& context) = 0;
+ //! @note added in v1.7
+ virtual void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
+
void setWidth(double width);
double width() const;
Modified: trunk/qgis/src/core/symbology-ng/qgssymbollayerv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbollayerv2.cpp 2010-12-06 21:56:55 UTC (rev 14854)
+++ trunk/qgis/src/core/symbology-ng/qgssymbollayerv2.cpp 2010-12-06 22:14:50 UTC (rev 14855)
@@ -45,6 +45,17 @@
stopRender( context );
}
+void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
+{
+ renderPolyline( points, context );
+ if ( rings )
+ {
+ foreach( const QPolygonF& ring, *rings )
+ renderPolyline( ring, context );
+ }
+}
+
+
void QgsFillSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
{
QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
Modified: trunk/qgis/src/core/symbology-ng/qgssymbollayerv2.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbollayerv2.h 2010-12-06 21:56:55 UTC (rev 14854)
+++ trunk/qgis/src/core/symbology-ng/qgssymbollayerv2.h 2010-12-06 22:14:50 UTC (rev 14855)
@@ -99,6 +99,9 @@
public:
virtual void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) = 0;
+ //! @note added in v1.7
+ virtual void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
+
virtual void setWidth( double width ) { mWidth = width; }
virtual double width() const { return mWidth; }
Modified: trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp 2010-12-06 21:56:55 UTC (rev 14854)
+++ trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp 2010-12-06 22:14:50 UTC (rev 14855)
@@ -28,7 +28,7 @@
{
mLayers.removeAt( i-- );
}
- else if ( mLayers[i]->type() != mType )
+ else if ( !isSymbolLayerCompatible( mLayers[i]->type() ) )
{
delete mLayers[i];
mLayers.removeAt( i-- );
@@ -69,12 +69,21 @@
}
+bool QgsSymbolV2::isSymbolLayerCompatible( SymbolType t )
+{
+ // fill symbol can contain also line symbol layers for drawing of outlines
+ if ( mType == Fill && t == Line )
+ return true;
+ return mType == t;
+}
+
+
bool QgsSymbolV2::insertSymbolLayer( int index, QgsSymbolLayerV2* layer )
{
if ( index < 0 || index > mLayers.count() ) // can be added also after the last index
return false;
- if ( layer == NULL || layer->type() != mType )
+ if ( layer == NULL || !isSymbolLayerCompatible( layer->type() ) )
return false;
mLayers.insert( index, layer );
@@ -84,7 +93,7 @@
bool QgsSymbolV2::appendSymbolLayer( QgsSymbolLayerV2* layer )
{
- if ( layer == NULL || layer->type() != mType )
+ if ( layer == NULL || !isSymbolLayerCompatible( layer->type() ) )
return false;
mLayers.append( layer );
@@ -116,7 +125,7 @@
{
if ( index < 0 || index >= mLayers.count() )
return false;
- if ( layer == NULL || layer->type() != mType )
+ if ( layer == NULL || !isSymbolLayerCompatible( layer->type() ) )
return false;
delete mLayers[index]; // first delete the original layer
@@ -165,7 +174,20 @@
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, false, mRenderHints );
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
{
- ( *it )->drawPreviewIcon( symbolContext, size );
+ if ( mType == Fill && ( *it )->type() == Line )
+ {
+ // line symbol layer would normally draw just a line
+ // so we override this case to force it to draw a polygon outline
+ QgsLineSymbolLayerV2* lsl = ( QgsLineSymbolLayerV2* ) * it;
+
+ // from QgsFillSymbolLayerV2::drawPreviewIcon()
+ QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
+ lsl->startRender( symbolContext );
+ lsl->renderPolygonOutline( poly, NULL, symbolContext );
+ lsl->stopRender( symbolContext );
+ }
+ else
+ ( *it )->drawPreviewIcon( symbolContext, size );
}
}
@@ -456,14 +478,29 @@
if ( layer != -1 )
{
if ( layer >= 0 && layer < mLayers.count() )
- (( QgsFillSymbolLayerV2* ) mLayers[layer] )->renderPolygon( points, rings, symbolContext );
+ {
+ QgsSymbolV2::SymbolType layertype = mLayers.at( layer )->type();
+ if ( layertype == QgsSymbolV2::Fill )
+ (( QgsFillSymbolLayerV2* ) mLayers[layer] )->renderPolygon( points, rings, symbolContext );
+ else if ( layertype == QgsSymbolV2::Line )
+ (( QgsLineSymbolLayerV2* ) mLayers[layer] )->renderPolygonOutline( points, rings, symbolContext );
+ }
return;
}
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
{
- QgsFillSymbolLayerV2* layer = ( QgsFillSymbolLayerV2* ) * it;
- layer->renderPolygon( points, rings, symbolContext );
+ QgsSymbolV2::SymbolType layertype = ( *it )->type();
+ if ( layertype == QgsSymbolV2::Fill )
+ {
+ QgsFillSymbolLayerV2* layer = ( QgsFillSymbolLayerV2* ) * it;
+ layer->renderPolygon( points, rings, symbolContext );
+ }
+ else if ( layertype == QgsSymbolV2::Line )
+ {
+ QgsLineSymbolLayerV2* layer = ( QgsLineSymbolLayerV2* ) * it;
+ layer->renderPolygonOutline( points, rings, symbolContext );
+ }
}
}
Modified: trunk/qgis/src/core/symbology-ng/qgssymbolv2.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbolv2.h 2010-12-06 21:56:55 UTC (rev 14854)
+++ trunk/qgis/src/core/symbology-ng/qgssymbolv2.h 2010-12-06 22:14:50 UTC (rev 14855)
@@ -101,6 +101,11 @@
QgsSymbolLayerV2List cloneLayers() const;
+ //! check whether a symbol layer type can be used within the symbol
+ //! (marker-marker, line-line, fill-fill/line)
+ //! @note added in 1.7
+ bool isSymbolLayerCompatible( SymbolType t );
+
SymbolType mType;
QgsSymbolLayerV2List mLayers;
Modified: trunk/qgis/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp
===================================================================
--- trunk/qgis/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp 2010-12-06 21:56:55 UTC (rev 14854)
+++ trunk/qgis/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp 2010-12-06 22:14:50 UTC (rev 14855)
@@ -164,6 +164,17 @@
cboLayerType->clear();
for ( int i = 0; i < types.count(); i++ )
cboLayerType->addItem( QgsSymbolLayerV2Registry::instance()->symbolLayerMetadata( types[i] )->visibleName(), types[i] );
+
+ if ( mSymbol->type() == QgsSymbolV2::Fill )
+ {
+ QStringList typesLine = QgsSymbolLayerV2Registry::instance()->symbolLayersForType( QgsSymbolV2::Line );
+ for ( int i = 0; i < typesLine.count(); i++ )
+ {
+ QString visibleName = QgsSymbolLayerV2Registry::instance()->symbolLayerMetadata( typesLine[i] )->visibleName();
+ QString name = QString( tr( "Outline: %1" ) ).arg( visibleName );
+ cboLayerType->addItem( name, typesLine[i] );
+ }
+ }
}
@@ -223,6 +234,10 @@
QStringList layerTypes = pReg->symbolLayersForType( mSymbol->type() );
+ // also load line symbol layers for fill symbols
+ if ( mSymbol->type() == QgsSymbolV2::Fill )
+ layerTypes += pReg->symbolLayersForType( QgsSymbolV2::Line );
+
for ( int i = 0; i < layerTypes.count(); i++ )
{
QString layerType = layerTypes[i];
More information about the QGIS-commit
mailing list