Merge pull request #8320 from rldhont/server-reactivate-print-selection-3

[Server] Reactivate the capability to print selection with Server 3.4
This commit is contained in:
rldhont 2018-10-26 14:23:09 +02:00 committed by GitHub
commit 6249b07f7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 3 deletions

View File

@ -29,6 +29,7 @@ Stores information relating to the current rendering settings for a layout.
FlagUseAdvancedEffects,
FlagForceVectorOutput,
FlagHideCoverageLayer,
FlagDrawSelection,
};
typedef QFlags<QgsLayoutRenderContext::Flag> Flags;
@ -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

View File

@ -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() );

View File

@ -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 )
@ -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.
@ -206,6 +221,8 @@ class CORE_EXPORT QgsLayoutRenderContext : public QObject
int mCurrentExportLayer = -1;
QColor mSelectionColor = Qt::yellow;
QgsLayoutMeasurementConverter mMeasurementConverter;
bool mIsPreviewRender = true;

View File

@ -66,7 +66,6 @@
#include "qgslayerrestorer.h"
#include "qgsdxfexport.h"
#include "qgssymbollayerutils.h"
#include "qgslayoutitemlegend.h"
#include "qgsserverexception.h"
#include <QImage>
@ -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"
@ -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 );
}
@ -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 ) );
@ -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 );
@ -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 );
@ -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,

View File

@ -286,6 +286,7 @@ class TestQgsServerWMSGetPrint(QgsServerTestBase):
"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",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 979 KiB

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 296 KiB

After

Width:  |  Height:  |  Size: 290 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 296 KiB

After

Width:  |  Height:  |  Size: 290 KiB