Skip to content
Permalink
Browse files

Custom embedded attribute form ui: Forward esc keypress to parent

Fix #10675
  • Loading branch information
m-kuhn committed Jun 24, 2014
1 parent bbb9700 commit acea234267a58201370edf488e869dcc007292de
Showing with 32 additions and 0 deletions.
  1. +22 −0 src/gui/qgsattributeform.cpp
  2. +10 −0 src/gui/qgsattributeform.h
@@ -28,6 +28,7 @@
#include <QFormLayout>
#include <QGridLayout>
#include <QGroupBox>
#include <QKeyEvent>
#include <QLabel>
#include <QPushButton>
#include <QScrollArea>
@@ -322,6 +323,8 @@ void QgsAttributeForm::init()
formWidget->show();
file.close();
createWrappers();

formWidget->installEventFilter( this );
}
}

@@ -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;
}
@@ -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

0 comments on commit acea234

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