Move isAuxiliaryField to QgsVectorLayer

This commit is contained in:
Blottiere Paul 2017-08-30 15:51:27 +01:00
parent 070cc6aac0
commit 4920a14aab
5 changed files with 44 additions and 28 deletions

View File

@ -1123,6 +1123,15 @@ Returns true if the provider has been modified since the last commit
:rtype: bool
%End
bool isAuxiliaryField( int index ) const;
%Docstring
Returns true if the field comes from the auxiliary layer,
false otherwise.
.. versionadded:: 3.0
:rtype: bool
%End
virtual void reload();
%Docstring
Synchronises with changes in the datasource

View File

@ -491,7 +491,7 @@ bool QgsMapToolLabel::labelIsRotatable( QgsVectorLayer *layer, const QgsPalLayer
if ( rotationCol >= 0 )
{
bool auxiliaryField = isAuxiliaryField( layer, rotationCol );
bool auxiliaryField = layer->isAuxiliaryField( rotationCol );
if ( !auxiliaryField )
{
@ -604,8 +604,8 @@ bool QgsMapToolLabel::diagramMoveable( QgsVectorLayer *vlayer, int &xCol, int &y
// defined columns come from auxiliary storage
if ( xCol >= 0 && yCol >= 0 )
{
bool xAuxiliaryField = isAuxiliaryField( vlayer, xCol );
bool yAuxiliaryField = isAuxiliaryField( vlayer, yCol );
bool xAuxiliaryField = vlayer->isAuxiliaryField( xCol );
bool yAuxiliaryField = vlayer->isAuxiliaryField( yCol );
if ( ! xAuxiliaryField || ! yAuxiliaryField )
{
@ -653,8 +653,8 @@ bool QgsMapToolLabel::labelMoveable( QgsVectorLayer *vlayer, const QgsPalLayerSe
// columns come from auxiliary storage
if ( xCol >= 0 && yCol >= 0 )
{
bool xAuxiliaryField = isAuxiliaryField( vlayer, xCol );
bool yAuxiliaryField = isAuxiliaryField( vlayer, yCol );
bool xAuxiliaryField = vlayer->isAuxiliaryField( xCol );
bool yAuxiliaryField = vlayer->isAuxiliaryField( yCol );
if ( ! xAuxiliaryField || ! yAuxiliaryField )
{
@ -691,7 +691,7 @@ bool QgsMapToolLabel::labelCanShowHide( QgsVectorLayer *vlayer, int &showCol ) c
showCol = vlayer->fields().lookupField( fieldname );
if ( showCol >= 0 )
{
bool auxiliaryField = isAuxiliaryField( vlayer, showCol );
bool auxiliaryField = vlayer->isAuxiliaryField( showCol );
if ( ! auxiliaryField )
{
@ -751,7 +751,7 @@ bool QgsMapToolLabel::diagramCanShowHide( QgsVectorLayer *vlayer, int &showCol )
if ( showCol >= 0 )
{
bool auxiliaryField = isAuxiliaryField( vlayer, showCol );
bool auxiliaryField = vlayer->isAuxiliaryField( showCol );
if ( !auxiliaryField )
{
@ -789,22 +789,3 @@ QgsMapToolLabel::LabelDetails::LabelDetails( const QgsLabelPosition &p )
settings = QgsPalLayerSettings();
}
}
bool QgsMapToolLabel::isAuxiliaryField( QgsVectorLayer *layer, int index ) const
{
bool auxiliaryField = false;
if ( !layer->auxiliaryLayer() )
return auxiliaryField;
if ( index >= 0 && layer->fields().fieldOrigin( index ) == QgsFields::OriginJoin )
{
int srcFieldIndex;
const QgsVectorLayerJoinInfo *info = layer->joinBuffer()->joinForFieldIndex( index, layer->fields(), srcFieldIndex );
if ( info && info->joinLayerId() == layer->auxiliaryLayer()->id() )
auxiliaryField = true;
}
return auxiliaryField;
}

View File

@ -175,8 +175,6 @@ class APP_EXPORT QgsMapToolLabel: public QgsMapTool
\since QGIS 2.16
*/
bool isPinned();
bool isAuxiliaryField( QgsVectorLayer *layer, int index ) const;
};
#endif // QGSMAPTOOLLABEL_H

View File

@ -2833,6 +2833,26 @@ bool QgsVectorLayer::isModified() const
return mEditBuffer && mEditBuffer->isModified();
}
bool QgsVectorLayer::isAuxiliaryField( int index ) const
{
bool auxiliaryField = false;
if ( !auxiliaryLayer() )
return auxiliaryField;
if ( index >= 0 && fields().fieldOrigin( index ) == QgsFields::OriginJoin )
{
int srcFieldIndex;
const QgsVectorLayerJoinInfo *info = mJoinBuffer->joinForFieldIndex( index, fields(), srcFieldIndex );
if ( info && info->joinLayerId() == auxiliaryLayer()->id() )
auxiliaryField = true;
}
return auxiliaryField;
}
void QgsVectorLayer::setRenderer( QgsFeatureRenderer *r )
{
if ( !isSpatial() )

View File

@ -1154,6 +1154,14 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Returns true if the provider has been modified since the last commit
virtual bool isModified() const;
/**
* Returns true if the field comes from the auxiliary layer,
* false otherwise.
*
* \since QGIS 3.0
*/
bool isAuxiliaryField( int index ) const;
//! Synchronises with changes in the datasource
virtual void reload() override;