@@ -4942,6 +4942,67 @@ void QgsVectorLayer::createJoinCaches()
4942
4942
}
4943
4943
}
4944
4944
4945
+ void QgsVectorLayer::uniqueValues ( int index, QList<QVariant> &uniqueValues, int limit )
4946
+ {
4947
+ uniqueValues.clear ();
4948
+ if ( !mDataProvider )
4949
+ {
4950
+ return ;
4951
+ }
4952
+
4953
+ int maxProviderIndex;
4954
+ QgsVectorLayerJoinBuffer::maximumIndex ( mDataProvider ->fields (), maxProviderIndex );
4955
+
4956
+ if ( index <= maxProviderIndex && !mEditable ) // a provider field
4957
+ {
4958
+ return mDataProvider ->uniqueValues ( index , uniqueValues, limit );
4959
+ }
4960
+ else // a joined field?
4961
+ {
4962
+ if ( mJoinBuffer )
4963
+ {
4964
+ int indexOffset; // offset between layer index and joined provider index
4965
+ const QgsVectorJoinInfo* join = mJoinBuffer ->joinForFieldIndex ( index , maxProviderIndex, indexOffset );
4966
+ if ( join )
4967
+ {
4968
+ QgsVectorLayer* vl = dynamic_cast <QgsVectorLayer*>( QgsMapLayerRegistry::instance ()->mapLayer ( join->joinLayerId ) );
4969
+ if ( vl && vl->dataProvider () )
4970
+ {
4971
+ return vl->dataProvider ()->uniqueValues ( index - indexOffset, uniqueValues, limit );
4972
+ }
4973
+ }
4974
+ }
4975
+ }
4976
+
4977
+
4978
+ // the layer is editable, but in certain cases it can still be avoided going through all features
4979
+ if ( mDeletedFeatureIds .size () < 1 && mAddedFeatures .size () < 1 && !mDeletedAttributeIds .contains ( index ) && mChangedAttributeValues .size () < 1 )
4980
+ {
4981
+ return mDataProvider ->uniqueValues ( index , uniqueValues, limit );
4982
+ }
4983
+
4984
+ // we need to go through each feature
4985
+ QgsAttributeList attList;
4986
+ attList << index ;
4987
+
4988
+ select ( attList, QgsRectangle (), false , false );
4989
+
4990
+ QgsFeature f;
4991
+ QVariant currentValue;
4992
+ QHash<QString, QVariant> val;
4993
+ while ( nextFeature ( f ) )
4994
+ {
4995
+ currentValue = f.attributeMap ()[index ];
4996
+ val.insert ( currentValue.toString (), currentValue );
4997
+ if ( limit >= 0 && val.size () >= limit )
4998
+ {
4999
+ break ;
5000
+ }
5001
+ }
5002
+
5003
+ uniqueValues = val.values ();
5004
+ }
5005
+
4945
5006
void QgsVectorLayer::stopRendererV2 ( QgsRenderContext& rendererContext, QgsSingleSymbolRendererV2* selRenderer )
4946
5007
{
4947
5008
mRendererV2 ->stopRender ( rendererContext );
0 commit comments