Skip to content

Commit

Permalink
Apply requested UX logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jul 30, 2024
1 parent 9fab4fc commit 53040f0
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
16 changes: 16 additions & 0 deletions python/PyQt6/gui/auto_generated/editorwidgets/qgsspinbox.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
16 changes: 16 additions & 0 deletions python/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
16 changes: 16 additions & 0 deletions python/gui/auto_generated/editorwidgets/qgsspinbox.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsdoublespinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
14 changes: 14 additions & 0 deletions src/gui/editorwidgets/qgsdoublespinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/editorwidgets/qgsspinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions src/gui/editorwidgets/qgsspinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsadvanceddigitizingdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgsadvanceddigitizingtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget()
mCircle1X = new QgsDoubleSpinBox( toolWidget );
mCircle1X->setMinimum( std::numeric_limits<double>::min() );
mCircle1X->setMaximum( std::numeric_limits<double>::max() );
connect( mCircle1X, &QgsDoubleSpinBox::textEdited, this, [ = ]() { mCircle1Digitize->setChecked( false ); } );
layout->addWidget( mCircle1X, 1, 1 );

label = new QLabel( QStringLiteral( "Y" ), toolWidget );
Expand All @@ -65,6 +66,7 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget()
mCircle1Y = new QgsDoubleSpinBox( toolWidget );
mCircle1Y->setMinimum( std::numeric_limits<double>::min() );
mCircle1Y->setMaximum( std::numeric_limits<double>::max() );
connect( mCircle1Y, &QgsDoubleSpinBox::textEdited, this, [ = ]() { mCircle1Digitize->setChecked( false ); } );
layout->addWidget( mCircle1Y, 2, 1 );

label = new QLabel( QStringLiteral( "Distance" ), toolWidget );
Expand All @@ -73,6 +75,7 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget()
mCircle1Distance = new QgsDoubleSpinBox( toolWidget );
mCircle1Distance->setMinimum( 0 );
mCircle1Distance->setMaximum( std::numeric_limits<double>::max() );
connect( mCircle1Distance, &QgsDoubleSpinBox::returnPressed, this, [ = ]() { mCircle2Digitize->setChecked( true ); } );
layout->addWidget( mCircle1Distance, 3, 1 );

label = new QLabel( QStringLiteral( "Circle #2" ), toolWidget );
Expand All @@ -90,6 +93,7 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget()
mCircle2X = new QgsDoubleSpinBox( toolWidget );
mCircle2X->setMinimum( std::numeric_limits<double>::min() );
mCircle2X->setMaximum( std::numeric_limits<double>::max() );
connect( mCircle2X, &QgsDoubleSpinBox::textEdited, this, [ = ]() { mCircle2Digitize->setChecked( false ); } );
layout->addWidget( mCircle2X, 5, 1 );

label = new QLabel( QStringLiteral( "Y" ), toolWidget );
Expand All @@ -98,6 +102,7 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget()
mCircle2Y = new QgsDoubleSpinBox( toolWidget );
mCircle2Y->setMinimum( std::numeric_limits<double>::min() );
mCircle2Y->setMaximum( std::numeric_limits<double>::max() );
connect( mCircle2Y, &QgsDoubleSpinBox::textEdited, this, [ = ]() { mCircle2Digitize->setChecked( false ); } );
layout->addWidget( mCircle2Y, 6, 1 );

label = new QLabel( QStringLiteral( "Distance" ), toolWidget );
Expand All @@ -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;
}
Expand Down Expand Up @@ -157,6 +164,7 @@ void QgsAdvancedDigitizingCirclesIntersectionTool::canvasReleaseEvent( QgsMapMou
mCircle1X->setValue( event->mapPoint().x() );
mCircle1Y->setValue( event->mapPoint().y() );
mCircle1Digitize->setChecked( false );
mCircle1Distance->setFocus();
event->setAccepted( false );
return;
}
Expand All @@ -165,6 +173,7 @@ void QgsAdvancedDigitizingCirclesIntersectionTool::canvasReleaseEvent( QgsMapMou
mCircle2X->setValue( event->mapPoint().x() );
mCircle2Y->setValue( event->mapPoint().y() );
mCircle2Digitize->setChecked( false );
mCircle2Distance->setFocus();
event->setAccepted( false );
return;
}
Expand Down

0 comments on commit 53040f0

Please sign in to comment.