|
15 | 15 | ***************************************************************************/
|
16 | 16 |
|
17 | 17 | #include <QHBoxLayout>
|
| 18 | +#include <QObject> |
| 19 | +#include <QKeyEvent> |
18 | 20 |
|
19 | 21 | #include "qgsapplication.h"
|
20 | 22 | #include "qgsfieldexpressionwidget.h"
|
@@ -62,12 +64,12 @@ QgsFieldExpressionWidget::QgsFieldExpressionWidget( QWidget *parent )
|
62 | 64 | connect( mButton, &QAbstractButton::clicked, this, &QgsFieldExpressionWidget::editExpression );
|
63 | 65 | connect( mFieldProxyModel, &QAbstractItemModel::modelAboutToBeReset, this, &QgsFieldExpressionWidget::beforeResetModel );
|
64 | 66 | connect( mFieldProxyModel, &QAbstractItemModel::modelReset, this, &QgsFieldExpressionWidget::afterResetModel );
|
65 |
| - // NW TODO - Fix in 2.6 |
66 |
| -// connect( mCombo->lineEdit(), SIGNAL( returnPressed() ), this, SIGNAL( returnPressed() ) ); |
67 | 67 |
|
68 | 68 | mExpressionContext = QgsExpressionContext();
|
69 | 69 | mExpressionContext << QgsExpressionContextUtils::globalScope()
|
70 | 70 | << QgsExpressionContextUtils::projectScope( QgsProject::instance() );
|
| 71 | + |
| 72 | + mCombo->installEventFilter( this ); |
71 | 73 | }
|
72 | 74 |
|
73 | 75 | void QgsFieldExpressionWidget::setExpressionDialogTitle( const QString &title )
|
@@ -269,6 +271,20 @@ void QgsFieldExpressionWidget::afterResetModel()
|
269 | 271 | mCombo->lineEdit()->setText( mBackupExpression );
|
270 | 272 | }
|
271 | 273 |
|
| 274 | +bool QgsFieldExpressionWidget::eventFilter( QObject *watched, QEvent *event ) |
| 275 | +{ |
| 276 | + if ( watched == mCombo && event->type() == QEvent::KeyPress ) |
| 277 | + { |
| 278 | + QKeyEvent *keyEvent = static_cast<QKeyEvent *>( event ); |
| 279 | + if ( keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return ) |
| 280 | + { |
| 281 | + expressionEditingFinished(); |
| 282 | + return true; |
| 283 | + } |
| 284 | + } |
| 285 | + return QObject::eventFilter( watched, event ); |
| 286 | +} |
| 287 | + |
272 | 288 | bool QgsFieldExpressionWidget::allowEvalErrors() const
|
273 | 289 | {
|
274 | 290 | return mAllowEvalErrors;
|
|
0 commit comments