1
+ # -*- coding: utf-8 -*-
1
2
from PyQt4 .QtCore import *
2
3
from PyQt4 .QtGui import *
3
4
from qgis .core import *
@@ -17,7 +18,7 @@ def __init__( self, iface, function ):
17
18
self .cancel_close = self .buttonBox_2 .button ( QDialogButtonBox .Close )
18
19
self .progressBar .setValue ( 0 )
19
20
self .partProgressBar .setValue ( 0 )
20
- self .partProgressBar .setEnabled ( False )
21
+ self .partProgressBar .setVisible ( False )
21
22
22
23
def keyPressEvent ( self , e ):
23
24
'''
@@ -27,11 +28,11 @@ def keyPressEvent( self, e ):
27
28
selection = self .lstUnique .selectedItems ()
28
29
items = QString ()
29
30
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 " )
32
33
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 " )
35
36
if not items .isEmpty ():
36
37
clip_board = QApplication .clipboard ()
37
38
clip_board .setText ( items )
@@ -125,26 +126,25 @@ def cancelThread( self ):
125
126
126
127
def runFinishedFromThread ( self , output ):
127
128
self .testThread .stop ()
128
-
129
129
result = output [ 0 ]
130
130
numRows = len ( result )
131
131
self .tblUnique .setRowCount ( numRows )
132
132
if self .myFunction in ( 1 , 2 ):
133
133
self .tblUnique .setColumnCount ( 1 )
134
134
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 )
137
137
else :
138
138
self .tblUnique .setColumnCount ( 2 )
139
139
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 ()
148
148
self .tblUnique .horizontalHeader ().setResizeMode ( 0 , QHeaderView .Stretch )
149
149
self .tblUnique .resizeRowsToContents ()
150
150
@@ -162,11 +162,11 @@ def runRangeFromThread( self, range_vals ):
162
162
def runPartStatusFromThread ( self , status ):
163
163
self .partProgressBar .setValue ( status )
164
164
if status >= self .part_max :
165
- self .partProgressBar .setEnabled ( False )
165
+ self .partProgressBar .setVisible ( False )
166
166
167
167
def runPartRangeFromThread ( self , range_vals ):
168
168
self .part_max = range_vals [ 1 ]
169
- self .partProgressBar .setEnabled ( True )
169
+ self .partProgressBar .setVisible ( True )
170
170
self .partProgressBar .setRange ( range_vals [ 0 ], range_vals [ 1 ] )
171
171
172
172
class visualThread ( QThread ):
@@ -230,7 +230,8 @@ def basic_statistics( self, vlayer, myField ):
230
230
first = True
231
231
nElement = 0
232
232
# 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' ):
234
235
fillVal = 0
235
236
emptyVal = 0
236
237
if self .mySelection : # only selected features
@@ -260,6 +261,7 @@ def basic_statistics( self, vlayer, myField ):
260
261
nFeat = vprovider .featureCount ()
261
262
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
262
263
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
264
+ vprovider .select ( allAttrs )
263
265
while vprovider .nextFeature ( feat ):
264
266
atMap = feat .attributeMap ()
265
267
lenVal = float ( len ( atMap [ index ].toString () ) )
@@ -290,14 +292,16 @@ def basic_statistics( self, vlayer, myField ):
290
292
lstStats .append ( self .tr ( "N:" ) + unicode ( nVal ) )
291
293
return ( lstStats , [] )
292
294
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
297
301
if self .mySelection : # only selected features
298
302
selection = vlayer .selectedFeatures ()
299
303
nFeat = vlayer .selectedFeatureCount ()
300
- uniqueVal = ftools_utils .getUniqueValuesCount ( vlayer , index , True )
304
+ uniqueVal = ftools_utils .getUniqueValuesCount ( vlayer , index , True )
301
305
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
302
306
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
303
307
for f in selection :
@@ -316,9 +320,10 @@ def basic_statistics( self, vlayer, myField ):
316
320
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
317
321
else : # there is no selection, process the whole layer
318
322
nFeat = vprovider .featureCount ()
319
- uniqueVal = ftools_utils .getUniqueValuesCount ( vlayer , index , False )
323
+ uniqueVal = ftools_utils .getUniqueValuesCount ( vlayer , index , False )
320
324
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
321
325
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
326
+ vprovider .select ( allAttrs )
322
327
while vprovider .nextFeature ( feat ):
323
328
atMap = feat .attributeMap ()
324
329
value = float ( atMap [ index ].toDouble ()[ 0 ] )
@@ -343,12 +348,12 @@ def basic_statistics( self, vlayer, myField ):
343
348
stdVal = math .sqrt ( stdVal / nVal )
344
349
cvVal = stdVal / meanVal
345
350
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 ) ]
352
357
lstStats = []
353
358
lstStats .append ( self .tr ( "Mean:" ) + unicode ( meanVal ) )
354
359
lstStats .append ( self .tr ( "StdDev:" ) + unicode ( stdVal ) )
@@ -411,6 +416,7 @@ def check_geometry( self, vlayer ):
411
416
nElement = 0
412
417
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
413
418
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
419
+
414
420
while vprovider .nextFeature ( feat ):
415
421
geom = QgsGeometry ( feat .geometry () )
416
422
nElement += 1
0 commit comments