31#include <QDialogButtonBox>
34#include "moc_qgslabelingwidget.cpp"
40 , mMessageBar( messageBar )
46 mLabelModeComboBox->addItem(
QgsApplication::getThemeIcon( QStringLiteral(
"labelingSingle.svg" ) ), tr(
"Single Labels" ), ModeSingle );
47 mLabelModeComboBox->addItem(
QgsApplication::getThemeIcon( QStringLiteral(
"labelingRuleBased.svg" ) ), tr(
"Rule-based Labeling" ), ModeRuleBased );
50 connect( mLabelRulesButton, &QAbstractButton::clicked,
this, &QgsLabelingWidget::showLabelingEngineRulesPrivate );
51 connect( mEngineSettingsButton, &QAbstractButton::clicked,
this, &QgsLabelingWidget::showEngineConfigDialogPrivate );
53 connect( mLabelModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLabelingWidget::labelModeChanged );
57 mEngineSettingsButton->setIconSize( QSize( iconSize16, iconSize16 ) );
58 mLabelRulesButton->setIconSize( QSize( iconSize16, iconSize16 ) );
63 return qobject_cast<QgsLabelingGui *>( mWidget );
70 mLayer->setLabeling( mOldSettings.release() );
71 mLayer->setLabelsEnabled( mOldLabelsEnabled );
89 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer );
91 if ( mLayer->labeling() )
93 mOldSettings.reset( mLayer->labeling()->clone() );
110 if ( mLayer->labelsEnabled() && mLayer->labeling()->type() == QLatin1String(
"rule-based" ) )
112 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( ModeRuleBased ) );
114 else if ( mLayer->labelsEnabled() && mLayer->labeling()->type() == QLatin1String(
"simple" ) )
118 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( lyr.
drawLabels ? ModeSingle : ModeBlocking ) );
122 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( ModeNone ) );
125 if ( QgsLabelingGui *lg = qobject_cast<QgsLabelingGui *>( mWidget ) )
133 const Mode mode =
static_cast<Mode
>( mLabelModeComboBox->currentData().toInt() );
140 mLayer->setLabelsEnabled(
true );
147 mLayer->setLabelsEnabled(
true );
154 mLayer->setLabelsEnabled(
true );
160 mLayer->setLabelsEnabled(
false );
171 mLayer->triggerRepaint();
174void QgsLabelingWidget::labelModeChanged(
int index )
177 mStackedWidget->removeWidget( mWidget );
185 const Mode mode =
static_cast<Mode
>( mLabelModeComboBox->currentData().toInt() );
196 mWidget = ruleWidget;
197 mStackedWidget->addWidget( mWidget );
198 mStackedWidget->setCurrentWidget( mWidget );
205 mSimpleSettings.reset();
206 if ( mLayer->labeling() && mLayer->labeling()->type() == QLatin1String(
"simple" ) )
208 mSimpleSettings = std::make_unique<QgsPalLayerSettings>( mLayer->labeling()->settings() );
210 else if ( mLayer->labeling() && mLayer->labeling()->type() == QLatin1String(
"rule-based" ) )
213 const QgsRuleBasedLabeling *rl =
static_cast<const QgsRuleBasedLabeling *
>( mLayer->labeling() );
214 if (
const QgsRuleBasedLabeling::Rule *rootRule = rl->
rootRule() )
216 if (
const QgsRuleBasedLabeling::Rule *firstChild = rootRule->children().value( 0 ) )
218 if ( firstChild->settings() )
219 mSimpleSettings = std::make_unique<QgsPalLayerSettings>( *firstChild->settings() );
224 if ( !mSimpleSettings )
229 if ( mSimpleSettings->fieldName.isEmpty() )
230 mSimpleSettings->fieldName = mLayer->displayField();
232 QgsSymbolWidgetContext context;
240 QgsLabelingGui *simpleWidget =
new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings,
this );
241 simpleWidget->setContext( context );
243 simpleWidget->setDockMode(
dockMode() );
247 simpleWidget->setLabelMode( QgsLabelingGui::Labels );
249 mWidget = simpleWidget;
254 QgsLabelObstacleSettingsWidget *obstacleWidget =
new QgsLabelObstacleSettingsWidget(
this, mLayer );
258 obstacleWidget->
setSettings( mSimpleSettings->obstacleSettings() );
261 mSimpleSettings->obstacleSettings().setIsObstacle(
true );
262 mSimpleSettings->drawLabels =
false;
265 mSimpleSettings->setObstacleSettings( obstacleWidget->
settings() );
271 mWidget = obstacleWidget;
280 mStackedWidget->addWidget( mWidget );
281 mStackedWidget->setCurrentWidget( mWidget );
296 QList<QgsAbstractLabelingEngineRule *> rules;
300 rules << const_cast<QgsAbstractLabelingEngineRule *>( rule );
329 parent->activateWindow();
333void QgsLabelingWidget::showLabelingEngineRulesPrivate()
352 parent->activateWindow();
356void 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.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
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.