From a83c9737a6bc5360799c051df93712a1d130af79 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Tue, 30 Jul 2024 09:56:52 +0700 Subject: [PATCH] Apply requested UX logic --- .../editorwidgets/qgsdoublespinbox.sip.in | 16 ++++++++++++++++ .../editorwidgets/qgsspinbox.sip.in | 16 ++++++++++++++++ .../editorwidgets/qgsdoublespinbox.sip.in | 16 ++++++++++++++++ .../editorwidgets/qgsspinbox.sip.in | 16 ++++++++++++++++ src/gui/editorwidgets/qgsdoublespinbox.cpp | 1 + src/gui/editorwidgets/qgsdoublespinbox.h | 14 ++++++++++++++ src/gui/editorwidgets/qgsspinbox.cpp | 2 ++ src/gui/editorwidgets/qgsspinbox.h | 14 ++++++++++++++ src/gui/qgsadvanceddigitizingdockwidget.cpp | 3 ++- src/gui/qgsadvanceddigitizingtools.cpp | 9 +++++++++ 10 files changed, 106 insertions(+), 1 deletion(-) diff --git a/python/PyQt6/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in b/python/PyQt6/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in index 2103aacc0641..b3106b79dfd2 100644 --- a/python/PyQt6/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in +++ b/python/PyQt6/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in @@ -138,6 +138,22 @@ is equal to :py:func:`~QgsDoubleSpinBox.minimum`. Typical use is to indicate tha virtual void stepBy( int steps ); + signals: + + void returnPressed(); +%Docstring +Emitted when the Return or Enter key is used in the line edit. + +.. versionadded:: 3.40 +%End + + void textEdited( const QString &text ); +%Docstring +Emitted when the the value has been manually edited via line edit. + +.. versionadded:: 3.40 +%End + protected: virtual void changeEvent( QEvent *event ); diff --git a/python/PyQt6/gui/auto_generated/editorwidgets/qgsspinbox.sip.in b/python/PyQt6/gui/auto_generated/editorwidgets/qgsspinbox.sip.in index 8e3fb06ba77e..7461c9ccd83e 100644 --- a/python/PyQt6/gui/auto_generated/editorwidgets/qgsspinbox.sip.in +++ b/python/PyQt6/gui/auto_generated/editorwidgets/qgsspinbox.sip.in @@ -136,6 +136,22 @@ is equal to :py:func:`~QgsSpinBox.minimum`. Typical use is to indicate that this virtual void stepBy( int steps ); + signals: + + void returnPressed(); +%Docstring +Emitted when the Return or Enter key is used in the line edit + +.. versionadded:: 3.40 +%End + + void textEdited( const QString &text ); +%Docstring +Emitted when the the value has been manually edited via line edit. + +.. versionadded:: 3.40 +%End + protected: virtual void changeEvent( QEvent *event ); diff --git a/python/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in b/python/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in index 592b70c3a898..e167a3500f26 100644 --- a/python/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in +++ b/python/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in @@ -138,6 +138,22 @@ is equal to :py:func:`~QgsDoubleSpinBox.minimum`. Typical use is to indicate tha virtual void stepBy( int steps ); + signals: + + void returnPressed(); +%Docstring +Emitted when the Return or Enter key is used in the line edit. + +.. versionadded:: 3.40 +%End + + void textEdited( const QString &text ); +%Docstring +Emitted when the the value has been manually edited via line edit. + +.. versionadded:: 3.40 +%End + protected: virtual void changeEvent( QEvent *event ); diff --git a/python/gui/auto_generated/editorwidgets/qgsspinbox.sip.in b/python/gui/auto_generated/editorwidgets/qgsspinbox.sip.in index 15de6adb253f..022beaa9ad9e 100644 --- a/python/gui/auto_generated/editorwidgets/qgsspinbox.sip.in +++ b/python/gui/auto_generated/editorwidgets/qgsspinbox.sip.in @@ -136,6 +136,22 @@ is equal to :py:func:`~QgsSpinBox.minimum`. Typical use is to indicate that this virtual void stepBy( int steps ); + signals: + + void returnPressed(); +%Docstring +Emitted when the Return or Enter key is used in the line edit + +.. versionadded:: 3.40 +%End + + void textEdited( const QString &text ); +%Docstring +Emitted when the the value has been manually edited via line edit. + +.. versionadded:: 3.40 +%End + protected: virtual void changeEvent( QEvent *event ); diff --git a/src/gui/editorwidgets/qgsdoublespinbox.cpp b/src/gui/editorwidgets/qgsdoublespinbox.cpp index 71d354f8e5dc..a4446cf16194 100644 --- a/src/gui/editorwidgets/qgsdoublespinbox.cpp +++ b/src/gui/editorwidgets/qgsdoublespinbox.cpp @@ -40,6 +40,7 @@ QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent ) : QDoubleSpinBox( parent ) { mLineEdit = new QgsSpinBoxLineEdit(); + connect( mLineEdit, &QLineEdit::returnPressed, this, &QgsDoubleSpinBox::returnPressed ); // By default, group separator is off setLineEdit( mLineEdit ); diff --git a/src/gui/editorwidgets/qgsdoublespinbox.h b/src/gui/editorwidgets/qgsdoublespinbox.h index f1ad4ddf542f..7bf91175efa3 100644 --- a/src/gui/editorwidgets/qgsdoublespinbox.h +++ b/src/gui/editorwidgets/qgsdoublespinbox.h @@ -142,6 +142,20 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox void paintEvent( QPaintEvent *e ) override; void stepBy( int steps ) override; + signals: + + /** + * Emitted when the Return or Enter key is used in the line edit. + * \since QGIS 3.40 + */ + void returnPressed(); + + /** + * Emitted when the the value has been manually edited via line edit. + * \since QGIS 3.40 + */ + void textEdited( const QString &text ); + protected: void changeEvent( QEvent *event ) override; void wheelEvent( QWheelEvent *event ) override; diff --git a/src/gui/editorwidgets/qgsspinbox.cpp b/src/gui/editorwidgets/qgsspinbox.cpp index 920949936553..b9f273a9b8d6 100644 --- a/src/gui/editorwidgets/qgsspinbox.cpp +++ b/src/gui/editorwidgets/qgsspinbox.cpp @@ -39,6 +39,8 @@ QgsSpinBox::QgsSpinBox( QWidget *parent ) : QSpinBox( parent ) { mLineEdit = new QgsSpinBoxLineEdit(); + connect( mLineEdit, &QLineEdit::returnPressed, this, &QgsSpinBox::returnPressed ); + connect( mLineEdit, &QLineEdit::textEdited, this, &QgsSpinBox::textEdited ); setLineEdit( mLineEdit ); const QSize msz = minimumSizeHint(); diff --git a/src/gui/editorwidgets/qgsspinbox.h b/src/gui/editorwidgets/qgsspinbox.h index d9fb3367b503..636215fd7dfa 100644 --- a/src/gui/editorwidgets/qgsspinbox.h +++ b/src/gui/editorwidgets/qgsspinbox.h @@ -141,6 +141,20 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox QValidator::State validate( QString &input, int &pos ) const override; void stepBy( int steps ) override; + signals: + + /** + * Emitted when the Return or Enter key is used in the line edit + * \since QGIS 3.40 + */ + void returnPressed(); + + /** + * Emitted when the the value has been manually edited via line edit. + * \since QGIS 3.40 + */ + void textEdited( const QString &text ); + protected: void changeEvent( QEvent *event ) override; diff --git a/src/gui/qgsadvanceddigitizingdockwidget.cpp b/src/gui/qgsadvanceddigitizingdockwidget.cpp index 383c0e2d31f7..f4fb773a32d4 100644 --- a/src/gui/qgsadvanceddigitizingdockwidget.cpp +++ b/src/gui/qgsadvanceddigitizingdockwidget.cpp @@ -244,11 +244,12 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas * QMenu *toolsMenu = new QMenu( this ); connect( toolsMenu, &QMenu::aboutToShow, this, [ = ]() { + toolsMenu->clear(); const QStringList toolMetadataNames = QgsGui::instance()->advancedDigitizingToolsRegistry()->toolMetadataNames(); for ( const QString &name : toolMetadataNames ) { QgsAdvancedDigitizingToolAbstractMetadata *toolMetadata = QgsGui::instance()->advancedDigitizingToolsRegistry()->toolMetadata( name ); - QAction *toolAction = new QAction( toolMetadata->icon(), toolMetadata->visibleName(), this ); + QAction *toolAction = new QAction( toolMetadata->icon(), toolMetadata->visibleName(), toolsMenu ); connect( toolAction, &QAction::triggered, this, [ = ]() { setTool( toolMetadata->createTool( mMapCanvas, this ) ); diff --git a/src/gui/qgsadvanceddigitizingtools.cpp b/src/gui/qgsadvanceddigitizingtools.cpp index b85e4d16cce6..ca483f5a9c61 100644 --- a/src/gui/qgsadvanceddigitizingtools.cpp +++ b/src/gui/qgsadvanceddigitizingtools.cpp @@ -57,6 +57,7 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget() mCircle1X = new QgsDoubleSpinBox( toolWidget ); mCircle1X->setMinimum( std::numeric_limits::min() ); mCircle1X->setMaximum( std::numeric_limits::max() ); + connect( mCircle1X, &QgsDoubleSpinBox::textEdited, this, [ = ]() { mCircle1Digitize->setChecked( false ); } ); layout->addWidget( mCircle1X, 1, 1 ); label = new QLabel( QStringLiteral( "Y" ), toolWidget ); @@ -65,6 +66,7 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget() mCircle1Y = new QgsDoubleSpinBox( toolWidget ); mCircle1Y->setMinimum( std::numeric_limits::min() ); mCircle1Y->setMaximum( std::numeric_limits::max() ); + connect( mCircle1Y, &QgsDoubleSpinBox::textEdited, this, [ = ]() { mCircle1Digitize->setChecked( false ); } ); layout->addWidget( mCircle1Y, 2, 1 ); label = new QLabel( QStringLiteral( "Distance" ), toolWidget ); @@ -73,6 +75,7 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget() mCircle1Distance = new QgsDoubleSpinBox( toolWidget ); mCircle1Distance->setMinimum( 0 ); mCircle1Distance->setMaximum( std::numeric_limits::max() ); + connect( mCircle1Distance, &QgsDoubleSpinBox::returnPressed, this, [ = ]() { mCircle2Digitize->setChecked( true ); } ); layout->addWidget( mCircle1Distance, 3, 1 ); label = new QLabel( QStringLiteral( "Circle #2" ), toolWidget ); @@ -90,6 +93,7 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget() mCircle2X = new QgsDoubleSpinBox( toolWidget ); mCircle2X->setMinimum( std::numeric_limits::min() ); mCircle2X->setMaximum( std::numeric_limits::max() ); + connect( mCircle2X, &QgsDoubleSpinBox::textEdited, this, [ = ]() { mCircle2Digitize->setChecked( false ); } ); layout->addWidget( mCircle2X, 5, 1 ); label = new QLabel( QStringLiteral( "Y" ), toolWidget ); @@ -98,6 +102,7 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget() mCircle2Y = new QgsDoubleSpinBox( toolWidget ); mCircle2Y->setMinimum( std::numeric_limits::min() ); mCircle2Y->setMaximum( std::numeric_limits::max() ); + connect( mCircle2Y, &QgsDoubleSpinBox::textEdited, this, [ = ]() { mCircle2Digitize->setChecked( false ); } ); layout->addWidget( mCircle2Y, 6, 1 ); label = new QLabel( QStringLiteral( "Distance" ), toolWidget ); @@ -115,6 +120,8 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget() connect( mCircle2Y, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double ) { processParameters(); } ); connect( mCircle2Distance, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double ) { processParameters(); } ); + mCircle1Digitize->setChecked( true ); + mToolWidget = toolWidget; return toolWidget; } @@ -135,11 +142,13 @@ void QgsAdvancedDigitizingCirclesIntersectionTool::canvasMoveEvent( QgsMapMouseE { mCircle1X->setValue( event->mapPoint().x() ); mCircle1Y->setValue( event->mapPoint().y() ); + QTimer::singleShot( 100, [ = ]() { mCircle1Distance->setFocus(); } ); } else if ( mCircle2Digitize->isChecked() ) { mCircle2X->setValue( event->mapPoint().x() ); mCircle2Y->setValue( event->mapPoint().y() ); + QTimer::singleShot( 100, [ = ]() { mCircle2Distance->setFocus(); } ); } if ( !mP1.isEmpty() )