Skip to content

Commit

Permalink
docs and replacement of qmlexpression
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Sep 5, 2018
1 parent ae1333d commit 76df5b0
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 50 deletions.
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsattributeeditorelement.sip.in
Expand Up @@ -358,7 +358,14 @@ An attribute editor widget that will represent arbitrary QML code.
#include "qgsattributeeditorelement.h"
%End
public:

QgsAttributeEditorQmlElement( const QString &name, QgsAttributeEditorElement *parent );
%Docstring
Creates a new element which can display QML

:param name: The name of the widget
:param parent: The parent (used as container)
%End

virtual QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const /Factory/;

Expand Down
40 changes: 9 additions & 31 deletions python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in
Expand Up @@ -10,21 +10,9 @@
class QgsQmlWidgetWrapper : QgsWidgetWrapper
{
%Docstring
*************************************************************************
qgsqmlwidgetwrapper.h
Wraps a QQuickWidget to display QML code

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

**************************************************************************
.. versionadded:: 3.4
%End

%TypeHeaderCode
Expand All @@ -33,6 +21,13 @@ the Free Software Foundation; either version 2 of the License, or *
public:

QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );
%Docstring
Create a qml widget wrapper

:param layer: The layer on which the feature is
:param editor: An editor widget. Can be NULL if one should be autogenerated.
:param parent: A parent widget
%End

virtual bool valid() const;

Expand Down Expand Up @@ -63,23 +58,6 @@ passes the ``feature`` into the context property of the widget

};


class QmlExpression : QObject
{

%TypeHeaderCode
#include "qgsqmlwidgetwrapper.h"
%End
public:
void setExpressionContext( const QgsExpressionContext &context );

QVariant evaluate( const QString &expression ) const;
%Docstring
evaluates the value regarding the /a expression and the context
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributesformproperties.cpp
Expand Up @@ -1141,7 +1141,7 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
qmlObjectTemplate->addItem( tr( "Rectangle" ) );
qmlObjectTemplate->addItem( tr( "Pie chart" ) );
qmlObjectTemplate->addItem( tr( "Bar chart" ) );
connect( qmlObjectTemplate, QOverload<int>::of( &QComboBox::currentIndexChanged ), qmlCode, [ = ]( int index )
connect( qmlObjectTemplate, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), qmlCode, [ = ]( int index )
{
qmlCode->clear();
switch ( index )
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsattributeeditorelement.h
Expand Up @@ -413,13 +413,21 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
};

/**
* \ingroup core
* An attribute editor widget that will represent arbitrary QML code.
*
* \since QGIS 3.4
*/
class CORE_EXPORT QgsAttributeEditorQmlElement : public QgsAttributeEditorElement
{
public:

/**
* Creates a new element which can display QML
*
* \param name The name of the widget
* \param parent The parent (used as container)
*/
QgsAttributeEditorQmlElement( const QString &name, QgsAttributeEditorElement *parent )
: QgsAttributeEditorElement( AeTypeQmlElement, name, parent )
{}
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -558,13 +558,13 @@ QgsAttributeEditorElement *QgsEditFormConfig::attributeEditorElementFromDomEleme

newElement = container;
}
else if ( elem.tagName() == QStringLiteral( "attributeEditorField" ) )
else if ( elem.tagName() == QLatin1String( "attributeEditorField" ) )
{
QString name = elem.attribute( QStringLiteral( "name" ) );
int idx = d->mFields.lookupField( name );
newElement = new QgsAttributeEditorField( name, idx, parent );
}
else if ( elem.tagName() == QStringLiteral( "attributeEditorRelation" ) )
else if ( elem.tagName() == QLatin1String( "attributeEditorRelation" ) )
{
// At this time, the relations are not loaded
// So we only grab the id and delegate the rest to onRelationsLoaded()
Expand All @@ -573,7 +573,7 @@ QgsAttributeEditorElement *QgsEditFormConfig::attributeEditorElementFromDomEleme
relElement->setShowUnlinkButton( elem.attribute( QStringLiteral( "showUnlinkButton" ), QStringLiteral( "1" ) ).toInt() );
newElement = relElement;
}
else if ( elem.tagName() == QStringLiteral( "attributeEditorQmlElement" ) )
else if ( elem.tagName() == QLatin1String( "attributeEditorQmlElement" ) )
{
QgsAttributeEditorQmlElement *qmlElement = new QgsAttributeEditorQmlElement( elem.attribute( QStringLiteral( "name" ) ), parent );
qmlElement->setQmlCode( elem.text() );
Expand Down
20 changes: 20 additions & 0 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp
Expand Up @@ -20,6 +20,26 @@
#include <QQmlContext>
#include <QQmlEngine>

/**
* \ingroup gui
* To pass the QgsExpression functionality and it's context to the context of the QQuickWidget
* \since QGIS 3.4
*/
class GUI_EXPORT QmlExpression : public QObject
{
Q_OBJECT

public:
void setExpressionContext( const QgsExpressionContext &context );

//! evaluates the value regarding the /a expression and the context
Q_INVOKABLE QVariant evaluate( const QString &expression ) const;

private:
QgsExpressionContext mExpressionContext;
};


QgsQmlWidgetWrapper::QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent )
: QgsWidgetWrapper( layer, editor, parent )
{
Expand Down
27 changes: 12 additions & 15 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.h
Expand Up @@ -21,12 +21,24 @@
#include "qgis_gui.h"
#include <QtQuickWidgets/QQuickWidget>

/**
* \ingroup gui
* Wraps a QQuickWidget to display QML code
* \since QGIS 3.4
*/
class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
{
Q_OBJECT

public:

/**
* Create a qml widget wrapper
*
* \param layer The layer on which the feature is
* \param editor An editor widget. Can be NULL if one should be autogenerated.
* \param parent A parent widget
*/
QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );

bool valid() const override;
Expand All @@ -51,19 +63,4 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
QQuickWidget *mWidget = nullptr;
};


class GUI_EXPORT QmlExpression : public QObject
{
Q_OBJECT

public:
void setExpressionContext( const QgsExpressionContext &context );

//! evaluates the value regarding the /a expression and the context
Q_INVOKABLE QVariant evaluate( const QString &expression ) const;

private:
QgsExpressionContext mExpressionContext;
};

#endif // QGSQMLWIDGETWRAPPER_H

0 comments on commit 76df5b0

Please sign in to comment.