Skip to content

Commit

Permalink
Clear errors on stop editing
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent d17011e commit 7f142ad
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 19 deletions.
55 changes: 38 additions & 17 deletions src/app/qgsgeometryvalidationdock.cpp
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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() )
Expand All @@ -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() );
}
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsgeometryvalidationdock.h
Expand Up @@ -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:
Expand Down
23 changes: 21 additions & 2 deletions src/app/qgsgeometryvalidationservice.cpp
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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 )
Expand All @@ -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 );
Expand Down Expand Up @@ -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() )
Expand All @@ -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() );
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsgeometryvalidationservice.h
Expand Up @@ -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 );
Expand Down

0 comments on commit 7f142ad

Please sign in to comment.