Skip to content
Permalink
Browse files

Remember last used source in load styles dialog

... just a tiny UX improvement
  • Loading branch information
elpaso committed Feb 13, 2019
1 parent 3e041b3 commit 767fc059b20a8995ff1062617c20534a0b35cf0a
Showing with 21 additions and 9 deletions.
  1. +21 −9 src/app/qgsvectorlayerloadstyledialog.cpp
@@ -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 );
@@ -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() );
@@ -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
@@ -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();
}

@@ -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

0 comments on commit 767fc05

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