Skip to content

Commit

Permalink
Added a resolution parameter in option->Canvas&Legend to instruct WMS…
Browse files Browse the repository at this point in the history
… getLegendGraphic

to get WMS legend with a good resolution for printing.
Set value to 0 to get default pixmap resolution.

Drawback in case of big resolution of the legend, it becames too big to be
correctly shown as PopUp in the QgsLegend interface.

Developed with funding from Regione Toscana-SITA
  • Loading branch information
luipir committed Oct 18, 2013
1 parent 48002db commit 32da13b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -541,6 +541,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :

cmbLegendDoubleClickAction->setCurrentIndex( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() );

// WMS getLegendGraphic setting
mLegendGraphicResolutionSpinBox->setValue( settings.value("/qgis/defaultLegendGraphicResolution", 0).toInt() );

//
// Raster properties
//
Expand Down Expand Up @@ -961,6 +964,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() );
settings.setValue( "/qgis/addOracleDC", cbxAddOracleDC->isChecked() );
settings.setValue( "/qgis/addNewLayersToCurrentGroup", cbxAddNewLayersToCurrentGroup->isChecked() );
settings.setValue( "/qgis/defaultLegendGraphicResolution", mLegendGraphicResolutionSpinBox->value() );
bool createRasterLegendIcons = settings.value( "/qgis/createRasterLegendIcons", false ).toBool();
settings.setValue( "/qgis/createRasterLegendIcons", cbxCreateRasterLegendIcons->isChecked() );
settings.setValue( "/qgis/copyGeometryAsWKT", cbxCopyWKTGeomFromTable->isChecked() );
Expand Down
18 changes: 18 additions & 0 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -4663,6 +4663,24 @@ QImage QgsWmsProvider::getLegendGraphic( double scale, bool forceRefresh )
setQueryItem( url, "SCALE", QString::number( scale, 'f') );
setQueryItem( url, "FORMAT", mImageMimeType );

// add config parameter related to resolution
QSettings s;
int defaultLegendGraphicResolution = s.value( "/qgis/defaultLegendGraphicResolution", 0 ).toInt();
QgsDebugMsg( QString( "defaultLegendGraphicResolution: %1" ).arg( defaultLegendGraphicResolution ) );
if ( defaultLegendGraphicResolution ) {
if (url.queryItemValue("map_resolution") != "")
{
setQueryItem( url, "map_resolution", QString::number(defaultLegendGraphicResolution) );
}
else if (url.queryItemValue("dpi") != "")
{
setQueryItem( url, "dpi", QString::number(defaultLegendGraphicResolution) );
}
else{
QgsLogger::warning(tr("getLegendGraphic: Can not determine resolution uri parameter [map_resolution | dpi]. No resolution parameter will be used"));
}
}

mError = "";

QNetworkRequest request( url );
Expand Down
43 changes: 43 additions & 0 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -2345,6 +2345,49 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_34">
<item>
<widget class="QLabel" name="label_58">
<property name="text">
<string>WMS getLegendGraphic Resolution</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_39">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="mLegendGraphicResolutionSpinBox">
<property name="toolTip">
<string extracomment="MAP_RESOLUTION or DPI value overloading getMap default value (set 0 to use default)"/>
</property>
<property name="whatsThis">
<string extracomment="MAP_RESOLUTION or DPI value overloading getMap default value (set 0 to use default)"/>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1000000</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 32da13b

Please sign in to comment.