Skip to content
Permalink
Browse files

[vertex tool] small code cleanup (#9237)

* [vertex tool] rename mSelectedFeature to mLockedFeature

* also rename file and class

* remove uselesss method, move code to constructor

and initialize in header

* followup rename
  • Loading branch information
3nids committed Feb 22, 2019
1 parent c389fad commit fcdb4c025ce078b2b963b5eca245155edb55418f
@@ -125,7 +125,7 @@ SET(QGIS_APP_SRCS
decorations/qgsdecorationgrid.cpp
decorations/qgsdecorationgriddialog.cpp

vertextool/qgsselectedfeature.cpp
vertextool/qgslockedfeature.cpp
vertextool/qgsvertexentry.cpp
vertextool/qgsvertexeditor.cpp
vertextool/qgsvertextool.cpp
@@ -384,7 +384,7 @@ SET (QGIS_APP_MOC_HDRS
decorations/qgsdecorationgrid.h
decorations/qgsdecorationgriddialog.h

vertextool/qgsselectedfeature.h
vertextool/qgslockedfeature.h
vertextool/qgsvertexeditor.h
vertextool/qgsvertextool.h

@@ -1,5 +1,5 @@
/***************************************************************************
qgsselectedfeature.cpp - selected feature of vertextool
qgslockedfeature.cpp - locked feature of vertextool
---------------------
begin : April 2009
copyright : (C) 2009 by Richard Kostecky
@@ -13,7 +13,7 @@
* *
***************************************************************************/

#include "vertextool/qgsselectedfeature.h"
#include "vertextool/qgslockedfeature.h"
#include "vertextool/qgsvertexentry.h"

#include "qgsfeatureiterator.h"
@@ -32,16 +32,33 @@
#include "qgsmapcanvas.h"


QgsSelectedFeature::QgsSelectedFeature( QgsFeatureId featureId,
QgsVectorLayer *vlayer,
QgsMapCanvas *canvas )
QgsLockedFeature::QgsLockedFeature( QgsFeatureId featureId,
QgsVectorLayer *layer,
QgsMapCanvas *canvas )
: mFeatureId( featureId )
, mChangingGeometry( false )
, mLayer( layer )
, mCanvas( canvas )
{
setSelectedFeature( featureId, vlayer, canvas );
// signal changing of current layer
connect( QgisApp::instance()->layerTreeView(), &QgsLayerTreeView::currentLayerChanged, this, &QgsLockedFeature::currentLayerChanged );

// feature was deleted
connect( mLayer, &QgsVectorLayer::featureDeleted, this, &QgsLockedFeature::featureDeleted );

// rolling back
connect( mLayer, &QgsVectorLayer::beforeRollBack, this, &QgsLockedFeature::beforeRollBack );

// projection or extents changed
connect( canvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsLockedFeature::updateVertexMarkersPosition );
connect( canvas, &QgsMapCanvas::extentsChanged, this, &QgsLockedFeature::updateVertexMarkersPosition );

// geometry was changed
connect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsLockedFeature::geometryChanged );

replaceVertexMap();
}

QgsSelectedFeature::~QgsSelectedFeature()
QgsLockedFeature::~QgsLockedFeature()
{
deleteVertexMap();

@@ -61,13 +78,13 @@ QgsSelectedFeature::~QgsSelectedFeature()
delete mGeometry;
}

void QgsSelectedFeature::currentLayerChanged( QgsMapLayer *layer )
void QgsLockedFeature::currentLayerChanged( QgsMapLayer *layer )
{
if ( layer == mLayer )
deleteLater();
}

void QgsSelectedFeature::updateGeometry( const QgsGeometry *geom )
void QgsLockedFeature::updateGeometry( const QgsGeometry *geom )
{
delete mGeometry;

@@ -86,68 +103,40 @@ void QgsSelectedFeature::updateGeometry( const QgsGeometry *geom )
}
}

void QgsSelectedFeature::setSelectedFeature( QgsFeatureId featureId, QgsVectorLayer *layer, QgsMapCanvas *canvas )
{
mFeatureId = featureId;
mLayer = layer;
mCanvas = canvas;

delete mGeometry;
mGeometry = nullptr;

// signal changing of current layer
connect( QgisApp::instance()->layerTreeView(), &QgsLayerTreeView::currentLayerChanged, this, &QgsSelectedFeature::currentLayerChanged );

// feature was deleted
connect( mLayer, &QgsVectorLayer::featureDeleted, this, &QgsSelectedFeature::featureDeleted );

// rolling back
connect( mLayer, &QgsVectorLayer::beforeRollBack, this, &QgsSelectedFeature::beforeRollBack );

// projection or extents changed
connect( canvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsSelectedFeature::updateVertexMarkersPosition );
connect( canvas, &QgsMapCanvas::extentsChanged, this, &QgsSelectedFeature::updateVertexMarkersPosition );

// geometry was changed
connect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsSelectedFeature::geometryChanged );

replaceVertexMap();
}

void QgsSelectedFeature::beforeRollBack()
void QgsLockedFeature::beforeRollBack()
{
disconnect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsSelectedFeature::geometryChanged );
disconnect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsLockedFeature::geometryChanged );
deleteVertexMap();
}

void QgsSelectedFeature::beginGeometryChange()
void QgsLockedFeature::beginGeometryChange()
{
Q_ASSERT( !mChangingGeometry );
mChangingGeometry = true;

disconnect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsSelectedFeature::geometryChanged );
disconnect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsLockedFeature::geometryChanged );
}

void QgsSelectedFeature::endGeometryChange()
void QgsLockedFeature::endGeometryChange()
{
Q_ASSERT( mChangingGeometry );
mChangingGeometry = false;

connect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsSelectedFeature::geometryChanged );
connect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsLockedFeature::geometryChanged );
}

void QgsSelectedFeature::canvasLayersChanged()
void QgsLockedFeature::canvasLayersChanged()
{
currentLayerChanged( mCanvas->currentLayer() );
}

void QgsSelectedFeature::featureDeleted( QgsFeatureId fid )
void QgsLockedFeature::featureDeleted( QgsFeatureId fid )
{
if ( fid == mFeatureId )
deleteLater();
}

void QgsSelectedFeature::geometryChanged( QgsFeatureId fid, const QgsGeometry &geom )
void QgsLockedFeature::geometryChanged( QgsFeatureId fid, const QgsGeometry &geom )
{
QgsDebugCall;

@@ -159,7 +148,7 @@ void QgsSelectedFeature::geometryChanged( QgsFeatureId fid, const QgsGeometry &g
replaceVertexMap();
}

void QgsSelectedFeature::validateGeometry( QgsGeometry *g )
void QgsLockedFeature::validateGeometry( QgsGeometry *g )
{
QgsSettings settings;
if ( settings.value( QStringLiteral( "qgis/digitizing/validate_geometries" ), 1 ).toInt() == 0 )
@@ -190,15 +179,15 @@ void QgsSelectedFeature::validateGeometry( QgsGeometry *g )
if ( settings.value( QStringLiteral( "qgis/digitizing/validate_geometries" ), 1 ).toInt() == 2 )
method = QgsGeometry::ValidatorGeos;
mValidator = new QgsGeometryValidator( *g, nullptr, method );
connect( mValidator, &QgsGeometryValidator::errorFound, this, &QgsSelectedFeature::addError );
connect( mValidator, &QThread::finished, this, &QgsSelectedFeature::validationFinished );
connect( mValidator, &QgsGeometryValidator::errorFound, this, &QgsLockedFeature::addError );
connect( mValidator, &QThread::finished, this, &QgsLockedFeature::validationFinished );
mValidator->start();

QgsStatusBar *sb = QgisApp::instance()->statusBarIface();
sb->showMessage( tr( "Validation started." ) );
}

void QgsSelectedFeature::addError( QgsGeometry::Error e )
void QgsLockedFeature::addError( QgsGeometry::Error e )
{
mGeomErrors << e;
if ( !mTip.isEmpty() )
@@ -223,13 +212,13 @@ void QgsSelectedFeature::addError( QgsGeometry::Error e )
sb->setToolTip( mTip );
}

void QgsSelectedFeature::validationFinished()
void QgsLockedFeature::validationFinished()
{
QgsStatusBar *sb = QgisApp::instance()->statusBarIface();
sb->showMessage( tr( "Validation finished (%n error(s) found).", "number of geometry errors", mGeomErrorMarkers.size() ) );
}

void QgsSelectedFeature::replaceVertexMap()
void QgsLockedFeature::replaceVertexMap()
{
// delete old map
deleteVertexMap();
@@ -243,7 +232,7 @@ void QgsSelectedFeature::replaceVertexMap()
emit vertexMapChanged();
}

void QgsSelectedFeature::deleteVertexMap()
void QgsLockedFeature::deleteVertexMap()
{
Q_FOREACH ( QgsVertexEntry *entry, mVertexMap )
{
@@ -253,18 +242,18 @@ void QgsSelectedFeature::deleteVertexMap()
mVertexMap.clear();
}

bool QgsSelectedFeature::isSelected( int vertexNr )
bool QgsLockedFeature::isSelected( int vertexNr )
{
return mVertexMap.at( vertexNr )->isSelected();
}

QgsGeometry *QgsSelectedFeature::geometry()
QgsGeometry *QgsLockedFeature::geometry()
{
Q_ASSERT( mGeometry );
return mGeometry;
}

void QgsSelectedFeature::createVertexMap()
void QgsLockedFeature::createVertexMap()
{

if ( !mGeometry )
@@ -292,7 +281,7 @@ void QgsSelectedFeature::createVertexMap()
}
}

void QgsSelectedFeature::selectVertex( int vertexNr )
void QgsLockedFeature::selectVertex( int vertexNr )
{
if ( vertexNr < 0 || vertexNr >= mVertexMap.size() )
return;
@@ -303,7 +292,7 @@ void QgsSelectedFeature::selectVertex( int vertexNr )
emit selectionChanged();
}

void QgsSelectedFeature::deselectVertex( int vertexNr )
void QgsLockedFeature::deselectVertex( int vertexNr )
{
if ( vertexNr < 0 || vertexNr >= mVertexMap.size() )
return;
@@ -314,7 +303,7 @@ void QgsSelectedFeature::deselectVertex( int vertexNr )
emit selectionChanged();
}

void QgsSelectedFeature::deselectAllVertices()
void QgsLockedFeature::deselectAllVertices()
{
for ( int i = 0; i < mVertexMap.size(); i++ )
{
@@ -323,7 +312,7 @@ void QgsSelectedFeature::deselectAllVertices()
emit selectionChanged();
}

void QgsSelectedFeature::invertVertexSelection( int vertexNr )
void QgsLockedFeature::invertVertexSelection( int vertexNr )
{
if ( vertexNr < 0 || vertexNr >= mVertexMap.size() )
return;
@@ -336,7 +325,7 @@ void QgsSelectedFeature::invertVertexSelection( int vertexNr )
emit selectionChanged();
}

void QgsSelectedFeature::invertVertexSelection( const QVector<int> &vertexIndices )
void QgsLockedFeature::invertVertexSelection( const QVector<int> &vertexIndices )
{
Q_FOREACH ( int index, vertexIndices )
{
@@ -349,25 +338,25 @@ void QgsSelectedFeature::invertVertexSelection( const QVector<int> &vertexIndice
emit selectionChanged();
}

void QgsSelectedFeature::updateVertexMarkersPosition()
void QgsLockedFeature::updateVertexMarkersPosition()
{
Q_FOREACH ( QgsVertexEntry *vertexEntry, mVertexMap )
{
vertexEntry->placeMarker();
}
}

QgsFeatureId QgsSelectedFeature::featureId()
QgsFeatureId QgsLockedFeature::featureId()
{
return mFeatureId;
}

QList<QgsVertexEntry *> &QgsSelectedFeature::vertexMap()
QList<QgsVertexEntry *> &QgsLockedFeature::vertexMap()
{
return mVertexMap;
}

QgsVectorLayer *QgsSelectedFeature::layer()
QgsVectorLayer *QgsLockedFeature::layer()
{
return mLayer;
}
@@ -1,5 +1,5 @@
/***************************************************************************
qgsselectedfeature.h - selected feature of vertextool
qgslockedfeature.h - selected feature of vertextool
---------------------
begin : April 2009
copyright : (C) 2009 by Richard Kostecky
@@ -13,8 +13,8 @@
* *
***************************************************************************/

#ifndef QGSSELECTEDFEATURE_H
#define QGSSELECTEDFEATURE_H
#ifndef QGSLOCKEDFEATURE_H
#define QGSLOCKEDFEATURE_H

#include "qgsgeometry.h"
#include "qgsfeatureid.h"
@@ -38,21 +38,21 @@ static const double ZERO_TOLERANCE = 0.000000001;
/**
* Class that keeps the selected feature
*/
class QgsSelectedFeature: public QObject
class QgsLockedFeature: public QObject
{
Q_OBJECT

public:
QgsSelectedFeature( QgsFeatureId id, QgsVectorLayer *layer, QgsMapCanvas *canvas );
~QgsSelectedFeature() override;

/**
* Setting selected feature
* Creates a locked feature
* \param featureId id of feature which was selected
* \param vlayer vector layer in which feature is selected
* \param layer vector layer in which feature is selected
* \param canvas mapCanvas on which we are working
*/
void setSelectedFeature( QgsFeatureId featureId, QgsVectorLayer *layer, QgsMapCanvas *canvas );
QgsLockedFeature( QgsFeatureId id, QgsVectorLayer *layer, QgsMapCanvas *canvas );

~QgsLockedFeature() override;

/**
* Function to select vertex with number
@@ -191,8 +191,7 @@ class QgsSelectedFeature: public QObject

QgsFeatureId mFeatureId;
QgsGeometry *mGeometry = nullptr;
bool mFeatureSelected;
bool mChangingGeometry;
bool mChangingGeometry = false;
QgsVectorLayer *mLayer = nullptr;
QList<QgsVertexEntry *> mVertexMap;
QgsMapCanvas *mCanvas = nullptr;

0 comments on commit fcdb4c0

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