Skip to content

Commit

Permalink
[FEATURE] Add geometry generator symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 10, 2015
1 parent 554b41d commit 17f9d55
Show file tree
Hide file tree
Showing 18 changed files with 677 additions and 68 deletions.
3 changes: 3 additions & 0 deletions python/core/core.sip
Expand Up @@ -290,6 +290,9 @@
%Include symbology-ng/qgslinesymbollayerv2.sip
%Include symbology-ng/qgsmarkersymbollayerv2.sip
%Include symbology-ng/qgssymbollayerv2registry.sip
%Include symbology-ng/qgspolygongeneratorsymbollayerv2.sip
%Include symbology-ng/qgslinegeneratorsymbollayerv2.sip
%Include symbology-ng/qgspointgeneratorsymbollayerv2.sip

%Include symbology-ng/qgssymbologyv2conversion.sip

Expand Down
56 changes: 56 additions & 0 deletions python/core/symbology-ng/qgslinegeneratorsymbollayerv2.sip
@@ -0,0 +1,56 @@
/***************************************************************************
qgslinegeneratorsymbollayerv2.sip
---------------------
begin : November 2015
copyright : (C) 2015 by Matthias Kuhn
email : matthias at opengis dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
class QgsLineGeneratorSymbolLayerV2 : QgsLineSymbolLayerV2
{
%TypeHeaderCode
#include "qgslinegeneratorsymbollayerv2.h"
%End
public:
static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );

QgsLineGeneratorSymbolLayerV2( QgsLineSymbolV2* symbol, const QgsStringMap& properties = QgsStringMap() );

QString layerType() const;

void startRender( QgsSymbolV2RenderContext& context );

void stopRender( QgsSymbolV2RenderContext& context );

QgsSymbolLayerV2* clone() const;

QgsStringMap properties() const;

void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );

void setGeometryExpression( const QString& exp );

QString geometryExpression() const;

virtual QgsSymbolV2* subSymbol();

virtual bool setSubSymbol( QgsSymbolV2* symbol );

virtual QSet<QString> usedAttributes() const;

//! Will always return true.
//! This is a hybrid layer, it constructs its own geometry so it does not
//! care about the geometry of its parents.
bool isCompatibleWithSymbol( QgsSymbolV2* symbol );

virtual void renderPolyline( const QPolygonF& point, QgsSymbolV2RenderContext& context );

private:
QgsLineGeneratorSymbolLayerV2( const QgsLineGeneratorSymbolLayerV2& copy );
};
56 changes: 56 additions & 0 deletions python/core/symbology-ng/qgspointgeneratorsymbollayerv2.sip
@@ -0,0 +1,56 @@
/***************************************************************************
qgspointgeneratorsymbollayerv2.sip
---------------------
begin : November 2015
copyright : (C) 2015 by Matthias Kuhn
email : matthias at opengis dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
class QgsPointGeneratorSymbolLayerV2 : QgsMarkerSymbolLayerV2
{
%TypeHeaderCode
#include "qgspointgeneratorsymbollayerv2.h"
%End
public:
static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );

QgsPointGeneratorSymbolLayerV2( QgsMarkerSymbolV2* symbol, const QgsStringMap& properties = QgsStringMap() );

QString layerType() const;

void startRender( QgsSymbolV2RenderContext& context );

void stopRender( QgsSymbolV2RenderContext& context );

QgsSymbolLayerV2* clone() const;

QgsStringMap properties() const;

void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );

void setGeometryExpression( const QString& exp );

QString geometryExpression() const;

virtual QgsSymbolV2* subSymbol();

virtual bool setSubSymbol( QgsSymbolV2* symbol );

virtual QSet<QString> usedAttributes() const;

//! Will always return true.
//! This is a hybrid layer, it constructs its own geometry so it does not
//! care about the geometry of its parents.
bool isCompatibleWithSymbol( QgsSymbolV2* symbol );

void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );

private:
QgsPointGeneratorSymbolLayerV2( const QgsPointGeneratorSymbolLayerV2& copy );
};
56 changes: 56 additions & 0 deletions python/core/symbology-ng/qgspolygongeneratorsymbollayerv2.sip
@@ -0,0 +1,56 @@
/***************************************************************************
qgspolygongeneratorsymbollayerv2.sip
---------------------
begin : November 2015
copyright : (C) 2015 by Matthias Kuhn
email : matthias at opengis dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
class QgsPolygonGeneratorSymbolLayerV2 : QgsFillSymbolLayerV2
{
%TypeHeaderCode
#include "qgspolygongeneratorsymbollayerv2.h"
%End
public:
static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );

QgsPolygonGeneratorSymbolLayerV2( QgsFillSymbolV2* symbol, const QgsStringMap& properties = QgsStringMap() );

QString layerType() const;

void startRender( QgsSymbolV2RenderContext& context );

void stopRender( QgsSymbolV2RenderContext& context );

QgsSymbolLayerV2* clone() const;

QgsStringMap properties() const;

void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );

void setGeometryExpression( const QString& exp );

QString geometryExpression() const;

virtual QgsSymbolV2* subSymbol();

virtual bool setSubSymbol( QgsSymbolV2* symbol );

virtual QSet<QString> usedAttributes() const;

//! Will always return true.
//! This is a hybrid layer, it constructs its own geometry so it does not
//! care about the geometry of its parents.
bool isCompatibleWithSymbol( QgsSymbolV2* symbol );

void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );

private:
QgsPolygonGeneratorSymbolLayerV2( const QgsPolygonGeneratorSymbolLayerV2& copy );
};
3 changes: 3 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -1470,6 +1470,9 @@ void QgsProjectProperties::populateStyles()
case QgsSymbolV2::Fill :
cbo = cboStyleFill;
break;
case QgsSymbolV2::Hybrid:
// Shouldn't get here
break;
}
if ( cbo )
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -40,6 +40,7 @@ SET(QGIS_CORE_SRCS
symbology-ng/qgspointdisplacementrenderer.cpp
symbology-ng/qgsvectorfieldsymbollayer.cpp
symbology-ng/qgscolorbrewerpalette.cpp
symbology-ng/qgsgeometrygeneratorsymbollayerv2.cpp

diagram/qgsdiagram.cpp
diagram/qgspiediagram.cpp
Expand Down Expand Up @@ -755,6 +756,7 @@ SET(QGIS_CORE_HDRS
symbology-ng/qgssymbolv2.h
symbology-ng/qgsvectorcolorrampv2.h
symbology-ng/qgsvectorfieldsymbollayer.h
symbology-ng/qgsgeometrygeneratorsymbollayerv2.h

layertree/qgslayertree.h
layertree/qgslayertreeutils.h
Expand Down

2 comments on commit 17f9d55

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 17f9d55 Dec 11, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn , Geometry Generator doesn't work for line layers. Steps to reproduce:

  1. Load a line layer
  2. Open symbology, add a Geometry Generator layer, set it to polygon, and use a buffer expression (e.g. buffer($geometry, 200) )
  3. Apply the symbology, and note the generated polygon isn't drawn

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 17f9d55 Dec 11, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c9fa334
I added some tests to check for fill generators on points and line layers to avoid such issues in the future.

Please sign in to comment.