Skip to content
Permalink
Browse files

Fix crash loading style from postgres db when there is no "layer_styl…

…es" table in the database

Fix #20155 -crash loading style from postgres db when there is no "layer_styles" table in the database
  • Loading branch information
elpaso committed Oct 22, 2018
1 parent 225c922 commit 897322a4ea985e42644a7ae2f7a9e1e85a22b859
Showing with 19 additions and 15 deletions.
  1. +19 −15 src/app/qgsvectorlayerloadstyledialog.cpp
@@ -128,9 +128,10 @@ QString QgsVectorLayerLoadStyleDialog::filePath() const

void QgsVectorLayerLoadStyleDialog::initializeLists( const QStringList &ids, const QStringList &names, const QStringList &descriptions, int sectionLimit )
{
// -1 means no ids
mSectionLimit = sectionLimit;
int relatedTableNOfCols = sectionLimit > 0 ? 2 : 1;
int othersTableNOfCols = ids.count() - sectionLimit > 0 ? 2 : 1;
int othersTableNOfCols = ( sectionLimit >= 0 && ids.count() - sectionLimit > 0 ) ? 2 : 1;
QString twoColsHeader( QStringLiteral( "Name;Description" ) );
QString oneColsHeader( QStringLiteral( "No styles found in the database" ) );
QString relatedTableHeader = relatedTableNOfCols == 1 ? oneColsHeader : twoColsHeader;
@@ -141,24 +142,27 @@ void QgsVectorLayerLoadStyleDialog::initializeLists( const QStringList &ids, con
mRelatedTable->setHorizontalHeaderLabels( relatedTableHeader.split( ';' ) );
mOthersTable->setHorizontalHeaderLabels( othersTableHeader.split( ';' ) );
mRelatedTable->setRowCount( sectionLimit );
mOthersTable->setRowCount( ids.count() - sectionLimit );
mOthersTable->setRowCount( sectionLimit >= 0 ? ( ids.count() - sectionLimit ) : 0 );
mRelatedTable->setDisabled( relatedTableNOfCols == 1 );
mOthersTable->setDisabled( othersTableNOfCols == 1 );

for ( int i = 0; i < sectionLimit; i++ )
if ( sectionLimit > 0 )
{
QTableWidgetItem *item = new QTableWidgetItem( names.value( i, QString() ) );
item->setData( Qt::UserRole, ids[i] );
mRelatedTable->setItem( i, 0, item );
mRelatedTable->setItem( i, 1, new QTableWidgetItem( descriptions.value( i, QString() ) ) );
}
for ( int i = sectionLimit; i < ids.count(); i++ )
{
int j = i - sectionLimit;
QTableWidgetItem *item = new QTableWidgetItem( names.value( i, QString() ) );
item->setData( Qt::UserRole, ids[i] );
mOthersTable->setItem( j, 0, item );
mOthersTable->setItem( j, 1, new QTableWidgetItem( descriptions.value( i, QString() ) ) );
for ( int i = 0; i < sectionLimit; i++ )
{
QTableWidgetItem *item = new QTableWidgetItem( names.value( i, QString() ) );
item->setData( Qt::UserRole, ids[i] );
mRelatedTable->setItem( i, 0, item );
mRelatedTable->setItem( i, 1, new QTableWidgetItem( descriptions.value( i, QString() ) ) );
}
for ( int i = sectionLimit; i < ids.count(); i++ )
{
int j = i - sectionLimit;
QTableWidgetItem *item = new QTableWidgetItem( names.value( i, QString() ) );
item->setData( Qt::UserRole, ids[i] );
mOthersTable->setItem( j, 0, item );
mOthersTable->setItem( j, 1, new QTableWidgetItem( descriptions.value( i, QString() ) ) );
}
}
}

0 comments on commit 897322a

Please sign in to comment.
You can’t perform that action at this time.