20#include <QDialogButtonBox>
28 : QDialog( parent, flags )
32 setWindowTitle( tr(
"Configure Rule" ) );
33 setObjectName( QStringLiteral(
"QgsLabelingEngineRuleDialog" ) );
35 QVBoxLayout *layout =
new QVBoxLayout(
this );
36 layout->addWidget( mWidget );
38 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal,
this );
39 layout->addWidget( mButtonBox );
44 connect( mButtonBox->button( QDialogButtonBox::Ok ), &QAbstractButton::clicked,
this, &QDialog::accept );
45 connect( mButtonBox->button( QDialogButtonBox::Cancel ), &QAbstractButton::clicked,
this, &QDialog::reject );
55 return mWidget->
rule();
63QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget::QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget( QWidget *parent )
68 setWindowTitle( tr(
"Prevent Labels Overlapping Features" ) );
69 setPanelTitle( tr(
"Configure Rule" ) );
74 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget::onChanged );
86 mEditName->setText( castRule->
name() );
90 mBlockSignals =
false;
95 std::unique_ptr< QgsLabelingEngineRuleAvoidLabelOverlapWithFeature > res = std::make_unique< QgsLabelingEngineRuleAvoidLabelOverlapWithFeature >();
96 res->setName( mEditName->text() );
97 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
98 res->setTargetLayer( qobject_cast< QgsVectorLayer * >( mComboTargetLayer->currentLayer() ) );
102void QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget::onChanged()
104 if ( !mBlockSignals )
112QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget( QWidget *parent )
117 setWindowTitle( tr(
"Push Labels Away from Features" ) );
118 setPanelTitle( tr(
"Configure Rule" ) );
126 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged );
130 connect( mSpinDistance, qOverload< double >( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged );
132 connect( mCostSlider, &QSlider::valueChanged,
this, &QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged );
141 mBlockSignals =
true;
142 mEditName->setText( castRule->
name() );
146 mSpinDistance->setValue( castRule->
distance() );
147 mDistanceUnitWidget->setUnit( castRule->
distanceUnit() );
150 mCostSlider->setValue(
static_cast< int >( castRule->
cost() * 10 ) );
152 mBlockSignals =
false;
157 std::unique_ptr< QgsLabelingEngineRuleMinimumDistanceLabelToFeature > res = std::make_unique< QgsLabelingEngineRuleMinimumDistanceLabelToFeature >();
158 res->setName( mEditName->text() );
159 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
160 res->setTargetLayer( qobject_cast< QgsVectorLayer * >( mComboTargetLayer->currentLayer() ) );
162 res->setDistance( mSpinDistance->value() );
163 res->setDistanceUnit( mDistanceUnitWidget->unit() );
164 res->setDistanceUnitScale( mDistanceUnitWidget->getMapUnitScale() );
166 res->setCost( mCostSlider->value() / 10.0 );
168 return res.release();
171void QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged()
173 if ( !mBlockSignals )
181QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget( QWidget *parent )
186 setWindowTitle( tr(
"Pull Labels toward Features" ) );
187 setPanelTitle( tr(
"Configure Rule" ) );
195 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged );
199 connect( mSpinDistance, qOverload< double >( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged );
201 connect( mCostSlider, &QSlider::valueChanged,
this, &QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged );
210 mBlockSignals =
true;
211 mEditName->setText( castRule->
name() );
215 mSpinDistance->setValue( castRule->
distance() );
216 mDistanceUnitWidget->setUnit( castRule->
distanceUnit() );
219 mCostSlider->setValue(
static_cast< int >( castRule->
cost() * 10 ) );
221 mBlockSignals =
false;
226 std::unique_ptr< QgsLabelingEngineRuleMaximumDistanceLabelToFeature > res = std::make_unique< QgsLabelingEngineRuleMaximumDistanceLabelToFeature >();
227 res->setName( mEditName->text() );
228 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
229 res->setTargetLayer( qobject_cast< QgsVectorLayer * >( mComboTargetLayer->currentLayer() ) );
231 res->setDistance( mSpinDistance->value() );
232 res->setDistanceUnit( mDistanceUnitWidget->unit() );
233 res->setDistanceUnitScale( mDistanceUnitWidget->getMapUnitScale() );
235 res->setCost( mCostSlider->value() / 10.0 );
237 return res.release();
240void QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged()
242 if ( !mBlockSignals )
251QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget( QWidget *parent )
256 setWindowTitle( tr(
"Pull Labels toward Features" ) );
257 setPanelTitle( tr(
"Configure Rule" ) );
265 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::onChanged );
269 connect( mSpinDistance, qOverload< double >( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::onChanged );
279 mBlockSignals =
true;
280 mEditName->setText( castRule->
name() );
284 mSpinDistance->setValue( castRule->
distance() );
285 mDistanceUnitWidget->setUnit( castRule->
distanceUnit() );
288 mBlockSignals =
false;
293 std::unique_ptr< QgsLabelingEngineRuleMinimumDistanceLabelToLabel > res = std::make_unique< QgsLabelingEngineRuleMinimumDistanceLabelToLabel >();
294 res->setName( mEditName->text() );
295 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
296 res->setTargetLayer( mComboTargetLayer->currentLayer() );
298 res->setDistance( mSpinDistance->value() );
299 res->setDistanceUnit( mDistanceUnitWidget->unit() );
300 res->setDistanceUnitScale( mDistanceUnitWidget->getMapUnitScale() );
302 return res.release();
305void QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::onChanged()
307 if ( !mBlockSignals )
@ SpatialLayer
All spatial layers.
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MetersInMapUnits
Meters value as Map units.
Qgis::RenderUnit distanceUnit() const
Returns the units for the distance between labels and the features from the targetLayer().
const QgsMapUnitScale & distanceUnitScale() const
Returns the scaling for the distance between labels and the features from the targetLayer().
double distance() const
Returns the acceptable distance threshold between labels and the features from the targetLayer().
QgsVectorLayer * targetLayer() const
Returns the layer providing the features which labels must be distant from (or close to).
double cost() const
Returns the penalty cost incurred when the rule is violated.
QgsMapLayer * labeledLayer() const
Returns the layer providing the labels.
Abstract base class for labeling engine rules.
QString name() const
Returns the name for this instance of the rule.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
A labeling engine rule which prevents labels being placed overlapping features from a different layer...
QgsMapLayer * labeledLayer() const
Returns the layer providing the labels.
QgsVectorLayer * targetLayer() const
Returns the layer providing the features which labels must not overlap.
void setRule(const QgsAbstractLabelingEngineRule *rule)
Sets the rule to show in the dialog.
QgsAbstractLabelingEngineRule * rule()
Returns the rule defined by the current settings in the dialog.
QgsLabelingEngineRuleDialog(QgsLabelingEngineRuleWidget *widget, QWidget *parent=nullptr, Qt::WindowFlags flags=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsLabelingEngineRuleDialog.
A labeling engine rule which prevents labels being placed too far from features from a different laye...
A labeling engine rule which prevents labels being placed too close to features from a different laye...
A labeling engine rule which prevents labels being placed too close to labels from a different layer.
double distance() const
Returns the minimum permitted distance between labels from the labeledLayer() and the labels from the...
const QgsMapUnitScale & distanceUnitScale() const
Returns the scaling for the distance between labels from the labeledLayer() and the labels from the t...
QgsMapLayer * labeledLayer() const
Returns the layer providing the labels.
QgsMapLayer * targetLayer() const
Returns the layer providing the labels which labels must be distant from.
Qgis::RenderUnit distanceUnit() const
Returns the units for the distance between labels from the labeledLayer() and the labels from the tar...
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
QList< Qgis::RenderUnit > RenderUnitList
List of render units.