Skip to content

Commit

Permalink
browser items moveToThread() also children
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Dec 16, 2014
1 parent 8076e53 commit d0ea44a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
30 changes: 15 additions & 15 deletions src/core/qgsdataitem.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
{
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsdataitem.h
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down
9 changes: 6 additions & 3 deletions src/providers/postgres/qgspostgresdataitems.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -248,7 +250,8 @@ void QgsPGLayerItem::deleteLayer()
else
{
QMessageBox::information( 0, tr( "Delete layer" ), tr( "Layer deleted successfully." ) );
mParent->refresh();
if ( mParent )
mParent->refresh();
}
}

Expand Down

0 comments on commit d0ea44a

Please sign in to comment.