17#include "moc_qgslabelingenginerulewidget.cpp"
22#include <QDialogButtonBox>
30 : QDialog( parent, flags )
34 setWindowTitle( tr(
"Configure Rule" ) );
35 setObjectName( QStringLiteral(
"QgsLabelingEngineRuleDialog" ) );
37 QVBoxLayout *layout =
new QVBoxLayout(
this );
38 layout->addWidget( mWidget );
40 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, Qt::Horizontal,
this );
41 layout->addWidget( mButtonBox );
46 connect( mButtonBox->button( QDialogButtonBox::Ok ), &QAbstractButton::clicked,
this, &QDialog::accept );
47 connect( mButtonBox->button( QDialogButtonBox::Cancel ), &QAbstractButton::clicked,
this, &QDialog::reject );
48 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, [=] {
49 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#labeling-rules" ) );
60 return mWidget->
rule();
68QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget::QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget( QWidget *parent )
73 setWindowTitle( tr(
"Prevent Labels Overlapping Features" ) );
74 setPanelTitle( tr(
"Configure Rule" ) );
79 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget::onChanged );
91 mEditName->setText( castRule->
name() );
95 mBlockSignals =
false;
100 std::unique_ptr<QgsLabelingEngineRuleAvoidLabelOverlapWithFeature> res = std::make_unique<QgsLabelingEngineRuleAvoidLabelOverlapWithFeature>();
101 res->setName( mEditName->text() );
102 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
103 res->setTargetLayer( qobject_cast<QgsVectorLayer *>( mComboTargetLayer->currentLayer() ) );
104 return res.release();
107void QgsLabelingEngineRuleAvoidLabelOverlapWithFeatureWidget::onChanged()
109 if ( !mBlockSignals )
117QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget( QWidget *parent )
122 setWindowTitle( tr(
"Push Labels Away from Features" ) );
123 setPanelTitle( tr(
"Configure Rule" ) );
130 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged );
134 connect( mSpinDistance, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged );
136 connect( mCostSlider, &QSlider::valueChanged,
this, &QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged );
145 mBlockSignals =
true;
146 mEditName->setText( castRule->
name() );
150 mSpinDistance->setValue( castRule->
distance() );
151 mDistanceUnitWidget->setUnit( castRule->
distanceUnit() );
154 mCostSlider->setValue(
static_cast<int>( castRule->
cost() * 10 ) );
156 mBlockSignals =
false;
161 std::unique_ptr<QgsLabelingEngineRuleMinimumDistanceLabelToFeature> res = std::make_unique<QgsLabelingEngineRuleMinimumDistanceLabelToFeature>();
162 res->setName( mEditName->text() );
163 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
164 res->setTargetLayer( qobject_cast<QgsVectorLayer *>( mComboTargetLayer->currentLayer() ) );
166 res->setDistance( mSpinDistance->value() );
167 res->setDistanceUnit( mDistanceUnitWidget->unit() );
168 res->setDistanceUnitScale( mDistanceUnitWidget->getMapUnitScale() );
170 res->setCost( mCostSlider->value() / 10.0 );
172 return res.release();
175void QgsLabelingEngineRuleMinimumDistanceLabelToFeatureWidget::onChanged()
177 if ( !mBlockSignals )
185QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget( QWidget *parent )
190 setWindowTitle( tr(
"Pull Labels toward Features" ) );
191 setPanelTitle( tr(
"Configure Rule" ) );
198 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged );
202 connect( mSpinDistance, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged );
204 connect( mCostSlider, &QSlider::valueChanged,
this, &QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged );
213 mBlockSignals =
true;
214 mEditName->setText( castRule->
name() );
218 mSpinDistance->setValue( castRule->
distance() );
219 mDistanceUnitWidget->setUnit( castRule->
distanceUnit() );
222 mCostSlider->setValue(
static_cast<int>( castRule->
cost() * 10 ) );
224 mBlockSignals =
false;
229 std::unique_ptr<QgsLabelingEngineRuleMaximumDistanceLabelToFeature> res = std::make_unique<QgsLabelingEngineRuleMaximumDistanceLabelToFeature>();
230 res->setName( mEditName->text() );
231 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
232 res->setTargetLayer( qobject_cast<QgsVectorLayer *>( mComboTargetLayer->currentLayer() ) );
234 res->setDistance( mSpinDistance->value() );
235 res->setDistanceUnit( mDistanceUnitWidget->unit() );
236 res->setDistanceUnitScale( mDistanceUnitWidget->getMapUnitScale() );
238 res->setCost( mCostSlider->value() / 10.0 );
240 return res.release();
243void QgsLabelingEngineRuleMaximumDistanceLabelToFeatureWidget::onChanged()
245 if ( !mBlockSignals )
254QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget( QWidget *parent )
259 setWindowTitle( tr(
"Pull Labels toward Features" ) );
260 setPanelTitle( tr(
"Configure Rule" ) );
267 connect( mEditName, &QLineEdit::textChanged,
this, &QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::onChanged );
271 connect( mSpinDistance, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::onChanged );
281 mBlockSignals =
true;
282 mEditName->setText( castRule->
name() );
286 mSpinDistance->setValue( castRule->
distance() );
287 mDistanceUnitWidget->setUnit( castRule->
distanceUnit() );
290 mBlockSignals =
false;
295 std::unique_ptr<QgsLabelingEngineRuleMinimumDistanceLabelToLabel> res = std::make_unique<QgsLabelingEngineRuleMinimumDistanceLabelToLabel>();
296 res->setName( mEditName->text() );
297 res->setLabeledLayer( mComboLabeledLayer->currentLayer() );
298 res->setTargetLayer( mComboTargetLayer->currentLayer() );
300 res->setDistance( mSpinDistance->value() );
301 res->setDistanceUnit( mDistanceUnitWidget->unit() );
302 res->setDistanceUnitScale( mDistanceUnitWidget->getMapUnitScale() );
304 return res.release();
307void QgsLabelingEngineRuleMinimumDistanceLabelToLabelWidget::onChanged()
309 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...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
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.