Skip to content
Permalink
Browse files

Fix #19465 - Don't delete expression when pressing enter in combo (#8134

)
  • Loading branch information
NathanW2 committed Oct 8, 2018
1 parent 4da2b80 commit 556cddd4d9fcb3e45ddb8cd210e2306ef65a2446
@@ -224,6 +224,9 @@ updateLineEditStyle will re-style (color/font) the line edit depending on conten
virtual void changeEvent( QEvent *event );


virtual bool eventFilter( QObject *watched, QEvent *event );


};

/************************************************************************
@@ -15,6 +15,8 @@
***************************************************************************/

#include <QHBoxLayout>
#include <QObject>
#include <QKeyEvent>

#include "qgsapplication.h"
#include "qgsfieldexpressionwidget.h"
@@ -62,12 +64,12 @@ QgsFieldExpressionWidget::QgsFieldExpressionWidget( QWidget *parent )
connect( mButton, &QAbstractButton::clicked, this, &QgsFieldExpressionWidget::editExpression );
connect( mFieldProxyModel, &QAbstractItemModel::modelAboutToBeReset, this, &QgsFieldExpressionWidget::beforeResetModel );
connect( mFieldProxyModel, &QAbstractItemModel::modelReset, this, &QgsFieldExpressionWidget::afterResetModel );
// NW TODO - Fix in 2.6
// connect( mCombo->lineEdit(), SIGNAL( returnPressed() ), this, SIGNAL( returnPressed() ) );

mExpressionContext = QgsExpressionContext();
mExpressionContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope( QgsProject::instance() );

mCombo->installEventFilter( this );
}

void QgsFieldExpressionWidget::setExpressionDialogTitle( const QString &title )
@@ -269,6 +271,20 @@ void QgsFieldExpressionWidget::afterResetModel()
mCombo->lineEdit()->setText( mBackupExpression );
}

bool QgsFieldExpressionWidget::eventFilter( QObject *watched, QEvent *event )
{
if ( watched == mCombo && event->type() == QEvent::KeyPress )
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>( event );
if ( keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return )
{
expressionEditingFinished();
return true;
}
}
return QObject::eventFilter( watched, event );
}

bool QgsFieldExpressionWidget::allowEvalErrors() const
{
return mAllowEvalErrors;
@@ -216,6 +216,8 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
protected:
void changeEvent( QEvent *event ) override;

bool eventFilter( QObject *watched, QEvent *event ) override;

private slots:
void reloadLayer();

0 comments on commit 556cddd

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