Skip to content

Commit

Permalink
get attributes from current feature
Browse files Browse the repository at this point in the history
by feature.attribute("outlet_1")
  • Loading branch information
signedav committed Sep 5, 2018
1 parent e8e32fa commit 016b0cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "qgsqmlwidgetwrapper.h"
#include "qgsmessagelog.h"
#include <QtQuickWidgets/QQuickWidget>
#include <QQuickWidget>
#include <QQmlContext>

QgsQmlWidgetWrapper::QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent )
: QgsWidgetWrapper( layer, editor, parent )
Expand All @@ -35,9 +37,9 @@ QWidget *QgsQmlWidgetWrapper::createWidget( QWidget *parent )

void QgsQmlWidgetWrapper::initWidget( QWidget *editor )
{
QQuickWidget *quickWidget = qobject_cast<QQuickWidget *>( editor );
mWidget = qobject_cast<QQuickWidget *>( editor );

if ( !quickWidget )
if ( !mWidget )
return;


Expand All @@ -47,7 +49,7 @@ void QgsQmlWidgetWrapper::initWidget( QWidget *editor )
return;
}

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

mQmlFile.close();
}
Expand All @@ -67,5 +69,6 @@ void QgsQmlWidgetWrapper::setQmlCode( const QString &qmlCode )

void QgsQmlWidgetWrapper::setFeature( const QgsFeature &feature )
{

if ( mWidget )
mWidget->rootContext()->setContextProperty( "feature", feature );
}
2 changes: 2 additions & 0 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
QTemporaryFile mQmlFile;

QQuickWidget *mWidget = nullptr;

QgsFeature mFeature;
};

#endif // QGSQMLWIDGETWRAPPER_H

0 comments on commit 016b0cb

Please sign in to comment.