Skip to content

Commit

Permalink
Custom embedded attribute form ui: Forward esc keypress to parent
Browse files Browse the repository at this point in the history
Fix #10675
  • Loading branch information
m-kuhn committed Jun 24, 2014
1 parent bbb9700 commit acea234
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -28,6 +28,7 @@
#include <QFormLayout>
#include <QGridLayout>
#include <QGroupBox>
#include <QKeyEvent>
#include <QLabel>
#include <QPushButton>
#include <QScrollArea>
Expand Down Expand Up @@ -322,6 +323,8 @@ void QgsAttributeForm::init()
formWidget->show();
file.close();
createWrappers();

formWidget->installEventFilter( this );
}
}

Expand Down Expand Up @@ -664,3 +667,22 @@ void QgsAttributeForm::connectWrappers()
connect( eww, SIGNAL( valueChanged( const QVariant& ) ), this, SLOT( onAttributeChanged( const QVariant& ) ) );
}
}


bool QgsAttributeForm::eventFilter( QObject* object, QEvent* e )
{
Q_UNUSED( object )

if ( e->type() == QEvent::KeyPress )
{
QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>( e );
if ( keyEvent->key() == Qt::Key_Escape )
{
// Re-emit to this form so it will be forwarded to parent
event( e );
return true;
}
}

return false;
}
10 changes: 10 additions & 0 deletions src/gui/qgsattributeform.h
Expand Up @@ -66,6 +66,16 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
*/
void setEditCommandMessage( const QString& message ) { mEditCommandMessage = message; }

/**
* Intercepts keypress on custom form (escape should not close it)
*
* @param object The object for which the event has been sent
* @param event The event which is being filtered
*
* @return true if the event has been handled (key was ESC)
*/
bool eventFilter( QObject* object, QEvent* event );

signals:
/**
* Notifies about changes of attributes
Expand Down

0 comments on commit acea234

Please sign in to comment.