Skip to content

Commit

Permalink
some more fixes
Browse files Browse the repository at this point in the history
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 5f4acde
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
19 changes: 0 additions & 19 deletions python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
12 changes: 7 additions & 5 deletions src/app/qgsattributesformproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
} );

Expand All @@ -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 )
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down
8 changes: 7 additions & 1 deletion src/gui/editorwidgets/qgsqmlwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.