Skip to content

Commit

Permalink
Check if join information is for auxiliary layer when filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Oct 9, 2017
1 parent cbd7973 commit 9fd80f9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
12 changes: 12 additions & 0 deletions python/core/qgsvectorlayerjoinbuffer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ Quick way to test if there is any join at all
:rtype: QgsFeature
%End

bool isAuxiliaryJoin( const QgsVectorLayerJoinInfo &info ) const;
%Docstring
Returns true if the join information is about auxiliary layer, false otherwise

\param info The join information

:return: true if the join information is about auxiliary layer, false otherwise

.. versionadded:: 3.0
:rtype: bool
%End

QgsVectorLayerJoinBuffer *clone() const /Factory/;
%Docstring
Create a copy of the join buffer
Expand Down
10 changes: 9 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "qgstaskmanager.h"
#include "qgsziputils.h"
#include "qgsbrowsermodel.h"
#include "qgsvectorlayerjoinbuffer.h"

#ifdef HAVE_3D
#include "qgsabstract3drenderer.h"
Expand Down Expand Up @@ -8635,7 +8636,14 @@ void QgisApp::layerSubsetString()
if ( !vlayer )
return;

if ( !vlayer->vectorJoins().isEmpty() )
bool joins = !vlayer->vectorJoins().isEmpty();
if ( vlayer->vectorJoins().size() == 1 )
{
QgsVectorLayerJoinInfo info = vlayer->vectorJoins()[0];
joins = !vlayer->joinBuffer()->isAuxiliaryJoin( info );
}

if ( joins )
{
if ( QMessageBox::question( nullptr, tr( "Filter on joined fields" ),
tr( "You are about to set a subset filter on a layer that has joined fields. "
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsvectorlayerjoinbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qgslogger.h"
#include "qgsproject.h"
#include "qgsvectordataprovider.h"
#include "qgsauxiliarystorage.h"

#include <QDomElement>

Expand Down Expand Up @@ -265,6 +266,9 @@ void QgsVectorLayerJoinBuffer::writeXml( QDomNode &layer_node, QDomDocument &doc
QList< QgsVectorLayerJoinInfo >::const_iterator joinIt = mVectorJoins.constBegin();
for ( ; joinIt != mVectorJoins.constEnd(); ++joinIt )
{
if ( isAuxiliaryJoin( *joinIt ) )
continue;

QDomElement joinElem = document.createElement( QStringLiteral( "join" ) );

joinElem.setAttribute( QStringLiteral( "targetFieldName" ), joinIt->targetFieldName() );
Expand Down Expand Up @@ -656,3 +660,13 @@ bool QgsVectorLayerJoinBuffer::deleteFeatures( const QgsFeatureIds &fids ) const

return true;
}

bool QgsVectorLayerJoinBuffer::isAuxiliaryJoin( const QgsVectorLayerJoinInfo &info ) const
{
const QgsAuxiliaryLayer *al = mLayer->auxiliaryLayer();

if ( al && al->id() == info.joinLayerId() )
return true;
else
return false;
}
11 changes: 11 additions & 0 deletions src/core/qgsvectorlayerjoinbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject, public QgsFeatureSi
*/
QgsFeature targetedFeatureOf( const QgsVectorLayerJoinInfo *info, const QgsFeature &feature ) const;

/**
* Returns true if the join information is about auxiliary layer, false otherwise
*
* \param info The join information
*
* \returns true if the join information is about auxiliary layer, false otherwise
*
* \since QGIS 3.0
*/
bool isAuxiliaryJoin( const QgsVectorLayerJoinInfo &info ) const;

/**
* Create a copy of the join buffer
* \since QGIS 2.6
Expand Down

0 comments on commit 9fd80f9

Please sign in to comment.