Yay, more QML!

This commit is contained in:
Matthias Kuhn 2018-08-17 14:03:34 +02:00 committed by signedav
parent 35898f9f0e
commit f41aaa79cb
5 changed files with 63 additions and 0 deletions

View File

@ -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
};

View File

@ -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() );

View File

@ -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;

View File

@ -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:

View File

@ -1775,6 +1775,10 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
const QgsAttributeEditorQmlElement *elementDef = static_cast<const QgsAttributeEditorQmlElement *>( 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 );