Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make geometry validation automatic resolutions experimental
The automatic resolutions work unreliably (mostly due to geometry precision) and
therefore cannot be use reliably. Therefore they should rather be treated as a
technology preview which can be opted into for the moment.
  • Loading branch information
m-kuhn committed Mar 18, 2019
1 parent 9cc86fb commit de6a27d
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 12 deletions.
23 changes: 23 additions & 0 deletions python/core/auto_generated/qgsgeometryoptions.sip.in
Expand Up @@ -116,6 +116,24 @@ Write the geometry options to the ``node``.
Read the geometry options from ``node``.

.. versionadded:: 3.4
%End

bool automaticProblemResolutionEnabled() const;
%Docstring
Automatic problem resolution offers strategies to fix errors with
a single click.
This is currently experimental

.. versionadded:: 3.8
%End

void setAutomaticProblemResolutionEnabled( bool automaticProblemResolutionEnabled );
%Docstring
Automatic problem resolution offers strategies to fix errors with
a single click.
This is currently experimental

.. versionadded:: 3.8
%End

signals:
Expand Down Expand Up @@ -148,6 +166,11 @@ Geometries which are edited on this layer will be rounded to multiples of this v
Set to 0.0 to disable.

.. versionadded:: 3.4
%End

void automaticProblemResolutionEnabledChanged();
%Docstring
Defines if the automatic fixes
%End

};
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgsgeometryvalidationdock.cpp
Expand Up @@ -150,6 +150,14 @@ void QgsGeometryValidationDock::onRowsInserted()
setUserVisible( true );
}

void QgsGeometryValidationDock::updateResolutionWidgetVisibility()
{
if ( !mCurrentLayer )
return;

mResolutionWidget->setVisible( mCurrentLayer->geometryOptions()->automaticProblemResolutionEnabled() );
}

QgsGeometryValidationService *QgsGeometryValidationDock::geometryValidationService() const
{
return mGeometryValidationService;
Expand Down Expand Up @@ -258,6 +266,8 @@ void QgsGeometryValidationDock::onCurrentLayerChanged( QgsMapLayer *layer )
disconnect( mCurrentLayer, &QgsVectorLayer::editingStarted, this, &QgsGeometryValidationDock::onLayerEditingStatusChanged );
disconnect( mCurrentLayer, &QgsVectorLayer::editingStopped, this, &QgsGeometryValidationDock::onLayerEditingStatusChanged );
disconnect( mCurrentLayer, &QgsVectorLayer::destroyed, this, &QgsGeometryValidationDock::onLayerDestroyed );
disconnect( mCurrentLayer->geometryOptions(), &QgsGeometryOptions::automaticProblemResolutionEnabledChanged, this, &QgsGeometryValidationDock::updateResolutionWidgetVisibility );
updateResolutionWidgetVisibility();
}

mCurrentLayer = qobject_cast<QgsVectorLayer *>( layer );
Expand All @@ -267,6 +277,7 @@ void QgsGeometryValidationDock::onCurrentLayerChanged( QgsMapLayer *layer )
connect( mCurrentLayer, &QgsVectorLayer::editingStarted, this, &QgsGeometryValidationDock::onLayerEditingStatusChanged );
connect( mCurrentLayer, &QgsVectorLayer::editingStopped, this, &QgsGeometryValidationDock::onLayerEditingStatusChanged );
connect( mCurrentLayer, &QgsVectorLayer::destroyed, this, &QgsGeometryValidationDock::onLayerDestroyed );
connect( mCurrentLayer->geometryOptions(), &QgsGeometryOptions::automaticProblemResolutionEnabledChanged, this, &QgsGeometryValidationDock::updateResolutionWidgetVisibility );
}

onLayerEditingStatusChanged();
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsgeometryvalidationdock.h
Expand Up @@ -56,6 +56,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
void updateLayerTransform();
void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles );
void onRowsInserted();
void updateResolutionWidgetVisibility();

private:

Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -461,12 +461,14 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
}
mTopologyChecksGroupBox->setLayout( topologyCheckLayout );
mTopologyChecksGroupBox->setVisible( !topologyCheckFactories.isEmpty() );
mAutomaticProblemResolutionCheckbox->setChecked( mLayer->geometryOptions()->automaticProblemResolutionEnabled() );
}
else
{
mRemoveDuplicateNodesCheckbox->setEnabled( false );
mGeometryPrecisionLineEdit->setEnabled( false );
mGeometryAutoFixesGroupBox->setEnabled( false );
mAutomaticProblemResolutionCheckbox->setEnabled( false );
}

mOptsPage_Information->setProperty( "helpPage", QStringLiteral( "working_with_vector/vector_properties.html#information-properties" ) );
Expand Down Expand Up @@ -842,6 +844,7 @@ void QgsVectorLayerProperties::apply()
activeChecks << it.value();
}
mLayer->geometryOptions()->setGeometryChecks( activeChecks );
mLayer->geometryOptions()->setAutomaticProblemResolutionEnabled( mAutomaticProblemResolutionCheckbox->isChecked() );

mLayer->triggerRepaint();
// notify the project we've made a change
Expand Down
14 changes: 13 additions & 1 deletion src/core/qgsgeometryoptions.cpp
Expand Up @@ -52,7 +52,7 @@ void QgsGeometryOptions::apply( QgsGeometry &geometry ) const
geometry = geometry.snappedToGrid( mGeometryPrecision, mGeometryPrecision );

if ( mRemoveDuplicateNodes )
geometry.removeDuplicateNodes();
geometry.removeDuplicateNodes( 4 * std::numeric_limits<double>::epsilon(), true );
}

QStringList QgsGeometryOptions::geometryChecks() const
Expand Down Expand Up @@ -108,3 +108,15 @@ void QgsGeometryOptions::readXml( const QDomNode &node )
const QVariant checkConfiguration = QgsXmlUtils::readVariant( checkConfigurationElem );
mCheckConfiguration = checkConfiguration.toMap();
}

bool QgsGeometryOptions::automaticProblemResolutionEnabled() const
{
return mAutomaticProblemResolutionEnabled;
}

void QgsGeometryOptions::setAutomaticProblemResolutionEnabled( bool automaticFixesEnabled )
{
if ( automaticFixesEnabled != mAutomaticProblemResolutionEnabled )
mAutomaticProblemResolutionEnabled = automaticFixesEnabled;
emit automaticProblemResolutionEnabledChanged();
}
24 changes: 24 additions & 0 deletions src/core/qgsgeometryoptions.h
Expand Up @@ -131,6 +131,24 @@ class CORE_EXPORT QgsGeometryOptions : public QObject
*/
void readXml( const QDomNode &node );

/**
* Automatic problem resolution offers strategies to fix errors with
* a single click.
* This is currently experimental
*
* \since QGIS 3.8
*/
bool automaticProblemResolutionEnabled() const;

/**
* Automatic problem resolution offers strategies to fix errors with
* a single click.
* This is currently experimental
*
* \since QGIS 3.8
*/
void setAutomaticProblemResolutionEnabled( bool automaticProblemResolutionEnabled );

signals:

/**
Expand Down Expand Up @@ -163,6 +181,11 @@ class CORE_EXPORT QgsGeometryOptions : public QObject
*/
void geometryPrecisionChanged();

/**
* Defines if the automatic fixes
*/
void automaticProblemResolutionEnabledChanged();

private:

/**
Expand All @@ -183,6 +206,7 @@ class CORE_EXPORT QgsGeometryOptions : public QObject

QStringList mGeometryChecks;
QVariantMap mCheckConfiguration;
bool mAutomaticProblemResolutionEnabled = false;
};

#endif // QGSGEOMETRYOPTIONS_H
32 changes: 21 additions & 11 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -436,8 +436,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>662</width>
<height>804</height>
<width>315</width>
<height>403</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
Expand Down Expand Up @@ -724,8 +724,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>662</width>
<height>804</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
Expand Down Expand Up @@ -910,8 +910,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>662</width>
<height>804</height>
<width>113</width>
<height>110</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">
Expand Down Expand Up @@ -1305,8 +1305,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>662</width>
<height>804</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_21">
Expand Down Expand Up @@ -1508,7 +1508,7 @@ border-radius: 2px;</string>
<x>0</x>
<y>0</y>
<width>734</width>
<height>790</height>
<height>372</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_32">
Expand Down Expand Up @@ -1964,8 +1964,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>662</width>
<height>804</height>
<width>378</width>
<height>678</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
Expand Down Expand Up @@ -2439,6 +2439,16 @@ border-radius: 2px;</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mAutomaticProblemResolutionCheckbox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This enables additional buttons for check results that will automatically fix problems.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Experimental&lt;/span&gt;&lt;/p&gt;&lt;p&gt;This functionality is tagged as experimental since some of the automatic fixes do not work completely reliable.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Offer automatic problem resolution (Experimental)</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
Expand Down

0 comments on commit de6a27d

Please sign in to comment.