Skip to content

Commit

Permalink
[Server] Use Project selection color in GetPrint for 3.4
Browse files Browse the repository at this point in the history
Because selection was deactivated in layout, selection color was not transmitted from QgsProject to QgsLayoutRenderContext to QgsMapSettings.

forward porting of #7294
  • Loading branch information
rldhont committed Oct 25, 2018
1 parent 74f2785 commit a9e6950
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/core/auto_generated/layout/qgslayoutrendercontext.sip.in
Expand Up @@ -104,6 +104,24 @@ Returns the ``dpi`` for outputting the layout.
.. seealso:: :py:func:`setDpi`
%End

void setSelectionColor( const QColor &color );
%Docstring
Sets color that is used for drawing of selected vector features

.. seealso:: :py:func:`selectionColor`

.. versionadded:: 3.4
%End

QColor selectionColor() const;
%Docstring
Gets color that is used for drawing of selected vector features

.. seealso:: :py:func:`setSelectionColor`

.. versionadded:: 3.4
%End


QgsLayoutMeasurementConverter &measurementConverter();
%Docstring
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutitemmap.cpp
Expand Up @@ -1104,6 +1104,7 @@ QgsMapSettings QgsLayoutItemMap::mapSettings( const QgsRectangle &extent, QSizeF
jobMapSettings.setFlag( QgsMapSettings::ForceVectorOutput, true ); // force vector output (no caching of marker images etc.)
jobMapSettings.setFlag( QgsMapSettings::Antialiasing, mLayout->renderContext().flags() & QgsLayoutRenderContext::FlagAntialiasing );
jobMapSettings.setFlag( QgsMapSettings::DrawEditingInfo, false );
jobMapSettings.setSelectionColor( mLayout->renderContext().selectionColor() );
jobMapSettings.setFlag( QgsMapSettings::DrawSelection, mLayout->renderContext().flags() & QgsLayoutRenderContext::FlagDrawSelection );
jobMapSettings.setFlag( QgsMapSettings::UseAdvancedEffects, mLayout->renderContext().flags() & QgsLayoutRenderContext::FlagUseAdvancedEffects );
jobMapSettings.setTransformContext( mLayout->project()->transformContext() );
Expand Down
16 changes: 16 additions & 0 deletions src/core/layout/qgslayoutrendercontext.h
Expand Up @@ -105,6 +105,20 @@ class CORE_EXPORT QgsLayoutRenderContext : public QObject
*/
double dpi() const;

/**
* Sets color that is used for drawing of selected vector features
* \see selectionColor()
* \since QGIS 3.4
*/
void setSelectionColor( const QColor &color ) { mSelectionColor = color; }

/**
* Gets color that is used for drawing of selected vector features
* \see setSelectionColor()
* \since QGIS 3.4
*/
QColor selectionColor() const { return mSelectionColor; }

/**
* Returns the layout measurement converter to be used in the layout. This converter is used
* for translating between other measurement units and the layout's native unit.
Expand Down Expand Up @@ -207,6 +221,8 @@ class CORE_EXPORT QgsLayoutRenderContext : public QObject

int mCurrentExportLayer = -1;

QColor mSelectionColor = Qt::yellow;

QgsLayoutMeasurementConverter mMeasurementConverter;

bool mIsPreviewRender = true;
Expand Down
8 changes: 8 additions & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -450,6 +450,7 @@ namespace QgsWms

bool QgsRenderer::configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings )
{
c->renderContext().setSelectionColor( mapSettings.selectionColor() );
c->renderContext().setFlag( QgsLayoutRenderContext::FlagDrawSelection, true );
// Maps are configured first
QList<QgsLayoutItemMap *> maps;
Expand Down Expand Up @@ -1141,6 +1142,13 @@ namespace QgsWms

// enable rendering optimization
mapSettings.setFlag( QgsMapSettings::UseRenderingOptimization );

// set selection color
int myRed = mProject->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
int myGreen = mProject->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
int myBlue = mProject->readNumEntry( "Gui", "/SelectionColorBluePart", 0 );
int myAlpha = mProject->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 );
mapSettings.setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
}

QDomDocument QgsRenderer::featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
Expand Down

0 comments on commit a9e6950

Please sign in to comment.