original_docstring: Activated anytime Mapwindow is closed either programmatically or
              if the user finds some other way to close the window. Automatically
              finishes the polygon if it's unconnected.
          
docstring: Activated anytime Mapwindow is closed either programmatically or
  if the user finds some other way to close the window. Automatically
  finishes the polygon if it's unconnected.
docstring_tokens: Activated anytime Mapwindow is closed either programmatically or if the user finds some other way to close the window . Automatically finishes the polygon if it ' s unconnected .
code: def closeEvent(self, event):
          """Activated anytime Mapwindow is closed either programmatically or
              if the user finds some other way to close the window. Automatically
              finishes the polygon if it's unconnected.
          """
          self.toolDraw.finishPolygon()
          points = self.getPolygon()
          if points:
              polygon = QgsGeometry.fromPolygonXY([points])
              feature = QgsFeature()
              feature.setGeometry(polygon)
              data_str = "Polygon?crs=epsg:3067"
              new_layer = QgsVectorLayer(data_str, "drawn_polygon", "memory")
              new_layer.dataProvider().addFeatures([feature])
              if new_layer.isValid():
                  QgsProject.instance().addMapLayer(new_layer)
              else:
                  print("Unable to create a new layer from the drawing")
              print(polygon)
              for point in points:
                  print(point)
          QMainWindow.closeEvent(self, event)
code_tokens: def closeEvent ( self , event ) : self . toolDraw . finishPolygon ( ) points = self . getPolygon ( ) if points : polygon = QgsGeometry . fromPolygonXY ( [ points ] ) feature = QgsFeature ( ) feature . setGeometry ( polygon ) data_str = "Polygon?crs=epsg:3067" new_layer = QgsVectorLayer ( data_str , "drawn_polygon" , "memory" ) new_layer . dataProvider ( ) . addFeatures ( [ feature ] ) if new_layer . isValid ( ) : QgsProject . instance ( ) . addMapLayer ( new_layer ) else : print ( "Unable to create a new layer from the drawing" ) print ( polygon ) for point in points : print ( point ) QMainWindow . closeEvent ( self , event )
short_docstring: Activated anytime Mapwindow is closed either programmatically or
  if the user finds some other way to close the window.
short_docstring_tokens: Activated anytime Mapwindow is closed either programmatically or if the user finds some other way to close the window .
comment: """Activated anytime Mapwindow is closed either programmatically or
              if the user finds some other way to close the window. Automatically
              finishes the polygon if it's unconnected.
          """