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 );
}
Esempio n. 2
0
void QgsLabelingWidget::labelModeChanged( int index )
{
  if ( mWidget )
    mStackedWidget->removeWidget( mWidget );

  delete mWidget;
  mWidget = nullptr;

  if ( index < 0 )
    return;

  if ( index == 2 )
  {
    QgsRuleBasedLabelingWidget *ruleWidget = new QgsRuleBasedLabelingWidget( mLayer, mCanvas, this );
    ruleWidget->setDockMode( dockMode() );
    connect( ruleWidget, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );
    connect( ruleWidget, &QgsRuleBasedLabelingWidget::widgetChanged, this, &QgsLabelingWidget::widgetChanged );
    mWidget = ruleWidget;
    mStackedWidget->addWidget( mWidget );
    mStackedWidget->setCurrentWidget( mWidget );
  }
  else if ( index == 1 || index == 3 )
  {
    if ( mLayer->labeling() && mLayer->labeling()->type() == QLatin1String( "simple" ) )
      mSimpleSettings.reset( new QgsPalLayerSettings( mLayer->labeling()->settings() ) );
    else
      mSimpleSettings.reset( new QgsPalLayerSettings() );

    QgsLabelingGui *simpleWidget = new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings, this );
    simpleWidget->setDockMode( dockMode() );
    connect( simpleWidget, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingWidget::widgetChanged );

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

    mWidget = simpleWidget;
    mStackedWidget->addWidget( mWidget );
    mStackedWidget->setCurrentWidget( mWidget );
  }
  emit widgetChanged();
}
Esempio n. 3
0
void QgsLabelingWidget::labelModeChanged( int index )
{
  if ( mWidget )
    mStackedWidget->removeWidget( mWidget );

  delete mWidget;
  mWidget = nullptr;

  if ( index < 0 )
    return;

  if ( index == 2 )
  {
    // note - QgsRuleBasedLabelingWidget handles conversion of existing non-rule based labels to rule based
    QgsRuleBasedLabelingWidget *ruleWidget = new QgsRuleBasedLabelingWidget( mLayer, mCanvas, this );
    ruleWidget->setDockMode( dockMode() );
    connect( ruleWidget, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );
    connect( ruleWidget, &QgsRuleBasedLabelingWidget::widgetChanged, this, &QgsLabelingWidget::widgetChanged );
    mWidget = ruleWidget;
    mStackedWidget->addWidget( mWidget );
    mStackedWidget->setCurrentWidget( mWidget );
  }
  else if ( index == 1 || index == 3 )
  {
    mSimpleSettings.reset();
    if ( mLayer->labeling() && mLayer->labeling()->type() == QLatin1String( "simple" ) )
    {
      mSimpleSettings.reset( new QgsPalLayerSettings( mLayer->labeling()->settings() ) );
    }
    else if ( mLayer->labeling() && mLayer->labeling()->type() == QLatin1String( "rule-based" ) )
    {
      // changing from rule-based to simple labels... grab first rule, and copy settings
      const QgsRuleBasedLabeling *rl = static_cast<const QgsRuleBasedLabeling *>( mLayer->labeling() );
      if ( const QgsRuleBasedLabeling::Rule *rootRule = rl->rootRule() )
      {
        if ( const QgsRuleBasedLabeling::Rule *firstChild = rootRule->children().value( 0 ) )
        {
          if ( firstChild->settings() )
            mSimpleSettings.reset( new QgsPalLayerSettings( *firstChild->settings() ) );
        }
      }
    }

    if ( !mSimpleSettings )
      mSimpleSettings.reset( new QgsPalLayerSettings() );

    QgsLabelingGui *simpleWidget = new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings, this );
    simpleWidget->setDockMode( dockMode() );
    connect( simpleWidget, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingWidget::widgetChanged );
    connect( simpleWidget, &QgsLabelingGui::auxiliaryFieldCreated, this, &QgsLabelingWidget::auxiliaryFieldCreated );

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

    mWidget = simpleWidget;
    mStackedWidget->addWidget( mWidget );
    mStackedWidget->setCurrentWidget( mWidget );
  }
  emit widgetChanged();
}