Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9829 from signedav/default_symbol_scale_bp_36
[server] Default scale/mupmm on GetLegendGraphics
  • Loading branch information
pblottiere committed Apr 24, 2019
2 parents a767198 + 1dbe784 commit 9637753
Show file tree
Hide file tree
Showing 18 changed files with 1,146 additions and 515 deletions.
11 changes: 11 additions & 0 deletions python/server/auto_generated/qgsserverprojectutils.sip.in
Expand Up @@ -161,6 +161,17 @@ Returns the maximum number of atlas features which can be printed in a request
:param project: the QGIS project

:return: the number of atlas features
%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 );
Expand Down
31 changes: 31 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -642,6 +642,25 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa

mWMSMaxAtlasFeaturesSpinBox->setValue( QgsProject::instance()->readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), 1 ) );

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

Expand Down Expand Up @@ -1298,6 +1317,18 @@ void QgsProjectProperties::apply()
int maxAtlasFeatures = mWMSMaxAtlasFeaturesSpinBox->value();
QgsProject::instance()->writeEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), maxAtlasFeatures );

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;
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsprojectproperties.h
Expand Up @@ -22,6 +22,7 @@
#include "qgis.h"
#include "qgsunittypes.h"
#include "qgsguiutils.h"
#include "qgsscalewidget.h"
#include "qgshelp.h"
#include "qgis_app.h"

Expand Down Expand Up @@ -204,6 +205,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();
Expand Down
5 changes: 5 additions & 0 deletions src/server/qgsserverprojectutils.cpp
Expand Up @@ -116,6 +116,11 @@ int QgsServerProjectUtils::wmsMaxAtlasFeatures( const QgsProject &project )
return project.readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), 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( "/" ), "" );
Expand Down
8 changes: 8 additions & 0 deletions src/server/qgsserverprojectutils.h
Expand Up @@ -154,6 +154,14 @@ namespace QgsServerProjectUtils
*/
SERVER_EXPORT int wmsMaxAtlasFeatures( 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
Expand Down
12 changes: 8 additions & 4 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -183,15 +183,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() )
{
Expand Down Expand Up @@ -231,7 +236,6 @@ namespace QgsWms
legendRendererNew.drawLegend( painter.get() );
painter->end();
}

rootGroup.clear();
return image.release();
}
Expand Down

0 comments on commit 9637753

Please sign in to comment.