コード例 #1
0
    def canvasReleaseEvent(self, mouseEvent):
        self._feature = None
        self._iface.setActiveLayer(self._layers.addressLayer())
        results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer)
        
        if len(results) == 0: 
            return
        elif len(results) == 1:
            # initialise an address object and populate from selected feature
            self._feature = UiUtility.mapResultsToAddObj(results[0], self._controller)

        else: # Stacked points
            identifiedFeatures=[] 
            for i in range (0,len(results)):
                identifiedFeatures.append(dict(
                fullAddress=results[i].mFeature.attribute('fullAddress'),
                addressId= results[i].mFeature.attribute('addressId')))
                
            dlg = updateAddressDialog(self._iface.mainWindow())
            updFeatures = dlg.selectFeatures(identifiedFeatures)

            if updFeatures: 
                updFeatureIds = [d['addressId'] for d in updFeatures]

                for result in results:
                    if result.mFeature.attribute('addressId') in updFeatureIds:
                        self._feature = UiUtility.mapResultsToAddObj(result, self._controller)
                        break
        # Open form
        if self._feature:
            # highlight feature 
                        
            self.setMarker(results[0].mFeature.geometry().asPoint())
            UpdateAddressDialog.updateAddress(self._feature, self._layers, self._controller, self._iface.mainWindow())
            self._canvas.scene().removeItem(self._marker)
コード例 #2
0
 def canvasReleaseEvent(self, mouseEvent):
     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._canvas.scene().removeItem(self._marker)
         
         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(UiUtility.mapResultsToAddObj(results[0], self._controller))
             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 result in results:
                     if result.mFeature.attribute('addressId') in moveFeaturesIds:
                         self._features.append(UiUtility.mapResultsToAddObj(result, self._controller))
                                        
                 self._sb.showMessage("Right click for features new location")
                 
             else: 
                 self._features = None
                 self._canvas.scene().removeItem(self._marker)
     
     # 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 = UiUtility.transform(self._iface, coords)
             for feature in self._features:          
                     feature.set_x(coords[0])
                     feature.set_y(coords[1])  
                 
             payload = feature.aimsObject()
             valErrors = self._controller.updateFeature(payload)
         
             if len(valErrors) == 0:
                 pass #no errors
             else:
                 QMessageBox.warning(self._iface.mainWindow(),"Move Feature", valErrors +'\n'*2 + feature._fullAddress )
             
             self._features = []
             self._canvas.scene().removeItem(self._marker)
             self._sb.clearMessage()
             
         else: QMessageBox.warning(self._iface.mainWindow(),"Move Feature", "You must first select a feature to move")