Skip to content
Permalink
Browse files
avoid changes of the input layer when layers in canvas changed
git-svn-id: http://svn.osgeo.org/qgis/trunk@15713 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler committed Apr 15, 2011
1 parent adbcbcb commit 8a3a5a528d26195c0f39d3bf804e59340ace1b7d
Showing with 1,081 additions and 1,481 deletions.
  1. +1 −1 python/plugins/GdalTools/__init__.py
  2. +6 −7 python/plugins/GdalTools/tools/GdalTools_utils.py
  3. +26 −24 python/plugins/GdalTools/tools/doBuildVRT.py
  4. +23 −45 python/plugins/GdalTools/tools/doClipper.py
  5. +33 −25 python/plugins/GdalTools/tools/doContour.py
  6. +20 −25 python/plugins/GdalTools/tools/doDEM.py
  7. +25 −37 python/plugins/GdalTools/tools/doGrid.py
  8. +11 −15 python/plugins/GdalTools/tools/doInfo.py
  9. +19 −12 python/plugins/GdalTools/tools/doMerge.py
  10. +17 −21 python/plugins/GdalTools/tools/doNearBlack.py
  11. +17 −31 python/plugins/GdalTools/tools/doOverview.py
  12. +38 −52 python/plugins/GdalTools/tools/doPctRgb.py
  13. +19 −22 python/plugins/GdalTools/tools/doPolygonize.py
  14. +24 −30 python/plugins/GdalTools/tools/doProjection.py
  15. +17 −20 python/plugins/GdalTools/tools/doProximity.py
  16. +25 −35 python/plugins/GdalTools/tools/doRasterize.py
  17. +30 −45 python/plugins/GdalTools/tools/doRgbPct.py
  18. +16 −20 python/plugins/GdalTools/tools/doSieve.py
  19. +16 −10 python/plugins/GdalTools/tools/doTileIndex.py
  20. +32 −51 python/plugins/GdalTools/tools/doTranslate.py
  21. +45 −70 python/plugins/GdalTools/tools/doWarp.py
  22. +239 −0 python/plugins/GdalTools/tools/inOutSelector.py
  23. +54 −0 python/plugins/GdalTools/tools/inOutSelector.ui
  24. +17 −45 python/plugins/GdalTools/tools/widgetBuildVRT.ui
  25. +19 −79 python/plugins/GdalTools/tools/widgetClipper.ui
  26. +17 −51 python/plugins/GdalTools/tools/widgetContour.ui
  27. +34 −44 python/plugins/GdalTools/tools/widgetConvert.ui
  28. +18 −72 python/plugins/GdalTools/tools/widgetDEM.ui
  29. +15 −51 python/plugins/GdalTools/tools/widgetGrid.ui
  30. +14 −26 python/plugins/GdalTools/tools/widgetInfo.ui
  31. +15 −45 python/plugins/GdalTools/tools/widgetMerge.ui
  32. +17 −51 python/plugins/GdalTools/tools/widgetNearBlack.ui
  33. +13 −29 python/plugins/GdalTools/tools/widgetOverview.ui
  34. +2 −2 python/plugins/GdalTools/tools/widgetPluginBase.py
  35. +17 −51 python/plugins/GdalTools/tools/widgetPolygonize.ui
  36. +25 −35 python/plugins/GdalTools/tools/widgetProjection.ui
  37. +17 −44 python/plugins/GdalTools/tools/widgetProximity.ui
  38. +15 −49 python/plugins/GdalTools/tools/widgetRasterize.ui
  39. +17 −51 python/plugins/GdalTools/tools/widgetSieve.ui
  40. +21 −29 python/plugins/GdalTools/tools/widgetTileIndex.ui
  41. +15 −51 python/plugins/GdalTools/tools/widgetTranslate.ui
  42. +20 −78 python/plugins/GdalTools/tools/widgetWarp.ui
@@ -22,7 +22,7 @@ def name():
def description():
return "Integrate gdal tools into qgis"
def version():
return "Version 1.2.25"
return "Version 1.2.26"
def qgisMinimumVersion():
return "1.0"
def icon():
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-

# Utility functions
# -------------------------------------------------
# getLastUsedDir()
# setLastUsedDir( QString *file_or_dir path )
# -------------------------------------------------

from PyQt4.QtCore import *
from PyQt4.QtGui import *
@@ -143,9 +147,7 @@ def isRaster(self, layer):
return True

def getRasterLayers(self):
layers = filter( self.isRaster, LayerRegistry.layers )
names = map( lambda x: x.name(), layers )
return ( layers, names )
return filter( self.isRaster, LayerRegistry.layers )

@classmethod
def isVector(self, layer):
@@ -154,10 +156,7 @@ def isVector(self, layer):
return True

def getVectorLayers(self):
layers = filter( self.isVector, LayerRegistry.layers )
names = map( lambda x: x.name(), layers )
return ( layers, names )

return filter( self.isVector, LayerRegistry.layers )

def getRasterFiles(path, recursive=False):
rasters = QStringList()
@@ -18,65 +18,61 @@ def __init__(self, iface):
self.setupUi(self)
BasePluginWidget.__init__(self, self.iface, "gdalbuildvrt")

self.inSelector.setType( self.inSelector.FILE )
self.outSelector.setType( self.outSelector.FILE )
self.recurseCheck.hide()

self.setParamsStatus(
[
(self.inputFilesEdit, SIGNAL("textChanged(const QString &)")),
(self.outputFileEdit, SIGNAL("textChanged(const QString &)")),
(self.inSelector, SIGNAL("filenameChanged()")),
(self.outSelector, SIGNAL("filenameChanged()")),
(self.resolutionComboBox, SIGNAL("currentIndexChanged(int)"), self.resolutionCheck),
(self.srcNoDataSpin, SIGNAL("valueChanged(int)"), self.srcNoDataCheck, "1.7.0"),
(self.separateCheck, SIGNAL("stateChanged(int)"), None, "1.7.0"),
(self.inputDirCheck, SIGNAL("stateChanged(int)")),
(self.separateCheck, SIGNAL("stateChanged(int)"), None, "1.7.0"),
(self.recurseCheck, SIGNAL("stateChanged(int)"), self.inputDirCheck)
]
)

self.connect(self.selectInputFilesButton, SIGNAL("clicked()"), self.fillInputFilesEdit)
self.connect(self.selectOutputFileButton, SIGNAL("clicked()"), self.fillOutputFileEdit)
self.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
self.connect(self.outSelector, SIGNAL("selectClicked()"), self.fillOutputFileEdit)
self.connect( self.inputDirCheck, SIGNAL( "stateChanged( int )" ), self.switchToolMode )

def switchToolMode(self):
self.inputFilesEdit.clear()
self.recurseCheck.setVisible( self.inputDirCheck.isChecked() )
self.inSelector.clear()

if self.inputDirCheck.isChecked():
self.inFileLabel = self.label.text()
self.label.setText( QCoreApplication.translate( "GdalTools", "&Input directory" ) )

self.recurseCheck.show()

QObject.disconnect( self.selectInputFilesButton, SIGNAL( "clicked()" ), self.fillInputFilesEdit )
QObject.connect( self.selectInputFilesButton, SIGNAL( "clicked()" ), self.fillInputDir )
QObject.disconnect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
QObject.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputDir)
else:
self.label.setText( self.inFileLabel )

self.recurseCheck.hide()

QObject.connect( self.selectInputFilesButton, SIGNAL( "clicked()" ), self.fillInputFilesEdit )
QObject.disconnect( self.selectInputFilesButton, SIGNAL( "clicked()" ), self.fillInputDir )
QObject.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
QObject.disconnect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputDir)

def fillInputFilesEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
files = Utils.FileDialog.getOpenFileNames(self, self.tr( "Select the files for VRT" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter)
if files.isEmpty():
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

self.inputFilesEdit.setText(files.join(","))
self.inSelector.setFilename(files.join(","))

def fillOutputFileEdit(self):
outputFile = Utils.FileDialog.getSaveFileName(self, self.tr( "Select where to save the VRT" ), self.tr( "VRT (*.vrt)" ))
if outputFile.isEmpty():
return

self.outputFileEdit.setText(outputFile)
self.outSelector.setFilename(outputFile)

def fillInputDir( self ):
inputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the input directory with files for VRT" ))
if inputDir.isEmpty():
return

self.inputFilesEdit.setText( inputDir )
self.inSelector.setFilename( inputDir )

def getArguments(self):
arguments = QStringList()
@@ -88,15 +84,21 @@ def getArguments(self):
if self.srcNoDataCheck.isChecked():
arguments << "-srcnodata"
arguments << str(self.srcNoDataSpin.value())
arguments << self.outputFileEdit.text()
arguments << self.getOutputFileName()
if self.inputDirCheck.isChecked():
arguments << Utils.getRasterFiles( self.inputFilesEdit.text(), self.recurseCheck.isChecked() )
arguments << Utils.getRasterFiles( self.getInputFileName(), self.recurseCheck.isChecked() )
else:
arguments << self.inputFilesEdit.text().split(",")
arguments << self.getInputFileName()
return arguments

def getOutputFileName(self):
return self.outputFileEdit.text()
return self.outSelector.filename()

def getInputFileName(self):
if self.inputDirCheck.isChecked():
return self.inSelector.filename()
return self.inSelector.filename().split(",")

def addLayerIntoCanvas(self, fileInfo):
self.iface.addRasterLayer(fileInfo.filePath())

@@ -16,27 +16,26 @@ def __init__(self, iface):
self.canvas = self.iface.mapCanvas()

self.setupUi(self)
BasePluginWidget.__init__(self, self.iface, "gdal_translate", None, self.iface.mainWindow())
BasePluginWidget.__init__(self, self.iface, "gdal_translate", self.iface.mainWindow())

self.outSelector.setType( self.outSelector.FILE )
self.extentSelector.setCanvas(self.canvas)
self.outputFormat = Utils.fillRasterOutputFormat()
self.layers = []
self.maskLayers = []

self.setParamsStatus(
[
(self.inputLayerCombo, [SIGNAL("currentIndexChanged(int)"), SIGNAL("editTextChanged(const QString &)")] ),
(self.outputFileEdit, SIGNAL("textChanged(const QString &)")),
(self.inSelector, SIGNAL("filenameChanged()") ),
(self.outSelector, SIGNAL("filenameChanged()") ),
(self.noDataSpin, SIGNAL("valueChanged(int)"), self.noDataCheck, "1.7.0"),
(self.maskLayerCombo, [SIGNAL("currentIndexChanged(int)"), SIGNAL("editTextChanged(const QString &)")], self.maskModeRadio, "1.6.0"),
( self.extentSelector, [SIGNAL("selectionStarted()"), SIGNAL("newExtentDefined()")] ),
(self.maskSelector, SIGNAL("filenameChanged()"), self.maskModeRadio, "1.6.0"),
(self.extentSelector, [SIGNAL("selectionStarted()"), SIGNAL("newExtentDefined()")], self.extentModeRadio),
(self.modeStackedWidget, SIGNAL("currentIndexChanged(int)"))
]
)

self.connect(self.selectInputFileButton, SIGNAL("clicked()"), self.fillInputFileEdit)
self.connect(self.selectOutputFileButton, SIGNAL("clicked()"), self.fillOutputFileEdit)
self.connect(self.selectMaskFileButton, SIGNAL("clicked()"), self.fillMaskFileEdit)
self.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFileEdit)
self.connect(self.outSelector, SIGNAL("selectClicked()"), self.fillOutputFileEdit)
self.connect(self.maskSelector, SIGNAL("selectClicked()"), self.fillMaskFileEdit)
self.connect(self.extentSelector, SIGNAL("newExtentDefined()"), self.checkRun)
self.connect(self.extentSelector, SIGNAL("selectionStarted()"), self.checkRun)

@@ -64,27 +63,22 @@ def checkRun(self):
if self.extentModeRadio.isChecked():
enabler = self.extentSelector.isCoordsValid()
else:
enabler = not self.getMaskFileName().isEmpty()
enabler = not self.maskSelector.filename().isEmpty()
self.base.enableRun( enabler )

def onLayersChanged(self):
self.fillInputLayerCombo()
self.fillMaskLayerCombo()

def fillInputLayerCombo(self):
self.inputLayerCombo.clear()
( self.layers, names ) = Utils.LayerRegistry.instance().getRasterLayers()
self.inputLayerCombo.addItems( names )
self.inSelector.setLayers( Utils.LayerRegistry.instance().getRasterLayers() )
self.maskSelector.setLayers( filter( lambda x: x.geometryType() == QGis.Polygon, Utils.LayerRegistry.instance().getVectorLayers() ) )
self.checkRun()

def fillInputFileEdit( self ):
def fillInputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
inputFile = Utils.FileDialog.getOpenFileName( self, self.tr( "Select the input file for Translate" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
inputFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the input file for Polygonize" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
if inputFile.isEmpty():
return
Utils.FileFilter.setLastUsedRasterFilter( lastUsedFilter )
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

self.inputLayerCombo.setCurrentIndex(-1)
self.inputLayerCombo.setEditText( inputFile )
self.inSelector.setFilename(inputFile)

def fillOutputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
@@ -94,23 +88,16 @@ def fillOutputFileEdit(self):
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

self.outputFormat = Utils.fillRasterOutputFormat(lastUsedFilter, outputFile)
self.outputFileEdit.setText(outputFile)

def fillMaskLayerCombo(self):
self.maskLayerCombo.clear()
self.maskLayers = filter( lambda x: x.geometryType() == QGis.Polygon, Utils.LayerRegistry.instance().getVectorLayers()[0] )
self.maskLayerCombo.addItems( map( lambda x: x.name(), self.maskLayers ) )
self.checkRun()
self.outSelector.setFilename(outputFile)

def fillMaskFileEdit( self ):
def fillMaskFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedVectorFilter()
maskFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the mask file" ), Utils.FileFilter.allVectorsFilter(), lastUsedFilter )
if maskFile.isEmpty():
return
Utils.FileFilter.setLastUsedVectorFilter(lastUsedFilter)

self.maskLayerCombo.setCurrentIndex(-1)
self.maskLayerCombo.setEditText( maskFile )
self.maskSelector.setFilename(maskFile)
self.checkRun()

def getArguments(self):
@@ -132,8 +119,6 @@ def getArgsModeExtent(self):
arguments << str(rect.yMaximum())
arguments << str(rect.xMaximum())
arguments << str(rect.yMinimum())
if Utils.GdalConfig.version() >= "1.7.0":
arguments << "-q"
if not self.getOutputFileName().isEmpty():
arguments << "-of"
arguments << self.outputFormat
@@ -148,7 +133,7 @@ def getArgsModeMask(self):
arguments << "-dstnodata"
arguments << str(self.noDataSpin.value())
if self.maskModeRadio.isChecked():
mask = self.getMaskFileName()
mask = self.maskSelector.filename()
if not mask.isEmpty():
arguments << "-q"
arguments << "-cutline"
@@ -164,17 +149,10 @@ def getArgsModeMask(self):
return arguments

def getOutputFileName(self):
return self.outputFileEdit.text()
return self.outSelector.filename()

def getInputFileName(self):
if self.inputLayerCombo.currentIndex() >= 0:
return self.layers[self.inputLayerCombo.currentIndex()].source()
return self.inputLayerCombo.currentText()

def getMaskFileName(self):
if self.maskLayerCombo.currentIndex() >= 0:
return self.maskLayers[self.maskLayerCombo.currentIndex()].source()
return self.maskLayerCombo.currentText()
return self.inSelector.filename()

def addLayerIntoCanvas(self, fileInfo):
self.iface.addRasterLayer(fileInfo.filePath())
@@ -17,28 +17,28 @@ def __init__(self, iface):
self.setupUi(self)
BasePluginWidget.__init__(self, self.iface, "gdal_contour")

gdalVersion = Utils.GdalConfig.version()
self.useDirAsOutput = gdalVersion < "1.7.0"

self.outSelector.setType( self.outSelector.FILE )

# set the default QSpinBoxes value
self.intervalDSpinBox.setValue(10.0)

self.setParamsStatus(
[
(self.inputLayerCombo, [SIGNAL("currentIndexChanged(int)"), SIGNAL("editTextChanged(const QString &)")] ),
(self.outputDirEdit, SIGNAL("textChanged(const QString &)")),
(self.inSelector, SIGNAL("filenameChanged()") ),
(self.outSelector, SIGNAL("filenameChanged()")),
(self.intervalDSpinBox, SIGNAL("valueChanged(double)")),
(self.attributeEdit, SIGNAL("textChanged(const QString &)"), self.attributeCheck)
]
)

self.connect(self.selectInputFileButton, SIGNAL("clicked()"), self.fillInputFileEdit)
self.connect(self.selectOutputDirButton, SIGNAL("clicked()"), self.fillOutputDirEdit)
self.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFileEdit)
self.connect(self.outSelector, SIGNAL("selectClicked()"), self.fillOutputFileEdit)

def onLayersChanged(self):
self.fillInputLayerCombo()

def fillInputLayerCombo( self ):
self.inputLayerCombo.clear()
( self.layers, names ) = Utils.LayerRegistry.instance().getRasterLayers()
self.inputLayerCombo.addItems( names )
self.inSelector.setLayers( Utils.LayerRegistry.instance().getRasterLayers() )

def fillInputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
@@ -47,15 +47,22 @@ def fillInputFileEdit(self):
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

self.inputLayerCombo.setCurrentIndex(-1)
self.inputLayerCombo.setEditText(inputFile)
self.inSelector.setFilename(inputFile)

def fillOutputFileEdit(self):
if not self.useDirAsOutput:
lastUsedFilter = Utils.FileFilter.lastUsedVectorFilter()
outputFile, encoding = Utils.FileDialog.getOpenFileName(self, self.tr( "Select where to save the Contour output" ), Utils.FileFilter.allVectorsFilter(), lastUsedFilter, True)
else:
outputFile, encoding = Utils.FileDialog.getExistingDirectory(self, self.tr( "Select where to save the Contour output" ), True)

def fillOutputDirEdit(self):
outputDir, encoding = Utils.FileDialog.getExistingDirectory(self, self.tr( "Select where to save the Contour output" ), True)
if outputDir.isEmpty():
if outputFile.isEmpty():
return

self.outputDirEdit.setText(outputDir)
if not self.useDirAsOutput:
Utils.FileFilter.setLastUsedVectorFilter(lastUsedFilter)

self.outSelector.setFilename(outputFile)
self.lastEncoding = encoding

def getArguments(self):
@@ -66,20 +73,21 @@ def getArguments(self):
if True: # XXX in this moment the -i argument is not optional
arguments << "-i"
arguments << QString(str(self.intervalDSpinBox.value()))
if self.inputLayerCombo.currentIndex() >= 0:
arguments << self.layers[ self.inputLayerCombo.currentIndex() ].source()
else:
arguments << self.inputLayerCombo.currentText()
arguments << self.outputDirEdit.text()
arguments << self.getInputFileName()
arguments << self.outSelector.filename()
return arguments

def getInputFileName(self):
return self.inSelector.filename()

def getOutputFileName(self):
if self.outputDirEdit.text().isEmpty():
return ""
return self.outputDirEdit.text() + QDir.separator() + "contour.shp"
if self.useDirAsOutput:
fn = self.outSelector.filename()
return fn if fn.isEmpty() else fn + QDir.separator() + "contour.shp"
return self.outSelector.filename()

def addLayerIntoCanvas(self, fileInfo):
vl = self.iface.addVectorLayer(fileInfo.filePath(), "contour", "ogr")
vl = self.iface.addVectorLayer(fileInfo.filePath(), fileInfo.baseName(), "ogr")
if vl != None and vl.isValid():
if hasattr(self, 'lastEncoding'):
vl.setProviderEncoding(self.lastEncoding)

0 comments on commit 8a3a5a5

Please sign in to comment.