@@ -5003,6 +5003,114 @@ void QgsVectorLayer::uniqueValues( int index, QList<QVariant> &uniqueValues, int
5003
5003
uniqueValues = val.values ();
5004
5004
}
5005
5005
5006
+ QVariant QgsVectorLayer::minimumValue ( int index )
5007
+ {
5008
+ if ( !mDataProvider )
5009
+ {
5010
+ return QVariant ();
5011
+ }
5012
+
5013
+ int maxProviderIndex;
5014
+ QgsVectorLayerJoinBuffer::maximumIndex ( mDataProvider ->fields (), maxProviderIndex );
5015
+
5016
+ if ( index <= maxProviderIndex && !mEditable ) // a provider field
5017
+ {
5018
+ return mDataProvider ->minimumValue ( index );
5019
+ }
5020
+ else // a joined field?
5021
+ {
5022
+ int indexOffset; // offset between layer index and joined provider index
5023
+ const QgsVectorJoinInfo* join = mJoinBuffer ->joinForFieldIndex ( index , maxProviderIndex, indexOffset );
5024
+ if ( join )
5025
+ {
5026
+ QgsVectorLayer* vl = dynamic_cast <QgsVectorLayer*>( QgsMapLayerRegistry::instance ()->mapLayer ( join->joinLayerId ) );
5027
+ if ( vl )
5028
+ {
5029
+ return vl->minimumValue ( index );
5030
+ }
5031
+ }
5032
+ }
5033
+
5034
+ // the layer is editable, but in certain cases it can still be avoided going through all features
5035
+ if ( mDeletedFeatureIds .size () < 1 && mAddedFeatures .size () < 1 && !mDeletedAttributeIds .contains ( index ) && mChangedAttributeValues .size () < 1 )
5036
+ {
5037
+ return mDataProvider ->minimumValue ( index );
5038
+ }
5039
+
5040
+ // we need to go through each feature
5041
+ QgsAttributeList attList;
5042
+ attList << index ;
5043
+
5044
+ select ( attList, QgsRectangle (), false , false );
5045
+
5046
+ QgsFeature f;
5047
+ double minimumValue = std::numeric_limits<double >::max ();
5048
+ double currentValue = 0 ;
5049
+ while ( nextFeature ( f ) )
5050
+ {
5051
+ currentValue = f.attributeMap ()[index ].toDouble ();
5052
+ if ( currentValue < minimumValue )
5053
+ {
5054
+ minimumValue = currentValue;
5055
+ }
5056
+ }
5057
+ return QVariant ( minimumValue );
5058
+ }
5059
+
5060
+ QVariant QgsVectorLayer::maximumValue ( int index )
5061
+ {
5062
+ if ( !mDataProvider )
5063
+ {
5064
+ return QVariant ();
5065
+ }
5066
+
5067
+ int maxProviderIndex;
5068
+ QgsVectorLayerJoinBuffer::maximumIndex ( mDataProvider ->fields (), maxProviderIndex );
5069
+
5070
+ if ( index <= maxProviderIndex && !mEditable ) // a provider field
5071
+ {
5072
+ return mDataProvider ->maximumValue ( index );
5073
+ }
5074
+ else // a joined field?
5075
+ {
5076
+ int indexOffset; // offset between layer index and joined provider index
5077
+ const QgsVectorJoinInfo* join = mJoinBuffer ->joinForFieldIndex ( index , maxProviderIndex, indexOffset );
5078
+ if ( join )
5079
+ {
5080
+ QgsVectorLayer* vl = dynamic_cast <QgsVectorLayer*>( QgsMapLayerRegistry::instance ()->mapLayer ( join->joinLayerId ) );
5081
+ if ( vl )
5082
+ {
5083
+ return vl->maximumValue ( index );
5084
+ }
5085
+ }
5086
+ }
5087
+
5088
+ // the layer is editable, but in certain cases it can still be avoided going through all features
5089
+ if ( mDeletedFeatureIds .size () < 1 && mAddedFeatures .size () < 1 && !mDeletedAttributeIds .contains ( index ) && mChangedAttributeValues .size () < 1 )
5090
+ {
5091
+ return mDataProvider ->maximumValue ( index );
5092
+ }
5093
+
5094
+ // we need to go through each feature
5095
+ QgsAttributeList attList;
5096
+ attList << index ;
5097
+
5098
+ select ( attList, QgsRectangle (), false , false );
5099
+
5100
+ QgsFeature f;
5101
+ double maximumValue = -std::numeric_limits<double >::max ();
5102
+ double currentValue = 0 ;
5103
+ while ( nextFeature ( f ) )
5104
+ {
5105
+ currentValue = f.attributeMap ()[index ].toDouble ();
5106
+ if ( currentValue > maximumValue )
5107
+ {
5108
+ maximumValue = currentValue;
5109
+ }
5110
+ }
5111
+ return QVariant ( maximumValue );
5112
+ }
5113
+
5006
5114
void QgsVectorLayer::stopRendererV2 ( QgsRenderContext& rendererContext, QgsSingleSymbolRendererV2* selRenderer )
5007
5115
{
5008
5116
mRendererV2 ->stopRender ( rendererContext );
0 commit comments