Skip to content
Permalink
Browse files

fix behaviour on focusOut and textEdited

it now matches exactly (i think) the dockwidget's behaviour
  • Loading branch information
olivierdalang committed May 15, 2019
1 parent d6ac603 commit 04d7e2af8e28a05a7820c791f307d69350e7ee4c
@@ -14,6 +14,8 @@
***************************************************************************/

#include <QMenu>
#include <QEvent>
#include <QCoreApplication>

#include <cmath>

@@ -160,25 +162,61 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
disable();
}

void QgsAdvancedDigitizingDockWidget::setX( const QString &value )
void QgsAdvancedDigitizingDockWidget::setX( const QString &value, WidgetSetMode mode )
{
mXLineEdit->setText( value );
mXLineEdit->returnPressed();
if( mode == WidgetSetMode::ReturnPressed){
mXLineEdit->returnPressed();
}
else if ( mode == WidgetSetMode::FocusOut){
QEvent *e = new QEvent(QEvent::FocusOut);
QCoreApplication::postEvent(mXLineEdit, e);
}
else if ( mode == WidgetSetMode::TextEdited){
mXLineEdit->textEdited(value);
}
}
void QgsAdvancedDigitizingDockWidget::setY( const QString &value )
void QgsAdvancedDigitizingDockWidget::setY( const QString &value, WidgetSetMode mode )
{
mYLineEdit->setText( value );
mYLineEdit->returnPressed();
if( mode == WidgetSetMode::ReturnPressed){
mYLineEdit->returnPressed();
}
else if ( mode == WidgetSetMode::FocusOut){
QEvent *e = new QEvent(QEvent::FocusOut);
QCoreApplication::postEvent(mYLineEdit, e);
}
else if ( mode == WidgetSetMode::TextEdited){
mYLineEdit->textEdited(value);
}
}
void QgsAdvancedDigitizingDockWidget::setAngle( const QString &value )
void QgsAdvancedDigitizingDockWidget::setAngle( const QString &value, WidgetSetMode mode )
{
mAngleLineEdit->setText( value );
mAngleLineEdit->returnPressed();
if( mode == WidgetSetMode::ReturnPressed){
mAngleLineEdit->returnPressed();
}
else if ( mode == WidgetSetMode::FocusOut){
QEvent *e = new QEvent(QEvent::FocusOut);
QCoreApplication::postEvent(mAngleLineEdit, e);
}
else if ( mode == WidgetSetMode::TextEdited){
mAngleLineEdit->textEdited(value);
}
}
void QgsAdvancedDigitizingDockWidget::setDistance( const QString &value )
void QgsAdvancedDigitizingDockWidget::setDistance( const QString &value, WidgetSetMode mode )
{
mDistanceLineEdit->setText( value );
mDistanceLineEdit->returnPressed();
if( mode == WidgetSetMode::ReturnPressed){
mDistanceLineEdit->returnPressed();
}
else if ( mode == WidgetSetMode::FocusOut){
QEvent *e = new QEvent(QEvent::FocusOut);
QCoreApplication::postEvent(mDistanceLineEdit, e);
}
else if ( mode == WidgetSetMode::TextEdited){
mDistanceLineEdit->textEdited(value);
}
}


@@ -74,6 +74,13 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
Parallel //!< Parallel
};

/**
* Type of interaction to simulate when editing values from external widget
*/
enum WidgetSetMode {
ReturnPressed, FocusOut, TextEdited
};


/**
* \ingroup gui
@@ -344,36 +351,42 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
void updateCadPaintItem();

/**
* Set and lock the X \a value.
* Can be used to set constraints.
* Set the X \a value on the widget.
* Can be used to set constraints by external widgets.
* \param mode What type of interaction to emulate
* \note The value is a QString, as it could be an expression.
* \since QGIS 3.8
*/
void setX( const QString &value );
void setX( const QString &value, WidgetSetMode mode );

/**
* Set and lock the Y \a value.
* Can be used to set constraints.
* Set the Y \a value on the widget.
* Can be used to set constraints by external widgets.
* \param mode What type of interaction to emulate
* \note The value is a QString, as it could be an expression.
* \since QGIS 3.8
*/
void setY( const QString &value );
void setY( const QString &value, WidgetSetMode mode );

/**
* Set and lock the angle \a value.
* Can be used to set constraints.
* Set the angle \a value on the widget.
* Can be used to set constraints by external widgets.
* \param mode What type of interaction to emulate
* \note The value is a QString, as it could be an expression.
* \since QGIS 3.8
*/
void setAngle( const QString &value );
void setAngle( const QString &value, WidgetSetMode mode );

/**
* Set and lock the distance \a value.
* Can be used to set constraints.
* Set the distance \a value on the widget.
* Can be used to set constraints by external widgets.
* \param mode What type of interaction to emulate
* \note The value is a QString, as it could be an expression.
* \since QGIS 3.8
*/
void setDistance( const QString &value );
void setDistance( const QString &value, WidgetSetMode mode );



signals:

@@ -21,6 +21,7 @@
#include "qgsmessagelog.h"
#include "qgsmapcanvas.h"
#include "qgssettings.h"
#include "qgsfocuswatcher.h"

QgsAdvancedDigitizingFloater::QgsAdvancedDigitizingFloater( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget )
: QWidget( canvas->viewport() ), mMapCanvas( canvas ), mCadDockWidget( cadDockWidget )
@@ -71,11 +72,26 @@ QgsAdvancedDigitizingFloater::QgsAdvancedDigitizingFloater( QgsMapCanvas *canvas
connect( cadDockWidget, &QgsAdvancedDigitizingDockWidget::enabledChangedAngle, this, &QgsAdvancedDigitizingFloater::enabledChangedAngle );
connect( cadDockWidget, &QgsAdvancedDigitizingDockWidget::enabledChangedDistance, this, &QgsAdvancedDigitizingFloater::enabledChangedDistance );

// Connect our line edits signals to update cadDockWidget's state
connect( mXLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->setX( mXLineEdit->text() ); } );
connect( mYLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->setY( mYLineEdit->text() ); } );
connect( mAngleLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->setAngle( mAngleLineEdit->text() ); } );
connect( mDistanceLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->setDistance( mDistanceLineEdit->text() ); } );
// Connect our line edits signals to update cadDockWidget's state (implementation copied from QgsAdvancedDigitizingDockWidget)
connect( mXLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
connect( mYLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
connect( mAngleLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
connect( mDistanceLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );

connect( mXLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
connect( mYLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
connect( mAngleLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
connect( mDistanceLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );

QgsFocusWatcher *xWatcher = new QgsFocusWatcher( mXLineEdit );
connect( xWatcher, &QgsFocusWatcher::focusOut, cadDockWidget, [=](){ cadDockWidget->setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
QgsFocusWatcher *yWatcher = new QgsFocusWatcher( mYLineEdit );
connect( yWatcher, &QgsFocusWatcher::focusOut, cadDockWidget, [=](){ cadDockWidget->setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
QgsFocusWatcher *angleWatcher = new QgsFocusWatcher( mAngleLineEdit );
connect( angleWatcher, &QgsFocusWatcher::focusOut, cadDockWidget, [=](){ cadDockWidget->setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
QgsFocusWatcher *distanceWatcher = new QgsFocusWatcher( mDistanceLineEdit );
connect( distanceWatcher, &QgsFocusWatcher::focusOut, cadDockWidget, [=](){ cadDockWidget->setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );

}

bool QgsAdvancedDigitizingFloater::eventFilter( QObject *obj, QEvent *event )

0 comments on commit 04d7e2a

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