void QgsGeometryCheckerResultTab::highlightErrors( bool current ) { qDeleteAll( mCurrentRubberBands ); mCurrentRubberBands.clear(); QList<QTableWidgetItem*> items; QList<QgsPoint> errorPositions; QgsRectangle totextent; if ( current ) { items.append( ui.tableWidgetErrors->currentItem() ); } else { items.append( ui.tableWidgetErrors->selectedItems() ); } foreach ( QTableWidgetItem* item, items ) { QgsGeometryCheckError* error = ui.tableWidgetErrors->item( item->row(), 0 )->data( Qt::UserRole ).value<QgsGeometryCheckError*>(); QgsAbstractGeometryV2* geometry = error->geometry(); if ( ui.checkBoxHighlight->isChecked() && geometry ) { QgsRubberBand* featureRubberBand = new QgsRubberBand( mIface->mapCanvas() ); QgsGeometry geom( geometry ); featureRubberBand->addGeometry( &geom, mFeaturePool->getLayer() ); featureRubberBand->setWidth( 5 ); featureRubberBand->setColor( Qt::yellow ); mCurrentRubberBands.append( featureRubberBand ); } else { // QgsGeometry above takes ownership of geometry and deletes it when it goes out of scope delete geometry; geometry = 0; } if ( ui.radioButtonError->isChecked() || current || error->status() == QgsGeometryCheckError::StatusFixed ) { QgsRubberBand* pointRubberBand = new QgsRubberBand( mIface->mapCanvas(), QGis::Point ); QgsPoint pos = mIface->mapCanvas()->mapSettings().layerToMapCoordinates( mFeaturePool->getLayer(), QgsPoint( error->location().x(), error->location().y() ) ); pointRubberBand->addPoint( pos ); pointRubberBand->setWidth( 20 ); pointRubberBand->setColor( Qt::red ); mCurrentRubberBands.append( pointRubberBand ); errorPositions.append( pos ); } else if ( ui.radioButtonFeature->isChecked() && geometry ) { QgsRectangle geomextent = mIface->mapCanvas()->mapSettings().layerExtentToOutputExtent( mFeaturePool->getLayer(), geometry->boundingBox() ); if ( totextent.isEmpty() ) { totextent = geomextent; } else { totextent.unionRect( geomextent ); } } }
void QgsGeometryCheckerResultTab::highlightErrors( bool current ) { qDeleteAll( mCurrentRubberBands ); mCurrentRubberBands.clear(); QList<QTableWidgetItem *> items; QVector<QgsPointXY> errorPositions; QgsRectangle totextent; if ( current ) { items.append( ui.tableWidgetErrors->currentItem() ); } else { items.append( ui.tableWidgetErrors->selectedItems() ); } for ( QTableWidgetItem *item : qgis::as_const( items ) ) { QgsGeometryCheckError *error = ui.tableWidgetErrors->item( item->row(), 0 )->data( Qt::UserRole ).value<QgsGeometryCheckError *>(); const QgsGeometry geom = error->geometry(); if ( ui.checkBoxHighlight->isChecked() && !geom.isNull() ) { QgsRubberBand *featureRubberBand = new QgsRubberBand( mIface->mapCanvas() ); featureRubberBand->addGeometry( geom, nullptr ); featureRubberBand->setWidth( 5 ); featureRubberBand->setColor( Qt::yellow ); mCurrentRubberBands.append( featureRubberBand ); } if ( ui.radioButtonError->isChecked() || current || error->status() == QgsGeometryCheckError::StatusFixed ) { QgsRubberBand *pointRubberBand = new QgsRubberBand( mIface->mapCanvas(), QgsWkbTypes::PointGeometry ); pointRubberBand->addPoint( error->location() ); pointRubberBand->setWidth( 20 ); pointRubberBand->setColor( Qt::red ); mCurrentRubberBands.append( pointRubberBand ); errorPositions.append( error->location() ); } else if ( ui.radioButtonFeature->isChecked() ) { QgsRectangle geomextent = error->affectedAreaBBox(); if ( totextent.isEmpty() ) { totextent = geomextent; } else { totextent.combineExtentWith( geomextent ); } } } // If error positions positions are marked, pan to the center of all positions, // and zoom out if necessary to make all points fit. if ( !errorPositions.isEmpty() ) { double cx = 0., cy = 0.; QgsRectangle pointExtent( errorPositions.first(), errorPositions.first() ); Q_FOREACH ( const QgsPointXY &p, errorPositions ) { cx += p.x(); cy += p.y(); pointExtent.include( p ); }