Skip to content

Commit

Permalink
Add a way to set split feature sort expression in the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
JuhoErvasti committed Dec 10, 2024
1 parent ae5f79b commit 1716ddb
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/app/qgsvectorlayerdigitizingproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgsanalysis.h"
#include "qgscollapsiblegroupbox.h"
#include "qgsdoublespinbox.h"
#include "qgsexpressioncontextutils.h"
#include "qgsgeometrycheckfactory.h"
#include "qgsgeometrycheckregistry.h"
#include "qgsgeometrycheck.h"
Expand Down Expand Up @@ -118,12 +119,29 @@ QgsVectorLayerDigitizingPropertiesPage::QgsVectorLayerDigitizingPropertiesPage(
}
mTopologyChecksGroupBox->setLayout( topologyCheckLayout );
mTopologyChecksGroupBox->setVisible( !topologyCheckFactories.isEmpty() );

if ( vlayer->geometryType() != Qgis::GeometryType::Point )
{
const QString splitFeaturesOrderByExpression = vlayer->geometryOptions()->splitFeaturesOrderByExpression();
const Qt::SortOrder splitFeaturesSortOrder = vlayer->geometryOptions()->splitFeaturesSortOrder();
mSplitFeaturesExpressionLineEdit->setExpression( splitFeaturesOrderByExpression );
mSplitFeaturesOrderComboBox->setCurrentIndex( splitFeaturesSortOrder );

mSplitFeaturesExpressionLineEdit->setExpectedOutputFormat( tr( "numeric" ) );
mSplitFeaturesExpressionLineEdit->registerExpressionContextGenerator( this );
mSplitFeaturesExpressionLineEdit->setLayer( vlayer );
}
else
{
mSplitFeaturesSortGroupBox->hide();
}
}
else
{
mRemoveDuplicateNodesCheckbox->setEnabled( false );
mGeometryPrecisionLineEdit->setEnabled( false );
mGeometryAutoFixesGroupBox->setEnabled( false );
mSplitFeaturesSortGroupBox->setEnabled( false );
}

setProperty( "helpPage", QStringLiteral( "working_with_vector/vector_properties.html#digitizing-properties" ) );
Expand Down Expand Up @@ -163,8 +181,20 @@ void QgsVectorLayerDigitizingPropertiesPage::apply()

vlayer->geometryOptions()->setCheckConfiguration( QStringLiteral( "QgsGeometryGapCheck" ), gapCheckConfig );
}

vlayer->geometryOptions()->setSplitFeaturesOrderByExpression( mSplitFeaturesExpressionLineEdit->expression() );
vlayer->geometryOptions()->setSplitFeaturesSortOrder( static_cast<Qt::SortOrder>( mSplitFeaturesOrderComboBox->currentIndex() ) );
}

QgsExpressionContext QgsVectorLayerDigitizingPropertiesPage::createExpressionContext() const
{
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
context << QgsExpressionContextUtils::splitFeaturesScope( QgsGeometry() );

context.setHighlightedVariables( QStringList() << QStringLiteral( "split_geometry" ) );

return context;
}

QgsVectorLayerDigitizingPropertiesFactory::QgsVectorLayerDigitizingPropertiesFactory( QObject *parent )
: QObject( parent )
Expand Down
12 changes: 10 additions & 2 deletions src/app/qgsvectorlayerdigitizingproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef QGSVECTORLAYERDIGITIZINGPROPERTIES_H
#define QGSVECTORLAYERDIGITIZINGPROPERTIES_H

#include "qgsexpressioncontextgenerator.h"
#include "qgsmaplayerconfigwidget.h"
#include "qgsmaplayerconfigwidgetfactory.h"
#include "ui_qgsvectorlayerdigitizingproperties.h"
Expand All @@ -26,15 +27,22 @@ class QgsMapLayerComboBox;
class QgsDoubleSpinBox;


class QgsVectorLayerDigitizingPropertiesPage : public QgsMapLayerConfigWidget, private Ui::QgsVectorLayerDigitizingPropertiesPage
class QgsVectorLayerDigitizingPropertiesPage : public QgsMapLayerConfigWidget, private Ui::QgsVectorLayerDigitizingPropertiesPage, private QgsExpressionContextGenerator
{
Q_OBJECT

public:
explicit QgsVectorLayerDigitizingPropertiesPage( QgsMapLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr );

/*
* Creates the expression context for this widget.
*
* \since QGIS 3.42
*/
QgsExpressionContext createExpressionContext() const override;

public slots:
virtual void apply();
virtual void apply() override;

private:
bool mRemoveDuplicateNodesManuallyActivated = false;
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsgeometryoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsgeometryoptions.h"
#include "moc_qgsgeometryoptions.cpp"
#include "qgsxmlutils.h"
#include "qgssettingsentryimpl.h"
#include "qgssettingstree.h"
Expand Down
48 changes: 48 additions & 0 deletions src/ui/qgsvectorlayerdigitizingproperties.ui
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,48 @@
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="mSplitFeaturesSortGroupBox">
<property name="title">
<string>Split features</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Controls the order in which the split features digitizing tool creates new features, for example according to the split geometries using the @split_geometry variable. This affects autogenerating fields (such as id fields) so that the first feature in the resulting list will inherit the original feature's attributes.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Sort expression</string>
</property>
</widget>
</item>
<item>
<widget class="QgsExpressionLineEdit" name="mSplitFeaturesExpressionLineEdit" native="true"/>
</item>
<item>
<widget class="QComboBox" name="mSplitFeaturesOrderComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Ascending</string>
</property>
</item>
<item>
<property name="text">
<string>Descending</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
Expand All @@ -146,6 +188,12 @@
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsExpressionLineEdit</class>
<extends>QWidget</extends>
<header>qgsexpressionlineedit.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down

0 comments on commit 1716ddb

Please sign in to comment.