Skip to content

Commit

Permalink
Move isAuxiliaryField to QgsVectorLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Oct 9, 2017
1 parent 070cc6a commit 4920a14
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 28 deletions.
9 changes: 9 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -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
Expand Down
33 changes: 7 additions & 26 deletions src/app/qgsmaptoollabel.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
}
2 changes: 0 additions & 2 deletions src/app/qgsmaptoollabel.h
Expand Up @@ -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
20 changes: 20 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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() )
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -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;

Expand Down

0 comments on commit 4920a14

Please sign in to comment.