Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and nyalldawson committed Nov 26, 2021
1 parent 5759fbc commit b09d2fa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
8 changes: 5 additions & 3 deletions python/processing/algfactory.py
Expand Up @@ -322,10 +322,12 @@ class ProcessingAlgFactory():
RASTER_LAYER = "RASTER_LAYER",
VECTOR_LAYER = "VECTOR_LAYER",
MESH_LAYER = "MESH_LAYER",
POINT_CLOUD_LAYER = "MESH_LAYER",
FILE_DEST = "FILE_DEST",
FOLDER_DEST = "FOLDER_DEST",
RASTER_LAYER_DEST = "RASTER_LAYER_DEST",
VECTOR_LAYER_DEST = "VECTOR_LAYER_DEST",
POINTCLOUD_LAYER_DEST = "VECTOR_LAYER_DEST",
BAND = "BAND",
BOOL = "BOOL",
CRS = "CRS",
Expand All @@ -348,7 +350,7 @@ class ProcessingAlgFactory():
DATABASE_SCHEMA = "DATABASE_SCHEMA"
DATABASE_TABLE = "DATABASE_TABLE"
COORDINATE_OPERATION = "COORDINATE_OPERATION"
POINT_CLOUD_LAYER = "POINT_CLOUD_LAYER"
POINTCLOUD_LAYER = "POINTCLOUD_LAYER"
ANNOTATION_LAYER = "ANNOTATION_LAYER"

def __init__(self):
Expand Down Expand Up @@ -412,7 +414,7 @@ def output(self, type, *args, **kwargs):
alg.MULTILAYER: QgsProcessingOutputMultipleLayers
alg.RASTER_LAYER: QgsProcessingOutputRasterLayer
alg.VECTOR_LAYER: QgsProcessingOutputVectorLayer
alg.POINTCLOUD_LAYER: QgsProcessingOutputPointCloudLayer
alg.POINT_CLOUD_LAYER: QgsProcessingOutputPointCloudLayer
alg.BOOL: QgsProcessingOutputBoolean
:param type: The type of the input. This should be a type define on `alg` like alg.STRING, alg.DISTANCE
Expand Down Expand Up @@ -552,7 +554,7 @@ def dec(f):
ProcessingAlgFactory.DATABASE_SCHEMA: QgsProcessingParameterDatabaseSchema,
ProcessingAlgFactory.DATABASE_TABLE: QgsProcessingParameterDatabaseTable,
ProcessingAlgFactory.COORDINATE_OPERATION: QgsProcessingParameterCoordinateOperation,
ProcessingAlgFactory.POINT_CLOUD_LAYER: QgsProcessingParameterPointCloudLayer,
ProcessingAlgFactory.POINTCLOUD_LAYER: QgsProcessingParameterPointCloudLayer,
ProcessingAlgFactory.ANNOTATION_LAYER: QgsProcessingParameterAnnotationLayer
}

Expand Down
12 changes: 12 additions & 0 deletions src/core/processing/qgsprocessingprovider.cpp
Expand Up @@ -190,6 +190,18 @@ bool QgsProcessingProvider::isSupportedOutputValue( const QVariant &outputValue,
}
return true;
}
else if ( parameter->type() == QgsProcessingParameterPointCloudDestination::typeName() )
{
const QFileInfo fi( outputPath );
const QString extension = fi.completeSuffix();
qDebug() << supportedOutputPointCloudLayerExtensions();
if ( !supportedOutputPointCloudLayerExtensions().contains( extension, Qt::CaseInsensitive ) )
{
error = tr( "“.%1” files are not supported as outputs for this algorithm" ).arg( extension );
return false;
}
return true;
}
else
{
return true;
Expand Down
1 change: 0 additions & 1 deletion src/gui/processing/qgsprocessingguiregistry.cpp
Expand Up @@ -81,7 +81,6 @@ QgsProcessingGuiRegistry::QgsProcessingGuiRegistry()
addParameterWidgetFactory( new QgsProcessingMeshDatasetTimeWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingPointCloudLayerWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingAnnotationLayerWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingAnnotationLayerWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingPointCloudDestinationWidgetWrapper() );
}

Expand Down
25 changes: 15 additions & 10 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -473,6 +473,11 @@ class DummyProvider3 : public QgsProcessingProvider // clazy:exclude=missing-qob
return QStringList() << QStringLiteral( "mig" ) << QStringLiteral( "sdat" );
}

QStringList supportedOutputPointCloudLayerExtensions() const override
{
return QStringList() << QStringLiteral( "las" ) << QStringLiteral( "ept.json" );
}

void loadAlgorithms() override
{
QVERIFY( addAlgorithm( new DummyAlgorithm2( "alg1" ) ) );
Expand Down Expand Up @@ -7088,7 +7093,7 @@ void TestQgsProcessing::parameterPointCloudOut()
QCOMPARE( fromCode->defaultValue(), def->defaultValue() );

// optional
def.reset( new QgsProcessingParameterPointCloudDestination( "optional", QString(), QString( "default.las" ), true ) );
def.reset( new QgsProcessingParameterPointCloudDestination( "optional", QString(), QString( "default.laz" ), true ) );
QVERIFY( !def->checkValueIsAcceptable( false ) );
QVERIFY( !def->checkValueIsAcceptable( true ) );
QVERIFY( !def->checkValueIsAcceptable( 5 ) );
Expand All @@ -7099,12 +7104,12 @@ void TestQgsProcessing::parameterPointCloudOut()
QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "layer1231123" ) ) );

params.insert( "optional", QVariant() );
QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), params, context ), QStringLiteral( "default.las" ) );
QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), params, context ), QStringLiteral( "default.laz" ) );

pythonCode = def->asPythonString();
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterPointCloudDestination('optional', '', optional=True, createByDefault=True, defaultValue='default.las')" ) );
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterPointCloudDestination('optional', '', optional=True, createByDefault=True, defaultValue='default.laz')" ) );
code = def->asScriptCode();
QCOMPARE( code, QStringLiteral( "##optional=optional pointCloudDestination default.las" ) );
QCOMPARE( code, QStringLiteral( "##optional=optional pointCloudDestination default.laz" ) );
fromCode.reset( dynamic_cast< QgsProcessingParameterPointCloudDestination * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) );
QVERIFY( fromCode.get() );
QCOMPARE( fromCode->name(), def->name() );
Expand All @@ -7116,12 +7121,12 @@ void TestQgsProcessing::parameterPointCloudOut()
QString error;
QVERIFY( !provider.isSupportedOutputValue( QVariant(), def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( QString(), def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( "d:/test.las", def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( "d:/test.LAS", def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( QgsProcessingOutputLayerDefinition( "d:/test.las" ), def.get(), context, error ) );
QVERIFY( provider.isSupportedOutputValue( "d:/test.mig", def.get(), context, error ) );
QVERIFY( provider.isSupportedOutputValue( "d:/test.MIG", def.get(), context, error ) );
QVERIFY( provider.isSupportedOutputValue( QgsProcessingOutputLayerDefinition( "d:/test.MIG" ), def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( "d:/test.laz", def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( "d:/test.LAZ", def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( QgsProcessingOutputLayerDefinition( "d:/test.laz" ), def.get(), context, error ) );
QVERIFY( provider.isSupportedOutputValue( "d:/test.las", def.get(), context, error ) );
QVERIFY( provider.isSupportedOutputValue( "d:/test.LAS", def.get(), context, error ) );
QVERIFY( provider.isSupportedOutputValue( QgsProcessingOutputLayerDefinition( "d:/test.LAS" ), def.get(), context, error ) );

// test layers to load on completion
def.reset( new QgsProcessingParameterPointCloudDestination( "x", QStringLiteral( "desc" ), QStringLiteral( "default.las" ), true ) );
Expand Down

0 comments on commit b09d2fa

Please sign in to comment.