@@ -299,6 +299,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
299
299
mModel = new QgsBrowserModel ( mBrowserView );
300
300
301
301
connect ( QgisApp::instance (), SIGNAL ( newProject () ), mModel , SLOT ( updateProjectHome () ) );
302
+ connect ( mModel , SIGNAL ( fetchFinished ( const QModelIndex & ) ), SLOT ( fetchFinished ( const QModelIndex & ) ) );
302
303
303
304
mProxyModel = new QgsBrowserTreeFilterProxyModel ( this );
304
305
mProxyModel ->setBrowserModel ( mModel );
@@ -309,26 +310,22 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
309
310
mBrowserView ->header ()->setStretchLastSection ( false );
310
311
311
312
QSettings settings;
312
- QString lastPath = settings.value ( " / " + objectName (). toLower () + " /lastExpanded " ).toString ();
313
+ mInitPath = settings.value ( lastExpandedKey () ).toString ();
313
314
314
315
// expand root favourites item
315
316
for ( int i = 0 ; i < mModel ->rowCount (); i++ )
316
317
{
317
318
QModelIndex index = mModel ->index ( i, 0 );
318
319
QgsDataItem* item = mModel ->dataItem ( index );
319
320
if ( item && item->type () == QgsDataItem::Favourites )
320
- mBrowserView ->expand ( index );
321
+ {
322
+ QModelIndex proxyIndex = mProxyModel ->mapFromSource ( index );
323
+ mBrowserView ->expand ( proxyIndex );
324
+ }
321
325
}
322
326
323
327
// expand last expanded path from previous session
324
- QgsDebugMsg ( " lastPath = " + lastPath );
325
- if ( !lastPath.isEmpty () )
326
- {
327
- expandPath ( lastPath );
328
- // save again lastExpanded because QTreeView expands items from deepest and last expanded() signal
329
- // is called from highest item and that is stored in settings
330
- settings.setValue ( " /" + objectName ().toLower () + " /lastExpanded" , lastPath );
331
- }
328
+ expandPath ( mInitPath );
332
329
}
333
330
334
331
QDockWidget::showEvent ( e );
@@ -703,23 +700,73 @@ void QgsBrowserDockWidget::itemExpanded( const QModelIndex& index )
703
700
if ( !item )
704
701
return ;
705
702
706
- settings.setValue ( " / " + objectName (). toLower () + " /lastExpanded " , item->path () );
703
+ settings.setValue ( lastExpandedKey () , item->path () );
707
704
QgsDebugMsg ( " last expanded: " + item->path () );
708
705
}
709
706
710
707
void QgsBrowserDockWidget::expandPath ( QString path )
711
708
{
712
- return ; // debug
713
709
QgsDebugMsg ( " path = " + path );
714
710
711
+ if ( path.isEmpty () )
712
+ return ;
713
+
715
714
if ( !mModel || !mProxyModel )
716
715
return ;
716
+
717
717
QModelIndex srcIndex = mModel ->findPath ( path, Qt::MatchStartsWith );
718
718
QModelIndex index = mProxyModel ->mapFromSource ( srcIndex );
719
719
QgsDebugMsg ( QString ( " srcIndex.isValid() = %1 index.isValid() = %2" ).arg ( srcIndex.isValid () ).arg ( index.isValid () ) );
720
- if ( index.isValid () )
720
+
721
+ if ( !index.isValid () )
722
+ return ;
723
+
724
+ QgsDataItem *item = mModel ->dataItem ( srcIndex );
725
+ if ( !item )
726
+ return ;
727
+
728
+ if ( item->isPopulated () ) // may be already populated if children were added with grandchildren
721
729
{
722
730
mBrowserView ->expand ( index );
723
- mBrowserView ->scrollTo ( index, QAbstractItemView::PositionAtTop );
724
731
}
732
+ else
733
+ {
734
+ mModel ->fetchMore ( srcIndex ); // -> fetch in thread -> fetchFinished
735
+ }
736
+ mBrowserView ->scrollTo ( index, QAbstractItemView::PositionAtTop );
737
+ }
738
+
739
+ void QgsBrowserDockWidget::fetchFinished ( const QModelIndex & index )
740
+ {
741
+ Q_UNUSED ( index );
742
+ QgsDebugMsg ( " Entered" );
743
+ QSettings settings;
744
+
745
+ // Continue expanding mInitPath if user has not expanded another item
746
+ if ( mInitPath .isEmpty () )
747
+ return ;
748
+
749
+ QString lastExpanded = settings.value ( lastExpandedKey () ).toString ();
750
+
751
+ if ( !mInitPath .startsWith ( lastExpanded ) )
752
+ {
753
+ // User expanded another -> stop mInitPath expansion
754
+ QgsDebugMsg ( " Stop init path expansion" );
755
+ mInitPath .clear ();
756
+ return ;
757
+ }
758
+
759
+ // Expand fetched children in init path
760
+ QModelIndex proxyIndex = mProxyModel ->mapFromSource ( index );
761
+ if ( index.isValid () )
762
+ {
763
+ mBrowserView ->expand ( proxyIndex );
764
+ }
765
+
766
+ expandPath ( mInitPath );
767
+ }
768
+
769
+ QString QgsBrowserDockWidget::lastExpandedKey () const
770
+ {
771
+ return " /" + objectName ().toLower () + " /lastExpanded" ;
725
772
}
0 commit comments