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(); }
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(); }