Skip to content
Permalink
Browse files
browser items moveToThread() also children
  • Loading branch information
blazek committed Dec 16, 2014
1 parent 8076e53 commit d0ea44aef3d8a9946e40bdc6cf5099a8f8e2f718
Showing with 26 additions and 19 deletions.
  1. +15 −15 src/core/qgsdataitem.cpp
  2. +5 −1 src/core/qgsdataitem.h
  3. +6 −3 src/providers/postgres/qgspostgresdataitems.cpp
@@ -224,6 +224,20 @@ void QgsDataItem::deleteLater( QVector<QgsDataItem*> &items )
items.clear();
}

void QgsDataItem::moveToThread( QThread * targetThread )
{
// QObject::moveToThread() cannot move objects with parent, but QgsDataItem is not using paren/children from QObject
foreach ( QgsDataItem* child, mChildren )
{
if ( !child ) // should not happen
continue;
QgsDebugMsg( "moveToThread child " + child->path() );
child->QObject::setParent( 0 ); // to be sure
child->moveToThread( targetThread );
}
QObject::moveToThread( targetThread );
}

QIcon QgsDataItem::icon()
{
if ( state() == Populating )
@@ -315,11 +329,8 @@ QVector<QgsDataItem*> QgsDataItem::runCreateChildren( QgsDataItem* item )
{
if ( !child ) // should not happen
continue;
// The object cannot be moved if it has a parent.
QgsDebugMsg( "moveToThread child " + child->path() );
child->setParent( 0 );
child->moveToThread( QApplication::instance()->thread() ); // moves also children
child->setParent( item );
}
QgsDebugMsg( "finished path = " + item->path() );
return children;
@@ -455,18 +466,7 @@ void QgsDataItem::setParent( QgsDataItem* parent )
{
if ( mParent )
{
disconnect( this, SIGNAL( beginInsertItems( QgsDataItem*, int, int ) ),
mParent, SLOT( emitBeginInsertItems( QgsDataItem*, int, int ) ) );
disconnect( this, SIGNAL( endInsertItems() ),
mParent, SLOT( emitEndInsertItems() ) );
disconnect( this, SIGNAL( beginRemoveItems( QgsDataItem*, int, int ) ),
mParent, SLOT( emitBeginRemoveItems( QgsDataItem*, int, int ) ) );
disconnect( this, SIGNAL( endRemoveItems() ),
mParent, SLOT( emitEndRemoveItems() ) );
disconnect( this, SIGNAL( dataChanged( QgsDataItem* ) ),
mParent, SLOT( emitDataChanged( QgsDataItem* ) ) );
disconnect( this, SIGNAL( stateChanged( QgsDataItem*, QgsDataItem::State ) ),
mParent, SLOT( emitStateChanged( QgsDataItem*, QgsDataItem::State ) ) );
disconnect( this, 0, mParent, 0 );
}
if ( parent )
{
@@ -38,7 +38,8 @@ class QgsDataItem;
typedef QgsDataItem * dataItem_t( QString, QgsDataItem* );


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

/** Move object and all its descendants to thread */
void moveToThread( QThread * targetThread );

protected:
virtual void populate( QVector<QgsDataItem*> children );
virtual void refresh( QVector<QgsDataItem*> children );
@@ -121,15 +121,17 @@ void QgsPGConnectionItem::editConnection()
if ( nc.exec() )
{
// the parent should be updated
mParent->refresh();
if ( mParent )
mParent->refresh();
}
}

void QgsPGConnectionItem::deleteConnection()
{
QgsPostgresConn::deleteConnection( mName );
// the parent should be updated
mParent->refresh();
if ( mParent )
mParent->refresh();
}

void QgsPGConnectionItem::refreshConnection()
@@ -248,7 +250,8 @@ void QgsPGLayerItem::deleteLayer()
else
{
QMessageBox::information( 0, tr( "Delete layer" ), tr( "Layer deleted successfully." ) );
mParent->refresh();
if ( mParent )
mParent->refresh();
}
}

0 comments on commit d0ea44a

Please sign in to comment.