Exemplo n.º 1
0
    def on_mPageStyleButton_clicked(self):
        if self.timeStart != 0:
            self.timeEnd = time.time()
            print self.timeEnd
            if self.timeEnd - self.timeStart <= 2:
                self.timeStart = 0
                return
        if ( not self.mComposition ):
            return

        coverageLayer = None
        # use the atlas coverage layer, if any
        if ( self.mComposition.atlasComposition().enabled() ):
            coverageLayer = self.mComposition.atlasComposition().coverageLayer()

        newSymbol = self.mComposition.pageStyleSymbol().clone()
        if ( not newSymbol ):
            newSymbol = QgsFillSymbolV2()
        d = QgsSymbolV2SelectorDialog( newSymbol, QgsStyleV2.defaultStyle(), coverageLayer, self)
        d.setExpressionContext( self.mComposition.createExpressionContext() )

        if ( d.exec_() == QDialog.Accepted ):

            self.mComposition.setPageStyleSymbol( newSymbol )
            self.updatePageStyle()
        self.timeStart = time.time()
Exemplo n.º 2
0
    def test_add_symbol_to_legend(self):
        """Test we can add a symbol to the legend."""
        layer, _ = load_layer('test_floodimpact.tif')
        map_legend = MapLegend(layer)
        symbol = QgsFillSymbolV2()
        symbol.setColor(QtGui.QColor(12, 34, 56))
        map_legend.add_symbol(
            symbol,
            minimum=0,
            # expect 2.0303 in legend
            maximum=2.02030,
            label='Foo')
        path = unique_filename(
            prefix='addSymbolToLegend',
            suffix='.png',
            dir=temp_dir('test'))
        map_legend.get_legend().save(path, 'PNG')
        LOGGER.debug(path)
        # As we have discovered, different versions of Qt and
        # OS platforms cause different output, so myControlImages is a list
        # of 'known good' renders.

        tolerance = 0  # to allow for version number changes in disclaimer
        flag, message = check_images(
            'addSymbolToLegend', path, tolerance)
        message += (
            '\nWe want these images to match, if they do already, copy the '
            'test image generated to create a new control image.')
        self.assertTrue(flag, message)
def validatedDefaultSymbol(geometryType):
    symbol = QgsSymbolV2.defaultSymbol(geometryType)
    if symbol is None:
        if geometryType == QGis.Point:
            symbol = QgsMarkerSymbolV2()
        elif geometryType == QGis.Line:
            symbol = QgsLineSymbolV2()
        elif geometryType == QGis.Polygon:
            symbol = QgsFillSymbolV2()
    return symbol
Exemplo n.º 4
0
def get_default_symbol( geom_type):
    symbol = QgsSymbolV2.defaultSymbol(geom_type)
    if symbol is None:
        if geom_type == QGis.Point:
            symbol = QgsMarkerSymbolV2()
        elif geom_type == QGis.Line:
            symbol = QgsLineSymbolV2()
        elif geom_type == QGis.Polygon:
            symbol = QgsFillSymbolV2()
    return symbol
Exemplo n.º 5
0
 def _validated_default_symbol(self, geometryType):
     """Validates that the symbol is of the correct type, (point, line or
     polygon and then returning a Qgis type symbol)"""
     symbol = QgsSymbolV2.defaultSymbol(geometryType)
     if symbol is None:
         if geometryType == QGis.Point:
             symbol = QgsMarkerSymbolV2()
         elif geometryType == QGis.Line:
             symbol = QgsLineSymbolV2()
         elif geometryType == QGis.Polygon:
             symbol = QgsFillSymbolV2()
     return symbol
Exemplo n.º 6
0
 def prepare_renderer(levels, inter_time, lenpoly):
     cats = [('{} - {} min'.format(levels[i] - inter_time, levels[i]),
              levels[i] - inter_time, levels[i])
             for i in xrange(lenpoly)]  # label, lower bound, upper bound
     colors = get_isochrones_colors(len(levels))
     ranges = []
     for ix, cat in enumerate(cats):
         symbol = QgsFillSymbolV2()
         symbol.setColor(QtGui.QColor(colors[ix]))
         rng = QgsRendererRangeV2(cat[1], cat[2], symbol, cat[0])
         ranges.append(rng)
     expression = 'max'
     return QgsGraduatedSymbolRendererV2(expression, ranges)
Exemplo n.º 7
0
raster_legend = atlas_legend.modelV2().rootGroup().addLayer(raster_layer)
QgsLegendRenderer.setNodeLegendStyle(raster_legend, QgsComposerLegendStyle.Hidden)
atlas_legend.updateLegend()
# atlas_legend.refreshLayerLegend(raster_legend)
stats_table = composition.getComposerItemById("stats_table").multiFrame()
stats_table.setContentMode(QgsComposerHtml.ManualHtml)
title_label = composition.getComposerItemById("title_label")
title_text = title_label.text()
description_label = composition.getComposerItemById("description_label")
description_text = description_label.text()

# Set a rule based style to highlight the atlas feature
normal_style = QgsFillSymbolV2().createSimple(
    {
        "color": "#000000",
        "color_border": "#000000",
        "width_border": "0.25",
        "style": "no",
    }
)
highlight_style = QgsFillSymbolV2().createSimple(
    {
        "color": "#000000",
        "color_border": "#ff0000",
        "width_border": "0.85",
        "style": "no",
    }
)
highlight_rule = QgsRuleBasedRendererV2.Rule(highlight_style)
highlight_rule.setFilterExpression("$id = @atlas_featureid")
highlight_renderer = QgsRuleBasedRendererV2(normal_style)
highlight_renderer.rootRule().appendChild(highlight_rule)