Skip to content

Commit

Permalink
Do not crash on spatialite setSql connect
Browse files Browse the repository at this point in the history
Fixes #41950
  • Loading branch information
elpaso authored and nyalldawson committed Mar 3, 2021
1 parent badb014 commit d112261
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/providers/spatialite/qgsspatialitesourceselect.cpp
Expand Up @@ -521,7 +521,13 @@ QString QgsSpatiaLiteSourceSelect::connectionInfo()
void QgsSpatiaLiteSourceSelect::setSql( const QModelIndex &index )
{
QModelIndex idx = mProxyModel.mapToSource( index );
QString tableName = mTableModel.itemFromIndex( idx.sibling( idx.row(), 0 ) )->text();
const auto item { mTableModel.itemFromIndex( idx.sibling( idx.row(), 0 ) ) };
if ( !item )
{
return;
}

const QString tableName = item->text();

const QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() };
QgsVectorLayer *vlayer = new QgsVectorLayer( layerURI( idx ), tableName, QStringLiteral( "spatialite" ), options );
Expand Down Expand Up @@ -588,7 +594,9 @@ void QgsSpatiaLiteSourceSelect::setSearchExpression( const QString &regexp )

void QgsSpatiaLiteSourceSelect::treeWidgetSelectionChanged( const QItemSelection &, const QItemSelection & )
{
emit enableButtons( !mTablesTreeView->selectionModel()->selection().isEmpty() );
const bool selectionIsNotEmpty { !mTablesTreeView->selectionModel()->selection().isEmpty() };
mBuildQueryButton->setEnabled( selectionIsNotEmpty );
emit enableButtons( selectionIsNotEmpty );
}

void QgsSpatiaLiteSourceSelect::showHelp()
Expand Down

0 comments on commit d112261

Please sign in to comment.