def test_filter_proxy(self): style = QgsStyle() style.createMemoryDatabase() 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('BB', 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('another', symbol_C, True)) ramp_a = QgsLimitedRandomColorRamp(5) self.assertTrue(style.addColorRamp('ramp a', ramp_a, True)) style.tagSymbol(QgsStyle.ColorrampEntity, 'ramp a', ['tag 1', 'tag 2']) symbol_B = QgsLimitedRandomColorRamp() self.assertTrue(style.addColorRamp('ramp BB', symbol_B, True)) symbol_b = QgsLimitedRandomColorRamp() self.assertTrue(style.addColorRamp('ramp c', symbol_b, True)) model = QgsStyleProxyModel(style) self.assertEqual(model.rowCount(), 8) # filter string model.setFilterString('xx') self.assertEqual(model.filterString(), 'xx') self.assertEqual(model.rowCount(), 0) model.setFilterString('b') self.assertEqual(model.rowCount(), 3) self.assertEqual(model.data(model.index(0, 0)), 'b') self.assertEqual(model.data(model.index(1, 0)), 'BB') self.assertEqual(model.data(model.index(2, 0)), 'ramp BB') model.setFilterString('bb') self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), 'BB') self.assertEqual(model.data(model.index(1, 0)), 'ramp BB') model.setFilterString('tag 1') self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), 'a') self.assertEqual(model.data(model.index(1, 0)), 'ramp a') model.setFilterString('TAG 1') self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), 'a') self.assertEqual(model.data(model.index(1, 0)), 'ramp a') model.setFilterString('ram b') self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'ramp BB') model.setFilterString('ta ram') # match ta -> "tag 1", ram -> "ramp a" self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'ramp a') model.setFilterString('') self.assertEqual(model.rowCount(), 8) # entity type model.setEntityFilter(QgsStyle.SymbolEntity) self.assertEqual(model.rowCount(), 8) model.setEntityFilter(QgsStyle.ColorrampEntity) self.assertEqual(model.rowCount(), 8) model.setEntityFilterEnabled(True) self.assertEqual(model.rowCount(), 3) self.assertEqual(model.data(model.index(0, 0)), 'ramp a') self.assertEqual(model.data(model.index(1, 0)), 'ramp BB') self.assertEqual(model.data(model.index(2, 0)), 'ramp c') model.setFilterString('BB') self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'ramp BB') model.setFilterString('') model.setEntityFilter(QgsStyle.SymbolEntity) self.assertEqual(model.rowCount(), 5) self.assertEqual(model.data(model.index(0, 0)), 'a') self.assertEqual(model.data(model.index(1, 0)), 'another') self.assertEqual(model.data(model.index(2, 0)), 'b') self.assertEqual(model.data(model.index(3, 0)), 'BB') self.assertEqual(model.data(model.index(4, 0)), 'C') model.setFilterString('ot') self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'another') model.setFilterString('') model.setEntityFilterEnabled(False) self.assertEqual(model.rowCount(), 8) # symbol type filter model.setSymbolType(QgsSymbol.Line) self.assertEqual(model.rowCount(), 8) model.setSymbolType(QgsSymbol.Marker) self.assertEqual(model.rowCount(), 8) model.setSymbolTypeFilterEnabled(True) self.assertEqual(model.rowCount(), 6) self.assertEqual(model.data(model.index(0, 0)), 'a') self.assertEqual(model.data(model.index(1, 0)), 'another') self.assertEqual(model.data(model.index(2, 0)), 'BB') self.assertEqual(model.data(model.index(3, 0)), 'ramp a') self.assertEqual(model.data(model.index(4, 0)), 'ramp BB') model.setEntityFilterEnabled(True) self.assertEqual(model.rowCount(), 3) self.assertEqual(model.data(model.index(0, 0)), 'a') self.assertEqual(model.data(model.index(1, 0)), 'another') self.assertEqual(model.data(model.index(2, 0)), 'BB') model.setFilterString('oth') self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'another') model.setEntityFilterEnabled(False) self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'another') model.setEntityFilterEnabled(True) model.setFilterString('') model.setSymbolType(QgsSymbol.Line) self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'C') model.setSymbolType(QgsSymbol.Fill) self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'b') model.setSymbolTypeFilterEnabled(False) model.setEntityFilterEnabled(False) self.assertEqual(model.rowCount(), 8) # tag filter self.assertEqual(model.tagId(), -1) tag_1_id = style.tagId('tag 1') tag_3_id = style.tagId('tag 3') model.setTagId(tag_1_id) self.assertEqual(model.tagId(), tag_1_id) self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), 'a') self.assertEqual(model.data(model.index(1, 0)), 'ramp a') model.setEntityFilterEnabled(True) model.setEntityFilter(QgsStyle.ColorrampEntity) self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'ramp a') model.setEntityFilterEnabled(False) model.setFilterString('ra') self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'ramp a') model.setEntityFilterEnabled(False) model.setFilterString('') model.setTagId(-1) self.assertEqual(model.rowCount(), 8) model.setTagId(tag_3_id) self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'C') style.tagSymbol(QgsStyle.ColorrampEntity, 'ramp c', ['tag 3']) self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), 'C') self.assertEqual(model.data(model.index(1, 0)), 'ramp c') style.detagSymbol(QgsStyle.ColorrampEntity, 'ramp c') self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'C') model.setTagId(-1) self.assertEqual(model.rowCount(), 8) # favorite filter style.addFavorite(QgsStyle.ColorrampEntity, 'ramp c') style.addFavorite(QgsStyle.SymbolEntity, 'another') self.assertEqual(model.favoritesOnly(), False) model.setFavoritesOnly(True) self.assertEqual(model.favoritesOnly(), True) self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), 'another') self.assertEqual(model.data(model.index(1, 0)), 'ramp c') model.setEntityFilterEnabled(True) model.setEntityFilter(QgsStyle.ColorrampEntity) self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'ramp c') model.setEntityFilterEnabled(False) model.setFilterString('er') self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'another') model.setEntityFilterEnabled(False) model.setFilterString('') self.assertEqual(model.rowCount(), 2) style.addFavorite(QgsStyle.ColorrampEntity, 'ramp a') self.assertEqual(model.rowCount(), 3) self.assertEqual(model.data(model.index(0, 0)), 'another') self.assertEqual(model.data(model.index(1, 0)), 'ramp a') self.assertEqual(model.data(model.index(2, 0)), 'ramp c') style.removeFavorite(QgsStyle.ColorrampEntity, 'ramp a') self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), 'another') self.assertEqual(model.data(model.index(1, 0)), 'ramp c') style.addFavorite(QgsStyle.SymbolEntity, 'BB') self.assertEqual(model.rowCount(), 3) self.assertEqual(model.data(model.index(0, 0)), 'another') self.assertEqual(model.data(model.index(1, 0)), 'BB') self.assertEqual(model.data(model.index(2, 0)), 'ramp c') style.removeFavorite(QgsStyle.SymbolEntity, 'another') self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), 'BB') self.assertEqual(model.data(model.index(1, 0)), 'ramp c') model.setFavoritesOnly(False) self.assertEqual(model.rowCount(), 8) # smart group filter style.addSmartgroup('smart', 'AND', ['tag 3'], [], ['c'], []) self.assertEqual(model.smartGroupId(), -1) model.setSmartGroupId(1) self.assertEqual(model.smartGroupId(), 1) self.assertEqual(model.rowCount(), 1) self.assertEqual(model.data(model.index(0, 0)), 'C') style.addSmartgroup('smart', 'OR', ['tag 3'], [], ['c'], []) model.setSmartGroupId(2) self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), 'C') self.assertEqual(model.data(model.index(1, 0)), 'ramp c') style.tagSymbol(QgsStyle.SymbolEntity, 'a', ['tag 3']) self.assertEqual(model.rowCount(), 3) self.assertEqual(model.data(model.index(0, 0)), 'a') self.assertEqual(model.data(model.index(1, 0)), 'C') self.assertEqual(model.data(model.index(2, 0)), 'ramp c') style.renameColorRamp('ramp c', 'x') self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), 'a') self.assertEqual(model.data(model.index(1, 0)), 'C') model.setSmartGroupId(-1) self.assertEqual(model.rowCount(), 8)