Skip to content

Commit

Permalink
Fix remaining cppcheck nullPointerRedundantCheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 17, 2023
1 parent 8451357 commit 22b3b2d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
71 changes: 39 additions & 32 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -191,15 +191,16 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
restoreGeometry( settings.value( QStringLiteral( "Windows/BetterAttributeTable/geometry" ) ).toByteArray() );

QgsDistanceArea da;
da.setSourceCrs( mLayer->crs(), QgsProject::instance()->transformContext() );
if ( mLayer )
da.setSourceCrs( mLayer->crs(), QgsProject::instance()->transformContext() );
da.setEllipsoid( QgsProject::instance()->ellipsoid() );

QgsAttributeEditorContext editorContext = QgisApp::instance()->createAttributeEditorContext();
editorContext.setDistanceArea( da );

QgsFeatureRequest r;
bool needsGeom = false;
if ( mLayer->geometryType() != Qgis::GeometryType::Null &&
if ( mLayer && mLayer->geometryType() != Qgis::GeometryType::Null &&
initialMode == QgsAttributeTableFilterModel::ShowVisible )
{
QgsMapCanvas *mc = QgisApp::instance()->mapCanvas();
Expand All @@ -223,12 +224,15 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
r.setFlags( QgsFeatureRequest::NoGeometry );

// Initialize dual view
mMainView->init( mLayer, QgisApp::instance()->mapCanvas(), r, editorContext, false );
if ( mLayer )
{
mMainView->init( mLayer, QgisApp::instance()->mapCanvas(), r, editorContext, false );

QgsAttributeTableConfig config = mLayer->attributeTableConfig();
mMainView->setAttributeTableConfig( config );
QgsAttributeTableConfig config = mLayer->attributeTableConfig();
mMainView->setAttributeTableConfig( config );

mFeatureFilterWidget->init( mLayer, editorContext, mMainView, QgisApp::instance()->messageBar(), QgsMessageBar::defaultMessageTimeout() );
mFeatureFilterWidget->init( mLayer, editorContext, mMainView, QgisApp::instance()->messageBar(), QgsMessageBar::defaultMessageTimeout() );
}

mActionFeatureActions = new QToolButton();
mActionFeatureActions->setAutoRaise( false );
Expand All @@ -242,27 +246,30 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
connect( mActionSetStyles, &QAction::triggered, this, &QgsAttributeTableDialog::openConditionalStyles );

// info from layer to table
connect( mLayer, &QgsVectorLayer::editingStarted, this, &QgsAttributeTableDialog::editingToggled );
connect( mLayer, &QgsVectorLayer::editingStopped, this, &QgsAttributeTableDialog::editingToggled );
connect( mLayer, &QObject::destroyed, mMainView, &QgsDualView::cancelProgress );
connect( mLayer, &QgsVectorLayer::selectionChanged, this, &QgsAttributeTableDialog::updateTitle );
connect( mLayer, &QgsVectorLayer::featureAdded, this, &QgsAttributeTableDialog::updateTitle );
connect( mLayer, &QgsVectorLayer::featuresDeleted, this, &QgsAttributeTableDialog::updateTitle );
connect( mLayer, &QgsVectorLayer::editingStopped, this, &QgsAttributeTableDialog::updateTitle );
connect( mLayer, &QgsVectorLayer::readOnlyChanged, this, &QgsAttributeTableDialog::editingToggled );
connect( mLayer, &QgsVectorLayer::layerModified, this, &QgsAttributeTableDialog::updateLayerModifiedActions );

// When transaction group is enabled, collect related layers and connect modified actions to enable save action
const auto relations { QgsProject::instance()->relationManager()->referencedRelations( mLayer ) };
const auto transactionGroups = QgsProject::instance()->transactionGroups();
for ( const auto &relation : std::as_const( relations ) )
if ( mLayer )
{
for ( auto it = transactionGroups.constBegin(); it != transactionGroups.constEnd(); ++it )
connect( mLayer, &QgsVectorLayer::editingStarted, this, &QgsAttributeTableDialog::editingToggled );
connect( mLayer, &QgsVectorLayer::editingStopped, this, &QgsAttributeTableDialog::editingToggled );
connect( mLayer, &QObject::destroyed, mMainView, &QgsDualView::cancelProgress );
connect( mLayer, &QgsVectorLayer::selectionChanged, this, &QgsAttributeTableDialog::updateTitle );
connect( mLayer, &QgsVectorLayer::featureAdded, this, &QgsAttributeTableDialog::updateTitle );
connect( mLayer, &QgsVectorLayer::featuresDeleted, this, &QgsAttributeTableDialog::updateTitle );
connect( mLayer, &QgsVectorLayer::editingStopped, this, &QgsAttributeTableDialog::updateTitle );
connect( mLayer, &QgsVectorLayer::readOnlyChanged, this, &QgsAttributeTableDialog::editingToggled );
connect( mLayer, &QgsVectorLayer::layerModified, this, &QgsAttributeTableDialog::updateLayerModifiedActions );

// When transaction group is enabled, collect related layers and connect modified actions to enable save action
const auto relations { QgsProject::instance()->relationManager()->referencedRelations( mLayer ) };
const auto transactionGroups = QgsProject::instance()->transactionGroups();
for ( const auto &relation : std::as_const( relations ) )
{
if ( relation.isValid() && it.value()->layers().contains( { mLayer, relation.referencingLayer() } ) )
for ( auto it = transactionGroups.constBegin(); it != transactionGroups.constEnd(); ++it )
{
mReferencingLayers.push_back( relation.referencingLayer() );
connect( relation.referencingLayer(), &QgsVectorLayer::layerModified, this, &QgsAttributeTableDialog::updateLayerModifiedActions );
if ( relation.isValid() && it.value()->layers().contains( { mLayer, relation.referencingLayer() } ) )
{
mReferencingLayers.push_back( relation.referencingLayer() );
connect( relation.referencingLayer(), &QgsVectorLayer::layerModified, this, &QgsAttributeTableDialog::updateLayerModifiedActions );
}
}
}
}
Expand Down Expand Up @@ -333,7 +340,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
mActionFeatureActions->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mAction.svg" ) ) );

// toggle editing
QgsVectorDataProvider::Capabilities capabilities = mLayer->dataProvider()->capabilities();
QgsVectorDataProvider::Capabilities capabilities = ( mLayer && mLayer->dataProvider() ) ? mLayer->dataProvider()->capabilities() : QgsVectorDataProvider::Capabilities();
bool canChangeAttributes = capabilities & QgsVectorDataProvider::ChangeAttributeValues;
bool canDeleteFeatures = capabilities & QgsVectorDataProvider::DeleteFeatures;
bool canAddAttributes = capabilities & QgsVectorDataProvider::AddAttributes;
Expand All @@ -343,20 +350,20 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr

mActionToggleEditing->blockSignals( true );
mActionToggleEditing->setCheckable( true );
mActionToggleEditing->setChecked( mLayer->isEditable() );
mActionToggleEditing->setChecked( mLayer && mLayer->isEditable() );
mActionToggleEditing->blockSignals( false );

mActionSaveEdits->setEnabled( mActionToggleEditing->isEnabled() && mLayer->isEditable() && mLayer->isModified() );
mActionReload->setEnabled( ! mLayer->isEditable() );
mActionAddAttribute->setEnabled( ( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() );
mActionRemoveAttribute->setEnabled( canDeleteAttributes && mLayer->isEditable() );
mActionSaveEdits->setEnabled( mActionToggleEditing->isEnabled() && mLayer && mLayer->isEditable() && mLayer->isModified() );
mActionReload->setEnabled( mLayer && !mLayer->isEditable() );
mActionAddAttribute->setEnabled( ( canChangeAttributes || canAddAttributes ) && mLayer && mLayer->isEditable() );
mActionRemoveAttribute->setEnabled( canDeleteAttributes && mLayer && mLayer->isEditable() );
if ( !canDeleteFeatures )
{
mToolbar->removeAction( mActionDeleteSelected );
mToolbar->removeAction( mActionCutSelectedRows );
}
mActionAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() );
mActionPasteFeatures->setEnabled( canAddFeatures && mLayer->isEditable() );
mActionAddFeature->setEnabled( canAddFeatures && mLayer && mLayer->isEditable() );
mActionPasteFeatures->setEnabled( canAddFeatures && mLayer && mLayer->isEditable() );
if ( !canAddFeatures )
{
mToolbar->removeAction( mActionAddFeature );
Expand Down
2 changes: 1 addition & 1 deletion src/core/maprenderer/qgsmaprenderersequentialjob.cpp
Expand Up @@ -83,9 +83,9 @@ void QgsMapRendererSequentialJob::cancel()
return;

QgsDebugMsgLevel( QStringLiteral( "sequential - cancel internal" ), 5 );
// cppcheck-suppress nullPointerRedundantCheck
mInternalJob->cancel();

// cppcheck-suppress nullPointerRedundantCheck
Q_ASSERT( !mInternalJob && !mPainter );
}

Expand Down
5 changes: 4 additions & 1 deletion src/server/qgsserverplugins.cpp
Expand Up @@ -73,7 +73,10 @@ bool QgsServerPlugins::initPlugins( QgsServerInterface *interface )

QgsDebugMsg( QStringLiteral( "Python support library's instance() symbol resolved." ) );
sPythonUtils = pythonlib_inst();
sPythonUtils->initServerPython( interface );
if ( sPythonUtils )
{
sPythonUtils->initServerPython( interface );
}

if ( sPythonUtils && sPythonUtils->isEnabled() )
{
Expand Down

0 comments on commit 22b3b2d

Please sign in to comment.