@@ -271,9 +271,8 @@ void QgsAttributeDialog::init()
271
271
272
272
foreach ( const QgsRelation& relation , relations )
273
273
{
274
- relation .id ();
275
-
276
- QWidget *myWidget = QgsRelationEditorWidget::createRelationEditor ( relation , *mFeature , mContext );
274
+ QWidget *myWidget = new QWidget ();
275
+ myWidget->setProperty ( " qgisRelation" , relation .id () );
277
276
myWidget->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
278
277
if ( !myWidget )
279
278
continue ;
@@ -303,48 +302,71 @@ void QgsAttributeDialog::init()
303
302
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
304
303
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
305
304
#endif
306
- for ( int fldIdx = 0 ; fldIdx < theFields.count (); ++fldIdx )
307
- {
308
- QList<QWidget *> myWidgets = mDialog ->findChildren <QWidget*>( theFields[fldIdx].name () );
309
- if ( myWidgets.isEmpty () )
310
- continue ;
311
305
312
- foreach ( QWidget *myWidget, myWidgets )
306
+ // Get all widgets on the dialog
307
+ QList<QWidget *> myWidgets = mDialog ->findChildren <QWidget*>();
308
+ Q_FOREACH ( QWidget* myWidget, myWidgets )
309
+ {
310
+ // Check the widget's properties for a relation definition
311
+ QVariant vRel = myWidget->property ( " qgisRelation" );
312
+ if ( vRel.isValid () )
313
313
{
314
- QgsAttributeEditor::createAttributeEditor ( mDialog , myWidget, mLayer , fldIdx, mFeature -> attribute ( fldIdx ), mContext );
315
-
316
- if ( mLayer -> editType ( fldIdx ) != QgsVectorLayer::Immutable )
314
+ QgsRelationManager* relMgr = QgsProject::instance ()-> relationManager ( );
315
+ QgsRelation relation = relMgr-> relation ( vRel. toString () );
316
+ if ( relation . isValid () )
317
317
{
318
- if ( mLayer ->isEditable () && mLayer ->fieldEditable ( fldIdx ) )
319
- {
320
- myWidget->setEnabled ( true );
321
- }
322
- else if ( mLayer ->editType ( fldIdx ) == QgsVectorLayer::Photo )
323
- {
324
- foreach ( QWidget *w, myWidget->findChildren <QWidget *>() )
325
- {
326
- w->setEnabled ( qobject_cast<QLabel *>( w ) ? true : false );
327
- }
328
- }
329
- else if ( mLayer ->editType ( fldIdx ) == QgsVectorLayer::WebView )
318
+ QgsRelationEditorWidget *relWdg = QgsRelationEditorWidget::createRelationEditor ( relation , *mFeature , mContext , myWidget );
319
+ if ( !myWidget->layout () )
330
320
{
331
- foreach ( QWidget *w, myWidget->findChildren <QWidget *>() )
332
- {
333
- w->setEnabled ( qobject_cast<QWebView *>( w ) ? true : false );
334
- }
321
+ myWidget->setLayout ( new QHBoxLayout () );
335
322
}
336
- else if ( mLayer ->editType ( fldIdx ) == QgsVectorLayer::EditorWidgetV2 )
323
+ myWidget->layout ()->addWidget ( relWdg );
324
+ }
325
+ }
326
+ else
327
+ {
328
+ // No widget definition properties defined, check if the widget's
329
+ // objectName matches a field name
330
+ for ( int fldIdx = 0 ; fldIdx < theFields.count (); ++fldIdx )
331
+ {
332
+ if ( myWidget->objectName () == theFields[fldIdx].name () )
337
333
{
338
- QgsEditorWidgetWrapper* ww = QgsEditorWidgetWrapper::fromWidget ( myWidget );
339
- if ( ww )
334
+ QgsAttributeEditor::createAttributeEditor ( mDialog , myWidget, mLayer , fldIdx, mFeature ->attribute ( fldIdx ), mContext );
335
+
336
+ if ( mLayer ->editType ( fldIdx ) != QgsVectorLayer::Immutable )
340
337
{
341
- ww->setEnabled ( false );
338
+ if ( mLayer ->isEditable () && mLayer ->fieldEditable ( fldIdx ) )
339
+ {
340
+ myWidget->setEnabled ( true );
341
+ }
342
+ else if ( mLayer ->editType ( fldIdx ) == QgsVectorLayer::Photo )
343
+ {
344
+ foreach ( QWidget *w, myWidget->findChildren <QWidget *>() )
345
+ {
346
+ w->setEnabled ( qobject_cast<QLabel *>( w ) ? true : false );
347
+ }
348
+ }
349
+ else if ( mLayer ->editType ( fldIdx ) == QgsVectorLayer::WebView )
350
+ {
351
+ foreach ( QWidget *w, myWidget->findChildren <QWidget *>() )
352
+ {
353
+ w->setEnabled ( qobject_cast<QWebView *>( w ) ? true : false );
354
+ }
355
+ }
356
+ else if ( mLayer ->editType ( fldIdx ) == QgsVectorLayer::EditorWidgetV2 )
357
+ {
358
+ QgsEditorWidgetWrapper* ww = QgsEditorWidgetWrapper::fromWidget ( myWidget );
359
+ if ( ww )
360
+ {
361
+ ww->setEnabled ( false );
362
+ }
363
+ }
364
+ else
365
+ {
366
+ myWidget->setEnabled ( false );
367
+ }
342
368
}
343
369
}
344
- else
345
- {
346
- myWidget->setEnabled ( false );
347
- }
348
370
}
349
371
}
350
372
}
0 commit comments