Skip to content

Commit

Permalink
Fix file based data collection items should requerying sublayers
Browse files Browse the repository at this point in the history
when refreshed, or they won't respond to external changes
to the container (such as layers added/deleted elsewhere)
  • Loading branch information
nyalldawson committed Jul 27, 2021
1 parent 00f9d7e commit 201c13b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/core/browser/qgsfilebaseddataitemprovider.cpp
Expand Up @@ -133,14 +133,25 @@ QgsFileDataCollectionItem::QgsFileDataCollectionItem( QgsDataItem *parent, const

QVector<QgsDataItem *> QgsFileDataCollectionItem::createChildren()
{
if ( QgsProviderUtils::sublayerDetailsAreIncomplete( mSublayers, QgsProviderUtils::SublayerCompletenessFlag::IgnoreUnknownFeatureCount ) )
QList< QgsProviderSublayerDetails> sublayers;
if ( QgsProviderUtils::sublayerDetailsAreIncomplete( mSublayers, QgsProviderUtils::SublayerCompletenessFlag::IgnoreUnknownFeatureCount )
|| mSublayers.empty() )
{
sublayers = QgsProviderRegistry::instance()->querySublayers( path(), Qgis::SublayerQueryFlag::ResolveGeometryType );
}
else
{
mSublayers = QgsProviderRegistry::instance()->querySublayers( path(), Qgis::SublayerQueryFlag::ResolveGeometryType );
sublayers = mSublayers;
}
// only ever use the initial sublayers for first population -- after that we requery when asked to create children,
// or the item won't "refresh" and update its sublayers when the actual file changes
mSublayers.clear();
// remove the fast flag -- after the first population we need to requery the dataset
setCapabilities( capabilities2() & ~static_cast< int >( Qgis::BrowserItemCapability::Fast ) );

QVector<QgsDataItem *> children;
children.reserve( mSublayers.size() );
for ( const QgsProviderSublayerDetails &sublayer : std::as_const( mSublayers ) )
children.reserve( sublayers.size() );
for ( const QgsProviderSublayerDetails &sublayer : std::as_const( sublayers ) )
{
QgsProviderSublayerItem *item = new QgsProviderSublayerItem( this, sublayer.name(), sublayer );
children.append( item );
Expand Down

0 comments on commit 201c13b

Please sign in to comment.