Skip to content

Commit 5f4acde

Browse files
committed
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
1 parent 4504845 commit 5f4acde

File tree

3 files changed

+14
-25
lines changed

3 files changed

+14
-25
lines changed

python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,7 @@ passes the ``feature`` into the context property of the widget
5858

5959
};
6060

61-
class QmlExpression : QObject
62-
{
63-
%Docstring
64-
To pass the QgsExpression functionality and it's context to the context of the QQuickWidget
65-
66-
.. versionadded:: 3.4
67-
%End
68-
69-
%TypeHeaderCode
70-
#include "qgsqmlwidgetwrapper.h"
71-
%End
72-
public:
73-
void setExpressionContext( const QgsExpressionContext &context );
7461

75-
QVariant evaluate( const QString &expression ) const;
76-
%Docstring
77-
evaluates the value regarding the /a expression and the context
78-
%End
79-
80-
};
8162

8263
/************************************************************************
8364
* This file has been generated automatically from *

src/app/qgsattributesformproperties.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,14 +1124,14 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
11241124
qmlCode->setPlaceholderText( tr( "Insert QML code here..." ) );
11251125

11261126
QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this );
1127-
qmlWrapper->setQmlCode( qmlCode->toPlainText() );
1127+
QgsFeature previewFeature;
1128+
mLayer->getFeatures().nextFeature( previewFeature );
1129+
11281130
//update preview on text change
11291131
connect( qmlCode, &QPlainTextEdit::textChanged, this, [ = ]
11301132
{
11311133
qmlWrapper->setQmlCode( qmlCode->toPlainText() );
11321134
qmlWrapper->reinitWidget();
1133-
QgsFeature previewFeature;
1134-
mLayer->getFeatures().nextFeature( previewFeature );
11351135
qmlWrapper->setFeature( previewFeature );
11361136
} );
11371137

@@ -1141,7 +1141,7 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
11411141
qmlObjectTemplate->addItem( tr( "Rectangle" ) );
11421142
qmlObjectTemplate->addItem( tr( "Pie chart" ) );
11431143
qmlObjectTemplate->addItem( tr( "Bar chart" ) );
1144-
connect( qmlObjectTemplate, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), qmlCode, [ = ]( int index )
1144+
connect( qmlObjectTemplate, qgis::overload<int>::of( &QComboBox::activated ), qmlCode, [ = ]( int index )
11451145
{
11461146
qmlCode->clear();
11471147
switch ( index )
@@ -1215,7 +1215,7 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
12151215

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

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

12381240
QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );

src/gui/editorwidgets/qgsqmlwidgetwrapper.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,16 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
6363
QQuickWidget *mWidget = nullptr;
6464
};
6565

66+
67+
#ifndef SIP_RUN
68+
///@cond PRIVATE
69+
6670
/**
6771
* \ingroup gui
6872
* To pass the QgsExpression functionality and it's context to the context of the QQuickWidget
6973
* \since QGIS 3.4
7074
*/
71-
class GUI_EXPORT QmlExpression : public QObject
75+
class QmlExpression : public QObject
7276
{
7377
Q_OBJECT
7478

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

8591
#endif // QGSQMLWIDGETWRAPPER_H

0 commit comments

Comments
 (0)