Skip to content
Permalink
Browse files

preview

  • Loading branch information
signedav committed Sep 5, 2018
1 parent 7fd8732 commit 6ac41b42d9bd441df5875df7c8d2d0680a632a34
@@ -43,6 +43,8 @@ the Free Software Foundation; either version 2 of the License, or *
virtual void initWidget( QWidget *editor );


void reinitWidget();

void setQmlCode( const QString &qmlCode );

public slots:
@@ -19,6 +19,7 @@
#include "qgsattributesforminitcode.h"
#include "qgisapp.h"
#include "qgsfieldcombobox.h"
#include "qgsqmlwidgetwrapper.h"

QgsAttributesFormProperties::QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent )
: QWidget( parent )
@@ -1105,10 +1106,14 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
case QgsAttributesFormProperties::DnDTreeItemData::QmlWidget:
{
QDialog dlg;
dlg.resize( 600, 400 );
dlg.setWindowTitle( tr( "Configure QML Widget" ) );
QFormLayout *layout = new QFormLayout() ;
dlg.setLayout( layout );

QVBoxLayout *mainLayout = new QVBoxLayout();
QHBoxLayout *qmlLayout = new QHBoxLayout();
QFormLayout *layout = new QFormLayout();
mainLayout->addLayout( qmlLayout );
qmlLayout->addLayout( layout );
dlg.setLayout( mainLayout );
layout->addWidget( baseWidget );

//widget title
@@ -1166,20 +1171,31 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
} );


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


layout->addRow( tr( "Title" ), title );
QGroupBox *qmlCodeBox = new QGroupBox( tr( "QML Code" ) );
qmlCodeBox->setLayout( new QGridLayout );
qmlCodeBox->layout()->addWidget( qmlObjectTemplate );
qmlCodeBox->layout()->addWidget( attributeFieldCombo );
qmlCodeBox->layout()->addWidget( qmlCode );
layout->addRow( qmlCodeBox );
qmlLayout->addWidget( qmlWrapper->widget() );

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

connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );

dlg.layout()->addWidget( buttonBox );
mainLayout->addWidget( buttonBox );


if ( dlg.exec() )
{
@@ -18,6 +18,7 @@
#include <QtQuickWidgets/QQuickWidget>
#include <QQuickWidget>
#include <QQmlContext>
#include <QQmlEngine>

QgsQmlWidgetWrapper::QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent )
: QgsWidgetWrapper( layer, editor, parent )
@@ -54,6 +55,25 @@ void QgsQmlWidgetWrapper::initWidget( QWidget *editor )
mQmlFile.close();
}


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();
}


void QgsQmlWidgetWrapper::setQmlCode( const QString &qmlCode )
{
if ( !mQmlFile.open() )
@@ -62,6 +82,7 @@ void QgsQmlWidgetWrapper::setQmlCode( const QString &qmlCode )
return;
}

mQmlFile.resize( 0 );
mQmlFile.write( qmlCode.toUtf8() );

mQmlFile.close();
@@ -35,6 +35,8 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper

void initWidget( QWidget *editor ) override;

void reinitWidget();

void setQmlCode( const QString &qmlCode );

public slots:

0 comments on commit 6ac41b4

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