Skip to content

Commit

Permalink
Merge pull request #8320 from rldhont/server-reactivate-print-selecti…
Browse files Browse the repository at this point in the history
…on-3

[Server] Reactivate the capability to print selection with Server 3.4
  • Loading branch information
rldhont committed Oct 26, 2018
2 parents 4ba77f8 + b4e3160 commit 6249b07
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 3 deletions.
19 changes: 19 additions & 0 deletions python/core/auto_generated/layout/qgslayoutrendercontext.sip.in
Expand Up @@ -29,6 +29,7 @@ Stores information relating to the current rendering settings for a layout.
FlagUseAdvancedEffects,
FlagForceVectorOutput,
FlagHideCoverageLayer,
FlagDrawSelection,
};
typedef QFlags<QgsLayoutRenderContext::Flag> Flags;

Expand Down Expand Up @@ -103,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
3 changes: 2 additions & 1 deletion src/core/layout/qgslayoutitemmap.cpp
Expand Up @@ -1104,7 +1104,8 @@ 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.setFlag( QgsMapSettings::DrawSelection, 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() );
jobMapSettings.setPathResolver( mLayout->project()->pathResolver() );
Expand Down
17 changes: 17 additions & 0 deletions src/core/layout/qgslayoutrendercontext.h
Expand Up @@ -45,6 +45,7 @@ class CORE_EXPORT QgsLayoutRenderContext : public QObject
FlagUseAdvancedEffects = 1 << 4, //!< Enable advanced effects such as blend modes.
FlagForceVectorOutput = 1 << 5, //!< Force output in vector format where possible, even if items require rasterization to keep their correct appearance.
FlagHideCoverageLayer = 1 << 6, //!< Hide coverage layer in outputs
FlagDrawSelection = 1 << 7, //!< Draw selection
};
Q_DECLARE_FLAGS( Flags, Flag )

Expand Down Expand Up @@ -104,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 @@ -206,6 +221,8 @@ class CORE_EXPORT QgsLayoutRenderContext : public QObject

int mCurrentExportLayer = -1;

QColor mSelectionColor = Qt::yellow;

QgsLayoutMeasurementConverter mMeasurementConverter;

bool mIsPreviewRender = true;
Expand Down
16 changes: 14 additions & 2 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -66,7 +66,6 @@
#include "qgslayerrestorer.h"
#include "qgsdxfexport.h"
#include "qgssymbollayerutils.h"
#include "qgslayoutitemlegend.h"
#include "qgsserverexception.h"

#include <QImage>
Expand All @@ -80,6 +79,7 @@
#include "qgslayoutmanager.h"
#include "qgslayoutexporter.h"
#include "qgslayoutsize.h"
#include "qgslayoutrendercontext.h"
#include "qgslayoutmeasurement.h"
#include "qgsprintlayout.h"
#include "qgslayoutpagecollection.h"
Expand Down Expand Up @@ -396,6 +396,8 @@ namespace QgsWms
if ( ok )
exportSettings.dpi = dpi;
}
// Draw selections
exportSettings.flags |= QgsLayoutRenderContext::FlagDrawSelection;
QgsLayoutExporter exporter( layout.get() );
exporter.exportToSvg( tempOutputFile.fileName(), exportSettings );
}
Expand All @@ -413,6 +415,8 @@ namespace QgsWms
dpi = _dpi;
}
exportSettings.dpi = dpi;
// Draw selections
exportSettings.flags |= QgsLayoutRenderContext::FlagDrawSelection;
// Destination image size in px
QgsLayoutSize layoutSize( layout->pageCollection()->page( 0 )->sizeWithUnits() );
QgsLayoutMeasurement width( layout->convertFromLayoutUnits( layoutSize.width(), QgsUnitTypes::LayoutUnit::LayoutMillimeters ) );
Expand All @@ -435,6 +439,8 @@ namespace QgsWms
if ( ok )
exportSettings.dpi = dpi;
}
// Draw selections
exportSettings.flags |= QgsLayoutRenderContext::FlagDrawSelection;
// Export all pages
QgsLayoutExporter exporter( layout.get() );
exporter.exportToPdf( tempOutputFile.fileName(), exportSettings );
Expand All @@ -450,7 +456,6 @@ namespace QgsWms

bool QgsRenderer::configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings )
{

// Maps are configured first
QList<QgsLayoutItemMap *> maps;
c->layoutItems<QgsLayoutItemMap>( maps );
Expand Down Expand Up @@ -1141,6 +1146,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
1 change: 1 addition & 0 deletions tests/src/python/test_qgsserver_wms_getprint.py
Expand Up @@ -286,6 +286,7 @@ def test_wms_getprint_selection(self):
"REQUEST": "GetPrint",
"TEMPLATE": "layoutA4",
"FORMAT": "png",
"LAYERS": "Country,Hello",
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
"map0:LAYERS": "Country,Hello",
"CRS": "EPSG:3857",
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 6249b07

Please sign in to comment.