Skip to content
Permalink
Browse files

remove uselesss method, move code to constructor

and initialize in header
  • Loading branch information
3nids committed Feb 25, 2019
1 parent 36fc62c commit dbad206c982662733dba1ca4dfa0c2f10ef9e255
@@ -33,12 +33,29 @@


QgsLockedFeature::QgsLockedFeature( QgsFeatureId featureId,
QgsVectorLayer *vlayer,
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();
}

QgsLockedFeature::~QgsLockedFeature()
@@ -86,34 +103,6 @@ void QgsLockedFeature::updateGeometry( const QgsGeometry *geom )
}
}

void QgsLockedFeature::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, &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();
}

void QgsLockedFeature::beforeRollBack()
{
disconnect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsLockedFeature::geometryChanged );
@@ -43,16 +43,16 @@ class QgsLockedFeature: public QObject
Q_OBJECT

public:
QgsLockedFeature( QgsFeatureId id, QgsVectorLayer *layer, QgsMapCanvas *canvas );
~QgsLockedFeature() 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 QgsLockedFeature: public QObject

QgsFeatureId mFeatureId;
QgsGeometry *mGeometry = nullptr;
bool mFeatureSelected;
bool mChangingGeometry;
bool mChangingGeometry = false;
QgsVectorLayer *mLayer = nullptr;
QList<QgsVertexEntry *> mVertexMap;
QgsMapCanvas *mCanvas = nullptr;
@@ -47,14 +47,14 @@ QgsVertexEditorModel::QgsVertexEditorModel( QgsMapCanvas *canvas, QObject *paren
mWidgetFont = parentWidget->font();
}

void QgsVertexEditorModel::setFeature( QgsLockedFeature *selectedFeature )
void QgsVertexEditorModel::setFeature( QgsLockedFeature *lockedFeature )
{
beginResetModel();

mSelectedFeature = selectedFeature;
if ( mSelectedFeature && mSelectedFeature->layer() )
mLockedFeature = lockedFeature;
if ( mLockedFeature && mLockedFeature->layer() )
{
QgsWkbTypes::Type layerWKBType = mSelectedFeature->layer()->wkbType();
QgsWkbTypes::Type layerWKBType = mLockedFeature->layer()->wkbType();

mHasZ = QgsWkbTypes::hasZ( layerWKBType );
mHasM = QgsWkbTypes::hasM( layerWKBType );
@@ -74,35 +74,35 @@ void QgsVertexEditorModel::setFeature( QgsLockedFeature *selectedFeature )

int QgsVertexEditorModel::rowCount( const QModelIndex &parent ) const
{
if ( parent.isValid() || !mSelectedFeature )
if ( parent.isValid() || !mLockedFeature )
return 0;

return mSelectedFeature->vertexMap().count();
return mLockedFeature->vertexMap().count();
}

int QgsVertexEditorModel::columnCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent );
if ( !mSelectedFeature )
if ( !mLockedFeature )
return 0;
else
return 2 + ( mHasZ ? 1 : 0 ) + ( mHasM ? 1 : 0 ) + ( mHasR ? 1 : 0 );
}

QVariant QgsVertexEditorModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() || !mSelectedFeature ||
if ( !index.isValid() || !mLockedFeature ||
( role != Qt::DisplayRole && role != Qt::EditRole && role != MIN_RADIUS_ROLE && role != Qt::FontRole ) )
return QVariant();

if ( index.row() >= mSelectedFeature->vertexMap().count() )
if ( index.row() >= mLockedFeature->vertexMap().count() )
return QVariant();

if ( index.column() >= columnCount() )
return QVariant();

//get QgsVertexEntry for row
const QgsVertexEntry *vertex = mSelectedFeature->vertexMap().at( index.row() );
const QgsVertexEntry *vertex = mLockedFeature->vertexMap().at( index.row() );
if ( !vertex )
{
return QVariant();
@@ -209,7 +209,7 @@ bool QgsVertexEditorModel::setData( const QModelIndex &index, const QVariant &va
{
return false;
}
if ( !mSelectedFeature || !mSelectedFeature->layer() || index.row() >= mSelectedFeature->vertexMap().count() )
if ( !mLockedFeature || !mLockedFeature->layer() || index.row() >= mLockedFeature->vertexMap().count() )
{
return false;
}
@@ -223,20 +223,20 @@ bool QgsVertexEditorModel::setData( const QModelIndex &index, const QVariant &va
doubleValue = QLocale( QLocale::English ).toDouble( value.toString() );
}

double x = ( index.column() == 0 ? doubleValue : mSelectedFeature->vertexMap().at( index.row() )->point().x() );
double y = ( index.column() == 1 ? doubleValue : mSelectedFeature->vertexMap().at( index.row() )->point().y() );
double x = ( index.column() == 0 ? doubleValue : mLockedFeature->vertexMap().at( index.row() )->point().x() );
double y = ( index.column() == 1 ? doubleValue : mLockedFeature->vertexMap().at( index.row() )->point().y() );

if ( index.column() == mRCol ) // radius modified
{
if ( index.row() == 0 || index.row() >= mSelectedFeature->vertexMap().count() - 1 )
if ( index.row() == 0 || index.row() >= mLockedFeature->vertexMap().count() - 1 )
return false;

double x1 = mSelectedFeature->vertexMap().at( index.row() - 1 )->point().x();
double y1 = mSelectedFeature->vertexMap().at( index.row() - 1 )->point().y();
double x1 = mLockedFeature->vertexMap().at( index.row() - 1 )->point().x();
double y1 = mLockedFeature->vertexMap().at( index.row() - 1 )->point().y();
double x2 = x;
double y2 = y;
double x3 = mSelectedFeature->vertexMap().at( index.row() + 1 )->point().x();
double y3 = mSelectedFeature->vertexMap().at( index.row() + 1 )->point().y();
double x3 = mLockedFeature->vertexMap().at( index.row() + 1 )->point().x();
double y3 = mLockedFeature->vertexMap().at( index.row() + 1 )->point().y();

QgsPoint result;
if ( QgsGeometryUtils::segmentMidPoint( QgsPoint( x1, y1 ), QgsPoint( x3, y3 ), result, doubleValue, QgsPoint( x2, y2 ) ) )
@@ -245,14 +245,14 @@ bool QgsVertexEditorModel::setData( const QModelIndex &index, const QVariant &va
y = result.y();
}
}
double z = ( index.column() == mZCol ? value.toDouble() : mSelectedFeature->vertexMap().at( index.row() )->point().z() );
double m = ( index.column() == mMCol ? value.toDouble() : mSelectedFeature->vertexMap().at( index.row() )->point().m() );
double z = ( index.column() == mZCol ? value.toDouble() : mLockedFeature->vertexMap().at( index.row() )->point().z() );
double m = ( index.column() == mMCol ? value.toDouble() : mLockedFeature->vertexMap().at( index.row() )->point().m() );
QgsPoint p( QgsWkbTypes::PointZM, x, y, z, m );

mSelectedFeature->layer()->beginEditCommand( QObject::tr( "Moved vertices" ) );
mSelectedFeature->layer()->moveVertex( p, mSelectedFeature->featureId(), index.row() );
mSelectedFeature->layer()->endEditCommand();
mSelectedFeature->layer()->triggerRepaint();
mLockedFeature->layer()->beginEditCommand( QObject::tr( "Moved vertices" ) );
mLockedFeature->layer()->moveVertex( p, mLockedFeature->featureId(), index.row() );
mLockedFeature->layer()->endEditCommand();
mLockedFeature->layer()->triggerRepaint();

return false;
}
@@ -273,18 +273,18 @@ Qt::ItemFlags QgsVertexEditorModel::flags( const QModelIndex &index ) const

bool QgsVertexEditorModel::calcR( int row, double &r, double &minRadius ) const
{
if ( row <= 0 || !mSelectedFeature || row >= mSelectedFeature->vertexMap().count() - 1 )
if ( row <= 0 || !mLockedFeature || row >= mLockedFeature->vertexMap().count() - 1 )
return false;

const QgsVertexEntry *entry = mSelectedFeature->vertexMap().at( row );
const QgsVertexEntry *entry = mLockedFeature->vertexMap().at( row );

bool curvePoint = ( entry->vertexId().type == QgsVertexId::CurveVertex );
if ( !curvePoint )
return false;

const QgsPoint &p1 = mSelectedFeature->vertexMap().at( row - 1 )->point();
const QgsPoint &p2 = mSelectedFeature->vertexMap().at( row )->point();
const QgsPoint &p3 = mSelectedFeature->vertexMap().at( row + 1 )->point();
const QgsPoint &p1 = mLockedFeature->vertexMap().at( row - 1 )->point();
const QgsPoint &p2 = mLockedFeature->vertexMap().at( row )->point();
const QgsPoint &p3 = mLockedFeature->vertexMap().at( row + 1 )->point();

double cx, cy;
QgsGeometryUtils::circleCenterRadius( p1, p2, p3, r, cx, cy );
@@ -332,19 +332,19 @@ QgsVertexEditor::QgsVertexEditor( QgsMapCanvas *canvas )
setWidget( content );
}

void QgsVertexEditor::updateEditor( QgsLockedFeature *selectedFeature )
void QgsVertexEditor::updateEditor( QgsLockedFeature *lockedFeature )
{

mSelectedFeature = selectedFeature;
mLockedFeature = lockedFeature;

mVertexModel->setFeature( mSelectedFeature );
mVertexModel->setFeature( mLockedFeature );

if ( mSelectedFeature )
if ( mLockedFeature )
{
mHintLabel->setVisible( false );
mTableView->setVisible( true );

connect( mSelectedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
}
else
{
@@ -355,12 +355,12 @@ void QgsVertexEditor::updateEditor( QgsLockedFeature *selectedFeature )

void QgsVertexEditor::updateTableSelection()
{
if ( !mSelectedFeature || mUpdatingVertexSelection )
if ( !mLockedFeature || mUpdatingVertexSelection )
return;

mUpdatingTableSelection = true;
mTableView->selectionModel()->clearSelection();
const QList<QgsVertexEntry *> &vertexMap = mSelectedFeature->vertexMap();
const QList<QgsVertexEntry *> &vertexMap = mLockedFeature->vertexMap();
int firstSelectedRow = -1;
QItemSelection selection;
for ( int i = 0, n = vertexMap.size(); i < n; ++i )
@@ -382,23 +382,23 @@ void QgsVertexEditor::updateTableSelection()

void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, const QItemSelection & )
{
if ( !mSelectedFeature || mUpdatingTableSelection )
if ( !mLockedFeature || mUpdatingTableSelection )
return;

mUpdatingVertexSelection = true;

mSelectedFeature->deselectAllVertices();
mLockedFeature->deselectAllVertices();

QgsCoordinateTransform t( mSelectedFeature->layer()->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() );
QgsCoordinateTransform t( mLockedFeature->layer()->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() );
std::unique_ptr<QgsRectangle> bbox;
QModelIndexList indexList = selected.indexes();
for ( int i = 0; i < indexList.length(); ++i )
{
int vertexIdx = indexList.at( i ).row();
mSelectedFeature->selectVertex( vertexIdx );
mLockedFeature->selectVertex( vertexIdx );

// create a bounding box of selected vertices
QgsPointXY point( mSelectedFeature->vertexMap().at( vertexIdx )->point() );
QgsPointXY point( mLockedFeature->vertexMap().at( vertexIdx )->point() );
if ( !bbox )
bbox.reset( new QgsRectangle( point, point ) );
else
@@ -38,7 +38,7 @@ class QgsVertexEditorModel : public QAbstractTableModel

QgsVertexEditorModel( QgsMapCanvas *canvas, QObject *parent = nullptr );

void setFeature( QgsLockedFeature *selectedFeature );
void setFeature( QgsLockedFeature *lockedFeature );

int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
@@ -48,7 +48,7 @@ class QgsVertexEditorModel : public QAbstractTableModel
Qt::ItemFlags flags( const QModelIndex &index ) const override;

private:
QgsLockedFeature *mSelectedFeature = nullptr;
QgsLockedFeature *mLockedFeature = nullptr;
QgsMapCanvas *mCanvas = nullptr;

bool mHasZ = false;
@@ -72,8 +72,8 @@ class QgsVertexEditor : public QgsDockWidget
QgsVertexEditor( QgsMapCanvas *canvas );

public:
void updateEditor( QgsLockedFeature *selectedFeature );
QgsLockedFeature *mSelectedFeature = nullptr;
void updateEditor( QgsLockedFeature *lockedFeature );
QgsLockedFeature *mLockedFeature = nullptr;
QgsMapCanvas *mCanvas = nullptr;
QTableView *mTableView = nullptr;
QgsVertexEditorModel *mVertexModel = nullptr;

0 comments on commit dbad206

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