Skip to content

Commit

Permalink
Add QgsLabelObstacleSettingsWidget widget for customising label obsta…
Browse files Browse the repository at this point in the history
…cle settings
  • Loading branch information
nyalldawson committed Dec 4, 2019
1 parent de2b60d commit ed93ebd
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 53 deletions.
57 changes: 57 additions & 0 deletions python/gui/auto_generated/qgslabelobstaclesettingswidget.sip.in
@@ -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 *
************************************************************************/
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -96,6 +96,7 @@
%Include auto_generated/qgshistogramwidget.sip
%Include auto_generated/qgsidentifymenu.sip
%Include auto_generated/qgskeyvaluewidget.sip
%Include auto_generated/qgslabelobstaclesettingswidget.sip
%Include auto_generated/qgslabelsettingswidgetbase.sip
%Include auto_generated/qgslegendfilterbutton.sip
%Include auto_generated/qgslimitedrandomcolorrampdialog.sip
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -315,6 +315,7 @@ SET(QGIS_GUI_SRCS
qgsidentifymenu.cpp
qgskeyvaluewidget.cpp
qgslabelinggui.cpp
qgslabelobstaclesettingswidget.cpp
qgslabelsettingswidgetbase.cpp
qgslistwidget.cpp
qgslegendfilterbutton.cpp
Expand Down Expand Up @@ -517,6 +518,7 @@ SET(QGIS_GUI_HDRS
qgsidentifymenu.h
qgskeyvaluewidget.h
qgslabelinggui.h
qgslabelobstaclesettingswidget.h
qgslabelsettingswidgetbase.h
qgslegendfilterbutton.h
qgslimitedrandomcolorrampdialog.h
Expand Down
60 changes: 60 additions & 0 deletions src/gui/qgslabelobstaclesettingswidget.cpp
@@ -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 );
}
66 changes: 66 additions & 0 deletions src/gui/qgslabelobstaclesettingswidget.h
@@ -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
91 changes: 38 additions & 53 deletions src/ui/qgslabelobstaclesettingswidgetbase.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsLabelObstacleSettingsWidgetBase</class>
<widget class="QWidget" name="QgsLabelObstacleSettingsWidgetBase">
<widget class="QgsPanelWidget" name="QgsLabelObstacleSettingsWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
Expand All @@ -14,7 +14,37 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<item row="1" column="0">
<widget class="QLabel" name="mObstacleTypeLabel">
<property name="text">
<string>Minimize placing labels</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mObstacleTypeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_40">
Expand Down Expand Up @@ -64,57 +94,6 @@
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Minimize placing labels</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="mObstacleTypeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QCheckBox" name="mChkNoObstacle">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Discourage labels from covering features</string>
</property>
</widget>
</item>
<item>
<widget class="QgsPropertyOverrideButton" name="mIsObstacleDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
Expand All @@ -123,6 +102,12 @@
<extends>QToolButton</extends>
<header>qgspropertyoverridebutton.h</header>
</customwidget>
<customwidget>
<class>QgsPanelWidget</class>
<extends>QWidget</extends>
<header>qgspanelwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down

0 comments on commit ed93ebd

Please sign in to comment.