Skip to content

Commit

Permalink
Fixes #34982 : set sql filter on the right row for postgres datasource
Browse files Browse the repository at this point in the history
(cherry picked from commit a261a06)
  • Loading branch information
troopa81 authored and nyalldawson committed Jun 19, 2020
1 parent 6b5834f commit 0361872
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/providers/postgres/qgspgtablemodel.cpp
Expand Up @@ -250,6 +250,7 @@ void QgsPgTableModel::setSql( const QModelIndex &index, const QString &sql )
QModelIndex schemaSibling = index.sibling( index.row(), DbtmSchema );
QModelIndex tableSibling = index.sibling( index.row(), DbtmTable );
QModelIndex geomSibling = index.sibling( index.row(), DbtmGeomCol );
QModelIndex geomTypeSibling = index.sibling( index.row(), DbtmType );

if ( !schemaSibling.isValid() || !tableSibling.isValid() || !geomSibling.isValid() )
{
Expand All @@ -259,6 +260,7 @@ void QgsPgTableModel::setSql( const QModelIndex &index, const QString &sql )
QString schemaName = itemFromIndex( schemaSibling )->text();
QString tableName = itemFromIndex( tableSibling )->text();
QString geomName = itemFromIndex( geomSibling )->text();
QString geomType = itemFromIndex( geomTypeSibling )->text();

QList<QStandardItem *> schemaItems = findItems( schemaName, Qt::MatchExactly, DbtmSchema );
if ( schemaItems.empty() )
Expand Down Expand Up @@ -289,7 +291,15 @@ void QgsPgTableModel::setSql( const QModelIndex &index, const QString &sql )
continue;
}

if ( itemFromIndex( currentTableIndex )->text() == tableName && itemFromIndex( currentGeomIndex )->text() == geomName )
QModelIndex currentGeomType = currentChildIndex.sibling( i, DbtmType );
if ( !currentGeomType.isValid() )
{
continue;
}

if ( itemFromIndex( currentTableIndex )->text() == tableName
&& itemFromIndex( currentGeomIndex )->text() == geomName
&& itemFromIndex( currentGeomType )->text() == geomType )
{
QModelIndex sqlIndex = currentChildIndex.sibling( i, DbtmSql );
if ( sqlIndex.isValid() )
Expand Down

0 comments on commit 0361872

Please sign in to comment.