Skip to content

Commit

Permalink
Merge pull request #8480 from lbartoletti/rectangle3PointsProjected
Browse files Browse the repository at this point in the history
[FEATURE][needs-docs]Add map tool: rectangle 3 points (projected)
  • Loading branch information
3nids authored Nov 19, 2018
2 parents 29875d3 + 2c12146 commit b089b57
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 76 deletions.
3 changes: 2 additions & 1 deletion images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,8 @@
<file>themes/default/mActionEllipseCenterPoint.svg</file>
<file>themes/default/mActionEllipseExtent.svg</file>
<file>themes/default/mActionRectangleExtent.svg</file>
<file>themes/default/mActionRectangle3Points.svg</file>
<file>themes/default/mActionRectangle3PointsDistance.svg</file>
<file>themes/default/mActionRectangle3PointsProjected.svg</file>
<file>themes/default/mActionRectangleCenter.svg</file>
<file>themes/default/mActionRegularPolygonCenterCorner.svg</file>
<file>themes/default/mActionRegularPolygon2Points.svg</file>
Expand Down
122 changes: 122 additions & 0 deletions images/themes/default/mActionRectangle3PointsProjected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 21 additions & 14 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/***************************************************************************
qgisapp.cpp - description
-------------------
qgisapp.cpp - description
-------------------

begin : Sat Jun 22 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
Romans 3:23=>Romans 6:23=>Romans 10:9,10=>Romans 12
***************************************************************************/
begin : Sat Jun 22 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
Romans 3:23=>Romans 6:23=>Romans 10:9,10=>Romans 12
***************************************************************************/

/***************************************************************************
* *
Expand Down Expand Up @@ -1531,7 +1531,8 @@ QgisApp::~QgisApp()
delete mMapTools.mEllipseFoci;
delete mMapTools.mRectangleCenterPoint;
delete mMapTools.mRectangleExtent;
delete mMapTools.mRectangle3Points;
delete mMapTools.mRectangle3PointsDistance;
delete mMapTools.mRectangle3PointsProjected;
delete mMapTools.mRegularPolygon2Points;
delete mMapTools.mRegularPolygonCenterPoint;
delete mMapTools.mRegularPolygonCenterCorner;
Expand Down Expand Up @@ -2091,7 +2092,8 @@ void QgisApp::createActions()
connect( mActionEllipseFoci, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mEllipseFoci, true ); } );
connect( mActionRectangleCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangleCenterPoint, true ); } );
connect( mActionRectangleExtent, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangleExtent, true ); } );
connect( mActionRectangle3Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangle3Points, true ); } );
connect( mActionRectangle3PointsDistance, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangle3PointsDistance, true ); } );
connect( mActionRectangle3PointsProjected, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangle3PointsProjected, true ); } );
connect( mActionRegularPolygon2Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygon2Points, true ); } );
connect( mActionRegularPolygonCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygonCenterPoint, true ); } );
connect( mActionRegularPolygonCenterCorner, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygonCenterCorner, true ); } );
Expand Down Expand Up @@ -2376,7 +2378,8 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionEllipseFoci );
mMapToolGroup->addAction( mActionRectangleCenterPoint );
mMapToolGroup->addAction( mActionRectangleExtent );
mMapToolGroup->addAction( mActionRectangle3Points );
mMapToolGroup->addAction( mActionRectangle3PointsDistance );
mMapToolGroup->addAction( mActionRectangle3PointsProjected );
mMapToolGroup->addAction( mActionRegularPolygon2Points );
mMapToolGroup->addAction( mActionRegularPolygonCenterPoint );
mMapToolGroup->addAction( mActionRegularPolygonCenterCorner );
Expand Down Expand Up @@ -2935,7 +2938,8 @@ void QgisApp::createToolBars()
tbAddRectangle->setPopupMode( QToolButton::MenuButtonPopup );
tbAddRectangle->addAction( mActionRectangleCenterPoint );
tbAddRectangle->addAction( mActionRectangleExtent );
tbAddRectangle->addAction( mActionRectangle3Points );
tbAddRectangle->addAction( mActionRectangle3PointsDistance );
tbAddRectangle->addAction( mActionRectangle3PointsProjected );
tbAddRectangle->setDefaultAction( mActionRectangleCenterPoint );
connect( tbAddRectangle, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );
mShapeDigitizeToolBar->insertWidget( mActionVertexTool, tbAddRectangle );
Expand Down Expand Up @@ -3576,8 +3580,10 @@ void QgisApp::createCanvasTools()
mMapTools.mRectangleCenterPoint->setAction( mActionRectangleCenterPoint );
mMapTools.mRectangleExtent = new QgsMapToolRectangleExtent( mMapTools.mAddFeature, mMapCanvas );
mMapTools.mRectangleExtent->setAction( mActionRectangleExtent );
mMapTools.mRectangle3Points = new QgsMapToolRectangle3Points( mMapTools.mAddFeature, mMapCanvas );
mMapTools.mRectangle3Points->setAction( mActionRectangle3Points );
mMapTools.mRectangle3PointsDistance = new QgsMapToolRectangle3Points( mMapTools.mAddFeature, mMapCanvas, QgsMapToolRectangle3Points::DistanceMode );
mMapTools.mRectangle3PointsDistance->setAction( mActionRectangle3PointsDistance );
mMapTools.mRectangle3PointsProjected = new QgsMapToolRectangle3Points( mMapTools.mAddFeature, mMapCanvas, QgsMapToolRectangle3Points::ProjectedMode );
mMapTools.mRectangle3PointsProjected->setAction( mActionRectangle3PointsProjected );
mMapTools.mRegularPolygon2Points = new QgsMapToolRegularPolygon2Points( mMapTools.mAddFeature, mMapCanvas );
mMapTools.mRegularPolygon2Points->setAction( mActionRegularPolygon2Points );
mMapTools.mRegularPolygonCenterPoint = new QgsMapToolRegularPolygonCenterPoint( mMapTools.mAddFeature, mMapCanvas );
Expand Down Expand Up @@ -12543,7 +12549,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionEllipseFoci->setEnabled( enableShapeTools );
mActionRectangleCenterPoint->setEnabled( enableShapeTools );
mActionRectangleExtent->setEnabled( enableShapeTools );
mActionRectangle3Points->setEnabled( enableShapeTools );
mActionRectangle3PointsDistance->setEnabled( enableShapeTools );
mActionRectangle3PointsProjected->setEnabled( enableShapeTools );
mActionRegularPolygon2Points->setEnabled( enableShapeTools );
mActionRegularPolygonCenterPoint->setEnabled( enableShapeTools );
mActionRegularPolygonCenterCorner->setEnabled( enableShapeTools );
Expand Down
15 changes: 8 additions & 7 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/***************************************************************************
qgisapp.h - description
-------------------
begin : Sat Jun 22 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
qgisapp.h - description
-------------------
begin : Sat Jun 22 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/

/***************************************************************************
* *
Expand Down Expand Up @@ -2044,7 +2044,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool *mEllipseFoci = nullptr;
QgsMapTool *mRectangleCenterPoint = nullptr;
QgsMapTool *mRectangleExtent = nullptr;
QgsMapTool *mRectangle3Points = nullptr;
QgsMapTool *mRectangle3PointsDistance = nullptr;
QgsMapTool *mRectangle3PointsProjected = nullptr;
QgsMapTool *mRegularPolygon2Points = nullptr;
QgsMapTool *mRegularPolygonCenterPoint = nullptr;
QgsMapTool *mRegularPolygonCenterCorner = nullptr;
Expand Down
43 changes: 26 additions & 17 deletions src/app/qgsmaptoolrectangle3points.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/***************************************************************************
qgsmaptoolrectangle3points.cpp - map tool for adding rectangle
from 3 points
---------------------
begin : September 2017
copyright : (C) 2017 by Loïc Bartoletti
email : lbartoletti at tuxfamily dot org
***************************************************************************
* *
* 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 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
qgsmaptoolrectangle3points.cpp - map tool for adding rectangle
from 3 points
---------------------
begin : September 2017
copyright : (C) 2017 by Loïc Bartoletti
email : lbartoletti at tuxfamily dot org
***************************************************************************
* *
* 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 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmaptoolrectangle3points.h"
#include "qgsgeometryrubberband.h"
Expand All @@ -25,8 +25,9 @@
#include "qgssnapindicator.h"

QgsMapToolRectangle3Points::QgsMapToolRectangle3Points( QgsMapToolCapture *parentTool,
QgsMapCanvas *canvas, CaptureMode mode )
: QgsMapToolAddRectangle( parentTool, canvas, mode )
QgsMapCanvas *canvas, CreateMode createMode, CaptureMode mode )
: QgsMapToolAddRectangle( parentTool, canvas, mode ),
mCreateMode( createMode )
{
}

Expand Down Expand Up @@ -77,7 +78,15 @@ void QgsMapToolRectangle3Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )
break;
case 2:
{
setDistance2( mPoints.at( 1 ).distance( point ) );
switch ( mCreateMode )
{
case DistanceMode:
setDistance2( mPoints.at( 1 ).distance( point ) );
break;
case ProjectedMode:
setDistance2( QgsGeometryUtils::perpendicularSegment( point, mPoints.at( 0 ), mPoints.at( 1 ) ).length() );
break;
}
int side = QgsGeometryUtils::leftOfLine( point.x(), point.y(),
mPoints.at( 0 ).x(), mPoints.at( 0 ).y(),
mPoints.at( 1 ).x(), mPoints.at( 1 ).y() );
Expand Down
38 changes: 23 additions & 15 deletions src/app/qgsmaptoolrectangle3points.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/***************************************************************************
qgsmaptoolrectangle3points.h - map tool for adding rectangle
from 3 points
---------------------
begin : September 2017
copyright : (C) 2017 by Loïc Bartoletti
email : lbartoletti at tuxfamily dot org
***************************************************************************
* *
* 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 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
qgsmaptoolrectangle3points.h - map tool for adding rectangle
from 3 points
---------------------
begin : September 2017
copyright : (C) 2017 by Loïc Bartoletti
email : lbartoletti at tuxfamily dot org
***************************************************************************
* *
* 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 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSMAPTOOLRECTANGLE3POINTS_H
#define QGSMAPTOOLRECTANGLE3POINTS_H
Expand All @@ -25,11 +25,19 @@ class APP_EXPORT QgsMapToolRectangle3Points: public QgsMapToolAddRectangle
Q_OBJECT

public:
QgsMapToolRectangle3Points( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine );
enum CreateMode
{
DistanceMode,
ProjectedMode,
};
QgsMapToolRectangle3Points( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CreateMode createMode, CaptureMode mode = CaptureLine );

void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;

private:
CreateMode mCreateMode;

};

#endif // QGSMAPTOOLRECTANGLE3POINTS_H
Loading

0 comments on commit b089b57

Please sign in to comment.