Skip to content

Commit d0ea44a

Browse files
committedDec 16, 2014
browser items moveToThread() also children
1 parent 8076e53 commit d0ea44a

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed
 

‎src/core/qgsdataitem.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,20 @@ void QgsDataItem::deleteLater( QVector<QgsDataItem*> &items )
224224
items.clear();
225225
}
226226

227+
void QgsDataItem::moveToThread( QThread * targetThread )
228+
{
229+
// QObject::moveToThread() cannot move objects with parent, but QgsDataItem is not using paren/children from QObject
230+
foreach ( QgsDataItem* child, mChildren )
231+
{
232+
if ( !child ) // should not happen
233+
continue;
234+
QgsDebugMsg( "moveToThread child " + child->path() );
235+
child->QObject::setParent( 0 ); // to be sure
236+
child->moveToThread( targetThread );
237+
}
238+
QObject::moveToThread( targetThread );
239+
}
240+
227241
QIcon QgsDataItem::icon()
228242
{
229243
if ( state() == Populating )
@@ -315,11 +329,8 @@ QVector<QgsDataItem*> QgsDataItem::runCreateChildren( QgsDataItem* item )
315329
{
316330
if ( !child ) // should not happen
317331
continue;
318-
// The object cannot be moved if it has a parent.
319332
QgsDebugMsg( "moveToThread child " + child->path() );
320-
child->setParent( 0 );
321333
child->moveToThread( QApplication::instance()->thread() ); // moves also children
322-
child->setParent( item );
323334
}
324335
QgsDebugMsg( "finished path = " + item->path() );
325336
return children;
@@ -455,18 +466,7 @@ void QgsDataItem::setParent( QgsDataItem* parent )
455466
{
456467
if ( mParent )
457468
{
458-
disconnect( this, SIGNAL( beginInsertItems( QgsDataItem*, int, int ) ),
459-
mParent, SLOT( emitBeginInsertItems( QgsDataItem*, int, int ) ) );
460-
disconnect( this, SIGNAL( endInsertItems() ),
461-
mParent, SLOT( emitEndInsertItems() ) );
462-
disconnect( this, SIGNAL( beginRemoveItems( QgsDataItem*, int, int ) ),
463-
mParent, SLOT( emitBeginRemoveItems( QgsDataItem*, int, int ) ) );
464-
disconnect( this, SIGNAL( endRemoveItems() ),
465-
mParent, SLOT( emitEndRemoveItems() ) );
466-
disconnect( this, SIGNAL( dataChanged( QgsDataItem* ) ),
467-
mParent, SLOT( emitDataChanged( QgsDataItem* ) ) );
468-
disconnect( this, SIGNAL( stateChanged( QgsDataItem*, QgsDataItem::State ) ),
469-
mParent, SLOT( emitStateChanged( QgsDataItem*, QgsDataItem::State ) ) );
469+
disconnect( this, 0, mParent, 0 );
470470
}
471471
if ( parent )
472472
{

‎src/core/qgsdataitem.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class QgsDataItem;
3838
typedef QgsDataItem * dataItem_t( QString, QgsDataItem* );
3939

4040

41-
/** base class for all items in the model */
41+
/** Base class for all items in the model.
42+
* Parent/children hierarchy is not based on QObject. */
4243
class CORE_EXPORT QgsDataItem : public QObject
4344
{
4445
Q_OBJECT
@@ -158,6 +159,9 @@ class CORE_EXPORT QgsDataItem : public QObject
158159
// deleteLater() items anc clear the vector
159160
static void deleteLater( QVector<QgsDataItem*> &items );
160161

162+
/** Move object and all its descendants to thread */
163+
void moveToThread( QThread * targetThread );
164+
161165
protected:
162166
virtual void populate( QVector<QgsDataItem*> children );
163167
virtual void refresh( QVector<QgsDataItem*> children );

‎src/providers/postgres/qgspostgresdataitems.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,17 @@ void QgsPGConnectionItem::editConnection()
121121
if ( nc.exec() )
122122
{
123123
// the parent should be updated
124-
mParent->refresh();
124+
if ( mParent )
125+
mParent->refresh();
125126
}
126127
}
127128

128129
void QgsPGConnectionItem::deleteConnection()
129130
{
130131
QgsPostgresConn::deleteConnection( mName );
131132
// the parent should be updated
132-
mParent->refresh();
133+
if ( mParent )
134+
mParent->refresh();
133135
}
134136

135137
void QgsPGConnectionItem::refreshConnection()
@@ -248,7 +250,8 @@ void QgsPGLayerItem::deleteLayer()
248250
else
249251
{
250252
QMessageBox::information( 0, tr( "Delete layer" ), tr( "Layer deleted successfully." ) );
251-
mParent->refresh();
253+
if ( mParent )
254+
mParent->refresh();
252255
}
253256
}
254257

0 commit comments

Comments
 (0)
Please sign in to comment.