Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ftools vector grid: UI improvements
  • Loading branch information
etiennesky committed Mar 28, 2012
1 parent 7f71a7d commit 8966899
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
35 changes: 33 additions & 2 deletions python/plugins/fTools/tools/doVectorGrid.py
Expand Up @@ -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():
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand All @@ -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()
Expand All @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/fTools/tools/frmVectorGrid.ui
Expand Up @@ -286,7 +286,7 @@
<string>Output grid as polygons</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
Expand All @@ -295,6 +295,9 @@
<property name="text">
<string>Output grid as lines</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down

0 comments on commit 8966899

Please sign in to comment.