From 5f4acded15a3b5b86f49b82960f00f7aa07982e9 Mon Sep 17 00:00:00 2001 From: signedav Date: Thu, 6 Sep 2018 07:57:17 +0200 Subject: [PATCH] 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 --- .../editorwidgets/qgsqmlwidgetwrapper.sip.in | 19 ------------------- src/app/qgsattributesformproperties.cpp | 12 +++++++----- src/gui/editorwidgets/qgsqmlwidgetwrapper.h | 8 +++++++- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in b/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in index a40dc53f5de..c4515d11ead 100644 --- a/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in +++ b/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in @@ -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 * diff --git a/src/app/qgsattributesformproperties.cpp b/src/app/qgsattributesformproperties.cpp index 345d127a634..84bc7f347ff 100644 --- a/src/app/qgsattributesformproperties.cpp +++ b/src/app/qgsattributesformproperties.cpp @@ -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::of( &QComboBox::currentIndexChanged ), qmlCode, [ = ]( int index ) + connect( qmlObjectTemplate, qgis::overload::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 ); diff --git a/src/gui/editorwidgets/qgsqmlwidgetwrapper.h b/src/gui/editorwidgets/qgsqmlwidgetwrapper.h index 63e02ea64d2..650ae25a37f 100644 --- a/src/gui/editorwidgets/qgsqmlwidgetwrapper.h +++ b/src/gui/editorwidgets/qgsqmlwidgetwrapper.h @@ -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