|
4 | 4 | #include <QTreeView>
|
5 | 5 | #include <QMenu>
|
6 | 6 | #include <QSettings>
|
| 7 | +#include <QToolButton> |
7 | 8 |
|
8 | 9 | #include "qgsbrowsermodel.h"
|
9 | 10 | #include "qgsdataitem.h"
|
10 | 11 | #include "qgslogger.h"
|
11 | 12 | #include "qgsmaplayerregistry.h"
|
12 | 13 | #include "qgsrasterlayer.h"
|
13 | 14 | #include "qgsvectorlayer.h"
|
| 15 | +#include "qgisapp.h" |
14 | 16 |
|
15 | 17 | #include <QDragEnterEvent>
|
16 | 18 | /**
|
@@ -52,7 +54,22 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
|
52 | 54 | setWindowTitle( tr( "Browser" ) );
|
53 | 55 |
|
54 | 56 | 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 ); |
56 | 73 |
|
57 | 74 | connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
|
58 | 75 | //connect( mBrowserView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) );
|
@@ -216,3 +233,36 @@ void QgsBrowserDockWidget::removeFavourite()
|
216 | 233 | // reload the browser model so that the favourite directory is not shown anymore
|
217 | 234 | mModel->reload();
|
218 | 235 | }
|
| 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 | +} |
0 commit comments