Skip to content
Permalink
Browse files
ftools vector grid: UI improvements
  • Loading branch information
etiennesky committed Mar 28, 2012
1 parent 7f71a7d commit 8966899d22d6ccc39e02811d842073778918098e
Showing with 37 additions and 3 deletions.
  1. +33 −2 python/plugins/fTools/tools/doVectorGrid.py
  2. +4 −1 python/plugins/fTools/tools/frmVectorGrid.ui
@@ -59,6 +59,8 @@ def populateLayers( self ):
layermap = QgsMapLayerRegistry.instance().mapLayers()
for name, layer in layermap.iteritems():
self.inShape.addItem( unicode( layer.name() ) )
if layer == self.iface.activeLayer():
self.inShape.setCurrentIndex( self.inShape.count() -1 )

def offset(self, value):
if self.chkLock.isChecked():
@@ -140,7 +142,9 @@ def accept(self):
if self.rdoPolygons.isChecked(): polygon = True
else: polygon = False
self.outShape.clear()
QApplication.setOverrideCursor(Qt.WaitCursor)
self.compute( boundBox, xSpace, ySpace, polygon )
QApplication.restoreOverrideCursor()
addToTOC = QMessageBox.question(self, self.tr("Generate Vector Grid"), self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg(unicode(self.shapefileName)), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
if addToTOC == QMessageBox.Yes:
ftools_utils.addShapeToCanvas( self.shapefileName )
@@ -171,8 +175,13 @@ def compute( self, bound, xOffset, yOffset, polygon ):
outFeat = QgsFeature()
outGeom = QgsGeometry()
idVar = 0
self.progressBar.setRange( 0, 0 )
# self.progressBar.setRange( 0, 0 )
self.progressBar.setValue( 0 )
if not polygon:
# counters for progressbar - update every 5%
count = 0
count_max = (bound.yMaximum() - bound.yMinimum()) / yOffset
count_update = count_max * 0.10
y = bound.yMaximum()
while y >= bound.yMinimum():
pt1 = QgsPoint(bound.xMinimum(), y)
@@ -184,6 +193,15 @@ def compute( self, bound, xOffset, yOffset, polygon ):
writer.addFeature(outFeat)
y = y - yOffset
idVar = idVar + 1
count += 1
if int( math.fmod( count, count_update ) ) == 0:
prog = int( count / count_max * 50 )
self.progressBar.setValue( prog )
self.progressBar.setValue( 50 )
# counters for progressbar - update every 5%
count = 0
count_max = (bound.xMaximum() - bound.xMinimum()) / xOffset
count_update = count_max * 0.10
x = bound.xMinimum()
while x <= bound.xMaximum():
pt1 = QgsPoint(x, bound.yMaximum())
@@ -195,7 +213,15 @@ def compute( self, bound, xOffset, yOffset, polygon ):
writer.addFeature(outFeat)
x = x + xOffset
idVar = idVar + 1
count += 1
if int( math.fmod( count, count_update ) ) == 0:
prog = 50 + int( count / count_max * 50 )
self.progressBar.setValue( prog )
else:
# counters for progressbar - update every 5%
count = 0
count_max = (bound.yMaximum() - bound.yMinimum()) / yOffset
count_update = count_max * 0.05
y = bound.yMaximum()
while y >= bound.yMinimum():
x = bound.xMinimum()
@@ -216,7 +242,12 @@ def compute( self, bound, xOffset, yOffset, polygon ):
idVar = idVar + 1
x = x + xOffset
y = y - yOffset
self.progressBar.setRange( 0, 100 )
count += 1
if int( math.fmod( count, count_update ) ) == 0:
prog = int( count / count_max * 100 )

self.progressBar.setValue( 100 )
#self.progressBar.setRange( 0, 100 )
del writer

def outFile(self):
@@ -286,7 +286,7 @@
<string>Output grid as polygons</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@@ -295,6 +295,9 @@
<property name="text">
<string>Output grid as lines</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>

0 comments on commit 8966899

Please sign in to comment.