Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] Add a dedicated pan tool for navigating models
Fixes #40714
- Loading branch information
1 parent
f3413ac
commit ac43030
Showing
6 changed files
with
199 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/*************************************************************************** | ||
qgsmodelviewtoolpan.cpp | ||
------------------------------------ | ||
Date : March 2020 | ||
Copyright : (C) 2020 Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsmodelviewtoolpan.h" | ||
#include "qgsmodelviewmouseevent.h" | ||
#include "qgsmodelgraphicsview.h" | ||
#include <QScrollBar> | ||
|
||
QgsModelViewToolPan::QgsModelViewToolPan( QgsModelGraphicsView *view ) | ||
: QgsModelViewTool( view, tr( "Pan" ) ) | ||
{ | ||
setCursor( Qt::OpenHandCursor ); | ||
} | ||
|
||
void QgsModelViewToolPan::modelPressEvent( QgsModelViewMouseEvent *event ) | ||
{ | ||
mMousePressStartPos = event->pos(); | ||
|
||
if ( event->button() != Qt::LeftButton ) | ||
{ | ||
event->ignore(); | ||
return; | ||
} | ||
|
||
mIsPanning = true; | ||
mLastMousePos = event->pos(); | ||
view()->setCursor( Qt::ClosedHandCursor ); | ||
} | ||
|
||
void QgsModelViewToolPan::modelMoveEvent( QgsModelViewMouseEvent *event ) | ||
{ | ||
if ( !mIsPanning ) | ||
{ | ||
event->ignore(); | ||
return; | ||
} | ||
|
||
view()->horizontalScrollBar()->setValue( view()->horizontalScrollBar()->value() - ( event->x() - mLastMousePos.x() ) ); | ||
view()->verticalScrollBar()->setValue( view()->verticalScrollBar()->value() - ( event->y() - mLastMousePos.y() ) ); | ||
mLastMousePos = event->pos(); | ||
} | ||
|
||
void QgsModelViewToolPan::modelReleaseEvent( QgsModelViewMouseEvent *event ) | ||
{ | ||
bool clickOnly = !isClickAndDrag( mMousePressStartPos, event->pos() ); | ||
|
||
if ( event->button() == Qt::MiddleButton && clickOnly ) | ||
{ | ||
//middle mouse button click = recenter on point | ||
|
||
//get current visible part of scene | ||
QRect viewportRect( 0, 0, view()->viewport()->width(), view()->viewport()->height() ); | ||
QgsRectangle visibleRect = QgsRectangle( view()->mapToScene( viewportRect ).boundingRect() ); | ||
QPointF scenePoint = event->modelPoint(); | ||
visibleRect.scale( 1, scenePoint.x(), scenePoint.y() ); | ||
QRectF boundsRect = visibleRect.toRectF(); | ||
|
||
//zoom view to fit desired bounds | ||
view()->fitInView( boundsRect, Qt::KeepAspectRatio ); | ||
return; | ||
} | ||
|
||
if ( !mIsPanning || event->button() != Qt::LeftButton ) | ||
{ | ||
event->ignore(); | ||
return; | ||
} | ||
|
||
mIsPanning = false; | ||
view()->setCursor( Qt::OpenHandCursor ); | ||
} | ||
|
||
void QgsModelViewToolPan::deactivate() | ||
{ | ||
mIsPanning = false; | ||
QgsModelViewTool::deactivate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*************************************************************************** | ||
qgsmodelviewtoolpan.h | ||
---------------------------------- | ||
Date : December 2020 | ||
Copyright : (C) 2020 Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSMODELVIEWTOOLPAN_H | ||
#define QGSMODELVIEWTOOLPAN_H | ||
|
||
#include "qgis_sip.h" | ||
#include "qgis_gui.h" | ||
#include "qgsmodelviewtool.h" | ||
|
||
#define SIP_NO_FILE | ||
|
||
/** | ||
* \ingroup gui | ||
* Model designer view tool for panning a model. | ||
* \since QGIS 3.18 | ||
*/ | ||
class GUI_EXPORT QgsModelViewToolPan : public QgsModelViewTool | ||
{ | ||
|
||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsModelViewToolPan. | ||
*/ | ||
QgsModelViewToolPan( QgsModelGraphicsView *view SIP_TRANSFERTHIS ); | ||
|
||
void modelPressEvent( QgsModelViewMouseEvent *event ) override; | ||
void modelMoveEvent( QgsModelViewMouseEvent *event ) override; | ||
void modelReleaseEvent( QgsModelViewMouseEvent *event ) override; | ||
void deactivate() override; | ||
|
||
private: | ||
|
||
bool mIsPanning = false; | ||
QPoint mLastMousePos; | ||
//! Start position for mouse press | ||
QPoint mMousePressStartPos; | ||
|
||
}; | ||
#endif // QGSMODELVIEWTOOLPAN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters