FieldStudiesCouncil / QGIS-Biological-Recording-Tools

QGIS plugin for biological recorders. Created with the FSC Tomorrow's Biodiversity project.
GNU General Public License v3.0
10 stars 4 forks source link

QGIS 3.30 breaks TomBio Tools #65

Closed fruit-github closed 1 year ago

fruit-github commented 1 year ago

This is such a useful tool but sadly

TomBio Tools 3.4.1 on QGIS 3.30 gives the following

WARNING    Traceback (most recent call last):
              File "/home/fred/Documents/Shared/QGIS-stuff/profiles/default/python/plugins/TomBio/tombio.py", line 148, in showOsgrDialog
              self.guiOsgr = osgrdialog.OsgrDialog(self.iface, self.dwOsgr)
              File "/home/fred/Documents/Shared/QGIS-stuff/profiles/default/python/plugins/TomBio/osgrdialog.py", line 95, in __init__
              self.dragTool = drag_box_tool.RectangleMapTool(self.canvas, self.iface)
              File "/home/fred/Documents/Shared/QGIS-stuff/profiles/default/python/plugins/TomBio/drag_box_tool.py", line 35, in __init__
              self.rubberBand = QgsRubberBand(self.canvas, FALSE)
             NameError: name 'FALSE' is not defined
richieb977 commented 1 year ago

Similar (QGIS 3.30.0, TomBio Tools 3.4.1, Python 3.9.5, Win 10):

WARNING Traceback (most recent call last): File "C:\Users/xxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins/TomBio/tombio.py", line 148, in showOsgrDialog self.guiOsgr = osgrdialog.OsgrDialog(self.iface, self.dwOsgr) File "C:\Users/xxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins/TomBio/osgrdialog.py", line 95, in __init__ self.dragTool = drag_box_tool.RectangleMapTool(self.canvas, self.iface) File "C:\Users/xxxx/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins/TomBio/drag_box_tool.py", line 35, in __init__ self.rubberBand = QgsRubberBand(self.canvas, False) TypeError: QgsRubberBand(): argument 2 has unexpected type 'bool'

richieb977 commented 1 year ago

I've had a bit of a look - please note I am am not a Python programmer, nor a QGIS expert, but I am an Analyst/Programmer...

QgsRubberBand expects a geometry as the second parameter, andFalse isn't a geometry.

Maybe defining the relevent geometry at Class level in drag_box_tool.py, e.g.

mygeometry = QgsWkbTypes.[insert-the-right-one-here]

and using self.mygeometry in place of 'False' in the three occurrences in the class would cure the error?

Hope this helps.

fruit-github commented 1 year ago

Good to know there is someone else here :)

I should have added in my first post that the API appears to have changed https://api.qgis.org/api/classQgsRubberBand.html

I have had a few attempts at understanding what is going on there but so far it's beyond me. I have never managed to master python and too old now.

richieb977 commented 1 year ago

I'm sure the API has been changed, too. I made the change I suggested to drag_box_tool.py and it got the tool to work for getting the OSGR from the map (which is all I needed!).

It's throwing other errors, which I can ignore (it doesn't want to select an area... but neither do I). If I get really bored I'll have a look at those as well one day - I'm too old to want learn python as well.

fruit-github commented 1 year ago

All seems good and is working as it should from a quick session.

Many thanks

burkmarr commented 1 year ago

Thanks for the heads-up. It looks as though the constructor for qgis.gui.QgsRubberBand changed quite a few versions back but was presumably overloaded to accommodate the deprecated API and that overloading disappeared with v3.30. Also failing was the reset method for similar reasons. Both the constructor and that method now take a QgsWkbTypes.GeometryType argument, which in both cases defaults to QgsWkbTypes.LineGeometry which is the required value, so I have simply left the argument out.

I've fixed and released v3.4.2 which is uploaded to the plugin repository (https://plugins.qgis.org/plugins/TomBio/) though it may take a few hours before it is available from the QGIS plugin manager.

richieb977 commented 1 year ago

Brilliant thanks!