Skip to content

Commit ec005b2

Browse files
etienneskytimlinux
authored andcommitted
browser and dataitems - show wait cursor when loading
Signed-off-by: Tim Sutton <tim@linfiniti.com>
1 parent 58ebe86 commit ec005b2

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

src/app/qgsbrowserdockwidget.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
104104
setWidget( innerWidget );
105105

106106
connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
107-
//connect( mBrowserView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) );
108-
connect( mBrowserView, SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) );
107+
connect( mBrowserView, SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( addLayerAtIndex( const QModelIndex& ) ) );
109108

110109
}
111110

@@ -126,19 +125,6 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
126125
QDockWidget::showEvent( e );
127126
}
128127

129-
130-
void QgsBrowserDockWidget::itemClicked( const QModelIndex& index )
131-
{
132-
QgsDataItem *dataItem = mModel->dataItem( index );
133-
134-
if ( dataItem != NULL && dataItem->type() == QgsDataItem::Layer )
135-
{
136-
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( dataItem );
137-
if ( layerItem != NULL )
138-
addLayer( layerItem );
139-
}
140-
}
141-
142128
void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
143129
{
144130
QModelIndex idx = mBrowserView->indexAt( pt );
@@ -168,7 +154,7 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
168154

169155
else if ( item->type() == QgsDataItem::Layer )
170156
{
171-
menu->addAction( tr( "Add Layer" ), this, SLOT( itemClicked( idx ) ) );
157+
menu->addAction( tr( "Add Layer" ), this, SLOT( addCurrentLayer( ) ) );
172158
menu->addAction( tr( "Add Selected Layers" ), this, SLOT( addSelectedLayers() ) );
173159
}
174160

@@ -312,6 +298,27 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
312298
}
313299
}
314300

301+
void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex& index )
302+
{
303+
QgsDataItem *dataItem = mModel->dataItem( index );
304+
305+
if ( dataItem != NULL && dataItem->type() == QgsDataItem::Layer )
306+
{
307+
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( dataItem );
308+
if ( layerItem != NULL )
309+
{
310+
QApplication::setOverrideCursor( Qt::WaitCursor );
311+
addLayer( layerItem );
312+
QApplication::restoreOverrideCursor();
313+
}
314+
}
315+
}
316+
317+
void QgsBrowserDockWidget::addCurrentLayer( )
318+
{
319+
addLayerAtIndex( mBrowserView->currentIndex() );
320+
}
321+
315322
void QgsBrowserDockWidget::addSelectedLayers()
316323
{
317324
QApplication::setOverrideCursor( Qt::WaitCursor );

src/app/qgsbrowserdockwidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ class QgsBrowserDockWidget : public QDockWidget
1717
signals:
1818

1919
public slots:
20-
void itemClicked( const QModelIndex& index );
20+
void addLayerAtIndex( const QModelIndex& index );
2121
void showContextMenu( const QPoint & );
2222

2323
void addFavourite();
2424
void removeFavourite();
2525

2626
void refresh();
2727

28+
void addCurrentLayer();
2829
void addSelectedLayers();
2930

3031
protected:

src/core/qgsdataitem.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,22 @@ QVector<QgsDataItem*> QgsDataItem::createChildren( )
172172

173173
void QgsDataItem::populate()
174174
{
175+
if ( mPopulated )
176+
return;
177+
178+
QgsDebugMsg( "mPath = " + mPath );
179+
180+
QApplication::setOverrideCursor( Qt::WaitCursor );
181+
175182
QVector<QgsDataItem*> children = createChildren( );
176183
foreach( QgsDataItem *child, children )
177184
{
178185
// initialization, do not refresh! That would result in infinite loop (beginInsertItems->rowCount->populate)
179186
addChildItem( child );
180187
}
181188
mPopulated = true;
189+
190+
QApplication::restoreOverrideCursor();
182191
}
183192

184193
int QgsDataItem::rowCount()
@@ -246,6 +255,8 @@ void QgsDataItem::refresh()
246255
{
247256
QgsDebugMsg( "mPath = " + mPath );
248257

258+
QApplication::setOverrideCursor( Qt::WaitCursor );
259+
249260
QVector<QgsDataItem*> items = createChildren( );
250261

251262
// Remove no more present items
@@ -272,6 +283,8 @@ void QgsDataItem::refresh()
272283
}
273284
addChildItem( item, true );
274285
}
286+
287+
QApplication::restoreOverrideCursor();
275288
}
276289

277290
bool QgsDataItem::equal( const QgsDataItem *other )

0 commit comments

Comments
 (0)