Skip to content

Commit

Permalink
Merge pull request #6994 from pblottiere/server_candidates
Browse files Browse the repository at this point in the history
[server] Labeling settings
  • Loading branch information
pblottiere authored May 17, 2018
2 parents 56104bc + 2246ad6 commit d5ffc5a
Show file tree
Hide file tree
Showing 6 changed files with 3,403 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,7 @@ bool QgsProject::writeProjectFile( const QString &filename )
}
qgisNode.appendChild( layerOrderNode );

mLabelingEngineSettings->writeSettingsToProject( this );

// now add the optional extra properties

Expand All @@ -1646,8 +1647,6 @@ bool QgsProject::writeProjectFile( const QString &filename )

mMapThemeCollection->writeXml( *doc );

mLabelingEngineSettings->writeSettingsToProject( this );

mTransformContext.writeXml( qgisNode, context );

QDomElement metadataElem = doc->createElement( QStringLiteral( "projectMetadata" ) );
Expand Down
3 changes: 3 additions & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,9 @@ namespace QgsWms
QgsExpressionContext context = mProject->createExpressionContext();
context << QgsExpressionContextUtils::mapSettingsScope( mapSettings );
mapSettings.setExpressionContext( context );

// add labeling engine settings
mapSettings.setLabelingEngineSettings( mProject->labelingEngineSettings() );
}

QDomDocument QgsRenderer::featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
Expand Down
23 changes: 23 additions & 0 deletions tests/src/python/test_qgsproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
QgsApplication,
QgsUnitTypes,
QgsCoordinateReferenceSystem,
QgsLabelingEngineSettings,
QgsVectorLayer,
QgsRasterLayer,
QgsMapLayer,
Expand Down Expand Up @@ -1033,6 +1034,28 @@ def testCustomLayerOrderFrom3xProject(self):
self.assertEqual(tree.customLayerOrder(), [layer_y, layer_x])
self.assertEqual(tree.layerOrder(), [layer_y, layer_x])

def testPalPropertiesReadWrite(self):
tmpDir = QTemporaryDir()
tmpFile = "{}/project.qgs".format(tmpDir.path())

s0 = QgsLabelingEngineSettings()
s0.setNumCandidatePositions(3, 33, 333)

p0 = QgsProject()
p0.setFileName(tmpFile)
p0.setLabelingEngineSettings(s0)
p0.write()

p1 = QgsProject()
p1.read(tmpFile)

s1 = p1.labelingEngineSettings()
candidates = s1.numCandidatePositions()

self.assertEqual(candidates[0], 3)
self.assertEqual(candidates[1], 33)
self.assertEqual(candidates[2], 333)


if __name__ == '__main__':
unittest.main()
25 changes: 25 additions & 0 deletions tests/src/python/test_qgsserver_wms_getmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import osgeo.gdal # NOQA

from test_qgsserver import QgsServerTestBase
from utilities import unitTestDataPath
from qgis.core import QgsProject

# Strip path and content length because path may vary
Expand Down Expand Up @@ -515,6 +516,30 @@ def test_wms_getmap_transparent(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_Transparent")

def test_wms_getmap_labeling_settings(self):
# Test the `DrawRectOnly` option with 1 candidate (`CandidatesPolygon`).
# May fail if the labeling position engine is tweaked.

d = unitTestDataPath('qgis_server_accesscontrol') + '/'
project = os.path.join(d, "project_labeling_settings.qgs")
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(project),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetMap",
"LAYERS": "Country_Labels",
"STYLES": "",
"FORMAT": "image/png",
"BBOX": "-16817707,-4710778,5696513,14587125",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857",
"TRANSPARENT": "TRUE"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_LabelingSettings")

def test_wms_getmap_background(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d5ffc5a

Please sign in to comment.