Skip to content

Commit

Permalink
[relations] Support for .ui file dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 3, 2013
1 parent 81ea0c6 commit 08b43aa
Showing 1 changed file with 58 additions and 36 deletions.
94 changes: 58 additions & 36 deletions src/gui/qgsattributedialog.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
}
}
}
Expand Down

0 comments on commit 08b43aa

Please sign in to comment.