Skip to content

Commit

Permalink
Merge pull request #9277 from 3nids/vertextool_36
Browse files Browse the repository at this point in the history
vertex tool / editor synchronisation backport 3.6
  • Loading branch information
3nids committed Feb 25, 2019
2 parents 0da3651 + 3e7d781 commit a95f872
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 190 deletions.
1 change: 0 additions & 1 deletion src/app/CMakeLists.txt
Expand Up @@ -126,7 +126,6 @@ SET(QGIS_APP_SRCS
decorations/qgsdecorationgriddialog.cpp

vertextool/qgslockedfeature.cpp
vertextool/qgsvertexentry.cpp
vertextool/qgsvertexeditor.cpp
vertextool/qgsvertextool.cpp

Expand Down
20 changes: 4 additions & 16 deletions src/app/vertextool/qgslockedfeature.cpp
Expand Up @@ -13,8 +13,8 @@
* *
***************************************************************************/

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

#include "qgsfeatureiterator.h"
#include "qgspoint.h"
Expand Down Expand Up @@ -48,10 +48,6 @@ QgsLockedFeature::QgsLockedFeature( QgsFeatureId featureId,
// 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 );

Expand Down Expand Up @@ -277,7 +273,7 @@ void QgsLockedFeature::createVertexMap()
QgsPoint pt;
while ( geom->nextVertex( vertexId, pt ) )
{
mVertexMap.append( new QgsVertexEntry( mCanvas, mLayer, pt, vertexId, tr( "ring %1, vertex %2" ).arg( vertexId.ring ).arg( vertexId.vertex ) ) );
mVertexMap.append( new QgsVertexEntry( pt, vertexId ) );
}
}

Expand All @@ -287,7 +283,7 @@ void QgsLockedFeature::selectVertex( int vertexNr )
return;

QgsVertexEntry *entry = mVertexMap.at( vertexNr );
entry->setSelected();
entry->setSelected( true );

emit selectionChanged();
}
Expand Down Expand Up @@ -338,14 +334,6 @@ void QgsLockedFeature::invertVertexSelection( const QVector<int> &vertexIndices
emit selectionChanged();
}

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

QgsFeatureId QgsLockedFeature::featureId()
{
return mFeatureId;
Expand Down
11 changes: 2 additions & 9 deletions src/app/vertextool/qgslockedfeature.h
Expand Up @@ -16,18 +16,16 @@
#ifndef QGSLOCKEDFEATURE_H
#define QGSLOCKEDFEATURE_H

#include <QObject>

#include "qgsgeometry.h"
#include "qgsfeatureid.h"

#include <QObject>

class QgsMapCanvas;
class QgsVectorLayer;
class QgsMapLayer;
class QgsRubberBand;
class QgsGeometryValidator;
class QgsVertexMarker;

class QgsVertexEntry;

/**
Expand Down Expand Up @@ -136,11 +134,6 @@ class QgsLockedFeature: public QObject
*/
void validationFinished();

/**
* Updates vertex markers position accoording to changed feature geometry
*/
void updateVertexMarkersPosition();

/*
* a feature was removed from the layer - might be the selected
*/
Expand Down
20 changes: 11 additions & 9 deletions src/app/vertextool/qgsvertexeditor.cpp
Expand Up @@ -20,7 +20,6 @@
#include "qgsmapcanvas.h"
#include "qgsmessagelog.h"
#include "qgslockedfeature.h"
#include "qgsvertexentry.h"
#include "qgsvectorlayer.h"
#include "qgsgeometryutils.h"
#include "qgsproject.h"
Expand Down Expand Up @@ -361,6 +360,8 @@ void QgsVertexEditor::updateEditor( QgsLockedFeature *lockedFeature )

mVertexModel->setFeature( mLockedFeature );

updateTableSelection();

if ( mLockedFeature )
{
mHintLabel->setVisible( false );
Expand All @@ -377,11 +378,10 @@ void QgsVertexEditor::updateEditor( QgsLockedFeature *lockedFeature )

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

mUpdatingTableSelection = true;
mTableView->selectionModel()->clearSelection();
const QList<QgsVertexEntry *> &vertexMap = mLockedFeature->vertexMap();
int firstSelectedRow = -1;
QItemSelection selection;
Expand All @@ -394,17 +394,17 @@ void QgsVertexEditor::updateTableSelection()
selection.select( mVertexModel->index( i, 0 ), mVertexModel->index( i, mVertexModel->columnCount() - 1 ) );
}
}
mTableView->selectionModel()->select( selection, QItemSelectionModel::Select );
mTableView->selectionModel()->select( selection, QItemSelectionModel::ClearAndSelect );

if ( firstSelectedRow >= 0 )
mTableView->scrollTo( mVertexModel->index( firstSelectedRow, 0 ), QAbstractItemView::PositionAtTop );

mUpdatingTableSelection = false;
}

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

mUpdatingVertexSelection = true;
Expand All @@ -413,10 +413,10 @@ void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, con

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 )
const QModelIndexList indexList = mTableView->selectionModel()->selectedRows();
for ( const QModelIndex &index : indexList )
{
int vertexIdx = indexList.at( i ).row();
int vertexIdx = index.row();
mLockedFeature->selectVertex( vertexIdx );

// create a bounding box of selected vertices
Expand Down Expand Up @@ -497,3 +497,5 @@ void CoordinateItemDelegate::setModelData( QWidget *editor, QAbstractItemModel *
QStyledItemDelegate::setModelData( editor, model, index );
}
}


44 changes: 36 additions & 8 deletions src/app/vertextool/qgsvertexeditor.h
Expand Up @@ -19,19 +19,48 @@
#ifndef QGSVERTEXEDITOR_H
#define QGSVERTEXEDITOR_H

#include "qgsdockwidget.h"
#include <QAbstractTableModel>
#include <QItemSelection>
#include <QStyledItemDelegate>

#include "qgis_app.h"
#include "qgsdockwidget.h"
#include "qgspoint.h"

class QLabel;
class QTableView;

class QgsMapCanvas;
class QgsLockedFeature;
class QgsVectorLayer;

class QLabel;
class QTableView;

class QgsVertexEditorModel : public QAbstractTableModel
class APP_EXPORT QgsVertexEntry
{
public:
QgsVertexEntry( const QgsPoint &p,
QgsVertexId vertexId )
: mSelected( false )
, mPoint( p )
, mVertexId( vertexId )
{
}

QgsVertexEntry( const QgsVertexEntry &rh ) = delete;
QgsVertexEntry &operator=( const QgsVertexEntry &rh ) = delete;

const QgsPoint &point() const { return mPoint; }
QgsVertexId vertexId() const { return mVertexId; }
bool isSelected() const { return mSelected; }
void setSelected( bool selected ) { mSelected = selected; }

private:
bool mSelected;
QgsPoint mPoint;
QgsVertexId mVertexId;
};

class APP_EXPORT QgsVertexEditorModel : public QAbstractTableModel
{
Q_OBJECT
public:
Expand Down Expand Up @@ -65,13 +94,12 @@ class QgsVertexEditorModel : public QAbstractTableModel

};

class QgsVertexEditor : public QgsDockWidget
class APP_EXPORT QgsVertexEditor : public QgsDockWidget
{
Q_OBJECT
public:
QgsVertexEditor( QgsMapCanvas *canvas );

public:
void updateEditor( QgsLockedFeature *lockedFeature );
QgsLockedFeature *mLockedFeature = nullptr;
QgsMapCanvas *mCanvas = nullptr;
Expand All @@ -88,7 +116,7 @@ class QgsVertexEditor : public QgsDockWidget

private slots:
void updateTableSelection();
void updateVertexSelection( const QItemSelection &selected, const QItemSelection &deselected );
void updateVertexSelection( const QItemSelection &, const QItemSelection &deselected );

private:

Expand All @@ -99,7 +127,7 @@ class QgsVertexEditor : public QgsDockWidget
};


class CoordinateItemDelegate : public QStyledItemDelegate
class APP_EXPORT CoordinateItemDelegate : public QStyledItemDelegate
{
Q_OBJECT

Expand Down
83 changes: 0 additions & 83 deletions src/app/vertextool/qgsvertexentry.cpp

This file was deleted.

61 changes: 0 additions & 61 deletions src/app/vertextool/qgsvertexentry.h

This file was deleted.

0 comments on commit a95f872

Please sign in to comment.