|
19 | 19 | #include "qgsattributeeditorcontext.h" |
20 | 20 | #include "qgsproject.h" |
21 | 21 | #include "qgsrelationmanager.h" |
22 | | - |
| 22 | +#undef QGISDEBUG |
| 23 | +#include "qgslogger.h" |
23 | 24 | #include <QWidget> |
24 | 25 |
|
25 | 26 | QgsRelationWidgetWrapper::QgsRelationWidgetWrapper( QgsVectorLayer *vl, const QgsRelation &relation, QWidget *editor, QWidget *parent ) |
@@ -48,22 +49,27 @@ void QgsRelationWidgetWrapper::setVisible( bool visible ) |
48 | 49 |
|
49 | 50 | void QgsRelationWidgetWrapper::aboutToSave() |
50 | 51 | { |
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 |
52 | 59 | const QgsAttributeEditorContext *ctx = &context(); |
53 | 60 | do |
54 | 61 | { |
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 | + ) |
57 | 65 | { |
| 66 | + QgsDebugMsg( QString( "- Layer %1 allready occured in the relation %2 as referenced layer" ).arg( mRelation.referencingLayer()->name(), ctx->relation().name() ) ); |
58 | 67 | return; |
59 | 68 | } |
60 | 69 | ctx = ctx->parentContext(); |
61 | 70 | } |
62 | 71 | while ( ctx ); |
63 | 72 |
|
64 | | - if ( !mRelation.isValid() || !widget() || !widget()->isVisible() ) |
65 | | - return; |
66 | | - |
67 | 73 | // Calling isModified() will emit a beforeModifiedCheck() |
68 | 74 | // signal that will make the embedded form to send any |
69 | 75 | // outstanding widget changes to the edit buffer |
@@ -139,7 +145,6 @@ void QgsRelationWidgetWrapper::initWidget( QWidget *editor ) |
139 | 145 | } |
140 | 146 | while ( ctx ); |
141 | 147 |
|
142 | | - |
143 | 148 | w->setRelations( mRelation, mNmRelation ); |
144 | 149 |
|
145 | 150 | mWidget = w; |
|
0 commit comments