Skip to content

Commit

Permalink
expressions on qml widget
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Sep 5, 2018
1 parent abbe5c5 commit ccdd4df
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
************************************************************************/



class QgsQmlWidgetWrapper : QgsWidgetWrapper
{
%Docstring
Expand Down Expand Up @@ -55,6 +54,19 @@ the Free Software Foundation; either version 2 of the License, or *
};


class QmlExpression : QObject
{

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

QVariant evaluate( const QString &expression ) const;

};

/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsattributesformproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )

connect( addExpressionButton, &QAbstractButton::clicked, this, [ = ]
{
qmlCode->insertPlainText( QStringLiteral( "expression.evaluate(\"(%1)\")" ).arg( expressionWidget->currentText()) );
qmlCode->insertPlainText( QStringLiteral( "expression.evaluate(\"(%1)\")" ).arg( expressionWidget->currentText() ) );
} );


Expand All @@ -1181,7 +1181,7 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
qmlWrapper->setQmlCode( qmlCode->toPlainText() );
qmlWrapper->reinitWidget();
QgsFeature f;
mLayer->getFeatures().nextFeature(f);
mLayer->getFeatures().nextFeature( f );
qmlWrapper->setFeature( f );
} );

Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ void QmlExpression::setExpressionContext( const QgsExpressionContext &context )
mExpressionContext = context;
}

QVariant QmlExpression::evaluate( const QString& expression ) const
QVariant QmlExpression::evaluate( const QString &expression ) const
{
QgsExpression exp = QgsExpression( expression );
exp.prepare( &mExpressionContext );
return exp.evaluate(&mExpressionContext);
return exp.evaluate( &mExpressionContext );
}
8 changes: 4 additions & 4 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper

class GUI_EXPORT QmlExpression : public QObject
{
Q_OBJECT
Q_OBJECT

public:
void setExpressionContext( const QgsExpressionContext &context );
void setExpressionContext( const QgsExpressionContext &context );

Q_INVOKABLE QVariant evaluate( const QString &expression) const;
Q_INVOKABLE QVariant evaluate( const QString &expression ) const;

private:
QgsExpressionContext mExpressionContext;
QgsExpressionContext mExpressionContext;
};

#endif // QGSQMLWIDGETWRAPPER_H

0 comments on commit ccdd4df

Please sign in to comment.