Work in progress

This commit is contained in:
Matthias Kuhn 2018-06-26 16:01:52 +02:00 committed by signedav
parent 1c8eadcdcc
commit 5acd33b32d
15 changed files with 313 additions and 7 deletions

View File

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

View File

@ -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<QgsRelationWidgetWrapper *>( sipCpp ) )
sipType = sipType_QgsRelationWidgetWrapper;
else if ( qobject_cast<QgsQmlWidgetWrapper *>( sipCpp ) )
sipType = sipType_QgsQmlWidgetWrapper;
else
sipType = 0;
%End

View File

@ -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 *
************************************************************************/

View File

@ -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 *
************************************************************************/

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<QgsRelationWidgetWrapper *>( sipCpp ) )
sipType = sipType_QgsRelationWidgetWrapper;
else if ( qobject_cast<QgsQmlWidgetWrapper *>( sipCpp ) )
sipType = sipType_QgsQmlWidgetWrapper;
else
sipType = 0;
SIP_END

View File

@ -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 )
{
}

View File

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

View File

@ -37,6 +37,7 @@
#include "qgsgui.h"
#include "qgsvectorlayerjoinbuffer.h"
#include "qgsvectorlayerutils.h"
#include "qgsqmlwidgetwrapper.h"
#include <QDir>
#include <QTextStream>
@ -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 );
@ -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;

21
src/gui/qgsqmlwidget.cpp Normal file
View File

@ -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()
{
}

27
src/gui/qgsqmlwidget.h Normal file
View File

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