diff --git a/python/core/auto_generated/qgsattributeeditorelement.sip.in b/python/core/auto_generated/qgsattributeeditorelement.sip.in index 2f3531ae28a..16e81262add 100644 --- a/python/core/auto_generated/qgsattributeeditorelement.sip.in +++ b/python/core/auto_generated/qgsattributeeditorelement.sip.in @@ -348,6 +348,11 @@ Determines if the "unlink feature" button should be shown class QgsAttributeEditorQmlElement : QgsAttributeEditorElement { +%Docstring +An attribute editor widget that will represent arbitrary QML code. + +.. versionadded:: 3.4 +%End %TypeHeaderCode #include "qgsattributeeditorelement.h" @@ -355,8 +360,22 @@ class QgsAttributeEditorQmlElement : QgsAttributeEditorElement public: QgsAttributeEditorQmlElement( QgsAttributeEditorElement *parent ); + virtual QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const /Factory/; + + QString qmlCode() const; +%Docstring +The QML code that will be represented within this widget. + +.. versionadded:: 3.4 +%End + void setQmlCode( const QString &qmlCode ); +%Docstring +The QML code that will be represented within this widget. + +@param qmlCode +%End }; diff --git a/src/app/qgsattributesformproperties.cpp b/src/app/qgsattributesformproperties.cpp index 9b69fd74064..206f441728a 100644 --- a/src/app/qgsattributesformproperties.cpp +++ b/src/app/qgsattributesformproperties.cpp @@ -491,6 +491,11 @@ void QgsAttributesFormProperties::onAttributeSelectionChanged() mAttributeTypeDialog->setVisible( false ); break; } + case DnDTreeItemData::QmlWidget: + { + + break; + } } } @@ -572,6 +577,15 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid widgetDef = container; break; } + + case DnDTreeItemData::QmlWidget: + { + QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement( parent ); + element->setQmlCode( "ABC " ); + + widgetDef = element; + break; + } } widgetDef->setShowLabel( itemData.showLabel() ); diff --git a/src/core/qgsattributeeditorelement.cpp b/src/core/qgsattributeeditorelement.cpp index c786ad3412d..e64763ba346 100644 --- a/src/core/qgsattributeeditorelement.cpp +++ b/src/core/qgsattributeeditorelement.cpp @@ -151,6 +151,14 @@ void QgsAttributeEditorRelation::setShowUnlinkButton( bool showUnlinkButton ) mShowUnlinkButton = showUnlinkButton; } +QgsAttributeEditorElement *QgsAttributeEditorQmlElement::clone( QgsAttributeEditorElement *parent ) const +{ + QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement( parent ); + element->setQmlCode( mQmlCode ); + + return element; +} + QString QgsAttributeEditorQmlElement::qmlCode() const { return mQmlCode; diff --git a/src/core/qgsattributeeditorelement.h b/src/core/qgsattributeeditorelement.h index c64615b0a31..7baa0c63c2c 100644 --- a/src/core/qgsattributeeditorelement.h +++ b/src/core/qgsattributeeditorelement.h @@ -412,6 +412,11 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement bool mShowUnlinkButton = true; }; +/** + * An attribute editor widget that will represent arbitrary QML code. + * + * \since QGIS 3.4 + */ class CORE_EXPORT QgsAttributeEditorQmlElement : public QgsAttributeEditorElement { public: @@ -419,7 +424,20 @@ class CORE_EXPORT QgsAttributeEditorQmlElement : public QgsAttributeEditorElemen : QgsAttributeEditorElement( AeTypeQmlElement, "TODO NAME", parent ) {} + QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const override SIP_FACTORY; + + /** + * The QML code that will be represented within this widget. + * + * \since QGIS 3.4 + */ QString qmlCode() const; + + /** + * The QML code that will be represented within this widget. + * + * @param qmlCode + */ void setQmlCode( const QString &qmlCode ); private: diff --git a/src/gui/qgsattributeform.cpp b/src/gui/qgsattributeform.cpp index 588b1d91b68..7b3960546a8 100644 --- a/src/gui/qgsattributeform.cpp +++ b/src/gui/qgsattributeform.cpp @@ -1775,6 +1775,10 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt const QgsAttributeEditorQmlElement *elementDef = static_cast( widgetDef ); QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this ); + QTemporaryFile *qmlFile = new QTemporaryFile(); + qmlFile->write( elementDef->qmlCode().toUtf8() ); + qmlFile->setParent( qmlWrapper ); + qmlWrapper->setConfig( mLayer->editFormConfig().widgetConfig( "TODO NAME??" ) ); qmlWrapper->setContext( context );