Beispiel #1
0
 def getSizeFromCmnd(self, sizeinfo):
     '''
     Returns a QSizeF based on the information in the dictionary
     sizeinfo.  Recognized keys are "width" and "height", and
     correspond to those float values in the QSizeF.  Values not
     given in sizeinfo are assigned as zero in the returned QSizeF.
     '''
     myrect = QSizeF(0.0, 0.0)
     try:
         myrect.setWidth(float(sizeinfo["width"]))
     except KeyError:
         pass
     try:
         myrect.setHeight(float(sizeinfo["height"]))
     except KeyError:
         pass
     return myrect
    def wplaceAnnotationsButton_click(self):
        annotations = self.getSelectedAnnotations()
        for anno in annotations:
            annoData = anno.data(1)
            annotation = QgsTextAnnotationItem(self.iface.mapCanvas())

            #Make data accessible from annotation
            annotation.setData(1, annoData)

            doc = annotation.document()
            #"layer": self.getLayer(),
            #"srid": crs.postgisSrid(),
            #"label":  label[0:256] ,

            #"content": annotation.document().toHtml().replace("'","''"),
            doc.setHtml(annoData.get('content', None))
            annotation.setDocument(doc)

            #"frame_color":annotation.frameColor().name(),
            color = QColor()
            color.setNamedColor(annoData.get('frame_color'))
            annotation.setFrameColor(color)

            #"bg_color": annotation.frameBackgroundColor().name(),
            color = QColor()
            color.setNamedColor(annoData.get('bg_color'))
            annotation.setFrameBackgroundColor(color)

            #"frame_width": frame_size.width(),
            #"frame_height": frame_size.height(),
            size = QSizeF()
            size.setWidth(annoData.get('frame_width'))
            size.setHeight(annoData.get('frame_height'))
            annotation.setFrameSize(size)

            #"frame_border_width": annotation.frameBorderWidth(),
            width = float(annoData.get('frame_border_width'))
            annotation.setFrameBorderWidth(width)

            #"map_position_x": map_position_x,
            #"map_position_y": map_position_y,
            map_position_x = float(annoData.get('map_position_x'))
            map_position_y = float(annoData.get('map_position_y'))
            annotation.setMapPosition(QgsPoint(map_position_x, map_position_y))

            #"offset_x": ref_offset.x(),
            #"offset_y": ref_offset.y(),
            offset_x = float(annoData.get('offset_x'))
            offset_y = float(annoData.get('offset_y'))
            annotation.setOffsetFromReferencePoint(QPointF(offset_x, offset_y))

            #"marker_symbol": json.dumps(self.dumpMarkerSymbol(marker))
            marker_symbol = annoData.get('marker_symbol')

            new_marker_symbol = QgsMarkerSymbolV2()
            #'color':marker.color().name(),
            color = QColor()
            color.setNamedColor(marker_symbol.get('color'))
            new_marker_symbol.setColor(color)

            #'alpha':marker.alpha(),
            alpha = float(marker_symbol.get('alpha'))
            new_marker_symbol.setAlpha(alpha)

            #'output_unit': marker.outputUnit(),
            output_unit = marker_symbol.get('output_unit')
            new_marker_symbol.setOutputUnit(output_unit)

            #'angle': marker.angle(),
            angle = float(marker_symbol.get('angle'))
            new_marker_symbol.setAngle(angle)

            #'size': marker.size(),
            size = float(marker_symbol.get('size'))
            new_marker_symbol.setSize(size)

            #'size_unit': marker.sizeUnit(),
            size_unit = marker_symbol.get('size_unit')
            new_marker_symbol.setSizeUnit(size_unit)

            #'symbol_layers': [self.dumpSymbolLayer(layer) for layer in marker.symbolLayers()]

            for properties in marker_symbol.get('symbol_layers'):
                print properties
                #properties = json.loads(properties)
                new_symbol_layer = QgsSimpleMarkerSymbolLayerV2()
                new_symbol_layer.restoreDataDefinedProperties(properties)
                new_marker_symbol.appendSymbolLayer(new_symbol_layer)

            annotation.setMarkerSymbol(new_marker_symbol)