def createFormatSettings(self): s = QgsTextFormat() s.setBuffer(self.createBufferSettings()) s.setBackground(self.createBackgroundSettings()) s.setShadow(self.createShadowSettings()) s.setFont(getTestFont()) s.setNamedStyle('Roman') s.setSize(5) s.setSizeUnit(QgsUnitTypes.RenderPoints) s.setSizeMapUnitScale(QgsMapUnitScale(1, 2)) s.setColor(QColor(255, 0, 0)) s.setOpacity(0.5) s.setBlendMode(QPainter.CompositionMode_Difference) s.setLineHeight(5) return s
def checkLabeledLayerWithBlendModesCannotBeCached(self, job_type): """ any labeled layer utilising blending modes cannot be cached""" layer = QgsVectorLayer("Point?field=fldtxt:string", "layer1", "memory") labelSettings = QgsPalLayerSettings() labelSettings.fieldName = "fldtxt" layer.setLabeling(QgsVectorLayerSimpleLabeling(labelSettings)) layer.setLabelsEnabled(True) layer2 = QgsVectorLayer("Point?field=fldtxt:string", "layer2", "memory") labelSettings2 = QgsPalLayerSettings() labelSettings2.fieldName = "fldtxt" format2 = QgsTextFormat() format2.setBlendMode(QPainter.CompositionMode_SourceIn) labelSettings2.setFormat(format2) layer2.setLabeling(QgsVectorLayerSimpleLabeling(labelSettings2)) layer2.setLabelsEnabled(True) settings = QgsMapSettings() settings.setExtent(QgsRectangle(5, 25, 25, 45)) settings.setOutputSize(QSize(600, 400)) settings.setLayers([layer, layer2]) # with cache - cache should not be populated! cache = QgsMapRendererCache() job = job_type(settings) job.setCache(cache) job.start() job.waitForFinished() self.assertFalse(job.usedCachedLabels()) self.assertFalse(cache.hasCacheImage('_labels_')) self.assertTrue(job.takeLabelingResults()) # second job should also not be able to use label cache job = job_type(settings) job.setCache(cache) job.start() job.waitForFinished() # shouldn't use cache self.assertFalse(job.usedCachedLabels()) # and results should not have been cached self.assertFalse(cache.hasCacheImage('_labels_')) self.assertTrue(job.takeLabelingResults())
def checkLabeledLayerWithBlendModesCannotBeCached(self, job_type): """ any labeled layer utilising blending modes cannot be cached""" layer = QgsVectorLayer("Point?field=fldtxt:string", "layer1", "memory") labelSettings = QgsPalLayerSettings() labelSettings.fieldName = "fldtxt" layer.setLabeling(QgsVectorLayerSimpleLabeling(labelSettings)) layer2 = QgsVectorLayer("Point?field=fldtxt:string", "layer2", "memory") labelSettings2 = QgsPalLayerSettings() labelSettings2.fieldName = "fldtxt" format2 = QgsTextFormat() format2.setBlendMode(QPainter.CompositionMode_SourceIn) labelSettings2.setFormat(format2) layer2.setLabeling(QgsVectorLayerSimpleLabeling(labelSettings2)) settings = QgsMapSettings() settings.setExtent(QgsRectangle(5, 25, 25, 45)) settings.setOutputSize(QSize(600, 400)) settings.setLayers([layer, layer2]) # with cache - cache should not be populated! cache = QgsMapRendererCache() job = job_type(settings) job.setCache(cache) job.start() job.waitForFinished() self.assertFalse(job.usedCachedLabels()) self.assertFalse(cache.hasCacheImage('_labels_')) self.assertTrue(job.takeLabelingResults()) # second job should also not be able to use label cache job = job_type(settings) job.setCache(cache) job.start() job.waitForFinished() # shouldn't use cache self.assertFalse(job.usedCachedLabels()) # and results should not have been cached self.assertFalse(cache.hasCacheImage('_labels_')) self.assertTrue(job.takeLabelingResults())
def createFormatSettings(self): s = QgsTextFormat() s.setBuffer(self.createBufferSettings()) s.setMask(self.createMaskSettings()) s.setBackground(self.createBackgroundSettings()) s.setShadow(self.createShadowSettings()) font = getTestFont() font.setKerning(False) s.setFont(font) s.setNamedStyle('Roman') s.setSize(5) s.setSizeUnit(QgsUnitTypes.RenderPoints) s.setSizeMapUnitScale(QgsMapUnitScale(1, 2)) s.setColor(QColor(255, 0, 0)) s.setOpacity(0.5) s.setBlendMode(QPainter.CompositionMode_Difference) s.setLineHeight(5) s.setOrientation(QgsTextFormat.VerticalOrientation) s.setPreviewBackgroundColor(QColor(100, 150, 200)) return s