Skip to content
Permalink
Browse files

[processing] Allow access to advanced per-feature-source input settings

via a new "options" button next to the source input box
  • Loading branch information
nyalldawson committed Mar 24, 2020
1 parent c040822 commit bff71e4bea129c02d409bb209ec14c7948074963
@@ -183,6 +183,7 @@ void QgsProcessingAlgorithmDialogBase::setMainWidget( QgsPanelWidget *widget )
}

mPanelStack->setMainPanel( widget );
widget->setDockMode( true );

mMainWidget = widget;
}
@@ -22,6 +22,8 @@
#include "qgsfeatureid.h"
#include "qgsapplication.h"
#include "qgsguiutils.h"
#include "qgspanelwidget.h"
#include "qgsprocessingfeaturesourceoptionswidget.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QToolButton>
@@ -62,10 +64,23 @@ QgsProcessingMapLayerComboBox::QgsProcessingMapLayerComboBox( const QgsProcessin

// button width is 1.25 * icon size, height 1.1 * icon size. But we round to ensure even pixel sizes for equal margins
mIterateButton->setFixedSize( 2 * static_cast< int >( 1.25 * iconSize / 2.0 ), 2 * static_cast< int >( iconSize * 1.1 / 2.0 ) );

mIterateButton->setIconSize( QSize( iconSize, iconSize ) );

layout->addWidget( mIterateButton );
layout->setAlignment( mIterateButton, Qt::AlignTop );

mSettingsButton = new QToolButton();
mSettingsButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionOptions.svg" ) ) );
mSettingsButton->setToolTip( tr( "Advanced options" ) );

// button width is 1.25 * icon size, height 1.1 * icon size. But we round to ensure even pixel sizes for equal margins
mSettingsButton->setFixedSize( 2 * static_cast< int >( 1.25 * iconSize / 2.0 ), 2 * static_cast< int >( iconSize * 1.1 / 2.0 ) );
mSettingsButton->setIconSize( QSize( iconSize, iconSize ) );
mSettingsButton->setAutoRaise( true );

connect( mSettingsButton, &QToolButton::clicked, this, &QgsProcessingMapLayerComboBox::showSourceOptions );
layout->addWidget( mSettingsButton );
layout->setAlignment( mSettingsButton, Qt::AlignTop );
}

QVBoxLayout *vl = new QVBoxLayout();
@@ -191,6 +206,15 @@ void QgsProcessingMapLayerComboBox::setValue( const QVariant &value, QgsProcessi
val = fromVar.source;
selectedOnly = fromVar.selectedFeaturesOnly;
iterate = fromVar.flags & QgsProcessingFeatureSourceDefinition::Flag::FlagCreateIndividualOutputPerInputFeature;
mFeatureLimit = fromVar.featureLimit;
mIsOverridingDefaultGeometryCheck = fromVar.flags & QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck;
mGeometryCheck = fromVar.geometryCheck;
}
else
{
mFeatureLimit = -1;
mIsOverridingDefaultGeometryCheck = false;
mGeometryCheck = QgsFeatureRequest::GeometryAbortOnInvalid;
}

if ( val.canConvert<QgsProperty>() )
@@ -281,17 +305,23 @@ QVariant QgsProcessingMapLayerComboBox::value() const
const bool selectedOnly = mUseSelectionCheckBox && mUseSelectionCheckBox->isChecked();
if ( QgsMapLayer *layer = mCombo->currentLayer() )
{
if ( selectedOnly || iterate )
return QgsProcessingFeatureSourceDefinition( layer->id(), selectedOnly, -1, iterate ? QgsProcessingFeatureSourceDefinition::Flag::FlagCreateIndividualOutputPerInputFeature : QgsProcessingFeatureSourceDefinition::Flags() );
if ( selectedOnly || iterate || mFeatureLimit != -1 || mIsOverridingDefaultGeometryCheck )
return QgsProcessingFeatureSourceDefinition( layer->id(), selectedOnly, mFeatureLimit,
( iterate ? QgsProcessingFeatureSourceDefinition::Flag::FlagCreateIndividualOutputPerInputFeature : QgsProcessingFeatureSourceDefinition::Flags() )
| ( mIsOverridingDefaultGeometryCheck ? QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck : QgsProcessingFeatureSourceDefinition::Flags() ),
mGeometryCheck );
else
return layer->id();
}
else
{
if ( !mCombo->currentText().isEmpty() )
{
if ( selectedOnly || iterate )
return QgsProcessingFeatureSourceDefinition( mCombo->currentText(), selectedOnly, -1, iterate ? QgsProcessingFeatureSourceDefinition::Flag::FlagCreateIndividualOutputPerInputFeature : QgsProcessingFeatureSourceDefinition::Flags() );
if ( selectedOnly || iterate || mFeatureLimit != -1 || mIsOverridingDefaultGeometryCheck )
return QgsProcessingFeatureSourceDefinition( mCombo->currentText(), selectedOnly, mFeatureLimit,
( iterate ? QgsProcessingFeatureSourceDefinition::Flag::FlagCreateIndividualOutputPerInputFeature : QgsProcessingFeatureSourceDefinition::Flags() )
| ( mIsOverridingDefaultGeometryCheck ? QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck : QgsProcessingFeatureSourceDefinition::Flags() ),
mGeometryCheck );
else
return mCombo->currentText();
}
@@ -522,6 +552,35 @@ void QgsProcessingMapLayerComboBox::selectionChanged( const QgsFeatureIds &selec
mUseSelectionCheckBox->setEnabled( !selected.isEmpty() );
}

void QgsProcessingMapLayerComboBox::showSourceOptions()
{
if ( QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this ) )
{
QgsProcessingFeatureSourceOptionsWidget *widget = new QgsProcessingFeatureSourceOptionsWidget();
widget->setPanelTitle( tr( "%1 Options" ).arg( mParameter->description() ) );

widget->setGeometryCheckMethod( mIsOverridingDefaultGeometryCheck, mGeometryCheck );
widget->setFeatureLimit( mFeatureLimit );

panel->openPanel( widget );

connect( widget, &QgsPanelWidget::widgetChanged, this, [ = ]
{
bool changed = false;
changed = changed | ( widget->featureLimit() != mFeatureLimit );
changed = changed | ( widget->isOverridingInvalidGeometryCheck() != mIsOverridingDefaultGeometryCheck );
changed = changed | ( widget->geometryCheckMethod() != mGeometryCheck );

mFeatureLimit = widget->featureLimit();
mIsOverridingDefaultGeometryCheck = widget->isOverridingInvalidGeometryCheck();
mGeometryCheck = widget->geometryCheckMethod();

if ( changed )
emit valueChanged();
} );
}
}



///@endcond
@@ -115,14 +115,19 @@ class GUI_EXPORT QgsProcessingMapLayerComboBox : public QWidget

void onLayerChanged( QgsMapLayer *layer );
void selectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect );
void showSourceOptions();

private:
std::unique_ptr< QgsProcessingParameterDefinition > mParameter;
QgsMapLayerComboBox *mCombo = nullptr;
QToolButton *mSelectButton = nullptr;
QToolButton *mIterateButton = nullptr;
QToolButton *mSettingsButton = nullptr;
QCheckBox *mUseSelectionCheckBox = nullptr;
bool mDragActive = false;
long long mFeatureLimit = -1;
bool mIsOverridingDefaultGeometryCheck = false;
QgsFeatureRequest::InvalidGeometryCheck mGeometryCheck = QgsFeatureRequest::GeometryAbortOnInvalid;
QPointer< QgsMapLayer> mPrevLayer;
int mBlockChangedSignal = 0;
QgsMapLayer *compatibleMapLayerFromMimeData( const QMimeData *data, bool &incompatibleLayerSelected ) const;
@@ -117,7 +117,7 @@
<string>…</string>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<iconset>
<normaloff>:/images/themes/default/mActionFileSave.svg</normaloff>:/images/themes/default/mActionFileSave.svg</iconset>
</property>
<property name="autoRaise">
@@ -134,7 +134,7 @@
<string>…</string>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<iconset>
<normaloff>:/images/themes/default/mActionEditCopy.svg</normaloff>:/images/themes/default/mActionEditCopy.svg</iconset>
</property>
<property name="autoRaise">
@@ -151,7 +151,7 @@
<string>…</string>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<iconset>
<normaloff>:/images/themes/default/console/iconClearConsole.svg</normaloff>:/images/themes/default/console/iconClearConsole.svg</iconset>
</property>
<property name="autoRaise">
@@ -228,10 +228,6 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
</resources>
<resources/>
<connections/>
</ui>
@@ -7783,7 +7783,7 @@ void TestQgsProcessing::processingFeatureSource()
QgsProcessingFeatureSourceDefinition fs( sourceString, true, 21, QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck, QgsFeatureRequest::GeometrySkipInvalid );
QCOMPARE( fs.source.staticValue().toString(), sourceString );
QVERIFY( fs.selectedFeaturesOnly );
QCOMPARE( fs.featureLimit, 21 );
QCOMPARE( fs.featureLimit, 21LL );
QCOMPARE( fs.flags, QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck );
QCOMPARE( fs.geometryCheck, QgsFeatureRequest::GeometrySkipInvalid );

@@ -7797,14 +7797,14 @@ void TestQgsProcessing::processingFeatureSource()
QVERIFY( dd.loadVariant( res.toMap() ) );
QCOMPARE( dd.source.staticValue().toString(), sourceString );
QVERIFY( dd.selectedFeaturesOnly );
QCOMPARE( dd.featureLimit, 21 );
QCOMPARE( dd.featureLimit, 21LL );
QCOMPARE( dd.flags, QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck );
QCOMPARE( dd.geometryCheck, QgsFeatureRequest::GeometrySkipInvalid );

QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( fsInVariant );
QCOMPARE( fromVar.source.staticValue().toString(), sourceString );
QVERIFY( fromVar.selectedFeaturesOnly );
QCOMPARE( fromVar.featureLimit, 21 );
QCOMPARE( fromVar.featureLimit, 21LL );
QCOMPARE( fromVar.flags, QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck );
QCOMPARE( fromVar.geometryCheck, QgsFeatureRequest::GeometrySkipInvalid );

@@ -4053,6 +4053,22 @@ void TestProcessingGui::mapLayerComboBox()
combo->setValue( sourceDef, context );
QVERIFY( !( combo->value().value< QgsProcessingFeatureSourceDefinition >().flags & QgsProcessingFeatureSourceDefinition::Flag::FlagCreateIndividualOutputPerInputFeature ) );

// advanced settings
sourceDef.featureLimit = 67;
combo->setValue( sourceDef, context );
QCOMPARE( combo->value().value< QgsProcessingFeatureSourceDefinition >().featureLimit, 67LL );
sourceDef.featureLimit = -1;
combo->setValue( sourceDef, context );
QCOMPARE( combo->value().value< QgsProcessingFeatureSourceDefinition >().featureLimit, -1LL );
sourceDef.flags |= QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck;
sourceDef.geometryCheck = QgsFeatureRequest::GeometrySkipInvalid;
combo->setValue( sourceDef, context );
QVERIFY( combo->value().value< QgsProcessingFeatureSourceDefinition >().flags & QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck );
QCOMPARE( combo->value().value< QgsProcessingFeatureSourceDefinition >().geometryCheck, QgsFeatureRequest::GeometrySkipInvalid );
sourceDef.flags = nullptr;
combo->setValue( sourceDef, context );
QVERIFY( !( combo->value().value< QgsProcessingFeatureSourceDefinition >().flags & QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck ) );

combo.reset();
param.reset();

0 comments on commit bff71e4

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