QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
19
21 : QgsLabelSettingsWidgetBase( parent, vl )
22{
23 setupUi( this );
24
25 setPanelTitle( tr( "Obstacle Settings" ) );
26
27 mObstacleTypeComboBox->addItem( tr( "Over the Feature's Interior" ), static_cast<int>( QgsLabelObstacleSettings::ObstacleType::PolygonInterior ) );
28 mObstacleTypeComboBox->addItem( tr( "Over the Feature's Boundary" ), static_cast< int >( QgsLabelObstacleSettings::ObstacleType::PolygonBoundary ) );
29
30 connect( mObstacleTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, [ = ]( int )
31 {
32 if ( !mBlockSignals )
33 emit changed();
34 } );
35 connect( mObstacleFactorSlider, &QSlider::valueChanged, this, [ = ]
36 {
37 if ( !mBlockSignals )
38 emit changed();
39 } );
40
42}
43
45{
46 mBlockSignals = true;
47 mObstacleFactorSlider->setValue( static_cast< int >( std::round( settings.factor() * 5 ) ) );
48 mObstacleTypeComboBox->setCurrentIndex( mObstacleTypeComboBox->findData( static_cast< int >( settings.type() ) ) );
49 mBlockSignals = false;
50}
51
53{
55 settings.setFactor( mObstacleFactorSlider->value() / 5.0 );
56 settings.setType( static_cast< QgsLabelObstacleSettings::ObstacleType >( mObstacleTypeComboBox->currentData().toInt() ) );
57 return settings;
58}
59
61{
62 mObstacleTypeComboBox->setVisible( type == Qgis::GeometryType::Polygon || type == Qgis::GeometryType::Unknown );
63 mObstacleTypeLabel->setVisible( type == Qgis::GeometryType::Polygon || type == Qgis::GeometryType::Unknown );
64}
65
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.