Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 767fc05
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/app/qgsvectorlayerloadstyledialog.cpp
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

0 comments on commit 767fc05

Please sign in to comment.