Skip to content

Commit 336b660

Browse files
rldhontnyalldawson
authored andcommitted
[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.
1 parent 085b939 commit 336b660

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed

src/server/qgssldconfigparser.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,15 @@ bool QgsSLDConfigParser::WMSInspireActivated() const
726726
return false;
727727
}
728728

729+
bool QgsSLDConfigParser::activateSelectionColor() const
730+
{
731+
if ( mFallbackParser )
732+
{
733+
return mFallbackParser->activateSelectionColor();
734+
}
735+
return false;
736+
}
737+
729738
QgsComposition* QgsSLDConfigParser::createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap, QStringList& highlightLayers ) const
730739
{
731740
if ( mFallbackParser )

src/server/qgssldconfigparser.h

+3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ class QgsSLDConfigParser : public QgsWMSConfigParser
112112
/** Adds inspire capabilities to xml document. ParentElem usually is the <Capabilities> element*/
113113
void inspireCapabilities( QDomElement& parentElement, QDomDocument& doc ) const override;
114114

115+
// Selection color
116+
bool activateSelectionColor() const override;
117+
115118
//printing
116119

117120
/** Creates a print composition, usually for a GetPrint request. Replaces map and label parameters*/

src/server/qgswmsconfigparser.h

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class SERVER_EXPORT QgsWMSConfigParser
118118
/** Adds inspire capabilities to xml document. ParentElem usually is the <Capabilities> element*/
119119
virtual void inspireCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;
120120

121+
// Selection color
122+
virtual bool activateSelectionColor() const = 0;
123+
121124
//printing
122125

123126
/** Creates a print composition, usually for a GetPrint request. Replaces map and label parameters*/

src/server/qgswmsprojectparser.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgspallabeling.h"
2727
#include "qgsrendererv2.h"
2828
#include "qgsvectorlayer.h"
29+
#include "qgsproject.h"
2930

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

473+
bool QgsWMSProjectParser::activateSelectionColor() const
474+
{
475+
QDomElement propertiesElem = mProjectParser->propertiesElem();
476+
if ( !propertiesElem.isNull() )
477+
{
478+
QDomElement guiElem = propertiesElem.firstChildElement( "Gui" );
479+
if ( !guiElem.isNull() )
480+
{
481+
int myAlpha = 255;
482+
int myRed = 255;
483+
int myGreen = 255;
484+
int myBlue = 0;
485+
486+
QDomElement alphaElem = guiElem.firstChildElement( "SelectionColorAlphaPart" );
487+
if ( !alphaElem.isNull() )
488+
{
489+
myAlpha = QVariant( alphaElem.text() ).toInt();
490+
}
491+
QDomElement redElem = guiElem.firstChildElement( "SelectionColorRedPart" );
492+
if ( !redElem.isNull() )
493+
{
494+
myRed = QVariant( redElem.text() ).toInt();
495+
}
496+
QDomElement greenElem = guiElem.firstChildElement( "SelectionColorGreenPart" );
497+
if ( !greenElem.isNull() )
498+
{
499+
myGreen = QVariant( greenElem.text() ).toInt();
500+
}
501+
QDomElement blueElem = guiElem.firstChildElement( "SelectionColorBluePart" );
502+
if ( !blueElem.isNull() )
503+
{
504+
myBlue = QVariant( blueElem.text() ).toInt();
505+
}
506+
QgsProject* prj = QgsProject::instance();
507+
prj->writeEntry( "Gui", "/SelectionColorRedPart", myRed );
508+
prj->writeEntry( "Gui", "/SelectionColorGreenPart", myGreen );
509+
prj->writeEntry( "Gui", "/SelectionColorBluePart", myBlue );
510+
prj->writeEntry( "Gui", "/SelectionColorAlphaPart", myAlpha );
511+
return true;
512+
}
513+
}
514+
515+
return false;
516+
}
517+
472518
QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap* >& mapList, QList< QgsComposerLegend* >& legendList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlList ) const
473519
{
474520
//Create composition from xml
@@ -484,6 +530,9 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem
484530
return nullptr;
485531
}
486532

533+
// Selection color
534+
activateSelectionColor();
535+
487536
QgsComposition* composition = new QgsComposition( mapRenderer->mapSettings() ); //set resolution, paper size from composer element attributes
488537
if ( !composition->readXML( compositionElem, *( mProjectParser->xmlDocument() ) ) )
489538
{

src/server/qgswmsprojectparser.h

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class SERVER_EXPORT QgsWMSProjectParser : public QgsWMSConfigParser
7272
bool WMSInspireActivated() const override;
7373
void inspireCapabilities( QDomElement& parentElement, QDomDocument& doc ) const override;
7474

75+
// Selection color
76+
bool activateSelectionColor() const override;
77+
7578
//printing
7679
QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap* >& mapList, QList< QgsComposerLegend* >& legendList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlFrameList ) const override;
7780
void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const override;

src/server/qgswmsserver.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,9 @@ QImage* QgsWMSServer::getMap( HitTest* hitTest )
14241424
QPainter thePainter( theImage );
14251425
thePainter.setRenderHint( QPainter::Antialiasing ); //make it look nicer
14261426

1427+
// Selection color
1428+
mConfigParser->activateSelectionColor();
1429+
14271430
QStringList layerSet = mMapRenderer->layerSet();
14281431
QStringList highlightLayers = QgsWMSConfigParser::addHighlightLayers( mParameters, layerSet );
14291432
mMapRenderer->setLayerSet( layerSet );
Loading

0 commit comments

Comments
 (0)