mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-04 00:04:25 -05:00 
			
		
		
		
	preview
This commit is contained in:
		
							parent
							
								
									7fd8732061
								
							
						
					
					
						commit
						6ac41b42d9
					
				@ -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,6 +1171,15 @@ 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 );
 | 
			
		||||
@ -1173,13 +1187,15 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
 | 
			
		||||
      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:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user