Skip to content

Commit d49dc89

Browse files
authored
Merge pull request #9246 from 3nids/vertextool_sync2
[vertex tool] synchronisation of map tool and editor selections
2 parents 4839740 + 57ac4e6 commit d49dc89

9 files changed

+99
-190
lines changed

src/app/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ SET(QGIS_APP_SRCS
126126
decorations/qgsdecorationgriddialog.cpp
127127

128128
vertextool/qgslockedfeature.cpp
129-
vertextool/qgsvertexentry.cpp
130129
vertextool/qgsvertexeditor.cpp
131130
vertextool/qgsvertextool.cpp
132131

src/app/vertextool/qgslockedfeature.cpp

+4-16
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* *
1414
***************************************************************************/
1515

16-
#include "vertextool/qgslockedfeature.h"
17-
#include "vertextool/qgsvertexentry.h"
16+
#include "qgslockedfeature.h"
17+
#include "qgsvertexeditor.h"
1818

1919
#include "qgsfeatureiterator.h"
2020
#include "qgspoint.h"
@@ -48,10 +48,6 @@ QgsLockedFeature::QgsLockedFeature( QgsFeatureId featureId,
4848
// rolling back
4949
connect( mLayer, &QgsVectorLayer::beforeRollBack, this, &QgsLockedFeature::beforeRollBack );
5050

51-
// projection or extents changed
52-
connect( canvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsLockedFeature::updateVertexMarkersPosition );
53-
connect( canvas, &QgsMapCanvas::extentsChanged, this, &QgsLockedFeature::updateVertexMarkersPosition );
54-
5551
// geometry was changed
5652
connect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsLockedFeature::geometryChanged );
5753

@@ -277,7 +273,7 @@ void QgsLockedFeature::createVertexMap()
277273
QgsPoint pt;
278274
while ( geom->nextVertex( vertexId, pt ) )
279275
{
280-
mVertexMap.append( new QgsVertexEntry( mCanvas, mLayer, pt, vertexId, tr( "ring %1, vertex %2" ).arg( vertexId.ring ).arg( vertexId.vertex ) ) );
276+
mVertexMap.append( new QgsVertexEntry( pt, vertexId ) );
281277
}
282278
}
283279

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

289285
QgsVertexEntry *entry = mVertexMap.at( vertexNr );
290-
entry->setSelected();
286+
entry->setSelected( true );
291287

292288
emit selectionChanged();
293289
}
@@ -338,14 +334,6 @@ void QgsLockedFeature::invertVertexSelection( const QVector<int> &vertexIndices
338334
emit selectionChanged();
339335
}
340336

341-
void QgsLockedFeature::updateVertexMarkersPosition()
342-
{
343-
Q_FOREACH ( QgsVertexEntry *vertexEntry, mVertexMap )
344-
{
345-
vertexEntry->placeMarker();
346-
}
347-
}
348-
349337
QgsFeatureId QgsLockedFeature::featureId()
350338
{
351339
return mFeatureId;

src/app/vertextool/qgslockedfeature.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@
1616
#ifndef QGSLOCKEDFEATURE_H
1717
#define QGSLOCKEDFEATURE_H
1818

19+
#include <QObject>
20+
1921
#include "qgsgeometry.h"
2022
#include "qgsfeatureid.h"
2123

22-
#include <QObject>
23-
2424
class QgsMapCanvas;
2525
class QgsVectorLayer;
2626
class QgsMapLayer;
27-
class QgsRubberBand;
2827
class QgsGeometryValidator;
2928
class QgsVertexMarker;
30-
3129
class QgsVertexEntry;
3230

3331
/**
@@ -136,11 +134,6 @@ class QgsLockedFeature: public QObject
136134
*/
137135
void validationFinished();
138136

139-
/**
140-
* Updates vertex markers position accoording to changed feature geometry
141-
*/
142-
void updateVertexMarkersPosition();
143-
144137
/*
145138
* a feature was removed from the layer - might be the selected
146139
*/

src/app/vertextool/qgsvertexeditor.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "qgsmapcanvas.h"
2121
#include "qgsmessagelog.h"
2222
#include "qgslockedfeature.h"
23-
#include "qgsvertexentry.h"
2423
#include "qgsvectorlayer.h"
2524
#include "qgsgeometryutils.h"
2625
#include "qgsproject.h"
@@ -361,6 +360,8 @@ void QgsVertexEditor::updateEditor( QgsLockedFeature *lockedFeature )
361360

362361
mVertexModel->setFeature( mLockedFeature );
363362

363+
updateTableSelection();
364+
364365
if ( mLockedFeature )
365366
{
366367
mHintLabel->setVisible( false );
@@ -377,11 +378,10 @@ void QgsVertexEditor::updateEditor( QgsLockedFeature *lockedFeature )
377378

378379
void QgsVertexEditor::updateTableSelection()
379380
{
380-
if ( !mLockedFeature || mUpdatingVertexSelection )
381+
if ( !mLockedFeature || mUpdatingVertexSelection || mUpdatingTableSelection )
381382
return;
382383

383384
mUpdatingTableSelection = true;
384-
mTableView->selectionModel()->clearSelection();
385385
const QList<QgsVertexEntry *> &vertexMap = mLockedFeature->vertexMap();
386386
int firstSelectedRow = -1;
387387
QItemSelection selection;
@@ -394,17 +394,17 @@ void QgsVertexEditor::updateTableSelection()
394394
selection.select( mVertexModel->index( i, 0 ), mVertexModel->index( i, mVertexModel->columnCount() - 1 ) );
395395
}
396396
}
397-
mTableView->selectionModel()->select( selection, QItemSelectionModel::Select );
397+
mTableView->selectionModel()->select( selection, QItemSelectionModel::ClearAndSelect );
398398

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

402402
mUpdatingTableSelection = false;
403403
}
404404

405-
void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, const QItemSelection & )
405+
void QgsVertexEditor::updateVertexSelection( const QItemSelection &, const QItemSelection & )
406406
{
407-
if ( !mLockedFeature || mUpdatingTableSelection )
407+
if ( !mLockedFeature || mUpdatingVertexSelection || mUpdatingTableSelection )
408408
return;
409409

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

414414
QgsCoordinateTransform t( mLockedFeature->layer()->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() );
415415
std::unique_ptr<QgsRectangle> bbox;
416-
QModelIndexList indexList = selected.indexes();
417-
for ( int i = 0; i < indexList.length(); ++i )
416+
const QModelIndexList indexList = mTableView->selectionModel()->selectedRows();
417+
for ( const QModelIndex &index : indexList )
418418
{
419-
int vertexIdx = indexList.at( i ).row();
419+
int vertexIdx = index.row();
420420
mLockedFeature->selectVertex( vertexIdx );
421421

422422
// create a bounding box of selected vertices
@@ -497,3 +497,5 @@ void CoordinateItemDelegate::setModelData( QWidget *editor, QAbstractItemModel *
497497
QStyledItemDelegate::setModelData( editor, model, index );
498498
}
499499
}
500+
501+

src/app/vertextool/qgsvertexeditor.h

+36-8
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,48 @@
1919
#ifndef QGSVERTEXEDITOR_H
2020
#define QGSVERTEXEDITOR_H
2121

22-
#include "qgsdockwidget.h"
2322
#include <QAbstractTableModel>
2423
#include <QItemSelection>
2524
#include <QStyledItemDelegate>
2625

26+
#include "qgis_app.h"
27+
#include "qgsdockwidget.h"
28+
#include "qgspoint.h"
29+
30+
class QLabel;
31+
class QTableView;
32+
2733
class QgsMapCanvas;
2834
class QgsLockedFeature;
2935
class QgsVectorLayer;
3036

31-
class QLabel;
32-
class QTableView;
3337

34-
class QgsVertexEditorModel : public QAbstractTableModel
38+
class APP_EXPORT QgsVertexEntry
39+
{
40+
public:
41+
QgsVertexEntry( const QgsPoint &p,
42+
QgsVertexId vertexId )
43+
: mSelected( false )
44+
, mPoint( p )
45+
, mVertexId( vertexId )
46+
{
47+
}
48+
49+
QgsVertexEntry( const QgsVertexEntry &rh ) = delete;
50+
QgsVertexEntry &operator=( const QgsVertexEntry &rh ) = delete;
51+
52+
const QgsPoint &point() const { return mPoint; }
53+
QgsVertexId vertexId() const { return mVertexId; }
54+
bool isSelected() const { return mSelected; }
55+
void setSelected( bool selected ) { mSelected = selected; }
56+
57+
private:
58+
bool mSelected;
59+
QgsPoint mPoint;
60+
QgsVertexId mVertexId;
61+
};
62+
63+
class APP_EXPORT QgsVertexEditorModel : public QAbstractTableModel
3564
{
3665
Q_OBJECT
3766
public:
@@ -65,13 +94,12 @@ class QgsVertexEditorModel : public QAbstractTableModel
6594

6695
};
6796

68-
class QgsVertexEditor : public QgsDockWidget
97+
class APP_EXPORT QgsVertexEditor : public QgsDockWidget
6998
{
7099
Q_OBJECT
71100
public:
72101
QgsVertexEditor( QgsMapCanvas *canvas );
73102

74-
public:
75103
void updateEditor( QgsLockedFeature *lockedFeature );
76104
QgsLockedFeature *mLockedFeature = nullptr;
77105
QgsMapCanvas *mCanvas = nullptr;
@@ -88,7 +116,7 @@ class QgsVertexEditor : public QgsDockWidget
88116

89117
private slots:
90118
void updateTableSelection();
91-
void updateVertexSelection( const QItemSelection &selected, const QItemSelection &deselected );
119+
void updateVertexSelection( const QItemSelection &, const QItemSelection &deselected );
92120

93121
private:
94122

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

101129

102-
class CoordinateItemDelegate : public QStyledItemDelegate
130+
class APP_EXPORT CoordinateItemDelegate : public QStyledItemDelegate
103131
{
104132
Q_OBJECT
105133

src/app/vertextool/qgsvertexentry.cpp

-83
This file was deleted.

src/app/vertextool/qgsvertexentry.h

-61
This file was deleted.

0 commit comments

Comments
 (0)