17#include "moc_qgslabelingenginerulewidget.cpp"
21#include <QDialogButtonBox>
29 : QDialog( parent, flags )
33 setWindowTitle( tr(
"Configure Rule" ) );
34 setObjectName( QStringLiteral(
"QgsLabelingEngineRuleDialog" ) );
36 QVBoxLayout *layout =
new QVBoxLayout(
this );
37 layout->addWidget( mWidget );
39 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal,
this );
40 layout->addWidget( mButtonBox );
45 connect( mButtonBox->button( QDialogButtonBox::Ok ), &QAbstractButton::clicked,
this, &QDialog::accept );
46 connect( mButtonBox->button( QDialogButtonBox::Cancel ), &QAbstractButton::clicked,
this, &QDialog::reject );
56 return mWidget->
rule();
64QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget::QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget( QWidget *parent )
69 setWindowTitle( tr(
"Prevent Labels Overlapping Features" ) );
70 setPanelTitle( tr(
"Configure Rule" ) );
75 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget::onChanged );
87 mEditName->setText( castRule->
name() );
91 mBlockSignals =
false;
96 std::unique_ptr< QgsLabelingEngineRuleAvoidLabelOverlapWithFeature > res = std::make_unique< QgsLabelingEngineRuleAvoidLabelOverlapWithFeature >();
97 res->setName( mEditName->text() );
98 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
99 res->setTargetLayer( qobject_cast< QgsVectorLayer * >( mComboTargetLayer->currentLayer() ) );
100 return res.release();
103void QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget::onChanged()
105 if ( !mBlockSignals )
113QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget( QWidget *parent )
118 setWindowTitle( tr(
"Push Labels Away from Features" ) );
119 setPanelTitle( tr(
"Configure Rule" ) );
127 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged );
131 connect( mSpinDistance, qOverload< double >( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged );
133 connect( mCostSlider, &QSlider::valueChanged,
this, &QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged );
142 mBlockSignals =
true;
143 mEditName->setText( castRule->
name() );
147 mSpinDistance->setValue( castRule->
distance() );
148 mDistanceUnitWidget->setUnit( castRule->
distanceUnit() );
151 mCostSlider->setValue(
static_cast< int >( castRule->
cost() * 10 ) );
153 mBlockSignals =
false;
158 std::unique_ptr< QgsLabelingEngineRuleMinimumDistanceLabelToFeature > res = std::make_unique< QgsLabelingEngineRuleMinimumDistanceLabelToFeature >();
159 res->setName( mEditName->text() );
160 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
161 res->setTargetLayer( qobject_cast< QgsVectorLayer * >( mComboTargetLayer->currentLayer() ) );
163 res->setDistance( mSpinDistance->value() );
164 res->setDistanceUnit( mDistanceUnitWidget->unit() );
165 res->setDistanceUnitScale( mDistanceUnitWidget->getMapUnitScale() );
167 res->setCost( mCostSlider->value() / 10.0 );
169 return res.release();
172void QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged()
174 if ( !mBlockSignals )
182QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget( QWidget *parent )
187 setWindowTitle( tr(
"Pull Labels toward Features" ) );
188 setPanelTitle( tr(
"Configure Rule" ) );
196 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged );
200 connect( mSpinDistance, qOverload< double >( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged );
202 connect( mCostSlider, &QSlider::valueChanged,
this, &QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged );
211 mBlockSignals =
true;
212 mEditName->setText( castRule->
name() );
216 mSpinDistance->setValue( castRule->
distance() );
217 mDistanceUnitWidget->setUnit( castRule->
distanceUnit() );
220 mCostSlider->setValue(
static_cast< int >( castRule->
cost() * 10 ) );
222 mBlockSignals =
false;
227 std::unique_ptr< QgsLabelingEngineRuleMaximumDistanceLabelToFeature > res = std::make_unique< QgsLabelingEngineRuleMaximumDistanceLabelToFeature >();
228 res->setName( mEditName->text() );
229 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
230 res->setTargetLayer( qobject_cast< QgsVectorLayer * >( mComboTargetLayer->currentLayer() ) );
232 res->setDistance( mSpinDistance->value() );
233 res->setDistanceUnit( mDistanceUnitWidget->unit() );
234 res->setDistanceUnitScale( mDistanceUnitWidget->getMapUnitScale() );
236 res->setCost( mCostSlider->value() / 10.0 );
238 return res.release();
241void QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged()
243 if ( !mBlockSignals )
252QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget( QWidget *parent )
257 setWindowTitle( tr(
"Pull Labels toward Features" ) );
258 setPanelTitle( tr(
"Configure Rule" ) );
266 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::onChanged );
270 connect( mSpinDistance, qOverload< double >( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::onChanged );
280 mBlockSignals =
true;
281 mEditName->setText( castRule->
name() );
285 mSpinDistance->setValue( castRule->
distance() );
286 mDistanceUnitWidget->setUnit( castRule->
distanceUnit() );
289 mBlockSignals =
false;
294 std::unique_ptr< QgsLabelingEngineRuleMinimumDistanceLabelToLabel > res = std::make_unique< QgsLabelingEngineRuleMinimumDistanceLabelToLabel >();
295 res->setName( mEditName->text() );
296 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
297 res->setTargetLayer( mComboTargetLayer->currentLayer() );
299 res->setDistance( mSpinDistance->value() );
300 res->setDistanceUnit( mDistanceUnitWidget->unit() );
301 res->setDistanceUnitScale( mDistanceUnitWidget->getMapUnitScale() );
303 return res.release();
306void QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::onChanged()
308 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.