Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin updated for QGIS3 #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
plugin/resources_rc.py
plugin/ui_quickdraw.py
plugin/quickdraw.zip
3 changes: 2 additions & 1 deletion plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""
from __future__ import absolute_import

def classFactory(iface):
# load QuickDraw class from file QuickDraw
from quickdraw import QuickDraw
from .quickdraw import QuickDraw
return QuickDraw(iface)
4 changes: 2 additions & 2 deletions plugin/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

[general]
name=Quick Draw
qgisMinimumVersion=2.0
qgisMinimumVersion=3.0
description=Input simple geometries as text coordinates and display them on the map canvas.
version=0.4
author=Homme Zwaagstra
Expand All @@ -27,7 +27,7 @@ [email protected]
category=Vector

# tags are comma separated with spaces allowed
tags=geometry,geometries,point,polygon,polyline,bbox,bounding box,draw,canvas,digitizing,digitising
tags=geometry,geometries,point,polygon,polyline,bbox,bounding box,draw,canvas

homepage=http://www.github.com/geo-data/qgis-quick-draw
tracker=http://www.github.com/geo-data/qgis-quick-draw/issues
Expand Down
74 changes: 46 additions & 28 deletions plugin/quickdraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,31 @@
* *
***************************************************************************/
"""
from __future__ import absolute_import
# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from builtins import zip
from builtins import str
from builtins import range
from builtins import object
from qgis.PyQt.QtCore import QSettings, QObject
from qgis.PyQt.QtWidgets import QAction, QDialogButtonBox, QMessageBox
from qgis.PyQt.QtGui import QIcon, QColor
from qgis.core import QgsPointXY, QgsGeometry, QgsRectangle
from qgis.gui import QgsVertexMarker, QgsRubberBand
# Initialize Qt resources from file resources.py
import resources_rc
from . import resources_rc
# Import the code for the dialog
from quickdrawdialog import QuickDrawDialog
from .quickdrawdialog import QuickDrawDialog
import os.path

from random import uniform
from itertools import izip


class QuickDrawError(Exception):
def __init__(self, message, title):
super(QuickDrawError, self).__init__(message)
self.title = title
self.message=message

class InvalidGeometry(QuickDrawError):
def __init__(self, geom):
Expand All @@ -47,7 +54,7 @@ def __init__(self, geom):
super(InvalidGeometry, self).__init__("The geometry formatting is wrong: %s" % msg, 'Invalid Geometry')
self.geom = geom

class QuickDraw:
class QuickDraw(object):

def __init__(self, iface):
# Save reference to the QGIS interface
Expand Down Expand Up @@ -89,23 +96,33 @@ def initGui(self):
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu(u"&Quick Draw", self.action)

QObject.connect(self.dlg.clearButton, SIGNAL("clicked()"), self.clearButtonClicked)
self.dlg.buttonBox.clicked.connect(self.buttonBoxClicked)
self.dlg.clearButton.clicked.connect(self.clearButtonClicked)
# self.dlg.buttonBox.clicked.connect(self.buttonBoxClicked)
self.dlg.buttonBox.button(QDialogButtonBox.Reset).clicked.connect(self.buttonBoxReset)
self.dlg.buttonBox.button(QDialogButtonBox.Apply).clicked.connect(self.buttonBoxApply)

self.dlg.exampleComboBox.activated.connect(self.exampleSelected)

def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu(u"&Quick Draw", self.action)
self.iface.removeToolBarIcon(self.action)
self.removeItems()

def buttonBoxClicked(self, button):
button_text = str(button.text())
if button_text == 'Apply':
self.draw()
self.applied = True
elif button_text == 'Reset':
self.resetText()

def buttonBoxReset(self, button):
self.resetText()

def buttonBoxApply(self, button):
self.draw()
self.applied = True

# def buttonBoxClicked(self, button):
# button_text = str(button.text())
# if button_text == 'Apply':
# self.draw()
# self.applied = True
# elif button_text == 'Reset':
# self.resetText()

def clearButtonClicked(self):
self.dlg.geometryTextEdit.setPlainText('')
Expand All @@ -132,7 +149,7 @@ def exampleSelected(self, index):
for i in range(3):
x.append(uniform(minx, maxx))
y.append(uniform(miny, maxy))
text = ','.join(('%s,%s' % t for t in izip(sorted(x), y)))
text = ','.join(('%s,%s' % t for t in zip(sorted(x), y)))
else: # polygon
x, y = [], []
for i in range(4):
Expand All @@ -141,8 +158,7 @@ def exampleSelected(self, index):
x.sort()
x.append(x[0])
y.append(y[0])
text = ','.join(('%s,%s' % t for t in izip(x, y)))

text = ','.join(('%s,%s' % t for t in zip(x, y)))
self.dlg.geometryTextEdit.appendPlainText(text)

def draw(self, checkZoom = True):
Expand All @@ -157,7 +173,7 @@ def draw(self, checkZoom = True):
r = self.geometryToCanvas(geom)
r.show()
drawStack.append(r)
except QuickDrawError, e:
except QuickDrawError as e:
message = e.message + "\n\nUse the QGIS \"What's This?\" help tool to click on the text input box for information on how to correctly format geometries."
QMessageBox.warning(self.dlg, e.title, message)
self.removeItems(drawStack) # remove added items
Expand Down Expand Up @@ -216,10 +232,10 @@ def getBBOX(item):
for item in self.drawStack[1:]:
bbox = getBBOX(item)
extent.combineExtentWith(bbox)

if extent:
canvas.setExtent(extent)
canvas.updateFullExtent()
#canvas.refresh()
#canvas.updateFullExtent()

def removeItems(self, drawStack = None):
if drawStack is None:
Expand Down Expand Up @@ -264,7 +280,7 @@ def toCoords(text):
return toCoords(text)

def coordsToPoints(self, coords):
return [QgsPoint(*coord) for coord in coords]
return [QgsPointXY(*coord) for coord in coords]

def textToGeometry(self, text):
coords = self.textToCoords(text)
Expand All @@ -275,12 +291,14 @@ def textToGeometry(self, text):
return points[0]
elif coord_count > 2 and coords[0] == coords[-1]:
# it's a polygon
return QgsGeometry.fromPolygon([points])
return QgsGeometry.fromPolygonXY([points])

return QgsGeometry.fromPolyline(points)
#return QgsGeometry.fromPolyline(points)
# fromPolyline() now requires a list of QgsPoint objects, instead of QgsPointXY 2d points. A new method fromPolylineXY was added which uses the old list of 2d QgsPointXY objects. Using the newer method
return QgsGeometry.fromPolylineXY(points)

def geometryToCanvas(self, geom):
if isinstance(geom, QgsPoint):
if isinstance(geom, QgsPointXY):
r = self.pointToVertexMarker(geom)
else:
r = self.geometryToRubberBand(geom)
Expand Down
9 changes: 5 additions & 4 deletions plugin/quickdrawdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
***************************************************************************/
"""

from PyQt4 import QtCore, QtGui
from ui_quickdraw import Ui_QuickDraw
from qgis.PyQt import QtCore, QtGui
from .ui_quickdraw import Ui_QuickDraw
from qgis.PyQt.QtWidgets import QDialog
# create the dialog for zoom to point


class QuickDrawDialog(QtGui.QDialog, Ui_QuickDraw):
class QuickDrawDialog(QDialog, Ui_QuickDraw):
def __init__(self):
QtGui.QDialog.__init__(self)
QDialog.__init__(self)
# Set up the user interface from Designer.
# After setupUI you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
Expand Down
127 changes: 127 additions & 0 deletions plugin/resources_rc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-

# Resource object code
#
# Created by: The Resource Compiler for PyQt5 (Qt v5.11.2)
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore

qt_resource_data = b"\
\x00\x00\x03\xfc\
\x89\
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
\x00\x00\x18\x00\x00\x00\x18\x08\x06\x00\x00\x00\xe0\x77\x3d\xf8\
\x00\x00\x00\x04\x73\x42\x49\x54\x08\x08\x08\x08\x7c\x08\x64\x88\
\x00\x00\x00\x09\x70\x48\x59\x73\x00\x00\x00\xfd\x00\x00\x00\xfd\
\x01\xe2\x7b\x83\x93\x00\x00\x00\x19\x74\x45\x58\x74\x53\x6f\x66\
\x74\x77\x61\x72\x65\x00\x77\x77\x77\x2e\x69\x6e\x6b\x73\x63\x61\
\x70\x65\x2e\x6f\x72\x67\x9b\xee\x3c\x1a\x00\x00\x00\x18\x74\x45\
\x58\x74\x54\x69\x74\x6c\x65\x00\x64\x65\x66\x69\x62\x72\x69\x6c\
\x6c\x61\x74\x6f\x72\x20\x6c\x6f\x67\x6f\x49\x7d\x98\x6d\x00\x00\
\x00\x0f\x74\x45\x58\x74\x41\x75\x74\x68\x6f\x72\x00\x62\x74\x6f\
\x75\x72\x6e\x61\x79\x5e\xff\xe2\x3a\x00\x00\x00\x22\x74\x45\x58\
\x74\x44\x65\x73\x63\x72\x69\x70\x74\x69\x6f\x6e\x00\x68\x65\x61\
\x72\x74\x20\x77\x69\x74\x68\x20\x61\x20\x6c\x69\x67\x68\x74\x6e\
\x69\x6e\x67\xf6\x00\x12\x31\x00\x00\x00\x21\x74\x45\x58\x74\x43\
\x72\x65\x61\x74\x69\x6f\x6e\x20\x54\x69\x6d\x65\x00\x32\x30\x31\
\x33\x2d\x30\x32\x2d\x30\x38\x54\x30\x34\x3a\x35\x32\x3a\x35\x37\
\x13\xdf\x34\xbd\x00\x00\x00\x51\x74\x45\x58\x74\x53\x6f\x75\x72\
\x63\x65\x00\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x70\x65\x6e\x63\x6c\
\x69\x70\x61\x72\x74\x2e\x6f\x72\x67\x2f\x64\x65\x74\x61\x69\x6c\
\x2f\x31\x37\x34\x39\x30\x37\x2f\x64\x65\x66\x69\x62\x72\x69\x6c\
\x6c\x61\x74\x6f\x72\x2d\x6c\x6f\x67\x6f\x2d\x62\x79\x2d\x62\x74\
\x6f\x75\x72\x6e\x61\x79\x2d\x31\x37\x34\x39\x30\x37\x28\xad\x41\
\x8e\x00\x00\x00\x49\x74\x45\x58\x74\x43\x6f\x70\x79\x72\x69\x67\
\x68\x74\x00\x50\x75\x62\x6c\x69\x63\x20\x44\x6f\x6d\x61\x69\x6e\
\x20\x68\x74\x74\x70\x3a\x2f\x2f\x63\x72\x65\x61\x74\x69\x76\x65\
\x63\x6f\x6d\x6d\x6f\x6e\x73\x2e\x6f\x72\x67\x2f\x6c\x69\x63\x65\
\x6e\x73\x65\x73\x2f\x70\x75\x62\x6c\x69\x63\x64\x6f\x6d\x61\x69\
\x6e\x2f\x59\xc3\xfe\xca\x00\x00\x02\x2d\x49\x44\x41\x54\x48\x89\
\xb5\xd2\x4f\x48\xd3\x61\x1c\xc7\xf1\xf7\x58\x05\x41\x04\x05\x41\
\x82\x47\x3b\x44\x78\x88\x0e\x0d\x8a\xe8\xd0\x1f\xaa\x75\x28\x5a\
\x14\x9d\x44\x0c\x22\x74\x1e\xd2\x20\x3d\x18\x46\x48\x60\x44\x48\
\x52\x96\x4d\x1d\x18\x31\x29\xdc\xe6\x2a\x33\x45\x11\xc3\xb2\x3f\
\x4a\xb3\x44\x33\x4c\xb3\xa5\x92\xa0\x4b\xd2\xfd\xfa\x74\x10\x63\
\xfe\x99\xce\xb9\x9e\xef\xfd\xf5\xe6\x79\x9e\xaf\x49\x88\xff\x71\
\xf2\xf7\x98\xb6\x0f\x8d\x92\xbc\x2a\xde\xf0\xc9\x44\xd3\xda\x53\
\x56\x72\x37\x06\x48\xe8\x68\x24\x0d\xc5\x71\xee\x9c\xc0\xfa\xbe\
\x80\xb7\x9e\x74\xee\xdb\xc0\x2c\x44\x5c\xe0\xec\x9d\x24\xbe\xb8\
\x48\xd9\x98\x93\x29\x6f\x18\xbe\xe2\x80\x0d\xcc\x95\x29\x64\xf4\
\xdd\xa2\x3f\x54\x85\x3c\x19\x38\xc2\xf1\x15\x05\x0a\x8f\x62\x69\
\xcd\xa3\x2e\xe4\x42\x91\xf0\x98\x02\x67\x92\x58\xef\xb1\x73\x7d\
\xa4\x9c\x71\x3d\x9a\xc6\xbd\x76\xca\x16\xc2\x97\x1d\x28\x49\xe1\
\xf4\xc7\x62\xfc\x7a\x86\xe4\x43\x46\x35\xaa\xc9\x8c\x8c\x47\x1d\
\xc8\xb7\xb2\xa5\xbe\x00\xd7\x44\x1d\x86\x9a\x90\x1a\x90\x51\x8b\
\x6a\xb2\x16\xc7\x97\x0c\xec\x80\xd5\x0f\x2e\x91\xd3\xef\xe3\x87\
\xde\x21\xb5\x21\xb5\x22\xa3\x19\xf9\x72\x29\x5f\x0a\x5f\x34\x70\
\x33\x8d\x7d\xaf\x2b\x69\x31\xba\x90\x3e\x21\xf9\x91\x3a\x90\xf1\
\x06\x79\xf3\xa9\x88\x06\x8f\x18\xc8\x3e\xc2\x56\xff\x53\x06\x34\
\x80\xd4\x87\xd4\x8b\xd4\x3d\x1d\xea\x75\x13\xb8\x72\x1c\x4b\xb4\
\xff\x16\xf9\x06\xe9\x58\xba\x1a\xf0\x2b\x80\xf4\x0d\xe9\x2b\xd2\
\x17\xa4\x1e\xf4\xbd\x91\x11\xe7\x05\x32\x01\x53\xcc\x01\x21\xb2\
\x0f\x91\xd8\xe2\xe2\xf9\x9f\x21\x34\x37\xf4\xbb\x13\xd5\xde\xc0\
\x95\x75\x98\xcd\x31\x07\x84\xd8\xbb\x89\x75\x2f\x1f\xd3\xae\x9f\
\x48\xc3\xb3\x43\x83\xcd\x0c\x95\xd8\xc9\x88\x39\x60\x03\xb3\xfb\
\x1e\xa5\xa1\x20\xd2\x2f\xa4\x31\xa4\x51\x34\xde\xcb\x64\xbd\x83\
\x8a\x3c\x1b\x49\x31\x3f\x91\x0d\xcc\xee\x52\x4a\x43\x53\x48\x42\
\x0a\xa1\x50\x10\xb5\x3d\xa1\xb1\xc8\xce\xfe\xa5\xe0\x45\x03\xf3\
\x70\xa1\xee\x0e\x7a\x9c\xd7\x38\x1f\xed\x7a\x46\x0c\xcc\xc5\x87\
\x07\x19\xf5\x96\x51\x78\x6e\x37\x1b\x96\x03\x2f\x18\x08\xc7\x27\
\x82\x18\x4d\xd5\x54\x15\x9c\x25\x39\x16\x78\x5e\x60\x06\x9f\x9a\
\x44\xed\xcd\xbc\x2a\xce\xe1\xd8\x4a\xe0\x59\x81\x19\xfc\xf3\x07\
\x06\x1e\x16\x91\xb5\x0d\xd6\xc4\x03\x17\x02\x1b\x98\xef\x5e\xc6\
\x51\x53\xce\xed\xcc\x83\x24\xc4\x0b\xfe\x17\xb0\x1f\x20\xf5\x6a\
\x2a\xbb\xe2\x0d\xcf\xcc\x5f\xbe\x9b\x21\x4f\xe8\x97\x46\xcf\x00\
\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82\
"

qt_resource_name = b"\
\x00\x07\
\x07\x3b\xe0\xb3\
\x00\x70\
\x00\x6c\x00\x75\x00\x67\x00\x69\x00\x6e\x00\x73\
\x00\x09\
\x0f\xa1\x49\xe7\
\x00\x71\
\x00\x75\x00\x69\x00\x63\x00\x6b\x00\x64\x00\x72\x00\x61\x00\x77\
\x00\x08\
\x0a\x61\x5a\xa7\
\x00\x69\
\x00\x63\x00\x6f\x00\x6e\x00\x2e\x00\x70\x00\x6e\x00\x67\
"

qt_resource_struct_v1 = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
\x00\x00\x00\x14\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\
\x00\x00\x00\x2c\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
"

qt_resource_struct_v2 = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x14\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x2c\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x01\x5e\x04\xd1\xe4\x90\
"

qt_version = [int(v) for v in QtCore.qVersion().split('.')]
if qt_version < [5, 8, 0]:
rcc_version = 1
qt_resource_struct = qt_resource_struct_v1
else:
rcc_version = 2
qt_resource_struct = qt_resource_struct_v2

def qInitResources():
QtCore.qRegisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data)

def qCleanupResources():
QtCore.qUnregisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data)

qInitResources()
Binary file added plugin/resources_rc.pyc
Binary file not shown.
Loading