Skip to content

Commit

Permalink
Use QgsExpressionLineEdit for geometry generator expression
Browse files Browse the repository at this point in the history
The full expression builder widget is too large to fit
comfortable in the geometry generator setting widget,
especially when used in layer styling dock mode.
  • Loading branch information
nyalldawson committed Aug 21, 2016
1 parent ae3d6e7 commit c468a04
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
15 changes: 6 additions & 9 deletions src/gui/symbology-ng/qgssymbollayerwidget.cpp
Expand Up @@ -3346,23 +3346,20 @@ QgsGeometryGeneratorSymbolLayerWidget::QgsGeometryGeneratorSymbolLayerWidget( co
, mLayer( nullptr )
{
setupUi( this );
modificationExpressionSelector->setMultiLine( true );
modificationExpressionSelector->setLayer( const_cast<QgsVectorLayer*>( vl ) );
modificationExpressionSelector->loadFieldNames();
modificationExpressionSelector->setExpressionContext( createExpressionContext() );
modificationExpressionSelector->registerExpressionContextGenerator( this );
cbxGeometryType->addItem( QgsApplication::getThemeIcon( "/mIconPolygonLayer.svg" ), tr( "Polygon / MultiPolygon" ), QgsSymbol::Fill );
cbxGeometryType->addItem( QgsApplication::getThemeIcon( "/mIconLineLayer.svg" ), tr( "LineString / MultiLineString" ), QgsSymbol::Line );
cbxGeometryType->addItem( QgsApplication::getThemeIcon( "/mIconPointLayer.svg" ), tr( "Point / MultiPoint" ), QgsSymbol::Marker );
connect( modificationExpressionSelector, SIGNAL( expressionParsed( bool ) ), this, SLOT( updateExpression() ) );
connect( modificationExpressionSelector, SIGNAL( expressionChanged( QString ) ), this, SLOT( updateExpression( QString ) ) );
connect( cbxGeometryType, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updateSymbolType() ) );
}

void QgsGeometryGeneratorSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer* l )
{
mLayer = static_cast<QgsGeometryGeneratorSymbolLayer*>( l );

if ( mPresetExpressionContext )
modificationExpressionSelector->setExpressionContext( *mPresetExpressionContext );
modificationExpressionSelector->setExpressionText( mLayer->geometryExpression() );
modificationExpressionSelector->setExpression( mLayer->geometryExpression() );
cbxGeometryType->setCurrentIndex( cbxGeometryType->findData( mLayer->symbolType() ) );
}

Expand All @@ -3371,9 +3368,9 @@ QgsSymbolLayer* QgsGeometryGeneratorSymbolLayerWidget::symbolLayer()
return mLayer;
}

void QgsGeometryGeneratorSymbolLayerWidget::updateExpression()
void QgsGeometryGeneratorSymbolLayerWidget::updateExpression( const QString& string )
{
mLayer->setGeometryExpression( modificationExpressionSelector->expressionText() );
mLayer->setGeometryExpression( string );

emit changed();
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/symbology-ng/qgssymbollayerwidget.h
Expand Up @@ -29,7 +29,7 @@ class QgsMapCanvas;
/** \ingroup gui
* \class QgsSymbolLayerWidget
*/
class GUI_EXPORT QgsSymbolLayerWidget : public QWidget, private QgsExpressionContextGenerator
class GUI_EXPORT QgsSymbolLayerWidget : public QWidget, protected QgsExpressionContextGenerator
{
Q_OBJECT

Expand Down Expand Up @@ -797,7 +797,7 @@ class GUI_EXPORT QgsGeometryGeneratorSymbolLayerWidget : public QgsSymbolLayerWi
QgsGeometryGeneratorSymbolLayer* mLayer;

private slots:
void updateExpression();
void updateExpression( const QString& string );
void updateSymbolType();
};

Expand Down
12 changes: 3 additions & 9 deletions src/ui/symbollayer/qgsgeometrygeneratorwidgetbase.ui
Expand Up @@ -15,13 +15,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="QgsExpressionBuilderWidget" name="modificationExpressionSelector" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<number>0</number>
</property>
</layout>
</widget>
<widget class="QgsExpressionLineEdit" name="modificationExpressionSelector" native="true"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbxGeometryType"/>
Expand All @@ -43,9 +37,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsExpressionBuilderWidget</class>
<class>QgsExpressionLineEdit</class>
<extends>QWidget</extends>
<header>qgsexpressionbuilderwidget.h</header>
<header>qgsexpressionlineedit.h</header>
<container>1</container>
</customwidget>
</customwidgets>
Expand Down

0 comments on commit c468a04

Please sign in to comment.