From 7277ee1f3c145093c70c6df71bb6234e88cd1a3a Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 16 Dec 2024 11:29:08 +1000 Subject: [PATCH 01/11] Fix some uninitialized members --- src/3d/mesh/qgsmesh3dgeometry_p.h | 2 +- src/app/3d/qgs3danimationwidget.h | 4 ++-- src/app/mesh/qgsmeshtransformcoordinatesdockwidget.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/3d/mesh/qgsmesh3dgeometry_p.h b/src/3d/mesh/qgsmesh3dgeometry_p.h index bc25aaa88ee5..33c878542809 100644 --- a/src/3d/mesh/qgsmesh3dgeometry_p.h +++ b/src/3d/mesh/qgsmesh3dgeometry_p.h @@ -150,7 +150,7 @@ class QgsMesh3DGeometry : public Qt3DCore::QGeometry Qt3DCore::QAttribute *mIndexAttribute = nullptr; #endif - QgsMesh3DGeometryBuilder *mBuilder; + QgsMesh3DGeometryBuilder *mBuilder = nullptr; protected slots: virtual void getData(); diff --git a/src/app/3d/qgs3danimationwidget.h b/src/app/3d/qgs3danimationwidget.h index 21c2e720d478..7d4964d3314c 100644 --- a/src/app/3d/qgs3danimationwidget.h +++ b/src/app/3d/qgs3danimationwidget.h @@ -64,8 +64,8 @@ class Qgs3DAnimationWidget : public QWidget, private Ui::Animation3DWidget private: std::unique_ptr mAnimationSettings; - QgsCameraController *mCameraController; - Qgs3DMapSettings *mMap; + QgsCameraController *mCameraController = nullptr; + Qgs3DMapSettings *mMap = nullptr; QTimer *mAnimationTimer = nullptr; }; diff --git a/src/app/mesh/qgsmeshtransformcoordinatesdockwidget.h b/src/app/mesh/qgsmeshtransformcoordinatesdockwidget.h index 530ea717bcf1..d17df2fd8796 100644 --- a/src/app/mesh/qgsmeshtransformcoordinatesdockwidget.h +++ b/src/app/mesh/qgsmeshtransformcoordinatesdockwidget.h @@ -70,7 +70,7 @@ class APP_EXPORT QgsMeshTransformCoordinatesDockWidget : public QgsDockWidget, p private: QgsMeshTransformVerticesByExpression mTransformVertices; - QgsMeshLayer *mInputLayer; + QgsMeshLayer *mInputLayer = nullptr; QList mInputVertices; bool mIsCalculated = false; bool mIsResultValid = false; From 24a70e202d56c98aee7dafc4ea168f6b2df2fc15 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 16 Dec 2024 11:29:53 +1000 Subject: [PATCH 02/11] Fix coverity nullptr dereference warning --- src/app/pluginmanager/qgspluginmanager.cpp | 8 ++++---- src/app/pluginmanager/qgspluginmanager.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/pluginmanager/qgspluginmanager.cpp b/src/app/pluginmanager/qgspluginmanager.cpp index e1d918bc0d62..5c4807c4c895 100644 --- a/src/app/pluginmanager/qgspluginmanager.cpp +++ b/src/app/pluginmanager/qgspluginmanager.cpp @@ -1650,10 +1650,10 @@ void QgsPluginManager::ckbDeprecated_toggled( bool state ) // PRIVATE METHODS /////////////////////////////////////////////////////////////////// -bool QgsPluginManager::isPluginEnabled( QString key ) +bool QgsPluginManager::isPluginEnabled( const QString &key ) { const QMap *plugin = pluginMetadata( key ); - if ( plugin->isEmpty() ) + if ( !plugin || plugin->isEmpty() ) { // No such plugin in the metadata registry return false; @@ -1663,8 +1663,8 @@ bool QgsPluginManager::isPluginEnabled( QString key ) if ( plugin->value( QStringLiteral( "pythonic" ) ) != QLatin1String( "true" ) ) { // Trim "cpp:" prefix from cpp plugin id - key = key.mid( 4 ); - return ( mySettings.value( "/Plugins/" + key, QVariant( false ) ).toBool() ); + const QString trimmedKey = key.mid( 4 ); + return ( mySettings.value( "/Plugins/" + trimmedKey, QVariant( false ) ).toBool() ); } else { diff --git a/src/app/pluginmanager/qgspluginmanager.h b/src/app/pluginmanager/qgspluginmanager.h index fc2bc2d66ce8..210cfd17bddd 100644 --- a/src/app/pluginmanager/qgspluginmanager.h +++ b/src/app/pluginmanager/qgspluginmanager.h @@ -211,7 +211,7 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag void initTabDescriptions(); //! Returns true if given plugin is enabled in QgsSettings - bool isPluginEnabled( QString key ); + bool isPluginEnabled( const QString &key ); //! Returns true if there are plugins available for download in the metadata registry bool hasAvailablePlugins(); From 164e17ab71ef565f48bc9be77334502ad6b4e4b1 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 16 Dec 2024 11:30:56 +1000 Subject: [PATCH 03/11] Fix some use of deprecated implicit capture of this --- src/gui/attributetable/qgsdualview.cpp | 28 +++++++++---------- src/gui/qgsdatasourcemanagerdialog.cpp | 2 +- src/gui/qgsextentwidget.cpp | 2 +- src/gui/qgsexternalstoragefilewidget.cpp | 2 +- .../virtual/qgsvirtuallayerprovider.cpp | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/gui/attributetable/qgsdualview.cpp b/src/gui/attributetable/qgsdualview.cpp index 1f340b8d56eb..efc31af319e5 100644 --- a/src/gui/attributetable/qgsdualview.cpp +++ b/src/gui/attributetable/qgsdualview.cpp @@ -87,7 +87,7 @@ QgsDualView::QgsDualView( QWidget *parent ) connect( mFirstFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editFirstFeature ); connect( mLastFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editLastFeature ); - auto createShortcuts = [=]( const QString &objectName, void ( QgsFeatureListView::*slot )() ) { + auto createShortcuts = [this]( const QString &objectName, void ( QgsFeatureListView::*slot )() ) { QShortcut *sc = QgsGui::shortcutsManager()->shortcutByName( objectName ); // do not assert for sc as it would lead to crashes in testing // or when using custom widgets lib if built with Debug @@ -129,7 +129,7 @@ void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const Qg mLayer = layer; // Keep fields order in sync: force config reset - connect( mLayer, &QgsVectorLayer::updatedFields, this, [=] { + connect( mLayer, &QgsVectorLayer::updatedFields, this, [this] { mFilterModel->setAttributeTableConfig( attributeTableConfig(), /* force */ true ); } ); @@ -154,7 +154,7 @@ void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const Qg mFeatureListView->setModel( mFeatureListModel ); connect( mFilterModel, &QgsAttributeTableFilterModel::sortColumnChanged, this, &QgsDualView::onSortColumnChanged ); - connect( mLayer, &QgsVectorLayer::afterCommitChanges, this, [=] { mFeatureListView->setCurrentFeatureEdited( false ); } ); + connect( mLayer, &QgsVectorLayer::afterCommitChanges, this, [this] { mFeatureListView->setCurrentFeatureEdited( false ); } ); if ( mFeatureListPreviewButton->defaultAction() ) mFeatureListView->setDisplayExpression( mDisplayExpression ); @@ -194,13 +194,13 @@ void QgsDualView::initAttributeForm( const QgsFeature &feature ) connect( mAttributeForm, &QgsAttributeForm::widgetValueChanged, this, &QgsDualView::featureFormAttributeChanged ); connect( mAttributeForm, &QgsAttributeForm::modeChanged, this, &QgsDualView::formModeChanged ); connect( mAttributeForm, &QgsAttributeForm::filterExpressionSet, this, &QgsDualView::filterExpressionSet ); - connect( mAttributeForm, &QgsAttributeForm::flashFeatures, this, [=]( const QString &filter ) { + connect( mAttributeForm, &QgsAttributeForm::flashFeatures, this, [this]( const QString &filter ) { if ( QgsMapCanvas *canvas = mFilterModel->mapCanvas() ) { QgsMapCanvasUtils::flashMatchingFeatures( canvas, mLayer, filter ); } } ); - connect( mAttributeForm, &QgsAttributeForm::zoomToFeatures, this, [=]( const QString &filter ) { + connect( mAttributeForm, &QgsAttributeForm::zoomToFeatures, this, [this]( const QString &filter ) { if ( QgsMapCanvas *canvas = mFilterModel->mapCanvas() ) { QgsMapCanvasUtils::zoomToMatchingFeatures( canvas, mLayer, filter ); @@ -235,7 +235,7 @@ void QgsDualView::columnBoxInit() // Generate action for the preview popup button of the feature list QAction *previewAction = new QAction( icon, text, mFeatureListPreviewButton ); - connect( previewAction, &QAction::triggered, this, [=] { previewColumnChanged( previewAction, fieldName ); } ); + connect( previewAction, &QAction::triggered, this, [this, previewAction, fieldName] { previewColumnChanged( previewAction, fieldName ); } ); mPreviewColumnsMenu->addAction( previewAction ); if ( text == defaultField ) @@ -250,17 +250,17 @@ void QgsDualView::columnBoxInit() sortMenuAction->setMenu( sortMenu ); QAction *sortByPreviewExpressionAsc = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "sort.svg" ) ), tr( "By Preview Expression (ascending)" ), this ); - connect( sortByPreviewExpressionAsc, &QAction::triggered, this, [=]() { + connect( sortByPreviewExpressionAsc, &QAction::triggered, this, [this]() { mFeatureListModel->setSortByDisplayExpression( true, Qt::AscendingOrder ); } ); sortMenu->addAction( sortByPreviewExpressionAsc ); QAction *sortByPreviewExpressionDesc = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "sort-reverse.svg" ) ), tr( "By Preview Expression (descending)" ), this ); - connect( sortByPreviewExpressionDesc, &QAction::triggered, this, [=]() { + connect( sortByPreviewExpressionDesc, &QAction::triggered, this, [this]() { mFeatureListModel->setSortByDisplayExpression( true, Qt::DescendingOrder ); } ); sortMenu->addAction( sortByPreviewExpressionDesc ); QAction *sortByPreviewExpressionCustom = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mIconExpressionPreview.svg" ) ), tr( "By Custom Expression" ), this ); - connect( sortByPreviewExpressionCustom, &QAction::triggered, this, [=]() { + connect( sortByPreviewExpressionCustom, &QAction::triggered, this, [this]() { if ( modifySort() ) mFeatureListModel->setSortByDisplayExpression( false ); } ); @@ -584,16 +584,16 @@ void QgsDualView::panOrZoomToFeature( const QgsFeatureIds &featureset ) if ( mBrowsingAutoPanScaleAllowed ) { if ( mAutoPanButton->isChecked() ) - QTimer::singleShot( 0, this, [=]() { + QTimer::singleShot( 0, this, [this, featureset, canvas]() { canvas->panToFeatureIds( mLayer, featureset, false ); } ); else if ( mAutoZoomButton->isChecked() ) - QTimer::singleShot( 0, this, [=]() { + QTimer::singleShot( 0, this, [this, featureset, canvas]() { canvas->zoomToFeatureIds( mLayer, featureset ); } ); } if ( mFlashButton->isChecked() ) - QTimer::singleShot( 0, this, [=]() { + QTimer::singleShot( 0, this, [this, featureset, canvas]() { canvas->flashFeatureIds( mLayer, featureset ); } ); mLastFeatureSet = featureset; @@ -900,7 +900,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &maste QgsMapLayerActionContext context; for ( QgsMapLayerAction *action : registeredActions ) { - menu->addAction( action->text(), action, [=]() { + menu->addAction( action->text(), action, [this, action, context]() { Q_NOWARN_DEPRECATED_PUSH action->triggerForFeatures( mLayer, mLayer->selectedFeatures() ); Q_NOWARN_DEPRECATED_POP @@ -958,7 +958,7 @@ void QgsDualView::showViewHeaderMenu( QPoint point ) connect( organize, &QAction::triggered, this, &QgsDualView::organizeColumns ); mHorizontalHeaderMenu->addAction( organize ); QAction *sort = new QAction( tr( "&Sort…" ), mHorizontalHeaderMenu ); - connect( sort, &QAction::triggered, this, [=]() { modifySort(); } ); + connect( sort, &QAction::triggered, this, [this]() { modifySort(); } ); mHorizontalHeaderMenu->addAction( sort ); mHorizontalHeaderMenu->popup( mTableView->horizontalHeader()->mapToGlobal( point ) ); diff --git a/src/gui/qgsdatasourcemanagerdialog.cpp b/src/gui/qgsdatasourcemanagerdialog.cpp index f464630dfa72..f55afc267616 100644 --- a/src/gui/qgsdatasourcemanagerdialog.cpp +++ b/src/gui/qgsdatasourcemanagerdialog.cpp @@ -178,7 +178,7 @@ void QgsDataSourceManagerDialog::configureFromUri( const QString &pageName, cons const int pageIdx = mPageProviderNames.indexOf( pageName ); if ( pageIdx != -1 ) { - QTimer::singleShot( 0, this, [=] { + QTimer::singleShot( 0, this, [this, pageIdx, uri] { setCurrentPage( pageIdx ); if ( QgsAbstractDataSourceWidget *dataSourceWidget = qobject_cast( ui->mOptionsStackedWidget->currentWidget() ) ) { diff --git a/src/gui/qgsextentwidget.cpp b/src/gui/qgsextentwidget.cpp index 7b3c8c8fe853..a5c90521d8dd 100644 --- a/src/gui/qgsextentwidget.cpp +++ b/src/gui/qgsextentwidget.cpp @@ -451,7 +451,7 @@ void QgsExtentWidget::bookmarkMenuAboutToShow() } QAction *action = new QAction( mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast( QgsBookmarkManagerModel::CustomRole::Name ) ).toString(), mBookmarkMenu ); const QgsReferencedRectangle extent = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast( QgsBookmarkManagerModel::CustomRole::Extent ) ).value(); - connect( action, &QAction::triggered, this, [=] { setOutputExtentFromUser( extent, extent.crs() ); } ); + connect( action, &QAction::triggered, this, [this, extent] { setOutputExtentFromUser( extent, extent.crs() ); } ); destMenu->addAction( action ); } diff --git a/src/gui/qgsexternalstoragefilewidget.cpp b/src/gui/qgsexternalstoragefilewidget.cpp index 07c3a6c6d9da..ff909e1a33c8 100644 --- a/src/gui/qgsexternalstoragefilewidget.cpp +++ b/src/gui/qgsexternalstoragefilewidget.cpp @@ -242,7 +242,7 @@ void QgsExternalStorageFileWidget::storeExternalFiles( QStringList fileNames, QS connect( storedContent, &QgsExternalStorageStoredContent::progressChanged, mProgressBar, &QProgressBar::setValue ); connect( mCancelButton, &QToolButton::clicked, storedContent, &QgsExternalStorageStoredContent::cancel ); - auto onStoreFinished = [=] { + auto onStoreFinished = [this, storedContent, fileNames, storedUrls, filePath, url] { mStoreInProgress = false; updateLayout(); storedContent->deleteLater(); diff --git a/src/providers/virtual/qgsvirtuallayerprovider.cpp b/src/providers/virtual/qgsvirtuallayerprovider.cpp index 1d6029df61a7..16761f09e94d 100644 --- a/src/providers/virtual/qgsvirtuallayerprovider.cpp +++ b/src/providers/virtual/qgsvirtuallayerprovider.cpp @@ -134,7 +134,7 @@ bool QgsVirtualLayerProvider::loadSourceLayers() connect( vl, &QgsVectorLayer::featureAdded, this, &QgsVirtualLayerProvider::invalidateStatistics ); connect( vl, &QgsVectorLayer::featureDeleted, this, &QgsVirtualLayerProvider::invalidateStatistics ); connect( vl, &QgsVectorLayer::geometryChanged, this, &QgsVirtualLayerProvider::invalidateStatistics ); - connect( vl, &QgsVectorLayer::updatedFields, this, [=] { createVirtualTable( vl, layer.name() ); } ); + connect( vl, &QgsVectorLayer::updatedFields, this, [this, vl, layer] { createVirtualTable( vl, layer.name() ); } ); } else { From 9a6c25c02527079e8ddd0a65b1e5d0bced48763c Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 16 Dec 2024 11:31:19 +1000 Subject: [PATCH 04/11] Fix coverity nullptr dereference warning --- src/providers/wfs/qgswfsfeatureiterator.cpp | 56 +++++++++++---------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/providers/wfs/qgswfsfeatureiterator.cpp b/src/providers/wfs/qgswfsfeatureiterator.cpp index e844917a8326..97e833677b2e 100644 --- a/src/providers/wfs/qgswfsfeatureiterator.cpp +++ b/src/providers/wfs/qgswfsfeatureiterator.cpp @@ -630,38 +630,40 @@ void QgsWFSFeatureDownloaderImpl::run( bool serializeFeatures, long long maxFeat if ( f.hasGeometry() && f.geometry().wkbType() == Qgis::WkbType::GeometryCollection && ( mShared->mWKBType == Qgis::WkbType::MultiPoint || mShared->mWKBType == Qgis::WkbType::MultiLineString || mShared->mWKBType == Qgis::WkbType::MultiPolygon ) ) { Qgis::WkbType singleType = QgsWkbTypes::singleType( mShared->mWKBType ); - auto g = f.geometry().constGet(); - auto gc = qgsgeometry_cast( g ); - bool allExpectedType = true; - for ( int i = 0; i < gc->numGeometries(); ++i ) + const QgsAbstractGeometry *g = f.geometry().constGet(); + if ( const QgsGeometryCollection *gc = qgsgeometry_cast( g ) ) { - if ( gc->geometryN( i )->wkbType() != singleType ) - { - allExpectedType = false; - break; - } - } - if ( allExpectedType ) - { - QgsGeometryCollection *newGC; - if ( mShared->mWKBType == Qgis::WkbType::MultiPoint ) - { - newGC = new QgsMultiPoint(); - } - else if ( mShared->mWKBType == Qgis::WkbType::MultiLineString ) - { - newGC = new QgsMultiLineString(); - } - else + bool allExpectedType = true; + for ( int i = 0; i < gc->numGeometries(); ++i ) { - newGC = new QgsMultiPolygon(); + if ( gc->geometryN( i )->wkbType() != singleType ) + { + allExpectedType = false; + break; + } } - newGC->reserve( gc->numGeometries() ); - for ( int i = 0; i < gc->numGeometries(); ++i ) + if ( allExpectedType ) { - newGC->addGeometry( gc->geometryN( i )->clone() ); + QgsGeometryCollection *newGC; + if ( mShared->mWKBType == Qgis::WkbType::MultiPoint ) + { + newGC = new QgsMultiPoint(); + } + else if ( mShared->mWKBType == Qgis::WkbType::MultiLineString ) + { + newGC = new QgsMultiLineString(); + } + else + { + newGC = new QgsMultiPolygon(); + } + newGC->reserve( gc->numGeometries() ); + for ( int i = 0; i < gc->numGeometries(); ++i ) + { + newGC->addGeometry( gc->geometryN( i )->clone() ); + } + f.setGeometry( QgsGeometry( newGC ) ); } - f.setGeometry( QgsGeometry( newGC ) ); } } else if ( f.hasGeometry() && !mShared->mWFSGeometryTypeFilter.isEmpty() && QgsWkbTypes::flatType( f.geometry().wkbType() ) != mShared->mWKBType ) From c03490c74603c23170086f9d0769d31f4be014ad Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 16 Dec 2024 11:32:21 +1000 Subject: [PATCH 05/11] Remove some useless calls --- src/core/layertree/qgslayertreemodellegendnode.cpp | 1 - src/gui/qgsattributeform.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/core/layertree/qgslayertreemodellegendnode.cpp b/src/core/layertree/qgslayertreemodellegendnode.cpp index 7ebd00138106..ac6709580df3 100644 --- a/src/core/layertree/qgslayertreemodellegendnode.cpp +++ b/src/core/layertree/qgslayertreemodellegendnode.cpp @@ -835,7 +835,6 @@ QJsonObject QgsSymbolLegendNode::exportSymbolToJson( const QgsLegendSettings &se { json[ QStringLiteral( "scaleMinDenom" ) ] = mItem.scaleMinDenom(); } - mItem.scaleMaxDenom(); const QgsSymbol *s = mCustomSymbol ? mCustomSymbol.get() : mItem.symbol(); if ( !s ) diff --git a/src/gui/qgsattributeform.cpp b/src/gui/qgsattributeform.cpp index 463440ed8ab1..867a50bd98df 100644 --- a/src/gui/qgsattributeform.cpp +++ b/src/gui/qgsattributeform.cpp @@ -781,7 +781,6 @@ bool QgsAttributeForm::saveMultiEdits() //find changed attributes QgsAttributeMap newAttributeValues; const QList fieldIndexes = mFormEditorWidgets.uniqueKeys(); - mFormEditorWidgets.constBegin(); for ( int fieldIndex : fieldIndexes ) { const QList widgets = mFormEditorWidgets.values( fieldIndex ); From 79aa38958b061af2bb38ed341460798e3c4e34c9 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 17 Dec 2024 07:46:17 +1000 Subject: [PATCH 06/11] Use unique_ptr --- src/providers/wfs/qgswfsfeatureiterator.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/providers/wfs/qgswfsfeatureiterator.cpp b/src/providers/wfs/qgswfsfeatureiterator.cpp index 97e833677b2e..f0b5fabab8fd 100644 --- a/src/providers/wfs/qgswfsfeatureiterator.cpp +++ b/src/providers/wfs/qgswfsfeatureiterator.cpp @@ -644,25 +644,25 @@ void QgsWFSFeatureDownloaderImpl::run( bool serializeFeatures, long long maxFeat } if ( allExpectedType ) { - QgsGeometryCollection *newGC; + std::unique_ptr< QgsGeometryCollection > newGC; if ( mShared->mWKBType == Qgis::WkbType::MultiPoint ) { - newGC = new QgsMultiPoint(); + newGC = std::make_unique< QgsMultiPoint >(); } else if ( mShared->mWKBType == Qgis::WkbType::MultiLineString ) { - newGC = new QgsMultiLineString(); + newGC = std::make_unique< QgsMultiLineString >(); } else { - newGC = new QgsMultiPolygon(); + newGC = std::make_unique< QgsMultiPolygon >(); } newGC->reserve( gc->numGeometries() ); for ( int i = 0; i < gc->numGeometries(); ++i ) { newGC->addGeometry( gc->geometryN( i )->clone() ); } - f.setGeometry( QgsGeometry( newGC ) ); + f.setGeometry( std::move( newGC ) ); } } } From c5c5fae7e3f537a3374e8d5ed313466ac0faa27b Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 17 Dec 2024 11:28:57 +1000 Subject: [PATCH 07/11] Fix coverity 'nesting level does not match indentation' warnings The QgsDebugMsgLevel macro is multiline, so we need to enclose it in braces --- src/core/pointcloud/qgspointcloudlayerexporter.cpp | 4 ++++ src/core/proj/qgscoordinatereferencesystem.cpp | 4 ++++ src/core/proj/qgscoordinatetransform.cpp | 2 ++ src/core/vector/qgsvectorlayerprofilegenerator.cpp | 4 ++++ src/gui/attributetable/qgsattributetablemodel.cpp | 4 ++++ src/providers/postgres/qgspostgresconn.cpp | 6 ++++++ 6 files changed, 24 insertions(+) diff --git a/src/core/pointcloud/qgspointcloudlayerexporter.cpp b/src/core/pointcloud/qgspointcloudlayerexporter.cpp index b3c13f2f41c4..e5e4787792d6 100644 --- a/src/core/pointcloud/qgspointcloudlayerexporter.cpp +++ b/src/core/pointcloud/qgspointcloudlayerexporter.cpp @@ -195,8 +195,12 @@ void QgsPointCloudLayerExporter::prepareExport() if ( mFormat == ExportFormat::Memory ) { +#ifdef QGISDEBUG if ( QApplication::instance()->thread() != QThread::currentThread() ) + { QgsDebugMsgLevel( QStringLiteral( "prepareExport() should better be called from the main thread!" ), 2 ); + } +#endif mMemoryLayer = QgsMemoryProviderUtils::createMemoryLayer( mName, outputFields(), Qgis::WkbType::PointZ, mTargetCrs ); } diff --git a/src/core/proj/qgscoordinatereferencesystem.cpp b/src/core/proj/qgscoordinatereferencesystem.cpp index 8f49fec5f94a..5b4d2ff63dfc 100644 --- a/src/core/proj/qgscoordinatereferencesystem.cpp +++ b/src/core/proj/qgscoordinatereferencesystem.cpp @@ -1724,9 +1724,13 @@ bool QgsCoordinateReferenceSystem::setWktString( const QString &wkt ) QgsDebugMsgLevel( QStringLiteral( "This CRS could *** NOT *** be set from the supplied Wkt " ), 2 ); QgsDebugMsgLevel( "INPUT: " + wkt, 2 ); for ( auto iter = warnings; iter && *iter; ++iter ) + { QgsDebugMsgLevel( *iter, 2 ); + } for ( auto iter = grammarErrors; iter && *iter; ++iter ) + { QgsDebugMsgLevel( *iter, 2 ); + } QgsDebugMsgLevel( QStringLiteral( "---------------------------------------------------------------\n" ), 2 ); } proj_string_list_destroy( warnings ); diff --git a/src/core/proj/qgscoordinatetransform.cpp b/src/core/proj/qgscoordinatetransform.cpp index e5736e85da1e..cf7963adda94 100644 --- a/src/core/proj/qgscoordinatetransform.cpp +++ b/src/core/proj/qgscoordinatetransform.cpp @@ -782,7 +782,9 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double * #ifdef QGISDEBUG if ( !mHasContext ) + { QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 ); + } #endif // use proj4 to do the transform diff --git a/src/core/vector/qgsvectorlayerprofilegenerator.cpp b/src/core/vector/qgsvectorlayerprofilegenerator.cpp index 17f6cae20a90..c6406dcf0be5 100644 --- a/src/core/vector/qgsvectorlayerprofilegenerator.cpp +++ b/src/core/vector/qgsvectorlayerprofilegenerator.cpp @@ -1443,8 +1443,12 @@ bool QgsVectorLayerProfileGenerator::generateProfileForPolygons() intersection.reset( mProfileBufferedCurveEngine->intersection( shiftedPoly.get(), &error ) ); if ( intersection.get() ) processTriangleLineIntersect( clampedPolygon.get(), intersection.get(), transformedParts, crossSectionParts ); +#ifdef QGISDEBUG else + { QgsDebugMsgLevel( QStringLiteral( "processPolygon after shift bad geom! error: %1" ).arg( error ), 0 ); + } +#endif } } diff --git a/src/gui/attributetable/qgsattributetablemodel.cpp b/src/gui/attributetable/qgsattributetablemodel.cpp index 599af4f6ed78..7a597bc8f524 100644 --- a/src/gui/attributetable/qgsattributetablemodel.cpp +++ b/src/gui/attributetable/qgsattributetablemodel.cpp @@ -235,11 +235,15 @@ bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex & QgsDebugMsgLevel( QStringLiteral( "after removal rows %1, ids %2" ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 4 ); QgsDebugMsgLevel( QStringLiteral( "id->row" ), 4 ); for ( QHash::const_iterator it = mIdRowMap.constBegin(); it != mIdRowMap.constEnd(); ++it ) + { QgsDebugMsgLevel( QStringLiteral( "%1->%2" ).arg( FID_TO_STRING( it.key() ) ).arg( *it ), 4 ); + } QgsDebugMsgLevel( QStringLiteral( "row->id" ), 4 ); for ( QHash::const_iterator it = mRowIdMap.constBegin(); it != mRowIdMap.constEnd(); ++it ) + { QgsDebugMsgLevel( QStringLiteral( "%1->%2" ).arg( it.key() ).arg( FID_TO_STRING( *it ) ), 4 ); + } } #endif diff --git a/src/providers/postgres/qgspostgresconn.cpp b/src/providers/postgres/qgspostgresconn.cpp index fe87882499dd..6ae7845272a8 100644 --- a/src/providers/postgres/qgspostgresconn.cpp +++ b/src/providers/postgres/qgspostgresconn.cpp @@ -1592,8 +1592,12 @@ int QgsPostgresConn::PQCancel() { char errbuf[255]; result = ::PQcancel( cancel, errbuf, 255 ); +#ifdef QGISDEBUG if ( !result ) + { QgsDebugMsgLevel( QStringLiteral( "Error canceling the query:" ).arg( errbuf ), 3 ); + } +#endif } ::PQfreeCancel( cancel ); return result; @@ -2028,7 +2032,9 @@ void QgsPostgresConn::deduceEndian() "FETCH FORWARD 1 FROM oidcursor;" "CLOSE oidcursor;" "COMMIT;" ) ) ) + { QgsDebugMsgLevel( QStringLiteral( "PQsendQuery(...) error %1" ).arg( PQerrorMessage() ), 2 ); + } for ( ;; ) { From a5de6596f5430578a35e2e96a8ad95035cdd284f Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 17 Dec 2024 11:30:18 +1000 Subject: [PATCH 08/11] Fix coverity overflowed constant warning --- src/core/providers/ogr/qgsogrprovider.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/providers/ogr/qgsogrprovider.cpp b/src/core/providers/ogr/qgsogrprovider.cpp index f08462a6a481..67a9ab99baa0 100644 --- a/src/core/providers/ogr/qgsogrprovider.cpp +++ b/src/core/providers/ogr/qgsogrprovider.cpp @@ -626,6 +626,8 @@ QString QgsOgrProvider::subsetStringHelpUrl() const uint QgsOgrProvider::subLayerCount() const { uint count = layerCount(); + if ( count == 0 ) + return 0; QString errCause; QgsOgrLayerUniquePtr layerStyles = QgsOgrProviderUtils::getLayer( mFilePath, QStringLiteral( "layer_styles" ), errCause ); From a27931e1968d47080b9a46daac3e664efd80d25e Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 17 Dec 2024 11:32:10 +1000 Subject: [PATCH 09/11] Fix leak --- src/app/mesh/qgsmaptooleditmeshframe.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/mesh/qgsmaptooleditmeshframe.cpp b/src/app/mesh/qgsmaptooleditmeshframe.cpp index 7c170927bff4..095e5aa77aae 100644 --- a/src/app/mesh/qgsmaptooleditmeshframe.cpp +++ b/src/app/mesh/qgsmaptooleditmeshframe.cpp @@ -2754,12 +2754,12 @@ void QgsMapToolEditMeshFrame::selectByExpression( const QString &textExpression, return; QgsExpression expression( textExpression ); - std::unique_ptr distArea = std::make_unique(); - distArea->setSourceCrs( mCurrentLayer->crs(), QgsProject::instance()->transformContext() ); - distArea->setEllipsoid( QgsProject::instance()->ellipsoid() ); + QgsDistanceArea distArea; + distArea.setSourceCrs( mCurrentLayer->crs(), QgsProject::instance()->transformContext() ); + distArea.setEllipsoid( QgsProject::instance()->ellipsoid() ); expression.setAreaUnits( QgsProject::instance()->areaUnits() ); expression.setDistanceUnits( QgsProject::instance()->distanceUnits() ); - expression.setGeomCalculator( distArea.release() ); + expression.setGeomCalculator( &distArea ); switch ( elementType ) { From 2ba1cf4116ab694557fe2a9b8a2fc36db832ebe1 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 17 Dec 2024 11:36:29 +1000 Subject: [PATCH 10/11] Fix leak --- src/core/classification/qgsclassificationmethodregistry.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/classification/qgsclassificationmethodregistry.cpp b/src/core/classification/qgsclassificationmethodregistry.cpp index 5278f087bd40..e467c2670ed4 100644 --- a/src/core/classification/qgsclassificationmethodregistry.cpp +++ b/src/core/classification/qgsclassificationmethodregistry.cpp @@ -54,8 +54,10 @@ bool QgsClassificationMethodRegistry::addMethod( QgsClassificationMethod *method QgsClassificationMethod *QgsClassificationMethodRegistry::method( const QString &id ) { - QgsClassificationMethod *method = mMethods.value( id, new QgsClassificationCustom() ); - return method->clone(); + auto it = mMethods.constFind( id ); + if ( it == mMethods.constEnd() ) + return new QgsClassificationCustom(); + return it.value()->clone(); } QMap QgsClassificationMethodRegistry::methodNames() const From 6fb137bbd1ad4678f19669472435022c8e2504f5 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 17 Dec 2024 11:40:35 +1000 Subject: [PATCH 11/11] Fix leak in point cloud exporter --- src/core/pointcloud/qgspointcloudlayerexporter.cpp | 2 +- src/core/pointcloud/qgspointcloudlayerexporter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/pointcloud/qgspointcloudlayerexporter.cpp b/src/core/pointcloud/qgspointcloudlayerexporter.cpp index e5e4787792d6..c042aa5d1b11 100644 --- a/src/core/pointcloud/qgspointcloudlayerexporter.cpp +++ b/src/core/pointcloud/qgspointcloudlayerexporter.cpp @@ -54,7 +54,7 @@ QString QgsPointCloudLayerExporter::getOgrDriverName( ExportFormat format ) QgsPointCloudLayerExporter::QgsPointCloudLayerExporter( QgsPointCloudLayer *layer ) : mLayerAttributeCollection( layer->attributes() ) - , mIndex( layer->dataProvider()->index()->clone().release() ) + , mIndex( layer->dataProvider()->index()->clone() ) , mSourceCrs( QgsCoordinateReferenceSystem( layer->crs() ) ) , mTargetCrs( QgsCoordinateReferenceSystem( layer->crs() ) ) { diff --git a/src/core/pointcloud/qgspointcloudlayerexporter.h b/src/core/pointcloud/qgspointcloudlayerexporter.h index 45ed03e42357..fbca3aa606c8 100644 --- a/src/core/pointcloud/qgspointcloudlayerexporter.h +++ b/src/core/pointcloud/qgspointcloudlayerexporter.h @@ -256,7 +256,7 @@ class CORE_EXPORT QgsPointCloudLayerExporter SIP_NODEFAULTCTORS const QgsPointCloudAttributeCollection mLayerAttributeCollection; - QgsPointCloudIndex *mIndex = nullptr; + std::unique_ptr< QgsPointCloudIndex > mIndex; QString mName = QObject::tr( "Exported" ); ExportFormat mFormat = ExportFormat::Memory; QString mFilename;