Skip to content

Commit

Permalink
Fix crash loading style from postgres db when there is no "layer_styl…
Browse files Browse the repository at this point in the history
…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 897322a
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/app/qgsvectorlayerloadstyledialog.cpp
Expand Up @@ -128,9 +128,10 @@ QString QgsVectorLayerLoadStyleDialog::filePath() const


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


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


Expand Down

0 comments on commit 897322a

Please sign in to comment.