Skip to content
Permalink
Browse files

some more fixes

Removed QmlExpression from api
On activation of template box, we overwrite the text in the GUI
The preview is loaded including expression values on start
Takes expression instead of currentText from ExpressionWidget - means it delivers fields in quotes
  • Loading branch information
signedav committed Sep 6, 2018
1 parent 4504845 commit 5f4acded15a3b5b86f49b82960f00f7aa07982e9
@@ -58,26 +58,7 @@ passes the ``feature`` into the context property of the widget

};

class QmlExpression : QObject
{
%Docstring
To pass the QgsExpression functionality and it's context to the context of the QQuickWidget

.. versionadded:: 3.4
%End

%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 *
@@ -1124,14 +1124,14 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
qmlCode->setPlaceholderText( tr( "Insert QML code here..." ) );

QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this );
qmlWrapper->setQmlCode( qmlCode->toPlainText() );
QgsFeature previewFeature;
mLayer->getFeatures().nextFeature( previewFeature );

//update preview on text change
connect( qmlCode, &QPlainTextEdit::textChanged, this, [ = ]
{
qmlWrapper->setQmlCode( qmlCode->toPlainText() );
qmlWrapper->reinitWidget();
QgsFeature previewFeature;
mLayer->getFeatures().nextFeature( previewFeature );
qmlWrapper->setFeature( previewFeature );
} );

@@ -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, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), qmlCode, [ = ]( int index )
connect( qmlObjectTemplate, qgis::overload<int>::of( &QComboBox::activated ), qmlCode, [ = ]( int index )
{
qmlCode->clear();
switch ( index )
@@ -1215,7 +1215,7 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )

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

layout->addRow( tr( "Title" ), title );
@@ -1233,6 +1233,8 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
qmlPreviewBox->setLayout( new QGridLayout );
qmlPreviewBox->setMinimumWidth( 400 );
qmlPreviewBox->layout()->addWidget( qmlWrapper->widget() );
//emit to load preview for the first time
emit qmlCode->textChanged();
qmlLayout->addWidget( qmlPreviewBox );

QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
@@ -63,12 +63,16 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
QQuickWidget *mWidget = nullptr;
};


#ifndef SIP_RUN
///@cond PRIVATE

/**
* \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
class QmlExpression : public QObject
{
Q_OBJECT

@@ -81,5 +85,7 @@ class GUI_EXPORT QmlExpression : public QObject
private:
QgsExpressionContext mExpressionContext;
};
///@endcond
#endif //SIP_RUN

#endif // QGSQMLWIDGETWRAPPER_H

0 comments on commit 5f4acde

Please sign in to comment.
You can’t perform that action at this time.