Skip to content
Permalink
Browse files

Merge pull request #9246 from 3nids/vertextool_sync2

[vertex tool] synchronisation of map tool and editor selections
  • Loading branch information
3nids committed Feb 25, 2019
2 parents 4839740 + 57ac4e6 commit d49dc897f5cf2b079208fd3127df88735b33e0b2
@@ -126,7 +126,6 @@ SET(QGIS_APP_SRCS
decorations/qgsdecorationgriddialog.cpp

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

@@ -13,8 +13,8 @@
* *
***************************************************************************/

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

#include "qgsfeatureiterator.h"
#include "qgspoint.h"
@@ -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 );

@@ -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 ) );
}
}

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

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

emit selectionChanged();
}
@@ -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;
@@ -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;

/**
@@ -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
*/
@@ -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"
@@ -361,6 +360,8 @@ void QgsVertexEditor::updateEditor( QgsLockedFeature *lockedFeature )

mVertexModel->setFeature( mLockedFeature );

updateTableSelection();

if ( mLockedFeature )
{
mHintLabel->setVisible( false );
@@ -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;
@@ -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;
@@ -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
@@ -497,3 +497,5 @@ void CoordinateItemDelegate::setModelData( QWidget *editor, QAbstractItemModel *
QStyledItemDelegate::setModelData( editor, model, index );
}
}


@@ -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:
@@ -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;
@@ -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:

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


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

This file was deleted.

This file was deleted.

0 comments on commit d49dc89

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