Skip to content

Commit f41aaa7

Browse files
m-kuhnsignedav
authored andcommittedSep 5, 2018
Yay, more QML!
1 parent 35898f9 commit f41aaa7

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed
 

‎python/core/auto_generated/qgsattributeeditorelement.sip.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,34 @@ Determines if the "unlink feature" button should be shown
348348

349349
class QgsAttributeEditorQmlElement : QgsAttributeEditorElement
350350
{
351+
%Docstring
352+
An attribute editor widget that will represent arbitrary QML code.
353+
354+
.. versionadded:: 3.4
355+
%End
351356

352357
%TypeHeaderCode
353358
#include "qgsattributeeditorelement.h"
354359
%End
355360
public:
356361
QgsAttributeEditorQmlElement( QgsAttributeEditorElement *parent );
357362

363+
virtual QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const /Factory/;
364+
365+
358366
QString qmlCode() const;
367+
%Docstring
368+
The QML code that will be represented within this widget.
369+
370+
.. versionadded:: 3.4
371+
%End
372+
359373
void setQmlCode( const QString &qmlCode );
374+
%Docstring
375+
The QML code that will be represented within this widget.
376+
377+
@param qmlCode
378+
%End
360379

361380
};
362381

‎src/app/qgsattributesformproperties.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ void QgsAttributesFormProperties::onAttributeSelectionChanged()
491491
mAttributeTypeDialog->setVisible( false );
492492
break;
493493
}
494+
case DnDTreeItemData::QmlWidget:
495+
{
496+
497+
break;
498+
}
494499

495500
}
496501
}
@@ -572,6 +577,15 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
572577
widgetDef = container;
573578
break;
574579
}
580+
581+
case DnDTreeItemData::QmlWidget:
582+
{
583+
QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement( parent );
584+
element->setQmlCode( "ABC " );
585+
586+
widgetDef = element;
587+
break;
588+
}
575589
}
576590

577591
widgetDef->setShowLabel( itemData.showLabel() );

‎src/core/qgsattributeeditorelement.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ void QgsAttributeEditorRelation::setShowUnlinkButton( bool showUnlinkButton )
151151
mShowUnlinkButton = showUnlinkButton;
152152
}
153153

154+
QgsAttributeEditorElement *QgsAttributeEditorQmlElement::clone( QgsAttributeEditorElement *parent ) const
155+
{
156+
QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement( parent );
157+
element->setQmlCode( mQmlCode );
158+
159+
return element;
160+
}
161+
154162
QString QgsAttributeEditorQmlElement::qmlCode() const
155163
{
156164
return mQmlCode;

‎src/core/qgsattributeeditorelement.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,32 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
412412
bool mShowUnlinkButton = true;
413413
};
414414

415+
/**
416+
* An attribute editor widget that will represent arbitrary QML code.
417+
*
418+
* \since QGIS 3.4
419+
*/
415420
class CORE_EXPORT QgsAttributeEditorQmlElement : public QgsAttributeEditorElement
416421
{
417422
public:
418423
QgsAttributeEditorQmlElement( QgsAttributeEditorElement *parent )
419424
: QgsAttributeEditorElement( AeTypeQmlElement, "TODO NAME", parent )
420425
{}
421426

427+
QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const override SIP_FACTORY;
428+
429+
/**
430+
* The QML code that will be represented within this widget.
431+
*
432+
* \since QGIS 3.4
433+
*/
422434
QString qmlCode() const;
435+
436+
/**
437+
* The QML code that will be represented within this widget.
438+
*
439+
* @param qmlCode
440+
*/
423441
void setQmlCode( const QString &qmlCode );
424442

425443
private:

‎src/gui/qgsattributeform.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,10 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
17751775
const QgsAttributeEditorQmlElement *elementDef = static_cast<const QgsAttributeEditorQmlElement *>( widgetDef );
17761776

17771777
QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this );
1778+
QTemporaryFile *qmlFile = new QTemporaryFile();
1779+
qmlFile->write( elementDef->qmlCode().toUtf8() );
1780+
qmlFile->setParent( qmlWrapper );
1781+
17781782
qmlWrapper->setConfig( mLayer->editFormConfig().widgetConfig( "TODO NAME??" ) );
17791783
qmlWrapper->setContext( context );
17801784

0 commit comments

Comments
 (0)
Please sign in to comment.