@@ -48,13 +48,13 @@ class ShiftClickState(Enum):
4848# polygon geometries. It handles the drawing of rubber bands on the
4949# map canvas and the capturing of clicks to build the geometry.
5050class AIVectorizerTool (QgsMapToolCapture ):
51- def __init__ (self , plugin , current_mode ):
51+ def __init__ (self , plugin ):
5252 # Extend QgsMapToolCapture
5353 cadDockWidget = plugin .iface .cadDockWidget ()
54- super (AIVectorizerTool , self ).__init__ (plugin .iface .mapCanvas (), cadDockWidget , current_mode )
54+ super (AIVectorizerTool , self ).__init__ (plugin .iface .mapCanvas (), cadDockWidget , QgsMapToolCapture . CaptureNone )
5555
5656 self .plugin = plugin
57- self .rb = self .initRubberBand (current_mode )
57+ self .rb = self .initRubberBand ()
5858
5959 # Options
6060 self .num_completions = 50
@@ -84,13 +84,14 @@ def __init__(self, plugin, current_mode):
8484 self .snapIndicator = QgsSnapIndicator (plugin .iface .mapCanvas ())
8585 self .snapper = plugin .iface .mapCanvas ().snappingUtils ()
8686
87- def initRubberBand (self , mode ):
88- if mode == QgsMapToolCapture .CaptureLine :
87+ def initRubberBand (self ):
88+ if self . mode () == QgsMapToolCapture .CaptureLine :
8989 rb = QgsRubberBand (self .plugin .iface .mapCanvas (), QgsWkbTypes .LineGeometry )
90- elif mode == QgsMapToolCapture .CapturePolygon :
90+ elif self . mode () == QgsMapToolCapture .CapturePolygon :
9191 rb = QgsRubberBand (self .plugin .iface .mapCanvas (), QgsWkbTypes .PolygonGeometry )
9292 else :
93- raise ValueError
93+ # TODO not sure how we could get here
94+ rb = QgsRubberBand (self .plugin .iface .mapCanvas (), QgsWkbTypes .PolygonGeometry )
9495
9596 rb .setFillColor (self .digitizingFillColor ())
9697 rb .setStrokeColor (self .digitizingStrokeColor ())
@@ -223,17 +224,24 @@ def canvasReleaseEvent(self, e):
223224 finally :
224225 self .autocomplete_task = None
225226
226- # Right click means we end
227- if e .button () == Qt .RightButton :
228- vlayer = self .plugin .iface .activeLayer ()
229- if not isinstance (vlayer , QgsVectorLayer ):
230- self .plugin .iface .messageBar ().pushMessage (
231- "Bunting Labs AI Vectorizer" ,
232- "No active vector layer." ,
233- Qgis .Warning ,
234- duration = 15 )
235- return
227+ vlayer = self .plugin .iface .activeLayer ()
228+ if not isinstance (vlayer , QgsVectorLayer ):
229+ self .plugin .iface .messageBar ().pushMessage (
230+ "Bunting Labs AI Vectorizer" ,
231+ "No active vector layer." ,
232+ Qgis .Warning ,
233+ duration = 15 )
234+ return
235+ elif vlayer .wkbType () not in [QgsWkbTypes .LineString , QgsWkbTypes .MultiLineString ,
236+ QgsWkbTypes .Polygon , QgsWkbTypes .MultiPolygon ]:
237+ self .plugin .iface .messageBar ().pushMessage (
238+ "Bunting Labs AI Vectorizer" ,
239+ "Unsupported vector layer type for AI autocomplete." ,
240+ Qgis .Warning ,
241+ duration = 15 )
242+ return
236243
244+ if e .button () == Qt .RightButton :
237245 # Will be converted to the relevant geometry
238246 curve = self .captureCurve ()
239247
@@ -287,7 +295,6 @@ def canvasReleaseEvent(self, e):
287295 if len (self .vertices ) >= 2 and not (e .modifiers () & Qt .ShiftModifier ) and not wasDoubleClick :
288296 root = QgsProject .instance ().layerTreeRoot ()
289297 rlayers = [node .layer () for node in root .children () if isinstance (node , QgsLayerTreeLayer ) and isinstance (node .layer (), QgsRasterLayer ) and node .itemVisibilityChecked ()]
290- vlayer = self .plugin .iface .activeLayer ()
291298
292299 project_crs = QgsProject .instance ().crs ()
293300
@@ -308,4 +315,5 @@ def canvasReleaseEvent(self, e):
308315 def deactivate (self ):
309316 self .rb .reset ()
310317
311- self .scissors_icon .hide ()
318+ self .scissors_icon .hide ()
319+ self .plugin .action .setChecked (False )
0 commit comments