Skip to content
Permalink
Browse files

rotated ticks followup : tests for data-defined properties

  • Loading branch information
olivierdalang authored and nyalldawson committed Oct 7, 2020
1 parent 70527cb commit b593e689501b639cb7ea6ae9d5175e55b948b084
@@ -734,6 +734,56 @@ def testDataDefinedAnnotationDistance(self):
self.report += checker.report()
self.assertTrue(myTestResult, myMessage)

def testDataDefinedTicksAndAnnotationDisplay(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
map = QgsLayoutItemMap(layout)
map.attemptSetSceneRect(QRectF(40, 20, 200, 100))
map.setFrameEnabled(True)
map.setBackgroundColor(QColor(150, 100, 100))
layout.addLayoutItem(map)
myRectangle = QgsRectangle(0.5, -5.5, 10.5, 0.5)
map.setExtent(myRectangle)
map.setMapRotation(45)
map.grid().setEnabled(True)
map.grid().setIntervalX(1)
map.grid().setIntervalY(1)
map.grid().setAnnotationEnabled(True)
map.grid().setGridLineColor(QColor(0, 255, 0))
map.grid().setGridLineWidth(0.5)
map.grid().setFrameStyle(QgsLayoutItemMapGrid.ExteriorTicks)
map.grid().setFrameWidth(4)
map.grid().setFramePenSize(1)
map.grid().setFramePenColor(QColor(0, 0, 255))
map.grid().setAnnotationFrameDistance(5)

format = QgsTextFormat.fromQFont(getTestFont('Bold', 20))
format.setColor(QColor(255, 0, 0))
format.setOpacity(150 / 255)
map.grid().setAnnotationTextFormat(format)
map.grid().setAnnotationPrecision(0)

map.grid().setRotatedTicksEnabled(True)
map.grid().setRotatedAnnotationsEnabled(True)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.OnTick)

map.grid().dataDefinedProperties().setProperty(QgsLayoutObject.MapGridAnnotationDisplayLeft, QgsProperty.fromValue("x_only"))
map.grid().dataDefinedProperties().setProperty(QgsLayoutObject.MapGridAnnotationDisplayRight, QgsProperty.fromValue("Y_ONLY"))
map.grid().dataDefinedProperties().setProperty(QgsLayoutObject.MapGridAnnotationDisplayTop, QgsProperty.fromValue("disabled"))
map.grid().dataDefinedProperties().setProperty(QgsLayoutObject.MapGridAnnotationDisplayBottom, QgsProperty.fromValue("ALL"))
map.grid().dataDefinedProperties().setProperty(QgsLayoutObject.MapGridFrameDivisionsLeft, QgsProperty.fromValue("X_ONLY"))
map.grid().dataDefinedProperties().setProperty(QgsLayoutObject.MapGridFrameDivisionsRight, QgsProperty.fromValue("y_only"))
map.grid().dataDefinedProperties().setProperty(QgsLayoutObject.MapGridFrameDivisionsTop, QgsProperty.fromValue("DISABLED"))
map.grid().dataDefinedProperties().setProperty(QgsLayoutObject.MapGridFrameDivisionsBottom, QgsProperty.fromValue("all"))

map.grid().refresh()

checker = QgsLayoutChecker('composermap_datadefined_ticksandannotationdisplay', layout)
checker.setControlPathPrefix("composer_mapgrid")
myTestResult, myMessage = checker.testLayout()
self.report += checker.report()
self.assertTrue(myTestResult, myMessage)

def testDynamicInterval(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
Binary file not shown.

0 comments on commit b593e68

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