From 2db0254c9eb06ba05c9828f0fb983064de6788aa Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 7 Feb 2025 09:12:53 +1000 Subject: [PATCH] Catch another variant of make_unique --- scripts/qstringfixup.py | 7 +++++++ .../providers/qgsabstractdatabaseproviderconnection.cpp | 4 ++-- tests/src/analysis/testqgsprocessingalgspt1.cpp | 4 ++-- tests/src/analysis/testqgsprocessingalgspt2.cpp | 2 +- tests/src/core/testqgslegendrenderer.cpp | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/qstringfixup.py b/scripts/qstringfixup.py index e021351f686..8b1994fe4bf 100644 --- a/scripts/qstringfixup.py +++ b/scripts/qstringfixup.py @@ -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 diff --git a/src/core/providers/qgsabstractdatabaseproviderconnection.cpp b/src/core/providers/qgsabstractdatabaseproviderconnection.cpp index 6550396efcc..8207a913236 100644 --- a/src/core/providers/qgsabstractdatabaseproviderconnection.cpp +++ b/src/core/providers/qgsabstractdatabaseproviderconnection.cpp @@ -1230,7 +1230,7 @@ void QgsAbstractDatabaseProviderConnection::addField( const QgsField &field, con QgsVectorLayer::LayerOptions options { false, false }; options.skipCrsValidation = true; - std::unique_ptr vl( std::make_unique( tableUri( schema, tableName ), QStringLiteral( "temp_layer" ), mProviderKey, options ) ); + auto vl = std::make_unique( 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 vl( std::make_unique( tableUri( schema, tableName ), QStringLiteral( "temp_layer" ), mProviderKey, options ) ); + auto vl = std::make_unique( 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'" ) diff --git a/tests/src/analysis/testqgsprocessingalgspt1.cpp b/tests/src/analysis/testqgsprocessingalgspt1.cpp index 1e3b8e28120..1d12d38aa3d 100644 --- a/tests/src/analysis/testqgsprocessingalgspt1.cpp +++ b/tests/src/analysis/testqgsprocessingalgspt1.cpp @@ -191,7 +191,7 @@ QgsFeature TestQgsProcessingAlgsPt1::runForFeature( const std::unique_ptrsetFeedback( &feedback ); - std::unique_ptr inputLayer( std::make_unique( layerType, QStringLiteral( "layer" ), QStringLiteral( "memory" ) ) ); + auto inputLayer = std::make_unique( layerType, QStringLiteral( "layer" ), QStringLiteral( "memory" ) ); inputLayer->dataProvider()->addFeature( feature ); parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( inputLayer.get() ) ); @@ -4479,7 +4479,7 @@ void TestQgsProcessingAlgsPt1::bookmarksToLayer() void TestQgsProcessingAlgsPt1::layerToBookmarks() { - std::unique_ptr inputLayer( std::make_unique( QStringLiteral( "Polygon?crs=epsg:4326&field=province:string&field=municipality:string" ), QStringLiteral( "layer" ), QStringLiteral( "memory" ) ) ); + auto inputLayer = std::make_unique( QStringLiteral( "Polygon?crs=epsg:4326&field=province:string&field=municipality:string" ), QStringLiteral( "layer" ), QStringLiteral( "memory" ) ); QVERIFY( inputLayer->isValid() ); QgsFeature f; diff --git a/tests/src/analysis/testqgsprocessingalgspt2.cpp b/tests/src/analysis/testqgsprocessingalgspt2.cpp index a53e0a9b40d..b09d6a12df0 100644 --- a/tests/src/analysis/testqgsprocessingalgspt2.cpp +++ b/tests/src/analysis/testqgsprocessingalgspt2.cpp @@ -132,7 +132,7 @@ QgsFeature TestQgsProcessingAlgsPt2::runForFeature( const std::unique_ptrsetFeedback( &feedback ); - std::unique_ptr inputLayer( std::make_unique( layerType, QStringLiteral( "layer" ), QStringLiteral( "memory" ) ) ); + auto inputLayer = std::make_unique( layerType, QStringLiteral( "layer" ), QStringLiteral( "memory" ) ); inputLayer->dataProvider()->addFeature( feature ); parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( inputLayer.get() ) ); diff --git a/tests/src/core/testqgslegendrenderer.cpp b/tests/src/core/testqgslegendrenderer.cpp index 7521af29488..be637721712 100644 --- a/tests/src/core/testqgslegendrenderer.cpp +++ b/tests/src/core/testqgslegendrenderer.cpp @@ -1515,9 +1515,9 @@ void TestQgsLegendRenderer::testDiagramMeshLegend() rendererSettings.setActiveVectorDatasetGroup( vectorIndex ); layer->setRendererSettings( rendererSettings ); - std::unique_ptr root( std::make_unique() ); + auto root = std::make_unique(); root->addLayer( layer ); - std::unique_ptr legendModel( std::make_unique( root.get() ) ); + auto legendModel = std::make_unique( root.get() ); QgsLegendSettings settings;