Skip to content

Commit

Permalink
[Server] Read and activate selection color
Browse files Browse the repository at this point in the history
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 18, 2018
1 parent 085b939 commit 336b660
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/server/qgssldconfigparser.cpp
Expand Up @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions src/server/qgssldconfigparser.h
Expand Up @@ -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*/
Expand Down
3 changes: 3 additions & 0 deletions src/server/qgswmsconfigparser.h
Expand Up @@ -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*/
Expand Down
49 changes: 49 additions & 0 deletions src/server/qgswmsprojectparser.cpp
Expand Up @@ -26,6 +26,7 @@
#include "qgspallabeling.h"
#include "qgsrendererv2.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"

#include "qgscomposition.h"
#include "qgscomposerarrow.h"
Expand Down Expand Up @@ -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
Expand All @@ -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() ) ) )
{
Expand Down
3 changes: 3 additions & 0 deletions src/server/qgswmsprojectparser.h
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/server/qgswmsserver.cpp
Expand Up @@ -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 );
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 336b660

Please sign in to comment.