Skip to content
Permalink
Browse files

Add expression builder to labeling geometry generator

  • Loading branch information
m-kuhn committed Mar 10, 2019
1 parent b8305c0 commit c4528214abbc8d1445123910a005212889187fd4
@@ -24,6 +24,7 @@
#include "qgsauxiliarystorage.h"
#include "qgsnewauxiliarylayerdialog.h"
#include "qgsexpressioncontextutils.h"
#include "qgsexpressionbuilderdialog.h"

#include <QButtonGroup>

@@ -57,12 +58,6 @@ void QgsLabelingGui::registerDataDefinedButton( QgsPropertyOverrideButton *butto
mButtons[key] = button;
}

void QgsLabelingGui::setupWidget()
{
connect( mGeometryGeneratorGroupBox, &QGroupBox::toggled, this, &QgsLabelingGui::updateGeometryTypeBasedWidgets );
connect( mGeometryGeneratorType, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsLabelingGui::updateGeometryTypeBasedWidgets );
}

void QgsLabelingGui::updateProperty()
{
QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
@@ -84,6 +79,9 @@ QgsLabelingGui::QgsLabelingGui( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas,
connect( mFormatNumChkBx, &QAbstractButton::toggled, this, &QgsLabelingGui::updateUi );
connect( mScaleBasedVisibilityChkBx, &QAbstractButton::toggled, this, &QgsLabelingGui::updateUi );
connect( mFontLimitPixelChkBox, &QAbstractButton::toggled, this, &QgsLabelingGui::updateUi );
connect( mGeometryGeneratorGroupBox, &QGroupBox::toggled, this, &QgsLabelingGui::updateGeometryTypeBasedWidgets );
connect( mGeometryGeneratorType, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsLabelingGui::updateGeometryTypeBasedWidgets );
connect( mGeometryGeneratorExpressionButton, &QToolButton::clicked, this, &QgsLabelingGui::showGeometryGeneratorExpressionBuilder );

mFieldExpressionWidget->registerExpressionContextGenerator( this );

@@ -692,3 +690,17 @@ void QgsLabelingGui::updateGeometryTypeBasedWidgets()
mFontMultiLineAlignComboBox->removeItem( idx );
}
}

void QgsLabelingGui::showGeometryGeneratorExpressionBuilder()
{
QgsExpressionBuilderDialog expressionBuilder( mLayer );

expressionBuilder.setExpressionText( mGeometryGenerator->text() );
expressionBuilder.setExpressionContext( createExpressionContext() );

if ( expressionBuilder.exec() )
{
mGeometryGenerator->setText( expressionBuilder.expressionText() );
}

}
@@ -67,6 +67,10 @@ class APP_EXPORT QgsLabelingGui : public QgsTextFormatWidget, private QgsExpress
void blockInitSignals( bool block );
void syncDefinedCheckboxFrame( QgsPropertyOverrideButton *ddBtn, QCheckBox *chkBx, QFrame *f );

private slots:
void updateGeometryTypeBasedWidgets();
void showGeometryGeneratorExpressionBuilder();

private:
QgsVectorLayer *mLayer = nullptr;
const QgsPalLayerSettings &mSettings;
@@ -878,7 +878,7 @@ void QgsPalLayerSettings::readXml( QDomElement &elem, const QgsReadWriteContext
}

geometryGenerator = placementElem.attribute( QStringLiteral( "geometryGenerator" ) );
geometryGeneratorEnabled = placementElem.attribute( QStringLiteral( "labeling/geometryGeneratorEnabled" ) ).toInt();
geometryGeneratorEnabled = placementElem.attribute( QStringLiteral( "geometryGeneratorEnabled" ) ).toInt();

const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWkbTypes::GeometryType>() );
geometryGeneratorType = static_cast<QgsWkbTypes::GeometryType>( metaEnum.keyToValue( placementElem.attribute( QStringLiteral( "geometryGeneratorType" ) ).toUtf8().constData() ) );
@@ -1023,7 +1023,6 @@ QDomElement QgsPalLayerSettings::writeXml( QDomDocument &doc, const QgsReadWrite
const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWkbTypes::GeometryType>() );
placementElem.setAttribute( QStringLiteral( "geometryGeneratorType" ), metaEnum.valueToKey( geometryGeneratorType ) );


// rendering
QDomElement renderingElem = doc.createElement( QStringLiteral( "rendering" ) );
renderingElem.setAttribute( QStringLiteral( "drawLabels" ), drawLabels );
@@ -515,7 +515,10 @@ void QgsTextFormatWidget::initWidget()
<< radPolygonPerimeterCurved
<< radPredefinedOrder
<< mFieldExpressionWidget
<< mCheckBoxSubstituteText;
<< mCheckBoxSubstituteText
<< mGeometryGeneratorGroupBox
<< mGeometryGenerator
<< mGeometryGeneratorType;
connectValueChanged( widgets, SLOT( updatePreview() ) );

connect( mQuadrantBtnGrp, static_cast<void ( QButtonGroup::* )( int )>( &QButtonGroup::buttonClicked ), this, &QgsTextFormatWidget::updatePreview );
@@ -532,12 +535,6 @@ void QgsTextFormatWidget::initWidget()
lblFontPreview->setMapUnits( mMapCanvas->mapSettings().mapUnits() );
mPreviewScaleComboBox->setScale( mMapCanvas->mapSettings().scale() );
}

setupWidget();
}

void QgsTextFormatWidget::setupWidget()
{
}

void QgsTextFormatWidget::setWidgetMode( QgsTextFormatWidget::Mode mode )
@@ -649,6 +646,10 @@ void QgsTextFormatWidget::connectValueChanged( const QList<QWidget *> &widgets,
{
connect( w, SIGNAL( valueChanged( int ) ), this, slot );
}
else if ( QGroupBox *w = qobject_cast<QGroupBox *>( widget ) )
{
connect( w, SIGNAL( toggled( bool ) ), this, slot );
}
else
{
QgsLogger::warning( QStringLiteral( "Could not create connection for widget %1" ).arg( widget->objectName() ) );
@@ -163,10 +163,6 @@ class GUI_EXPORT QgsTextFormatWidget : public QWidget, protected Ui::QgsTextForm
bool mLoadSvgParams = false;

void initWidget();
/**
* Used to setup child classes. Called at the end of initWidget.
*/
virtual void setupWidget();
void setWidgetMode( Mode mode );
void toggleDDButtons( bool visible );
void blockFontChangeSignals( bool blk );
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>508</width>
<height>883</height>
<width>828</width>
<height>1081</height>
</rect>
</property>
<property name="windowTitle">
@@ -112,7 +112,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>474</width>
<width>794</width>
<height>300</height>
</rect>
</property>
@@ -3664,8 +3664,8 @@ font-style: italic;</string>
<property name="geometry">
<rect>
<x>0</x>
<y>-428</y>
<width>500</width>
<y>-370</y>
<width>772</width>
<height>1187</height>
</rect>
</property>
@@ -4881,48 +4881,45 @@ font-style: italic;</string>
<property name="verticalSpacing">
<number>12</number>
</property>
<item row="1" column="0">
<spacer name="horizontalSpacer_19">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="1" column="2">
<widget class="QgsDoubleSpinBox" name="mMaxCharAngleInDSpinBox">
<property name="decimals">
<number>1</number>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
<property name="minimum">
<double>20.000000000000000</double>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>20</height>
</size>
<property name="maximum">
<double>60.000000000000000</double>
</property>
</spacer>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="mMaxCharAngleInLabel">
<item row="1" column="3">
<widget class="QLabel" name="mMaxCharAngleOutLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>inside</string>
<string>outside</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QgsDoubleSpinBox" name="mMaxCharAngleInDSpinBox">
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>20.000000000000000</double>
</property>
<property name="maximum">
<double>60.000000000000000</double>
<item row="1" column="1">
<widget class="QLabel" name="mMaxCharAngleInLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
<property name="text">
<string>inside</string>
</property>
</widget>
</item>
@@ -4933,16 +4930,32 @@ font-style: italic;</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="mMaxCharAngleOutLabel">
<item row="1" column="0">
<spacer name="horizontalSpacer_19">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="6">
<widget class="QLabel" name="mMaxCharAngleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>outside</string>
<string>Maximum angle between curved characters</string>
</property>
</widget>
</item>
@@ -4962,22 +4975,22 @@ font-style: italic;</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="6">
<widget class="QLabel" name="mMaxCharAngleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Maximum angle between curved characters</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="mGeometryGeneratorGroupBox">
<property name="title">
@@ -4986,43 +4999,43 @@ font-style: italic;</string>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<layout class="QGridLayout" name="gridLayout_41">
<item row="1" column="1">
<widget class="QLineEdit" name="mGeometryGenerator"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<widget class="QToolButton" name="mGeometryGeneratorExpressionButton">
<property name="text">
<string>Expression</string>
<string>...</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="mGeometryGeneratorType"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Geometry Type</string>
<item row="3" column="0" colspan="2">
<widget class="QComboBox" name="mGeometryGeneratorType">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_9">
<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="1" column="0" rowspan="2">
<widget class="QgsCodeEditorExpression" name="mGeometryGenerator" native="true"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mPlacementDDGroupBox">
<property name="title">
@@ -6346,6 +6359,12 @@ font-style: italic;</string>
<header>effects/qgseffectstackpropertieswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCodeEditorExpression</class>
<extends>QWidget</extends>
<header>qgscodeeditorexpression.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mFieldExpressionWidget</tabstop>

0 comments on commit c452821

Please sign in to comment.
You can’t perform that action at this time.