Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions metadata.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
[general]
name:MapSwipe Tool
description:Swipe active layer with others layers
about:This plugin is a map tool for swipe active layer.
name=MapSwipe Tool
description=Swipe active layer with others layers
about=This plugin is a map tool for swipe active layer.
The active layer, or group, will appear above all others.
This plugin is developed of collaborative form with IBAMA [1] and APPLIED TECHNOLOGY CO., LTD [2].
[1] http://www.ibama.gov.br
[2] http://www.apptec.co.jp

version:1.4
qgisMinimumVersion:3.40
version=1.5
qgisMinimumVersion=3.99
qgisMaximumVersion=4.99
supportsQt6=True

author:Hirofumi Hayashi and Luiz Motta
email:hayashi@apptec.co.jp,motta.luiz@gmail.com
author=Hirofumi Hayashi and Luiz Motta
email=hayashi@apptec.co.jp,motta.luiz@gmail.com

# category:
tags:visibility,layers, swipe, IBAMA, APPLIED TECHNOLOGY CO.
tags=visibility,layers, swipe, IBAMA, APPLIED TECHNOLOGY CO.

homepage:https://github.com/lmotta/mapswipetool_plugin/wiki
tracker:https://github.com/lmotta/mapswipetool_plugin/issues
repository:https://github.com/lmotta/mapswipetool_plugin
homepage=https://github.com/lmotta/mapswipetool_plugin/wiki
tracker=https://github.com/lmotta/mapswipetool_plugin/issues
repository=https://github.com/lmotta/mapswipetool_plugin

icon:mapswipetool.png
icon=mapswipetool.png

experimental:False
deprecated:False
experimental=False
deprecated=False

changelog:1.4 (2025-12-09)
changelog=1.5(2025-01-08)
Upgrade to Qt6 and QGIS 4.x
- 1.4(2025-12-09)
Fixed issue #11, added "settings.setDevicePixelRatio( 1 )"
- 1.3(2024-05-31)
Fixed def paint and setLenght
Expand Down
18 changes: 9 additions & 9 deletions tool/maptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def __init__(self, title:str, iface:QgisInterface):
self.project = QgsProject.instance()
self.has_direction, self.has_swipe, self.disabled_swipe = None, None, None
self.first_point = QPoint()
self.cursor_v = QCursor( Qt.SplitVCursor )
self.cursor_h = QCursor( Qt.SplitHCursor )
self.cursor_v = QCursor( Qt.CursorShape.SplitVCursor )
self.cursor_h = QCursor( Qt.CursorShape.SplitHCursor )

self.swipe_map = SwipeMap( self.canvas )

Expand Down Expand Up @@ -171,7 +171,7 @@ def setTreeGroup(node:QgsLayerTreeGroup):
@pyqtSlot()
def activate(self)->None:
super().activate()
self.canvas.setCursor( QCursor( Qt.PointingHandCursor ) )
self.canvas.setCursor( QCursor( Qt.CursorShape.PointingHandCursor ) )
self._connect()
self.has_swipe = False
self.disabled_swipe = False
Expand All @@ -194,25 +194,25 @@ def canvasPressEvent(self, e:QgsMapMouseEvent)->None:
return

self.has_swipe = True
self.first_point.setX( e.x() )
self.first_point.setY( e.y() )
self.first_point.setX( e.pos().x() )
self.first_point.setY( e.pos().y() )
self.has_direction = False

@pyqtSlot(QgsMapMouseEvent)
def canvasReleaseEvent(self, e:QgsMapMouseEvent)->None:
self.has_swipe = False
self.canvas.setCursor( QCursor( Qt.PointingHandCursor ) )
self.canvas.setCursor( QCursor( Qt.CursorShape.PointingHandCursor ) )

@pyqtSlot(QgsMapMouseEvent)
def canvasMoveEvent(self, e:QgsMapMouseEvent)->None:
if not self.has_swipe:
return

if not self.has_direction:
dX = abs( e.x() - self.first_point.x() )
dY = abs( e.y() - self.first_point.y() )
dX = abs( e.pos().x() - self.first_point.x() )
dY = abs( e.pos().y() - self.first_point.y() )
self.swipe_map.is_vertical = dX > dY
self.has_direction = True
self.canvas.setCursor( self.cursor_h if self.swipe_map.is_vertical else self.cursor_v )

self.swipe_map.setLength( e.x(), e.y() )
self.swipe_map.setLength( e.pos().x(), e.pos().y() )
270 changes: 135 additions & 135 deletions tool/swipemap.py
Original file line number Diff line number Diff line change
@@ -1,135 +1,135 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : MapSwipe tool
Description : Plugin for swipe active layer
Date : October, 2015
copyright : (C) 2015 by Hirofumi Hayashi and Luiz Motta
email : hayashi@apptec.co.jp and motta.luiz@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
__author__ = 'Luiz Motta'
__date__ = '2015-10-14'
__copyright__ = '(C) 2018, Luiz Motta'
__revision__ = '$Format:%H$'
from qgis.PyQt.QtCore import (
Qt,
QRect, QLine,
QObject, pyqtSignal
)
from qgis.PyQt.QtGui import (
QColor,
QImage, QPainter
)
from qgis.core import (
QgsMapRendererParallelJob,
QgsMapSettings
)
from qgis.gui import (
QgsMapCanvas, QgsMapCanvasItem
)
class SwipeSignals(QObject):
creatingImage = pyqtSignal()
finishedImage = pyqtSignal()
class SwipeMap(QgsMapCanvasItem):
def __init__(self, canvas:QgsMapCanvas):
self.canvas = canvas
super().__init__( canvas )
self.setZValue(10)
self.signals = SwipeSignals()
self.layers = []
self.image = None
self.length = 0
self.is_vertical = True
self.flg = False
def clear(self)->None:
self.layers = []
self.image = None
self.length = -1
self.updateCanvas()
def setLength(self, x:float, y:float)->None:
y = int(self.boundingRect().height() - y )
self.length = int(x) if self.is_vertical else int(y)
self.updateCanvas() # Call self.paint
def paint(self, painter:QPainter, *args): # NEED *args for WINDOWS!
def finished()->None:
painter.setClipRect( region )
painter.drawImage( 0,0, self.image )
painter.setRenderHint( QPainter.Antialiasing ) # Smooths edges
painter.drawLine( line )
if not self.layers or self.length == -1 or self.image is None:
return
region = QRect(0,0,0,0)
if self.is_vertical:
w = int(self.length)
h = int(self.boundingRect().height() - 2)
region.setWidth( w )
region.setHeight( h )
line = QLine( w-1,0,w-1,h-1 )
finished()
return
w = int(self.boundingRect().width() - 2)
h = int(self.boundingRect().height() - self.length)
region.setWidth( w )
region.setHeight( h )
line = QLine( 0,h-1,w-1,h-1 )
finished()
# It is a slot, the decorator 'pyqtSlot' fail because QgsMapCanvasItem not is QObject
def setImage(self):
def createMapSettings():
settings = QgsMapSettings()
settings.setBackgroundColor(QColor(Qt.transparent))
settings.setDevicePixelRatio( 1 )
settings.setLayers( self.layers )
settings.setDestinationCrs( self.canvas.mapSettings().destinationCrs() )
settings.setOutputSize( self.canvas.size() )
settings.setExtent( self.canvas.extent() )
return settings
def finished():
image = job.renderedImage()
if bool( self.canvas.property('retro') ):
image = image.scaled( image.width() / 3, image.height() / 3 )
image = image.convertToFormat( QImage.Format_Indexed8, Qt.OrderedDither | Qt.OrderedAlphaDither )
self.image = image
self.signals.finishedImage.emit()
self.updateCanvas()
if not self.layers:
return
self.signals.creatingImage.emit()
self.setRect( self.canvas.extent() )
self.image = None
job = QgsMapRendererParallelJob( createMapSettings() )
job.start()
job.finished.connect( finished )
#job.waitForFinished()
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : MapSwipe tool
Description : Plugin for swipe active layer
Date : October, 2015
copyright : (C) 2015 by Hirofumi Hayashi and Luiz Motta
email : hayashi@apptec.co.jp and motta.luiz@gmail.com

***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""

__author__ = 'Luiz Motta'
__date__ = '2015-10-14'
__copyright__ = '(C) 2018, Luiz Motta'
__revision__ = '$Format:%H$'


from qgis.PyQt.QtCore import (
Qt,
QRect, QLine,
QObject, pyqtSignal
)
from qgis.PyQt.QtGui import (
QColor,
QImage, QPainter
)

from qgis.core import (
QgsMapRendererParallelJob,
QgsMapSettings
)
from qgis.gui import (
QgsMapCanvas, QgsMapCanvasItem
)


class SwipeSignals(QObject):
creatingImage = pyqtSignal()
finishedImage = pyqtSignal()

class SwipeMap(QgsMapCanvasItem):
def __init__(self, canvas:QgsMapCanvas):
self.canvas = canvas
super().__init__( canvas )
self.setZValue(10)

self.signals = SwipeSignals()
self.layers = []
self.image = None
self.length = 0
self.is_vertical = True
self.flg = False

def clear(self)->None:
self.layers = []
self.image = None
self.length = -1
self.updateCanvas()

def setLength(self, x:float, y:float)->None:
y = int(self.boundingRect().height() - y )
self.length = int(x) if self.is_vertical else int(y)
self.updateCanvas() # Call self.paint

def paint(self, painter:QPainter, *args): # NEED *args for WINDOWS!
def finished()->None:
painter.setClipRect( region )
painter.drawImage( 0,0, self.image )
painter.setRenderHint( QPainter.RenderHint.Antialiasing ) # Smooths edges
painter.drawLine( line )

if not self.layers or self.length == -1 or self.image is None:
return

region = QRect(0,0,0,0)
if self.is_vertical:
w = int(self.length)
h = int(self.boundingRect().height() - 2)
region.setWidth( w )
region.setHeight( h )
line = QLine( w-1,0,w-1,h-1 )
finished()

return

w = int(self.boundingRect().width() - 2)
h = int(self.boundingRect().height() - self.length)
region.setWidth( w )
region.setHeight( h )
line = QLine( 0,h-1,w-1,h-1 )
finished()

# It is a slot, the decorator 'pyqtSlot' fail because QgsMapCanvasItem not is QObject
def setImage(self):
def createMapSettings():
settings = QgsMapSettings()
settings.setBackgroundColor(QColor(Qt.GlobalColor.transparent))
settings.setDevicePixelRatio( 1 )
settings.setLayers( self.layers )
settings.setDestinationCrs( self.canvas.mapSettings().destinationCrs() )
settings.setOutputSize( self.canvas.size() )
settings.setExtent( self.canvas.extent() )

return settings

def finished():
image = job.renderedImage()
if bool( self.canvas.property('retro') ):
image = image.scaled( image.width() / 3, image.height() / 3 )
image = image.convertToFormat( QImage.Format.Format_Indexed8, Qt.ImageConversionFlag.OrderedDither | Qt.ImageConversionFlag.OrderedAlphaDither )
self.image = image
self.signals.finishedImage.emit()
self.updateCanvas()

if not self.layers:
return

self.signals.creatingImage.emit()

self.setRect( self.canvas.extent() )
self.image = None
job = QgsMapRendererParallelJob( createMapSettings() )
job.start()
job.finished.connect( finished )
#job.waitForFinished()