@@ -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+
227241QIcon 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 {
0 commit comments