Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
backport #52259
  • Loading branch information
vcloarec committed Apr 28, 2023
1 parent 6d85fd9 commit 77e6135
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
Expand Up @@ -356,9 +356,16 @@ Adds point to the CAD point list

void removePreviousPoint();
%Docstring
Remove previous point in the CAD point list
Removes previous point in the CAD point list

.. versionadded:: 3.8
%End

void updateCurrentPoint( const QgsPoint &point );
%Docstring
Updates the current ``point`` in the CAD point list

.. versionadded:: 3.30.2
%End

void setPoints( const QList<QgsPointXY> &points );
Expand Down
55 changes: 49 additions & 6 deletions src/app/mesh/qgsmaptooleditmeshframe.cpp
Expand Up @@ -925,6 +925,7 @@ void QgsMapToolEditMeshFrame::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
mCurrentEdge.first != -1 && mCurrentEdge.second != -1 ) // flip edge
{
clearSelection();
mCadDockWidget->clearPoints();
const QVector<int> edgeVert = edgeVertices( mCurrentEdge );
mCurrentEditor->flipEdge( edgeVert.at( 0 ), edgeVert.at( 1 ) );
mCurrentEdge = {-1, -1};
Expand All @@ -935,13 +936,17 @@ void QgsMapToolEditMeshFrame::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
mCurrentEdge.first != -1 && mCurrentEdge.second != -1 ) // merge two faces
{
clearSelection();
mCadDockWidget->clearPoints();
const QVector<int> edgeVert = edgeVertices( mCurrentEdge );
mCurrentEditor->merge( edgeVert.at( 0 ), edgeVert.at( 1 ) );
mCurrentEdge = {-1, -1};
highLight( mapPoint );
}
else
{
select( mapPoint, e->modifiers(), tolerance );
mCadDockWidget->clearPoints();
}
}
break;
case AddingNewFace:
Expand All @@ -951,8 +956,12 @@ void QgsMapToolEditMeshFrame::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
if ( mCurrentVertexIndex != -1 )
{
addVertexToFaceCanditate( mCurrentVertexIndex );
const QgsPointXY currentPoint = mapVertexXY( mCurrentVertexIndex );
cadDockWidget()->setPoints( QList<QgsPointXY>() << currentPoint << currentPoint );
// Advanced digitizing base class adds a point at map point not at vertex position
// so we need to replace it by the position of the vertex
const QgsPoint &currentPoint = mapVertex( mCurrentVertexIndex );
cadDockWidget()->updateCurrentPoint( currentPoint );
cadDockWidget()->removePreviousPoint();
cadDockWidget()->addPoint( currentPoint );
}
else
{
Expand All @@ -967,8 +976,6 @@ void QgsMapToolEditMeshFrame::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
if ( acceptPoint )
{
addVertexToFaceCanditate( mapPoint );
const QgsPointXY currentPoint( mapPoint );
cadDockWidget()->setPoints( QList<QgsPointXY>() << currentPoint << currentPoint );
}
}
}
Expand All @@ -989,6 +996,7 @@ void QgsMapToolEditMeshFrame::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
const QgsGeometry selectionGeom = mSelectionBand->asGeometry();
selectByGeometry( selectionGeom, e->modifiers() );
mSelectionBand->reset( QgsWkbTypes::PolygonGeometry );
mCadDockWidget->clearPoints();
mCurrentState = Digitizing;
}
break;
Expand Down Expand Up @@ -1229,6 +1237,8 @@ void QgsMapToolEditMeshFrame::keyPressEvent( QKeyEvent *e )
if ( mNewFaceCandidate.isEmpty() )
mCurrentState = Digitizing;

mCadDockWidget->removePreviousPoint();

consumned = true;
}

Expand Down Expand Up @@ -1275,6 +1285,9 @@ void QgsMapToolEditMeshFrame::keyPressEvent( QKeyEvent *e )
break;
}

if ( e->key() == Qt::Key_Escape )
mCadDockWidget->clearPoints();

if ( !consumned && mZValueWidget )
QgsApplication::sendEvent( mZValueWidget->keyboardEntryWidget(), e );
else
Expand Down Expand Up @@ -1443,6 +1456,7 @@ void QgsMapToolEditMeshFrame::setCurrentLayer( QgsMapLayer *layer )
{
disconnect( mCurrentLayer, &QgsMeshLayer::editingStarted, this, &QgsMapToolEditMeshFrame::onEditingStarted );
disconnect( mCurrentLayer, &QgsMeshLayer::editingStopped, this, &QgsMapToolEditMeshFrame::onEditingStopped );
disconnect( mCurrentLayer->undoStack(), &QUndoStack::indexChanged, this, &QgsMapToolEditMeshFrame::onUndoRedo );
}

mCurrentLayer = meshLayer;
Expand All @@ -1459,6 +1473,7 @@ void QgsMapToolEditMeshFrame::setCurrentLayer( QgsMapLayer *layer )
{
connect( mCurrentLayer, &QgsMeshLayer::editingStarted, this, &QgsMapToolEditMeshFrame::onEditingStarted );
connect( mCurrentLayer, &QgsMeshLayer::editingStopped, this, &QgsMapToolEditMeshFrame::onEditingStopped );
connect( mCurrentLayer->undoStack(), &QUndoStack::indexChanged, this, &QgsMapToolEditMeshFrame::onUndoRedo );

if ( mCurrentLayer->isEditable() )
{
Expand Down Expand Up @@ -1629,7 +1644,7 @@ bool QgsMapToolEditMeshFrame::isFaceSelected( int faceIndex )
return true;
}

void QgsMapToolEditMeshFrame::setSelectedVertices( const QList<int> newSelectedVertices, Qgis::SelectBehavior behavior )
void QgsMapToolEditMeshFrame::setSelectedVertices( const QList<int> &newSelectedVertices, Qgis::SelectBehavior behavior )
{
if ( mSelectedVertices.isEmpty() )
{
Expand Down Expand Up @@ -1665,7 +1680,7 @@ void QgsMapToolEditMeshFrame::setSelectedVertices( const QList<int> newSelectedV
prepareSelection();
}

void QgsMapToolEditMeshFrame::setSelectedFaces( const QList<int> newSelectedFaces, Qgis::SelectBehavior behavior )
void QgsMapToolEditMeshFrame::setSelectedFaces( const QList<int> &newSelectedFaces, Qgis::SelectBehavior behavior )
{
bool removeFaces = false;

Expand Down Expand Up @@ -1931,6 +1946,34 @@ void QgsMapToolEditMeshFrame::reindexMesh()
mCurrentLayer->reindex( transform, true );
}

void QgsMapToolEditMeshFrame::onUndoRedo()
{
switch ( mCurrentState )
{
case Digitizing:
break;
case AddingNewFace:
mNewFaceBand->reset( Qgis::GeometryType::Polygon );
mNewFaceCandidate.clear();
mNewVerticesForNewFaceCandidate.clear();
mCurrentState = Digitizing;
mCadDockWidget->clearPoints();
break;
case MovingSelection:
mCurrentState = Digitizing;
mMovingEdgesRubberband->reset( Qgis::GeometryType::Line );
mMovingFacesRubberband->reset( Qgis::GeometryType::Polygon );
mMovingFreeVertexRubberband->reset( Qgis::GeometryType::Point );
mCadDockWidget->setEnabledZ( mCadDockWidget->cadEnabled() );
mCadDockWidget->clearPoints();
break;
case ForceByLines:
case Selecting:
case SelectingByPolygon:
break;
}
}

void QgsMapToolEditMeshFrame::selectByGeometry( const QgsGeometry &geometry, Qt::KeyboardModifiers modifiers )
{
if ( mCurrentLayer.isNull() || !mCurrentLayer->triangularMesh() || mCurrentEditor.isNull() )
Expand Down
5 changes: 3 additions & 2 deletions src/app/mesh/qgsmaptooleditmeshframe.h
Expand Up @@ -165,6 +165,7 @@ class APP_EXPORT QgsMapToolEditMeshFrame : public QgsMapToolAdvancedDigitizing
void selectByExpression( const QString &textExpression, Qgis::SelectBehavior behavior, QgsMesh::ElementType elementType );
void onZoomToSelected();
void reindexMesh();
void onUndoRedo();

private:

Expand Down Expand Up @@ -228,8 +229,8 @@ class APP_EXPORT QgsMapToolEditMeshFrame : public QgsMapToolAdvancedDigitizing
void addNewSelectedVertex( int vertexIndex );
void removeFromSelection( int vertexIndex );
bool isFaceSelected( int faceIndex );
void setSelectedVertices( const QList<int> newSelectedVertices, Qgis::SelectBehavior behavior );
void setSelectedFaces( const QList<int> newSelectedFaces, Qgis::SelectBehavior behavior );
void setSelectedVertices( const QList<int> &newSelectedVertices, Qgis::SelectBehavior behavior );
void setSelectedFaces( const QList<int> &newSelectedFaces, Qgis::SelectBehavior behavior );
void selectByGeometry( const QgsGeometry &geometry, Qt::KeyboardModifiers modifiers );
void selectTouchedByGeometry( const QgsGeometry &geometry, Qgis::SelectBehavior behavior );
void selectContainedByGeometry( const QgsGeometry &geometry, Qgis::SelectBehavior behavior );
Expand Down
1 change: 0 additions & 1 deletion src/gui/qgsadvanceddigitizingdockwidget.cpp
Expand Up @@ -1750,7 +1750,6 @@ void QgsAdvancedDigitizingDockWidget::updateCurrentPoint( const QgsPoint &point
updateCadPaintItem();
}


void QgsAdvancedDigitizingDockWidget::CadConstraint::setLockMode( LockMode mode )
{
mLockMode = mode;
Expand Down
12 changes: 7 additions & 5 deletions src/gui/qgsadvanceddigitizingdockwidget.h
Expand Up @@ -356,11 +356,17 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
void addPoint( const QgsPointXY &point );

/**
* Remove previous point in the CAD point list
* Removes previous point in the CAD point list
* \since QGIS 3.8
*/
void removePreviousPoint();

/**
* Updates the current \a point in the CAD point list
* \since QGIS 3.30.2
*/
void updateCurrentPoint( const QgsPoint &point );

/**
* Configures list of current CAD points
*
Expand Down Expand Up @@ -927,10 +933,6 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
*/
QList<QgsPointXY> snapSegmentToAllLayers( const QgsPointXY &originalMapPoint, bool *snapped = nullptr ) const;

//! update the current point in the CAD point list
void updateCurrentPoint( const QgsPoint &point );


/**
* filters key press
* \note called by eventFilter (filter on line edits), canvasKeyPressEvent (filter on map tool) and keyPressEvent (filter on dock)
Expand Down

0 comments on commit 77e6135

Please sign in to comment.