def testRunChecks(self): registry = QgsValidityCheckRegistry() res1 = QgsValidityCheckResult() res1.type = QgsValidityCheckResult.Warning res1.title = 'test' res1.detailedDescription = 'blah blah' c1 = TestCheck('c1', 'my check', 1, [res1]) registry.addCheck(c1) res2 = QgsValidityCheckResult() res2.type = QgsValidityCheckResult.Critical res2.title = 'test2' res2.detailedDescription = 'blah blah2' c2 = TestCheck('c2', 'my check2', 2, [res2]) registry.addCheck(c2) res3 = QgsValidityCheckResult() res3.type = QgsValidityCheckResult.Warning res3.title = 'test3' res3.detailedDescription = 'blah blah3' res4 = QgsValidityCheckResult() res4.type = QgsValidityCheckResult.Warning res4.title = 'test4' res4.detailedDescription = 'blah blah4' c3 = TestCheck('c3', 'my check3', 1, [res3, res4]) registry.addCheck(c3) context = TestContext() feedback = QgsFeedback() self.assertFalse(registry.runChecks(0, context, feedback)) self.assertEqual( [r.type for r in registry.runChecks(1, context, feedback)], [ QgsValidityCheckResult.Warning, QgsValidityCheckResult.Warning, QgsValidityCheckResult.Warning ]) self.assertEqual( [r.title for r in registry.runChecks(1, context, feedback)], ['test', 'test3', 'test4']) self.assertEqual([ r.detailedDescription for r in registry.runChecks(1, context, feedback) ], ['blah blah', 'blah blah3', 'blah blah4']) self.assertEqual( [r.type for r in registry.runChecks(2, context, feedback)], [QgsValidityCheckResult.Critical]) self.assertEqual( [r.title for r in registry.runChecks(2, context, feedback)], ['test2']) self.assertEqual([ r.detailedDescription for r in registry.runChecks(2, context, feedback) ], ['blah blah2'])
def testRunChecks(self): registry = QgsValidityCheckRegistry() res1 = QgsValidityCheckResult() res1.type = QgsValidityCheckResult.Warning res1.title = 'test' res1.detailedDescription = 'blah blah' c1 = TestCheck('c1', 'my check', 1, [res1]) registry.addCheck(c1) res2 = QgsValidityCheckResult() res2.type = QgsValidityCheckResult.Critical res2.title = 'test2' res2.detailedDescription = 'blah blah2' c2 = TestCheck('c2', 'my check2', 2, [res2]) registry.addCheck(c2) res3 = QgsValidityCheckResult() res3.type = QgsValidityCheckResult.Warning res3.title = 'test3' res3.detailedDescription = 'blah blah3' res4 = QgsValidityCheckResult() res4.type = QgsValidityCheckResult.Warning res4.title = 'test4' res4.detailedDescription = 'blah blah4' c3 = TestCheck('c3', 'my check3', 1, [res3, res4]) registry.addCheck(c3) context = TestContext() feedback = QgsFeedback() self.assertFalse(registry.runChecks(0, context, feedback)) self.assertEqual([r.type for r in registry.runChecks(1, context, feedback)], [QgsValidityCheckResult.Warning, QgsValidityCheckResult.Warning, QgsValidityCheckResult.Warning]) self.assertEqual([r.title for r in registry.runChecks(1, context, feedback)], ['test', 'test3', 'test4']) self.assertEqual([r.detailedDescription for r in registry.runChecks(1, context, feedback)], ['blah blah', 'blah blah3', 'blah blah4']) self.assertEqual([r.type for r in registry.runChecks(2, context, feedback)], [QgsValidityCheckResult.Critical]) self.assertEqual([r.title for r in registry.runChecks(2, context, feedback)], ['test2']) self.assertEqual([r.detailedDescription for r in registry.runChecks(2, context, feedback)], ['blah blah2'])
def layout_map_rasterized_check(context, feedback): layout = context.layout results = [] if layout.customProperty('rasterize', False): res = QgsValidityCheckResult() res.type = QgsValidityCheckResult.Warning res.title = 'Layout export will be rasterized' res.detailedDescription = 'The layout is set to be completely rasterized, even when exporting to vector formats such as PDF or SVG.' results.append(res) return results
def testModel(self): res1 = QgsValidityCheckResult() res1.type = QgsValidityCheckResult.Warning res1.title = 'test' res1.detailedDescription = 'blah blah' res2 = QgsValidityCheckResult() res2.type = QgsValidityCheckResult.Critical res2.title = 'test2' res2.detailedDescription = 'blah blah2' res3 = QgsValidityCheckResult() res3.type = QgsValidityCheckResult.Warning res3.title = 'test3' res3.detailedDescription = 'blah blah3' res4 = QgsValidityCheckResult() res4.type = QgsValidityCheckResult.Warning res4.title = 'test4' res4.detailedDescription = 'blah blah4' model = QgsValidityCheckResultsModel([]) self.assertEqual(model.rowCount(), 0) self.assertFalse(model.data(model.index(0, 0, QModelIndex()), Qt.DisplayRole)) self.assertFalse(model.data(model.index(-1, 0, QModelIndex()), Qt.DisplayRole)) self.assertFalse(model.data(model.index(1, 0, QModelIndex()), Qt.DisplayRole)) model = QgsValidityCheckResultsModel([res1, res2, res3, res4]) self.assertEqual(model.rowCount(), 4) self.assertFalse(model.data(model.index(-1, 0, QModelIndex()), Qt.DisplayRole)) self.assertEqual(model.data(model.index(0, 0, QModelIndex()), Qt.DisplayRole), 'test') self.assertEqual(model.data(model.index(1, 0, QModelIndex()), Qt.DisplayRole), 'test2') self.assertEqual(model.data(model.index(2, 0, QModelIndex()), Qt.DisplayRole), 'test3') self.assertEqual(model.data(model.index(3, 0, QModelIndex()), Qt.DisplayRole), 'test4') self.assertFalse(model.data(model.index(4, 0, QModelIndex()), Qt.DisplayRole)) self.assertEqual(model.data(model.index(0, 0, QModelIndex()), QgsValidityCheckResultsModel.DescriptionRole), 'blah blah') self.assertEqual(model.data(model.index(1, 0, QModelIndex()), QgsValidityCheckResultsModel.DescriptionRole), 'blah blah2') self.assertEqual(model.data(model.index(2, 0, QModelIndex()), QgsValidityCheckResultsModel.DescriptionRole), 'blah blah3') self.assertEqual(model.data(model.index(3, 0, QModelIndex()), QgsValidityCheckResultsModel.DescriptionRole), 'blah blah4')
def layout_item_rasterized_check(context, feedback): layout = context.layout results = [] for i in layout.items(): if isinstance(i, QgsLayoutItem): if i.requiresRasterization(): res = QgsValidityCheckResult() res.type = QgsValidityCheckResult.Warning res.title = 'Layout export will be rasterized' res.detailedDescription = 'The item {} uses settings (e.g. blending modes) which require the whole layout to be rasterized during export. This ' \ 'will degrade the quality of the output.'.format( i.displayName().replace('<', '<')) results.append(res) elif i.containsAdvancedEffects(): res = QgsValidityCheckResult() res.type = QgsValidityCheckResult.Warning res.title = 'Item will be rasterized' res.detailedDescription = 'The item {} uses settings (e.g. transparency) which require this item to be rasterized during export. This ' \ 'will degrade the quality of the output.'.format( i.displayName().replace('<', '<')) results.append(res) return results
def layout_map_unplaced_labels_check(context, feedback): layout = context.layout results = [] for i in layout.items(): if isinstance(i, QgsLayoutItemMap ) and i.mapFlags() & QgsLayoutItemMap.ShowUnplacedLabels: res = QgsValidityCheckResult() res.type = QgsValidityCheckResult.Warning res.title = 'Unplaced labels are visible' res.detailedDescription = 'The map item {} currently has unplaced labels shown. This setting is only suitable for draft exports.'.format( i.displayName()) results.append(res) return results
def my_check2(context, feedback): res = QgsValidityCheckResult() res.type = QgsValidityCheckResult.Warning res.title = 'test' res.detailedDescription = 'blah blah' return [res]