@@ -39,7 +39,6 @@ def __init__(self):
3939 self .help_browser .setHtml (abouthtml )
4040
4141class maxpDialog (QtGui .QDialog , Ui_maxp_ui ):
42- DONE_MSG = "Finish"
4342
4443 def __init__ (self ):
4544 QtGui .QDialog .__init__ (self )
@@ -48,6 +47,10 @@ def __init__(self):
4847 QtCore .SIGNAL ("currentIndexChanged(int)" ),
4948 self .updateThresholdLimits )
5049
50+ self .connect (self .attribute_combo ,
51+ QtCore .SIGNAL ("currentIndexChanged(int)" ),
52+ self .checkAttrValues )
53+
5154 self .connect (self .layer_combo ,
5255 QtCore .SIGNAL ("currentIndexChanged(int)" ),
5356 self .updateAttrCombo )
@@ -77,18 +80,46 @@ def updateAttrCombo(self, newindex):
7780 self .attribute_combo .addItems (fieldNames )
7881 self .threshold_attr_combo .addItems (fieldNames2 )
7982
83+ def checkAttrValues (self , newindex ):
84+ if newindex > - 1 :
85+ attributeName = self .attribute_combo .currentText ()
86+ self .checkAllValues (attributeName )
87+
88+ def checkAllValues (self , attributeName ):
89+ layerIndex = self .layer_combo .currentIndex ()
90+ fiterator = self .mc .layer (layerIndex ).dataProvider ().getFeatures ()
91+
92+ valid = True
93+ maximum = 0
94+ minimum = 99999
95+ for feature in fiterator :
96+ val = feature .attribute (attributeName )
97+ try :
98+ minimum = val if val < minimum else minimum
99+ maximum += val
100+ except TypeError :
101+ valid = False
102+
103+ if not valid :
104+ null_message = "Some values are missing.\n " + \
105+ "Check the Attribute Table for NULL or empty values.\n " + \
106+ "Column: " + str (attributeName ) + "\n " + \
107+ "Please update the Attribute Table in order to run Max-p."
108+
109+ # Showing a message box might be better to get the user's attention
110+ QtGui .QMessageBox .warning (self , "Clusterpy" , null_message )
111+ #self.showMessage("Clusterpy Error", "NULL or Empty Attrs",
112+ # level=QgsMessageBar.CRITICAL)
113+
114+ return minimum , maximum
115+
80116 def updateThresholdLimits (self , newindex ):
81117 if newindex > - 1 :
82118 layerIndex = self .layer_combo .currentIndex ()
83119 fiterator = self .mc .layer (layerIndex ).dataProvider ().getFeatures ()
84120 attributeName = self .threshold_attr_combo .currentText ()
85121
86- maximum = 0
87- minimum = 99999
88- for feature in fiterator :
89- val = feature .attribute (attributeName )
90- minimum = val if val < minimum else minimum
91- maximum += val
122+ minimum , maximum = self .checkAllValues (attributeName )
92123
93124 self .threshold_spin .setMinimum (minimum )
94125 self .threshold_spin .setMaximum (maximum )
@@ -145,8 +176,8 @@ def finishRun(self, success, outputmsg):
145176 self .okbutton .setEnabled (True )
146177 if success :
147178 self .addToCanvas ()
148- output_msg = "Success. New column added to attribute table. " + outputmsg
149- self .showMessage ("Clusterpy" , output_msg , duration = 0 )
179+ msg = "Success. New column added to attribute table. " + outputmsg
180+ self .showMessage ("Clusterpy" , msg , duration = 0 )
150181 else :
151182 self .showMessage ("Clusterpy Error" ,
152183 outputmsg ,
0 commit comments