diff --git a/python/core/auto_generated/qgsattributeeditorelement.sip.in b/python/core/auto_generated/qgsattributeeditorelement.sip.in index e089d71905c..2f3531ae28a 100644 --- a/python/core/auto_generated/qgsattributeeditorelement.sip.in +++ b/python/core/auto_generated/qgsattributeeditorelement.sip.in @@ -47,7 +47,8 @@ layer. AeTypeContainer, AeTypeField, AeTypeRelation, - AeTypeInvalid + AeTypeInvalid, + AeTypeQmlElement }; QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = 0 ); @@ -345,6 +346,19 @@ Determines if the "unlink feature" button should be shown }; +class QgsAttributeEditorQmlElement : QgsAttributeEditorElement +{ + +%TypeHeaderCode +#include "qgsattributeeditorelement.h" +%End + public: + QgsAttributeEditorQmlElement( QgsAttributeEditorElement *parent ); + + QString qmlCode() const; + void setQmlCode( const QString &qmlCode ); + +}; /************************************************************************ * This file has been generated automatically from * diff --git a/python/gui/auto_generated/editorwidgets/core/qgswidgetwrapper.sip.in b/python/gui/auto_generated/editorwidgets/core/qgswidgetwrapper.sip.in index 46497dbf845..0e224dfc78d 100644 --- a/python/gui/auto_generated/editorwidgets/core/qgswidgetwrapper.sip.in +++ b/python/gui/auto_generated/editorwidgets/core/qgswidgetwrapper.sip.in @@ -14,6 +14,7 @@ // so RTTI for casting is available in the whole module. %ModuleCode #include "qgsrelationwidgetwrapper.h" +#include "qgsqmlwidgetwrapper.h" %End class QgsWidgetWrapper : QObject @@ -37,6 +38,8 @@ changed status of the widget will be saved. sipType = sipType_QgsEditorWidgetWrapper; else if ( qobject_cast( sipCpp ) ) sipType = sipType_QgsRelationWidgetWrapper; + else if ( qobject_cast( sipCpp ) ) + sipType = sipType_QgsQmlWidgetWrapper; else sipType = 0; %End diff --git a/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in b/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in new file mode 100644 index 00000000000..3ffa415dfe2 --- /dev/null +++ b/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in @@ -0,0 +1,57 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/editorwidgets/qgsqmlwidgetwrapper.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + +class QgsQmlWidgetWrapper : QgsWidgetWrapper +{ +%Docstring +************************************************************************* +qgsqmlwidgetwrapper.h + +--------------------- +begin : 25.6.2018 +copyright : (C) 2018 by Matthias Kuhn +email : matthias@opengis.ch +************************************************************************** + +This program is free software; you can redistribute it and/or modify * +it under the terms of the GNU General Public License as published by * +the Free Software Foundation; either version 2 of the License, or * +(at your option) any later version. * + +************************************************************************** +%End + +%TypeHeaderCode +#include "qgsqmlwidgetwrapper.h" +%End + public: + QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent ); + + virtual bool valid() const; + + + virtual QWidget *createWidget( QWidget *parent ); + + + virtual void initWidget( QWidget *editor ); + + + public slots: + + virtual void setFeature( const QgsFeature &feature ); + +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/editorwidgets/qgsqmlwidgetwrapper.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/gui/auto_generated/qgsqmlwidget.sip.in b/python/gui/auto_generated/qgsqmlwidget.sip.in new file mode 100644 index 00000000000..b039619ae23 --- /dev/null +++ b/python/gui/auto_generated/qgsqmlwidget.sip.in @@ -0,0 +1,43 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/qgsqmlwidget.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + +class QgsQmlWidget +{ +%Docstring +************************************************************************* +qgsqmlwidget.h + +--------------------- +begin : 25.6.2018 +copyright : (C) 2018 by Matthias Kuhn +email : matthias@opengis.ch +************************************************************************** + +This program is free software; you can redistribute it and/or modify * +it under the terms of the GNU General Public License as published by * +the Free Software Foundation; either version 2 of the License, or * +(at your option) any later version. * + +************************************************************************** +%End + +%TypeHeaderCode +#include "qgsqmlwidget.h" +%End + public: + QgsQmlWidget(); +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/qgsqmlwidget.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/gui/gui_auto.sip b/python/gui/gui_auto.sip index 518511760db..612ba817d74 100644 --- a/python/gui/gui_auto.sip +++ b/python/gui/gui_auto.sip @@ -322,4 +322,5 @@ %Include auto_generated/processing/qgsprocessingtoolboxmodel.sip %Include auto_generated/processing/qgsprocessingtoolboxtreeview.sip %Include auto_generated/processing/qgsprocessingwidgetwrapper.sip +%Include auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip %Include auto_generated/qgsadvanceddigitizingcanvasitem.sip diff --git a/src/core/qgsattributeeditorelement.cpp b/src/core/qgsattributeeditorelement.cpp index 1b7f1e2fc6d..c786ad3412d 100644 --- a/src/core/qgsattributeeditorelement.cpp +++ b/src/core/qgsattributeeditorelement.cpp @@ -150,3 +150,24 @@ void QgsAttributeEditorRelation::setShowUnlinkButton( bool showUnlinkButton ) { mShowUnlinkButton = showUnlinkButton; } + +QString QgsAttributeEditorQmlElement::qmlCode() const +{ + return mQmlCode; +} + +void QgsAttributeEditorQmlElement::setQmlCode( const QString &qmlCode ) +{ + mQmlCode = qmlCode; +} + +void QgsAttributeEditorQmlElement::saveConfiguration( QDomElement &elem ) const +{ + QDomText codeElem = elem.ownerDocument().createTextNode( mQmlCode ); + elem.appendChild( codeElem ); +} + +QString QgsAttributeEditorQmlElement::typeIdentifier() const +{ + return QStringLiteral( "attributeEditorQmlElement" ); +} diff --git a/src/core/qgsattributeeditorelement.h b/src/core/qgsattributeeditorelement.h index 7ee61b47a20..c64615b0a31 100644 --- a/src/core/qgsattributeeditorelement.h +++ b/src/core/qgsattributeeditorelement.h @@ -61,7 +61,8 @@ class CORE_EXPORT QgsAttributeEditorElement SIP_ABSTRACT AeTypeContainer, //!< A container AeTypeField, //!< A field AeTypeRelation, //!< A relation - AeTypeInvalid //!< Invalid + AeTypeInvalid, //!< Invalid + AeTypeQmlElement //!< A QML element }; /** @@ -411,5 +412,20 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement bool mShowUnlinkButton = true; }; +class CORE_EXPORT QgsAttributeEditorQmlElement : public QgsAttributeEditorElement +{ + public: + QgsAttributeEditorQmlElement( QgsAttributeEditorElement *parent ) + : QgsAttributeEditorElement( AeTypeQmlElement, "TODO NAME", parent ) + {} + + QString qmlCode() const; + void setQmlCode( const QString &qmlCode ); + + private: + void saveConfiguration( QDomElement &elem ) const override; + QString typeIdentifier() const override; + QString mQmlCode; +}; #endif // QGSATTRIBUTEEDITORELEMENT_H diff --git a/src/core/qgseditformconfig.cpp b/src/core/qgseditformconfig.cpp index de14ed2c923..0ce7001d46b 100644 --- a/src/core/qgseditformconfig.cpp +++ b/src/core/qgseditformconfig.cpp @@ -61,9 +61,9 @@ void QgsEditFormConfig::setFields( const QgsFields &fields ) void QgsEditFormConfig::onRelationsLoaded() { - QList relations = d->mInvisibleRootContainer->findElements( QgsAttributeEditorElement::AeTypeRelation ); + const QList relations = d->mInvisibleRootContainer->findElements( QgsAttributeEditorElement::AeTypeRelation ); - Q_FOREACH ( QgsAttributeEditorElement *relElem, relations ) + for ( QgsAttributeEditorElement *relElem : relations ) { QgsAttributeEditorRelation *rel = dynamic_cast< QgsAttributeEditorRelation * >( relElem ); if ( !rel ) @@ -599,7 +599,9 @@ QgsAttributeEditorElement *QgsAttributeEditorContainer::clone( QgsAttributeEdito { QgsAttributeEditorContainer *element = new QgsAttributeEditorContainer( name(), parent ); - Q_FOREACH ( QgsAttributeEditorElement *child, children() ) + const auto childElements = children(); + + for ( QgsAttributeEditorElement *child : childElements ) { element->addChildElement( child->clone( element ) ); } diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index ab048a68e39..7ef84f045e3 100755 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -838,6 +838,25 @@ SET(QGIS_GUI_HDRS symbology/qgssymbolwidgetcontext.h ) + +Find_Package(Qt5Qml) + +IF(Qt5Qml_FOUND) +ADD_DEFINITIONS(-DWITH_QML) +SET(QGIS_GUI_MOC_HDRS + ${QGIS_GUI_MOC_HDRS} + editorwidgets/qgsqmlwidgetwrapper.h + qgsqmlwidget.h +) + +SET(QGIS_GUI_SRCS + ${QGIS_GUI_SRCS} + editorwidgets/qgsqmlwidgetwrapper.cpp + qgsqmlwidget.cpp +) + +ENDIF(Qt5Qml_FOUND) + SET_PROPERTY(GLOBAL PROPERTY QGIS_GUI_HDRS ${QGIS_GUI_HDRS}) diff --git a/src/gui/editorwidgets/core/qgswidgetwrapper.h b/src/gui/editorwidgets/core/qgswidgetwrapper.h index 0999f5bf525..8848af59f6b 100644 --- a/src/gui/editorwidgets/core/qgswidgetwrapper.h +++ b/src/gui/editorwidgets/core/qgswidgetwrapper.h @@ -32,6 +32,7 @@ class QgsVectorLayer; // so RTTI for casting is available in the whole module. % ModuleCode #include "qgsrelationwidgetwrapper.h" +#include "qgsqmlwidgetwrapper.h" % End #endif @@ -56,6 +57,8 @@ class GUI_EXPORT QgsWidgetWrapper : public QObject sipType = sipType_QgsEditorWidgetWrapper; else if ( qobject_cast( sipCpp ) ) sipType = sipType_QgsRelationWidgetWrapper; + else if ( qobject_cast( sipCpp ) ) + sipType = sipType_QgsQmlWidgetWrapper; else sipType = 0; SIP_END diff --git a/src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp b/src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp new file mode 100644 index 00000000000..fab3486f560 --- /dev/null +++ b/src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp @@ -0,0 +1,22 @@ +/*************************************************************************** + qgsqmlwidgetwrapper.cpp + + --------------------- + begin : 25.6.2018 + copyright : (C) 2018 by Matthias Kuhn + email : matthias@opengis.ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include "qgsqmlwidgetwrapper.h" + +QgsQmlWidgetWrapper::QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent ) + : QgsWidgetWrapper( layer, editor, parent ) +{ + +} diff --git a/src/gui/editorwidgets/qgsqmlwidgetwrapper.h b/src/gui/editorwidgets/qgsqmlwidgetwrapper.h new file mode 100644 index 00000000000..4d418bdd6eb --- /dev/null +++ b/src/gui/editorwidgets/qgsqmlwidgetwrapper.h @@ -0,0 +1,37 @@ +/*************************************************************************** + qgsqmlwidgetwrapper.h + + --------------------- + begin : 25.6.2018 + copyright : (C) 2018 by Matthias Kuhn + email : matthias@opengis.ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef QGSQMLWIDGETWRAPPER_H +#define QGSQMLWIDGETWRAPPER_H + +#include "qgswidgetwrapper.h" + +class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper +{ + public: + QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent ); + + bool valid() const override; + + QWidget *createWidget( QWidget *parent ) override; + + void initWidget( QWidget *editor ) override; + + public slots: + + void setFeature( const QgsFeature &feature ) override; +}; + +#endif // QGSQMLWIDGETWRAPPER_H diff --git a/src/gui/qgsattributeform.cpp b/src/gui/qgsattributeform.cpp index b4fe97efe64..588b1d91b68 100644 --- a/src/gui/qgsattributeform.cpp +++ b/src/gui/qgsattributeform.cpp @@ -37,6 +37,7 @@ #include "qgsgui.h" #include "qgsvectorlayerjoinbuffer.h" #include "qgsvectorlayerutils.h" +#include "qgsqmlwidgetwrapper.h" #include #include @@ -1709,9 +1710,9 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt int row = 0; int column = 0; - QList children = container->children(); + const QList children = container->children(); - Q_FOREACH ( QgsAttributeEditorElement *childDef, children ) + for ( QgsAttributeEditorElement *childDef : children ) { WidgetInfo widgetInfo = createWidgetFromDef( childDef, myContainer, vl, context ); @@ -1769,6 +1770,25 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt break; } + case QgsAttributeEditorElement::AeTypeQmlElement: + { + const QgsAttributeEditorQmlElement *elementDef = static_cast( widgetDef ); + + QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this ); + qmlWrapper->setConfig( mLayer->editFormConfig().widgetConfig( "TODO NAME??" ) ); + qmlWrapper->setContext( context ); + + // QgsAttributeFormRelationEditorWidget *formWidget = new QgsAttributeFormRelationEditorWidget( rww, this ); + + mWidgets.append( qmlWrapper ); + // mFormWidgets.append( formWidget ); + + newWidgetInfo.widget = qmlWrapper->widget(); + newWidgetInfo.labelText = QString(); + newWidgetInfo.labelOnTop = true; + break; + } + default: QgsDebugMsg( "Unknown attribute editor widget type encountered..." ); break; diff --git a/src/gui/qgsqmlwidget.cpp b/src/gui/qgsqmlwidget.cpp new file mode 100644 index 00000000000..9dcdcb255fa --- /dev/null +++ b/src/gui/qgsqmlwidget.cpp @@ -0,0 +1,21 @@ +/*************************************************************************** + qgsqmlwidget.cpp + + --------------------- + begin : 25.6.2018 + copyright : (C) 2018 by Matthias Kuhn + email : matthias@opengis.ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include "qgsqmlwidget.h" + +QgsQmlWidget::QgsQmlWidget() +{ + +} diff --git a/src/gui/qgsqmlwidget.h b/src/gui/qgsqmlwidget.h new file mode 100644 index 00000000000..4b1a9f82fa2 --- /dev/null +++ b/src/gui/qgsqmlwidget.h @@ -0,0 +1,27 @@ +/*************************************************************************** + qgsqmlwidget.h + + --------------------- + begin : 25.6.2018 + copyright : (C) 2018 by Matthias Kuhn + email : matthias@opengis.ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef QGSQMLWIDGET_H +#define QGSQMLWIDGET_H + +#include "qgis_gui.h" + +class GUI_EXPORT QgsQmlWidget +{ + public: + QgsQmlWidget(); +}; + +#endif // QGSQMLWIDGET_H