Skip to content

Commit b642c3f

Browse files
committedOct 5, 2016
Show fields in "default value" expression editor
1 parent 0348dd5 commit b642c3f

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed
 

‎src/app/qgsattributetypedialog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl, int fieldIdx
6969
isFieldEditableCheckBox->setEnabled( false );
7070
}
7171

72+
mExpressionWidget->setLayer( vl );
73+
7274
connect( mExpressionWidget, SIGNAL( expressionChanged( QString ) ), this, SLOT( defaultExpressionChanged() ) );
7375

7476
QSettings settings;

‎src/gui/qgsexpressionlineedit.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgsexpressionbuilderdialog.h"
2121
#include "qgsexpressioncontextgenerator.h"
2222
#include "qgscodeeditorsql.h"
23+
#include "qgsvectorlayer.h"
2324
#include <QHBoxLayout>
2425
#include <QVBoxLayout>
2526
#include <QToolButton>
@@ -113,6 +114,8 @@ void QgsExpressionLineEdit::setGeomCalculator( const QgsDistanceArea &da )
113114

114115
void QgsExpressionLineEdit::setLayer( QgsVectorLayer* layer )
115116
{
117+
if ( !mExpressionContextGenerator || mExpressionContextGenerator == mLayer )
118+
mExpressionContextGenerator = layer;
116119
mLayer = layer;
117120
}
118121

‎src/gui/qgsexpressionlineedit.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,44 @@ class GUI_EXPORT QgsExpressionLineEdit : public QWidget
5454
*/
5555
explicit QgsExpressionLineEdit( QWidget *parent = nullptr );
5656

57-
/** Sets the title used in the expression builder dialog
57+
/**
58+
* Sets the title used in the expression builder dialog
5859
* @param title dialog title
5960
* @see expressionDialogTitle()
6061
*/
6162
void setExpressionDialogTitle( const QString& title );
6263

63-
/** Returns the title used for the expression dialog.
64+
/**
65+
* Returns the title used for the expression dialog.
6466
* @see setExpressionDialogTitle()
6567
*/
6668
QString expressionDialogTitle() const { return mExpressionDialogTitle; }
6769

68-
/** Sets whether the widget should show a multiline text editor.
70+
/**
71+
* Sets whether the widget should show a multiline text editor.
6972
* @param multiLine set to true to show multiline editor, or false
7073
* to show single line editor (the default).
7174
*/
7275
void setMultiLine( bool multiLine );
7376

74-
/** Set the geometry calculator used in the expression dialog.
77+
/**
78+
* Set the geometry calculator used in the expression dialog.
7579
* @param distanceArea calculator
7680
*/
7781
void setGeomCalculator( const QgsDistanceArea &distanceArea );
7882

79-
/** Sets a layer associated with the widget. Required in order to get the fields and values
80-
* from the layer.
81-
* @param layer vector layer
82-
*/
83+
/**
84+
* Sets a layer associated with the widget. Required in order to get the fields and values
85+
* from the layer.
86+
* This will also automatically register the layer as expression context generator if
87+
* no generator has been set before or the previous layer has been used as generator.
88+
*
89+
* @see registerExpressionContextGenerator
90+
*/
8391
void setLayer( QgsVectorLayer* layer );
8492

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

111120
public slots:
112121

113-
/** Sets the current expression to show in the widget.
122+
/**
123+
* Sets the current expression to show in the widget.
114124
* @param expression expression string
115125
* @see expression()
116126
*/
117127
void setExpression( const QString& expression );
118128

119129
protected:
130+
120131
void changeEvent( QEvent* event ) override;
121132

122133
private slots:
134+
123135
//! When the expression is edited by the user in the line edit, it will be checked for validity
124136
void expressionEdited( const QString& expression );
125137
void expressionEdited();

2 commit comments

Comments
 (2)

nyalldawson commented on Oct 5, 2016

@nyalldawson
Collaborator

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

m-kuhn commented on Oct 5, 2016

@m-kuhn
MemberAuthor

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

Please sign in to comment.