Skip to content

Commit

Permalink
[simplify] accept/reject using keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Feb 26, 2018
1 parent 284ad06 commit a6eb520
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 8 deletions.
52 changes: 49 additions & 3 deletions src/app/qgsmaptoolsimplify.cpp
Expand Up @@ -45,7 +45,7 @@ QgsSimplifyUserInputWidget::QgsSimplifyUserInputWidget( QWidget *parent )
mToleranceUnitsComboBox->addItem( tr( "Pixels" ), QgsTolerance::Pixels ); mToleranceUnitsComboBox->addItem( tr( "Pixels" ), QgsTolerance::Pixels );
mToleranceUnitsComboBox->addItem( tr( "Map units" ), QgsTolerance::ProjectUnits ); mToleranceUnitsComboBox->addItem( tr( "Map units" ), QgsTolerance::ProjectUnits );


mSpinToleranceSpinBox->setShowClearButton( false ); mToleranceSpinBox->setShowClearButton( false );


mOffsetSpin->setClearValue( 25 ); mOffsetSpin->setClearValue( 25 );
mIterationsSpin->setClearValue( 1 ); mIterationsSpin->setClearValue( 1 );
Expand All @@ -55,7 +55,7 @@ QgsSimplifyUserInputWidget::QgsSimplifyUserInputWidget( QWidget *parent )
mOptionsStackedWidget->setCurrentIndex( 1 ); mOptionsStackedWidget->setCurrentIndex( 1 );


// communication with map tool // communication with map tool
connect( mSpinToleranceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimplifyUserInputWidget::toleranceChanged ); connect( mToleranceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimplifyUserInputWidget::toleranceChanged );
connect( mToleranceUnitsComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]( const int index ) {emit toleranceUnitsChanged( ( QgsTolerance::UnitType )index );} ); connect( mToleranceUnitsComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]( const int index ) {emit toleranceUnitsChanged( ( QgsTolerance::UnitType )index );} );
connect( mMethodComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]( const int method ) {emit methodChanged( ( QgsMapToolSimplify::Method )method );} ); connect( mMethodComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]( const int method ) {emit methodChanged( ( QgsMapToolSimplify::Method )method );} );
connect( mMethodComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ] connect( mMethodComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]
Expand All @@ -71,6 +71,12 @@ QgsSimplifyUserInputWidget::QgsSimplifyUserInputWidget( QWidget *parent )


connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsSimplifyUserInputWidget::accepted ); connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsSimplifyUserInputWidget::accepted );
connect( mButtonBox, &QDialogButtonBox::rejected, this, &QgsSimplifyUserInputWidget::rejected ); connect( mButtonBox, &QDialogButtonBox::rejected, this, &QgsSimplifyUserInputWidget::rejected );

mToleranceSpinBox->installEventFilter( this );
mOffsetSpin->installEventFilter( this );
mIterationsSpin->installEventFilter( this );

setFocusProxy( mButtonBox );
} }


void QgsSimplifyUserInputWidget::setConfig( const QgsMapToolSimplify::Method &method, void QgsSimplifyUserInputWidget::setConfig( const QgsMapToolSimplify::Method &method,
Expand All @@ -81,7 +87,7 @@ void QgsSimplifyUserInputWidget::setConfig( const QgsMapToolSimplify::Method &me
{ {
mMethodComboBox->setCurrentIndex( mMethodComboBox->findData( method ) ); mMethodComboBox->setCurrentIndex( mMethodComboBox->findData( method ) );


mSpinToleranceSpinBox->setValue( tolerance ); mToleranceSpinBox->setValue( tolerance );
mToleranceUnitsComboBox->setCurrentIndex( mToleranceUnitsComboBox->findData( units ) ); mToleranceUnitsComboBox->setCurrentIndex( mToleranceUnitsComboBox->findData( units ) );
mOffsetSpin->setValue( 100 * smoothOffset ); mOffsetSpin->setValue( 100 * smoothOffset );
mIterationsSpin->setValue( smoothIterations ); mIterationsSpin->setValue( smoothIterations );
Expand All @@ -97,6 +103,37 @@ void QgsSimplifyUserInputWidget::enableOkButton( bool enabled )
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled ); mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
} }


bool QgsSimplifyUserInputWidget::eventFilter( QObject *object, QEvent *ev )
{
Q_UNUSED( object );
if ( ev->type() == QEvent::KeyPress )
{
QKeyEvent *event = static_cast<QKeyEvent *>( ev );
if ( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return )
{
emit accepted();
return true;
}
}

return false;
}

void QgsSimplifyUserInputWidget::keyReleaseEvent( QKeyEvent *event )
{
if ( event->key() == Qt::Key_Escape )
{
emit rejected();
return;
}
if ( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return )
{
emit accepted();
return;
}
QWidget::keyReleaseEvent( event );
}

//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////




Expand Down Expand Up @@ -370,6 +407,15 @@ void QgsMapToolSimplify::canvasReleaseEvent( QgsMapMouseEvent *e )
updateSimplificationPreview(); updateSimplificationPreview();
} }


void QgsMapToolSimplify::keyReleaseEvent( QKeyEvent *e )
{
if ( e->key() == Qt::Key_Escape )
{
clearSelection();
return;
}
QgsMapTool::keyReleaseEvent( e );
}


void QgsMapToolSimplify::selectOneFeature( QPoint canvasPoint ) void QgsMapToolSimplify::selectOneFeature( QPoint canvasPoint )
{ {
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsmaptoolsimplify.h
Expand Up @@ -50,6 +50,7 @@ class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
void canvasPressEvent( QgsMapMouseEvent *e ) override; void canvasPressEvent( QgsMapMouseEvent *e ) override;
void canvasMoveEvent( QgsMapMouseEvent *e ) override; void canvasMoveEvent( QgsMapMouseEvent *e ) override;
void canvasReleaseEvent( QgsMapMouseEvent *e ) override; void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
void keyReleaseEvent( QKeyEvent *e ) override;


//! called when map tool is being deactivated //! called when map tool is being deactivated
void deactivate() override; void deactivate() override;
Expand Down Expand Up @@ -152,6 +153,9 @@ class APP_EXPORT QgsSimplifyUserInputWidget : public QWidget, private Ui::Simpli
void smoothOffsetChanged( double offset ); void smoothOffsetChanged( double offset );
void smoothIterationsChanged( int iterations ); void smoothIterationsChanged( int iterations );


protected:
bool eventFilter( QObject *object, QEvent *ev ) override;
void keyReleaseEvent( QKeyEvent *event ) override;
}; };


#endif #endif
48 changes: 43 additions & 5 deletions src/ui/qgssimplifytolerancedialog.ui
Expand Up @@ -10,6 +10,12 @@
<height>114</height> <height>114</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Simplification Tool</string> <string>Simplification Tool</string>
</property> </property>
Expand Down Expand Up @@ -51,7 +57,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QgsDoubleSpinBox" name="mSpinToleranceSpinBox"> <widget class="QgsDoubleSpinBox" name="mToleranceSpinBox">
<property name="decimals"> <property name="decimals">
<number>6</number> <number>6</number>
</property> </property>
Expand All @@ -64,7 +70,14 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="mToleranceUnitsComboBox"/> <widget class="QComboBox" name="mToleranceUnitsComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
Expand All @@ -91,6 +104,12 @@
</item> </item>
<item> <item>
<widget class="QgsSpinBox" name="mIterationsSpin"> <widget class="QgsSpinBox" name="mIterationsSpin">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Number of smooth iterations. More iterations results in smoother geometries, at the expense of greatly increasing the number of vertices in those geometries.</string> <string>Number of smooth iterations. More iterations results in smoother geometries, at the expense of greatly increasing the number of vertices in those geometries.</string>
</property> </property>
Expand All @@ -114,6 +133,12 @@
</item> </item>
<item> <item>
<widget class="QgsSpinBox" name="mOffsetSpin"> <widget class="QgsSpinBox" name="mOffsetSpin">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Offset from existing vertices at which to insert smoothed vertices. Larger values result in &quot;looser&quot; smoothing, smaller values result in &quot;tight&quot; smoothing.</string> <string>Offset from existing vertices at which to insert smoothed vertices. Larger values result in &quot;looser&quot; smoothing, smaller values result in &quot;tight&quot; smoothing.</string>
</property> </property>
Expand All @@ -129,16 +154,29 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="mMethodComboBox"/>
</item>
<item row="0" column="3"> <item row="0" column="3">
<widget class="QDialogButtonBox" name="mButtonBox"> <widget class="QDialogButtonBox" name="mButtonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="mMethodComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
Expand Down

0 comments on commit a6eb520

Please sign in to comment.