QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgslabelobstaclesettingswidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslabelobstaclesettingswidget.h
3 ----------------------
4 begin : December 2019
5 copyright : (C) 2019 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16
18#include "moc_qgslabelobstaclesettingswidget.cpp"
20
22 : QgsLabelSettingsWidgetBase( parent, vl )
23{
24 setupUi( this );
25
26 setPanelTitle( tr( "Obstacle Settings" ) );
27
28 mObstacleTypeComboBox->addItem( tr( "Over the Feature's Interior" ), static_cast<int>( QgsLabelObstacleSettings::ObstacleType::PolygonInterior ) );
29 mObstacleTypeComboBox->addItem( tr( "Over the Feature's Boundary" ), static_cast<int>( QgsLabelObstacleSettings::ObstacleType::PolygonBoundary ) );
30
31 connect( mObstacleTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, [=]( int ) {
32 if ( !mBlockSignals )
33 emit changed();
34 } );
35 connect( mObstacleFactorSlider, &QSlider::valueChanged, this, [=] {
36 if ( !mBlockSignals )
37 emit changed();
38 } );
39
41}
42
44{
45 mBlockSignals = true;
46 mObstacleFactorSlider->setValue( static_cast<int>( std::round( settings.factor() * 5 ) ) );
47 mObstacleTypeComboBox->setCurrentIndex( mObstacleTypeComboBox->findData( static_cast<int>( settings.type() ) ) );
48 mBlockSignals = false;
49}
50
52{
54 settings.setFactor( mObstacleFactorSlider->value() / 5.0 );
55 settings.setType( static_cast<QgsLabelObstacleSettings::ObstacleType>( mObstacleTypeComboBox->currentData().toInt() ) );
56 return settings;
57}
58
60{
61 mObstacleTypeComboBox->setVisible( type == Qgis::GeometryType::Polygon || type == Qgis::GeometryType::Unknown );
62 mObstacleTypeLabel->setVisible( type == Qgis::GeometryType::Polygon || type == Qgis::GeometryType::Unknown );
63}
64
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Polygon
Polygons.
@ Unknown
Unknown types.
void setGeometryType(Qgis::GeometryType type) override
Sets the geometry type of the features to customize the widget accordingly.
QgsLabelObstacleSettings settings() const
Returns the obstacle settings defined by the widget.
void updateDataDefinedProperties(QgsPropertyCollection &properties) override
Updates a data defined properties collection, correctly setting the values for any properties related...
void setSettings(const QgsLabelObstacleSettings &settings)
Sets the obstacle settings to show in the widget.
QgsLabelObstacleSettingsWidget(QWidget *parent=nullptr, QgsVectorLayer *vl=nullptr)
Constructor for QgsLabelObstacleSettingsWidget.
Contains settings related to how the label engine treats features as obstacles.
double factor() const
Returns the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels,...
void setType(ObstacleType type)
Controls how features act as obstacles for labels.
ObstacleType type() const
Returns how features act as obstacles for labels.
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels.
@ PolygonInterior
Avoid placing labels over interior of polygon (prefer placing labels totally outside or just slightly...
@ PolygonBoundary
Avoid placing labels over boundary of polygon (prefer placing outside or completely inside polygon)
void setFactor(double factor)
Sets the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels,...
Base class for widgets which allow customization of label engine properties, such as label placement ...
void changed()
Emitted when any of the settings described by the widget are changed.
void registerDataDefinedButton(QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key)
Registers a data defined override button.
QgsPropertyCollection mDataDefinedProperties
Contains the data defined properties defined by the widget.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
Represents a vector layer which manages a vector based data sets.