Skip to content

Commit

Permalink
Merge pull request #9170 from elpaso/bugfix-21254-load-style-from-db
Browse files Browse the repository at this point in the history
[ogr] Show style description instead of name in other styles
  • Loading branch information
elpaso authored Feb 14, 2019
2 parents 7418c18 + 62111b9 commit 24c09d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
30 changes: 21 additions & 9 deletions src/app/qgsvectorlayerloadstyledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,21 @@ QgsVectorLayerLoadStyleDialog::QgsVectorLayerLoadStyleDialog( QgsVectorLayer *la
connect( mStyleTypeComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, [ = ]( int )
{
QgsVectorLayerProperties::StyleType type = currentStyleType();
mFromFileWidget->setVisible( type != QgsVectorLayerProperties::DB );
mFromDbWidget->setVisible( type == QgsVectorLayerProperties::DB );
mDeleteButton->setVisible( type == QgsVectorLayerProperties::DB && mLayer->dataProvider()->isDeleteStyleFromDatabaseSupported() );
mStyleCategoriesListView->setEnabled( currentStyleType() != QgsVectorLayerProperties::SLD );
mFromFileWidget->setVisible( type != QgsVectorLayerProperties::StyleType::DB );
mFromDbWidget->setVisible( type == QgsVectorLayerProperties::StyleType::DB );
mDeleteButton->setVisible( type == QgsVectorLayerProperties::StyleType::DB && mLayer->dataProvider()->isDeleteStyleFromDatabaseSupported() );
mStyleCategoriesListView->setEnabled( currentStyleType() != QgsVectorLayerProperties::StyleType::SLD );
updateLoadButtonState();
} );
mStyleTypeComboBox->addItem( tr( "from file" ), QgsVectorLayerProperties::QML ); // QML is used as entry, but works for SLD too, see currentStyleType()
if ( mLayer->dataProvider()->isSaveAndLoadStyleToDatabaseSupported() )
mStyleTypeComboBox->addItem( tr( "from database (%1)" ).arg( providerName ), QgsVectorLayerProperties::DB );
{
mStyleTypeComboBox->addItem( tr( "from database (%1)" ).arg( providerName ), QgsVectorLayerProperties::StyleType::DB );
if ( settings.value( QStringLiteral( "style/lastLoadStyleTypeSelection" ) ) == QgsVectorLayerProperties::StyleType::DB )
{
mStyleTypeComboBox->setCurrentIndex( mStyleTypeComboBox->findData( QgsVectorLayerProperties::StyleType::DB ) );
}
}

// fill style categories
mModel = new QgsMapLayerStyleCategoriesModel( this );
Expand Down Expand Up @@ -105,6 +111,11 @@ QgsVectorLayerLoadStyleDialog::QgsVectorLayerLoadStyleDialog( QgsVectorLayer *la
connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsVectorLayerLoadStyleDialog::showHelp );
connect( mLoadButton, &QPushButton::clicked, this, &QDialog::accept );
connect( mDeleteButton, &QPushButton::clicked, this, &QgsVectorLayerLoadStyleDialog::deleteStyleFromDB );
connect( this, &QgsVectorLayerLoadStyleDialog::rejected, [ = ]
{
QgsSettings().setValue( QStringLiteral( "style/lastLoadStyleTypeSelection" ), currentStyleType() );
} );

setTabOrder( mRelatedTable, mOthersTable );

restoreGeometry( settings.value( QStringLiteral( "Windows/vectorLayerLoadStyle/geometry" ) ).toByteArray() );
Expand All @@ -113,8 +124,7 @@ QgsVectorLayerLoadStyleDialog::QgsVectorLayerLoadStyleDialog( QgsVectorLayer *la

QgsVectorLayerLoadStyleDialog::~QgsVectorLayerLoadStyleDialog()
{
QgsSettings settings;
settings.setValue( QStringLiteral( "Windows/vectorLayerLoadStyle/geometry" ), saveGeometry() );
QgsSettings().setValue( QStringLiteral( "Windows/vectorLayerLoadStyle/geometry" ), saveGeometry() );
}

QgsMapLayer::StyleCategories QgsVectorLayerLoadStyleDialog::styleCategories() const
Expand Down Expand Up @@ -240,7 +250,9 @@ void QgsVectorLayerLoadStyleDialog::selectionChanged( QTableWidget *styleTable )

void QgsVectorLayerLoadStyleDialog::accept()
{
QgsSettings().setFlagValue( QStringLiteral( "style/lastStyleCategories" ), styleCategories() );
QgsSettings settings;
settings.setFlagValue( QStringLiteral( "style/lastStyleCategories" ), styleCategories() );
settings.setValue( QStringLiteral( "style/lastLoadStyleTypeSelection" ), currentStyleType() );
QDialog::accept();
}

Expand Down Expand Up @@ -268,7 +280,7 @@ void QgsVectorLayerLoadStyleDialog::deleteStyleFromDB()
mRelatedTable->setRowCount( 0 );
mOthersTable->setRowCount( 0 );

//Fill UI widgets again from DB. Other users might have change the styles meanwhile.
//Fill UI widgets again from DB. Other users might have changed the styles meanwhile.
QString errorMsg;
QStringList ids, names, descriptions;
//get the list of styles in the db
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6317,7 +6317,7 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na

listTimestamp.append( ts );
mapIdToStyleName[fid] = styleName;
mapIdToDescription[fid] = styleName;
mapIdToDescription[fid] = description;
mapTimestampToId[ts].append( fid );
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_provider_ogr_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def testStyle(self):
self.assertEqual(errmsg, "")
self.assertEqual(idlist, ['1', '3', '4', '2'])
self.assertEqual(namelist, ['name', 'name2', 'name3', 'name_test2'])
self.assertEqual(desclist, ['description_bis', 'description2', 'description3', 'name_test2'])
self.assertEqual(desclist, ['description_bis', 'description2', 'description3', 'description_test2'])

# Check that layers_style table is not list in subLayers()
vl = QgsVectorLayer(tmpfile, 'test', 'ogr')
Expand Down

0 comments on commit 24c09d1

Please sign in to comment.