16#include <QDialogButtonBox>
20#include "moc_qgslabelingwidget.cpp"
37 , mMessageBar( messageBar )
43 mLabelModeComboBox->addItem(
QgsApplication::getThemeIcon( QStringLiteral(
"labelingSingle.svg" ) ), tr(
"Single Labels" ), ModeSingle );
44 mLabelModeComboBox->addItem(
QgsApplication::getThemeIcon( QStringLiteral(
"labelingRuleBased.svg" ) ), tr(
"Rule-based Labeling" ), ModeRuleBased );
47 connect( mLabelRulesButton, &QAbstractButton::clicked,
this, &QgsLabelingWidget::showLabelingEngineRules );
48 connect( mEngineSettingsButton, &QAbstractButton::clicked,
this, &QgsLabelingWidget::showEngineConfigDialog );
50 connect( mLabelModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLabelingWidget::labelModeChanged );
54 mEngineSettingsButton->setIconSize( QSize( iconSize16, iconSize16 ) );
59 return qobject_cast<QgsLabelingGui *>( mWidget );
85 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer );
108 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( ModeRuleBased ) );
114 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( lyr.
drawLabels ? ModeSingle : ModeBlocking ) );
118 mLabelModeComboBox->setCurrentIndex( mLabelModeComboBox->findData( ModeNone ) );
121 if ( QgsLabelingGui *lg = qobject_cast<QgsLabelingGui *>( mWidget ) )
129 const Mode mode =
static_cast<Mode
>( mLabelModeComboBox->currentData().toInt() );
171void QgsLabelingWidget::labelModeChanged(
int index )
174 mStackedWidget->removeWidget( mWidget );
182 const Mode mode =
static_cast<Mode
>( mLabelModeComboBox->currentData().toInt() );
193 mWidget = ruleWidget;
194 mStackedWidget->addWidget( mWidget );
195 mStackedWidget->setCurrentWidget( mWidget );
202 mSimpleSettings.reset();
215 if ( firstChild->settings() )
221 if ( !mSimpleSettings )
226 if ( mSimpleSettings->fieldName.isEmpty() )
237 QgsLabelingGui *simpleWidget =
new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings,
this );
238 simpleWidget->setContext( context );
240 simpleWidget->setDockMode(
dockMode() );
244 simpleWidget->setLabelMode( QgsLabelingGui::Labels );
246 mWidget = simpleWidget;
255 obstacleWidget->
setSettings( mSimpleSettings->obstacleSettings() );
258 mSimpleSettings->obstacleSettings().setIsObstacle(
true );
259 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 );
315 dialog.setRules( rules );
319 settings.
setRules( dialog.rules() );
329void 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.