Skip to content

Commit

Permalink
Use random colors, fix sip includes, fix warnings in server
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Mar 27, 2020
1 parent 3c33bf7 commit 9e80f59
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 16 deletions.
Expand Up @@ -41,6 +41,7 @@ Constructs a style object
%Docstring
Constructs a style object as a copy of another style
%End
~QgsVectorTileBasicRendererStyle();

void setStyleName( const QString &name );
%Docstring
Expand Down Expand Up @@ -146,7 +147,7 @@ each defines a rendering rule.
public:
QgsVectorTileBasicRenderer();
%Docstring
Constructs renderer with some default styles
Constructs renderer with no styles
%End

virtual QString type() const;
Expand Down Expand Up @@ -178,7 +179,12 @@ Returns list of styles of the renderer
const QColor &lineStrokeColor, double lineStrokeWidth,
const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize );
%Docstring
Sets a default style to render all layers with the given fill/stroke colors, stroke widths and marker sizes
Returns a list of styles to render all layers with the given fill/stroke colors, stroke widths and marker sizes
%End

static QList<QgsVectorTileBasicRendererStyle> simpleStyleWithRandomColors();
%Docstring
Returns a list of styles to render all layers, using random colors
%End

};
Expand Down
6 changes: 3 additions & 3 deletions python/core/core_auto.sip
Expand Up @@ -531,10 +531,10 @@
%Include auto_generated/validity/qgsabstractvaliditycheck.sip
%Include auto_generated/validity/qgsvaliditycheckcontext.sip
%Include auto_generated/validity/qgsvaliditycheckregistry.sip
%Include auto_generated/vectortile/qgsvectortilebasicrenderer.sip
%Include auto_generated/vectortile/qgsvectortilelayer.sip
%Include auto_generated/vectortile/qgsvectortilerenderer.sip
%Include auto_generated/gps/qgsqtlocationconnection.sip
%Include auto_generated/gps/qgsgpsconnectionregistry.sip
%Include auto_generated/symbology/qgsmasksymbollayer.sip
%Include auto_generated/qgsuserprofile.sip
%Include auto_generated/vectortile/qgsvectortilebasicrenderer.sip
%Include auto_generated/vectortile/qgsvectortilelayer.sip
%Include auto_generated/vectortile/qgsvectortilerenderer.sip
19 changes: 11 additions & 8 deletions src/core/vectortile/qgsvectortilebasicrenderer.cpp
Expand Up @@ -15,6 +15,8 @@

#include "qgsvectortilebasicrenderer.h"

#include "qgsapplication.h"
#include "qgscolorschemeregistry.h"
#include "qgsexpressioncontextutils.h"
#include "qgsfillsymbollayer.h"
#include "qgslinesymbollayer.h"
Expand Down Expand Up @@ -48,6 +50,8 @@ QgsVectorTileBasicRendererStyle &QgsVectorTileBasicRendererStyle::operator=( con
return *this;
}

QgsVectorTileBasicRendererStyle::~QgsVectorTileBasicRendererStyle() = default;

void QgsVectorTileBasicRendererStyle::setSymbol( QgsSymbol *sym )
{
mSymbol.reset( sym );
Expand Down Expand Up @@ -97,7 +101,6 @@ void QgsVectorTileBasicRendererStyle::readXml( const QDomElement &elem, const Qg

QgsVectorTileBasicRenderer::QgsVectorTileBasicRenderer()
{
setDefaultStyle();
}

QString QgsVectorTileBasicRenderer::type() const
Expand Down Expand Up @@ -229,24 +232,24 @@ QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::styles() cons
return mStyles;
}

void QgsVectorTileBasicRenderer::setDefaultStyle()
QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyleWithRandomColors()
{
QColor polygonFillColor = Qt::blue;
QColor polygonFillColor = QgsApplication::colorSchemeRegistry()->fetchRandomStyleColor();
QColor polygonStrokeColor = polygonFillColor;
polygonFillColor.setAlpha( 100 );
double polygonStrokeWidth = DEFAULT_LINE_WIDTH;

QColor lineStrokeColor = Qt::blue;
QColor lineStrokeColor = QgsApplication::colorSchemeRegistry()->fetchRandomStyleColor();
double lineStrokeWidth = DEFAULT_LINE_WIDTH;

QColor pointFillColor = Qt::red;
QColor pointFillColor = QgsApplication::colorSchemeRegistry()->fetchRandomStyleColor();
QColor pointStrokeColor = pointFillColor;
pointFillColor.setAlpha( 100 );
double pointSize = DEFAULT_POINT_SIZE;

setStyles( simpleStyle( polygonFillColor, polygonStrokeColor, polygonStrokeWidth,
lineStrokeColor, lineStrokeWidth,
pointFillColor, pointStrokeColor, pointSize ) );
return simpleStyle( polygonFillColor, polygonStrokeColor, polygonStrokeWidth,
lineStrokeColor, lineStrokeWidth,
pointFillColor, pointStrokeColor, pointSize );
}

QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyle(
Expand Down
8 changes: 6 additions & 2 deletions src/core/vectortile/qgsvectortilebasicrenderer.h
Expand Up @@ -51,6 +51,7 @@ class CORE_EXPORT QgsVectorTileBasicRendererStyle
//! Constructs a style object as a copy of another style
QgsVectorTileBasicRendererStyle( const QgsVectorTileBasicRendererStyle &other );
QgsVectorTileBasicRendererStyle &operator=( const QgsVectorTileBasicRendererStyle &other );
~QgsVectorTileBasicRendererStyle();

//! Sets human readable name of this style
void setStyleName( const QString &name ) { mStyleName = name; }
Expand Down Expand Up @@ -125,7 +126,7 @@ class CORE_EXPORT QgsVectorTileBasicRendererStyle
class CORE_EXPORT QgsVectorTileBasicRenderer : public QgsVectorTileRenderer
{
public:
//! Constructs renderer with some default styles
//! Constructs renderer with no styles
QgsVectorTileBasicRenderer();

QString type() const override;
Expand All @@ -142,12 +143,15 @@ class CORE_EXPORT QgsVectorTileBasicRenderer : public QgsVectorTileRenderer
//! Returns list of styles of the renderer
QList<QgsVectorTileBasicRendererStyle> styles() const;

//! Sets a default style to render all layers with the given fill/stroke colors, stroke widths and marker sizes
//! Returns a list of styles to render all layers with the given fill/stroke colors, stroke widths and marker sizes
static QList<QgsVectorTileBasicRendererStyle> simpleStyle(
const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth,
const QColor &lineStrokeColor, double lineStrokeWidth,
const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize );

//! Returns a list of styles to render all layers, using random colors
static QList<QgsVectorTileBasicRendererStyle> simpleStyleWithRandomColors();

private:
void setDefaultStyle();

Expand Down
4 changes: 3 additions & 1 deletion src/core/vectortile/qgsvectortilelayer.cpp
Expand Up @@ -78,7 +78,9 @@ QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseN
setValid( true );

// set a default renderer
setRenderer( new QgsVectorTileBasicRenderer );
QgsVectorTileBasicRenderer *renderer = new QgsVectorTileBasicRenderer;
renderer->setStyles( QgsVectorTileBasicRenderer::simpleStyleWithRandomColors() );
setRenderer( renderer );
}

QgsVectorTileLayer::~QgsVectorTileLayer() = default;
Expand Down
2 changes: 2 additions & 0 deletions src/server/services/wms/qgslayerrestorer.cpp
Expand Up @@ -73,6 +73,7 @@ QgsLayerRestorer::QgsLayerRestorer( const QList<QgsMapLayer *> &layers )
}

case QgsMapLayerType::MeshLayer:
case QgsMapLayerType::VectorTileLayer:
case QgsMapLayerType::PluginLayer:
break;
}
Expand Down Expand Up @@ -128,6 +129,7 @@ QgsLayerRestorer::~QgsLayerRestorer()
}

case QgsMapLayerType::MeshLayer:
case QgsMapLayerType::VectorTileLayer:
case QgsMapLayerType::PluginLayer:
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/server/services/wms/qgswmsdescribelayer.cpp
Expand Up @@ -191,6 +191,7 @@ namespace QgsWms
}

case QgsMapLayerType::MeshLayer:
case QgsMapLayerType::VectorTileLayer:
case QgsMapLayerType::PluginLayer:
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/server/services/wms/qgswmsgetcapabilities.cpp
Expand Up @@ -1956,6 +1956,7 @@ namespace QgsWms
}

case QgsMapLayerType::MeshLayer:
case QgsMapLayerType::VectorTileLayer:
case QgsMapLayerType::PluginLayer:
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -2725,6 +2725,7 @@ namespace QgsWms
}

case QgsMapLayerType::MeshLayer:
case QgsMapLayerType::VectorTileLayer:
case QgsMapLayerType::PluginLayer:
break;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/src/core/testqgsvectortilelayer.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgsproject.h"
#include "qgsrenderchecker.h"
#include "qgstiles.h"
#include "qgsvectortilebasicrenderer.h"
#include "qgsvectortilelayer.h"

/**
Expand Down Expand Up @@ -75,6 +76,24 @@ void TestQgsVectorTileLayer::initTestCase()
mMapSettings = new QgsMapSettings();
mMapSettings->setLayers( QList<QgsMapLayer *>() << mLayer );

// let's have some standard style config for the layer
QColor polygonFillColor = Qt::blue;
QColor polygonStrokeColor = polygonFillColor;
polygonFillColor.setAlpha( 100 );
double polygonStrokeWidth = DEFAULT_LINE_WIDTH;
QColor lineStrokeColor = Qt::blue;
double lineStrokeWidth = DEFAULT_LINE_WIDTH;
QColor pointFillColor = Qt::red;
QColor pointStrokeColor = pointFillColor;
pointFillColor.setAlpha( 100 );
double pointSize = DEFAULT_POINT_SIZE;

QgsVectorTileBasicRenderer *rend = new QgsVectorTileBasicRenderer;
rend->setStyles( QgsVectorTileBasicRenderer::simpleStyle(
polygonFillColor, polygonStrokeColor, polygonStrokeWidth,
lineStrokeColor, lineStrokeWidth,
pointFillColor, pointStrokeColor, pointSize ) );
mLayer->setRenderer( rend ); // takes ownership
}

void TestQgsVectorTileLayer::cleanupTestCase()
Expand Down

0 comments on commit 9e80f59

Please sign in to comment.