def __init__(self, iface, layerManager, controller): """ Intialise Move Address Tool @param iface: QgisInterface Abstract base class defining interfaces exposed by QgisApp @type iface: Qgisinterface Object @param layerManager: Plugins layer manager @type layerManager: AimsUI.LayerManager() @param controller: Instance of the plugins controller @type controller: AimsUI.AimsClient.Gui.Controller() """ QgsMapToolIdentify.__init__(self, iface.mapCanvas()) self._iface = iface self._canvas = iface.mapCanvas() self._layers = layerManager self._controller = controller self.RespHandler = ResponseHandler(self._iface, self._controller.uidm) self.highlighter = self._controller.highlighter self.afc = { ft: AddressFactory.getInstance(FEEDS['AC']) for ft in FeedType.reverse } self.aff = FeatureFactory.getInstance( FeedRef(FeatureType.ADDRESS, FeedType.FEATURES)) self._features = [] self._sb = self._iface.mainWindow().statusBar() self.activate()
def __init__(self, iface, configManager): """ Initialise UI Data Manager and Response Handler @param iface: QgisInterface Abstract base class defining interfaces exposed by QgisApp @type iface: Qgisinterface Object """ QObject.__init__(self) self.iface = iface self._queues = None self._dockWindow = None self._currentMapTool = None self.rclParent = None self.currentRevItem = None self.actions = [] if Controller._instance == None: Controller._instance = self self.uidm = UiDataManager(self.iface, self) self.RespHandler = ResponseHandler(self.iface, self.uidm) self._config_ui = configManager self.refLayer = None self.adrlayer = None self.revLayer = None
def __init__(self, iface, layerManager, controller): """ Intialise Update Address Tool @param iface: QgisInterface Abstract base class defining interfaces exposed by QgisApp @type iface: Qgisinterface Object @param layerManager: Plugins layer manager @type layerManager: AimsUI.LayerManager() @param controller: Instance of the plugins controller @type controller: AimsUI.AimsClient.Gui.Controller() """ QgsMapToolIdentify.__init__(self, iface.mapCanvas()) self._iface = iface self._controller = controller self._layers = layerManager self._canvas = iface.mapCanvas() self.RespHandler = ResponseHandler(self._iface, self._controller.uidm) self._currentRevItem = None
def __init__(self, iface, layerManager, controller): """ Intialise Move Address Tool @param iface: QgisInterface Abstract base class defining interfaces exposed by QgisApp @type iface: Qgisinterface Object @param layerManager: Plugins layer manager @type layerManager: AimsUI.LayerManager() @param controller: Instance of the plugins controller @type controller: AimsUI.AimsClient.Gui.Controller() """ QgsMapToolIdentify.__init__(self, iface.mapCanvas()) self._iface = iface self._canvas = iface.mapCanvas() self._layers = layerManager self._controller = controller self.RespHandler = ResponseHandler(self._iface, self._controller.uidm) self.highlighter = self._controller.highlighter self.af = {ft: AddressFactory.getInstance(FEEDS["AC"]) for ft in FeedType.reverse} self._features = [] self._sb = self._iface.mainWindow().statusBar() self.activate()
class UpdateReviewPosition(QgsMapToolIdentifyFeature): """ Tool for relocating AIMS Review Features """ def __init__(self, iface, layerManager, controller): """ Intialise Update Address Tool @param iface: QgisInterface Abstract base class defining interfaces exposed by QgisApp @type iface: Qgisinterface Object @param layerManager: Plugins layer manager @type layerManager: AimsUI.LayerManager() @param controller: Instance of the plugins controller @type controller: AimsUI.AimsClient.Gui.Controller() """ QgsMapToolIdentify.__init__(self, iface.mapCanvas()) self._iface = iface self._controller = controller self._layers = layerManager self._canvas = iface.mapCanvas() self.RespHandler = ResponseHandler(self._iface, self._controller.uidm) self._currentRevItem = None def activate(self): """ Activate Update Review Position Tool """ QgsMapTool.activate(self) self._currentRevItem = self._controller.currentRevItem sb = self._iface.mainWindow().statusBar() sb.showMessage('Click map to select new position for review item') def deactivate(self): """ Deactivate Update Review Position Tool """ sb = self._iface.mainWindow().statusBar() sb.clearMessage() def setEnabled(self, enabled): """ When Tool related QAction is checked/unchecked Activate / Disable the tool respectively @param enabled: Tool enabled. Boolean value @type enabled: boolean """ self._enabled = enabled if enabled: self.activate() else: self.deactivate() def canvasReleaseEvent(self, mouseEvent): """ Identify the AIMS Feature(s) the user clicked @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self._iface.setActiveLayer(self._layers.addressLayer()) results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if self._currentRevItem: if self._currentRevItem._changeType in ('Retire', 'AddLineage' ): self._iface.messageBar().pushMessage("{} review items cannot be relocated".format(self._currentRevItem._changeType), level=QgsMessageBar.WARNING, duration = 5) return if len(results) == 0: coords = self.toMapCoordinates(QPoint(mouseEvent.x(), mouseEvent.y())) else: # Snapping. i.e Move to stack coords = results[0].mFeature.geometry().asPoint() coords = list(UiUtility.transform(self._iface, coords)) respId = int(time.time()) if self._currentRevItem._changeType in ('Add', 'Update'): feedType = FEEDS['AR'] self._currentRevItem._addressedObject_addressPositions[0].setCoordinates(coords) self._controller.uidm.repairAddress(self._currentRevItem, respId) else: feedType = FEEDS['GR'] changeId = self._currentRevItem._changeId self._currentRevItem = self._currentRevItem.meta.entities[0] self._currentRevItem._addressedObject_addressPositions[0].setCoordinates(coords) self._currentRevItem.setChangeId(changeId) self._controller.uidm.repairAddress(self._currentRevItem, respId) self.RespHandler.handleResp(respId, feedType) self._controller.setPreviousMapTool()
class MoveAddressTool(QgsMapToolIdentify): """ Tool for relocating AIMS Features """ # logging global uilog uilog = Logger.setup(lf="uiLog") def __init__(self, iface, layerManager, controller): """ Intialise Move Address Tool @param iface: QgisInterface Abstract base class defining interfaces exposed by QgisApp @type iface: Qgisinterface Object @param layerManager: Plugins layer manager @type layerManager: AimsUI.LayerManager() @param controller: Instance of the plugins controller @type controller: AimsUI.AimsClient.Gui.Controller() """ QgsMapToolIdentify.__init__(self, iface.mapCanvas()) self._iface = iface self._canvas = iface.mapCanvas() self._layers = layerManager self._controller = controller self.RespHandler = ResponseHandler(self._iface, self._controller.uidm) self.highlighter = self._controller.highlighter self.af = {ft: AddressFactory.getInstance(FEEDS["AC"]) for ft in FeedType.reverse} self._features = [] self._sb = self._iface.mainWindow().statusBar() self.activate() def activate(self): """ Activate Move Address Tool """ QgsMapTool.activate(self) self._sb.showMessage("Select feature to move") self.cursor = QCursor(Qt.CrossCursor) self.parent().setCursor(self.cursor) def deactivate(self): """ Deactivate Move Address Tool """ self._sb.clearMessage() def setEnabled(self, enabled): """ When Tool related QAction is checked/unchecked Activate / Disable respectively @param enabled: Tool enabled. Boolean value @type enabled: boolean """ self._enabled = enabled if enabled: self.activate() else: self.deactivate() def setMarker(self, coords): """ Place marker on canvas to indicate the feature to be moved @param coords: QgsPoint @type coords: QgsPoint """ self.highlighter.setAddress(coords) def hideMarker(self): """ Remove the marker from the canvas """ self.highlighter.hideAddress() def canvasReleaseEvent(self, mouseEvent): """ Identify the AIMS Feature(s) the user clicked @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self._iface.setActiveLayer(self._layers.addressLayer()) if mouseEvent.button() == Qt.LeftButton: results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) # Ensure feature list and highlighting is reset self._features = [] self.hideMarker() if len(results) == 0: return elif len(results) == 1: # Highlight feature coords = results[0].mFeature.geometry().asPoint() self.setMarker(coords) # create address object for feature. It is this obj properties that will be passed to API self._features.append( self._controller.uidm.singleFeatureObj(results[0].mFeature.attribute("addressId")) ) self._sb.showMessage("Right click for features new location") else: # Stacked points identifiedFeatures = [] coords = results[0].mFeature.geometry().asPoint() self.setMarker(coords) for i in range(0, len(results)): identifiedFeatures.append( dict( fullAddress=results[i].mFeature.attribute("fullAddress"), addressId=results[i].mFeature.attribute("addressId"), ) ) dlg = MoveAddressDialog(self._iface.mainWindow()) moveFeatures = dlg.selectFeatures(identifiedFeatures) if moveFeatures: # Form a list of Ids as selected by the user moveFeaturesIds = [d["addressId"] for d in moveFeatures] for featureId in moveFeaturesIds: self._features.append(self._controller.uidm.singleFeatureObj(featureId)) self._sb.showMessage("Right click for features new location") else: self._features = None # Right click for new position if mouseEvent.button() == Qt.RightButton: results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if self._features: if len(results) == 0: coords = self.toMapCoordinates(QPoint(mouseEvent.x(), mouseEvent.y())) else: # Snapping. i.e Move to stack coords = results[0].mFeature.geometry().asPoint() # set new coords for all selected features coords = list(UiUtility.transform(self._iface, coords)) for feature in self._features: # Hack to retrieve the properties missing on the # feature feed from the resolution feed < respId = int(time.time()) self._controller.uidm.supplementAddress(feature, respId) feature = self._controller.RespHandler.handleResp(respId, FEEDS["AR"], "supplement") # /> feature._addressedObject_addressPositions[0].setCoordinates(coords) if feature._codes_isMeshblockOverride != True: feature.setMeshblock(None) feature = self.af[FeedType.CHANGEFEED].cast(feature) respId = int(time.time()) self._controller.uidm.updateAddress(feature, respId) self.RespHandler.handleResp(respId, FEEDS["AC"]) self._features = [] self.hideMarker() self._sb.clearMessage()
class UpdateReviewPosition(QgsMapToolIdentifyFeature): """ Tool for relocating AIMS Review Features """ def __init__(self, iface, layerManager, controller): """ Intialise Update Address Tool @param iface: QgisInterface Abstract base class defining interfaces exposed by QgisApp @type iface: Qgisinterface Object @param layerManager: Plugins layer manager @type layerManager: AimsUI.LayerManager() @param controller: Instance of the plugins controller @type controller: AimsUI.AimsClient.Gui.Controller() """ QgsMapToolIdentify.__init__(self, iface.mapCanvas()) self._iface = iface self._controller = controller self._layers = layerManager self._canvas = iface.mapCanvas() self.RespHandler = ResponseHandler(self._iface, self._controller.uidm) self._currentRevItem = None def activate(self): """ Activate Update Review Position Tool """ QgsMapTool.activate(self) self._currentRevItem = self._controller.currentRevItem sb = self._iface.mainWindow().statusBar() sb.showMessage('Click map to select new position for review item') def deactivate(self): """ Deactivate Update Review Position Tool """ sb = self._iface.mainWindow().statusBar() sb.clearMessage() def setEnabled(self, enabled): """ When Tool related QAction is checked/unchecked Activate / Disable the tool respectively @param enabled: Tool enabled. Boolean value @type enabled: boolean """ self._enabled = enabled if enabled: self.activate() else: self.deactivate() def canvasReleaseEvent(self, mouseEvent): """ Identify the AIMS Feature(s) the user clicked @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self._iface.setActiveLayer(self._layers.addressLayer()) results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if self._currentRevItem: if self._currentRevItem._changeType in ('Retire', 'AddLineage'): self._iface.messageBar().pushMessage( "{} review items cannot be relocated".format( self._currentRevItem._changeType), level=QgsMessageBar.WARNING, duration=5) return if len(results) == 0: coords = self.toMapCoordinates( QPoint(mouseEvent.x(), mouseEvent.y())) else: # Snapping. i.e Move to stack coords = results[0].mFeature.geometry().asPoint() coords = list(UiUtility.transform(self._iface, coords)) respId = int(time.time()) if self._currentRevItem._changeType in ('Add', 'Update'): feedType = FEEDS['AR'] self._currentRevItem._addressedObject_addressPositions[ 0].setCoordinates(coords) self._controller.uidm.repairAddress(self._currentRevItem, respId) else: feedType = FEEDS['GR'] changeId = self._currentRevItem._changeId self._currentRevItem = self._currentRevItem.meta.entities[0] self._currentRevItem._addressedObject_addressPositions[ 0].setCoordinates(coords) self._currentRevItem.setChangeId(changeId) self._controller.uidm.repairAddress(self._currentRevItem, respId) self.RespHandler.handleResp(respId, feedType) self._controller.setPreviousMapTool()
class MoveAddressTool(QgsMapToolIdentify): """ Tool for relocating AIMS Features """ # logging global uilog uilog = Logger.setup(lf='uiLog') def __init__(self, iface, layerManager, controller): """ Intialise Move Address Tool @param iface: QgisInterface Abstract base class defining interfaces exposed by QgisApp @type iface: Qgisinterface Object @param layerManager: Plugins layer manager @type layerManager: AimsUI.LayerManager() @param controller: Instance of the plugins controller @type controller: AimsUI.AimsClient.Gui.Controller() """ QgsMapToolIdentify.__init__(self, iface.mapCanvas()) self._iface = iface self._canvas = iface.mapCanvas() self._layers = layerManager self._controller = controller self.RespHandler = ResponseHandler(self._iface, self._controller.uidm) self.highlighter = self._controller.highlighter self.afc = { ft: AddressFactory.getInstance(FEEDS['AC']) for ft in FeedType.reverse } self.aff = FeatureFactory.getInstance( FeedRef(FeatureType.ADDRESS, FeedType.FEATURES)) self._features = [] self._sb = self._iface.mainWindow().statusBar() self.activate() def activate(self): """ Activate Move Address Tool """ QgsMapTool.activate(self) self._sb.showMessage("Select feature to move") self.cursor = QCursor(Qt.CrossCursor) self.parent().setCursor(self.cursor) def deactivate(self): """ Deactivate Move Address Tool """ self._sb.clearMessage() def setEnabled(self, enabled): """ When Tool related QAction is checked/unchecked Activate / Disable respectively @param enabled: Tool enabled. Boolean value @type enabled: boolean """ self._enabled = enabled if enabled: self.activate() else: self.deactivate() def setMarker(self, coords): """ Place marker on canvas to indicate the feature to be moved @param coords: QgsPoint @type coords: QgsPoint """ self.highlighter.setAddress(coords) def hideMarker(self): """ Remove the marker from the canvas """ self.highlighter.hideAddress() def canvasReleaseEvent(self, mouseEvent): """ Identify the AIMS Feature(s) the user clicked @param mouseEvent: QtGui.QMouseEvent @type mouseEvent: QtGui.QMouseEvent """ self._iface.setActiveLayer(self._layers.addressLayer()) if mouseEvent.button() == Qt.LeftButton: results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) # Ensure feature list and highlighting is reset self._features = [] self.hideMarker() if len(results) == 0: return elif len(results) == 1: # Highlight feature coords = results[0].mFeature.geometry().asPoint() self.setMarker(coords) # create address object for feature. It is this obj properties that will be passed to API self._features.append( self._controller.uidm.singleFeatureObj( results[0].mFeature.attribute('addressId'))) self._sb.showMessage("Right click for features new location") else: # Stacked points identifiedFeatures = [] coords = results[0].mFeature.geometry().asPoint() self.setMarker(coords) for i in range(0, len(results)): identifiedFeatures.append( dict(fullAddress=results[i].mFeature.attribute( 'fullAddress'), addressId=results[i].mFeature.attribute( 'addressId'))) dlg = MoveAddressDialog(self._iface.mainWindow()) moveFeatures = dlg.selectFeatures(identifiedFeatures) if moveFeatures: # Form a list of Ids as selected by the user moveFeaturesIds = [d['addressId'] for d in moveFeatures] for featureId in moveFeaturesIds: self._features.append( self._controller.uidm.singleFeatureObj(featureId)) self._sb.showMessage( "Right click for features new location") else: self._features = None # Right click for new position if mouseEvent.button() == Qt.RightButton: results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if self._features: if len(results) == 0: coords = self.toMapCoordinates( QPoint(mouseEvent.x(), mouseEvent.y())) else: # Snapping. i.e Move to stack coords = results[0].mFeature.geometry().asPoint() # set new coords for all selected features coords = list(UiUtility.transform(self._iface, coords)) for feature in self._features: # Hack to retrieve the properties missing on the # feature feed from the resolution feed < respId = int(time.time()) self._controller.uidm.supplementAddress(feature, respId) feature = self._controller.RespHandler.handleResp( respId, FEEDS['AR'], 'supplement') # /> #feature.type = FEEDS['AF'] # below clone is part of a fix still to be tested clone = feature.clone(feature, self.aff.get()) clone._addressedObject_addressPositions[0].setCoordinates( coords, ) if clone._codes_isMeshblockOverride != True: clone.setMeshblock(None) respId = int(time.time()) clone = self.afc[FeedType.CHANGEFEED].cast(clone) self._controller.uidm.updateAddress(clone, respId) self.RespHandler.handleResp(respId, FEEDS['AC']) self._features = [] self.hideMarker() self._sb.clearMessage()