1+ # -*- coding: utf-8 -*-
12from PyQt4 .QtCore import *
23from PyQt4 .QtGui import *
34from qgis .core import *
@@ -17,7 +18,7 @@ def __init__( self, iface, function ):
1718 self .cancel_close = self .buttonBox_2 .button ( QDialogButtonBox .Close )
1819 self .progressBar .setValue ( 0 )
1920 self .partProgressBar .setValue ( 0 )
20- self .partProgressBar .setEnabled ( False )
21+ self .partProgressBar .setVisible ( False )
2122
2223 def keyPressEvent ( self , e ):
2324 '''
@@ -27,11 +28,11 @@ def keyPressEvent( self, e ):
2728 selection = self .lstUnique .selectedItems ()
2829 items = QString ()
2930 if self .myFunction in ( 1 , 2 ):
30- for rec in range ( self .tblUnique .rowCount () ):
31- items .append ( self .tblUnique .item ( rec , 0 ).text () + "\n " )
31+ for rec in range ( self .tblUnique .rowCount () ):
32+ items .append ( self .tblUnique .item ( rec , 0 ).text () + "\n " )
3233 else :
33- for rec in range ( self .tblUnique .rowCount () ):
34- items .append ( self .tblUnique .item ( rec , 0 ).text () + ":" + self .tblUnique .item ( rec , 1 ).text () + "\n " )
34+ for rec in range ( self .tblUnique .rowCount () ):
35+ items .append ( self .tblUnique .item ( rec , 0 ).text () + ":" + self .tblUnique .item ( rec , 1 ).text () + "\n " )
3536 if not items .isEmpty ():
3637 clip_board = QApplication .clipboard ()
3738 clip_board .setText ( items )
@@ -125,26 +126,25 @@ def cancelThread( self ):
125126
126127 def runFinishedFromThread ( self , output ):
127128 self .testThread .stop ()
128-
129129 result = output [ 0 ]
130130 numRows = len ( result )
131131 self .tblUnique .setRowCount ( numRows )
132132 if self .myFunction in ( 1 , 2 ):
133133 self .tblUnique .setColumnCount ( 1 )
134134 for rec in range ( numRows ):
135- item = QTableWidgetItem ( result [ rec ] )
136- self .tblUnique .setItem ( rec , 0 , item )
135+ item = QTableWidgetItem ( result [ rec ] )
136+ self .tblUnique .setItem ( rec , 0 , item )
137137 else :
138138 self .tblUnique .setColumnCount ( 2 )
139139 for rec in range ( numRows ):
140- tmp = result [ rec ].split ( ":" )
141- item = QTableWidgetItem ( tmp [ 0 ] )
142- self .tblUnique .setItem ( rec , 0 , item )
143- item = QTableWidgetItem ( tmp [ 1 ] )
144- self .tblUnique .setItem ( rec , 1 , item )
145- self .tblUnique .setHorizontalHeaderLabels ( [ self .tr ("Parameter" ), self .tr ("Value" ) ] )
146- self .tblUnique .horizontalHeader ().setResizeMode ( 1 , QHeaderView .ResizeToContents )
147- self .tblUnique .horizontalHeader ().show ()
140+ tmp = result [ rec ].split ( ":" )
141+ item = QTableWidgetItem ( tmp [ 0 ] )
142+ self .tblUnique .setItem ( rec , 0 , item )
143+ item = QTableWidgetItem ( tmp [ 1 ] )
144+ self .tblUnique .setItem ( rec , 1 , item )
145+ self .tblUnique .setHorizontalHeaderLabels ( [ self .tr ("Parameter" ), self .tr ("Value" ) ] )
146+ self .tblUnique .horizontalHeader ().setResizeMode ( 1 , QHeaderView .ResizeToContents )
147+ self .tblUnique .horizontalHeader ().show ()
148148 self .tblUnique .horizontalHeader ().setResizeMode ( 0 , QHeaderView .Stretch )
149149 self .tblUnique .resizeRowsToContents ()
150150
@@ -162,11 +162,11 @@ def runRangeFromThread( self, range_vals ):
162162 def runPartStatusFromThread ( self , status ):
163163 self .partProgressBar .setValue ( status )
164164 if status >= self .part_max :
165- self .partProgressBar .setEnabled ( False )
165+ self .partProgressBar .setVisible ( False )
166166
167167 def runPartRangeFromThread ( self , range_vals ):
168168 self .part_max = range_vals [ 1 ]
169- self .partProgressBar .setEnabled ( True )
169+ self .partProgressBar .setVisible ( True )
170170 self .partProgressBar .setRange ( range_vals [ 0 ], range_vals [ 1 ] )
171171
172172class visualThread ( QThread ):
@@ -230,7 +230,8 @@ def basic_statistics( self, vlayer, myField ):
230230 first = True
231231 nElement = 0
232232 # determine selected field type
233- if ftools_utils .getFieldType ( vlayer , myField ) == 'String' :
233+ if ftools_utils .getFieldType ( vlayer , myField ) in (
234+ 'String' , 'varchar' , 'char' , 'text' ):
234235 fillVal = 0
235236 emptyVal = 0
236237 if self .mySelection : # only selected features
@@ -260,6 +261,7 @@ def basic_statistics( self, vlayer, myField ):
260261 nFeat = vprovider .featureCount ()
261262 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
262263 self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
264+ vprovider .select ( allAttrs )
263265 while vprovider .nextFeature ( feat ):
264266 atMap = feat .attributeMap ()
265267 lenVal = float ( len ( atMap [ index ].toString () ) )
@@ -290,14 +292,16 @@ def basic_statistics( self, vlayer, myField ):
290292 lstStats .append ( self .tr ( "N:" ) + unicode ( nVal ) )
291293 return ( lstStats , [] )
292294 else : # numeric field
293- stdVal = 0
294- cvVal = 0
295- rangeVal = 0
296- medianVal = 0
295+ stdVal = 0.00
296+ cvVal = 0.00
297+ rangeVal = 0.00
298+ medianVal = 0.00
299+ maxVal = 0.00
300+ minVal = 0.00
297301 if self .mySelection : # only selected features
298302 selection = vlayer .selectedFeatures ()
299303 nFeat = vlayer .selectedFeatureCount ()
300- uniqueVal = ftools_utils .getUniqueValuesCount ( vlayer , index , True )
304+ uniqueVal = ftools_utils .getUniqueValuesCount ( vlayer , index , True )
301305 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
302306 self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
303307 for f in selection :
@@ -316,9 +320,10 @@ def basic_statistics( self, vlayer, myField ):
316320 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
317321 else : # there is no selection, process the whole layer
318322 nFeat = vprovider .featureCount ()
319- uniqueVal = ftools_utils .getUniqueValuesCount ( vlayer , index , False )
323+ uniqueVal = ftools_utils .getUniqueValuesCount ( vlayer , index , False )
320324 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
321325 self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
326+ vprovider .select ( allAttrs )
322327 while vprovider .nextFeature ( feat ):
323328 atMap = feat .attributeMap ()
324329 value = float ( atMap [ index ].toDouble ()[ 0 ] )
@@ -343,12 +348,12 @@ def basic_statistics( self, vlayer, myField ):
343348 stdVal = math .sqrt ( stdVal / nVal )
344349 cvVal = stdVal / meanVal
345350 if nVal > 1 :
346- lstVal = values
347- lstVal .sort ()
348- if ( nVal % 2 ) == 0 :
349- medianVal = 0.5 * ( lstVal [ int ( ( nVal - 1 ) / 2 ) ] + lstVal [ int ( ( nVal ) / 2 ) ] )
350- else :
351- medianVal = lstVal [ int ( ( nVal + 1 ) / 2 ) ]
351+ lstVal = values
352+ lstVal .sort ()
353+ if ( nVal % 2 ) == 0 :
354+ medianVal = 0.5 * ( lstVal [ int ( ( nVal - 1 ) / 2 ) ] + lstVal [ int ( ( nVal ) / 2 ) ] )
355+ else :
356+ medianVal = lstVal [ int ( ( nVal + 1 ) / 2 ) ]
352357 lstStats = []
353358 lstStats .append ( self .tr ( "Mean:" ) + unicode ( meanVal ) )
354359 lstStats .append ( self .tr ( "StdDev:" ) + unicode ( stdVal ) )
@@ -411,6 +416,7 @@ def check_geometry( self, vlayer ):
411416 nElement = 0
412417 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
413418 self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
419+
414420 while vprovider .nextFeature ( feat ):
415421 geom = QgsGeometry ( feat .geometry () )
416422 nElement += 1
0 commit comments