Skip to content

Commit bfe2fbc

Browse files
committedSep 17, 2018
check for layers instead of relations
1 parent f7f36cd commit bfe2fbc

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed
 

‎src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#include "qgsattributeeditorcontext.h"
2020
#include "qgsproject.h"
2121
#include "qgsrelationmanager.h"
22-
22+
#undef QGISDEBUG
23+
#include "qgslogger.h"
2324
#include <QWidget>
2425

2526
QgsRelationWidgetWrapper::QgsRelationWidgetWrapper( QgsVectorLayer *vl, const QgsRelation &relation, QWidget *editor, QWidget *parent )
@@ -48,22 +49,27 @@ void QgsRelationWidgetWrapper::setVisible( bool visible )
4849

4950
void QgsRelationWidgetWrapper::aboutToSave()
5051
{
51-
// If this widget is already embedded by the same relation return
52+
if ( !mRelation.isValid() || !widget() || !widget()->isVisible() || mRelation.referencingLayer()->name() == mRelation.referencedLayer()->name() )
53+
return;
54+
55+
56+
QgsDebugMsg( QString( "2. Rel Name: %1, ParentLayer: %2 ChildLayer: %3" ).arg( mRelation.name(), mRelation.referencedLayer()->name(), mRelation.referencingLayer()->name() ) );
57+
58+
// If this widget is already embedded by the same relation, reduce functionality
5259
const QgsAttributeEditorContext *ctx = &context();
5360
do
5461
{
55-
if ( ( ctx->relation().name() == mRelation.name() && ctx->formMode() == QgsAttributeEditorContext::Embed )
56-
|| ( mNmRelation.isValid() && ctx->relation().name() == mNmRelation.name() ) )
62+
if ( ctx->relation().isValid() && ( ctx->relation().referencedLayer()->name() == mRelation.referencingLayer()->name()
63+
|| ctx->relation().referencedLayer()->name() == mNmRelation.referencedLayer()->name() )
64+
)
5765
{
66+
QgsDebugMsg( QString( "- Layer %1 allready occured in the relation %2 as referenced layer" ).arg( mRelation.referencingLayer()->name(), ctx->relation().name() ) );
5867
return;
5968
}
6069
ctx = ctx->parentContext();
6170
}
6271
while ( ctx );
6372

64-
if ( !mRelation.isValid() || !widget() || !widget()->isVisible() )
65-
return;
66-
6773
// Calling isModified() will emit a beforeModifiedCheck()
6874
// signal that will make the embedded form to send any
6975
// outstanding widget changes to the edit buffer
@@ -139,7 +145,6 @@ void QgsRelationWidgetWrapper::initWidget( QWidget *editor )
139145
}
140146
while ( ctx );
141147

142-
143148
w->setRelations( mRelation, mNmRelation );
144149

145150
mWidget = w;

0 commit comments

Comments
 (0)
Please sign in to comment.