Skip to content
Permalink
Browse files

Merge pull request #9841 from signedav/default_symbol_scale_bp_34

[server] Default scale/mupmm on GetLegendGraphics
  • Loading branch information
pblottiere committed Apr 24, 2019
2 parents 8e19a32 + 434df5b commit fe45af0f53adda54abe2fdd342b640b7fb2c7e7f
@@ -152,6 +152,17 @@ Returns the quality for WMS images defined in a QGIS project.
:param project: the QGIS project

:return: quality if defined in project, -1 otherwise.
%End

double wmsDefaultMapUnitsPerMm( const QgsProject &project );
%Docstring
Returns the default number of map units per millimeters in case of the scale is not given

:param project: the QGIS project

:return: the default number of map units per millimeter

.. versionadded:: 3.4
%End

bool wmsUseLayerIds( const QgsProject &project );
@@ -637,6 +637,25 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mWMSImageQualitySpinBox->setValue( imageQuality );
}

QString defaultValueToolTip = tr( "In case of no other information to evaluate the map unit sized symbols, it uses default scale (on projected CRS) or default map units per mm (on geographic CRS)." );
mWMSDefaultMapUnitsPerMm = new QDoubleSpinBox();
mWMSDefaultMapUnitsPerMm->setDecimals( 4 );
mWMSDefaultMapUnitsPerMm->setSingleStep( 0.001 );
mWMSDefaultMapUnitsPerMm->setValue( QgsProject::instance()->readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 ) );
mWMSDefaultMapUnitsPerMm->setToolTip( defaultValueToolTip );
mWMSDefaultMapUnitScale = new QgsScaleWidget();
mWMSDefaultMapUnitScale->setScale( QgsProject::instance()->readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 ) * QgsUnitTypes::fromUnitToUnitFactor( QgsProject::instance()->crs().mapUnits(), QgsUnitTypes::DistanceMillimeters ) );
mWMSDefaultMapUnitScale->setToolTip( defaultValueToolTip );
if ( QgsProject::instance()->crs().isGeographic() )
{
mWMSDefaultMapUnitsPerMmLayout->addWidget( mWMSDefaultMapUnitsPerMm );
}
else
{
mWMSDefaultMapUnitsPerMmLayout->addWidget( mWMSDefaultMapUnitScale );
mWMSDefaultMapUnitsPerMmLabel->setText( tr( "Default scale for legend" ) );
}

mWMTSUrlLineEdit->setText( QgsProject::instance()->readEntry( QStringLiteral( "WMTSUrl" ), QStringLiteral( "/" ), QString() ) );
mWMTSMinScaleLineEdit->setValue( QgsProject::instance()->readNumEntry( QStringLiteral( "WMTSMinScale" ), QStringLiteral( "/" ), 5000 ) );

@@ -1257,6 +1276,18 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), imageQualityValue );
}

double defaultMapUnitsPerMm;
if ( QgsProject::instance()->crs().isGeographic() )
{
defaultMapUnitsPerMm = mWMSDefaultMapUnitsPerMm->value();
}
else
{
defaultMapUnitsPerMm = mWMSDefaultMapUnitScale->scale() / QgsUnitTypes::fromUnitToUnitFactor( QgsProject::instance()->crs().mapUnits(), QgsUnitTypes::DistanceMillimeters );
}

QgsProject::instance()->writeEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), defaultMapUnitsPerMm );

QgsProject::instance()->writeEntry( QStringLiteral( "WMTSUrl" ), QStringLiteral( "/" ), mWMTSUrlLineEdit->text() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMTSMinScale" ), QStringLiteral( "/" ), mWMTSMinScaleLineEdit->value() );
bool wmtsProject = false;
@@ -22,6 +22,7 @@
#include "qgis.h"
#include "qgsunittypes.h"
#include "qgsguiutils.h"
#include "qgsscalewidget.h"
#include "qgshelp.h"
#include "qgis_app.h"

@@ -188,6 +189,9 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
QgsMetadataWidget *mMetadataWidget = nullptr;
QgsLayerCapabilitiesModel *mLayerCapabilitiesModel = nullptr;

QDoubleSpinBox *mWMSDefaultMapUnitsPerMm = nullptr;
QgsScaleWidget *mWMSDefaultMapUnitScale = nullptr;

QgsCoordinateReferenceSystem mCrs;

void checkPageWidgetNameMap();
@@ -111,6 +111,11 @@ int QgsServerProjectUtils::wmsImageQuality( const QgsProject &project )
return project.readNumEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), -1 );
}

double QgsServerProjectUtils::wmsDefaultMapUnitsPerMm( const QgsProject &project )
{
return project.readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 );
}

bool QgsServerProjectUtils::wmsInfoFormatSia2045( const QgsProject &project )
{
QString sia2045 = project.readEntry( QStringLiteral( "WMSInfoFormatSIA2045" ), QStringLiteral( "/" ), "" );
@@ -147,6 +147,14 @@ namespace QgsServerProjectUtils
*/
SERVER_EXPORT int wmsImageQuality( const QgsProject &project );

/**
* Returns the default number of map units per millimeters in case of the scale is not given
* \param project the QGIS project
* \returns the default number of map units per millimeter
* \since QGIS 3.4
*/
SERVER_EXPORT double wmsDefaultMapUnitsPerMm( const QgsProject &project );

/**
* Returns if layer ids are used as name in WMS.
* \param project the QGIS project
@@ -193,15 +193,20 @@ namespace QgsWms
std::unique_ptr<QImage> image;
std::unique_ptr<QPainter> painter;

// getting scale from bbox
// getting scale from bbox or default size
if ( !mWmsParameters.bbox().isEmpty() )
{
QgsMapSettings mapSettings;
image.reset( createImage( width(), height(), false ) );
configureMapSettings( image.get(), mapSettings );
std::unique_ptr<QImage> tmp( createImage( width(), height(), false ) );
configureMapSettings( tmp.get(), mapSettings );
legendSettings.setMapScale( mapSettings.scale() );
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
}
else
{
double defaultMapUnitsPerPixel = QgsServerProjectUtils::wmsDefaultMapUnitsPerMm( *mProject ) / dpmm;
legendSettings.setMapUnitsPerPixel( defaultMapUnitsPerPixel );
}

if ( !mWmsParameters.rule().isEmpty() )
{

0 comments on commit fe45af0

Please sign in to comment.
You can’t perform that action at this time.