Skip to content
Permalink
Browse files
refresh BuildVRT command when input layers changes, cleanup (follow 9…
  • Loading branch information
brushtyler committed Mar 10, 2012
1 parent 9da5d03 commit d6ea1a037ef3755f7989bbf4c44c320f12eeba43
Showing with 41 additions and 27 deletions.
  1. +33 −18 python/plugins/GdalTools/tools/doBuildVRT.py
  2. +3 −3 python/plugins/GdalTools/tools/widgetBuildVRT.ui
  3. +5 −6 python/plugins/GdalTools/tools/widgetPluginBase.py
@@ -3,7 +3,6 @@
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *

from ui_widgetBuildVRT import Ui_GdalToolsWidget as Ui_Widget
from widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
@@ -22,6 +21,7 @@ def __init__(self, iface):
self.inSelector.setType( self.inSelector.FILE )
self.outSelector.setType( self.outSelector.FILE )
self.recurseCheck.hide()
self.visibleRasterLayers = QStringList()

self.setParamsStatus(
[
@@ -32,14 +32,38 @@ def __init__(self, iface):
(self.inputDirCheck, SIGNAL("stateChanged(int)")),
(self.separateCheck, SIGNAL("stateChanged(int)"), None, "1.7.0"),
(self.allowProjDiffCheck, SIGNAL("stateChanged(int)"), None, "1.7.0"),
(self.recurseCheck, SIGNAL("stateChanged(int)"), self.inputDirCheck)
(self.recurseCheck, SIGNAL("stateChanged(int)"), self.inputDirCheck),
(self.inputSelLayersCheck, SIGNAL("stateChanged(int)"))
]
)

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 )
self.connect( self.useSelectedLayersCheck, SIGNAL( "stateChanged( int )" ), self.switchLayerMode )
self.connect( self.inputSelLayersCheck, SIGNAL( "stateChanged( int )" ), self.switchLayerMode )
self.connect( self.iface.mapCanvas(), SIGNAL( "stateChanged( int )" ), self.switchLayerMode )


def initialize(self):
# connect to mapCanvas.layerChanged() signal
self.connect(self.iface.mapCanvas(), SIGNAL("layersChanged()"), self.onVisibleLayersChanged)
BasePluginWidget.initialize(self)

def onClosing(self):
# disconnect from mapCanvas.layerChanged() signal
self.disconnect(self.iface.mapCanvas(), SIGNAL("layersChanged()"), self.onVisibleLayersChanged)
BasePluginWidget.onClosing(self)


def onVisibleLayersChanged(self):
# refresh list of visible raster layers
self.visibleRasterLayers = QStringList()
for layer in self.iface.mapCanvas().layers():
if Utils.LayerRegistry.isRaster( layer ):
self.visibleRasterLayers << layer.source()

# refresh the text in the command viewer
self.someValueChanged()

def switchToolMode(self):
self.recurseCheck.setVisible( self.inputDirCheck.isChecked() )
@@ -58,7 +82,7 @@ def switchToolMode(self):
QObject.disconnect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputDir)

def switchLayerMode(self):
enableInputFiles = not self.useSelectedLayersCheck.isChecked()
enableInputFiles = not self.inputSelLayersCheck.isChecked()
self.inputDirCheck.setEnabled( enableInputFiles )
self.inSelector.setEnabled( enableInputFiles )
self.recurseCheck.setEnabled( enableInputFiles )
@@ -96,13 +120,12 @@ def getArguments(self):
if self.allowProjDiffCheck.isChecked():
arguments << "-allow_projection_difference"
arguments << self.getOutputFileName()
if self.useSelectedLayersCheck.isChecked():
arguments << self.getInputFileNamesFromSelectedLayers()
if self.inputSelLayersCheck.isChecked():
arguments << self.visibleRasterLayers
elif self.inputDirCheck.isChecked():
arguments << Utils.getRasterFiles( self.getInputFileName(), self.recurseCheck.isChecked() )
else:
if self.inputDirCheck.isChecked():
arguments << Utils.getRasterFiles( self.getInputFileName(), self.recurseCheck.isChecked() )
else:
arguments << self.getInputFileName()
arguments << self.getInputFileName()
return arguments

def getOutputFileName(self):
@@ -113,14 +136,6 @@ def getInputFileName(self):
return self.inSelector.filename()
return self.inSelector.filename().split(",")

def getInputFileNamesFromSelectedLayers(self):
layers = iface.mapCanvas().layers()
files = list()
for layer in layers:
if layer.type() == QgsMapLayer.RasterLayer and layer.providerType() == "gdal":
files.append( str(layer.source()) )
return files

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

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>348</width>
<height>238</height>
<height>266</height>
</rect>
</property>
<property name="sizePolicy">
@@ -26,9 +26,9 @@
<enum>QLayout::SetNoConstraint</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="useSelectedLayersCheck">
<widget class="QCheckBox" name="inputSelLayersCheck">
<property name="text">
<string>Use selected layers for input</string>
<string>Use visible raster layers for input</string>
</property>
</widget>
</item>
@@ -30,20 +30,19 @@ def someValueChanged(self):
def onLayersChanged(self):
pass

def exec_(self):
def initialize(self):
if not self.initialized:
self.connect(Utils.LayerRegistry.instance(), SIGNAL("layersChanged"), self.onLayersChanged)
self.onLayersChanged()
self.someValueChanged()
self.initialized = True

def exec_(self):
self.initialize()
return self.base.exec_()

def show_(self):
if not self.initialized:
self.connect(Utils.LayerRegistry.instance(), SIGNAL("layersChanged"), self.onLayersChanged)
self.onLayersChanged()
self.someValueChanged()
self.initialized = True
self.initialize()
return self.base.show()

def setCommandViewerEnabled(self, enable):

0 comments on commit d6ea1a0

Please sign in to comment.