Skip to content
Permalink
Browse files

Show fields in "default value" expression editor

  • Loading branch information
m-kuhn committed Oct 5, 2016
1 parent 0348dd5 commit b642c3ff5ede2cae88d30f881f7ae7c99e1bfccc
Showing with 27 additions and 10 deletions.
  1. +2 −0 src/app/qgsattributetypedialog.cpp
  2. +3 −0 src/gui/qgsexpressionlineedit.cpp
  3. +22 −10 src/gui/qgsexpressionlineedit.h
@@ -69,6 +69,8 @@ QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl, int fieldIdx
isFieldEditableCheckBox->setEnabled( false );
}

mExpressionWidget->setLayer( vl );

connect( mExpressionWidget, SIGNAL( expressionChanged( QString ) ), this, SLOT( defaultExpressionChanged() ) );

QSettings settings;
@@ -20,6 +20,7 @@
#include "qgsexpressionbuilderdialog.h"
#include "qgsexpressioncontextgenerator.h"
#include "qgscodeeditorsql.h"
#include "qgsvectorlayer.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QToolButton>
@@ -113,6 +114,8 @@ void QgsExpressionLineEdit::setGeomCalculator( const QgsDistanceArea &da )

void QgsExpressionLineEdit::setLayer( QgsVectorLayer* layer )
{
if ( !mExpressionContextGenerator || mExpressionContextGenerator == mLayer )
mExpressionContextGenerator = layer;
mLayer = layer;
}

@@ -54,35 +54,44 @@ class GUI_EXPORT QgsExpressionLineEdit : public QWidget
*/
explicit QgsExpressionLineEdit( QWidget *parent = nullptr );

/** Sets the title used in the expression builder dialog
/**
* Sets the title used in the expression builder dialog
* @param title dialog title
* @see expressionDialogTitle()
*/
void setExpressionDialogTitle( const QString& title );

/** Returns the title used for the expression dialog.
/**
* Returns the title used for the expression dialog.
* @see setExpressionDialogTitle()
*/
QString expressionDialogTitle() const { return mExpressionDialogTitle; }

/** Sets whether the widget should show a multiline text editor.
/**
* Sets whether the widget should show a multiline text editor.
* @param multiLine set to true to show multiline editor, or false
* to show single line editor (the default).
*/
void setMultiLine( bool multiLine );

/** Set the geometry calculator used in the expression dialog.
/**
* Set the geometry calculator used in the expression dialog.
* @param distanceArea calculator
*/
void setGeomCalculator( const QgsDistanceArea &distanceArea );

/** Sets a layer associated with the widget. Required in order to get the fields and values
* from the layer.
* @param layer vector layer
*/
/**
* Sets a layer associated with the widget. Required in order to get the fields and values
* from the layer.
* This will also automatically register the layer as expression context generator if
* no generator has been set before or the previous layer has been used as generator.
*
* @see registerExpressionContextGenerator
*/
void setLayer( QgsVectorLayer* layer );

/** Returns the current expression shown in the widget.
/**
* Returns the current expression shown in the widget.
* @see setExpression()
*/
QString expression() const;
@@ -110,16 +119,19 @@ class GUI_EXPORT QgsExpressionLineEdit : public QWidget

public slots:

/** Sets the current expression to show in the widget.
/**
* Sets the current expression to show in the widget.
* @param expression expression string
* @see expression()
*/
void setExpression( const QString& expression );

protected:

void changeEvent( QEvent* event ) override;

private slots:

//! When the expression is edited by the user in the line edit, it will be checked for validity
void expressionEdited( const QString& expression );
void expressionEdited();

2 comments on commit b642c3f

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Oct 5, 2016

@m-kuhn this was deliberate - the calculation of default value does not have access to other field's values from the feature.

@m-kuhn

This comment has been minimized.

Copy link
Member Author

@m-kuhn m-kuhn replied Oct 5, 2016

Oops, good point. I wondered that you would have missed something like that...

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