Skip to content

Commit

Permalink
Finish porting mesh sublayer handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 12, 2021
1 parent 41d2206 commit b5a2b32
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 14 deletions.
88 changes: 75 additions & 13 deletions src/app/qgisapp.cpp
Expand Up @@ -7659,16 +7659,18 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
{
bool detailsAreIncomplete = QgsProviderUtils::sublayerDetailsAreIncomplete( sublayers, false );
const bool singleSublayerOnly = sublayers.size() == 1;
if ( singleSublayerOnly && !detailsAreIncomplete )
{
// nice and easy -- we only have one sublayer, so load that
}
else if ( allowInteractive )
QString groupName;

if ( allowInteractive && ( !singleSublayerOnly || detailsAreIncomplete ) )
{
// prompt user for sublayers
QgsProviderSublayersDialog dlg( fileName, sublayers, this );

dlg.exec();
if ( dlg.exec() )
sublayers = dlg.selectedLayers();
else
sublayers.clear(); // dialog was canceled, so don't add any sublayers
groupName = dlg.groupName();
}
else // non-interactive
{
Expand All @@ -7680,15 +7682,77 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
// requery sublayers, resolving geometry types
sublayers = QgsProviderRegistry::instance()->querySublayers( fileName, Qgis::SublayerQueryFlag::ResolveGeometryType );
}
}
ok = true;

// add all sublayers
// now add sublayers
if ( !sublayers.empty() )
{
QgsCanvasRefreshBlocker refreshBlocker;
QgsSettings settings;

QgsLayerTreeGroup *group = nullptr;
if ( !groupName.isEmpty() )
{
group = QgsProject::instance()->layerTreeRoot()->insertGroup( 0, groupName );
}

for ( const QgsProviderSublayerDetails &sublayer : std::as_const( sublayers ) )
{
QgsProviderSublayerDetails::LayerOptions options( QgsProject::instance()->transformContext() );
std::unique_ptr<QgsMapLayer> layer( sublayer.toLayer( options ) );
QgsMapLayer *ml = layer.get();
if ( !ml )
continue;

if ( group )
{
QgsProject::instance()->addMapLayer( layer.release(), false );
group->addLayer( ml );
}
else
{
QgsProject::instance()->addMapLayer( layer.release() );
}

switch ( ml->type() )
{
case QgsMapLayerType::VectorLayer:
break;
case QgsMapLayerType::RasterLayer:
break;
case QgsMapLayerType::PluginLayer:
break;
case QgsMapLayerType::MeshLayer:
postProcessAddedMeshLayer( qobject_cast< QgsMeshLayer * >( ml ) );
break;
case QgsMapLayerType::VectorTileLayer:
break;
case QgsMapLayerType::AnnotationLayer:
break;
case QgsMapLayerType::PointCloudLayer:
break;
}

if ( sublayers.size() == 1 )
{
QFileInfo info( fileName );
QString base = info.completeBaseName();
if ( settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() )
{
base = QgsMapLayer::formatLayerName( base );
}
ml->setName( base );
}
}
}
ok = true;
activateDeactivateLayerRelatedActions( activeLayer() );
}

CPLPopErrorHandler();

#if 0
// try to load it as raster
// try to load it as raster
if ( QgsRasterLayer::isValidRasterFileName( fileName ) )
{
// open .adf as a directory
Expand All @@ -7701,7 +7765,7 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
ok = addRasterLayer( fileName, fileInfo.completeBaseName() );
}

// try as a vector
// try as a vector
if ( !ok || fileName.endsWith( QLatin1String( ".gpkg" ), Qt::CaseInsensitive ) )
{
if ( allowInteractive )
Expand All @@ -7714,15 +7778,13 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
}
}

// Try to load as mesh layer after raster & vector
// Try to load as mesh layer after raster & vector
if ( !ok )
{
ok = static_cast< bool >( addMeshLayerPrivate( fileName, fileInfo.completeBaseName(), QStringLiteral( "mdal" ), false ) );
}
#endif

CPLPopErrorHandler();

if ( !ok )
{
// maybe a known file type, which couldn't be opened due to a missing dependency... (eg. las for a non-pdal-enabled build)
Expand Down
9 changes: 8 additions & 1 deletion src/app/qgsprovidersublayersdialog.cpp
Expand Up @@ -193,7 +193,14 @@ QString QgsProviderSublayersDialog::groupName() const
return QString();

const QFileInfo fi( mFilePath );
return fi.completeBaseName();
QString res = fi.completeBaseName();

QgsSettings settings;
if ( settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() )
{
res = QgsMapLayer::formatLayerName( res );
}
return res;
}

void QgsProviderSublayersDialog::treeSelectionChanged( const QItemSelection &, const QItemSelection & )
Expand Down

0 comments on commit b5a2b32

Please sign in to comment.