예제 #1
0
    def initLabelCombo(self, layer, ids):

        values = []
        for item in ids:
            uvals = layer.uniqueValues(item)
            # I don't want a list of lists but a flat list, that's why I'm doing this
            for val in uvals:
                if type(val) is unicode:
                    if uf.isNumeric(val) == False:
                        if any(char.isdigit() for char in val) == False:
                            values.append(val)
        values = sorted(set(values))

        ## initialize color list
        self.initColors(values)

        self.dock.labelCombo.clear()
        # self.dock.labelCombo.addItems(values)

        for i, item in enumerate(self.valColTuple):
            pixmap = QPixmap(16, 16)
            pixmap.fill(item[1])
            # self.dock.labelCombo.addItem(item[0])
            self.dock.labelCombo.insertItem(i, QIcon(pixmap), item[0])

        #set the currently selected label (for the first time)
        self.labelComboChanged()
예제 #2
0
def createCompoundThumbnail(_bboxes, thumbnails):
    bboxes = []
    transform = QgsCoordinateTransform(
        QgsCoordinateReferenceSystem("EPSG:4326"),
        QgsCoordinateReferenceSystem("EPSG:3857"),
        QgsProject.instance(),
    )
    for box in _bboxes:
        rect4326 = qgsgeometry_from_geojson(box).boundingBox()
        rect = transform.transformBoundingBox(rect4326)
        bboxes.append([
            rect.xMinimum(),
            rect.yMinimum(),
            rect.xMaximum(),
            rect.yMaximum()
        ])
    globalbox = (
        min([v[0] for v in bboxes]),
        min([v[1] for v in bboxes]),
        max([v[2] for v in bboxes]),
        max([v[3] for v in bboxes]),
    )
    SIZE = 256
    globalwidth = globalbox[2] - globalbox[0]
    globalheight = globalbox[3] - globalbox[1]
    pixmap = QPixmap(SIZE, SIZE)
    pixmap.fill(Qt.transparent)
    painter = QPainter(pixmap)
    try:
        for i, thumbnail in enumerate(thumbnails):
            box = bboxes[i]
            width = box[2] - box[0]
            height = box[3] - box[1]
            if width > height:
                offsety = (width - height) / 2
                offsetx = 0
            else:
                offsetx = (height - width) / 2
                offsety = 0
            x = int((box[0] - offsetx - globalbox[0]) / globalwidth * SIZE)
            y = int((globalbox[3] - box[3] - offsety) / globalheight * SIZE)
            outputwidth = int((width + 2 * offsetx) / globalwidth * SIZE)
            outputheight = int((height + 2 * offsety) / globalheight * SIZE)
            painter.drawPixmap(x, y, outputwidth, outputheight, thumbnail)
    except Exception:
        """
        Unexpected values for bboxes might cause uneexpected errors. We just ignore
        them and return an empty image in that case
        """
    finally:
        painter.end()
    return pixmap
예제 #3
0
    def drawMagnifierOnVideo(widget, dragPos, source, painter):
        ''' Draw Magnifier on Video '''
        oldTransform = painter.transform()
        painter.setTransform(oldTransform)
        painter.setBrush(DrawToolBar.transparent_brush)
        dim = min(widget.width(), widget.height())

        magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3)
        radius = magnifierSize / 2
        ring = radius - 15
        box = QSize(magnifierSize, magnifierSize)

        center = dragPos - QPoint(0, radius)
        center += QPoint(0, radius / 2)
        corner = center - QPoint(radius, radius)

        xy = center * MAX_FACTOR - QPoint(radius, radius)

        # only set the dimension to the magnified portion
        zoomPixmap = QPixmap(box)
        zoomPixmap.fill(Qt.black)

        painter_p = QPainter(zoomPixmap)
        painter_p.setRenderHint(QPainter.HighQualityAntialiasing)
        painter_p.translate(-xy)
        painter_p.scale(MAX_FACTOR, MAX_FACTOR)
        painter_p.drawImage(widget.surface.videoRect(), source,
                            widget.surface.sourceRect())

        painter_p.end()

        clipPath = QPainterPath()
        center = QPointF(center)

        # Shape Type
        if TYPE_MAGNIFIER == 0:
            # Square
            clipPath.addRect(center.x(), center.y(), magnifierSize,
                             magnifierSize)
            clipPath.translate(-radius, -radius)
        else:
            # Circle
            clipPath.addEllipse(center, ring, ring)

        painter.setClipPath(clipPath)
        painter.drawPixmap(corner, zoomPixmap)
        painter.setPen(DrawToolBar.glass_pen)
        painter.drawPath(clipPath)
        return
예제 #4
0
 def comboColors(self, combo, llista=mv.MAP_COLORS, colorBase=None, mantenirIndex=False):
     idx = -1
     if mantenirIndex:
         idx = combo.currentIndex()
     combo.clear()
     for nom, col in llista.items():
         if col is None:
             if colorBase is None:
                 col = mv.MAP_COLORS[self.renderParams.colorBase]
             else:
                 col = colorBase
         pixmap = QPixmap(80, 45)
         pixmap.fill(col)
         icon = QIcon(pixmap)
         combo.addItem(icon, nom)
     if mantenirIndex:
         combo.setCurrentIndex(idx)
예제 #5
0
def createCompoundThumbnail(_bboxes, thumbnails):
    bboxes = []
    transform = QgsCoordinateTransform(
        QgsCoordinateReferenceSystem('EPSG:4326'),
        QgsCoordinateReferenceSystem('EPSG:3857'), QgsProject.instance())
    for box in _bboxes:
        rect4326 = qgsgeometry_from_geojson(box).boundingBox()
        rect = transform.transformBoundingBox(rect4326)
        bboxes.append([
            rect.xMinimum(),
            rect.yMinimum(),
            rect.xMaximum(),
            rect.yMaximum()
        ])
    globalbox = (min([v[0] for v in bboxes]), min([v[1] for v in bboxes]),
                 max([v[2] for v in bboxes]), max([v[3] for v in bboxes]))
    SIZE = 256
    globalwidth = globalbox[2] - globalbox[0]
    globalheight = globalbox[3] - globalbox[1]
    pixmap = QPixmap(SIZE, SIZE)
    pixmap.fill(Qt.transparent)
    painter = QPainter(pixmap)
    for i, thumbnail in enumerate(thumbnails):
        box = bboxes[i]
        width = box[2] - box[0]
        height = box[3] - box[1]
        if width > height:
            offsety = (width - height) / 2
            offsetx = 0
        else:
            offsetx = (height - width) / 2
            offsety = 0
        x = int((box[0] - offsetx - globalbox[0]) / globalwidth * SIZE)
        y = int((globalbox[3] - box[3] - offsety) / globalheight * SIZE)
        outputwidth = int((width + 2 * offsetx) / globalwidth * SIZE)
        outputheight = int((height + 2 * offsety) / globalheight * SIZE)
        painter.drawPixmap(x, y, outputwidth, outputheight, thumbnail)
    painter.end()
    return pixmap
예제 #6
0
 def createIcon(color):
     color = QColor( color['r'], color['g'], color['b'] )
     pix = QPixmap(16, 16)
     pix.fill( color )
     return QIcon( pix )
예제 #7
0
 def setPointsReplicasColor(self, color):
     self.pointsReplicasColor = QColor(color)
     pixmap = QPixmap(20, 20)
     pixmap.fill(self.pointsReplicasColor)
     self.pointsReplicasColorBtn.setIcon(QIcon(pixmap))
예제 #8
0
 def setLabelsColor(self, color):
     self.labelsColor = QColor(color)
     pixmap = QPixmap(20, 20)
     pixmap.fill(self.labelsColor)
     self.labelsColorBtn.setIcon(QIcon(pixmap))
예제 #9
0
 def setTitleColor(self, color):
     self.titleColor = QColor(color)
     pixmap = QPixmap(20, 20)
     pixmap.fill(self.titleColor)
     self.titleColorBtn.setIcon(QIcon(pixmap))
예제 #10
0
 def setLinesThrendColor(self, color):
     self.linesThrendColor = QColor(color)
     pixmap = QPixmap(20, 20)
     pixmap.fill(self.linesThrendColor)
     self.linesThrendColorBtn.setIcon(QIcon(pixmap))
예제 #11
0
	def setPointsReplicasColor(self, color):
		self.pointsReplicasColor = QColor( color )
		pixmap = QPixmap( 20,20 )
		pixmap.fill( self.pointsReplicasColor )
		self.pointsReplicasColorBtn.setIcon( QIcon(pixmap) )
예제 #12
0
	def setLabelsColor(self, color):
		self.labelsColor = QColor( color )
		pixmap = QPixmap( 20,20 )
		pixmap.fill( self.labelsColor )
		self.labelsColorBtn.setIcon( QIcon(pixmap) )
예제 #13
0
	def setTitleColor(self, color):
		self.titleColor = QColor( color )
		pixmap = QPixmap( 20,20 )
		pixmap.fill( self.titleColor )
		self.titleColorBtn.setIcon( QIcon(pixmap) )
예제 #14
0
	def setLinesThrendColor(self, color):
		self.linesThrendColor = QColor( color )
		pixmap = QPixmap( 20,20 )
		pixmap.fill( self.linesThrendColor )
		self.linesThrendColorBtn.setIcon( QIcon(pixmap) )