Skip to content
Permalink
Browse files

Use the whitelist filter

  • Loading branch information
elpaso committed Mar 11, 2020
1 parent 31aeb6e commit e96e762946b11a137eb3252a9a9cba8f111a784c
Showing with 10 additions and 20 deletions.
  1. +10 −20 src/gui/qgsnewdatabasetablenamewidget.cpp
@@ -48,48 +48,38 @@ QgsNewDatabaseTableNameWidget::QgsNewDatabaseTableNameWidget(

setupUi( this );

QStringList hiddenProviders
{
QStringLiteral( "special:Favorites" ),
QStringLiteral( "special:Drives" ),
QStringLiteral( "special:Volumes" ),
QStringLiteral( "special:Home" ),
QStringLiteral( "special:ProjectHome" )
};
QStringList shownDataItemProvidersFilter;

const auto providerList { QgsApplication::dataItemProviderRegistry()->providers() };
for ( const auto &provider : providerList )
{
if ( provider->dataProviderKey().isEmpty() )
{
hiddenProviders.push_back( provider->name() );
continue;
}
QgsProviderMetadata *metadata { QgsProviderRegistry::instance()->providerMetadata( provider->dataProviderKey() ) };
if ( ! metadata )
{
hiddenProviders.push_back( provider->name() );
continue;
}
if ( provider->capabilities() & QgsDataProvider::DataCapability::Database )
{
if ( ! providersFilter.isEmpty() && ! providersFilter.contains( provider->dataProviderKey() ) )
{
hiddenProviders.push_back( provider->name() );
}
else
if ( providersFilter.isEmpty() || providersFilter.contains( provider->dataProviderKey() ) )
{
mShownProviders.insert( provider->dataProviderKey() );
shownDataItemProvidersFilter.push_back( provider->name() );
}
}
else
{
hiddenProviders.push_back( provider->name() );
}
}

mBrowserProxyModel.setBrowserModel( mBrowserModel );
mBrowserProxyModel.setDataItemProviderKeyFilter( hiddenProviders );
// If a filter was specified but the data provider could not be found
// this makes sure no providers are shown instead of ALL of them
if ( ! providersFilter.isEmpty() && shownDataItemProvidersFilter.isEmpty() )
{
shownDataItemProvidersFilter = providersFilter;
}
mBrowserProxyModel.setShownDataItemProviderKeyFilter( shownDataItemProvidersFilter );
mBrowserProxyModel.setShowLayers( false );
mBrowserTreeView->setHeaderHidden( true );
mBrowserTreeView->setModel( &mBrowserProxyModel );

0 comments on commit e96e762

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