16 #include <QDialogButtonBox>
17 #include <QDomElement>
35 , mMessageBar( messageBar )
41 mLabelModeComboBox->addItem(
QgsApplication::getThemeIcon( QStringLiteral(
"labelingSingle.svg" ) ), tr(
"Single Labels" ), ModeSingle );
42 mLabelModeComboBox->addItem(
QgsApplication::getThemeIcon( QStringLiteral(
"labelingRuleBased.svg" ) ), tr(
"Rule-based Labeling" ), ModeRuleBased );
45 connect( mEngineSettingsButton, &QAbstractButton::clicked,
this, &QgsLabelingWidget::showEngineConfigDialog );
47 connect( mLabelModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLabelingWidget::labelModeChanged );
51 mEngineSettingsButton->setIconSize( QSize( iconSize16, iconSize16 ) );
56 return qobject_cast<QgsLabelingGui *>( mWidget );
63 mLayer->setLabeling( mOldSettings.release() );
64 mLayer->setLabelsEnabled( mOldLabelsEnabled );
82 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer );
84 if ( mLayer->labeling() )
86 mOldSettings.reset( mLayer->labeling()->clone() );
103 if ( mLayer->labelsEnabled() && mLayer->labeling()->type() == QLatin1String(
"rule-based" ) )
105 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( ModeRuleBased ) );
107 else if ( mLayer->labelsEnabled() && mLayer->labeling()->type() == QLatin1String(
"simple" ) )
111 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( lyr.
drawLabels ? ModeSingle : ModeBlocking ) );
115 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( ModeNone ) );
118 if ( QgsLabelingGui *lg = qobject_cast<QgsLabelingGui *>( mWidget ) )
126 const Mode mode =
static_cast< Mode
>( mLabelModeComboBox->currentData().toInt() );
134 mLayer->setLabelsEnabled(
true );
141 mLayer->setLabelsEnabled(
true );
148 mLayer->setLabelsEnabled(
true );
154 mLayer->setLabelsEnabled(
false );
162 writeSettingsToLayer();
165 mLayer->triggerRepaint();
168 void QgsLabelingWidget::labelModeChanged(
int index )
171 mStackedWidget->removeWidget( mWidget );
179 const Mode mode =
static_cast< Mode
>( mLabelModeComboBox->currentData().toInt() );
186 QgsRuleBasedLabelingWidget *ruleWidget =
new QgsRuleBasedLabelingWidget( mLayer, mCanvas,
this );
187 ruleWidget->setDockMode( dockMode() );
190 mWidget = ruleWidget;
191 mStackedWidget->addWidget( mWidget );
192 mStackedWidget->setCurrentWidget( mWidget );
199 mSimpleSettings.reset();
200 if ( mLayer->labeling() && mLayer->labeling()->type() == QLatin1String(
"simple" ) )
204 else if ( mLayer->labeling() && mLayer->labeling()->type() == QLatin1String(
"rule-based" ) )
212 if ( firstChild->settings() )
218 if ( !mSimpleSettings )
223 if ( mSimpleSettings->fieldName.isEmpty() )
224 mSimpleSettings->fieldName = mLayer->displayField();
234 QgsLabelingGui *simpleWidget =
new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings,
this );
235 simpleWidget->setContext( context );
237 simpleWidget->setDockMode( dockMode() );
241 simpleWidget->setLabelMode( QgsLabelingGui::Labels );
243 mWidget = simpleWidget;
252 obstacleWidget->
setSettings( mSimpleSettings->obstacleSettings() );
255 mSimpleSettings->obstacleSettings().setIsObstacle(
true );
256 mSimpleSettings->drawLabels =
false;
260 mSimpleSettings->setObstacleSettings( obstacleWidget->
settings() );
262 emit widgetChanged();
266 mWidget = obstacleWidget;
275 mStackedWidget->addWidget( mWidget );
276 mStackedWidget->setCurrentWidget( mWidget );
283 emit widgetChanged();
286 void QgsLabelingWidget::showEngineConfigDialog()