Skip to content

Commit

Permalink
[needs-docs] Add else rule UI option in rule based widget (#6529)
Browse files Browse the repository at this point in the history
* [needs-docs] Add else rule UI option in rule based widget

* Review fixes
  • Loading branch information
NathanW2 authored Mar 6, 2018
1 parent 4489508 commit f2e8c37
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 81 deletions.
10 changes: 9 additions & 1 deletion src/app/qgsrulebasedlabelingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ QgsLabelingRulePropsWidget::QgsLabelingRulePropsWidget( QgsRuleBasedLabeling::Ru
{
setupUi( this );

mElseRadio->setChecked( mRule->isElse() );
mFilterRadio->setChecked( !mRule->isElse() );
editFilter->setText( mRule->filterExpression() );
editFilter->setToolTip( mRule->filterExpression() );
editDescription->setText( mRule->description() );
Expand Down Expand Up @@ -626,6 +628,8 @@ QgsLabelingRulePropsWidget::QgsLabelingRulePropsWidget( QgsRuleBasedLabeling::Ru
connect( mScaleRangeWidget, &QgsScaleRangeWidget::rangeChanged, this, &QgsLabelingRulePropsWidget::widgetChanged );
connect( groupSettings, &QGroupBox::toggled, this, &QgsLabelingRulePropsWidget::widgetChanged );
connect( mLabelingGui, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingRulePropsWidget::widgetChanged );
connect( mFilterRadio, &QRadioButton::toggled, this, [ = ]( bool toggled ) { filterFrame->setEnabled( toggled ) ; } );
connect( mElseRadio, &QRadioButton::toggled, this, [ = ]( bool toggled ) { if ( toggled ) editFilter->setText( QStringLiteral( "ELSE" ) );} );
}

QgsLabelingRulePropsWidget::~QgsLabelingRulePropsWidget()
Expand All @@ -641,6 +645,9 @@ void QgsLabelingRulePropsWidget::setDockMode( bool dockMode )

void QgsLabelingRulePropsWidget::testFilter()
{
if ( !mFilterRadio->isChecked() )
return;

QgsExpression filter( editFilter->text() );
if ( filter.hasParserError() )
{
Expand Down Expand Up @@ -691,7 +698,8 @@ void QgsLabelingRulePropsWidget::buildExpression()

void QgsLabelingRulePropsWidget::apply()
{
mRule->setFilterExpression( editFilter->text() );
QString filter = mElseRadio->isChecked() ? QStringLiteral( "ELSE" ) : editFilter->text();
mRule->setFilterExpression( filter );
mRule->setDescription( editDescription->text() );
mRule->setMinimumScale( groupScale->isChecked() ? mScaleRangeWidget->minimumScale() : 0 );
mRule->setMaximumScale( groupScale->isChecked() ? mScaleRangeWidget->maximumScale() : 0 );
Expand Down
10 changes: 9 additions & 1 deletion src/gui/symbology/qgsrulebasedrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ QgsRendererRulePropsWidget::QgsRendererRulePropsWidget( QgsRuleBasedRenderer::Ru
layout()->setMargin( 0 );
layout()->setContentsMargins( 0, 0, 0, 0 );

mElseRadio->setChecked( mRule->isElse() );
mFilterRadio->setChecked( !mRule->isElse() );
editFilter->setText( mRule->filterExpression() );
editFilter->setToolTip( mRule->filterExpression() );
editLabel->setText( mRule->label() );
Expand Down Expand Up @@ -677,6 +679,8 @@ QgsRendererRulePropsWidget::QgsRendererRulePropsWidget( QgsRuleBasedRenderer::Ru
connect( groupSymbol, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
connect( groupScale, &QGroupBox::toggled, this, &QgsPanelWidget::widgetChanged );
connect( mScaleRangeWidget, &QgsScaleRangeWidget::rangeChanged, this, &QgsPanelWidget::widgetChanged );
connect( mFilterRadio, &QRadioButton::toggled, this, [ = ]( bool toggled ) { filterFrame->setEnabled( toggled ) ; } );
connect( mElseRadio, &QRadioButton::toggled, this, [ = ]( bool toggled ) { if ( toggled ) editFilter->setText( QStringLiteral( "ELSE" ) );} );
}

#include "qgsvscrollarea.h"
Expand Down Expand Up @@ -754,6 +758,9 @@ void QgsRendererRulePropsWidget::buildExpression()

void QgsRendererRulePropsWidget::testFilter()
{
if ( !mFilterRadio->isChecked() )
return;

QgsExpression filter( editFilter->text() );
if ( filter.hasParserError() )
{
Expand Down Expand Up @@ -798,7 +805,8 @@ void QgsRendererRulePropsWidget::testFilter()

void QgsRendererRulePropsWidget::apply()
{
mRule->setFilterExpression( editFilter->text() );
QString filter = mElseRadio->isChecked() ? QStringLiteral( "ELSE" ) : editFilter->text();
mRule->setFilterExpression( filter );
mRule->setLabel( editLabel->text() );
mRule->setDescription( editDescription->text() );
// caution: rule uses scale denom, scale widget uses true scales
Expand Down
102 changes: 65 additions & 37 deletions src/ui/qgslabelingrulepropswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>666</width>
<height>573</height>
<width>579</width>
<height>336</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -39,8 +39,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>666</width>
<height>573</height>
<width>579</width>
<height>336</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand Down Expand Up @@ -72,39 +72,67 @@
<widget class="QLineEdit" name="editDescription"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<widget class="QRadioButton" name="mFilterRadio">
<property name="text">
<string>Filter</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="mElseRadio">
<property name="text">
<string>Else</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Catch all for other features</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="editFilter"/>
</item>
<item>
<widget class="QPushButton" name="btnExpressionBuilder">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset>
<normaloff>:/images/themes/default/mIconExpression.svg</normaloff>:/images/themes/default/mIconExpression.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnTestFilter">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
</layout>
<widget class="QFrame" name="filterFrame">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="editFilter"/>
</item>
<item>
<widget class="QPushButton" name="btnExpressionBuilder">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mIconExpression.svg</normaloff>:/images/themes/default/mIconExpression.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnTestFilter">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
Expand All @@ -121,7 +149,7 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QgsScaleRangeWidget" name="mScaleRangeWidget">
<widget class="QgsScaleRangeWidget" name="mScaleRangeWidget" native="true">
<property name="toolTip">
<string/>
</property>
Expand Down Expand Up @@ -156,17 +184,17 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsScaleRangeWidget</class>
<extends>QWidget</extends>
<header>qgsscalerangewidget.h</header>
</customwidget>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsScaleRangeWidget</class>
<extends>QWidget</extends>
<header>qgsscalerangewidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>scrollArea</tabstop>
Expand Down
132 changes: 90 additions & 42 deletions src/ui/qgsrendererrulepropsdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>376</width>
<height>155</height>
<width>443</width>
<height>315</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -19,61 +19,92 @@
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="1">
<widget class="QLineEdit" name="editLabel"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="editDescription"/>
</item>
<item row="3" column="1">
<widget class="QFrame" name="filterFrame">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="editFilter"/>
</item>
<item>
<widget class="QPushButton" name="btnExpressionBuilder">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset>
<normaloff>:/images/themes/default/mIconExpression.svg</normaloff>:/images/themes/default/mIconExpression.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnTestFilter">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QRadioButton" name="mElseRadio">
<property name="text">
<string>Else</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_1">
<property name="text">
<string>Label</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="editLabel"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<item row="3" column="0">
<widget class="QRadioButton" name="mFilterRadio">
<property name="text">
<string>Filter</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="editFilter"/>
</item>
<item>
<widget class="QPushButton" name="btnExpressionBuilder">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset>
<normaloff>:/images/themes/default/mIconExpression.svg</normaloff>:/images/themes/default/mIconExpression.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnTestFilter">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<item row="4" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Description</string>
<string>Catch all for other features</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="editDescription"/>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -136,5 +167,22 @@
<tabstop>groupSymbol</tabstop>
</tabstops>
<resources/>
<connections/>
<connections>
<connection>
<sender>mFilterRadio</sender>
<signal>toggled(bool)</signal>
<receiver>filterFrame</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>61</x>
<y>75</y>
</hint>
<hint type="destinationlabel">
<x>304</x>
<y>85</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit f2e8c37

Please sign in to comment.