Skip to content
Permalink
Browse files

Merge pull request #8267 from elpaso/bugfix-20155-pg-style-crash

Fix crash loading style from postgres db when there is no "layer_styl…
  • Loading branch information
elpaso committed Oct 23, 2018
2 parents 64c99b7 + 897322a commit f7cd2cf2a1ecbc424db5c3b205828e88d1324f07
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 f7cd2cf

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