Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QgsLabelObstacleSettingsWidget widget for customising label obsta…
…cle settings
- Loading branch information
1 parent
de2b60d
commit ed93ebd
Showing
6 changed files
with
224 additions
and
53 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
python/gui/auto_generated/qgslabelobstaclesettingswidget.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgslabelobstaclesettingswidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
class QgsLabelObstacleSettingsWidget : QgsLabelSettingsWidgetBase | ||
{ | ||
%Docstring | ||
A widget for customising label obstacle settings. | ||
|
||
.. versionadded:: 3.12 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslabelobstaclesettingswidget.h" | ||
%End | ||
public: | ||
|
||
QgsLabelObstacleSettingsWidget( QWidget *parent /TransferThis/ = 0, QgsVectorLayer *vl = 0 ); | ||
%Docstring | ||
Constructor for QgsLabelObstacleSettingsWidget. | ||
|
||
:param parent: parent widget | ||
:param vl: associated vector layer | ||
%End | ||
|
||
void setObstacleSettings( const QgsLabelObstacleSettings &settings ); | ||
%Docstring | ||
Sets the obstacle ``settings`` to show in the widget. | ||
|
||
.. seealso:: :py:func:`settings` | ||
%End | ||
|
||
QgsLabelObstacleSettings settings() const; | ||
%Docstring | ||
Returns the obstacle settings defined by the widget. | ||
|
||
.. seealso:: :py:func:`setSettings` | ||
%End | ||
|
||
virtual void setGeometryType( QgsWkbTypes::GeometryType type ); | ||
|
||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgslabelobstaclesettingswidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*************************************************************************** | ||
qgslabelobstaclesettingswidget.h | ||
---------------------- | ||
begin : December 2019 | ||
copyright : (C) 2019 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
|
||
#include "qgslabelobstaclesettingswidget.h" | ||
#include "qgsexpressioncontextutils.h" | ||
|
||
QgsLabelObstacleSettingsWidget::QgsLabelObstacleSettingsWidget( QWidget *parent, QgsVectorLayer *vl ) | ||
: QgsLabelSettingsWidgetBase( parent, vl ) | ||
{ | ||
setupUi( this ); | ||
|
||
mObstacleTypeComboBox->addItem( tr( "Over the Feature's Interior" ), QgsLabelObstacleSettings::PolygonInterior ); | ||
mObstacleTypeComboBox->addItem( tr( "Over the Feature's Boundary" ), QgsLabelObstacleSettings::PolygonBoundary ); | ||
|
||
connect( mObstacleTypeComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, [ = ]( int ) | ||
{ | ||
if ( !mBlockSignals ) | ||
emit changed(); | ||
} ); | ||
connect( mObstacleFactorSlider, &QSlider::valueChanged, this, [ = ] | ||
{ | ||
if ( !mBlockSignals ) | ||
emit changed(); | ||
} ); | ||
} | ||
|
||
void QgsLabelObstacleSettingsWidget::setObstacleSettings( const QgsLabelObstacleSettings &settings ) | ||
{ | ||
mBlockSignals = true; | ||
mObstacleFactorSlider->setValue( static_cast< int >( std::round( settings.factor() * 5 ) ) ); | ||
mObstacleTypeComboBox->setCurrentIndex( mObstacleTypeComboBox->findData( settings.type() ) ); | ||
mBlockSignals = false; | ||
} | ||
|
||
QgsLabelObstacleSettings QgsLabelObstacleSettingsWidget::settings() const | ||
{ | ||
QgsLabelObstacleSettings settings; | ||
settings.setFactor( mObstacleFactorSlider->value() / 5.0 ); | ||
settings.setType( static_cast< QgsLabelObstacleSettings::ObstacleType >( mObstacleTypeComboBox->currentData().toInt() ) ); | ||
return settings; | ||
} | ||
|
||
void QgsLabelObstacleSettingsWidget::setGeometryType( QgsWkbTypes::GeometryType type ) | ||
{ | ||
mObstacleTypeComboBox->setVisible( type == QgsWkbTypes::PolygonGeometry ); | ||
mObstacleTypeComboBox->setVisible( type == QgsWkbTypes::PolygonGeometry ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*************************************************************************** | ||
qgslabelobstaclesettingswidget.h | ||
---------------------- | ||
begin : December 2019 | ||
copyright : (C) 2019 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSLABELOBSTACLESETTINGSWIDGET_H | ||
#define QGSLABELOBSTACLESETTINGSWIDGET_H | ||
|
||
#include "ui_qgslabelobstaclesettingswidgetbase.h" | ||
#include "qgslabelsettingswidgetbase.h" | ||
#include "qgspallabeling.h" | ||
#include "qgis_gui.h" | ||
#include "qgis_sip.h" | ||
|
||
/** | ||
* \ingroup gui | ||
* \class QgsLabelObstacleSettingsWidget | ||
* A widget for customising label obstacle settings. | ||
* \since QGIS 3.12 | ||
*/ | ||
class GUI_EXPORT QgsLabelObstacleSettingsWidget : public QgsLabelSettingsWidgetBase, private Ui::QgsLabelObstacleSettingsWidgetBase | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsLabelObstacleSettingsWidget. | ||
* \param parent parent widget | ||
* \param vl associated vector layer | ||
*/ | ||
QgsLabelObstacleSettingsWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsVectorLayer *vl = nullptr ); | ||
|
||
/** | ||
* Sets the obstacle \a settings to show in the widget. | ||
* | ||
* \see settings() | ||
*/ | ||
void setObstacleSettings( const QgsLabelObstacleSettings &settings ); | ||
|
||
/** | ||
* Returns the obstacle settings defined by the widget. | ||
* | ||
* \see setSettings() | ||
*/ | ||
QgsLabelObstacleSettings settings() const; | ||
|
||
void setGeometryType( QgsWkbTypes::GeometryType type ) override; | ||
|
||
private: | ||
|
||
bool mBlockSignals = false; | ||
|
||
}; | ||
|
||
#endif // QGSLABELOBSTACLESETTINGSWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters