Skip to content
Permalink
Browse files
Add refresh button to browser dock (#4272)
  • Loading branch information
wonder-sk committed Oct 11, 2011
1 parent ac2b7da commit de9fb2ce018fa08ccd70064824ac98e896debdf8
Showing with 57 additions and 1 deletion.
  1. +51 −1 src/app/qgsbrowserdockwidget.cpp
  2. +6 −0 src/app/qgsbrowserdockwidget.h
@@ -4,13 +4,15 @@
#include <QTreeView>
#include <QMenu>
#include <QSettings>
#include <QToolButton>

#include "qgsbrowsermodel.h"
#include "qgsdataitem.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"
#include "qgisapp.h"

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

mBrowserView = new QgsBrowserTreeView( this );
setWidget( mBrowserView );

mRefreshButton = new QToolButton( this );
mRefreshButton->setIcon( QgisApp::instance()->getThemeIcon( "mActionDraw.png" ) );
mRefreshButton->setText( tr( "Refresh" ) );
mRefreshButton->setAutoRaise( true );
connect( mRefreshButton, SIGNAL( clicked() ), this, SLOT( refresh() ) );

QVBoxLayout* layout = new QVBoxLayout( this );
layout->setContentsMargins( 0, 0, 0, 0 );
layout->setSpacing( 0 );
layout->addWidget( mRefreshButton );
layout->addWidget( mBrowserView );

QWidget* innerWidget = new QWidget( this );
innerWidget->setLayout( layout );
setWidget( innerWidget );

connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
//connect( mBrowserView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) );
@@ -216,3 +233,36 @@ void QgsBrowserDockWidget::removeFavourite()
// reload the browser model so that the favourite directory is not shown anymore
mModel->reload();
}

void QgsBrowserDockWidget::refresh()
{
refreshModel( QModelIndex() );
}

void QgsBrowserDockWidget::refreshModel( const QModelIndex& index )
{
QgsDebugMsg( "Entered" );
if ( index.isValid() )
{
QgsDataItem *item = mModel->dataItem( index );
if ( item )
{
QgsDebugMsg( "path = " + item->path() );
}
else
{
QgsDebugMsg( "invalid item" );
}
}

mModel->refresh( index );

for ( int i = 0 ; i < mModel->rowCount( index ); i++ )
{
QModelIndex idx = mModel->index( i, 0, index );
if ( mBrowserView->isExpanded( idx ) )
{
refreshModel( idx );
}
}
}
@@ -6,6 +6,7 @@
class QgsBrowserModel;
class QModelIndex;
class QTreeView;
class QToolButton;

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

void refresh();

protected:

void refreshModel( const QModelIndex& index );

void showEvent( QShowEvent * event );

QTreeView* mBrowserView;
QToolButton* mRefreshButton;
QgsBrowserModel* mModel;
};

0 comments on commit de9fb2c

Please sign in to comment.