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 )
221 if ( mSimpleSettings->fieldName.isEmpty() )
222 mSimpleSettings->fieldName = mLayer->displayField();
232 QgsLabelingGui *simpleWidget =
new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings,
this );
233 simpleWidget->setContext( context );
235 simpleWidget->setDockMode( dockMode() );
239 simpleWidget->setLabelMode( QgsLabelingGui::Labels );
241 mWidget = simpleWidget;
250 obstacleWidget->
setSettings( mSimpleSettings->obstacleSettings() );
253 mSimpleSettings->obstacleSettings().setIsObstacle(
true );
254 mSimpleSettings->drawLabels =
false;
258 mSimpleSettings->setObstacleSettings( obstacleWidget->
settings() );
260 emit widgetChanged();
264 mWidget = obstacleWidget;
273 mStackedWidget->addWidget( mWidget );
274 mStackedWidget->setCurrentWidget( mWidget );
281 emit widgetChanged();
284 void QgsLabelingWidget::showEngineConfigDialog()