Skip to content

Commit

Permalink
Merge pull request #5435 from mhugent/wms_print_layers
Browse files Browse the repository at this point in the history
[needs-docs][feature] Wms print layers
  • Loading branch information
mhugent committed Oct 27, 2017
2 parents dfaabdc + 1592ccc commit 26bd6d7
Show file tree
Hide file tree
Showing 5 changed files with 352 additions and 16 deletions.
28 changes: 28 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -410,6 +410,13 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
mBandRenderingGrpBx->setSizePolicy( sizep );
mBandRenderingGrpBx->updateGeometry();
}

if ( mRasterLayer->providerType() != QStringLiteral( "wms" ) )
{
mWMSPrintGroupBox->hide();
mPublishDataSourceUrlCheckBox->hide();
mBackgroundLayerCheckBox->hide();
}
}

mRenderTypeComboBox_currentIndexChanged( widgetIndex );
Expand Down Expand Up @@ -786,6 +793,19 @@ void QgsRasterLayerProperties::sync()
mLayerLegendUrlLineEdit->setText( mRasterLayer->legendUrl() );
mLayerLegendUrlFormatComboBox->setCurrentIndex( mLayerLegendUrlFormatComboBox->findText( mRasterLayer->legendUrlFormat() ) );

//WMS print layer
QVariant wmsPrintLayer = mRasterLayer->customProperty( QStringLiteral( "WMSPrintLayer" ) );
if ( wmsPrintLayer.isValid() )
{
mWMSPrintLayerLineEdit->setText( wmsPrintLayer.toString() );
}

QVariant wmsPublishDataSourceUrl = mRasterLayer->customProperty( QStringLiteral( "WMSPublishDataSourceUrl" ), false );
mPublishDataSourceUrlCheckBox->setChecked( wmsPublishDataSourceUrl.toBool() );

QVariant wmsBackgroundLayer = mRasterLayer->customProperty( QStringLiteral( "WMSBackgroundLayer" ), false );
mBackgroundLayerCheckBox->setChecked( wmsBackgroundLayer.toBool() );

/*
* Legend Tab
*/
Expand Down Expand Up @@ -1013,6 +1033,14 @@ void QgsRasterLayerProperties::apply()
mMetadataFilled = false;
mRasterLayer->setLegendUrlFormat( mLayerLegendUrlFormatComboBox->currentText() );

if ( !mWMSPrintLayerLineEdit->text().isEmpty() )
{
mRasterLayer->setCustomProperty( QStringLiteral( "WMSPrintLayer" ), mWMSPrintLayerLineEdit->text() );
}

mRasterLayer->setCustomProperty( "WMSPublishDataSourceUrl", mPublishDataSourceUrlCheckBox->isChecked() );
mRasterLayer->setCustomProperty( "WMSBackgroundLayer", mBackgroundLayerCheckBox->isChecked() );

// update symbology
emit refreshLegend( mRasterLayer->id(), false );

Expand Down
35 changes: 35 additions & 0 deletions src/server/services/wms/qgswmsgetcapabilities.cpp
Expand Up @@ -1697,6 +1697,41 @@ namespace QgsWms

layerElem.appendChild( attributesElem );
}
else if ( currentLayer->type() == QgsMapLayer::RasterLayer )
{
const QgsDataProvider *provider = currentLayer->dataProvider();
if ( provider && provider->name() == "wms" )
{
//advertise as web map background layer
QVariant wmsBackgroundLayer = currentLayer->customProperty( QStringLiteral( "WMSBackgroundLayer" ), false );
QDomElement wmsBackgroundLayerElem = doc.createElement( "WMSBackgroundLayer" );
QDomText wmsBackgroundLayerText = doc.createTextNode( wmsBackgroundLayer.toBool() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
wmsBackgroundLayerElem.appendChild( wmsBackgroundLayerText );
layerElem.appendChild( wmsBackgroundLayerElem );

//publish datasource
QVariant wmsPublishDataSourceUrl = currentLayer->customProperty( QStringLiteral( "WMSPublishDataSourceUrl" ), false );
if ( wmsPublishDataSourceUrl.toBool() )
{
QList< QVariant > resolutionList = provider->property( "resolutions" ).toList();
bool tiled = resolutionList.size() > 0;

QDomElement dataSourceElem = doc.createElement( tiled ? QStringLiteral( "WMTSDataSource" ) : QStringLiteral( "WMSDataSource" ) );
QDomText dataSourceUri = doc.createTextNode( provider->dataSourceUri() );
dataSourceElem.appendChild( dataSourceUri );
layerElem.appendChild( dataSourceElem );
}
}

QVariant wmsPrintLayer = currentLayer->customProperty( QStringLiteral( "WMSPrintLayer" ) );
if ( wmsPrintLayer.isValid() )
{
QDomElement wmsPrintLayerElem = doc.createElement( "WMSPrintLayer" );
QDomText wmsPrintLayerText = doc.createTextNode( wmsPrintLayer.toString() );
wmsPrintLayerElem.appendChild( wmsPrintLayerText );
layerElem.appendChild( wmsPrintLayerElem );
}
}
}

}
Expand Down
58 changes: 42 additions & 16 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>789</width>
<height>593</height>
<width>815</width>
<height>777</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -236,7 +236,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>2</number>
<number>9</number>
</property>
<widget class="QWidget" name="mOptsPage_Information">
<layout class="QVBoxLayout" name="verticalLayout_20">
Expand Down Expand Up @@ -272,8 +272,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>608</width>
<height>527</height>
<width>311</width>
<height>106</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -392,8 +392,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>545</width>
<height>544</height>
<width>562</width>
<height>578</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
Expand Down Expand Up @@ -1023,8 +1023,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>368</width>
<height>502</height>
<width>371</width>
<height>550</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
Expand Down Expand Up @@ -1476,8 +1476,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>617</width>
<height>199</height>
<width>642</width>
<height>206</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down Expand Up @@ -1540,7 +1540,7 @@ border-radius: 2px;</string>
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'.SF NS Text'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:12pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
Expand Down Expand Up @@ -1646,8 +1646,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>85</width>
<height>31</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
Expand Down Expand Up @@ -1721,8 +1721,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>383</width>
<height>539</height>
<width>630</width>
<height>788</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_12">
Expand Down Expand Up @@ -2072,6 +2072,32 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="4" column="0">
<widget class="QgsCollapsibleGroupBox" name="mWMSPrintGroupBox">
<property name="title">
<string>WMS Print layer</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLineEdit" name="mWMSPrintLayerLineEdit"/>
</item>
</layout>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="mPublishDataSourceUrlCheckBox">
<property name="text">
<string>Publish WMS/WMTS data source uri</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="mBackgroundLayerCheckBox">
<property name="text">
<string>Advertise as background layer</string>
</property>
</widget>
</item>
<item row="7" column="0">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand Down
14 changes: 14 additions & 0 deletions tests/src/python/test_qgsserver_wms.py
Expand Up @@ -1946,6 +1946,20 @@ def test_wms_GetLegendGraphic_BBox2(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox2")

def test_wms_GetProjectSettings_wms_print_layers(self):
projectPath = self.testdata_path + "test_project_wms_printlayers.qgs"
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": projectPath,
"SERVICE": "WMS",
"VERSION": "1.3.0",
"REQUEST": "GetProjectSettings"
}.items())])
header, body = self._execute_request(qs)
xmlResult = body.decode('utf-8')
self.assertTrue(xmlResult.find("<WMSBackgroundLayer>1</WMSBackgroundLayer>") != -1)
self.assertTrue(xmlResult.find("<WMSDataSource>contextualWMSLegend=0&amp;crs=EPSG:21781&amp;dpiMode=7&amp;featureCount=10&amp;format=image/png&amp;layers=public_geo_gemeinden&amp;styles=&amp;url=https://qgiscloud.com/mhugent/qgis_unittest_wms/wms?</WMSDataSource>") != -1)
self.assertTrue(xmlResult.find("<WMSPrintLayer>contextualWMSLegend=0&amp;amp;crs=EPSG:21781&amp;amp;dpiMode=7&amp;amp;featureCount=10&amp;amp;format=image/png&amp;amp;layers=public_geo_gemeinden&amp;amp;styles=&amp;amp;url=https://qgiscloud.com/mhugent/qgis_unittest_wms_print/wms?</WMSPrintLayer>") != -1)


if __name__ == '__main__':
unittest.main()

0 comments on commit 26bd6d7

Please sign in to comment.