void QgsLayerPropertiesWidget::updateSymbolLayerWidget( QgsSymbolLayerV2* layer )
{
  if ( stackedWidget->currentWidget() != pageDummy )
  {
    // stop updating from the original widget
    disconnect( stackedWidget->currentWidget(), SIGNAL( changed() ), this, SLOT( emitSignalChanged() ) );
    stackedWidget->removeWidget( stackedWidget->currentWidget() );
  }

  QgsSymbolLayerV2Registry* pReg = QgsSymbolLayerV2Registry::instance();

  QString layerType = layer->layerType();
  QgsSymbolLayerV2AbstractMetadata* am = pReg->symbolLayerMetadata( layerType );
  if ( am )
  {
    QgsSymbolLayerV2Widget* w = am->createSymbolLayerWidget( mVectorLayer );
    if ( w )
    {
      w->setExpressionContext( mPresetExpressionContext );
      if ( mMapCanvas )
        w->setMapCanvas( mMapCanvas );
      w->setSymbolLayer( layer );
      stackedWidget->addWidget( w );
      stackedWidget->setCurrentWidget( w );
      // start receiving updates from widget
      connect( w, SIGNAL( changed() ), this, SLOT( emitSignalChanged() ) );
      connect( w, SIGNAL( symbolChanged() ), this, SLOT( reloadLayer() ) );
      return;
    }
  }
  // When anything is not right
  stackedWidget->setCurrentWidget( pageDummy );
}
Пример #2
0
void QgsFieldExpressionWidget::setLayer( QgsVectorLayer *layer )
{
  if ( mFieldProxyModel->sourceFieldModel()->layer() )
    disconnect( mFieldProxyModel->sourceFieldModel()->layer(), SIGNAL( updatedFields() ), this, SLOT( reloadLayer() ) );

  mExpressionContext.reset( new QgsExpressionContext() );
  mExpressionContext->appendScope( QgsExpressionContextUtils::globalScope() );
  mExpressionContext->appendScope( QgsExpressionContextUtils::projectScope() );
  if ( layer )
    mExpressionContext->appendScope( QgsExpressionContextUtils::layerScope( layer ) );

  mFieldProxyModel->sourceFieldModel()->setLayer( layer );

  if ( mFieldProxyModel->sourceFieldModel()->layer() )
    connect( mFieldProxyModel->sourceFieldModel()->layer(), SIGNAL( updatedFields() ), SLOT( reloadLayer() ), Qt::UniqueConnection );
}
void QgsFieldExpressionWidget::setLayer( QgsVectorLayer *layer )
{
  if ( mFieldProxyModel->sourceFieldModel()->layer() )
    disconnect( mFieldProxyModel->sourceFieldModel()->layer(), SIGNAL( updatedFields() ), this, SLOT( reloadLayer() ) );

  if ( layer )
    mExpressionContext = layer->createExpressionContext();
  else
    mExpressionContext = QgsProject::instance()->createExpressionContext();

  mFieldProxyModel->sourceFieldModel()->setLayer( layer );

  if ( mFieldProxyModel->sourceFieldModel()->layer() )
    connect( mFieldProxyModel->sourceFieldModel()->layer(), SIGNAL( updatedFields() ), SLOT( reloadLayer() ), Qt::UniqueConnection );
}