コード例 #1
0
ファイル: field_toolbox.py プロジェクト: sgtrafael/DsgTools
 def updateAttributesAfterAdding(self):
     """
     Updates feature attributes according to the button configuration
     :return:
     """
     layer = self.sender()
     while self.addedFeatures:
         featureId = self.addedFeatures.pop()
         #begining the edit command
         # layer.beginEditCommand(self.tr("DSG Tools reclassification tool: adjusting feature's attributes"))
         #accessing added features
         editBuffer = layer.editBuffer()
         features = editBuffer.addedFeatures()
         for key in features:
             #just checking the newly added feature, the other I don't care
             if key == featureId:
                 feature = features[key]
                 #setting the attributes using the reclassification dictionary
                 self.setFeatureAttributes(feature, editBuffer)
                 # layer.endEditCommand()
                 if 'openForm' in self.reclassificationDict[self.category][
                         self.edgvClass][self.buttonName]['buttonProp']:
                     layer.updateFeature(feature)
                     form = QgsAttributeDialog(layer, feature, False)
                     form.setMode(int(QgsAttributeForm.SingleEditMode))
                     form.exec_()
                     layer.updateFeature(feature)
コード例 #2
0
 def createGeometry(self, geom):
     geom = self.reprojectRubberBand(geom)
     if geom:
         layer = self.canvas.currentLayer()
         feature = QgsFeature()
         fields = layer.pendingFields()
         feature.setGeometry(geom)
         feature.initAttributes(fields.count())
         provider = layer.dataProvider()
         for i in range(fields.count()):
             feature.setAttribute(i, provider.defaultValue(i))
         form = QgsAttributeDialog(layer, feature, False)
         form.setMode(QgsAttributeForm.AddFeatureMode)
         formSuppress = layer.editFormConfig().suppress()
         if formSuppress == QgsEditFormConfig.SuppressDefault:
             if self.getSuppressOptions(
             ):  #this is calculated every time because user can switch options while using tool
                 layer.addFeature(feature, True)
             else:
                 if not form.dialog().exec_():
                     feature.setAttributes(form.feature().attributes())
         elif formSuppress == QgsEditFormConfig.SuppressOff:
             if not form.dialog().exec_():
                 feature.setAttributes(form.feature().attributes())
         else:
             layer.addFeature(feature, True)
         layer.endEditCommand()
         self.canvas.refresh()
         self.initVariable()
コード例 #3
0
 def createGeometry(self, geom):
     geom = self.reprojectRubberBand(geom)
     if geom :
         layer = self.canvas.currentLayer()
         feature = QgsFeature()
         fields = layer.pendingFields()
         feature.setGeometry(geom)
         feature.initAttributes(fields.count())            
         provider = layer.dataProvider()              
         for i in range(fields.count()):
             feature.setAttribute(i, provider.defaultValue(i))                
         form = QgsAttributeDialog(layer, feature, False)
         form.setMode(QgsAttributeForm.AddFeatureMode)
         formSuppress = layer.editFormConfig().suppress()
         if formSuppress == QgsEditFormConfig.SuppressDefault:
             if self.getSuppressOptions(): #this is calculated every time because user can switch options while using tool
                 layer.addFeature(feature, True)
             else:
                 if not form.dialog().exec_():
                     feature.setAttributes(form.feature().attributes())
         elif formSuppress == QgsEditFormConfig.SuppressOff:
             if not form.dialog().exec_():
                 feature.setAttributes(form.feature().attributes())
         else:
             layer.addFeature(feature, True)
         layer.endEditCommand()
         self.canvas.refresh()
         self.initVariable()   
コード例 #4
0
 def addFeature(self, feature, layer, field, pointValue):
     fields = layer.fields()
     feature.initAttributes(fields.count())            
     provider = layer.dataProvider()             
     for i in range(fields.count()):
         value = provider.defaultValue(i) if fields[i].name() != field else pointValue
         if value:
             feature.setAttribute(i, value)                
     form = QgsAttributeDialog(layer, feature, False)
     form.setMode(QgsAttributeForm.AddFeatureMode)
     formSuppress = layer.editFormConfig().suppress()
     if formSuppress == QgsEditFormConfig.SuppressDefault:
         if self.getSuppressOptions(): #this is calculated every time because user can switch options while using tool
             layer.addFeature(feature, True)
         else:
             if not form.exec_():
                 feature.setAttributes(form.feature().attributes())
     elif formSuppress == QgsEditFormConfig.SuppressOff:
         if not form.exec_():
             feature.setAttributes(form.feature().attributes())
     else:
         layer.addFeature(feature, True)