28 qDeleteAll( mChildren );
32 : d( new QgsEditFormConfigPrivate() )
39 d->mDataDefinedFieldProperties[ fieldName ] = properties;
44 return d->mDataDefinedFieldProperties.value( fieldName );
49 return QgsEditFormConfigPrivate::propertyDefinitions();
54 int fieldIndex = d->mFields.indexOf( widgetName );
55 if ( fieldIndex != -1 )
56 return d->mFields.at( fieldIndex ).editorWidgetSetup().config();
58 return d->mWidgetConfigs.value( widgetName );
61 void QgsEditFormConfig::setFields(
const QgsFields &fields )
66 if ( !d->mConfiguredRootContainer )
68 d->mInvisibleRootContainer->clear();
69 for (
int i = 0; i < d->mFields.size(); ++i )
72 d->mInvisibleRootContainer->addChildElement( field );
77 void QgsEditFormConfig::onRelationsLoaded()
93 if ( d->mFields.indexOf( widgetName ) != -1 )
95 QgsDebugMsg( QStringLiteral(
"Trying to set a widget config for a field on QgsEditFormConfig. Use layer->setEditorWidgetSetup() instead." ) );
100 d->mWidgetConfigs[widgetName] = config;
107 return d->mWidgetConfigs.remove( widgetName ) != 0;
132 d->mInvisibleRootContainer->addChildElement( data );
137 return d->mInvisibleRootContainer->children();
143 d->mInvisibleRootContainer->clear();
148 return d->mInvisibleRootContainer;
153 return d->mEditorLayout;
159 d->mEditorLayout = editorLayout;
162 d->mConfiguredRootContainer =
true;
167 return d->mUiFormPath;
172 if ( !ui.isEmpty() && !QUrl::fromUserInput( ui ).isLocalFile() )
191 if ( idx >= 0 && idx < d->mFields.count() )
196 return !d->mFieldEditables.value( d->mFields.at( idx ).name(),
true );
204 if ( idx >= 0 && idx < d->mFields.count() )
205 return d->mLabelOnTop.value( d->mFields.at( idx ).name(),
false );
212 if ( idx >= 0 && idx < d->mFields.count() )
215 d->mFieldEditables[ d->mFields.at( idx ).name()] = !
readOnly;
221 if ( idx >= 0 && idx < d->mFields.count() )
224 d->mLabelOnTop[ d->mFields.at( idx ).name()] = onTop;
230 return d->mInitFunction;
236 d->mInitFunction =
function;
252 return d->mInitFilePath;
258 d->mInitFilePath = filePath;
261 if ( !filePath.isEmpty() && !QUrl::fromUserInput( filePath ).isLocalFile() )
270 return d->mInitCodeSource;
281 return d->mSuppressForm;
287 d->mSuppressForm = s;
296 QDomNode editFormNode = node.namedItem( QStringLiteral(
"editform" ) );
297 if ( !editFormNode.isNull() )
299 QDomElement e = editFormNode.toElement();
300 const bool tolerantRemoteUrls = e.hasAttribute( QStringLiteral(
"tolerant" ) );
301 if ( !e.text().isEmpty() )
307 const bool localFile = QFileInfo::exists( uiFormPath );
308 if ( localFile || tolerantRemoteUrls || uiFormPath.startsWith( QLatin1String(
"http" ) ) )
313 QDomNode editFormInitNode = node.namedItem( QStringLiteral(
"editforminit" ) );
314 if ( !editFormInitNode.isNull() )
316 d->mInitFunction = editFormInitNode.toElement().text();
319 QDomNode editFormInitCodeSourceNode = node.namedItem( QStringLiteral(
"editforminitcodesource" ) );
320 if ( !editFormInitCodeSourceNode.isNull() && !editFormInitCodeSourceNode.toElement().text().isEmpty() )
325 QDomNode editFormInitCodeNode = node.namedItem( QStringLiteral(
"editforminitcode" ) );
326 if ( !editFormInitCodeNode.isNull() )
328 setInitCode( editFormInitCodeNode.toElement().text() );
336 int dotPos = d->mInitFunction.lastIndexOf(
'.' );
340 setInitCode( QStringLiteral(
"from %1 import %2\n" ).arg( d->mInitFunction.left( dotPos ), d->mInitFunction.mid( dotPos + 1 ) ) );
344 QDomNode editFormInitFilePathNode = node.namedItem( QStringLiteral(
"editforminitfilepath" ) );
345 if ( !editFormInitFilePathNode.isNull() && !editFormInitFilePathNode.toElement().text().isEmpty() )
350 QDomNode fFSuppNode = node.namedItem( QStringLiteral(
"featformsuppress" ) );
351 if ( fFSuppNode.isNull() )
357 QDomElement e = fFSuppNode.toElement();
362 QDomNode editorLayoutNode = node.namedItem( QStringLiteral(
"editorlayout" ) );
363 if ( editorLayoutNode.isNull() )
369 if ( editorLayoutNode.toElement().text() == QLatin1String(
"uifilelayout" ) )
373 else if ( editorLayoutNode.toElement().text() == QLatin1String(
"tablayout" ) )
383 d->mFieldEditables.clear();
384 QDomNodeList editableNodeList = node.namedItem( QStringLiteral(
"editable" ) ).toElement().childNodes();
385 for (
int i = 0; i < editableNodeList.size(); ++i )
387 QDomElement editableElement = editableNodeList.at( i ).toElement();
388 d->mFieldEditables.insert( editableElement.attribute( QStringLiteral(
"name" ) ),
static_cast< bool >( editableElement.attribute( QStringLiteral(
"editable" ) ).toInt() ) );
391 d->mLabelOnTop.clear();
392 QDomNodeList labelOnTopNodeList = node.namedItem( QStringLiteral(
"labelOnTop" ) ).toElement().childNodes();
393 for (
int i = 0; i < labelOnTopNodeList.size(); ++i )
395 QDomElement labelOnTopElement = labelOnTopNodeList.at( i ).toElement();
396 d->mLabelOnTop.insert( labelOnTopElement.attribute( QStringLiteral(
"name" ) ),
static_cast< bool >( labelOnTopElement.attribute( QStringLiteral(
"labelOnTop" ) ).toInt() ) );
400 QDomNodeList fieldDDPropertiesNodeList = node.namedItem( QStringLiteral(
"dataDefinedFieldProperties" ) ).toElement().childNodes();
401 for (
int i = 0; i < fieldDDPropertiesNodeList.size(); ++i )
403 QDomElement DDElement = fieldDDPropertiesNodeList.at( i ).toElement();
406 d->mDataDefinedFieldProperties.insert( DDElement.attribute( QStringLiteral(
"name" ) ), collection );
409 QDomNodeList widgetsNodeList = node.namedItem( QStringLiteral(
"widgets" ) ).toElement().childNodes();
411 for (
int i = 0; i < widgetsNodeList.size(); ++i )
413 QDomElement widgetElement = widgetsNodeList.at( i ).toElement();
416 d->mWidgetConfigs[widgetElement.attribute( QStringLiteral(
"name" ) )] = config.toMap();
420 QDomNode attributeEditorFormNode = node.namedItem( QStringLiteral(
"attributeEditorForm" ) );
421 if ( !attributeEditorFormNode.isNull() )
423 QDomNodeList attributeEditorFormNodeList = attributeEditorFormNode.toElement().childNodes();
425 if ( attributeEditorFormNodeList.size() )
427 d->mConfiguredRootContainer =
true;
430 for (
int i = 0; i < attributeEditorFormNodeList.size(); i++ )
432 QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();
435 if ( attributeEditorWidget )
436 addTab( attributeEditorWidget );
446 QDomDocument doc( node.ownerDocument() );
448 QDomElement efField = doc.createElement( QStringLiteral(
"editform" ) );
449 efField.setAttribute( QStringLiteral(
"tolerant" ), QStringLiteral(
"1" ) );
451 efField.appendChild( efText );
452 node.appendChild( efField );
454 QDomElement efiField = doc.createElement( QStringLiteral(
"editforminit" ) );
456 efiField.appendChild( doc.createTextNode(
initFunction() ) );
457 node.appendChild( efiField );
459 QDomElement eficsField = doc.createElement( QStringLiteral(
"editforminitcodesource" ) );
460 eficsField.appendChild( doc.createTextNode( QString::number(
initCodeSource() ) ) );
461 node.appendChild( eficsField );
463 QDomElement efifpField = doc.createElement( QStringLiteral(
"editforminitfilepath" ) );
465 node.appendChild( efifpField );
467 QDomElement eficField = doc.createElement( QStringLiteral(
"editforminitcode" ) );
468 eficField.appendChild( doc.createCDATASection(
initCode() ) );
469 node.appendChild( eficField );
471 QDomElement fFSuppElem = doc.createElement( QStringLiteral(
"featformsuppress" ) );
472 QDomText fFSuppText = doc.createTextNode( QString::number(
suppress() ) );
473 fFSuppElem.appendChild( fFSuppText );
474 node.appendChild( fFSuppElem );
477 QDomElement editorLayoutElem = doc.createElement( QStringLiteral(
"editorlayout" ) );
481 editorLayoutElem.appendChild( doc.createTextNode( QStringLiteral(
"uifilelayout" ) ) );
485 editorLayoutElem.appendChild( doc.createTextNode( QStringLiteral(
"tablayout" ) ) );
490 editorLayoutElem.appendChild( doc.createTextNode( QStringLiteral(
"generatedlayout" ) ) );
494 node.appendChild( editorLayoutElem );
497 if ( !
tabs().empty() && d->mConfiguredRootContainer )
499 QDomElement tabsElem = doc.createElement( QStringLiteral(
"attributeEditorForm" ) );
501 QDomElement rootElem = d->mInvisibleRootContainer->toDomElement( doc );
502 QDomNodeList elemList = rootElem.childNodes();
504 while ( !elemList.isEmpty() )
506 tabsElem.appendChild( elemList.at( 0 ) );
509 node.appendChild( tabsElem );
512 QDomElement editableElem = doc.createElement( QStringLiteral(
"editable" ) );
513 for (
auto editIt = d->mFieldEditables.constBegin(); editIt != d->mFieldEditables.constEnd(); ++editIt )
515 QDomElement fieldElem = doc.createElement( QStringLiteral(
"field" ) );
516 fieldElem.setAttribute( QStringLiteral(
"name" ), editIt.key() );
517 fieldElem.setAttribute( QStringLiteral(
"editable" ), editIt.value() ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
518 editableElem.appendChild( fieldElem );
520 node.appendChild( editableElem );
522 QDomElement labelOnTopElem = doc.createElement( QStringLiteral(
"labelOnTop" ) );
523 for (
auto labelOnTopIt = d->mLabelOnTop.constBegin(); labelOnTopIt != d->mLabelOnTop.constEnd(); ++labelOnTopIt )
525 QDomElement fieldElem = doc.createElement( QStringLiteral(
"field" ) );
526 fieldElem.setAttribute( QStringLiteral(
"name" ), labelOnTopIt.key() );
527 fieldElem.setAttribute( QStringLiteral(
"labelOnTop" ), labelOnTopIt.value() ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
528 labelOnTopElem.appendChild( fieldElem );
530 node.appendChild( labelOnTopElem );
533 QDomElement ddFieldPropsElement = doc.createElement( QStringLiteral(
"dataDefinedFieldProperties" ) );
534 for (
auto it = d->mDataDefinedFieldProperties.constBegin(); it != d->mDataDefinedFieldProperties.constEnd(); ++it )
536 QDomElement ddPropsElement = doc.createElement( QStringLiteral(
"field" ) );
537 ddPropsElement.setAttribute( QStringLiteral(
"name" ), it.key() );
539 ddFieldPropsElement.appendChild( ddPropsElement );
541 node.appendChild( ddFieldPropsElement );
543 QDomElement widgetsElem = doc.createElement( QStringLiteral(
"widgets" ) );
545 QMap<QString, QVariantMap >::ConstIterator configIt( d->mWidgetConfigs.constBegin() );
547 while ( configIt != d->mWidgetConfigs.constEnd() )
549 QDomElement widgetElem = doc.createElement( QStringLiteral(
"widget" ) );
550 widgetElem.setAttribute( QStringLiteral(
"name" ), configIt.key() );
554 configElem.setTagName( QStringLiteral(
"config" ) );
555 widgetElem.appendChild( configElem );
556 widgetsElem.appendChild( widgetElem );
560 node.appendChild( widgetsElem );
569 if ( elem.tagName() == QLatin1String(
"attributeEditorContainer" ) )
571 QColor backgroundColor( elem.attribute( QStringLiteral(
"backgroundColor" ), QString() ) );
573 elem.attribute( QStringLiteral(
"name" ) ) ), parent, backgroundColor );
575 int cc = elem.attribute( QStringLiteral(
"columnCount" ) ).toInt( &ok );
580 bool isGroupBox = elem.attribute( QStringLiteral(
"groupBox" ) ).toInt( &ok );
586 bool visibilityExpressionEnabled = elem.attribute( QStringLiteral(
"visibilityExpressionEnabled" ) ).toInt( &ok );
590 visibilityExpression.
setEnabled( visibilityExpressionEnabled );
591 visibilityExpression.
setData(
QgsExpression( elem.attribute( QStringLiteral(
"visibilityExpression" ) ) ) );
595 QDomNodeList childNodeList = elem.childNodes();
597 for (
int i = 0; i < childNodeList.size(); i++ )
599 QDomElement childElem = childNodeList.at( i ).toElement();
605 newElement = container;
607 else if ( elem.tagName() == QLatin1String(
"attributeEditorField" ) )
609 QString name = elem.attribute( QStringLiteral(
"name" ) );
610 int idx = d->mFields.lookupField( name );
613 else if ( elem.tagName() == QLatin1String(
"attributeEditorRelation" ) )
618 relElement->
setShowLinkButton( elem.attribute( QStringLiteral(
"showLinkButton" ), QStringLiteral(
"1" ) ).toInt() );
619 relElement->
setShowUnlinkButton( elem.attribute( QStringLiteral(
"showUnlinkButton" ), QStringLiteral(
"1" ) ).toInt() );
620 relElement->
setShowSaveChildEditsButton( elem.attribute( QStringLiteral(
"showSaveChildEditsButton" ), QStringLiteral(
"1" ) ).toInt() );
621 newElement = relElement;
623 else if ( elem.tagName() == QLatin1String(
"attributeEditorQmlElement" ) )
627 newElement = qmlElement;
629 else if ( elem.tagName() == QLatin1String(
"attributeEditorHtmlElement" ) )
633 newElement = htmlElement;
638 if ( elem.hasAttribute( QStringLiteral(
"showLabel" ) ) )
639 newElement->
setShowLabel( elem.attribute( QStringLiteral(
"showLabel" ) ).toInt() );
661 const auto childElements =
children();
667 element->mIsGroupBox = mIsGroupBox;
668 element->mColumnCount = mColumnCount;
669 element->mVisibilityExpression = mVisibilityExpression;
674 void QgsAttributeEditorContainer::saveConfiguration( QDomElement &elem )
const
676 elem.setAttribute( QStringLiteral(
"columnCount" ), mColumnCount );
677 elem.setAttribute( QStringLiteral(
"groupBox" ), mIsGroupBox ? 1 : 0 );
678 elem.setAttribute( QStringLiteral(
"visibilityExpressionEnabled" ), mVisibilityExpression.
enabled() ? 1 : 0 );
679 elem.setAttribute( QStringLiteral(
"visibilityExpression" ), mVisibilityExpression->expression() );
680 if ( mBackgroundColor.isValid() )
681 elem.setAttribute( QStringLiteral(
"backgroundColor" ), mBackgroundColor.name( ) );
682 const auto constMChildren = mChildren;
685 QDomDocument doc = elem.ownerDocument();
686 elem.appendChild( child->toDomElement( doc ) );
690 QString QgsAttributeEditorContainer::typeIdentifier()
const
692 return QStringLiteral(
"attributeEditorContainer" );