@@ -103,10 +103,14 @@ def accept(self):
103
103
outPath = self .outShape .text ()
104
104
self .compute (inName , inField , joinName , joinField , outPath , keep , useTable , self .progressBar )
105
105
self .outShape .clear ()
106
- addToTOC = QMessageBox .question (self , self .tr ("Join Attributes" ), self .tr ("Created output shapefile:\n %1\n \n Would you like to add the new layer to the TOC?" ).arg ( unicode (self .shapefileName ) ), QMessageBox .Yes , QMessageBox .No , QMessageBox .NoButton )
107
- if addToTOC == QMessageBox .Yes :
108
- if not ftools_utils .addShapeToCanvas ( unicode ( outPath ) ):
109
- QMessageBox .warning ( self , self .tr ("Geoprocessing" ), self .tr ( "Error loading output shapefile:\n %1" ).arg ( unicode ( outPath ) ))
106
+ if res :
107
+ addToTOC = QMessageBox .question (self , self .tr ("Join Attributes" ),
108
+ self .tr ("Created output shapefile:\n %1\n \n Would you like to add the new layer to the TOC?" )
109
+ .arg ( unicode (self .shapefileName ) ), QMessageBox .Yes , QMessageBox .No , QMessageBox .NoButton )
110
+ if addToTOC == QMessageBox .Yes :
111
+ if not ftools_utils .addShapeToCanvas ( unicode ( outPath ) ):
112
+ QMessageBox .warning ( self , self .tr ("Geoprocessing" ), self .tr ( "Error loading output shapefile:\n %1" )
113
+ .arg ( unicode ( outPath ) ))
110
114
self .progressBar .setValue (0 )
111
115
112
116
def outFile (self ):
@@ -171,12 +175,21 @@ def compute(self, inName, inField, joinName, joinField, outName, keep, useTable,
171
175
seq = range (0 , len (fieldList1 ) + len (fieldList2 ))
172
176
fieldList1 .extend (fieldList2 )
173
177
fieldList1 = dict (zip (seq , fieldList1 ))
178
+ # check for correct field names
179
+ longNames = ftools_utils .checkFieldNameLenght ( fieldList1 )
180
+ if not longNames .isEmpty ():
181
+ QMessageBox .warning ( self , self .tr ( 'Incorrect field names' ),
182
+ self .tr ( 'No output will be created.\n Following field names are longer then 10 characters:\n %1' )
183
+ .arg ( longNames .join ( '\n ' ) ) )
184
+ return False
174
185
sRs = provider1 .crs ()
175
186
progressBar .setValue (13 )
176
187
check = QFile (self .shapefileName )
177
188
if check .exists ():
178
189
if not QgsVectorFileWriter .deleteShapeFile (self .shapefileName ):
179
- return
190
+ QMessageBox .warning ( self , self .tr ( 'Error deleting shapefile' ),
191
+ self .tr ( "Can't delete existing shapefile\n %1" ).arg ( self .shapefileName ) )
192
+ return False
180
193
writer = QgsVectorFileWriter (self .shapefileName , self .encoding , fieldList1 , provider1 .geometryType (), sRs )
181
194
inFeat = QgsFeature ()
182
195
outFeat = QgsFeature ()
@@ -215,6 +228,7 @@ def compute(self, inName, inField, joinName, joinField, outName, keep, useTable,
215
228
nElement += 1
216
229
progressBar .setValue (nElement )
217
230
del writer
231
+ return True
218
232
219
233
def createFieldList (self , table , joinField ):
220
234
fieldList = {}
@@ -236,14 +250,3 @@ def createFieldList(self, table, joinField):
236
250
fieldList [item ] = field
237
251
item = item + 1
238
252
return (fieldList , index2 )
239
-
240
- def testForUniqueness (self , fieldList1 , fieldList2 ):
241
- changed = True
242
- while changed :
243
- changed = False
244
- for i in fieldList1 :
245
- for j in fieldList2 :
246
- if j .name () == i .name ():
247
- j = ftools_utils .createUniqueFieldName (j )
248
- changed = True
249
- return fieldList2
0 commit comments