Skip to content
Permalink
Browse files

Small code cleanup to warm up

  • Loading branch information
wonder-sk authored and nirvn committed Jan 31, 2019
1 parent 0d178aa commit f445c26f995e22aef313695d49e29d2142cda25d
@@ -294,10 +294,7 @@ bool QgsVertexEditorModel::calcR( int row, double &r, double &minRadius ) const
}


QgsVertexEditor::QgsVertexEditor(
QgsVectorLayer *layer,
QgsSelectedFeature *selectedFeature,
QgsMapCanvas *canvas )
QgsVertexEditor::QgsVertexEditor( QgsMapCanvas *canvas )
: mCanvas( canvas )
{
setWindowTitle( tr( "Vertex Editor" ) );
@@ -328,25 +325,22 @@ QgsVertexEditor::QgsVertexEditor(
layout->addWidget( mHintLabel );

setWidget( content );

updateEditor( layer, selectedFeature );
}

void QgsVertexEditor::updateEditor( QgsVectorLayer *layer, QgsSelectedFeature *selectedFeature )
void QgsVertexEditor::updateEditor( QgsSelectedFeature *selectedFeature )
{
if ( mSelectedFeature )
{
delete mVertexModel;
mVertexModel = nullptr;
}

mLayer = layer;
mSelectedFeature = selectedFeature;

if ( mLayer && mSelectedFeature )
if ( mSelectedFeature )
{
// TODO We really should just update the model itself.
mVertexModel = new QgsVertexEditorModel( mLayer, mSelectedFeature, mCanvas, this );
mVertexModel = new QgsVertexEditorModel( mSelectedFeature->layer(), mSelectedFeature, mCanvas, this );
mTableView->setModel( mVertexModel );

mHintLabel->setVisible( false );
@@ -398,7 +392,7 @@ void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, con

mSelectedFeature->deselectAllVertices();

QgsCoordinateTransform t( mLayer->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() );
QgsCoordinateTransform t( mSelectedFeature->layer()->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() );
std::unique_ptr<QgsRectangle> bbox;
QModelIndexList indexList = selected.indexes();
for ( int i = 0; i < indexList.length(); ++i )
@@ -72,13 +72,10 @@ class QgsVertexEditor : public QgsDockWidget
{
Q_OBJECT
public:
QgsVertexEditor( QgsVectorLayer *layer,
QgsSelectedFeature *selectedFeature,
QgsMapCanvas *canvas );
QgsVertexEditor( QgsMapCanvas *canvas );

public:
void updateEditor( QgsVectorLayer *layer, QgsSelectedFeature *selectedFeature );
QgsVectorLayer *mLayer = nullptr;
void updateEditor( QgsSelectedFeature *selectedFeature );
QgsSelectedFeature *mSelectedFeature = nullptr;
QgsMapCanvas *mCanvas = nullptr;
QTableView *mTableView = nullptr;
@@ -462,9 +462,10 @@ void QgsVertexTool::cadCanvasPressEvent( QgsMapMouseEvent *e )
{
if ( !mSelectionRect && !mDraggingVertex && !mDraggingEdge )
{
if ( mLastMouseMoveMatch.isValid() && mLastMouseMoveMatch.layer() )
QgsPointLocator::Match m = snapToEditableLayer( e );
if ( m.isValid() && m.layer() )
{
showVertexEditor(); //#spellok
updateVertexEditor( m.layer(), m.featureId() );
}
}
}
@@ -847,8 +848,6 @@ void QgsVertexTool::mouseMoveNotDragging( QgsMapMouseEvent *e )
QgsPointLocator::Match m = snapToEditableLayer( e );
bool targetIsAllowed = ( !mSelectedFeature || ( mSelectedFeature->featureId() == m.featureId() && mSelectedFeature->layer() == m.layer() ) );

mLastMouseMoveMatch = m;

// possibility to move a vertex
if ( m.type() == QgsPointLocator::Vertex && targetIsAllowed )
{
@@ -1074,7 +1073,7 @@ void QgsVertexTool::onCachedGeometryChanged( QgsFeatureId fid, const QgsGeometry
validateGeometry( layer, fid );

if ( mVertexEditor && mSelectedFeature && mSelectedFeature->featureId() == fid && mSelectedFeature->layer() == layer )
mVertexEditor->updateEditor( mSelectedFeature->layer(), mSelectedFeature.get() );
mVertexEditor->updateEditor( mSelectedFeature.get() );
}

void QgsVertexTool::onCachedGeometryDeleted( QgsFeatureId fid )
@@ -1089,35 +1088,43 @@ void QgsVertexTool::onCachedGeometryDeleted( QgsFeatureId fid )
setHighlightedVertices( mSelectedVertices );
}


void QgsVertexTool::showVertexEditor() //#spellok
void QgsVertexTool::updateVertexEditor( QgsVectorLayer *layer, QgsFeatureId fid )
{
QgsPointLocator::Match m = mLastMouseMoveMatch;
if ( m.isValid() && m.layer() )
if ( layer )
{
if ( mSelectedFeature && mSelectedFeature->featureId() == m.featureId() && mSelectedFeature->layer() == m.layer() )
if ( mSelectedFeature && mSelectedFeature->featureId() == fid && mSelectedFeature->layer() == layer )
{
// if show feature is called on a feature that's already binded to the vertex editor, toggle it off
mSelectedFeature.reset();
if ( mVertexEditor )
{
mVertexEditor->updateEditor( nullptr, nullptr );
mVertexEditor->updateEditor( nullptr );
}
return;
}

mSelectedFeature.reset( new QgsSelectedFeature( m.featureId(), m.layer(), mCanvas ) );
mSelectedFeature.reset( new QgsSelectedFeature( fid, layer, mCanvas ) );
connect( mSelectedFeature->layer(), &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::cleanEditor );
for ( int i = 0; i < mSelectedVertices.length(); ++i )
{
if ( mSelectedVertices.at( i ).layer == m.layer() && mSelectedVertices.at( i ).fid == m.featureId() )
if ( mSelectedVertices.at( i ).layer == layer && mSelectedVertices.at( i ).fid == fid )
{
mSelectedFeature->selectVertex( mSelectedVertices.at( i ).vertexId );
}
}
}

// make sure the vertex editor is alive and visible
showVertexEditor();

mVertexEditor->updateEditor( mSelectedFeature.get() );
}

void QgsVertexTool::showVertexEditor() //#spellok
{
if ( !mVertexEditor )
{
mVertexEditor.reset( new QgsVertexEditor( m.layer() ? m.layer() : currentVectorLayer(), mSelectedFeature ? mSelectedFeature.get() : nullptr, mCanvas ) );
mVertexEditor.reset( new QgsVertexEditor( mCanvas ) );
if ( !QgisApp::instance()->restoreDockWidget( mVertexEditor.get() ) )
QgisApp::instance()->addDockWidget( Qt::LeftDockWidgetArea, mVertexEditor.get() );

@@ -1129,16 +1136,9 @@ void QgsVertexTool::showVertexEditor() //#spellok
}
else
{
mVertexEditor->updateEditor( m.layer(), mSelectedFeature.get() );

mVertexEditor->show();
mVertexEditor->raise();
}

if ( mSelectedFeature )
{
connect( mSelectedFeature->layer(), &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::cleanEditor );
}
}

void QgsVertexTool::cleanupVertexEditor()
@@ -1739,7 +1739,7 @@ void QgsVertexTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocato
}

if ( mVertexEditor )
mVertexEditor->updateEditor( dragLayer, mSelectedFeature.get() );
mVertexEditor->updateEditor( mSelectedFeature.get() );

setHighlightedVertices( mSelectedVertices ); // update positions of existing highlighted vertices
setHighlightedVerticesVisible( true ); // time to show highlighted vertices again
@@ -1842,7 +1842,7 @@ void QgsVertexTool::applyEditsToLayers( QgsVertexTool::VertexEdits &edits )


if ( mVertexEditor )
mVertexEditor->updateEditor( layer, mSelectedFeature.get() );
mVertexEditor->updateEditor( mSelectedFeature.get() );
}
}

@@ -2003,7 +2003,7 @@ void QgsVertexTool::deleteVertex()
}

if ( mVertexEditor && mSelectedFeature )
mVertexEditor->updateEditor( mSelectedFeature->layer(), mSelectedFeature.get() );
mVertexEditor->updateEditor( mSelectedFeature.get() );
}

void QgsVertexTool::setHighlightedVertices( const QList<Vertex> &listVertices, HighlightMode mode )
@@ -96,6 +96,9 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
//! Toggle the vertex editor
void showVertexEditor(); //#spellok

//! Update vertex editor to show feature from the given match
void updateVertexEditor( QgsVectorLayer *layer, QgsFeatureId fid );

private slots:
//! update geometry of our feature
void onCachedGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
@@ -406,8 +409,6 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing

// support for vertex editor

//! most recent match when moving mouse
QgsPointLocator::Match mLastMouseMoveMatch;
//! Selected feature for the vertex editor
std::unique_ptr<QgsSelectedFeature> mSelectedFeature;
//! Dock widget which allows editing vertices

0 comments on commit f445c26

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