Skip to content
Permalink
Browse files

layout

  • Loading branch information
signedav committed Sep 5, 2018
1 parent 561ea3b commit 4ad7067348e28b39dc5e044ba11f8a4d91372418
@@ -1117,9 +1117,27 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
layout->addWidget( baseWidget );

QLineEdit *title = new QLineEdit( itemData.name() );

//qmlCode
QPlainTextEdit *qmlCode = new QPlainTextEdit( itemData.qmlElementEditorConfiguration().qmlCode );
qmlCode->setPlaceholderText( tr( "Insert QML code here..." ) );

QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this );
qmlWrapper->setQmlCode( qmlCode->toPlainText() );
QgsFeature previewFeature;
mLayer->getFeatures().nextFeature( previewFeature );
qmlWrapper->setFeature( 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 );
} );

//templates
QComboBox *qmlObjectTemplate = new QComboBox();
qmlObjectTemplate->addItem( tr( "Free text..." ) );
qmlObjectTemplate->addItem( tr( "Rectangle" ) );
@@ -1142,7 +1160,7 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
" width: 100\n"
" height: 100\n"
" color: \"steelblue\"\n"
" Text{ text: \"A rectangle\"\n"
" Text{ text: \"A rectangle\" }\n"
"}\n" ) );
break;
}
@@ -1179,18 +1197,6 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
qmlCode->insertPlainText( QStringLiteral( "expression.evaluate(\"%1\")" ).arg( expressionWidget->currentText() ) );
} );


QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this );
qmlWrapper->setQmlCode( qmlCode->toPlainText() );
connect( qmlCode, &QPlainTextEdit::textChanged, this, [ = ]
{
qmlWrapper->setQmlCode( qmlCode->toPlainText() );
qmlWrapper->reinitWidget();
QgsFeature f;
mLayer->getFeatures().nextFeature( f );
qmlWrapper->setFeature( f );
} );

layout->addRow( tr( "Title" ), title );
QGroupBox *qmlCodeBox = new QGroupBox( tr( "QML Code" ) );
qmlCodeBox->setLayout( new QGridLayout );
@@ -61,16 +61,9 @@ void QgsQmlWidgetWrapper::reinitWidget( )
if ( !mWidget )
return;

if ( !mQmlFile.open() )
{
QgsMessageLog::logMessage( tr( "Failed to open temporary QML file" ) );
return;
}

mWidget->engine()->clearComponentCache();
mWidget->setSource( QUrl::fromLocalFile( mQmlFile.fileName() ) );

mQmlFile.close();
initWidget( mWidget );
}


@@ -93,6 +86,9 @@ void QgsQmlWidgetWrapper::setFeature( const QgsFeature &feature )
if ( mWidget )
{
QgsExpressionContext context = layer()->createExpressionContext();
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope( QgsProject::instance() )
<< QgsExpressionContextUtils::layerScope( layer() );

context.setFeature( feature );

@@ -46,8 +46,6 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
QTemporaryFile mQmlFile;

QQuickWidget *mWidget = nullptr;

QgsFeature mFeature;
};


0 comments on commit 4ad7067

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