Skip to content
Permalink
Browse files

Merge pull request #5432 from Gustry/allow_pipe_filepath

allow pipe character in filepath in processing
  • Loading branch information
nyalldawson committed Oct 26, 2017
2 parents ecf93e3 + fb4e84a commit acbd9d18f5b481070dc9f0b380703846557a11d9
Showing with 40 additions and 17 deletions.
  1. +25 −17 src/core/processing/qgsprocessingutils.cpp
  2. +15 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -155,26 +155,34 @@ class ProjectionSettingRestorer

QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString( const QString &string )
{
QStringList components = string.split( '|' );
if ( components.isEmpty() )
return nullptr;

QFileInfo fi;
if ( QFileInfo::exists( string ) )
{
// TODO - remove when there is a cleaner way to block the unknown projection dialog!
ProjectionSettingRestorer restorer;
( void )restorer; // no warnings
fi = QFileInfo( string );
else if ( QFileInfo::exists( components.at( 0 ) ) )
fi = QFileInfo( components.at( 0 ) );
else
return nullptr;

QFileInfo fi( string );
QString name = fi.baseName();
// TODO - remove when there is a cleaner way to block the unknown projection dialog!
ProjectionSettingRestorer restorer;
( void )restorer; // no warnings

// brute force attempt to load a matching layer
std::unique_ptr< QgsVectorLayer > layer( new QgsVectorLayer( string, name, QStringLiteral( "ogr" ), false ) );
if ( layer->isValid() )
{
return layer.release();
}
std::unique_ptr< QgsRasterLayer > rasterLayer( new QgsRasterLayer( string, name, QStringLiteral( "gdal" ), false ) );
if ( rasterLayer->isValid() )
{
return rasterLayer.release();
}
QString name = fi.baseName();

// brute force attempt to load a matching layer
std::unique_ptr< QgsVectorLayer > layer( new QgsVectorLayer( string, name, QStringLiteral( "ogr" ), false ) );
if ( layer->isValid() )
{
return layer.release();
}
std::unique_ptr< QgsRasterLayer > rasterLayer( new QgsRasterLayer( string, name, QStringLiteral( "gdal" ), false ) );
if ( rasterLayer->isValid() )
{
return rasterLayer.release();
}
return nullptr;
}
@@ -709,6 +709,21 @@ void TestQgsProcessing::mapLayers()
QCOMPARE( l->type(), QgsMapLayer::VectorLayer );
QCOMPARE( l->name(), QStringLiteral( "multipoint" ) );
delete l;

// Test layers from a string with parameters
QString osmFilePath = testDataDir + "openstreetmap/testdata.xml";
QgsVectorLayer *osm = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::loadMapLayerFromString( osmFilePath ) );
QVERIFY( osm->isValid() );
QCOMPARE( osm->geometryType(), QgsWkbTypes::PointGeometry );

osm = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::loadMapLayerFromString( osmFilePath + "|layerid=3" ) );
QVERIFY( osm->isValid() );
QCOMPARE( osm->geometryType(), QgsWkbTypes::PolygonGeometry );

osm = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::loadMapLayerFromString( osmFilePath + "|layerid=3|subset=\"building\" is not null" ) );
QVERIFY( osm->isValid() );
QCOMPARE( osm->geometryType(), QgsWkbTypes::PolygonGeometry );
QCOMPARE( osm->subsetString(), QStringLiteral( "\"building\" is not null" ) );
}

void TestQgsProcessing::mapLayerFromStore()

0 comments on commit acbd9d1

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