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 class QgsAttributeEditorQmlElement : QgsAttributeEditorElement
{ {
%Docstring
An attribute editor widget that will represent arbitrary QML code.
.. versionadded:: 3.4
%End
%TypeHeaderCode %TypeHeaderCode
#include "qgsattributeeditorelement.h" #include "qgsattributeeditorelement.h"
@ -355,8 +360,22 @@ class QgsAttributeEditorQmlElement : QgsAttributeEditorElement
public: public:
QgsAttributeEditorQmlElement( QgsAttributeEditorElement *parent ); QgsAttributeEditorQmlElement( QgsAttributeEditorElement *parent );
virtual QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const /Factory/;
QString qmlCode() const; QString qmlCode() const;
%Docstring
The QML code that will be represented within this widget.
.. versionadded:: 3.4
%End
void setQmlCode( const QString &qmlCode ); 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 ); mAttributeTypeDialog->setVisible( false );
break; break;
} }
case DnDTreeItemData::QmlWidget:
{
break;
}
} }
} }
@ -572,6 +577,15 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
widgetDef = container; widgetDef = container;
break; break;
} }
case DnDTreeItemData::QmlWidget:
{
QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement( parent );
element->setQmlCode( "ABC " );
widgetDef = element;
break;
}
} }
widgetDef->setShowLabel( itemData.showLabel() ); widgetDef->setShowLabel( itemData.showLabel() );

View File

@ -151,6 +151,14 @@ void QgsAttributeEditorRelation::setShowUnlinkButton( bool showUnlinkButton )
mShowUnlinkButton = showUnlinkButton; mShowUnlinkButton = showUnlinkButton;
} }
QgsAttributeEditorElement *QgsAttributeEditorQmlElement::clone( QgsAttributeEditorElement *parent ) const
{
QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement( parent );
element->setQmlCode( mQmlCode );
return element;
}
QString QgsAttributeEditorQmlElement::qmlCode() const QString QgsAttributeEditorQmlElement::qmlCode() const
{ {
return mQmlCode; return mQmlCode;

View File

@ -412,6 +412,11 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
bool mShowUnlinkButton = true; bool mShowUnlinkButton = true;
}; };
/**
* An attribute editor widget that will represent arbitrary QML code.
*
* \since QGIS 3.4
*/
class CORE_EXPORT QgsAttributeEditorQmlElement : public QgsAttributeEditorElement class CORE_EXPORT QgsAttributeEditorQmlElement : public QgsAttributeEditorElement
{ {
public: public:
@ -419,7 +424,20 @@ class CORE_EXPORT QgsAttributeEditorQmlElement : public QgsAttributeEditorElemen
: QgsAttributeEditorElement( AeTypeQmlElement, "TODO NAME", parent ) : 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; QString qmlCode() const;
/**
* The QML code that will be represented within this widget.
*
* @param qmlCode
*/
void setQmlCode( const QString &qmlCode ); void setQmlCode( const QString &qmlCode );
private: private:

View File

@ -1775,6 +1775,10 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
const QgsAttributeEditorQmlElement *elementDef = static_cast<const QgsAttributeEditorQmlElement *>( widgetDef ); const QgsAttributeEditorQmlElement *elementDef = static_cast<const QgsAttributeEditorQmlElement *>( widgetDef );
QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this ); 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->setConfig( mLayer->editFormConfig().widgetConfig( "TODO NAME??" ) );
qmlWrapper->setContext( context ); qmlWrapper->setContext( context );