Skip to content
Permalink
Browse files

[simplify] accept/reject using keyboard

  • Loading branch information
3nids committed Feb 26, 2018
1 parent 284ad06 commit a6eb520a6187e2eb6920b23e092390e508a65987
Showing with 96 additions and 8 deletions.
  1. +49 −3 src/app/qgsmaptoolsimplify.cpp
  2. +4 −0 src/app/qgsmaptoolsimplify.h
  3. +43 −5 src/ui/qgssimplifytolerancedialog.ui
@@ -45,7 +45,7 @@ QgsSimplifyUserInputWidget::QgsSimplifyUserInputWidget( QWidget *parent )
mToleranceUnitsComboBox->addItem( tr( "Pixels" ), QgsTolerance::Pixels );
mToleranceUnitsComboBox->addItem( tr( "Map units" ), QgsTolerance::ProjectUnits );

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

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

// 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( 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, [ = ]
@@ -71,6 +71,12 @@ QgsSimplifyUserInputWidget::QgsSimplifyUserInputWidget( QWidget *parent )

connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsSimplifyUserInputWidget::accepted );
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,
@@ -81,7 +87,7 @@ void QgsSimplifyUserInputWidget::setConfig( const QgsMapToolSimplify::Method &me
{
mMethodComboBox->setCurrentIndex( mMethodComboBox->findData( method ) );

mSpinToleranceSpinBox->setValue( tolerance );
mToleranceSpinBox->setValue( tolerance );
mToleranceUnitsComboBox->setCurrentIndex( mToleranceUnitsComboBox->findData( units ) );
mOffsetSpin->setValue( 100 * smoothOffset );
mIterationsSpin->setValue( smoothIterations );
@@ -97,6 +103,37 @@ void QgsSimplifyUserInputWidget::enableOkButton( bool 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 );
}

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


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

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

void QgsMapToolSimplify::selectOneFeature( QPoint canvasPoint )
{
@@ -50,6 +50,7 @@ class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
void canvasPressEvent( QgsMapMouseEvent *e ) override;
void canvasMoveEvent( QgsMapMouseEvent *e ) override;
void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
void keyReleaseEvent( QKeyEvent *e ) override;

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

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

#endif
@@ -10,6 +10,12 @@
<height>114</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Simplification Tool</string>
</property>
@@ -51,7 +57,7 @@
</widget>
</item>
<item>
<widget class="QgsDoubleSpinBox" name="mSpinToleranceSpinBox">
<widget class="QgsDoubleSpinBox" name="mToleranceSpinBox">
<property name="decimals">
<number>6</number>
</property>
@@ -64,7 +70,14 @@
</widget>
</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>
</layout>
</widget>
@@ -91,6 +104,12 @@
</item>
<item>
<widget class="QgsSpinBox" name="mIterationsSpin">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<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>
</property>
@@ -114,6 +133,12 @@
</item>
<item>
<widget class="QgsSpinBox" name="mOffsetSpin">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<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>
</property>
@@ -129,16 +154,29 @@
</widget>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="mMethodComboBox"/>
</item>
<item row="0" column="3">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</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>
</widget>
<customwidgets>

0 comments on commit a6eb520

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