Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
browser and dataitems - show wait cursor when loading
Signed-off-by: Tim Sutton <tim@linfiniti.com>
  • Loading branch information
etiennesky authored and timlinux committed Mar 31, 2012
1 parent 58ebe86 commit ec005b2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
39 changes: 23 additions & 16 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -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& ) ) );

}

Expand All @@ -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<QgsLayerItem*>( dataItem );
if ( layerItem != NULL )
addLayer( layerItem );
}
}

void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
{
QModelIndex idx = mBrowserView->indexAt( pt );
Expand Down Expand Up @@ -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() ) );
}

Expand Down Expand Up @@ -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<QgsLayerItem*>( 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 );
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsbrowserdockwidget.h
Expand Up @@ -17,14 +17,15 @@ class QgsBrowserDockWidget : public QDockWidget
signals:

public slots:
void itemClicked( const QModelIndex& index );
void addLayerAtIndex( const QModelIndex& index );
void showContextMenu( const QPoint & );

void addFavourite();
void removeFavourite();

void refresh();

void addCurrentLayer();
void addSelectedLayers();

protected:
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsdataitem.cpp
Expand Up @@ -172,13 +172,22 @@ QVector<QgsDataItem*> QgsDataItem::createChildren( )

void QgsDataItem::populate()
{
if ( mPopulated )
return;

QgsDebugMsg( "mPath = " + mPath );

QApplication::setOverrideCursor( Qt::WaitCursor );

QVector<QgsDataItem*> children = createChildren( );
foreach( QgsDataItem *child, children )
{
// initialization, do not refresh! That would result in infinite loop (beginInsertItems->rowCount->populate)
addChildItem( child );
}
mPopulated = true;

QApplication::restoreOverrideCursor();
}

int QgsDataItem::rowCount()
Expand Down Expand Up @@ -246,6 +255,8 @@ void QgsDataItem::refresh()
{
QgsDebugMsg( "mPath = " + mPath );

QApplication::setOverrideCursor( Qt::WaitCursor );

QVector<QgsDataItem*> items = createChildren( );

// Remove no more present items
Expand All @@ -272,6 +283,8 @@ void QgsDataItem::refresh()
}
addChildItem( item, true );
}

QApplication::restoreOverrideCursor();
}

bool QgsDataItem::equal( const QgsDataItem *other )
Expand Down

0 comments on commit ec005b2

Please sign in to comment.