QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
20
21#include "moc_qgslabelobstaclesettingswidget.cpp"
22
24 : QgsLabelSettingsWidgetBase( parent, vl )
25{
26 setupUi( this );
27
28 setPanelTitle( tr( "Obstacle Settings" ) );
29
30 mObstacleTypeComboBox->addItem( tr( "Over the Feature's Interior" ), static_cast<int>( QgsLabelObstacleSettings::ObstacleType::PolygonInterior ) );
31 mObstacleTypeComboBox->addItem( tr( "Over the Feature's Boundary" ), static_cast<int>( QgsLabelObstacleSettings::ObstacleType::PolygonBoundary ) );
32
33 connect( mObstacleTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) {
34 if ( !mBlockSignals )
35 emit changed();
36 } );
37 connect( mObstacleFactorSlider, &QSlider::valueChanged, this, [this] {
38 if ( !mBlockSignals )
39 emit changed();
40 } );
41
43}
44
46{
47 mBlockSignals = true;
48 mObstacleFactorSlider->setValue( static_cast<int>( std::round( settings.factor() * 5 ) ) );
49 mObstacleTypeComboBox->setCurrentIndex( mObstacleTypeComboBox->findData( static_cast<int>( settings.type() ) ) );
50 mBlockSignals = false;
51}
52
54{
56 settings.setFactor( mObstacleFactorSlider->value() / 5.0 );
57 settings.setType( static_cast<QgsLabelObstacleSettings::ObstacleType>( mObstacleTypeComboBox->currentData().toInt() ) );
58 return settings;
59}
60
62{
63 mObstacleTypeComboBox->setVisible( type == Qgis::GeometryType::Polygon || type == Qgis::GeometryType::Unknown );
64 mObstacleTypeLabel->setVisible( type == Qgis::GeometryType::Polygon || type == Qgis::GeometryType::Unknown );
65}
66
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
@ Polygon
Polygons.
Definition qgis.h:361
@ Unknown
Unknown types.
Definition qgis.h:362
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.
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).
QgsLabelSettingsWidgetBase(QWidget *parent=nullptr, QgsMapLayer *vl=nullptr)
Constructor for QgsLabelSettingsWidgetBase.
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 an integer key value.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
Represents a vector layer which manages a vector based dataset.