示例#1
0
    def getAdjustedText(self, text):
        font = QFont('Verdana', 8)
        fm = QFontMetricsF(font)
        w = fm.width(text)
        if w < self.BOX_WIDTH - 25 - FlatButtonGraphicItem.WIDTH:
            return text

        text = text[0:-3] + '...'
        w = fm.width(text)
        while w > self.BOX_WIDTH - 25 - FlatButtonGraphicItem.WIDTH:
            text = text[0:-4] + '...'
            w = fm.width(text)
        return text
示例#2
0
    def getAdjustedText(self, text):
        font = QFont('Verdana', 8)
        fm = QFontMetricsF(font)
        w = fm.width(text)
        if w < self.BOX_WIDTH - 25 - FlatButtonGraphicItem.WIDTH:
            return text

        text = text[0:-3] + '...'
        w = fm.width(text)
        while w > self.BOX_WIDTH - 25 - FlatButtonGraphicItem.WIDTH:
            text = text[0:-4] + '...'
            w = fm.width(text)
        return text
示例#3
0
    def drawMarkings(self, painter):
        painter.save()
        painter.translate(self.width() / 2, self.height() / 2)
        scale = min((self.width() - self._margins) / 120.0,
                    (self.height() - self._margins) / 120.0)
        painter.scale(scale, scale)

        font = QFont(self.font())
        font.setPixelSize(10)
        metrics = QFontMetricsF(font)

        painter.setFont(font)
        painter.setPen(self.palette().color(QPalette.Shadow))

        i = 0
        while i < 360:
            if i % 45 == 0:
                painter.drawLine(0, -40, 0, -50)
                painter.drawText(int(-metrics.width(self._pointText[i]) / 2),
                                 -52, self._pointText[i])
            else:
                painter.drawLine(0, -45, 0, -50)
            painter.rotate(15)
            i += 15
        painter.restore()
示例#4
0
 def getLinkPointForOutput(self, outputIndex):
     if isinstance(self.element, Algorithm) and self.element.algorithm.outputs:
         outputIndex = (outputIndex if not self.element.outputsFolded else -1)
         text = self.getAdjustedText(self.element.algorithm.outputs[outputIndex].description)
         font = QFont('Verdana', 8)
         fm = QFontMetricsF(font)
         w = fm.width(text)
         h = fm.height() * 1.2 * (outputIndex + 1) + fm.height() / 2.0
         y = h + ModelerGraphicItem.BOX_HEIGHT / 2.0 + 5
         x = (-ModelerGraphicItem.BOX_WIDTH / 2 + 33 + w
              + 5 if not self.element.outputsFolded else 10)
         return QPointF(x, y)
     else:
         return QPointF(0, 0)
示例#5
0
 def getLinkPointForOutput(self, outputIndex):
     if isinstance(self.element, Algorithm) and self.element.algorithm.outputs:
         outputIndex = (outputIndex if not self.element.outputsFolded else -1)
         text = self.getAdjustedText(self.element.algorithm.outputs[outputIndex].description)
         font = QFont('Verdana', 8)
         fm = QFontMetricsF(font)
         w = fm.width(text)
         h = fm.height() * 1.2 * (outputIndex + 1) + fm.height() / 2.0
         y = h + ModelerGraphicItem.BOX_HEIGHT / 2.0 + 5
         x = (-ModelerGraphicItem.BOX_WIDTH / 2 + 33 + w
              + 5 if not self.element.outputsFolded else 10)
         return QPointF(x, y)
     else:
         return QPointF(0, 0)
示例#6
0
 def getLinkPointForOutput(self, outputIndex):
     if isinstance(self.element, QgsProcessingModelChildAlgorithm) and self.element.algorithm().outputDefinitions():
         outputIndex = (outputIndex if not self.element.outputsCollapsed() else -1)
         text = self.getAdjustedText(self.element.algorithm().outputDefinitions()[outputIndex].description())
         font = QFont('Verdana', 8)
         font.setPixelSize(12)
         fm = QFontMetricsF(font)
         w = fm.width(text)
         h = fm.height() * 1.2 * (outputIndex + 1) + fm.height() / 2.0
         y = h + ModelerGraphicItem.BOX_HEIGHT / 2.0 + 5
         x = (-ModelerGraphicItem.BOX_WIDTH / 2 + 33 + w + 5
              if not self.element.outputsCollapsed()
              else 10)
         return QPointF(x, y)
     else:
         return QPointF(0, 0)
示例#7
0
 def getLinkPointForOutput(self, outputIndex):
     if isinstance(self.element, QgsProcessingModelChildAlgorithm) and self.element.algorithm().outputDefinitions():
         outputIndex = (outputIndex if not self.element.outputsCollapsed() else -1)
         text = self.getAdjustedText(self.element.algorithm().outputDefinitions()[outputIndex].description())
         font = QFont('Verdana', 8)
         font.setPixelSize(12)
         fm = QFontMetricsF(font)
         w = fm.width(text)
         h = fm.height() * 1.2 * (outputIndex + 1) + fm.height() / 2.0
         y = h + ModelerGraphicItem.BOX_HEIGHT / 2.0 + 5
         x = (-ModelerGraphicItem.BOX_WIDTH / 2 + 33 + w + 5
              if not self.element.outputsCollapsed()
              else 10)
         return QPointF(x, y)
     else:
         return QPointF(0, 0)
示例#8
0
    def newItemAddedToLayout(self, frame):
        item = frame.multiFrame()
        item.setMap(None)
        text = 'Choose the data source of the table and ' \
               'the link columns in the STDM item properties.'
        table_text = QCoreApplication.translate('StdmItems', text)
        default_column = QgsLayoutTableColumn(table_text)

        item.setColumns([default_column])
        item.recalculateFrameSizes()

        fm = QFontMetricsF(item.headerTextFormat().font())
        table_width_layout_units = fm.width(text + '  ')

        size = frame.sizeWithUnits()
        size.setWidth(item.layout().convertFromLayoutUnits(
            table_width_layout_units, size.units()).length())
        frame.attemptResize(size)

        # Set ID to match UUID
        frame.setId(frame.uuid())
示例#9
0
    def set_symbol(self, symbol_image: QImage):
        self.pixmap = QPixmap.fromImage(symbol_image)
        fm = QFontMetricsF(self.marker_font)

        # set item size
        self.item_size.setWidth(self.pixmap.width() + fm.width("360"))

        pixmap_height = self.pixmap.height()
        font_height = fm.height()
        if pixmap_height >= font_height:
            self.item_size.setHeight(self.pixmap.height())
        else:
            self.item_size.setHeight(fm.height())

        half_item_width = self.pixmap.width() / 2.0
        self.arrow_path = QPainterPath()
        self.arrow_path.moveTo(half_item_width, pixmap_height)
        self.arrow_path.lineTo(half_item_width, 0)
        self.arrow_path.moveTo(self.pixmap.width() * 0.25,
                               pixmap_height * 0.25)
        self.arrow_path.lineTo(half_item_width, 0)
        self.arrow_path.lineTo(self.pixmap.width() * 0.75,
                               pixmap_height * 0.25)
示例#10
0
文件: qgis.py 项目: zyxgis/slyr
def append_CharacterMarkerSymbolLayerAsSvg(symbol, layer, context: Context):  # pylint: disable=too-many-locals
    """
    Appends a CharacterMarkerSymbolLayer to a symbol, rendering the font character
    to an SVG file.
    """
    font_family = layer.font
    character = chr(layer.unicode)
    color = symbol_color_to_qcolor(layer.color)
    angle = convert_angle(layer.angle)

    font = QFont(font_family)
    font.setPointSizeF(layer.size)

    # Using the rect of a painter path gives better results then using font metrics
    path = QPainterPath()
    path.setFillRule(Qt.WindingFill)
    path.addText(0, 0, font, character)

    rect = path.boundingRect()

    font_bounding_rect = QFontMetricsF(font).boundingRect(character)

    # adjust size -- marker size in esri is the font size, svg marker size in qgis is the svg rect size
    scale = rect.width() / font_bounding_rect.width()

    gen = QSvgGenerator()
    svg_path = symbol_name_to_filename(context.symbol_name,
                                       context.picture_folder, 'svg')
    gen.setFileName(svg_path)
    gen.setViewBox(rect)

    painter = QPainter(gen)
    painter.setFont(font)

    # todo -- size!

    if context.parameterise_svg:
        painter.setBrush(QBrush(QColor(255, 0, 0)))
    else:
        painter.setBrush(QBrush(color))
    painter.setPen(Qt.NoPen)
    painter.drawPath(path)
    painter.end()

    if context.parameterise_svg:
        with open(svg_path, 'r') as f:
            t = f.read()

        t = t.replace('#ff0000', 'param(fill)')
        t = t.replace('fill-opacity="1" ',
                      'fill-opacity="param(fill-opacity)"')
        t = t.replace(
            'stroke="none"',
            'stroke="param(outline)" stroke-opacity="param(outline-opacity) 1" stroke-width="param(outline-width) 0"'
        )
        with open(svg_path, 'w') as f:
            f.write(t)

    svg_path = context.convert_path(svg_path)

    out = QgsSvgMarkerSymbolLayer(svg_path)

    out.setSizeUnit(context.units)
    out.setSize(context.convert_size(scale * rect.width()))
    out.setAngle(angle)
    out.setFillColor(color)
    out.setStrokeWidth(0)

    out.setEnabled(layer.enabled)
    out.setLocked(layer.locked)

    out.setOffset(
        adjust_offset_for_rotation(
            QPointF(context.convert_size(layer.x_offset),
                    -context.convert_size(layer.y_offset)), layer.angle))
    out.setOffsetUnit(context.units)

    symbol.appendSymbolLayer(out)