Display current filename in progressbar when merging and add option to

select encoding for input files
This commit is contained in:
Alexander Bruy 2011-05-11 20:09:08 +03:00
parent 89fe2289f1
commit 8eac180f06

View File

@ -19,6 +19,7 @@ class Dialog( QDialog, Ui_Dialog ):
self.mergeThread = None
self.inputFiles = None
self.outFileName = None
self.inEncoding = None
self.btnOk = self.buttonBox.button( QDialogButtonBox.Ok )
self.btnClose = self.buttonBox.button( QDialogButtonBox.Close )
@ -26,6 +27,7 @@ class Dialog( QDialog, Ui_Dialog ):
QObject.connect( self.btnSelectDir, SIGNAL( "clicked()" ), self.inputDir )
QObject.connect( self.btnSelectFile, SIGNAL( "clicked()" ), self.outFile )
QObject.connect( self.chkListMode, SIGNAL( "stateChanged( int )" ), self.changeMode )
QObject.connect( self.leOutShape, SIGNAL( "editingFinished()" ), self.updateOutFile )
def inputDir( self ):
inDir = QFileDialog.getExistingDirectory( self,
@ -83,6 +85,11 @@ class Dialog( QDialog, Ui_Dialog ):
self.lblGeometry.setEnabled( True )
self.cmbGeometry.setEnabled( True )
def updateOutFile( self ):
self.outFileName = self.leOutShape.text()
settings = QSettings()
self.outEncoding = settings.value( "/UI/encoding" ).toString()
def reject( self ):
QDialog.reject( self )
@ -110,22 +117,27 @@ class Dialog( QDialog, Ui_Dialog ):
else:
baseDir = self.leInputDir.text()
# look for shapes with specified geometry type
self.inputFiles = ftools_utils.getShapesByGeometryType( baseDir, self.inputFiles, self.cmbGeometry.currentIndex() )
self.progressFiles.setRange( 0, self.inputFiles.count() )
outFile = QFile( self.outFileName )
if outFile.exists():
if not QgsVectorFileWriter.deleteShapeFile( self.outFileName ):
QMessageBox.warning( self, self.tr( "Delete error" ), self.tr( "Can't delete file %1" ).arg( outFileName ) )
return
# look for shapes with specified geometry type
self.inputFiles = ftools_utils.getShapesByGeometryType( baseDir, self.inputFiles, self.cmbGeometry.currentIndex() )
self.progressFiles.setRange( 0, self.inputFiles.count() )
if self.inEncoding == None:
self.inEncoding = "System"
QApplication.setOverrideCursor( QCursor( Qt.WaitCursor ) )
self.btnOk.setEnabled( False )
self.mergeThread = ShapeMergeThread( baseDir, self.inputFiles, self.outFileName, self.encoding )
self.mergeThread = ShapeMergeThread( baseDir, self.inputFiles, self.inEncoding, self.outFileName, self.encoding )
QObject.connect( self.mergeThread, SIGNAL( "rangeChanged( PyQt_PyObject )" ), self.setProgressRange )
QObject.connect( self.mergeThread, SIGNAL( "checkStarted()" ), self.setFeatureProgressFormat )
QObject.connect( self.mergeThread, SIGNAL( "checkFinished()" ), self.resetFeatureProgressFormat )
QObject.connect( self.mergeThread, SIGNAL( "fileNameChanged( PyQt_PyObject )" ), self.setShapeProgressFormat )
QObject.connect( self.mergeThread, SIGNAL( "featureProcessed()" ), self.featureProcessed )
QObject.connect( self.mergeThread, SIGNAL( "shapeProcessed()" ), self.shapeProcessed )
QObject.connect( self.mergeThread, SIGNAL( "processingFinished()" ), self.processingFinished )
@ -141,9 +153,18 @@ class Dialog( QDialog, Ui_Dialog ):
self.progressFeatures.setRange( 0, max )
self.progressFeatures.setValue( 0 )
def setFeatureProgressFormat( self ):
self.progressFeatures.setFormat( "Checking files: %p% ")
def resetFeatureProgressFormat( self ):
self.progressFeatures.setFormat( "%p% ")
def featureProcessed( self ):
self.progressFeatures.setValue( self.progressFeatures.value() + 1 )
def setShapeProgressFormat( self, fileName ):
self.progressFiles.setFormat( "%p% " + fileName )
def shapeProcessed( self ):
self.progressFiles.setValue( self.progressFiles.value() + 1 )
@ -152,7 +173,9 @@ class Dialog( QDialog, Ui_Dialog ):
if self.chkAddToCanvas.isChecked():
if not ftools_utils.addShapeToCanvas( unicode( self.outFileName ) ):
QMessageBox.warning( self, self.tr( "Merging" ), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.outFileName ) ) )
QMessageBox.warning( self, self.tr( "Merging" ),
self.tr( "Error loading output shapefile:\n%1" )
.arg( unicode( self.outFileName ) ) )
self.restoreGui()
@ -165,6 +188,7 @@ class Dialog( QDialog, Ui_Dialog ):
self.mergeThread = None
def restoreGui( self ):
self.progressFiles.setFormat( "%p%" )
self.progressFeatures.setRange( 0, 100 )
self.progressFeatures.setValue( 0 )
self.progressFiles.setValue( 0 )
@ -174,10 +198,11 @@ class Dialog( QDialog, Ui_Dialog ):
self.btnOk.setEnabled( True )
class ShapeMergeThread( QThread ):
def __init__( self, dir, shapes, outputFileName, outputEncoding ):
def __init__( self, dir, shapes, inputEncoding, outputFileName, outputEncoding ):
QThread.__init__( self, QThread.currentThread() )
self.baseDir = dir
self.shapes = shapes
self.inputEncoding = inputEncoding
self.outputFileName = outputFileName
self.outputEncoding = outputEncoding
@ -208,10 +233,12 @@ class ShapeMergeThread( QThread ):
if not newLayer.isValid():
continue
vprovider = newLayer.dataProvider()
vprovider.setEncoding( self.inputEncoding )
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
nFeat = vprovider.featureCount()
self.emit( SIGNAL( "rangeChanged( PyQt_PyObject )" ), nFeat )
self.emit( SIGNAL( "fileNameChanged( PyQt_PyObject )" ), fileName )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()