本文整理汇总了Python中qgis.core.QgsComposerPolygon类的典型用法代码示例。如果您正苦于以下问题:Python QgsComposerPolygon类的具体用法?Python QgsComposerPolygon怎么用?Python QgsComposerPolygon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QgsComposerPolygon类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, methodName):
"""Run once on class initialization."""
unittest.TestCase.__init__(self, methodName)
self.mapSettings = QgsMapSettings()
# create composition
self.mComposition = QgsComposition(self.mapSettings)
self.mComposition.setPaperSize(297, 210)
# create
polygon = QPolygonF()
polygon.append(QPointF(0.0, 0.0))
polygon.append(QPointF(100.0, 0.0))
polygon.append(QPointF(200.0, 100.0))
polygon.append(QPointF(100.0, 200.0))
self.mComposerPolygon = QgsComposerPolygon(polygon, self.mComposition)
self.mComposition.addComposerPolygon(self.mComposerPolygon)
# style
props = {}
props["color"] = "green"
props["style"] = "solid"
props["style_border"] = "solid"
props["color_border"] = "black"
props["width_border"] = "10.0"
props["joinstyle"] = "miter"
style = QgsFillSymbol.createSimple(props)
self.mComposerPolygon.setPolygonStyleSymbol(style)
示例2: TestQgsComposerPolygon
class TestQgsComposerPolygon(unittest.TestCase):
def __init__(self, methodName):
"""Run once on class initialization."""
unittest.TestCase.__init__(self, methodName)
self.mapSettings = QgsMapSettings()
# create composition
self.mComposition = QgsComposition(self.mapSettings)
self.mComposition.setPaperSize(297, 210)
# create
polygon = QPolygonF()
polygon.append(QPointF(0.0, 0.0))
polygon.append(QPointF(100.0, 0.0))
polygon.append(QPointF(200.0, 100.0))
polygon.append(QPointF(100.0, 200.0))
self.mComposerPolygon = QgsComposerPolygon(polygon, self.mComposition)
self.mComposition.addComposerPolygon(self.mComposerPolygon)
# style
props = {}
props["color"] = "green"
props["style"] = "solid"
props["style_border"] = "solid"
props["color_border"] = "black"
props["width_border"] = "10.0"
props["joinstyle"] = "miter"
style = QgsFillSymbol.createSimple(props)
self.mComposerPolygon.setPolygonStyleSymbol(style)
def testDisplayName(self):
"""Test if displayName is valid"""
self.assertEqual(self.mComposerPolygon.displayName(), "<polygon>")
def testType(self):
"""Test if type is valid"""
self.assertEqual(
self.mComposerPolygon.type(), QgsComposerItem.ComposerPolygon)
def testDefaultStyle(self):
"""Test polygon rendering with default style."""
self.mComposerPolygon.setDisplayNodes(False)
checker = QgsCompositionChecker(
'composerpolygon_defaultstyle', self.mComposition)
checker.setControlPathPrefix("composer_polygon")
myTestResult, myMessage = checker.testComposition()
assert myTestResult, myMessage
def testDisplayNodes(self):
"""Test displayNodes method"""
self.mComposerPolygon.setDisplayNodes(True)
checker = QgsCompositionChecker(
'composerpolygon_displaynodes', self.mComposition)
checker.setControlPathPrefix("composer_polygon")
myTestResult, myMessage = checker.testComposition()
assert myTestResult, myMessage
self.mComposerPolygon.setDisplayNodes(False)
checker = QgsCompositionChecker(
'composerpolygon_defaultstyle', self.mComposition)
checker.setControlPathPrefix("composer_polygon")
myTestResult, myMessage = checker.testComposition()
assert myTestResult, myMessage
def testSelectedNode(self):
"""Test selectedNode and unselectNode methods"""
self.mComposerPolygon.setDisplayNodes(True)
self.mComposerPolygon.setSelectedNode(3)
checker = QgsCompositionChecker(
'composerpolygon_selectednode', self.mComposition)
checker.setControlPathPrefix("composer_polygon")
myTestResult, myMessage = checker.testComposition()
assert myTestResult, myMessage
self.mComposerPolygon.unselectNode()
self.mComposerPolygon.setDisplayNodes(False)
checker = QgsCompositionChecker(
'composerpolygon_defaultstyle', self.mComposition)
checker.setControlPathPrefix("composer_polygon")
myTestResult, myMessage = checker.testComposition()
assert myTestResult, myMessage
def testRemoveNode(self):
"""Test removeNode method"""
rc = self.mComposerPolygon.removeNode(100)
self.assertEqual(rc, False)
checker = QgsCompositionChecker(
'composerpolygon_defaultstyle', self.mComposition)
#.........这里部分代码省略.........