diff --git a/python/PyQt6/core/auto_additions/qgsmimedatautils.py b/python/PyQt6/core/auto_additions/qgsmimedatautils.py index 551f882dfd1b..2bc2b665a9ff 100644 --- a/python/PyQt6/core/auto_additions/qgsmimedatautils.py +++ b/python/PyQt6/core/auto_additions/qgsmimedatautils.py @@ -1,6 +1,6 @@ # The following has been generated automatically from src/core/qgsmimedatautils.h try: - QgsMimeDataUtils.Uri.__attribute_docs__ = {'layerType': 'Type of URI.\n\nRecognized types include\n\n- "vector": vector layers\n- "raster": raster layers\n- "mesh": mesh layers\n- "pointcloud": point cloud layers\n- "vector-tile": vector tile layers\n- "tiled-scene": tiled scene layers\n- "plugin": plugin layers\n- "custom": custom types\n- "project": QGS/QGZ project file\n- "directory": directory path\n\nMime data from plugins may use additional custom layer types.', 'providerKey': 'For "vector" / "raster" type: provider id.\nFor "plugin" type: plugin layer type name.\nFor "custom" type: key of its :py:class:`QgsCustomDropHandler`\nFor "project" and "directory" types: unused', 'name': 'Human readable name to be used e.g. in layer tree', 'uri': 'Identifier of the data source recognized by its providerKey', 'layerId': 'Layer ID, if uri is associated with a layer from a :py:class:`QgsProject`.\n\n.. versionadded:: 3.8', 'pId': 'Unique ID associated with application instance. Can be used to identify\nif mime data was created inside the current application instance or not.\n\n.. versionadded:: 3.8', 'wkbType': 'WKB type, if associated with a vector layer, or :py:class:`QgsWkbTypes`.Unknown if not\nyet known.\n\n.. versionadded:: 3.8', 'filePath': 'Path to file, if uri is associated with a file.\n\n.. versionadded:: 3.22'} + QgsMimeDataUtils.Uri.__attribute_docs__ = {'layerType': 'Type of URI.\n\nRecognized types include\n\n- "vector": vector layers\n- "raster": raster layers\n- "mesh": mesh layers\n- "pointcloud": point cloud layers\n- "vector-tile": vector tile layers\n- "tiled-scene": tiled scene layers\n- "annotation": annotation layers\n- "group": group layers\n- "plugin": plugin layers\n- "custom": custom types\n- "project": QGS/QGZ project file\n- "directory": directory path\n\nNote: use :py:func:`QgsMapLayerFactory.typeToString()` to convert from a\n:py:class:`Qgis`.LayerType to a string (except for "custom", "project" and\n"directory")\n\nMime data from plugins may use additional custom layer types.', 'providerKey': 'For "vector" / "raster" type: provider id.\nFor "plugin" type: plugin layer type name.\nFor "custom" type: key of its :py:class:`QgsCustomDropHandler`\nFor "project" and "directory" types: unused', 'name': 'Human readable name to be used e.g. in layer tree', 'uri': 'Identifier of the data source recognized by its providerKey', 'layerId': 'Layer ID, if uri is associated with a layer from a :py:class:`QgsProject`.\n\n.. versionadded:: 3.8', 'pId': 'Unique ID associated with application instance. Can be used to identify\nif mime data was created inside the current application instance or not.\n\n.. versionadded:: 3.8', 'wkbType': 'WKB type, if associated with a vector layer, or :py:class:`QgsWkbTypes`.Unknown if not\nyet known.\n\n.. versionadded:: 3.8', 'filePath': 'Path to file, if uri is associated with a file.\n\n.. versionadded:: 3.22'} except (NameError, AttributeError): pass try: diff --git a/python/core/auto_additions/qgsmimedatautils.py b/python/core/auto_additions/qgsmimedatautils.py index 551f882dfd1b..2bc2b665a9ff 100644 --- a/python/core/auto_additions/qgsmimedatautils.py +++ b/python/core/auto_additions/qgsmimedatautils.py @@ -1,6 +1,6 @@ # The following has been generated automatically from src/core/qgsmimedatautils.h try: - QgsMimeDataUtils.Uri.__attribute_docs__ = {'layerType': 'Type of URI.\n\nRecognized types include\n\n- "vector": vector layers\n- "raster": raster layers\n- "mesh": mesh layers\n- "pointcloud": point cloud layers\n- "vector-tile": vector tile layers\n- "tiled-scene": tiled scene layers\n- "plugin": plugin layers\n- "custom": custom types\n- "project": QGS/QGZ project file\n- "directory": directory path\n\nMime data from plugins may use additional custom layer types.', 'providerKey': 'For "vector" / "raster" type: provider id.\nFor "plugin" type: plugin layer type name.\nFor "custom" type: key of its :py:class:`QgsCustomDropHandler`\nFor "project" and "directory" types: unused', 'name': 'Human readable name to be used e.g. in layer tree', 'uri': 'Identifier of the data source recognized by its providerKey', 'layerId': 'Layer ID, if uri is associated with a layer from a :py:class:`QgsProject`.\n\n.. versionadded:: 3.8', 'pId': 'Unique ID associated with application instance. Can be used to identify\nif mime data was created inside the current application instance or not.\n\n.. versionadded:: 3.8', 'wkbType': 'WKB type, if associated with a vector layer, or :py:class:`QgsWkbTypes`.Unknown if not\nyet known.\n\n.. versionadded:: 3.8', 'filePath': 'Path to file, if uri is associated with a file.\n\n.. versionadded:: 3.22'} + QgsMimeDataUtils.Uri.__attribute_docs__ = {'layerType': 'Type of URI.\n\nRecognized types include\n\n- "vector": vector layers\n- "raster": raster layers\n- "mesh": mesh layers\n- "pointcloud": point cloud layers\n- "vector-tile": vector tile layers\n- "tiled-scene": tiled scene layers\n- "annotation": annotation layers\n- "group": group layers\n- "plugin": plugin layers\n- "custom": custom types\n- "project": QGS/QGZ project file\n- "directory": directory path\n\nNote: use :py:func:`QgsMapLayerFactory.typeToString()` to convert from a\n:py:class:`Qgis`.LayerType to a string (except for "custom", "project" and\n"directory")\n\nMime data from plugins may use additional custom layer types.', 'providerKey': 'For "vector" / "raster" type: provider id.\nFor "plugin" type: plugin layer type name.\nFor "custom" type: key of its :py:class:`QgsCustomDropHandler`\nFor "project" and "directory" types: unused', 'name': 'Human readable name to be used e.g. in layer tree', 'uri': 'Identifier of the data source recognized by its providerKey', 'layerId': 'Layer ID, if uri is associated with a layer from a :py:class:`QgsProject`.\n\n.. versionadded:: 3.8', 'pId': 'Unique ID associated with application instance. Can be used to identify\nif mime data was created inside the current application instance or not.\n\n.. versionadded:: 3.8', 'wkbType': 'WKB type, if associated with a vector layer, or :py:class:`QgsWkbTypes`.Unknown if not\nyet known.\n\n.. versionadded:: 3.8', 'filePath': 'Path to file, if uri is associated with a file.\n\n.. versionadded:: 3.22'} except (NameError, AttributeError): pass try: diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 0d2bfecfc44a..8d3162d246ec 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -95,6 +95,7 @@ #include "qgsauxiliarystorage.h" #include "qgsvectortileutils.h" #include "qgsscaleutils.h" +#include "qgsmaplayerfactory.h" #include "qgsbrowserwidget.h" #include "annotations/qgsannotationitempropertieswidget.h" @@ -2447,6 +2448,8 @@ QList QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList const QgsMimeDataUtils::Uri &u = lst.at( i ); QString uri = crsAndFormatAdjustedLayerUri( u.uri, u.supportedCrs, u.supportedFormats ); + bool ok = false; + Qgis::LayerType layerType = QgsMapLayerFactory::typeFromString( u.layerType, ok ); if ( u.layerType == QLatin1String( "collection" ) ) { @@ -2455,7 +2458,7 @@ QList QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList if ( ok ) addedLayers.append( collectionLayers ); } - else if ( u.layerType == QLatin1String( "vector" ) ) + else if ( ok && layerType == Qgis::LayerType::Vector ) { const QList layerList { QgsAppLayerHandling::addVectorLayer( uri, u.name, u.providerKey, addToLegend ) }; for ( QgsVectorLayer *layer : std::as_const( layerList ) ) @@ -2463,7 +2466,7 @@ QList QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList addedLayers << layer; } } - else if ( u.layerType == QLatin1String( "raster" ) ) + else if ( ok && layerType == Qgis::LayerType::Raster ) { const QList layerList { QgsAppLayerHandling::addRasterLayer( uri, u.name, u.providerKey, addToLegend ) }; for ( QgsRasterLayer *layer : std::as_const( layerList ) ) @@ -2471,7 +2474,7 @@ QList QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList addedLayers << layer; } } - else if ( u.layerType == QLatin1String( "mesh" ) ) + else if ( ok && layerType == Qgis::LayerType::Mesh ) { const QList layerList { QgsAppLayerHandling::addMeshLayer( uri, u.name, u.providerKey, addToLegend ) }; for ( QgsMeshLayer *layer : std::as_const( layerList ) ) @@ -2479,17 +2482,17 @@ QList QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList addedLayers << layer; } } - else if ( u.layerType == QLatin1String( "pointcloud" ) ) + else if ( ok && layerType == Qgis::LayerType::PointCloud ) { if ( QgsMapLayer *layer = QgsAppLayerHandling::addLayer( uri, u.name, u.providerKey, addToLegend ) ) addedLayers << layer; } - else if ( u.layerType == QLatin1String( "tiled-scene" ) ) + else if ( ok && layerType == Qgis::LayerType::TiledScene ) { if ( QgsMapLayer *layer = QgsAppLayerHandling::addLayer( uri, u.name, u.providerKey, addToLegend ) ) addedLayers << layer; } - else if ( u.layerType == QLatin1String( "vector-tile" ) ) + else if ( ok && layerType == Qgis::LayerType::VectorTile ) { QgsTemporaryCursorOverride busyCursor( Qt::WaitCursor ); @@ -2587,7 +2590,7 @@ QList QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList addedLayers << layer; } } - else if ( u.layerType == QLatin1String( "plugin" ) ) + else if ( ok && layerType == Qgis::LayerType::Plugin ) { QgsMapLayer *layer = QgsAppLayerHandling::addLayer( uri, u.name, u.providerKey, addToLegend, false ); if ( layer ) diff --git a/src/core/browser/qgslayeritem.cpp b/src/core/browser/qgslayeritem.cpp index 7ba9fff15bb7..94a4fc9b4d6d 100644 --- a/src/core/browser/qgslayeritem.cpp +++ b/src/core/browser/qgslayeritem.cpp @@ -18,6 +18,7 @@ #include "qgslayeritem.h" #include "moc_qgslayeritem.cpp" #include "qgsmaplayer.h" +#include "qgsmaplayerfactory.h" #include "qgsvectorlayer.h" #include "qgsiconutils.h" @@ -243,11 +244,11 @@ bool QgsLayerItem::equal( const QgsDataItem *other ) QgsMimeDataUtils::UriList QgsLayerItem::mimeUris() const { QgsMimeDataUtils::Uri u; + u.layerType = QgsMapLayerFactory::typeToString( mapLayerType() ); switch ( mapLayerType() ) { case Qgis::LayerType::Vector: - u.layerType = QStringLiteral( "vector" ); switch ( mLayerType ) { case Qgis::BrowserLayerType::Point: @@ -277,28 +278,13 @@ QgsMimeDataUtils::UriList QgsLayerItem::mimeUris() const } break; case Qgis::LayerType::Raster: - u.layerType = QStringLiteral( "raster" ); - break; case Qgis::LayerType::Mesh: - u.layerType = QStringLiteral( "mesh" ); - break; case Qgis::LayerType::VectorTile: - u.layerType = QStringLiteral( "vector-tile" ); - break; case Qgis::LayerType::PointCloud: - u.layerType = QStringLiteral( "pointcloud" ); - break; case Qgis::LayerType::TiledScene: - u.layerType = QStringLiteral( "tiled-scene" ); - break; case Qgis::LayerType::Plugin: - u.layerType = QStringLiteral( "plugin" ); - break; case Qgis::LayerType::Group: - u.layerType = QStringLiteral( "group" ); - break; case Qgis::LayerType::Annotation: - u.layerType = QStringLiteral( "annotation" ); break; } diff --git a/src/core/providers/qgsprovidersublayerdetails.cpp b/src/core/providers/qgsprovidersublayerdetails.cpp index 02c621ddc54c..fabab7a1aca8 100644 --- a/src/core/providers/qgsprovidersublayerdetails.cpp +++ b/src/core/providers/qgsprovidersublayerdetails.cpp @@ -30,35 +30,20 @@ QgsMapLayer *QgsProviderSublayerDetails::toLayer( const LayerOptions &options ) QgsMimeDataUtils::Uri QgsProviderSublayerDetails::toMimeUri() const { QgsMimeDataUtils::Uri u; + u.layerType = QgsMapLayerFactory::typeToString( mType ); switch ( mType ) { case Qgis::LayerType::Vector: - u.layerType = QStringLiteral( "vector" ); u.wkbType = mWkbType; break; case Qgis::LayerType::Raster: - u.layerType = QStringLiteral( "raster" ); - break; case Qgis::LayerType::Mesh: - u.layerType = QStringLiteral( "mesh" ); - break; case Qgis::LayerType::VectorTile: - u.layerType = QStringLiteral( "vector-tile" ); - break; case Qgis::LayerType::PointCloud: - u.layerType = QStringLiteral( "pointcloud" ); - break; case Qgis::LayerType::Plugin: - u.layerType = QStringLiteral( "plugin" ); - break; case Qgis::LayerType::Group: - u.layerType = QStringLiteral( "group" ); - break; case Qgis::LayerType::Annotation: - u.layerType = QStringLiteral( "annotation" ); - break; case Qgis::LayerType::TiledScene: - u.layerType = QStringLiteral( "tiled-scene" ); break; } diff --git a/src/core/qgsmimedatautils.cpp b/src/core/qgsmimedatautils.cpp index 6ad3b7458184..528fe7c210fe 100644 --- a/src/core/qgsmimedatautils.cpp +++ b/src/core/qgsmimedatautils.cpp @@ -20,6 +20,7 @@ #include "qgslogger.h" #include "qgsrasterlayer.h" #include "qgsvectorlayer.h" +#include "qgsmaplayerfactory.h" #include "qgsmeshlayer.h" #include @@ -71,38 +72,20 @@ QgsMimeDataUtils::Uri::Uri( QgsMapLayer *layer ) , layerId( layer->id() ) , pId( QString::number( QCoreApplication::applicationPid() ) ) { + layerType = QgsMapLayerFactory::typeToString( layer->type() ); switch ( layer->type() ) { case Qgis::LayerType::Vector: { - layerType = QStringLiteral( "vector" ); wkbType = qobject_cast< QgsVectorLayer *>( layer )->wkbType(); break; } case Qgis::LayerType::Raster: - { - layerType = QStringLiteral( "raster" ); - break; - } - case Qgis::LayerType::Mesh: - { - layerType = QStringLiteral( "mesh" ); - break; - } case Qgis::LayerType::PointCloud: - { - layerType = QStringLiteral( "pointcloud" ); - break; - } case Qgis::LayerType::VectorTile: - { - layerType = QStringLiteral( "vector-tile" ); - break; - } case Qgis::LayerType::TiledScene: { - layerType = QStringLiteral( "tiled-scene" ); break; } diff --git a/src/core/qgsmimedatautils.h b/src/core/qgsmimedatautils.h index 2289a7a8cd62..c35248d46040 100644 --- a/src/core/qgsmimedatautils.h +++ b/src/core/qgsmimedatautils.h @@ -103,11 +103,17 @@ class CORE_EXPORT QgsMimeDataUtils * - "pointcloud": point cloud layers * - "vector-tile": vector tile layers * - "tiled-scene": tiled scene layers + * - "annotation": annotation layers + * - "group": group layers * - "plugin": plugin layers * - "custom": custom types * - "project": QGS/QGZ project file * - "directory": directory path * + * Note: use QgsMapLayerFactory::typeToString() to convert from a + * Qgis::LayerType to a string (except for "custom", "project" and + * "directory") + * * Mime data from plugins may use additional custom layer types. */ QString layerType; diff --git a/src/gui/processing/qgsprocessingmultipleselectiondialog.cpp b/src/gui/processing/qgsprocessingmultipleselectiondialog.cpp index f37b255cf0e2..ab51eb3f6553 100644 --- a/src/gui/processing/qgsprocessingmultipleselectiondialog.cpp +++ b/src/gui/processing/qgsprocessingmultipleselectiondialog.cpp @@ -19,6 +19,7 @@ #include "qgssettings.h" #include "qgsfileutils.h" #include "qgsvectorlayer.h" +#include "qgsmaplayerfactory.h" #include "qgsmeshlayer.h" #include "qgsrasterlayer.h" #include "qgspluginlayer.h" @@ -460,7 +461,7 @@ QStringList QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( c || parameter->layerType() == Qgis::ProcessingSourceType::VectorLine || parameter->layerType() == Qgis::ProcessingSourceType::VectorPoint || parameter->layerType() == Qgis::ProcessingSourceType::VectorPolygon ) - && u.layerType == QLatin1String( "vector" ) ) + && u.layerType == QgsMapLayerFactory::typeToString( Qgis::LayerType::Vector ) ) { bool acceptable = false; switch ( QgsWkbTypes::geometryType( u.wkbType ) ) @@ -493,16 +494,16 @@ QStringList QgsProcessingMultipleInputPanelWidget::compatibleUrisFromMimeData( c res.append( u.providerKey != QLatin1String( "ogr" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( u.providerKey, u.uri ) : u.uri ); } else if ( ( parameter->layerType() == Qgis::ProcessingSourceType::MapLayer || parameter->layerType() == Qgis::ProcessingSourceType::Raster ) - && u.layerType == QLatin1String( "raster" ) && u.providerKey == QLatin1String( "gdal" ) ) + && u.layerType == QgsMapLayerFactory::typeToString( Qgis::LayerType::Raster ) && u.providerKey == QLatin1String( "gdal" ) ) res.append( u.uri ); else if ( ( parameter->layerType() == Qgis::ProcessingSourceType::MapLayer || parameter->layerType() == Qgis::ProcessingSourceType::Mesh ) - && u.layerType == QLatin1String( "mesh" ) && u.providerKey == QLatin1String( "mdal" ) ) + && u.layerType == QgsMapLayerFactory::typeToString( Qgis::LayerType::Mesh ) && u.providerKey == QLatin1String( "mdal" ) ) res.append( u.uri ); else if ( ( parameter->layerType() == Qgis::ProcessingSourceType::MapLayer || parameter->layerType() == Qgis::ProcessingSourceType::PointCloud ) - && u.layerType == QLatin1String( "pointcloud" ) ) + && u.layerType == QgsMapLayerFactory::typeToString( Qgis::LayerType::PointCloud ) ) res.append( u.uri ); else if ( ( parameter->layerType() == Qgis::ProcessingSourceType::MapLayer || parameter->layerType() == Qgis::ProcessingSourceType::VectorTile ) - && u.layerType == QLatin1String( "vector-tile" ) ) + && u.layerType == QgsMapLayerFactory::typeToString( Qgis::LayerType::VectorTile ) ) res.append( u.uri ); // NOLINTEND(bugprone-branch-clone) }