Skip to content

Commit 08b43aa

Browse files
committed
[relations] Support for .ui file dialogs
1 parent 81ea0c6 commit 08b43aa

File tree

1 file changed

+58
-36
lines changed

1 file changed

+58
-36
lines changed

src/gui/qgsattributedialog.cpp

+58-36
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,8 @@ void QgsAttributeDialog::init()
271271

272272
foreach ( const QgsRelation& relation, relations )
273273
{
274-
relation.id();
275-
276-
QWidget *myWidget = QgsRelationEditorWidget::createRelationEditor( relation, *mFeature, mContext );
274+
QWidget *myWidget = new QWidget();
275+
myWidget->setProperty( "qgisRelation", relation.id() );
277276
myWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
278277
if ( !myWidget )
279278
continue;
@@ -303,48 +302,71 @@ void QgsAttributeDialog::init()
303302
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
304303
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
305304
#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;
311305

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() )
313313
{
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() )
317317
{
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() )
330320
{
331-
foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
332-
{
333-
w->setEnabled( qobject_cast<QWebView *>( w ) ? true : false );
334-
}
321+
myWidget->setLayout( new QHBoxLayout() );
335322
}
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() )
337333
{
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 )
340337
{
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+
}
342368
}
343369
}
344-
else
345-
{
346-
myWidget->setEnabled( false );
347-
}
348370
}
349371
}
350372
}

0 commit comments

Comments
 (0)