Skip to content

Commit

Permalink
[processing] widget wrapper for point layer parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Aug 5, 2021
1 parent 63952c1 commit 8e385da
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/gui/processing/qgsprocessingguiregistry.cpp
Expand Up @@ -79,6 +79,7 @@ QgsProcessingGuiRegistry::QgsProcessingGuiRegistry()
addParameterWidgetFactory( new QgsProcessingDxfLayersWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingMeshDatasetGroupsWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingMeshDatasetTimeWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingPointCloudLayerWidgetWrapper() );
}

QgsProcessingGuiRegistry::~QgsProcessingGuiRegistry()
Expand Down
66 changes: 63 additions & 3 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Expand Up @@ -211,7 +211,8 @@ QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes() const
<< QgsProcessingParameterVectorLayer::typeName()
<< QgsProcessingParameterMeshLayer::typeName()
<< QgsProcessingParameterExpression::typeName()
<< QgsProcessingParameterProviderConnection::typeName();
<< QgsProcessingParameterProviderConnection::typeName()
<< QgsProcessingParameterPointCloudLayer::typeName();
}

QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes() const
Expand Down Expand Up @@ -369,7 +370,8 @@ QStringList QgsProcessingCrsWidgetWrapper::compatibleParameterTypes() const
<< QgsProcessingParameterRasterLayer::typeName()
<< QgsProcessingParameterVectorLayer::typeName()
<< QgsProcessingParameterMeshLayer::typeName()
<< QgsProcessingParameterFeatureSource::typeName();
<< QgsProcessingParameterFeatureSource::typeName()
<< QgsProcessingParameterPointCloudLayer::typeName();
}

QStringList QgsProcessingCrsWidgetWrapper::compatibleOutputTypes() const
Expand Down Expand Up @@ -5747,7 +5749,8 @@ QStringList QgsProcessingExtentWidgetWrapper::compatibleParameterTypes() const
<< QgsProcessingParameterFeatureSource::typeName()
<< QgsProcessingParameterRasterLayer::typeName()
<< QgsProcessingParameterVectorLayer::typeName()
<< QgsProcessingParameterMeshLayer::typeName();
<< QgsProcessingParameterMeshLayer::typeName()
<< QgsProcessingParameterPointCloudLayer::typeName();

}

Expand Down Expand Up @@ -5897,6 +5900,7 @@ QStringList QgsProcessingMapLayerWidgetWrapper::compatibleParameterTypes() const
<< QgsProcessingParameterMeshLayer::typeName()
<< QgsProcessingParameterVectorLayer::typeName()
<< QgsProcessingParameterMapLayer::typeName()
<< QgsProcessingParameterPointCloudLayer::typeName()
<< QgsProcessingParameterString::typeName()
<< QgsProcessingParameterExpression::typeName();
}
Expand Down Expand Up @@ -7074,6 +7078,62 @@ QgsProcessingAbstractParameterDefinitionWidget *QgsProcessingMultipleLayerWidget
}


//
// QgsProcessingPointCloudLayerWidgetWrapper
//

QgsProcessingPointCloudLayerWidgetWrapper::QgsProcessingPointCloudLayerWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
: QgsProcessingMapLayerWidgetWrapper( parameter, type, parent )
{

}

QStringList QgsProcessingPointCloudLayerWidgetWrapper::compatibleParameterTypes() const
{
return QStringList()
<< QgsProcessingParameterPointCloudLayer::typeName()
<< QgsProcessingParameterMapLayer::typeName()
<< QgsProcessingParameterString::typeName()
<< QgsProcessingParameterExpression::typeName();
}

QStringList QgsProcessingPointCloudLayerWidgetWrapper::compatibleOutputTypes() const
{
return QStringList()
<< QgsProcessingOutputString::typeName()
// TODO << QgsProcessingOutputPointCloudLayer::typeName()
<< QgsProcessingOutputMapLayer::typeName()
<< QgsProcessingOutputFile::typeName()
<< QgsProcessingOutputFolder::typeName();
}

QString QgsProcessingPointCloudLayerWidgetWrapper::modelerExpressionFormatString() const
{
return tr( "path to a point cloud layer" );
}

QString QgsProcessingPointCloudLayerWidgetWrapper::parameterType() const
{
return QgsProcessingParameterPointCloudLayer::typeName();
}

QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingPointCloudLayerWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
{
return new QgsProcessingPointCloudLayerWidgetWrapper( parameter, type );
}

QgsProcessingAbstractParameterDefinitionWidget *QgsProcessingPointCloudLayerWidgetWrapper::createParameterDefinitionWidget( QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition, const QgsProcessingAlgorithm *algorithm )
{
Q_UNUSED( context );
Q_UNUSED( widgetContext );
Q_UNUSED( definition );
Q_UNUSED( algorithm );

return nullptr;
}



//
// QgsProcessingOutputWidgetWrapper
//
Expand Down
28 changes: 28 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.h
Expand Up @@ -2256,6 +2256,34 @@ class GUI_EXPORT QgsProcessingFolderDestinationWidgetWrapper : public QgsProcess

};

class GUI_EXPORT QgsProcessingPointCloudLayerWidgetWrapper : public QgsProcessingMapLayerWidgetWrapper
{
Q_OBJECT

public:

QgsProcessingPointCloudLayerWidgetWrapper( const QgsProcessingParameterDefinition *parameter = nullptr,
QgsProcessingGui::WidgetType type = QgsProcessingGui::Standard, QWidget *parent = nullptr );

// QgsProcessingParameterWidgetFactoryInterface
QString parameterType() const override;
QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type ) override;
QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
QgsProcessingContext &context,
const QgsProcessingParameterWidgetContext &widgetContext,
const QgsProcessingParameterDefinition *definition = nullptr,
const QgsProcessingAlgorithm *algorithm = nullptr ) override;

protected:
QStringList compatibleParameterTypes() const override;

QStringList compatibleOutputTypes() const override;

QString modelerExpressionFormatString() const override;

};


///@endcond PRIVATE

#endif // QGSPROCESSINGWIDGETWRAPPERIMPL_H
144 changes: 144 additions & 0 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -290,6 +290,7 @@ class TestProcessingGui : public QObject
void testProviderConnectionWrapper();
void testDatabaseSchemaWrapper();
void testDatabaseTableWrapper();
void testPointCloudLayerWrapper();
void testFieldMapWidget();
void testFieldMapWrapper();
void testAggregateWidget();
Expand Down Expand Up @@ -9899,6 +9900,149 @@ void TestProcessingGui::testMeshDatasetWrapperLayerOutsideProject()

}

void TestProcessingGui::testPointCloudLayerWrapper()
{
// setup a project with a range of layer types
QgsProject::instance()->removeAllMapLayers();
QgsPointCloudLayer *cloud1 = new QgsPointCloudLayer( QStringLiteral( TEST_DATA_DIR ) + "/point_clouds/las/cloud.las", QStringLiteral( "cloud1" ), QStringLiteral( "pdal" ) );
QVERIFY( cloud1->isValid() );
QgsProject::instance()->addMapLayer( cloud1 );
QgsPointCloudLayer *cloud2 = new QgsPointCloudLayer( QStringLiteral( TEST_DATA_DIR ) + "/point_clouds/las/cloud.las", QStringLiteral( "cloud2" ), QStringLiteral( "pdal" ) );
QVERIFY( cloud2->isValid() );
QgsProject::instance()->addMapLayer( cloud2 );

auto testWrapper = [ = ]( QgsProcessingGui::WidgetType type )
{
// non optional
QgsProcessingParameterPointCloudLayer param( QStringLiteral( "cloud" ), QStringLiteral( "cloud" ), false );

QgsProcessingPointCloudLayerWidgetWrapper wrapper( &param, type );

QgsProcessingContext context;
QWidget *w = wrapper.createWrappedWidget( context );

QSignalSpy spy( &wrapper, &QgsProcessingPointCloudLayerWidgetWrapper::widgetValueHasChanged );
wrapper.setWidgetValue( QStringLiteral( "bb" ), context );

switch ( type )
{
case QgsProcessingGui::Standard:
case QgsProcessingGui::Batch:
case QgsProcessingGui::Modeler:
QCOMPARE( spy.count(), 1 );
QCOMPARE( wrapper.widgetValue().toString(), QStringLiteral( "bb" ) );
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper.wrappedWidget() )->currentText(), QStringLiteral( "bb" ) );
wrapper.setWidgetValue( QStringLiteral( "aa" ), context );
QCOMPARE( spy.count(), 2 );
QCOMPARE( wrapper.widgetValue().toString(), QStringLiteral( "aa" ) );
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper.wrappedWidget() )->currentText(), QStringLiteral( "aa" ) );
break;
}

delete w;

// with project
QgsProcessingParameterWidgetContext widgetContext;
widgetContext.setProject( QgsProject::instance() );
context.setProject( QgsProject::instance() );

QgsProcessingMapLayerWidgetWrapper wrapper2( &param, type );
wrapper2.setWidgetContext( widgetContext );
w = wrapper2.createWrappedWidget( context );

QSignalSpy spy2( &wrapper2, &QgsProcessingPointCloudLayerWidgetWrapper::widgetValueHasChanged );
wrapper2.setWidgetValue( QStringLiteral( "bb" ), context );
QCOMPARE( spy2.count(), 1 );
QCOMPARE( wrapper2.widgetValue().toString(), QStringLiteral( "bb" ) );
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper2.wrappedWidget() )->currentText(), QStringLiteral( "bb" ) );
wrapper2.setWidgetValue( QStringLiteral( "cloud2" ), context );
QCOMPARE( spy2.count(), 2 );
QCOMPARE( wrapper2.widgetValue().toString(), cloud2->id() );
switch ( type )
{
case QgsProcessingGui::Standard:
case QgsProcessingGui::Batch:
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper2.wrappedWidget() )->currentText(), QStringLiteral( "cloud2 [EPSG:28356]" ) );
break;
case QgsProcessingGui::Modeler:
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper2.wrappedWidget() )->currentText(), QStringLiteral( "cloud2" ) );
break;
}

QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper2.wrappedWidget() )->currentLayer()->name(), QStringLiteral( "cloud2" ) );

// check signal
static_cast< QgsProcessingMapLayerComboBox * >( wrapper2.wrappedWidget() )->setLayer( cloud1 );
QCOMPARE( spy2.count(), 3 );
QCOMPARE( wrapper2.widgetValue().toString(), cloud1->id() );
switch ( type )
{
case QgsProcessingGui::Standard:
case QgsProcessingGui::Batch:
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper2.wrappedWidget() )->currentText(), QStringLiteral( "cloud1 [EPSG:28356]" ) );
break;

case QgsProcessingGui::Modeler:
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper2.wrappedWidget() )->currentText(), QStringLiteral( "cloud1" ) );
break;
}
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper2.wrappedWidget() )->currentLayer()->name(), QStringLiteral( "cloud1" ) );

delete w;

// optional
QgsProcessingParameterPoint param2( QStringLiteral( "cloud" ), QStringLiteral( "cloud" ), QVariant(), true );
QgsProcessingPointCloudLayerWidgetWrapper wrapper3( &param2, type );
wrapper3.setWidgetContext( widgetContext );
w = wrapper3.createWrappedWidget( context );

QSignalSpy spy3( &wrapper3, &QgsProcessingPointCloudLayerWidgetWrapper::widgetValueHasChanged );
wrapper3.setWidgetValue( QStringLiteral( "bb" ), context );
QCOMPARE( spy3.count(), 1 );
QCOMPARE( wrapper3.widgetValue().toString(), QStringLiteral( "bb" ) );
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper3.wrappedWidget() )->currentText(), QStringLiteral( "bb" ) );
wrapper3.setWidgetValue( QStringLiteral( "cloud2" ), context );
QCOMPARE( spy3.count(), 2 );
QCOMPARE( wrapper3.widgetValue().toString(), cloud2->id() );
switch ( type )
{
case QgsProcessingGui::Standard:
case QgsProcessingGui::Batch:
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper3.wrappedWidget() )->currentText(), QStringLiteral( "cloud2 [EPSG:28356]" ) );
break;
case QgsProcessingGui::Modeler:
QCOMPARE( static_cast< QgsProcessingMapLayerComboBox * >( wrapper3.wrappedWidget() )->currentText(), QStringLiteral( "cloud2" ) );
break;
}
wrapper3.setWidgetValue( QVariant(), context );
QCOMPARE( spy3.count(), 3 );
QVERIFY( !wrapper3.widgetValue().isValid() );
delete w;

QLabel *l = wrapper.createWrappedLabel();
if ( wrapper.type() != QgsProcessingGui::Batch )
{
QVERIFY( l );
QCOMPARE( l->text(), QStringLiteral( "cloud" ) );
QCOMPARE( l->toolTip(), param.toolTip() );
delete l;
}
else
{
QVERIFY( !l );
}
};

// standard wrapper
testWrapper( QgsProcessingGui::Standard );

// batch wrapper
testWrapper( QgsProcessingGui::Batch );

// modeler wrapper
testWrapper( QgsProcessingGui::Modeler );
}

void TestProcessingGui::testModelGraphicsView()
{
// test model
Expand Down

0 comments on commit 8e385da

Please sign in to comment.