Пример #1
0
Qgs25DRendererWidget::Qgs25DRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
    : QgsRendererV2Widget( layer, style )
    , mRenderer( nullptr )
{
  if ( !layer )
    return;

  // the renderer only applies to point vector layers
  if ( layer->geometryType() != QGis::Polygon )
  {
    //setup blank dialog
    QGridLayout* layout = new QGridLayout( this );
    QLabel* label = new QLabel( tr( "The 2.5D renderer only can be used with polygon layers. \n"
                                    "'%1' is not a polygon layer and cannot be rendered in 2.5D." )
                                .arg( layer->name() ), this );
    layout->addWidget( label );
    return;
  }

  setupUi( this );

  if ( renderer )
  {
    mRenderer = Qgs25DRenderer::convertFromRenderer( renderer );
  }

  mHeightWidget->setLayer( layer );

  QgsExpressionContextScope* scope = QgsExpressionContextUtils::layerScope( mLayer );
  QVariant height = scope->variable( "qgis_25d_height" );
  QVariant angle = scope->variable( "qgis_25d_angle" );
  delete scope;

  mHeightWidget->setField( height.isNull() ? "10" : height.toString() );
  mAngleWidget->setValue( angle.isNull() ? 70 : angle.toDouble() );
  mWallColorButton->setColor( mRenderer->wallColor() );
  mRoofColorButton->setColor( mRenderer->roofColor() );
  mShadowColorButton->setColor( mRenderer->shadowColor() );
  mShadowEnabledWidget->setChecked( mRenderer->shadowEnabled() );
  mShadowSizeWidget->setValue( mRenderer->shadowSpread() );
  mWallExpositionShading->setChecked( mRenderer->wallShadingEnabled() );

  connect( mAngleWidget, SIGNAL( valueChanged( int ) ), this, SLOT( updateRenderer() ) );
  connect( mHeightWidget, SIGNAL( fieldChanged( QString ) ), this, SLOT( updateRenderer() ) );
  connect( mWallColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
  connect( mRoofColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
  connect( mShadowColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( updateRenderer() ) );
  connect( mShadowEnabledWidget, SIGNAL( toggled( bool ) ), this, SLOT( updateRenderer() ) );
  connect( mShadowSizeWidget, SIGNAL( valueChanged( double ) ), this, SLOT( updateRenderer() ) );
  connect( mWallExpositionShading, SIGNAL( toggled( bool ) ), this, SLOT( updateRenderer() ) );
}
Пример #2
0
Qgs25DRendererWidget::Qgs25DRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer )
  : QgsRendererWidget( layer, style )

{
  if ( !layer )
    return;

  // the renderer only applies to point vector layers
  if ( layer->geometryType() != QgsWkbTypes::PolygonGeometry )
  {
    //setup blank dialog
    QGridLayout *layout = new QGridLayout( this );
    QLabel *label = new QLabel( tr( "The 2.5D renderer only can be used with polygon layers. \n"
                                    "'%1' is not a polygon layer and cannot be rendered in 2.5D." )
                                .arg( layer->name() ), this );
    layout->addWidget( label );
    return;
  }

  setupUi( this );
  this->layout()->setContentsMargins( 0, 0, 0, 0 );

  mAngleWidget->setClearValue( 0 );
  mWallColorButton->setColorDialogTitle( tr( "Select Wall Color" ) );
  mWallColorButton->setAllowOpacity( true );
  mWallColorButton->setContext( QStringLiteral( "symbology" ) );
  mRoofColorButton->setColorDialogTitle( tr( "Select Roof Color" ) );
  mRoofColorButton->setAllowOpacity( true );
  mRoofColorButton->setContext( QStringLiteral( "symbology" ) );
  mShadowColorButton->setColorDialogTitle( tr( "Select Shadow Color" ) );
  mShadowColorButton->setAllowOpacity( true );
  mShadowColorButton->setContext( QStringLiteral( "symbology" ) );

  if ( renderer )
  {
    mRenderer = Qgs25DRenderer::convertFromRenderer( renderer );
  }

  mHeightWidget->setLayer( layer );

  QgsExpressionContextScope *scope = QgsExpressionContextUtils::layerScope( mLayer );
  QVariant height = scope->variable( QStringLiteral( "qgis_25d_height" ) );
  QVariant angle = scope->variable( QStringLiteral( "qgis_25d_angle" ) );
  delete scope;

  mHeightWidget->setField( height.isNull() ? QStringLiteral( "10" ) : height.toString() );
  mAngleWidget->setValue( angle.isNull() ? 70 : angle.toDouble() );
  mWallColorButton->setColor( mRenderer->wallColor() );
  mRoofColorButton->setColor( mRenderer->roofColor() );
  mShadowColorButton->setColor( mRenderer->shadowColor() );
  mShadowEnabledWidget->setChecked( mRenderer->shadowEnabled() );
  mShadowSizeWidget->setValue( mRenderer->shadowSpread() );
  mWallExpositionShading->setChecked( mRenderer->wallShadingEnabled() );

  connect( mAngleWidget, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &Qgs25DRendererWidget::updateRenderer );
  connect( mHeightWidget, static_cast < void ( QgsFieldExpressionWidget::* )( const QString & ) > ( &QgsFieldExpressionWidget::fieldChanged ), this, &Qgs25DRendererWidget::updateRenderer );
  connect( mWallColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
  connect( mRoofColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
  connect( mShadowColorButton, &QgsColorButton::colorChanged, this, &Qgs25DRendererWidget::updateRenderer );
  connect( mShadowEnabledWidget, &QGroupBox::toggled, this, &Qgs25DRendererWidget::updateRenderer );
  connect( mShadowSizeWidget, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &Qgs25DRendererWidget::updateRenderer );
  connect( mWallExpositionShading, &QAbstractButton::toggled, this, &Qgs25DRendererWidget::updateRenderer );
}