31#include <QDialogButtonBox>
35#include "moc_qgslabelingwidget.cpp"
37using namespace Qt::StringLiterals;
43 , mMessageBar( messageBar )
53 connect( mLabelRulesButton, &QAbstractButton::clicked,
this, &QgsLabelingWidget::showLabelingEngineRulesPrivate );
54 connect( mEngineSettingsButton, &QAbstractButton::clicked,
this, &QgsLabelingWidget::showEngineConfigDialogPrivate );
56 connect( mLabelModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLabelingWidget::labelModeChanged );
60 mEngineSettingsButton->setIconSize( QSize( iconSize16, iconSize16 ) );
61 mLabelRulesButton->setIconSize( QSize( iconSize16, iconSize16 ) );
66 return qobject_cast<QgsLabelingGui *>( mWidget );
73 mLayer->setLabeling( mOldSettings.release() );
74 mLayer->setLabelsEnabled( mOldLabelsEnabled );
94 if ( mLayer->labeling() )
96 mOldSettings.reset( mLayer->labeling()->clone() );
100 mOldLabelsEnabled = mLayer->labelsEnabled();
113 if ( mLayer->labelsEnabled() && mLayer->labeling()->type() ==
"rule-based"_L1 )
115 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( ModeRuleBased ) );
117 else if ( mLayer->labelsEnabled() && mLayer->labeling()->type() ==
"simple"_L1 )
121 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( lyr.
drawLabels ? ModeSingle : ModeBlocking ) );
125 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( ModeNone ) );
128 if ( QgsLabelingGui *lg = qobject_cast<QgsLabelingGui *>( mWidget ) )
136 const Mode mode =
static_cast<Mode
>( mLabelModeComboBox->currentData().toInt() );
143 mLayer->setLabelsEnabled(
true );
150 mLayer->setLabelsEnabled(
true );
157 mLayer->setLabelsEnabled(
true );
163 mLayer->setLabelsEnabled(
false );
174 mLayer->triggerRepaint();
177void QgsLabelingWidget::labelModeChanged(
int index )
180 mStackedWidget->removeWidget( mWidget );
188 const Mode mode =
static_cast<Mode
>( mLabelModeComboBox->currentData().toInt() );
199 mWidget = ruleWidget;
200 mStackedWidget->addWidget( mWidget );
201 mStackedWidget->setCurrentWidget( mWidget );
208 mSimpleSettings.reset();
209 if ( mLayer->labeling() && mLayer->labeling()->type() ==
"simple"_L1 )
211 mSimpleSettings = std::make_unique<QgsPalLayerSettings>( mLayer->labeling()->settings() );
213 else if ( mLayer->labeling() && mLayer->labeling()->type() ==
"rule-based"_L1 )
216 const QgsRuleBasedLabeling *rl =
static_cast<const QgsRuleBasedLabeling *
>( mLayer->labeling() );
217 if (
const QgsRuleBasedLabeling::Rule *rootRule = rl->
rootRule() )
219 if (
const QgsRuleBasedLabeling::Rule *firstChild = rootRule->children().value( 0 ) )
221 if ( firstChild->settings() )
222 mSimpleSettings = std::make_unique<QgsPalLayerSettings>( *firstChild->settings() );
227 if ( !mSimpleSettings )
232 if ( mSimpleSettings->fieldName.isEmpty() )
233 mSimpleSettings->fieldName = mLayer->displayField();
235 QgsSymbolWidgetContext context;
243 QgsLabelingGui *simpleWidget =
new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings,
this );
244 simpleWidget->setContext( context );
246 simpleWidget->setDockMode(
dockMode() );
250 simpleWidget->setLabelMode( QgsLabelingGui::Labels );
252 mWidget = simpleWidget;
257 QgsLabelObstacleSettingsWidget *obstacleWidget =
new QgsLabelObstacleSettingsWidget(
this, mLayer );
261 obstacleWidget->
setSettings( mSimpleSettings->obstacleSettings() );
264 mSimpleSettings->obstacleSettings().setIsObstacle(
true );
265 mSimpleSettings->drawLabels =
false;
268 mSimpleSettings->setObstacleSettings( obstacleWidget->
settings() );
274 mWidget = obstacleWidget;
283 mStackedWidget->addWidget( mWidget );
284 mStackedWidget->setCurrentWidget( mWidget );
299 QList<QgsAbstractLabelingEngineRule *> rules;
303 rules << const_cast<QgsAbstractLabelingEngineRule *>( rule );
332 parent->activateWindow();
336void QgsLabelingWidget::showLabelingEngineRulesPrivate()
355 parent->activateWindow();
359void QgsLabelingWidget::showEngineConfigDialogPrivate()
Abstract base class for labeling engine rules.
static QgsPalLayerSettings defaultSettingsForLayer(const QgsVectorLayer *layer)
Returns the default layer settings to use for the specified vector layer.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Dialog for configuring the labeling engine.
A dialog which allows configuration of a list of labeling engine rules.
QList< QgsAbstractLabelingEngineRule * > rules() const
Returns the rules shown in the dialog.
void setRules(const QList< QgsAbstractLabelingEngineRule * > &rules)
Sets the rules to show in the dialog.
Stores global configuration for labeling engine.
void setRules(const QList< QgsAbstractLabelingEngineRule * > &rules)
Sets the labeling engine rules which must be satisfied while placing labels.
QList< QgsAbstractLabelingEngineRule * > rules()
Returns a list of labeling engine rules which must be satisfied while placing labels.
Map canvas is a class for displaying all GIS data types on a canvas.
void refreshAllLayers()
Reload all layers (including refreshing layer properties from their data sources),...
Base class for all map layer types.
A bar for displaying non-blocking messages to the user.
Contains settings for how a map layer will be labeled.
bool drawLabels
Whether to draw labels for this layer.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets project's global labeling engine settings.
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns project's global labeling engine settings.
void setDirty(bool b=true)
Flag the project as dirty (modified).
A child rule for QgsRuleBasedLabeling.
QgsRuleBasedLabeling::Rule * clone(bool resetRuleKey=true) const
clone this rule
Rule based labeling for a vector layer.
QgsRuleBasedLabeling::Rule * rootRule()
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
void widgetChanged()
Emitted when the text format defined by the widget changes.
Basic implementation of the labeling interface.
Represents a vector layer which manages a vector based dataset.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.