Skip to content
Permalink
Browse files

Clear errors on stop editing

  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent d17011e commit 7f142ad2b644d09f7da3d173f115cd41d4b9da84
@@ -85,6 +85,7 @@ void QgsGeometryValidationDock::setGeometryValidationModel( QgsGeometryValidatio
mErrorListView->setModel( mGeometryValidationModel );

connect( mErrorListView->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsGeometryValidationDock::onCurrentErrorChanged );
connect( mGeometryValidationModel, &QgsGeometryValidationModel::dataChanged, this, &QgsGeometryValidationDock::onDataChanged );
connect( mGeometryValidationModel, &QgsGeometryValidationModel::rowsRemoved, this, &QgsGeometryValidationDock::updateCurrentError );
connect( mGeometryValidationModel, &QgsGeometryValidationModel::rowsInserted, this, &QgsGeometryValidationDock::onRowsInserted );
}
@@ -141,6 +142,15 @@ void QgsGeometryValidationDock::updateLayerTransform()
mLayerTransform = QgsCoordinateTransform( mMapCanvas->currentLayer()->crs(), mMapCanvas->mapSettings().destinationCrs(), mMapCanvas->mapSettings().transformContext() );
}

void QgsGeometryValidationDock::onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles )
{
Q_UNUSED( bottomRight )
Q_UNUSED( roles )

if ( currentIndex() == topLeft )
updateCurrentError();
}

void QgsGeometryValidationDock::onRowsInserted()
{
if ( !isVisible() )
@@ -162,9 +172,15 @@ void QgsGeometryValidationDock::setGeometryValidationService( QgsGeometryValidat

void QgsGeometryValidationDock::updateCurrentError()
{
if ( mGeometryValidationModel->rowCount() == 0 )
mErrorListView->selectionModel()->clearCurrentIndex();

mFeatureRubberband->hide();
mFeatureRubberband->update();
mErrorRubberband->hide();
mErrorRubberband->update();
mErrorLocationRubberband->hide();
mErrorLocationRubberband->update();

onCurrentErrorChanged( currentIndex(), QModelIndex() );
}
@@ -200,31 +216,36 @@ void QgsGeometryValidationDock::onCurrentErrorChanged( const QModelIndex &curren
delete w;

delete mResolutionWidget->layout();
const QStringList resolutionMethods = error->check()->resolutionMethods();
QGridLayout *layout = new QGridLayout( mResolutionWidget );
int resolutionIndex = 0;
for ( const QString &resolutionMethod : resolutionMethods )

if ( error->status() != QgsGeometryCheckError::StatusFixed )
{
QToolButton *resolveBtn = new QToolButton( mResolutionWidget );
resolveBtn->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmCheckGeometry.svg" ) ) );
layout->addWidget( resolveBtn, resolutionIndex, 0 );
QLabel *resolveLabel = new QLabel( resolutionMethod, mResolutionWidget );
resolveLabel->setWordWrap( true );
layout->addWidget( resolveLabel, resolutionIndex, 1 );
connect( resolveBtn, &QToolButton::clicked, this, [resolutionIndex, error, this]()
const QStringList resolutionMethods = error->check()->resolutionMethods();
QGridLayout *layout = new QGridLayout( mResolutionWidget );
int resolutionIndex = 0;
for ( const QString &resolutionMethod : resolutionMethods )
{
mGeometryValidationService->fixError( error, resolutionIndex );
} );
resolutionIndex++;
QToolButton *resolveBtn = new QToolButton( mResolutionWidget );
resolveBtn->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmCheckGeometry.svg" ) ) );
layout->addWidget( resolveBtn, resolutionIndex, 0 );
QLabel *resolveLabel = new QLabel( resolutionMethod, mResolutionWidget );
resolveLabel->setWordWrap( true );
layout->addWidget( resolveLabel, resolutionIndex, 1 );
connect( resolveBtn, &QToolButton::clicked, this, [resolutionIndex, error, this]()
{
mGeometryValidationService->fixError( error, resolutionIndex );
} );
resolutionIndex++;
}

mResolutionWidget->setLayout( layout );

showHighlight( current );
}
mResolutionWidget->setLayout( layout );
}

bool hasFeature = !FID_IS_NULL( current.data( QgsGeometryValidationModel::ErrorFeatureIdRole ) );
mZoomToFeatureButton->setEnabled( hasFeature );

showHighlight( current );

switch ( mLastZoomToAction )
{
case ZoomToProblem:
@@ -52,6 +52,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
void zoomToFeature();
void triggerTopologyChecks();
void updateLayerTransform();
void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles );
void onRowsInserted();

private:
@@ -143,6 +143,12 @@ void QgsGeometryValidationService::onBeforeCommitChanges( QgsVectorLayer *layer
}
}

void QgsGeometryValidationService::onEditingStopped( QgsVectorLayer *layer )
{
cancelTopologyCheck( layer );
clearTopologyChecks( layer );
}

void QgsGeometryValidationService::cleanupLayerChecks( QgsVectorLayer *layer )
{
if ( !mLayerChecks.contains( layer ) )
@@ -256,6 +262,11 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
{
onBeforeCommitChanges( layer );
}, Qt::UniqueConnection );
checkInformation.connections
<< connect( layer, &QgsVectorLayer::editingStopped, this, [this, layer]()
{
onEditingStopped( layer );
}, Qt::UniqueConnection );
}

void QgsGeometryValidationService::cancelTopologyCheck( QgsVectorLayer *layer )
@@ -279,6 +290,14 @@ void QgsGeometryValidationService::cancelTopologyCheck( QgsVectorLayer *layer )
}
}

void QgsGeometryValidationService::clearTopologyChecks( QgsVectorLayer *layer )
{
QList<std::shared_ptr<QgsGeometryCheckError>> &allErrors = mLayerChecks[layer].topologyCheckErrors;
allErrors.clear();

emit topologyChecksCleared( layer );
}

void QgsGeometryValidationService::invalidateTopologyChecks( QgsVectorLayer *layer )
{
cancelTopologyCheck( layer );
@@ -309,8 +328,8 @@ void QgsGeometryValidationService::processFeature( QgsVectorLayer *layer, QgsFea

void QgsGeometryValidationService::triggerTopologyChecks( QgsVectorLayer *layer )
{
emit topologyChecksCleared( layer );
cancelTopologyCheck( layer );
clearTopologyChecks( layer );

QgsFeatureIds affectedFeatureIds;
if ( layer->editBuffer() )
@@ -327,7 +346,7 @@ void QgsGeometryValidationService::triggerTopologyChecks( QgsVectorLayer *layer
}

QList<std::shared_ptr<QgsGeometryCheckError>> &allErrors = mLayerChecks[layer].topologyCheckErrors;
allErrors.clear();

QMap<QString, QgsFeatureIds> layerIds;

QgsFeatureRequest request = QgsFeatureRequest( affectedFeatureIds ).setSubsetOfAttributes( QgsAttributeList() );
@@ -79,13 +79,16 @@ class QgsGeometryValidationService : public QObject
void onGeometryChanged( QgsVectorLayer *layer, QgsFeatureId fid, const QgsGeometry &geometry );
void onFeatureDeleted( QgsVectorLayer *layer, QgsFeatureId fid );
void onBeforeCommitChanges( QgsVectorLayer *layer );
void onEditingStopped( QgsVectorLayer *layer );

private:
void cleanupLayerChecks( QgsVectorLayer *layer );
void enableLayerChecks( QgsVectorLayer *layer );

void cancelTopologyCheck( QgsVectorLayer *layer );

void clearTopologyChecks( QgsVectorLayer *layer );

void invalidateTopologyChecks( QgsVectorLayer *layer );

void processFeature( QgsVectorLayer *layer, QgsFeatureId fid );

0 comments on commit 7f142ad

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