Skip to content

Commit a44c1bf

Browse files
author
cfarmer
committed
Adds validators for numeric input text edits. Patch supplied by Alexander Bruy
git-svn-id: http://svn.osgeo.org/qgis/trunk@13312 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4010b60 commit a44c1bf

File tree

2 files changed

+56
-65
lines changed

2 files changed

+56
-65
lines changed

python/plugins/fTools/tools/doGeoprocessing.py

+52-65
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def __init__( self, iface, function ):
1212
QDialog.__init__( self )
1313
self.iface = iface
1414
self.setupUi( self )
15+
self.param.setValidator(QDoubleValidator(self.param))
1516
self.myFunction = function
1617
QObject.connect( self.btnBrowse, SIGNAL( "clicked()" ), self.outFile )
1718
QObject.connect( self.inShapeA, SIGNAL( "currentIndexChanged(QString)" ), self.checkA )
@@ -541,12 +542,14 @@ def dissolve( self, useField ):
541542
vproviderA = self.vlayerA.dataProvider()
542543
allAttrsA = vproviderA.attributeIndexes()
543544
fields = vproviderA.fields()
544-
writer = QgsVectorFileWriter( self.myName, self.myEncoding,
545+
writer = QgsVectorFileWriter( self.myName, self.myEncoding,
545546
fields, vproviderA.geometryType(), vproviderA.crs() )
546547
inFeat = QgsFeature()
547548
outFeat = QgsFeature()
548549
vproviderA.rewind()
549550
nElement = 0
551+
inGeom = QgsGeometry()
552+
geoms = []
550553
# there is selection in input layer
551554
if self.mySelectionA:
552555
nFeat = self.vlayerA.selectedFeatureCount()
@@ -556,24 +559,21 @@ def dissolve( self, useField ):
556559
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
557560
first = True
558561
for inFeat in selectionA:
559-
nElement += 1
562+
nElement += 0.5
560563
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
561564
if first:
562565
attrs = inFeat.attributeMap()
563-
tmpInGeom = QgsGeometry( inFeat.geometry() )
564-
outFeat.setGeometry( tmpInGeom )
566+
inGeom = QgsGeometry( inFeat.geometry() )
565567
first = False
566568
else:
567-
tmpInGeom = QgsGeometry( inFeat.geometry() )
568-
tmpOutGeom = QgsGeometry( outFeat.geometry() )
569-
try:
570-
tmpOutGeom = QgsGeometry( tmpOutGeom.combine( tmpInGeom ) )
571-
outFeat.setGeometry( tmpOutGeom )
572-
except:
573-
GEOS_EXCEPT = False
574-
continue
575-
outFeat.setAttributeMap( attrs )
576-
writer.addFeature( outFeat )
569+
tmp_geom = QgsGeometry( inFeat.geometry() )
570+
geoms.append(tmp_geom)
571+
outGeom = QgsGeometry(inGeom.combineCascaded(geoms))
572+
nElement += nFeat/2
573+
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
574+
outFeat.setGeometry(outGeom)
575+
outFeat.setAttributeMap(attrs)
576+
writer.addFeature(outFeat)
577577
else:
578578
unique = vproviderA.uniqueValues( int( self.myParam ) )
579579
nFeat = nFeat * len( unique )
@@ -584,31 +584,25 @@ def dissolve( self, useField ):
584584
add = False
585585
vproviderA.select( allAttrsA )
586586
vproviderA.rewind()
587-
for inFeat in selectionA:
588-
nElement += 1
587+
filtered = [feat for feat in selectionA if feat.attributeMap()[
588+
self.myParam].toString().trimmed() == item.toString().trimmed()]
589+
for inFeat in filtered:
590+
nElement += 0.5
589591
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
590592
atMap = inFeat.attributeMap()
591-
tempItem = atMap[ self.myParam ]
592-
if tempItem.toString().trimmed() == item.toString().trimmed():
593-
add = True
594-
if first:
595-
QgsGeometry( inFeat.geometry() )
596-
tmpInGeom = QgsGeometry( inFeat.geometry() )
597-
outFeat.setGeometry( tmpInGeom )
598-
first = False
599-
attrs = inFeat.attributeMap()
600-
else:
601-
tmpInGeom = QgsGeometry( inFeat.geometry() )
602-
tmpOutGeom = QgsGeometry( outFeat.geometry() )
603-
try:
604-
tmpOutGeom = QgsGeometry( tmpOutGeom.combine( tmpInGeom ) )
605-
outFeat.setGeometry( tmpOutGeom )
606-
except:
607-
GEOS_EXCEPT = False
608-
add = False
609-
if add:
610-
outFeat.setAttributeMap( attrs )
611-
writer.addFeature( outFeat )
593+
if first:
594+
inGeom = QgsGeometry( inFeat.geometry() )
595+
first = False
596+
attrs = inFeat.attributeMap()
597+
else:
598+
tmp_geom = QgsGeometry( inFeat.geometry() )
599+
geoms.append(tmp_geom)
600+
outGeom = QgsGeometry(inGeom.combineCascaded(geoms))
601+
nElement += nFeat/2
602+
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
603+
outFeat.setGeometry(outGeom)
604+
outFeat.setAttributeMap(attrs)
605+
writer.addFeature(outFeat)
612606
# there is no selection in input layer
613607
else:
614608
nFeat = vproviderA.featureCount()
@@ -617,58 +611,51 @@ def dissolve( self, useField ):
617611
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
618612
first = True
619613
while vproviderA.nextFeature( inFeat ):
620-
nElement += 1
614+
nElement += 0.5
621615
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
622616
if first:
623617
attrs = inFeat.attributeMap()
624-
tmpInGeom = QgsGeometry( inFeat.geometry() )
625-
outFeat.setGeometry( tmpInGeom )
618+
inGeom = QgsGeometry( inFeat.geometry() )
626619
first = False
627620
else:
628-
tmpInGeom = QgsGeometry( inFeat.geometry() )
629-
tmpOutGeom = QgsGeometry( outFeat.geometry() )
630-
try:
631-
tmpOutGeom = QgsGeometry( tmpOutGeom.combine( tmpInGeom ) )
632-
outFeat.setGeometry( tmpOutGeom )
633-
except:
634-
GEOS_EXCEPT = False
635-
continue
636-
outFeat.setAttributeMap( attrs )
637-
writer.addFeature( outFeat )
621+
tmp_geom = QgsGeometry( inFeat.geometry() )
622+
geoms.append(tmp_geom)
623+
outGeom = QgsGeometry(inGeom.combineCascaded(geoms))
624+
nElement += nFeat/2
625+
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
626+
outFeat.setGeometry(outGeom)
627+
outFeat.setAttributeMap(attrs)
628+
writer.addFeature(outFeat)
638629
else:
639630
unique = vproviderA.uniqueValues( int( self.myParam ) )
640631
nFeat = nFeat * len( unique )
641632
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
642633
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
643634
for item in unique:
635+
geoms = []
644636
first = True
645637
add = True
646638
vproviderA.select( allAttrsA )
647639
vproviderA.rewind()
648640
while vproviderA.nextFeature( inFeat ):
649-
nElement += 1
641+
nElement += 0.5
650642
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
651643
atMap = inFeat.attributeMap()
652644
tempItem = atMap[ self.myParam ]
653645
if tempItem.toString().trimmed() == item.toString().trimmed():
654646
if first:
655-
QgsGeometry( inFeat.geometry() )
656-
tmpInGeom = QgsGeometry( inFeat.geometry() )
657-
outFeat.setGeometry( tmpInGeom )
647+
inGeom = QgsGeometry( inFeat.geometry() )
658648
first = False
659649
attrs = inFeat.attributeMap()
660650
else:
661-
tmpInGeom = QgsGeometry( inFeat.geometry() )
662-
tmpOutGeom = QgsGeometry( outFeat.geometry() )
663-
try:
664-
tmpOutGeom = QgsGeometry( tmpOutGeom.combine( tmpInGeom ) )
665-
outFeat.setGeometry( tmpOutGeom )
666-
except:
667-
GEOS_EXCEPT = False
668-
add = False
669-
if add:
670-
outFeat.setAttributeMap( attrs )
671-
writer.addFeature( outFeat )
651+
tmp_geom = QgsGeometry( inFeat.geometry() )
652+
geoms.append(tmp_geoms)
653+
outGeom = QgsGeometry(inGeom.combineCascaded(geoms))
654+
nElement += nFeat/2
655+
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
656+
outFeat.setGeometry(outGeom)
657+
outFeat.setAttributeMap(attrs)
658+
writer.addFeature(outFeat)
672659
del writer
673660
return GEOS_EXCEPT, FEATURE_EXCEPT, True
674661

python/plugins/fTools/tools/doRegPoints.py

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def __init__(self, iface):
4444
QDialog.__init__(self)
4545
self.iface = iface
4646
self.setupUi(self)
47+
self.xMin.setValidator(QDoubleValidator(self.xMin))
48+
self.xMax.setValidator(QDoubleValidator(self.xMax))
49+
self.yMin.setValidator(QDoubleValidator(self.yMin))
50+
self.yMax.setValidator(QDoubleValidator(self.yMax))
4751
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
4852
self.setWindowTitle( self.tr("Regular points") )
4953
self.progressBar.setValue(0)

0 commit comments

Comments
 (0)