[QGIS Commit] r14810 - in trunk/qgis/src: core/symbology-ng
gui/symbology-ng ui ui/symbollayer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Nov 30 13:47:27 EST 2010
Author: wonder
Date: 2010-11-30 10:47:27 -0800 (Tue, 30 Nov 2010)
New Revision: 14810
Added:
trunk/qgis/src/ui/symbollayer/widget_centroidfill.ui
Modified:
trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp
trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.h
trunk/qgis/src/core/symbology-ng/qgssymbollayerv2registry.cpp
trunk/qgis/src/gui/symbology-ng/qgssymbollayerv2widget.cpp
trunk/qgis/src/gui/symbology-ng/qgssymbollayerv2widget.h
trunk/qgis/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp
trunk/qgis/src/ui/CMakeLists.txt
Log:
[FEATURE] Added "centroid fill" symbol layer which draws a marker on polygon's centroid.
Developed for Faunalia (http://www.faunalia.it) with funding from Regione Toscana - Sistema Informativo per la Gestione del Territorio e dell' Ambiente [RT-SIGTA].
For the project: "Sviluppo di prodotti software GIS open-source basati sui prodotti QuantumGIS e Postgis (CIG 037728516E)"
Modified: trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp 2010-11-30 18:01:02 UTC (rev 14809)
+++ trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp 2010-11-30 18:47:27 UTC (rev 14810)
@@ -10,7 +10,7 @@
#include <QSvgRenderer>
QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2( QColor color, Qt::BrushStyle style, QColor borderColor, Qt::PenStyle borderStyle, double borderWidth )
- : mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth )
+ : mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth )
{
mColor = color;
}
@@ -25,17 +25,17 @@
double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH;
QPointF offset;
- if( props.contains( "color" ) )
+ if ( props.contains( "color" ) )
color = QgsSymbolLayerV2Utils::decodeColor( props["color"] );
- if( props.contains( "style" ) )
+ if ( props.contains( "style" ) )
style = QgsSymbolLayerV2Utils::decodeBrushStyle( props["style"] );
- if( props.contains( "color_border" ) )
+ if ( props.contains( "color_border" ) )
borderColor = QgsSymbolLayerV2Utils::decodeColor( props["color_border"] );
- if( props.contains( "style_border" ) )
+ if ( props.contains( "style_border" ) )
borderStyle = QgsSymbolLayerV2Utils::decodePenStyle( props["style_border"] );
- if( props.contains( "width_border" ) )
+ if ( props.contains( "width_border" ) )
borderWidth = props["width_border"].toDouble();
- if( props.contains( "offset" ) )
+ if ( props.contains( "offset" ) )
offset = QgsSymbolLayerV2Utils::decodePoint( props["offset"] );
QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( color, style, borderColor, borderStyle, borderWidth );
@@ -56,7 +56,7 @@
// scale brush content for printout
double rasterScaleFactor = context.renderContext().rasterScaleFactor();
- if( rasterScaleFactor != 1.0 )
+ if ( rasterScaleFactor != 1.0 )
{
mBrush.setMatrix( QMatrix().scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor ) );
}
@@ -64,7 +64,7 @@
QColor selColor = context.selectionColor();
// selColor.setAlphaF( context.alpha() );
mSelBrush = QBrush( selColor );
- if( selectFillStyle ) mSelBrush.setStyle( mBrushStyle );
+ if ( selectFillStyle ) mSelBrush.setStyle( mBrushStyle );
mBorderColor.setAlphaF( context.alpha() );
mPen = QPen( mBorderColor );
mPen.setStyle( mBorderStyle );
@@ -78,7 +78,7 @@
void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
{
QPainter* p = context.renderContext().painter();
- if( !p )
+ if ( !p )
{
return;
}
@@ -86,12 +86,12 @@
p->setBrush( context.selected() ? mSelBrush : mBrush );
p->setPen( mPen );
- if( !mOffset.isNull() )
+ if ( !mOffset.isNull() )
p->translate( mOffset );
_renderPolygon( p, points, rings );
- if( !mOffset.isNull() )
+ if ( !mOffset.isNull() )
p->translate( -mOffset );
}
@@ -138,7 +138,7 @@
void QgsSVGFillSymbolLayer::setSvgFilePath( const QString& svgPath )
{
QFile svgFile( svgPath );
- if( svgFile.open( QFile::ReadOnly ) )
+ if ( svgFile.open( QFile::ReadOnly ) )
{
mSvgData = svgFile.readAll();
storeViewBox();
@@ -153,24 +153,24 @@
QString svgFilePath;
- if( properties.contains( "width" ) )
+ if ( properties.contains( "width" ) )
{
width = properties["width"].toDouble();
}
- if( properties.contains( "svgFile" ) )
+ if ( properties.contains( "svgFile" ) )
{
QString svgName = properties["svgFile"];
QString savePath = QgsSvgMarkerSymbolLayerV2::symbolNameToPath( svgName );
svgFilePath = ( savePath.isEmpty() ? svgName : savePath );
}
- if( !svgFilePath.isEmpty() )
+ if ( !svgFilePath.isEmpty() )
{
return new QgsSVGFillSymbolLayer( svgFilePath, width );
}
else
{
- if( properties.contains( "data" ) )
+ if ( properties.contains( "data" ) )
{
data = QByteArray::fromHex( properties["data"].toLocal8Bit() );
}
@@ -186,7 +186,7 @@
void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
{
- if( mSvgViewBox.isNull() )
+ if ( mSvgViewBox.isNull() )
{
return;
}
@@ -201,13 +201,13 @@
//rasterise byte array to image
QPainter p( &textureImage );
QSvgRenderer r( mSvgData );
- if( !r.isValid() )
+ if ( !r.isValid() )
{
return;
}
r.render( &p );
- if( context.alpha() < 1.0 )
+ if ( context.alpha() < 1.0 )
{
QgsSymbolLayerV2Utils::multiplyImageOpacity( &textureImage, context.alpha() );
}
@@ -217,7 +217,7 @@
mBrush.setTextureImage( textureImage );
mBrush.setTransform( brushTransform );
- if( mOutline )
+ if ( mOutline )
{
mOutline->startRender( context.renderContext() );
}
@@ -225,7 +225,7 @@
void QgsSVGFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
{
- if( mOutline )
+ if ( mOutline )
{
mOutline->stopRender( context.renderContext() );
}
@@ -234,27 +234,27 @@
void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
{
QPainter* p = context.renderContext().painter();
- if( !p )
+ if ( !p )
{
return;
}
p->setPen( QPen( Qt::NoPen ) );
- if( context.selected() )
+ if ( context.selected() )
{
QColor selColor = context.selectionColor();
- if( ! selectionIsOpaque ) selColor.setAlphaF( context.alpha() );
+ if ( ! selectionIsOpaque ) selColor.setAlphaF( context.alpha() );
p->setBrush( QBrush( selColor ) );
_renderPolygon( p, points, rings );
}
p->setBrush( mBrush );
_renderPolygon( p, points, rings );
- if( mOutline )
+ if ( mOutline )
{
mOutline->renderPolyline( points, context.renderContext(), -1, selectFillBorder && context.selected() );
- if( rings )
+ if ( rings )
{
QList<QPolygonF>::const_iterator ringIt = rings->constBegin();
- for( ; ringIt != rings->constEnd(); ++ringIt )
+ for ( ; ringIt != rings->constEnd(); ++ringIt )
{
mOutline->renderPolyline( *ringIt, context.renderContext(), -1, selectFillBorder && context.selected() );
}
@@ -265,7 +265,7 @@
QgsStringMap QgsSVGFillSymbolLayer::properties() const
{
QgsStringMap map;
- if( !mSvgFilePath.isEmpty() )
+ if ( !mSvgFilePath.isEmpty() )
{
map.insert( "svgFile", QgsSvgMarkerSymbolLayerV2::symbolPathToName( mSvgFilePath ) );
}
@@ -281,7 +281,7 @@
QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
{
QgsSymbolLayerV2* clonedLayer = 0;
- if( !mSvgFilePath.isEmpty() )
+ if ( !mSvgFilePath.isEmpty() )
{
clonedLayer = new QgsSVGFillSymbolLayer( mSvgFilePath, mPatternWidth );
}
@@ -290,7 +290,7 @@
clonedLayer = new QgsSVGFillSymbolLayer( mSvgData, mPatternWidth );
}
- if( mOutline )
+ if ( mOutline )
{
clonedLayer->setSubSymbol( mOutline->clone() );
}
@@ -299,10 +299,10 @@
void QgsSVGFillSymbolLayer::storeViewBox()
{
- if( !mSvgData.isEmpty() )
+ if ( !mSvgData.isEmpty() )
{
QSvgRenderer r( mSvgData );
- if( r.isValid() )
+ if ( r.isValid() )
{
mSvgViewBox = r.viewBoxF();
return;
@@ -315,14 +315,14 @@
bool QgsSVGFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
{
- if( !symbol || symbol->type() != QgsSymbolV2::Line )
+ if ( !symbol || symbol->type() != QgsSymbolV2::Line )
{
delete symbol;
return false;
}
QgsLineSymbolV2* lineSymbol = dynamic_cast<QgsLineSymbolV2*>( symbol );
- if( lineSymbol )
+ if ( lineSymbol )
{
delete mOutline;
mOutline = lineSymbol;
@@ -332,3 +332,100 @@
delete symbol;
return false;
}
+
+
+//////////////
+
+
+QgsCentroidFillSymbolLayerV2::QgsCentroidFillSymbolLayerV2()
+{
+ mMarker = NULL;
+ setSubSymbol( new QgsMarkerSymbolV2() );
+}
+
+QgsCentroidFillSymbolLayerV2::~QgsCentroidFillSymbolLayerV2()
+{
+ delete mMarker;
+}
+
+QgsSymbolLayerV2* QgsCentroidFillSymbolLayerV2::create( const QgsStringMap& /*properties*/ )
+{
+ return new QgsCentroidFillSymbolLayerV2();
+}
+
+QString QgsCentroidFillSymbolLayerV2::layerType() const
+{
+ return "CentroidFill";
+}
+
+void QgsCentroidFillSymbolLayerV2::setColor( const QColor& color )
+{
+ mMarker->setColor( color );
+ mColor = color;
+}
+
+void QgsCentroidFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
+{
+ mMarker->setAlpha( context.alpha() );
+ mMarker->setOutputUnit( context.outputUnit() );
+
+ mMarker->startRender( context.renderContext() );
+}
+
+void QgsCentroidFillSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
+{
+ mMarker->stopRender( context.renderContext() );
+}
+
+void QgsCentroidFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
+{
+ // calculate centroid
+ double cx = 0, cy = 0;
+ double area, sum = 0;
+ for ( int i = points.count() - 1, j = 0; j < points.count(); i = j++ )
+ {
+ const QPointF& p1 = points[i];
+ const QPointF& p2 = points[j];
+ area = p1.x() * p2.y() - p1.y() * p2.x();
+ sum += area;
+ cx += ( p1.x() + p2.x() ) * area;
+ cy += ( p1.y() + p2.y() ) * area;
+ }
+ sum *= 3.0;
+ cx /= sum;
+ cy /= sum;
+
+ mMarker->renderPoint( QPointF( cx, cy ), context.renderContext(), -1, context.selected() );
+}
+
+QgsStringMap QgsCentroidFillSymbolLayerV2::properties() const
+{
+ return QgsStringMap();
+}
+
+QgsSymbolLayerV2* QgsCentroidFillSymbolLayerV2::clone() const
+{
+ QgsCentroidFillSymbolLayerV2* x = new QgsCentroidFillSymbolLayerV2();
+ x->setSubSymbol( mMarker->clone() );
+ return x;
+}
+
+
+QgsSymbolV2* QgsCentroidFillSymbolLayerV2::subSymbol()
+{
+ return mMarker;
+}
+
+bool QgsCentroidFillSymbolLayerV2::setSubSymbol( QgsSymbolV2* symbol )
+{
+ if ( symbol == NULL || symbol->type() != QgsSymbolV2::Marker )
+ {
+ delete symbol;
+ return false;
+ }
+
+ delete mMarker;
+ mMarker = static_cast<QgsMarkerSymbolV2*>( symbol );
+ mColor = mMarker->color();
+ return true;
+}
Modified: trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.h 2010-11-30 18:01:02 UTC (rev 14809)
+++ trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.h 2010-11-30 18:47:27 UTC (rev 14810)
@@ -121,4 +121,39 @@
void storeViewBox();
};
+
+
+class CORE_EXPORT QgsCentroidFillSymbolLayerV2 : public QgsFillSymbolLayerV2
+{
+ public:
+ QgsCentroidFillSymbolLayerV2();
+ ~QgsCentroidFillSymbolLayerV2();
+
+ // static stuff
+
+ static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
+
+ // implemented from base classes
+
+ QString layerType() const;
+
+ void startRender( QgsSymbolV2RenderContext& context );
+
+ void stopRender( QgsSymbolV2RenderContext& context );
+
+ void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
+
+ QgsStringMap properties() const;
+
+ QgsSymbolLayerV2* clone() const;
+
+ void setColor( const QColor& color );
+
+ QgsSymbolV2* subSymbol();
+ bool setSubSymbol( QgsSymbolV2* symbol );
+
+ protected:
+ QgsMarkerSymbolV2* mMarker;
+};
+
#endif
Modified: trunk/qgis/src/core/symbology-ng/qgssymbollayerv2registry.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbollayerv2registry.cpp 2010-11-30 18:01:02 UTC (rev 14809)
+++ trunk/qgis/src/core/symbology-ng/qgssymbollayerv2registry.cpp 2010-11-30 18:47:27 UTC (rev 14810)
@@ -26,7 +26,10 @@
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleFill", QObject::tr( "Simple fill" ), QgsSymbolV2::Fill,
QgsSimpleFillSymbolLayerV2::create ) );
- addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SVGFill", QObject::tr( "SVG fill" ), QgsSymbolV2::Fill, QgsSVGFillSymbolLayer::create ) );
+ addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SVGFill", QObject::tr( "SVG fill" ), QgsSymbolV2::Fill,
+ QgsSVGFillSymbolLayer::create ) );
+ addSymbolLayerType( new QgsSymbolLayerV2Metadata( "CentroidFill", QObject::tr( "Centroid fill" ), QgsSymbolV2::Fill,
+ QgsCentroidFillSymbolLayerV2::create ) );
}
QgsSymbolLayerV2Registry::~QgsSymbolLayerV2Registry()
Modified: trunk/qgis/src/gui/symbology-ng/qgssymbollayerv2widget.cpp
===================================================================
--- trunk/qgis/src/gui/symbology-ng/qgssymbollayerv2widget.cpp 2010-11-30 18:01:02 UTC (rev 14809)
+++ trunk/qgis/src/gui/symbology-ng/qgssymbollayerv2widget.cpp 2010-11-30 18:47:27 UTC (rev 14810)
@@ -807,3 +807,50 @@
mLayer->setCharacter( chr );
emit changed();
}
+
+
+///////////////
+
+
+QgsCentroidFillSymbolLayerV2Widget::QgsCentroidFillSymbolLayerV2Widget( QWidget* parent )
+ : QgsSymbolLayerV2Widget( parent )
+{
+ mLayer = NULL;
+
+ setupUi( this );
+
+ connect( btnChangeMarker, SIGNAL( clicked() ), this, SLOT( setMarker() ) );
+}
+
+void QgsCentroidFillSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
+{
+ if ( layer->layerType() != "CentroidFill" )
+ return;
+
+ // layer type is correct, we can do the cast
+ mLayer = static_cast<QgsCentroidFillSymbolLayerV2*>( layer );
+
+ // set values
+ updateMarker();
+}
+
+QgsSymbolLayerV2* QgsCentroidFillSymbolLayerV2Widget::symbolLayer()
+{
+ return mLayer;
+}
+
+void QgsCentroidFillSymbolLayerV2Widget::setMarker()
+{
+ QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), this );
+ if ( dlg.exec() == 0 )
+ return;
+ updateMarker();
+
+ emit changed();
+}
+
+void QgsCentroidFillSymbolLayerV2Widget::updateMarker()
+{
+ QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mLayer->subSymbol(), btnChangeMarker->iconSize() );
+ btnChangeMarker->setIcon( icon );
+}
Modified: trunk/qgis/src/gui/symbology-ng/qgssymbollayerv2widget.h
===================================================================
--- trunk/qgis/src/gui/symbology-ng/qgssymbollayerv2widget.h 2010-11-30 18:01:02 UTC (rev 14809)
+++ trunk/qgis/src/gui/symbology-ng/qgssymbollayerv2widget.h 2010-11-30 18:47:27 UTC (rev 14810)
@@ -282,5 +282,34 @@
CharacterWidget* widgetChar;
};
+//////////
+
+#include "ui_widget_centroidfill.h"
+
+class QgsCentroidFillSymbolLayerV2;
+
+class GUI_EXPORT QgsCentroidFillSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetCentroidFill
+{
+ Q_OBJECT
+
+ public:
+ QgsCentroidFillSymbolLayerV2Widget( QWidget* parent = NULL );
+
+ static QgsSymbolLayerV2Widget* create() { return new QgsCentroidFillSymbolLayerV2Widget(); }
+
+ // from base class
+ virtual void setSymbolLayer( QgsSymbolLayerV2* layer );
+ virtual QgsSymbolLayerV2* symbolLayer();
+
+ public slots:
+ void setMarker();
+
+ protected:
+ void updateMarker();
+
+ QgsCentroidFillSymbolLayerV2* mLayer;
+};
+
+
#endif
Modified: trunk/qgis/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp
===================================================================
--- trunk/qgis/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp 2010-11-30 18:01:02 UTC (rev 14809)
+++ trunk/qgis/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp 2010-11-30 18:47:27 UTC (rev 14810)
@@ -94,6 +94,7 @@
_initWidgetFunction( "SimpleFill", QgsSimpleFillSymbolLayerV2Widget::create );
_initWidgetFunction( "SVGFill", QgsSVGFillSymbolLayerWidget::create );
+ _initWidgetFunction( "CentroidFill", QgsCentroidFillSymbolLayerV2Widget::create );
initialized = true;
}
@@ -363,7 +364,7 @@
updateUi();
// set previous layer as active
- QModelIndex newIndex = listLayers->model()->index( qMin(row, mSymbol->symbolLayerCount()-1), 0 );
+ QModelIndex newIndex = listLayers->model()->index( qMin( row, mSymbol->symbolLayerCount() - 1 ), 0 );
listLayers->setCurrentIndex( newIndex );
}
Modified: trunk/qgis/src/ui/CMakeLists.txt
===================================================================
--- trunk/qgis/src/ui/CMakeLists.txt 2010-11-30 18:01:02 UTC (rev 14809)
+++ trunk/qgis/src/ui/CMakeLists.txt 2010-11-30 18:47:27 UTC (rev 14810)
@@ -1,4 +1,4 @@
-#
+
FILE(GLOB QGIS_UIS "${CMAKE_CURRENT_SOURCE_DIR}/*.ui")
FILE(GLOB SYMBOLLAYER_UIS "${CMAKE_CURRENT_SOURCE_DIR}/symbollayer/*.ui")
Added: trunk/qgis/src/ui/symbollayer/widget_centroidfill.ui
===================================================================
--- trunk/qgis/src/ui/symbollayer/widget_centroidfill.ui (rev 0)
+++ trunk/qgis/src/ui/symbollayer/widget_centroidfill.ui 2010-11-30 18:47:27 UTC (rev 14810)
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>WidgetCentroidFill</class>
+ <widget class="QWidget" name="WidgetCentroidFill">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>366</width>
+ <height>242</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Marker</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="btnChangeMarker">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Change</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Preferred</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>112</width>
+ <height>48</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>350</width>
+ <height>81</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>btnChangeMarker</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
More information about the QGIS-commit
mailing list