Skip to content
Permalink
Browse files

[Server] Read and activate selection color

The selection color is read from QgsProject by QgsMapRenderer during the
rendering. So Server has to activate selection color by set color read from
project XML.
  • Loading branch information
rldhont authored and nyalldawson committed Jun 15, 2018
1 parent 085b939 commit 336b66097283eddf2044b12738793bae08c26f39
@@ -726,6 +726,15 @@ bool QgsSLDConfigParser::WMSInspireActivated() const
return false;
}

bool QgsSLDConfigParser::activateSelectionColor() const
{
if ( mFallbackParser )
{
return mFallbackParser->activateSelectionColor();
}
return false;
}

QgsComposition* QgsSLDConfigParser::createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap, QStringList& highlightLayers ) const
{
if ( mFallbackParser )
@@ -112,6 +112,9 @@ class QgsSLDConfigParser : public QgsWMSConfigParser
/** Adds inspire capabilities to xml document. ParentElem usually is the <Capabilities> element*/
void inspireCapabilities( QDomElement& parentElement, QDomDocument& doc ) const override;

// Selection color
bool activateSelectionColor() const override;

//printing

/** Creates a print composition, usually for a GetPrint request. Replaces map and label parameters*/
@@ -118,6 +118,9 @@ class SERVER_EXPORT QgsWMSConfigParser
/** Adds inspire capabilities to xml document. ParentElem usually is the <Capabilities> element*/
virtual void inspireCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;

// Selection color
virtual bool activateSelectionColor() const = 0;

//printing

/** Creates a print composition, usually for a GetPrint request. Replaces map and label parameters*/
@@ -26,6 +26,7 @@
#include "qgspallabeling.h"
#include "qgsrendererv2.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"

#include "qgscomposition.h"
#include "qgscomposerarrow.h"
@@ -469,6 +470,51 @@ bool QgsWMSProjectParser::WMSInspireActivated() const
return inspireActivated;
}

bool QgsWMSProjectParser::activateSelectionColor() const
{
QDomElement propertiesElem = mProjectParser->propertiesElem();
if ( !propertiesElem.isNull() )
{
QDomElement guiElem = propertiesElem.firstChildElement( "Gui" );
if ( !guiElem.isNull() )
{
int myAlpha = 255;
int myRed = 255;
int myGreen = 255;
int myBlue = 0;

QDomElement alphaElem = guiElem.firstChildElement( "SelectionColorAlphaPart" );
if ( !alphaElem.isNull() )
{
myAlpha = QVariant( alphaElem.text() ).toInt();
}
QDomElement redElem = guiElem.firstChildElement( "SelectionColorRedPart" );
if ( !redElem.isNull() )
{
myRed = QVariant( redElem.text() ).toInt();
}
QDomElement greenElem = guiElem.firstChildElement( "SelectionColorGreenPart" );
if ( !greenElem.isNull() )
{
myGreen = QVariant( greenElem.text() ).toInt();
}
QDomElement blueElem = guiElem.firstChildElement( "SelectionColorBluePart" );
if ( !blueElem.isNull() )
{
myBlue = QVariant( blueElem.text() ).toInt();
}
QgsProject* prj = QgsProject::instance();
prj->writeEntry( "Gui", "/SelectionColorRedPart", myRed );
prj->writeEntry( "Gui", "/SelectionColorGreenPart", myGreen );
prj->writeEntry( "Gui", "/SelectionColorBluePart", myBlue );
prj->writeEntry( "Gui", "/SelectionColorAlphaPart", myAlpha );
return true;
}
}

return false;
}

QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap* >& mapList, QList< QgsComposerLegend* >& legendList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlList ) const
{
//Create composition from xml
@@ -484,6 +530,9 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem
return nullptr;
}

// Selection color
activateSelectionColor();

QgsComposition* composition = new QgsComposition( mapRenderer->mapSettings() ); //set resolution, paper size from composer element attributes
if ( !composition->readXML( compositionElem, *( mProjectParser->xmlDocument() ) ) )
{
@@ -72,6 +72,9 @@ class SERVER_EXPORT QgsWMSProjectParser : public QgsWMSConfigParser
bool WMSInspireActivated() const override;
void inspireCapabilities( QDomElement& parentElement, QDomDocument& doc ) const override;

// Selection color
bool activateSelectionColor() const override;

//printing
QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap* >& mapList, QList< QgsComposerLegend* >& legendList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlFrameList ) const override;
void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const override;
@@ -1424,6 +1424,9 @@ QImage* QgsWMSServer::getMap( HitTest* hitTest )
QPainter thePainter( theImage );
thePainter.setRenderHint( QPainter::Antialiasing ); //make it look nicer

// Selection color
mConfigParser->activateSelectionColor();

QStringList layerSet = mMapRenderer->layerSet();
QStringList highlightLayers = QgsWMSConfigParser::addHighlightLayers( mParameters, layerSet );
mMapRenderer->setLayerSet( layerSet );
Binary file not shown.

0 comments on commit 336b660

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