Skip to content
Permalink
Browse files

[relations] Support for .ui file dialogs

  • Loading branch information
m-kuhn committed Nov 28, 2013
1 parent 81ea0c6 commit 08b43aadd19414d267f86082f7d865f3abc179d1
Showing with 58 additions and 36 deletions.
  1. +58 −36 src/gui/qgsattributedialog.cpp
@@ -271,9 +271,8 @@ void QgsAttributeDialog::init()

foreach ( const QgsRelation& relation, relations )
{
relation.id();

QWidget *myWidget = QgsRelationEditorWidget::createRelationEditor( relation, *mFeature, mContext );
QWidget *myWidget = new QWidget();
myWidget->setProperty( "qgisRelation", relation.id() );
myWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
if ( !myWidget )
continue;
@@ -303,48 +302,71 @@ void QgsAttributeDialog::init()
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
#endif
for ( int fldIdx = 0; fldIdx < theFields.count(); ++fldIdx )
{
QList<QWidget *> myWidgets = mDialog->findChildren<QWidget*>( theFields[fldIdx].name() );
if ( myWidgets.isEmpty() )
continue;

foreach ( QWidget *myWidget, myWidgets )
// Get all widgets on the dialog
QList<QWidget *> myWidgets = mDialog->findChildren<QWidget*>();
Q_FOREACH( QWidget* myWidget, myWidgets )
{
// Check the widget's properties for a relation definition
QVariant vRel = myWidget->property( "qgisRelation" );
if ( vRel.isValid() )
{
QgsAttributeEditor::createAttributeEditor( mDialog, myWidget, mLayer, fldIdx, mFeature->attribute( fldIdx ), mContext );

if ( mLayer->editType( fldIdx ) != QgsVectorLayer::Immutable )
QgsRelationManager* relMgr = QgsProject::instance()->relationManager();
QgsRelation relation = relMgr->relation( vRel.toString() );
if ( relation.isValid() )
{
if ( mLayer->isEditable() && mLayer->fieldEditable( fldIdx ) )
{
myWidget->setEnabled( true );
}
else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::Photo )
{
foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
{
w->setEnabled( qobject_cast<QLabel *>( w ) ? true : false );
}
}
else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::WebView )
QgsRelationEditorWidget *relWdg = QgsRelationEditorWidget::createRelationEditor( relation, *mFeature, mContext, myWidget );
if ( !myWidget->layout() )
{
foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
{
w->setEnabled( qobject_cast<QWebView *>( w ) ? true : false );
}
myWidget->setLayout( new QHBoxLayout() );
}
else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::EditorWidgetV2 )
myWidget->layout()->addWidget( relWdg );
}
}
else
{
// No widget definition properties defined, check if the widget's
// objectName matches a field name
for ( int fldIdx = 0; fldIdx < theFields.count(); ++fldIdx )
{
if ( myWidget->objectName() == theFields[fldIdx].name() )
{
QgsEditorWidgetWrapper* ww = QgsEditorWidgetWrapper::fromWidget( myWidget );
if ( ww )
QgsAttributeEditor::createAttributeEditor( mDialog, myWidget, mLayer, fldIdx, mFeature->attribute( fldIdx ), mContext );

if ( mLayer->editType( fldIdx ) != QgsVectorLayer::Immutable )
{
ww->setEnabled( false );
if ( mLayer->isEditable() && mLayer->fieldEditable( fldIdx ) )
{
myWidget->setEnabled( true );
}
else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::Photo )
{
foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
{
w->setEnabled( qobject_cast<QLabel *>( w ) ? true : false );
}
}
else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::WebView )
{
foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
{
w->setEnabled( qobject_cast<QWebView *>( w ) ? true : false );
}
}
else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::EditorWidgetV2 )
{
QgsEditorWidgetWrapper* ww = QgsEditorWidgetWrapper::fromWidget( myWidget );
if ( ww )
{
ww->setEnabled( false );
}
}
else
{
myWidget->setEnabled( false );
}
}
}
else
{
myWidget->setEnabled( false );
}
}
}
}

0 comments on commit 08b43aa

Please sign in to comment.
You can’t perform that action at this time.