@@ -269,18 +269,9 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
269
269
{
270
270
mModel = new QgsBrowserModel ( mBrowserView );
271
271
272
- bool useFilter = true ;
273
- if ( useFilter ) // enable proxy model
274
- {
275
- // mBrowserView->setModel( mModel );
276
- mProxyModel = new QgsBrowserTreeFilterProxyModel ( this );
277
- mProxyModel ->setBrowserModel ( mModel );
278
- mBrowserView ->setModel ( mProxyModel );
279
- }
280
- else
281
- {
282
- mBrowserView ->setModel ( mModel );
283
- }
272
+ mProxyModel = new QgsBrowserTreeFilterProxyModel ( this );
273
+ mProxyModel ->setBrowserModel ( mModel );
274
+ mBrowserView ->setModel ( mProxyModel );
284
275
// provide a horizontal scroll bar instead of using ellipse (...) for longer items
285
276
mBrowserView ->setTextElideMode ( Qt::ElideNone );
286
277
mBrowserView ->header ()->setResizeMode ( 0 , QHeaderView::ResizeToContents );
@@ -301,8 +292,8 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
301
292
302
293
void QgsBrowserDockWidget::showContextMenu ( const QPoint & pt )
303
294
{
304
- QModelIndex idx = mBrowserView ->indexAt ( pt );
305
- QgsDataItem* item = dataItem ( idx );
295
+ QModelIndex index = mProxyModel -> mapToSource ( mBrowserView ->indexAt ( pt ) );
296
+ QgsDataItem* item = mModel -> dataItem ( index );
306
297
if ( !item )
307
298
return ;
308
299
@@ -358,7 +349,8 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
358
349
359
350
void QgsBrowserDockWidget::addFavourite ()
360
351
{
361
- QgsDataItem* item = dataItem ( mBrowserView ->currentIndex () );
352
+ QModelIndex index = mProxyModel ->mapToSource ( mBrowserView ->currentIndex () );
353
+ QgsDataItem* item = mModel ->dataItem ( index );
362
354
if ( !item )
363
355
return ;
364
356
@@ -390,7 +382,8 @@ void QgsBrowserDockWidget::addFavouriteDirectory( QString favDir )
390
382
391
383
void QgsBrowserDockWidget::removeFavourite ()
392
384
{
393
- QgsDataItem* item = dataItem ( mBrowserView ->currentIndex () );
385
+ QModelIndex index = mProxyModel ->mapToSource ( mBrowserView ->currentIndex () );
386
+ QgsDataItem* item = mModel ->dataItem ( index );
394
387
395
388
if ( !item )
396
389
return ;
@@ -420,7 +413,7 @@ void QgsBrowserDockWidget::refreshModel( const QModelIndex& index )
420
413
QgsDebugMsg ( " Entered" );
421
414
if ( index .isValid () )
422
415
{
423
- QgsDataItem *item = dataItem ( index );
416
+ QgsDataItem *item = mModel -> dataItem ( index );
424
417
if ( item )
425
418
{
426
419
QgsDebugMsg ( " path = " + item->path () );
@@ -436,7 +429,8 @@ void QgsBrowserDockWidget::refreshModel( const QModelIndex& index )
436
429
for ( int i = 0 ; i < mModel ->rowCount ( index ); i++ )
437
430
{
438
431
QModelIndex idx = mModel ->index ( i, 0 , index );
439
- if ( mBrowserView ->isExpanded ( idx ) || !mModel ->hasChildren ( idx ) )
432
+ QModelIndex proxyIdx = mProxyModel ->mapFromSource ( idx );
433
+ if ( mBrowserView ->isExpanded ( proxyIdx ) || !mModel ->hasChildren ( proxyIdx ) )
440
434
{
441
435
refreshModel ( idx );
442
436
}
@@ -468,7 +462,7 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
468
462
469
463
void QgsBrowserDockWidget::addLayerAtIndex ( const QModelIndex& index )
470
464
{
471
- QgsDataItem *item = dataItem ( index );
465
+ QgsDataItem *item = mModel -> dataItem ( mProxyModel -> mapToSource ( index ) );
472
466
473
467
if ( item != NULL && item->type () == QgsDataItem::Layer )
474
468
{
@@ -498,8 +492,7 @@ void QgsBrowserDockWidget::addSelectedLayers()
498
492
// add items in reverse order so they are in correct order in the layers dock
499
493
for ( int i = list.size () - 1 ; i >= 0 ; i-- )
500
494
{
501
- QModelIndex index = list[i];
502
- QgsDataItem *item = dataItem ( index );
495
+ QgsDataItem *item = mModel ->dataItem ( mProxyModel ->mapToSource ( list[i] ) );
503
496
if ( item && item->type () == QgsDataItem::Layer )
504
497
{
505
498
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( item );
@@ -513,9 +506,8 @@ void QgsBrowserDockWidget::addSelectedLayers()
513
506
514
507
void QgsBrowserDockWidget::showProperties ( )
515
508
{
516
- QgsDebugMsg ( " Entered" );
517
- QModelIndex index = mBrowserView ->currentIndex ();
518
- QgsDataItem* item = dataItem ( index );
509
+ QModelIndex index = mProxyModel ->mapToSource ( mBrowserView ->currentIndex () );
510
+ QgsDataItem* item = mModel ->dataItem ( index );
519
511
if ( ! item )
520
512
return ;
521
513
@@ -635,12 +627,3 @@ void QgsBrowserDockWidget::setFilterSyntax( QAction * action )
635
627
return ;
636
628
mProxyModel ->setFilterSyntax (( QRegExp::PatternSyntax ) action->data ().toInt () );
637
629
}
638
-
639
- QgsDataItem* QgsBrowserDockWidget::dataItem ( const QModelIndex& index )
640
- {
641
- if ( ! mProxyModel )
642
- return mModel ->dataItem ( index );
643
- else
644
- return mModel ->dataItem ( mProxyModel ->mapToSource ( index ) );
645
- }
646
-
0 commit comments