Skip to content

Commit 4920a14

Browse files
committedOct 9, 2017
Move isAuxiliaryField to QgsVectorLayer
1 parent 070cc6a commit 4920a14

File tree

5 files changed

+44
-28
lines changed

5 files changed

+44
-28
lines changed
 

‎python/core/qgsvectorlayer.sip

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,15 @@ Returns true if the provider has been modified since the last commit
11231123
:rtype: bool
11241124
%End
11251125

1126+
bool isAuxiliaryField( int index ) const;
1127+
%Docstring
1128+
Returns true if the field comes from the auxiliary layer,
1129+
false otherwise.
1130+
1131+
.. versionadded:: 3.0
1132+
:rtype: bool
1133+
%End
1134+
11261135
virtual void reload();
11271136
%Docstring
11281137
Synchronises with changes in the datasource

‎src/app/qgsmaptoollabel.cpp

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ bool QgsMapToolLabel::labelIsRotatable( QgsVectorLayer *layer, const QgsPalLayer
491491

492492
if ( rotationCol >= 0 )
493493
{
494-
bool auxiliaryField = isAuxiliaryField( layer, rotationCol );
494+
bool auxiliaryField = layer->isAuxiliaryField( rotationCol );
495495

496496
if ( !auxiliaryField )
497497
{
@@ -604,8 +604,8 @@ bool QgsMapToolLabel::diagramMoveable( QgsVectorLayer *vlayer, int &xCol, int &y
604604
// defined columns come from auxiliary storage
605605
if ( xCol >= 0 && yCol >= 0 )
606606
{
607-
bool xAuxiliaryField = isAuxiliaryField( vlayer, xCol );
608-
bool yAuxiliaryField = isAuxiliaryField( vlayer, yCol );
607+
bool xAuxiliaryField = vlayer->isAuxiliaryField( xCol );
608+
bool yAuxiliaryField = vlayer->isAuxiliaryField( yCol );
609609

610610
if ( ! xAuxiliaryField || ! yAuxiliaryField )
611611
{
@@ -653,8 +653,8 @@ bool QgsMapToolLabel::labelMoveable( QgsVectorLayer *vlayer, const QgsPalLayerSe
653653
// columns come from auxiliary storage
654654
if ( xCol >= 0 && yCol >= 0 )
655655
{
656-
bool xAuxiliaryField = isAuxiliaryField( vlayer, xCol );
657-
bool yAuxiliaryField = isAuxiliaryField( vlayer, yCol );
656+
bool xAuxiliaryField = vlayer->isAuxiliaryField( xCol );
657+
bool yAuxiliaryField = vlayer->isAuxiliaryField( yCol );
658658

659659
if ( ! xAuxiliaryField || ! yAuxiliaryField )
660660
{
@@ -691,7 +691,7 @@ bool QgsMapToolLabel::labelCanShowHide( QgsVectorLayer *vlayer, int &showCol ) c
691691
showCol = vlayer->fields().lookupField( fieldname );
692692
if ( showCol >= 0 )
693693
{
694-
bool auxiliaryField = isAuxiliaryField( vlayer, showCol );
694+
bool auxiliaryField = vlayer->isAuxiliaryField( showCol );
695695

696696
if ( ! auxiliaryField )
697697
{
@@ -751,7 +751,7 @@ bool QgsMapToolLabel::diagramCanShowHide( QgsVectorLayer *vlayer, int &showCol )
751751

752752
if ( showCol >= 0 )
753753
{
754-
bool auxiliaryField = isAuxiliaryField( vlayer, showCol );
754+
bool auxiliaryField = vlayer->isAuxiliaryField( showCol );
755755

756756
if ( !auxiliaryField )
757757
{
@@ -789,22 +789,3 @@ QgsMapToolLabel::LabelDetails::LabelDetails( const QgsLabelPosition &p )
789789
settings = QgsPalLayerSettings();
790790
}
791791
}
792-
793-
bool QgsMapToolLabel::isAuxiliaryField( QgsVectorLayer *layer, int index ) const
794-
{
795-
bool auxiliaryField = false;
796-
797-
if ( !layer->auxiliaryLayer() )
798-
return auxiliaryField;
799-
800-
if ( index >= 0 && layer->fields().fieldOrigin( index ) == QgsFields::OriginJoin )
801-
{
802-
int srcFieldIndex;
803-
const QgsVectorLayerJoinInfo *info = layer->joinBuffer()->joinForFieldIndex( index, layer->fields(), srcFieldIndex );
804-
805-
if ( info && info->joinLayerId() == layer->auxiliaryLayer()->id() )
806-
auxiliaryField = true;
807-
}
808-
809-
return auxiliaryField;
810-
}

‎src/app/qgsmaptoollabel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ class APP_EXPORT QgsMapToolLabel: public QgsMapTool
175175
\since QGIS 2.16
176176
*/
177177
bool isPinned();
178-
179-
bool isAuxiliaryField( QgsVectorLayer *layer, int index ) const;
180178
};
181179

182180
#endif // QGSMAPTOOLLABEL_H

‎src/core/qgsvectorlayer.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,6 +2833,26 @@ bool QgsVectorLayer::isModified() const
28332833
return mEditBuffer && mEditBuffer->isModified();
28342834
}
28352835

2836+
2837+
bool QgsVectorLayer::isAuxiliaryField( int index ) const
2838+
{
2839+
bool auxiliaryField = false;
2840+
2841+
if ( !auxiliaryLayer() )
2842+
return auxiliaryField;
2843+
2844+
if ( index >= 0 && fields().fieldOrigin( index ) == QgsFields::OriginJoin )
2845+
{
2846+
int srcFieldIndex;
2847+
const QgsVectorLayerJoinInfo *info = mJoinBuffer->joinForFieldIndex( index, fields(), srcFieldIndex );
2848+
2849+
if ( info && info->joinLayerId() == auxiliaryLayer()->id() )
2850+
auxiliaryField = true;
2851+
}
2852+
2853+
return auxiliaryField;
2854+
}
2855+
28362856
void QgsVectorLayer::setRenderer( QgsFeatureRenderer *r )
28372857
{
28382858
if ( !isSpatial() )

‎src/core/qgsvectorlayer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,14 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
11541154
//! Returns true if the provider has been modified since the last commit
11551155
virtual bool isModified() const;
11561156

1157+
/**
1158+
* Returns true if the field comes from the auxiliary layer,
1159+
* false otherwise.
1160+
*
1161+
* \since QGIS 3.0
1162+
*/
1163+
bool isAuxiliaryField( int index ) const;
1164+
11571165
//! Synchronises with changes in the datasource
11581166
virtual void reload() override;
11591167

0 commit comments

Comments
 (0)
Please sign in to comment.