Skip to content

Commit

Permalink
Improve visibility of tangents tool on cadCanvasMoveEvent (compatible
Browse files Browse the repository at this point in the history
when CADDockWidget is enabled)
  • Loading branch information
lbartoletti committed Oct 9, 2017
1 parent 81e0c1b commit 34433ae
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 20 deletions.
36 changes: 30 additions & 6 deletions src/app/qgsmaptoolcircle2tangentspoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ void QgsMapToolCircle2TangentsPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e
{

QgsPoint mapPoint( e->mapPoint() );
EdgesOnlyFilter filter;
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );

QgsPointXY p1, p2;

if ( e->button() == Qt::LeftButton )
{
if ( mPoints.size() < 2 * 2 )
{
EdgesOnlyFilter filter;
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );
if ( match.isValid() )
{
match.edgePoints( p1, p2 );
Expand All @@ -69,8 +69,8 @@ void QgsMapToolCircle2TangentsPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e
QgsMessageBar::CRITICAL, QgisApp::instance()->messageTimeout() );
deactivate();
}

createRadiusSpinBox();
else
createRadiusSpinBox();
}
}
else if ( e->button() == Qt::RightButton )
Expand Down Expand Up @@ -98,14 +98,38 @@ void QgsMapToolCircle2TangentsPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e
void QgsMapToolCircle2TangentsPoint::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint( e->mapPoint() );
if ( mPoints.size() == 4 )
EdgesOnlyFilter filter;
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );

if ( mPoints.size() < 2 * 2 )
{
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( ( mode() == CapturePolygon ) ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand->setFillColor( QColor( 0, 0, 255 ) );
mTempRubberBand->setStrokeColor( QColor( 0, 0, 255 ) );
mTempRubberBand->setStrokeWidth( 2 );
mTempRubberBand->show();
}
else
mTempRubberBand->hide();

if ( match.isValid() )
{
QgsPointXY p1, p2;
match.edgePoints( p1, p2 );
std::unique_ptr<QgsLineString> line( new QgsLineString() );

line->addVertex( QgsPoint( p1 ) );
line->addVertex( QgsPoint( p2 ) );

mTempRubberBand->setGeometry( line.release() );
mTempRubberBand->show();
}
}

if ( mPoints.size() == 4 )
{
QgsPoint center = QgsPoint( mCenters.at( 0 ) );
const double currentDist = mapPoint.distanceSquared( center );
for ( int i = 1; i < mCenters.size(); ++i )
Expand Down Expand Up @@ -248,7 +272,7 @@ void QgsMapToolCircle2TangentsPoint::radiusSpinBoxChanged( int radius )

qDeleteAll( mRubberBands );
mRubberBands.clear();
if ( mTempRubberBand )
if ( mPoints.size() == 4 )
{
std::unique_ptr<QgsMultiPolygonV2> rb( new QgsMultiPolygonV2() );
for ( int i = 0; i < mCenters.size(); ++i )
Expand Down
46 changes: 32 additions & 14 deletions src/app/qgsmaptoolcircle3tangents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,6 @@ void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
mPoints.append( QgsPoint( p1 ) );
mPoints.append( QgsPoint( p2 ) );
}
if ( !mPoints.isEmpty() )
{
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( ( mode() == CapturePolygon ) ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand->show();
}
std::unique_ptr<QgsLineString> line( new QgsLineString() );

line->addVertex( QgsPoint( p1 ) );
line->addVertex( QgsPoint( p2 ) );

mTempRubberBand->setGeometry( line.release() );
}
}
else if ( e->button() == Qt::RightButton )
{
Expand All @@ -84,3 +70,35 @@ void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
}
}
}

void QgsMapToolCircle3Tangents::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint( e->mapPoint() );
EdgesOnlyFilter filter;
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );

if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( ( mode() == CapturePolygon ) ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand->setFillColor( QColor( 0, 0, 255 ) );
mTempRubberBand->setStrokeColor( QColor( 0, 0, 255 ) );
mTempRubberBand->setStrokeWidth( 2 );
mTempRubberBand->show();
}
else
mTempRubberBand->hide();

if ( match.isValid() )
{
QgsPointXY p1, p2;
match.edgePoints( p1, p2 );
std::unique_ptr<QgsLineString> line( new QgsLineString() );

line->addVertex( QgsPoint( p1 ) );
line->addVertex( QgsPoint( p2 ) );

mTempRubberBand->setGeometry( line.release() );
mTempRubberBand->show();
}

}
1 change: 1 addition & 0 deletions src/app/qgsmaptoolcircle3tangents.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class QgsMapToolCircle3Tangents: public QgsMapToolAddCircle
QgsMapToolCircle3Tangents( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine );

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

#endif // QGSMAPTOOLCIRCLE3TANGENTS_H

0 comments on commit 34433ae

Please sign in to comment.