Skip to content
Permalink
Browse files

Merge pull request #35806 from uclaros/snapping-fixes

Snapping type menu fixes
  • Loading branch information
m-kuhn committed May 24, 2020
2 parents 0ddb530 + 85d0956 commit b09cdc43a46eab55cc393eb0ffabdccfa7a14b52
Showing with 42 additions and 2 deletions.
  1. +25 −1 src/app/qgssnappinglayertreemodel.cpp
  2. +17 −1 src/app/qgssnappingwidget.cpp
@@ -29,6 +29,30 @@
#include "qgsapplication.h"
#include "qgsscalewidget.h"

class SnapTypeMenu: public QMenu
{
public:
SnapTypeMenu( const QString &title, QWidget *parent = nullptr )
: QMenu( title, parent ) {}

void mouseReleaseEvent( QMouseEvent *e )
{
QAction *action = activeAction();
if ( action )
action->trigger();
else
QMenu::mouseReleaseEvent( e );
}

// set focus to parent so that mTypeButton is not displayed
void hideEvent( QHideEvent *e )
{
qobject_cast<QWidget *>( parent() )->setFocus();
QMenu::hideEvent( e );
}
};


QgsSnappingLayerDelegate::QgsSnappingLayerDelegate( QgsMapCanvas *canvas, QObject *parent )
: QItemDelegate( parent )
, mCanvas( canvas )
@@ -46,7 +70,7 @@ QWidget *QgsSnappingLayerDelegate::createEditor( QWidget *parent, const QStyleOp
QToolButton *mTypeButton = new QToolButton( parent );
mTypeButton->setToolTip( tr( "Snapping Type" ) );
mTypeButton->setPopupMode( QToolButton::InstantPopup );
QMenu *typeMenu = new QMenu( tr( "Set Snapping Mode" ), parent );
SnapTypeMenu *typeMenu = new SnapTypeMenu( tr( "Set Snapping Mode" ), parent );
QAction *mVertexAction = new QAction( QIcon( QgsApplication::getThemeIcon( "/mIconSnappingVertex.svg" ) ), tr( "Vertex" ), typeMenu );
QAction *mSegmentAction = new QAction( QIcon( QgsApplication::getThemeIcon( "/mIconSnappingSegment.svg" ) ), tr( "Segment" ), typeMenu );
QAction *mAreaAction = new QAction( QIcon( QgsApplication::getThemeIcon( "/mIconSnappingArea.svg" ) ), tr( "Area" ), typeMenu );
@@ -44,6 +44,22 @@
#include "qgsscalewidget.h"


class SnapTypeMenu: public QMenu
{
public:
SnapTypeMenu( const QString &title, QWidget *parent = nullptr )
: QMenu( title, parent ) {}

void mouseReleaseEvent( QMouseEvent *e )
{
QAction *action = activeAction();
if ( action )
action->trigger();
else
QMenu::mouseReleaseEvent( e );
}
};

QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas, QWidget *parent )
: QWidget( parent )
, mProject( project )
@@ -162,7 +178,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
mTypeButton = new QToolButton();
mTypeButton->setToolTip( tr( "Snapping Type" ) );
mTypeButton->setPopupMode( QToolButton::InstantPopup );
QMenu *typeMenu = new QMenu( tr( "Set Snapping Mode" ), this );
SnapTypeMenu *typeMenu = new SnapTypeMenu( tr( "Set Snapping Mode" ), this );
mVertexAction = new QAction( QIcon( QgsApplication::getThemeIcon( "/mIconSnappingVertex.svg" ) ), tr( "Vertex" ), typeMenu );
mSegmentAction = new QAction( QIcon( QgsApplication::getThemeIcon( "/mIconSnappingSegment.svg" ) ), tr( "Segment" ), typeMenu );
mAreaAction = new QAction( QIcon( QgsApplication::getThemeIcon( "/mIconSnappingArea.svg" ) ), tr( "Area" ), typeMenu );

0 comments on commit b09cdc4

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