Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and signedav committed Sep 5, 2018
1 parent 1c8eadc commit 5acd33b
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 7 deletions.
16 changes: 15 additions & 1 deletion python/core/auto_generated/qgsattributeeditorelement.sip.in
Expand Up @@ -47,7 +47,8 @@ layer.
AeTypeContainer,
AeTypeField,
AeTypeRelation,
AeTypeInvalid
AeTypeInvalid,
AeTypeQmlElement
};

QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = 0 );
Expand Down Expand Up @@ -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 *
Expand Down
Expand Up @@ -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
Expand All @@ -37,6 +38,8 @@ changed status of the widget will be saved.
sipType = sipType_QgsEditorWidgetWrapper;
else if ( qobject_cast<QgsRelationWidgetWrapper *>( sipCpp ) )
sipType = sipType_QgsRelationWidgetWrapper;
else if ( qobject_cast<QgsQmlWidgetWrapper *>( sipCpp ) )
sipType = sipType_QgsQmlWidgetWrapper;
else
sipType = 0;
%End
Expand Down
57 changes: 57 additions & 0 deletions 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 *
************************************************************************/
43 changes: 43 additions & 0 deletions 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 *
************************************************************************/
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -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
21 changes: 21 additions & 0 deletions src/core/qgsattributeeditorelement.cpp
Expand Up @@ -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" );
}
18 changes: 17 additions & 1 deletion src/core/qgsattributeeditorelement.h
Expand Up @@ -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
};

/**
Expand Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -61,9 +61,9 @@ void QgsEditFormConfig::setFields( const QgsFields &fields )

void QgsEditFormConfig::onRelationsLoaded()
{
QList<QgsAttributeEditorElement *> relations = d->mInvisibleRootContainer->findElements( QgsAttributeEditorElement::AeTypeRelation );
const QList<QgsAttributeEditorElement *> relations = d->mInvisibleRootContainer->findElements( QgsAttributeEditorElement::AeTypeRelation );

Q_FOREACH ( QgsAttributeEditorElement *relElem, relations )
for ( QgsAttributeEditorElement *relElem : relations )
{
QgsAttributeEditorRelation *rel = dynamic_cast< QgsAttributeEditorRelation * >( relElem );
if ( !rel )
Expand Down Expand Up @@ -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 ) );
}
Expand Down
19 changes: 19 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -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})


Expand Down
3 changes: 3 additions & 0 deletions src/gui/editorwidgets/core/qgswidgetwrapper.h
Expand Up @@ -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

Expand All @@ -56,6 +57,8 @@ class GUI_EXPORT QgsWidgetWrapper : public QObject
sipType = sipType_QgsEditorWidgetWrapper;
else if ( qobject_cast<QgsRelationWidgetWrapper *>( sipCpp ) )
sipType = sipType_QgsRelationWidgetWrapper;
else if ( qobject_cast<QgsQmlWidgetWrapper *>( sipCpp ) )
sipType = sipType_QgsQmlWidgetWrapper;
else
sipType = 0;
SIP_END
Expand Down
22 changes: 22 additions & 0 deletions 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 )
{

}
37 changes: 37 additions & 0 deletions 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
24 changes: 22 additions & 2 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -37,6 +37,7 @@
#include "qgsgui.h"
#include "qgsvectorlayerjoinbuffer.h"
#include "qgsvectorlayerutils.h"
#include "qgsqmlwidgetwrapper.h"

#include <QDir>
#include <QTextStream>
Expand Down Expand Up @@ -1709,9 +1710,9 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
int row = 0;
int column = 0;

QList<QgsAttributeEditorElement *> children = container->children();
const QList<QgsAttributeEditorElement *> children = container->children();

Q_FOREACH ( QgsAttributeEditorElement *childDef, children )
for ( QgsAttributeEditorElement *childDef : children )
{
WidgetInfo widgetInfo = createWidgetFromDef( childDef, myContainer, vl, context );

Expand Down Expand Up @@ -1769,6 +1770,25 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
break;
}

case QgsAttributeEditorElement::AeTypeQmlElement:
{
const QgsAttributeEditorQmlElement *elementDef = static_cast<const QgsAttributeEditorQmlElement *>( 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;
Expand Down

0 comments on commit 5acd33b

Please sign in to comment.