Esempio n. 1
0
void QgsLabelingWidget::labelModeChanged( int index )
{
  if ( index < 0 )
    return;

  if ( index != 2 )
  {
    if ( QgsLabelingGui* widgetSimple = qobject_cast<QgsLabelingGui*>( mWidget ) )
    {
      // lighter variant - just change the mode of existing widget
      if ( index == 3 )
        widgetSimple->setLabelMode( QgsLabelingGui::ObstaclesOnly );
      else
        widgetSimple->setLabelMode( static_cast< QgsLabelingGui::LabelMode >( index ) );
      return;
    }
  }

  // in general case we need to recreate the widget

  if ( mWidget )
    mStackedWidget->removeWidget( mWidget );

  delete mWidget;
  mWidget = nullptr;

  if ( index == 2 )
  {
    mWidget = new QgsRuleBasedLabelingWidget( mLayer, mCanvas, this );
  }
  else
  {
    QgsLabelingGui* w = new QgsLabelingGui( mLayer, mCanvas, nullptr, this );

    if ( index == 3 )
      w->setLabelMode( QgsLabelingGui::ObstaclesOnly );
    else
      w->setLabelMode( static_cast< QgsLabelingGui::LabelMode >( index ) );

    w->init();
    mWidget = w;
  }

  mStackedWidget->addWidget( mWidget );
  mStackedWidget->setCurrentWidget( mWidget );
}