本文整理汇总了Python中qgis.core.QgsStyleModel.headerData方法的典型用法代码示例。如果您正苦于以下问题:Python QgsStyleModel.headerData方法的具体用法?Python QgsStyleModel.headerData怎么用?Python QgsStyleModel.headerData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsStyleModel
的用法示例。
在下文中一共展示了QgsStyleModel.headerData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_style_with_symbols
# 需要导入模块: from qgis.core import QgsStyleModel [as 别名]
# 或者: from qgis.core.QgsStyleModel import headerData [as 别名]
def test_style_with_symbols(self):
style = QgsStyle()
style.createMemoryDatabase()
# style with only symbols
symbol_a = createMarkerSymbol()
symbol_a.setColor(QColor(255, 10, 10))
self.assertTrue(style.addSymbol('a', symbol_a, True))
style.tagSymbol(QgsStyle.SymbolEntity, 'a', ['tag 1', 'tag 2'])
symbol_B = createMarkerSymbol()
symbol_B.setColor(QColor(10, 255, 10))
self.assertTrue(style.addSymbol('B ', symbol_B, True))
symbol_b = createFillSymbol()
symbol_b.setColor(QColor(10, 255, 10))
self.assertTrue(style.addSymbol('b', symbol_b, True))
symbol_C = createLineSymbol()
symbol_C.setColor(QColor(10, 255, 10))
self.assertTrue(style.addSymbol('C', symbol_C, True))
style.tagSymbol(QgsStyle.SymbolEntity, 'C', ['tag 3'])
symbol_C = createMarkerSymbol()
symbol_C.setColor(QColor(10, 255, 10))
self.assertTrue(style.addSymbol(' ----c/- ', symbol_C, True))
model = QgsStyleModel(style)
self.assertEqual(model.rowCount(), 5)
self.assertEqual(model.columnCount(), 2)
self.assertEqual(model.headerData(0, Qt.Horizontal), 'Name')
self.assertEqual(model.headerData(1, Qt.Horizontal), 'Tags')
self.assertTrue(model.index(0, 0).isValid())
self.assertFalse(model.index(10, 0).isValid())
self.assertFalse(model.index(0, 10).isValid())
self.assertFalse(model.parent(model.index(0, 0)).isValid())
self.assertFalse(model.flags(model.index(-1, 0)) & Qt.ItemIsEditable)
self.assertFalse(model.flags(model.index(5, 0)) & Qt.ItemIsEditable)
self.assertFalse(model.flags(model.index(0, 1)) & Qt.ItemIsEditable)
self.assertTrue(model.flags(model.index(0, 0)) & Qt.ItemIsEditable)
for role in (Qt.DisplayRole, Qt.EditRole):
self.assertIsNone(model.data(model.index(-1, 0), role))
self.assertIsNone(model.data(model.index(-1, 1), role))
self.assertEqual(model.data(model.index(0, 0), role), ' ----c/- ')
self.assertFalse(model.data(model.index(0, 1), role))
self.assertIsNone(model.data(model.index(0, 2), role))
self.assertIsNone(model.data(model.index(0, -1), role))
self.assertEqual(model.data(model.index(1, 0), role), 'B ')
self.assertFalse(model.data(model.index(1, 1), role))
self.assertEqual(model.data(model.index(2, 0), role), 'C')
self.assertEqual(model.data(model.index(2, 1), role), 'tag 3')
self.assertEqual(model.data(model.index(3, 0), role), 'a')
self.assertEqual(model.data(model.index(3, 1), role), 'tag 1, tag 2')
self.assertEqual(model.data(model.index(4, 0), role), 'b')
self.assertFalse(model.data(model.index(4, 1), role))
self.assertIsNone(model.data(model.index(5, 0), role))
self.assertIsNone(model.data(model.index(5, 1), role))
# decorations
self.assertIsNone(model.data(model.index(-1, 0), Qt.DecorationRole))
self.assertIsNone(model.data(model.index(0, 1), Qt.DecorationRole))
self.assertIsNone(model.data(model.index(5, 0), Qt.DecorationRole))
self.assertFalse(model.data(model.index(0, 0), Qt.DecorationRole).isNull())
self.assertEqual(model.data(model.index(0, 0), QgsStyleModel.TypeRole), QgsStyle.SymbolEntity)
self.assertEqual(model.data(model.index(1, 0), QgsStyleModel.TypeRole), QgsStyle.SymbolEntity)
self.assertEqual(model.data(model.index(4, 0), QgsStyleModel.TypeRole), QgsStyle.SymbolEntity)