QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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" ), QgsLabelObstacleSettings::PolygonInterior );
28  mObstacleTypeComboBox->addItem( tr( "Over the Feature's Boundary" ), QgsLabelObstacleSettings::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 }
44 
46 {
47  mBlockSignals = true;
48  mObstacleFactorSlider->setValue( static_cast< int >( std::round( settings.factor() * 5 ) ) );
49  mObstacleTypeComboBox->setCurrentIndex( mObstacleTypeComboBox->findData( 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 == QgsWkbTypes::PolygonGeometry || type == QgsWkbTypes::UnknownGeometry );
64  mObstacleTypeLabel->setVisible( type == QgsWkbTypes::PolygonGeometry || type == QgsWkbTypes::UnknownGeometry );
65 }
66 
68 {
70 }
qgsexpressioncontextutils.h
QgsLabelObstacleSettingsWidget::setSettings
void setSettings(const QgsLabelObstacleSettings &settings)
Sets the obstacle settings to show in the widget.
Definition: qgslabelobstaclesettingswidget.cpp:45
qgslabelobstaclesettingswidget.h
QgsLabelObstacleSettings
Contains settings related to how the label engine treats features as obstacles.
Definition: qgslabelobstaclesettings.h:34
QgsLabelObstacleSettingsWidget::updateDataDefinedProperties
void updateDataDefinedProperties(QgsPropertyCollection &properties) override
Updates a data defined properties collection, correctly setting the values for any properties related...
Definition: qgslabelobstaclesettingswidget.cpp:67
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:144
QgsLabelObstacleSettings::setType
void setType(ObstacleType type)
Controls how features act as obstacles for labels.
Definition: qgslabelobstaclesettings.h:119
QgsPropertyCollection::property
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
Definition: qgspropertycollection.cpp:214
QgsPalLayerSettings::ObstacleFactor
@ ObstacleFactor
Definition: qgspallabeling.h:273
QgsLabelObstacleSettings::setFactor
void setFactor(double factor)
Sets the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels,...
Definition: qgslabelobstaclesettings.h:97
QgsLabelObstacleSettings::type
ObstacleType type() const
Returns how features act as obstacles for labels.
Definition: qgslabelobstaclesettings.h:108
QgsPanelWidget::setPanelTitle
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
Definition: qgspanelwidget.h:44
QgsLabelObstacleSettingsWidget::setGeometryType
void setGeometryType(QgsWkbTypes::GeometryType type) override
Sets the geometry type of the features to customize the widget accordingly.
Definition: qgslabelobstaclesettingswidget.cpp:61
QgsLabelSettingsWidgetBase::registerDataDefinedButton
void registerDataDefinedButton(QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key)
Registers a data defined override button.
Definition: qgslabelsettingswidgetbase.cpp:145
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsLabelSettingsWidgetBase
Base class for widgets which allow customization of label engine properties, such as label placement ...
Definition: qgslabelsettingswidgetbase.h:38
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsLabelObstacleSettings::PolygonBoundary
@ PolygonBoundary
Definition: qgslabelobstaclesettings.h:46
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:145
QgsPropertyCollection::setProperty
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
Definition: qgspropertycollection.cpp:187
QgsLabelSettingsWidgetBase::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Contains the data defined properties defined by the widget.
Definition: qgslabelsettingswidgetbase.h:118
QgsLabelObstacleSettings::ObstacleType
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels.
Definition: qgslabelobstaclesettings.h:42
QgsLabelObstacleSettingsWidget::settings
QgsLabelObstacleSettings settings() const
Returns the obstacle settings defined by the widget.
Definition: qgslabelobstaclesettingswidget.cpp:53
QgsLabelObstacleSettingsWidget::QgsLabelObstacleSettingsWidget
QgsLabelObstacleSettingsWidget(QWidget *parent=nullptr, QgsVectorLayer *vl=nullptr)
Constructor for QgsLabelObstacleSettingsWidget.
Definition: qgslabelobstaclesettingswidget.cpp:20
QgsLabelSettingsWidgetBase::changed
void changed()
Emitted when any of the settings described by the widget are changed.
QgsLabelObstacleSettings::factor
double factor() const
Returns the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels,...
Definition: qgslabelobstaclesettings.h:84
QgsLabelObstacleSettings::PolygonInterior
@ PolygonInterior
Definition: qgslabelobstaclesettings.h:44