16#include <QDialogButtonBox>
36 , mMessageBar( messageBar )
42 mLabelModeComboBox->addItem(
QgsApplication::getThemeIcon( QStringLiteral(
"labelingSingle.svg" ) ), tr(
"Single Labels" ), ModeSingle );
43 mLabelModeComboBox->addItem(
QgsApplication::getThemeIcon( QStringLiteral(
"labelingRuleBased.svg" ) ), tr(
"Rule-based Labeling" ), ModeRuleBased );
46 connect( mLabelRulesButton, &QAbstractButton::clicked,
this, &QgsLabelingWidget::showLabelingEngineRules );
47 connect( mEngineSettingsButton, &QAbstractButton::clicked,
this, &QgsLabelingWidget::showEngineConfigDialog );
49 connect( mLabelModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLabelingWidget::labelModeChanged );
53 mEngineSettingsButton->setIconSize( QSize( iconSize16, iconSize16 ) );
58 return qobject_cast<QgsLabelingGui *>( mWidget );
84 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer );
107 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( ModeRuleBased ) );
113 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( lyr.
drawLabels ? ModeSingle : ModeBlocking ) );
117 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( ModeNone ) );
120 if ( QgsLabelingGui *lg = qobject_cast<QgsLabelingGui *>( mWidget ) )
128 const Mode mode =
static_cast< Mode
>( mLabelModeComboBox->currentData().toInt() );
170void QgsLabelingWidget::labelModeChanged(
int index )
173 mStackedWidget->removeWidget( mWidget );
181 const Mode mode =
static_cast< Mode
>( mLabelModeComboBox->currentData().toInt() );
192 mWidget = ruleWidget;
193 mStackedWidget->addWidget( mWidget );
194 mStackedWidget->setCurrentWidget( mWidget );
201 mSimpleSettings.reset();
214 if ( firstChild->settings() )
220 if ( !mSimpleSettings )
225 if ( mSimpleSettings->fieldName.isEmpty() )
236 QgsLabelingGui *simpleWidget =
new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings,
this );
237 simpleWidget->setContext( context );
239 simpleWidget->setDockMode(
dockMode() );
243 simpleWidget->setLabelMode( QgsLabelingGui::Labels );
245 mWidget = simpleWidget;
254 obstacleWidget->
setSettings( mSimpleSettings->obstacleSettings() );
257 mSimpleSettings->obstacleSettings().setIsObstacle(
true );
258 mSimpleSettings->drawLabels =
false;
262 mSimpleSettings->setObstacleSettings( obstacleWidget->
settings() );
268 mWidget = obstacleWidget;
277 mStackedWidget->addWidget( mWidget );
278 mStackedWidget->setCurrentWidget( mWidget );
288void QgsLabelingWidget::showLabelingEngineRules()
292 QList< QgsAbstractLabelingEngineRule * > rules;
296 rules << const_cast<QgsAbstractLabelingEngineRule * >( rule );
316 dialog.setRules( rules );
320 settings.
setRules( dialog.rules() );
330void QgsLabelingWidget::showEngineConfigDialog()
The Qgis class provides global constants for use throughout the application.
Abstract base class for labeling engine rules.
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
static QgsPalLayerSettings defaultSettingsForLayer(const QgsVectorLayer *layer)
Returns the default layer settings to use for the specified vector layer.
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
virtual QgsAbstractVectorLayerLabeling * clone() const =0
Returns a new copy of the object.
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.
Stores global configuration for labeling engine.
void setRules(const QList< QgsAbstractLabelingEngineRule * > &rules)
Sets the labeling engine rules which must be satifisfied 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.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
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() const
clone this rule, return new instance
const QgsRuleBasedLabeling::RuleList & children() const
Returns all children rules of this rule.
Rule based labeling for a vector layer.
QgsRuleBasedLabeling::Rule * rootRule()
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
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 data sets.
void setLabeling(QgsAbstractVectorLayerLabeling *labeling)
Sets labeling configuration.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
void setLabelsEnabled(bool enabled)
Sets whether labels should be enabled for the layer.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
QString displayField() const
This is a shorthand for accessing the displayExpression if it is a simple field.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
@ Unknown
Unknown/invalid format.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.