Skip to content

Commit 5acd33b

Browse files
m-kuhnsignedav
authored andcommittedSep 5, 2018
Work in progress
1 parent 1c8eadc commit 5acd33b

15 files changed

+313
-7
lines changed
 

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ layer.
4747
AeTypeContainer,
4848
AeTypeField,
4949
AeTypeRelation,
50-
AeTypeInvalid
50+
AeTypeInvalid,
51+
AeTypeQmlElement
5152
};
5253

5354
QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = 0 );
@@ -345,6 +346,19 @@ Determines if the "unlink feature" button should be shown
345346

346347
};
347348

349+
class QgsAttributeEditorQmlElement : QgsAttributeEditorElement
350+
{
351+
352+
%TypeHeaderCode
353+
#include "qgsattributeeditorelement.h"
354+
%End
355+
public:
356+
QgsAttributeEditorQmlElement( QgsAttributeEditorElement *parent );
357+
358+
QString qmlCode() const;
359+
void setQmlCode( const QString &qmlCode );
360+
361+
};
348362

349363
/************************************************************************
350364
* This file has been generated automatically from *

‎python/gui/auto_generated/editorwidgets/core/qgswidgetwrapper.sip.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// so RTTI for casting is available in the whole module.
1515
%ModuleCode
1616
#include "qgsrelationwidgetwrapper.h"
17+
#include "qgsqmlwidgetwrapper.h"
1718
%End
1819

1920
class QgsWidgetWrapper : QObject
@@ -37,6 +38,8 @@ changed status of the widget will be saved.
3738
sipType = sipType_QgsEditorWidgetWrapper;
3839
else if ( qobject_cast<QgsRelationWidgetWrapper *>( sipCpp ) )
3940
sipType = sipType_QgsRelationWidgetWrapper;
41+
else if ( qobject_cast<QgsQmlWidgetWrapper *>( sipCpp ) )
42+
sipType = sipType_QgsQmlWidgetWrapper;
4043
else
4144
sipType = 0;
4245
%End
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/editorwidgets/qgsqmlwidgetwrapper.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
class QgsQmlWidgetWrapper : QgsWidgetWrapper
11+
{
12+
%Docstring
13+
*************************************************************************
14+
qgsqmlwidgetwrapper.h
15+
16+
---------------------
17+
begin : 25.6.2018
18+
copyright : (C) 2018 by Matthias Kuhn
19+
email : matthias@opengis.ch
20+
**************************************************************************
21+
22+
This program is free software; you can redistribute it and/or modify *
23+
it under the terms of the GNU General Public License as published by *
24+
the Free Software Foundation; either version 2 of the License, or *
25+
(at your option) any later version. *
26+
27+
**************************************************************************
28+
%End
29+
30+
%TypeHeaderCode
31+
#include "qgsqmlwidgetwrapper.h"
32+
%End
33+
public:
34+
QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );
35+
36+
virtual bool valid() const;
37+
38+
39+
virtual QWidget *createWidget( QWidget *parent );
40+
41+
42+
virtual void initWidget( QWidget *editor );
43+
44+
45+
public slots:
46+
47+
virtual void setFeature( const QgsFeature &feature );
48+
49+
};
50+
51+
/************************************************************************
52+
* This file has been generated automatically from *
53+
* *
54+
* src/gui/editorwidgets/qgsqmlwidgetwrapper.h *
55+
* *
56+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
57+
************************************************************************/
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/qgsqmlwidget.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
class QgsQmlWidget
11+
{
12+
%Docstring
13+
*************************************************************************
14+
qgsqmlwidget.h
15+
16+
---------------------
17+
begin : 25.6.2018
18+
copyright : (C) 2018 by Matthias Kuhn
19+
email : matthias@opengis.ch
20+
**************************************************************************
21+
22+
This program is free software; you can redistribute it and/or modify *
23+
it under the terms of the GNU General Public License as published by *
24+
the Free Software Foundation; either version 2 of the License, or *
25+
(at your option) any later version. *
26+
27+
**************************************************************************
28+
%End
29+
30+
%TypeHeaderCode
31+
#include "qgsqmlwidget.h"
32+
%End
33+
public:
34+
QgsQmlWidget();
35+
};
36+
37+
/************************************************************************
38+
* This file has been generated automatically from *
39+
* *
40+
* src/gui/qgsqmlwidget.h *
41+
* *
42+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
43+
************************************************************************/

‎python/gui/gui_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,5 @@
322322
%Include auto_generated/processing/qgsprocessingtoolboxmodel.sip
323323
%Include auto_generated/processing/qgsprocessingtoolboxtreeview.sip
324324
%Include auto_generated/processing/qgsprocessingwidgetwrapper.sip
325+
%Include auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip
325326
%Include auto_generated/qgsadvanceddigitizingcanvasitem.sip

‎src/core/qgsattributeeditorelement.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,24 @@ void QgsAttributeEditorRelation::setShowUnlinkButton( bool showUnlinkButton )
150150
{
151151
mShowUnlinkButton = showUnlinkButton;
152152
}
153+
154+
QString QgsAttributeEditorQmlElement::qmlCode() const
155+
{
156+
return mQmlCode;
157+
}
158+
159+
void QgsAttributeEditorQmlElement::setQmlCode( const QString &qmlCode )
160+
{
161+
mQmlCode = qmlCode;
162+
}
163+
164+
void QgsAttributeEditorQmlElement::saveConfiguration( QDomElement &elem ) const
165+
{
166+
QDomText codeElem = elem.ownerDocument().createTextNode( mQmlCode );
167+
elem.appendChild( codeElem );
168+
}
169+
170+
QString QgsAttributeEditorQmlElement::typeIdentifier() const
171+
{
172+
return QStringLiteral( "attributeEditorQmlElement" );
173+
}

‎src/core/qgsattributeeditorelement.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class CORE_EXPORT QgsAttributeEditorElement SIP_ABSTRACT
6161
AeTypeContainer, //!< A container
6262
AeTypeField, //!< A field
6363
AeTypeRelation, //!< A relation
64-
AeTypeInvalid //!< Invalid
64+
AeTypeInvalid, //!< Invalid
65+
AeTypeQmlElement //!< A QML element
6566
};
6667

6768
/**
@@ -411,5 +412,20 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
411412
bool mShowUnlinkButton = true;
412413
};
413414

415+
class CORE_EXPORT QgsAttributeEditorQmlElement : public QgsAttributeEditorElement
416+
{
417+
public:
418+
QgsAttributeEditorQmlElement( QgsAttributeEditorElement *parent )
419+
: QgsAttributeEditorElement( AeTypeQmlElement, "TODO NAME", parent )
420+
{}
421+
422+
QString qmlCode() const;
423+
void setQmlCode( const QString &qmlCode );
424+
425+
private:
426+
void saveConfiguration( QDomElement &elem ) const override;
427+
QString typeIdentifier() const override;
428+
QString mQmlCode;
429+
};
414430

415431
#endif // QGSATTRIBUTEEDITORELEMENT_H

‎src/core/qgseditformconfig.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ void QgsEditFormConfig::setFields( const QgsFields &fields )
6161

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

66-
Q_FOREACH ( QgsAttributeEditorElement *relElem, relations )
66+
for ( QgsAttributeEditorElement *relElem : relations )
6767
{
6868
QgsAttributeEditorRelation *rel = dynamic_cast< QgsAttributeEditorRelation * >( relElem );
6969
if ( !rel )
@@ -599,7 +599,9 @@ QgsAttributeEditorElement *QgsAttributeEditorContainer::clone( QgsAttributeEdito
599599
{
600600
QgsAttributeEditorContainer *element = new QgsAttributeEditorContainer( name(), parent );
601601

602-
Q_FOREACH ( QgsAttributeEditorElement *child, children() )
602+
const auto childElements = children();
603+
604+
for ( QgsAttributeEditorElement *child : childElements )
603605
{
604606
element->addChildElement( child->clone( element ) );
605607
}

‎src/gui/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,25 @@ SET(QGIS_GUI_HDRS
838838

839839
symbology/qgssymbolwidgetcontext.h
840840
)
841+
842+
Find_Package(Qt5Qml)
843+
844+
IF(Qt5Qml_FOUND)
845+
ADD_DEFINITIONS(-DWITH_QML)
846+
SET(QGIS_GUI_MOC_HDRS
847+
${QGIS_GUI_MOC_HDRS}
848+
editorwidgets/qgsqmlwidgetwrapper.h
849+
qgsqmlwidget.h
850+
)
851+
852+
SET(QGIS_GUI_SRCS
853+
${QGIS_GUI_SRCS}
854+
editorwidgets/qgsqmlwidgetwrapper.cpp
855+
qgsqmlwidget.cpp
856+
)
857+
858+
ENDIF(Qt5Qml_FOUND)
859+
841860
SET_PROPERTY(GLOBAL PROPERTY QGIS_GUI_HDRS ${QGIS_GUI_HDRS})
842861

843862

‎src/gui/editorwidgets/core/qgswidgetwrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class QgsVectorLayer;
3232
// so RTTI for casting is available in the whole module.
3333
% ModuleCode
3434
#include "qgsrelationwidgetwrapper.h"
35+
#include "qgsqmlwidgetwrapper.h"
3536
% End
3637
#endif
3738

@@ -56,6 +57,8 @@ class GUI_EXPORT QgsWidgetWrapper : public QObject
5657
sipType = sipType_QgsEditorWidgetWrapper;
5758
else if ( qobject_cast<QgsRelationWidgetWrapper *>( sipCpp ) )
5859
sipType = sipType_QgsRelationWidgetWrapper;
60+
else if ( qobject_cast<QgsQmlWidgetWrapper *>( sipCpp ) )
61+
sipType = sipType_QgsQmlWidgetWrapper;
5962
else
6063
sipType = 0;
6164
SIP_END
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/***************************************************************************
2+
qgsqmlwidgetwrapper.cpp
3+
4+
---------------------
5+
begin : 25.6.2018
6+
copyright : (C) 2018 by Matthias Kuhn
7+
email : matthias@opengis.ch
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
#include "qgsqmlwidgetwrapper.h"
17+
18+
QgsQmlWidgetWrapper::QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent )
19+
: QgsWidgetWrapper( layer, editor, parent )
20+
{
21+
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/***************************************************************************
2+
qgsqmlwidgetwrapper.h
3+
4+
---------------------
5+
begin : 25.6.2018
6+
copyright : (C) 2018 by Matthias Kuhn
7+
email : matthias@opengis.ch
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
#ifndef QGSQMLWIDGETWRAPPER_H
17+
#define QGSQMLWIDGETWRAPPER_H
18+
19+
#include "qgswidgetwrapper.h"
20+
21+
class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
22+
{
23+
public:
24+
QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );
25+
26+
bool valid() const override;
27+
28+
QWidget *createWidget( QWidget *parent ) override;
29+
30+
void initWidget( QWidget *editor ) override;
31+
32+
public slots:
33+
34+
void setFeature( const QgsFeature &feature ) override;
35+
};
36+
37+
#endif // QGSQMLWIDGETWRAPPER_H

‎src/gui/qgsattributeform.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "qgsgui.h"
3838
#include "qgsvectorlayerjoinbuffer.h"
3939
#include "qgsvectorlayerutils.h"
40+
#include "qgsqmlwidgetwrapper.h"
4041

4142
#include <QDir>
4243
#include <QTextStream>
@@ -1709,9 +1710,9 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
17091710
int row = 0;
17101711
int column = 0;
17111712

1712-
QList<QgsAttributeEditorElement *> children = container->children();
1713+
const QList<QgsAttributeEditorElement *> children = container->children();
17131714

1714-
Q_FOREACH ( QgsAttributeEditorElement *childDef, children )
1715+
for ( QgsAttributeEditorElement *childDef : children )
17151716
{
17161717
WidgetInfo widgetInfo = createWidgetFromDef( childDef, myContainer, vl, context );
17171718

@@ -1769,6 +1770,25 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
17691770
break;
17701771
}
17711772

1773+
case QgsAttributeEditorElement::AeTypeQmlElement:
1774+
{
1775+
const QgsAttributeEditorQmlElement *elementDef = static_cast<const QgsAttributeEditorQmlElement *>( widgetDef );
1776+
1777+
QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this );
1778+
qmlWrapper->setConfig( mLayer->editFormConfig().widgetConfig( "TODO NAME??" ) );
1779+
qmlWrapper->setContext( context );
1780+
1781+
// QgsAttributeFormRelationEditorWidget *formWidget = new QgsAttributeFormRelationEditorWidget( rww, this );
1782+
1783+
mWidgets.append( qmlWrapper );
1784+
// mFormWidgets.append( formWidget );
1785+
1786+
newWidgetInfo.widget = qmlWrapper->widget();
1787+
newWidgetInfo.labelText = QString();
1788+
newWidgetInfo.labelOnTop = true;
1789+
break;
1790+
}
1791+
17721792
default:
17731793
QgsDebugMsg( "Unknown attribute editor widget type encountered..." );
17741794
break;

‎src/gui/qgsqmlwidget.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/***************************************************************************
2+
qgsqmlwidget.cpp
3+
4+
---------------------
5+
begin : 25.6.2018
6+
copyright : (C) 2018 by Matthias Kuhn
7+
email : matthias@opengis.ch
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
#include "qgsqmlwidget.h"
17+
18+
QgsQmlWidget::QgsQmlWidget()
19+
{
20+
21+
}

‎src/gui/qgsqmlwidget.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/***************************************************************************
2+
qgsqmlwidget.h
3+
4+
---------------------
5+
begin : 25.6.2018
6+
copyright : (C) 2018 by Matthias Kuhn
7+
email : matthias@opengis.ch
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
#ifndef QGSQMLWIDGET_H
17+
#define QGSQMLWIDGET_H
18+
19+
#include "qgis_gui.h"
20+
21+
class GUI_EXPORT QgsQmlWidget
22+
{
23+
public:
24+
QgsQmlWidget();
25+
};
26+
27+
#endif // QGSQMLWIDGET_H

0 commit comments

Comments
 (0)
Please sign in to comment.