@@ -15,7 +15,12 @@ email : matthias@opengis.ch
15
15
16
16
#include " qgsgeometryvalidationdock.h"
17
17
#include " qgsgeometryvalidationmodel.h"
18
+ #include " qgsgeometryvalidationservice.h"
18
19
#include " qgsmapcanvas.h"
20
+ #include " qgsrubberband.h"
21
+ #include " qgsvectorlayer.h"
22
+ #include " qgsgeometrycheck.h"
23
+ #include " qgsgeometrycheckerror.h"
19
24
20
25
#include < QButtonGroup>
21
26
@@ -32,8 +37,23 @@ QgsGeometryValidationDock::QgsGeometryValidationDock( const QString &title, QgsM
32
37
connect ( mMapCanvas , &QgsMapCanvas::currentLayerChanged, this , &QgsGeometryValidationDock::updateLayerTransform );
33
38
connect ( mMapCanvas , &QgsMapCanvas::destinationCrsChanged, this , &QgsGeometryValidationDock::updateLayerTransform );
34
39
connect ( mMapCanvas , &QgsMapCanvas::transformContextChanged, this , &QgsGeometryValidationDock::updateLayerTransform );
40
+
41
+ mFeatureRubberband = new QgsRubberBand ( mMapCanvas );
42
+ mErrorRubberband = new QgsRubberBand ( mMapCanvas );
43
+ mErrorLocationRubberband = new QgsRubberBand ( mMapCanvas );
44
+
45
+ double scaleFactor = mMapCanvas ->fontMetrics ().xHeight () * .2 ;
46
+
47
+ mFeatureRubberband ->setColor ( QColor ( 250 , 180 , 180 , 100 ) );
48
+ mFeatureRubberband ->setWidth ( scaleFactor );
49
+ mErrorRubberband ->setColor ( QColor ( 180 , 250 , 180 , 100 ) );
50
+ mErrorRubberband ->setWidth ( scaleFactor );
51
+ mErrorLocationRubberband ->setIcon ( QgsRubberBand::ICON_X );
52
+ mErrorLocationRubberband ->setWidth ( scaleFactor * 3 );
53
+ mErrorLocationRubberband ->setColor ( QColor ( 180 , 180 , 250 , 100 ) );
35
54
}
36
55
56
+
37
57
QgsGeometryValidationModel *QgsGeometryValidationDock::geometryValidationModel () const
38
58
{
39
59
return mGeometryValidationModel ;
@@ -89,6 +109,16 @@ void QgsGeometryValidationDock::updateLayerTransform()
89
109
mLayerTransform = QgsCoordinateTransform ( mMapCanvas ->currentLayer ()->crs (), mMapCanvas ->mapSettings ().destinationCrs (), mMapCanvas ->mapSettings ().transformContext () );
90
110
}
91
111
112
+ QgsGeometryValidationService *QgsGeometryValidationDock::geometryValidationService () const
113
+ {
114
+ return mGeometryValidationService ;
115
+ }
116
+
117
+ void QgsGeometryValidationDock::setGeometryValidationService ( QgsGeometryValidationService *geometryValidationService )
118
+ {
119
+ mGeometryValidationService = geometryValidationService;
120
+ }
121
+
92
122
QModelIndex QgsGeometryValidationDock::currentIndex () const
93
123
{
94
124
return mErrorListView ->selectionModel ()->currentIndex ();
@@ -102,6 +132,38 @@ void QgsGeometryValidationDock::onCurrentErrorChanged( const QModelIndex ¤
102
132
103
133
mProblemDetailWidget ->setVisible ( current.isValid () );
104
134
mProblemDescriptionLabel ->setText ( current.data ().toString () );
135
+ {
136
+ QgsGeometryCheckError *error = current.data ( QgsGeometryValidationModel::GeometryCheckErrorRole ).value <QgsGeometryCheckError *>();
137
+ while ( QPushButton *btn = mResolutionWidget ->findChild <QPushButton *>() )
138
+ delete btn;
139
+ const QStringList resolutionMethods = error->check ()->resolutionMethods ();
140
+ int resolutionIndex = 0 ;
141
+ for ( const QString &resolutionMethod : resolutionMethods )
142
+ {
143
+ QPushButton *resolveBtn = new QPushButton ( resolutionMethod );
144
+ connect ( resolveBtn, &QPushButton::clicked, this , [resolutionIndex, error, this ]()
145
+ {
146
+ mGeometryValidationService ->fixError ( error, resolutionIndex );
147
+ } );
148
+ mResolutionWidget ->layout ()->addWidget ( resolveBtn );
149
+ resolutionIndex++;
150
+ }
151
+ }
152
+
153
+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas ->currentLayer () );
154
+ if ( vlayer )
155
+ {
156
+ QgsGeometry featureGeometry = current.data ( QgsGeometryValidationModel::FeatureGeometryRole ).value <QgsGeometry>();
157
+ QgsGeometry errorGeometry = current.data ( QgsGeometryValidationModel::ErrorGeometryRole ).value <QgsGeometry>();
158
+ QgsPointXY locationGeometry = current.data ( QgsGeometryValidationModel::ErrorLocationGeometryRole ).value <QgsPointXY>();
159
+ qDebug () << " feature geom : " << featureGeometry.asWkt ();
160
+ qDebug () << " error geom : " << errorGeometry.asWkt ();
161
+ qDebug () << " locationgeom : " << QgsGeometry ( new QgsPoint ( locationGeometry ) ).asWkt ();
162
+
163
+ mFeatureRubberband ->setToGeometry ( featureGeometry );
164
+ mErrorRubberband ->setToGeometry ( errorGeometry );
165
+ mErrorLocationRubberband ->setToGeometry ( QgsGeometry ( new QgsPoint ( locationGeometry ) ) );
166
+ }
105
167
106
168
switch ( mLastZoomToAction )
107
169
{
0 commit comments