Skip to content

Commit de9fb2c

Browse files
committed
Add refresh button to browser dock (#4272)
1 parent ac2b7da commit de9fb2c

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/app/qgsbrowserdockwidget.cpp

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
#include <QTreeView>
55
#include <QMenu>
66
#include <QSettings>
7+
#include <QToolButton>
78

89
#include "qgsbrowsermodel.h"
910
#include "qgsdataitem.h"
1011
#include "qgslogger.h"
1112
#include "qgsmaplayerregistry.h"
1213
#include "qgsrasterlayer.h"
1314
#include "qgsvectorlayer.h"
15+
#include "qgisapp.h"
1416

1517
#include <QDragEnterEvent>
1618
/**
@@ -52,7 +54,22 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
5254
setWindowTitle( tr( "Browser" ) );
5355

5456
mBrowserView = new QgsBrowserTreeView( this );
55-
setWidget( mBrowserView );
57+
58+
mRefreshButton = new QToolButton( this );
59+
mRefreshButton->setIcon( QgisApp::instance()->getThemeIcon( "mActionDraw.png" ) );
60+
mRefreshButton->setText( tr( "Refresh" ) );
61+
mRefreshButton->setAutoRaise( true );
62+
connect( mRefreshButton, SIGNAL( clicked() ), this, SLOT( refresh() ) );
63+
64+
QVBoxLayout* layout = new QVBoxLayout( this );
65+
layout->setContentsMargins( 0, 0, 0, 0 );
66+
layout->setSpacing( 0 );
67+
layout->addWidget( mRefreshButton );
68+
layout->addWidget( mBrowserView );
69+
70+
QWidget* innerWidget = new QWidget( this );
71+
innerWidget->setLayout( layout );
72+
setWidget( innerWidget );
5673

5774
connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
5875
//connect( mBrowserView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) );
@@ -216,3 +233,36 @@ void QgsBrowserDockWidget::removeFavourite()
216233
// reload the browser model so that the favourite directory is not shown anymore
217234
mModel->reload();
218235
}
236+
237+
void QgsBrowserDockWidget::refresh()
238+
{
239+
refreshModel( QModelIndex() );
240+
}
241+
242+
void QgsBrowserDockWidget::refreshModel( const QModelIndex& index )
243+
{
244+
QgsDebugMsg( "Entered" );
245+
if ( index.isValid() )
246+
{
247+
QgsDataItem *item = mModel->dataItem( index );
248+
if ( item )
249+
{
250+
QgsDebugMsg( "path = " + item->path() );
251+
}
252+
else
253+
{
254+
QgsDebugMsg( "invalid item" );
255+
}
256+
}
257+
258+
mModel->refresh( index );
259+
260+
for ( int i = 0 ; i < mModel->rowCount( index ); i++ )
261+
{
262+
QModelIndex idx = mModel->index( i, 0, index );
263+
if ( mBrowserView->isExpanded( idx ) )
264+
{
265+
refreshModel( idx );
266+
}
267+
}
268+
}

src/app/qgsbrowserdockwidget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class QgsBrowserModel;
77
class QModelIndex;
88
class QTreeView;
9+
class QToolButton;
910

1011
class QgsBrowserDockWidget : public QDockWidget
1112
{
@@ -22,11 +23,16 @@ class QgsBrowserDockWidget : public QDockWidget
2223
void addFavourite();
2324
void removeFavourite();
2425

26+
void refresh();
27+
2528
protected:
2629

30+
void refreshModel( const QModelIndex& index );
31+
2732
void showEvent( QShowEvent * event );
2833

2934
QTreeView* mBrowserView;
35+
QToolButton* mRefreshButton;
3036
QgsBrowserModel* mModel;
3137
};
3238

0 commit comments

Comments
 (0)