From ec005b29ce74508f06aef276554417353c61bf16 Mon Sep 17 00:00:00 2001 From: Etienne Tourigny Date: Sat, 24 Mar 2012 01:00:44 -0300 Subject: [PATCH] browser and dataitems - show wait cursor when loading Signed-off-by: Tim Sutton --- src/app/qgsbrowserdockwidget.cpp | 39 +++++++++++++++++++------------- src/app/qgsbrowserdockwidget.h | 3 ++- src/core/qgsdataitem.cpp | 13 +++++++++++ 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/app/qgsbrowserdockwidget.cpp b/src/app/qgsbrowserdockwidget.cpp index 15815df6a59..c853f79869c 100644 --- a/src/app/qgsbrowserdockwidget.cpp +++ b/src/app/qgsbrowserdockwidget.cpp @@ -104,8 +104,7 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) : setWidget( innerWidget ); connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) ); - //connect( mBrowserView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) ); - connect( mBrowserView, SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) ); + connect( mBrowserView, SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( addLayerAtIndex( const QModelIndex& ) ) ); } @@ -126,19 +125,6 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e ) QDockWidget::showEvent( e ); } - -void QgsBrowserDockWidget::itemClicked( const QModelIndex& index ) -{ - QgsDataItem *dataItem = mModel->dataItem( index ); - - if ( dataItem != NULL && dataItem->type() == QgsDataItem::Layer ) - { - QgsLayerItem *layerItem = qobject_cast( dataItem ); - if ( layerItem != NULL ) - addLayer( layerItem ); - } -} - void QgsBrowserDockWidget::showContextMenu( const QPoint & pt ) { QModelIndex idx = mBrowserView->indexAt( pt ); @@ -168,7 +154,7 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt ) else if ( item->type() == QgsDataItem::Layer ) { - menu->addAction( tr( "Add Layer" ), this, SLOT( itemClicked( idx ) ) ); + menu->addAction( tr( "Add Layer" ), this, SLOT( addCurrentLayer( ) ) ); menu->addAction( tr( "Add Selected Layers" ), this, SLOT( addSelectedLayers() ) ); } @@ -312,6 +298,27 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem ) } } +void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex& index ) +{ + QgsDataItem *dataItem = mModel->dataItem( index ); + + if ( dataItem != NULL && dataItem->type() == QgsDataItem::Layer ) + { + QgsLayerItem *layerItem = qobject_cast( dataItem ); + if ( layerItem != NULL ) + { + QApplication::setOverrideCursor( Qt::WaitCursor ); + addLayer( layerItem ); + QApplication::restoreOverrideCursor(); + } + } +} + +void QgsBrowserDockWidget::addCurrentLayer( ) +{ + addLayerAtIndex( mBrowserView->currentIndex() ); +} + void QgsBrowserDockWidget::addSelectedLayers() { QApplication::setOverrideCursor( Qt::WaitCursor ); diff --git a/src/app/qgsbrowserdockwidget.h b/src/app/qgsbrowserdockwidget.h index fcaf6d70b8b..0d9e6cfe936 100644 --- a/src/app/qgsbrowserdockwidget.h +++ b/src/app/qgsbrowserdockwidget.h @@ -17,7 +17,7 @@ class QgsBrowserDockWidget : public QDockWidget signals: public slots: - void itemClicked( const QModelIndex& index ); + void addLayerAtIndex( const QModelIndex& index ); void showContextMenu( const QPoint & ); void addFavourite(); @@ -25,6 +25,7 @@ class QgsBrowserDockWidget : public QDockWidget void refresh(); + void addCurrentLayer(); void addSelectedLayers(); protected: diff --git a/src/core/qgsdataitem.cpp b/src/core/qgsdataitem.cpp index 6cd9ed98567..91351925de2 100644 --- a/src/core/qgsdataitem.cpp +++ b/src/core/qgsdataitem.cpp @@ -172,6 +172,13 @@ QVector QgsDataItem::createChildren( ) void QgsDataItem::populate() { + if ( mPopulated ) + return; + + QgsDebugMsg( "mPath = " + mPath ); + + QApplication::setOverrideCursor( Qt::WaitCursor ); + QVector children = createChildren( ); foreach( QgsDataItem *child, children ) { @@ -179,6 +186,8 @@ void QgsDataItem::populate() addChildItem( child ); } mPopulated = true; + + QApplication::restoreOverrideCursor(); } int QgsDataItem::rowCount() @@ -246,6 +255,8 @@ void QgsDataItem::refresh() { QgsDebugMsg( "mPath = " + mPath ); + QApplication::setOverrideCursor( Qt::WaitCursor ); + QVector items = createChildren( ); // Remove no more present items @@ -272,6 +283,8 @@ void QgsDataItem::refresh() } addChildItem( item, true ); } + + QApplication::restoreOverrideCursor(); } bool QgsDataItem::equal( const QgsDataItem *other )