Navigation Menu

Skip to content

Commit

Permalink
Show fields in "default value" expression editor
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 5, 2016
1 parent 0348dd5 commit b642c3f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsexpressionlineedit.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgsexpressionbuilderdialog.h"
#include "qgsexpressioncontextgenerator.h"
#include "qgscodeeditorsql.h"
#include "qgsvectorlayer.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QToolButton>
Expand Down Expand Up @@ -113,6 +114,8 @@ void QgsExpressionLineEdit::setGeomCalculator( const QgsDistanceArea &da )

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

Expand Down
32 changes: 22 additions & 10 deletions src/gui/qgsexpressionlineedit.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

2 comments on commit b642c3f

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on b642c3f Oct 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.