Catch another variant of make_unique

This commit is contained in:
Nyall Dawson 2025-02-07 09:12:53 +10:00
parent 038036d021
commit 2db0254c9e
5 changed files with 14 additions and 7 deletions

View File

@ -96,6 +96,9 @@ qlatin1str_single_char = re.compile(
make_unique = re.compile(
r"""^(\s*)std::unique_ptr<\s*(.*?)\s*>(\s*.*?\s*=\s*std::make_unique<\s*(.*?)\s*>.*)$"""
)
make_unique2 = re.compile(
r"""^(\s*)std::unique_ptr<\s*(.*?)\s*>(?:\s*(.*?)\s*\()\s*(std::make_unique<\s*(.*?)\s*>.*?)\s*\)\s*;$"""
)
def qlatin1char_or_string(x):
@ -233,5 +236,9 @@ while i < len(lines):
if m and m.group(2) == m.group(4):
line = m.group(1) + "auto" + m.group(3)
m = make_unique2.match(line)
if m and m.group(2) == m.group(5):
line = m.group(1) + "auto " + m.group(3) + " = " + m.group(4) + ";"
print(line)
i += 1

View File

@ -1230,7 +1230,7 @@ void QgsAbstractDatabaseProviderConnection::addField( const QgsField &field, con
QgsVectorLayer::LayerOptions options { false, false };
options.skipCrsValidation = true;
std::unique_ptr<QgsVectorLayer> vl( std::make_unique<QgsVectorLayer>( tableUri( schema, tableName ), QStringLiteral( "temp_layer" ), mProviderKey, options ) );
auto vl = std::make_unique<QgsVectorLayer>( tableUri( schema, tableName ), QStringLiteral( "temp_layer" ), mProviderKey, options ) ;
if ( ! vl->isValid() )
{
throw QgsProviderConnectionException( QObject::tr( "Could not create a vector layer for table '%1' in schema '%2'" )
@ -1255,7 +1255,7 @@ void QgsAbstractDatabaseProviderConnection::renameField( const QString &schema,
QgsVectorLayer::LayerOptions options { false, false };
options.skipCrsValidation = true;
std::unique_ptr<QgsVectorLayer> vl( std::make_unique<QgsVectorLayer>( tableUri( schema, tableName ), QStringLiteral( "temp_layer" ), mProviderKey, options ) );
auto vl = std::make_unique<QgsVectorLayer>( tableUri( schema, tableName ), QStringLiteral( "temp_layer" ), mProviderKey, options ) ;
if ( ! vl->isValid() )
{
throw QgsProviderConnectionException( QObject::tr( "Could not create a vector layer for table '%1' in schema '%2'" )

View File

@ -191,7 +191,7 @@ QgsFeature TestQgsProcessingAlgsPt1::runForFeature( const std::unique_ptr<QgsPro
QgsProcessingFeedback feedback;
context->setFeedback( &feedback );
std::unique_ptr<QgsVectorLayer> inputLayer( std::make_unique<QgsVectorLayer>( layerType, QStringLiteral( "layer" ), QStringLiteral( "memory" ) ) );
auto inputLayer = std::make_unique<QgsVectorLayer>( layerType, QStringLiteral( "layer" ), QStringLiteral( "memory" ) );
inputLayer->dataProvider()->addFeature( feature );
parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue<QgsMapLayer *>( inputLayer.get() ) );
@ -4479,7 +4479,7 @@ void TestQgsProcessingAlgsPt1::bookmarksToLayer()
void TestQgsProcessingAlgsPt1::layerToBookmarks()
{
std::unique_ptr<QgsVectorLayer> inputLayer( std::make_unique<QgsVectorLayer>( QStringLiteral( "Polygon?crs=epsg:4326&field=province:string&field=municipality:string" ), QStringLiteral( "layer" ), QStringLiteral( "memory" ) ) );
auto inputLayer = std::make_unique<QgsVectorLayer>( QStringLiteral( "Polygon?crs=epsg:4326&field=province:string&field=municipality:string" ), QStringLiteral( "layer" ), QStringLiteral( "memory" ) );
QVERIFY( inputLayer->isValid() );
QgsFeature f;

View File

@ -132,7 +132,7 @@ QgsFeature TestQgsProcessingAlgsPt2::runForFeature( const std::unique_ptr<QgsPro
QgsProcessingFeedback feedback;
context->setFeedback( &feedback );
std::unique_ptr<QgsVectorLayer> inputLayer( std::make_unique<QgsVectorLayer>( layerType, QStringLiteral( "layer" ), QStringLiteral( "memory" ) ) );
auto inputLayer = std::make_unique<QgsVectorLayer>( layerType, QStringLiteral( "layer" ), QStringLiteral( "memory" ) );
inputLayer->dataProvider()->addFeature( feature );
parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue<QgsMapLayer *>( inputLayer.get() ) );

View File

@ -1515,9 +1515,9 @@ void TestQgsLegendRenderer::testDiagramMeshLegend()
rendererSettings.setActiveVectorDatasetGroup( vectorIndex );
layer->setRendererSettings( rendererSettings );
std::unique_ptr<QgsLayerTree> root( std::make_unique<QgsLayerTree>() );
auto root = std::make_unique<QgsLayerTree>();
root->addLayer( layer );
std::unique_ptr<QgsLayerTreeModel> legendModel( std::make_unique<QgsLayerTreeModel>( root.get() ) );
auto legendModel = std::make_unique<QgsLayerTreeModel>( root.get() );
QgsLegendSettings settings;