Skip to content
Permalink
Browse files

Merge pull request #6994 from pblottiere/server_candidates

[server] Labeling settings
  • Loading branch information
pblottiere committed May 17, 2018
2 parents 56104bc + 2246ad6 commit d5ffc5a2d986555ccc3fd3c4bb332b5e369a7082
@@ -1631,6 +1631,7 @@ bool QgsProject::writeProjectFile( const QString &filename )
}
qgisNode.appendChild( layerOrderNode );

mLabelingEngineSettings->writeSettingsToProject( this );

// now add the optional extra properties

@@ -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" ) );
@@ -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,
@@ -23,6 +23,7 @@
QgsApplication,
QgsUnitTypes,
QgsCoordinateReferenceSystem,
QgsLabelingEngineSettings,
QgsVectorLayer,
QgsRasterLayer,
QgsMapLayer,
@@ -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()
@@ -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
@@ -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),
Binary file not shown.

0 comments on commit d5ffc5a

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