void DisplayGroupRenderer::setDisplayGroup( DisplayGroupPtr displayGroup )
{
    QDeclarativeEngine& engine = renderContext_->getQmlEngine();

    // Update the scene with the new information
    engine.rootContext()->setContextProperty( "displaygroup",
                                              displayGroup.get( ));

    if( !displayGroupItem_ )
        createDisplayGroupQmlItem();

    if( hasBackgroundChanged( *displayGroup ))
    {
        setBackground( displayGroup->getBackgroundContent( ));
        adjustBackgroundTo( *displayGroup );
    }

    ContentWindowPtrs contentWindows = displayGroup->getContentWindows();

    // Update windows, creating new ones if needed
    QSet<QUuid> updatedWindows;
    int stackingOrder = BACKGROUND_STACKING_ORDER + 1;
    BOOST_FOREACH( ContentWindowPtr window, contentWindows )
    {
        const QUuid& id = window->getID();

        updatedWindows.insert( id );

        if( windowItems_.contains( id ))
            windowItems_[id]->update( window );
        else
            createWindowQmlItem( window );

        windowItems_[id]->setStackingOrder( stackingOrder++ );
    }

    // Remove old windows
    QmlWindows::iterator it = windowItems_.begin();
    while( it != windowItems_.end( ))
    {
        if( updatedWindows.contains( it.key( )))
            ++it;
        else
        {
            emit windowRemoved( *it );
            it = windowItems_.erase( it );
        }
    }

    // Retain the new DisplayGroup
    displayGroup_ = displayGroup;
}
                      filename.toStdString().c_str(), e.what( ));
            return false;
        }
        catch( const std::exception& e )
        {
            put_flog( LOG_ERROR, "Could not restore state file '%s'',"
                                 "wrong file format: %s",
                      filename.toStdString().c_str(), e.what( ));
            return false;
        }

        ifs.close();
    }

    DisplayGroupPtr newDisplayGroup = state.getDisplayGroup();
    ContentWindowPtrs contentWindows = newDisplayGroup->getContentWindows();
    if( state.getVersion() < FIRST_PIXEL_COORDINATES_FILE_VERSION )
        scaleToDisplayGroup( contentWindows );
    validate( contentWindows );

    displayGroup_->setShowWindowTitles( newDisplayGroup->getShowWindowTitles( ));
    displayGroup_->setContentWindows( contentWindows );
    return true;
}

void StateSerializationHelper::scaleToDisplayGroup( ContentWindowPtrs&
                                                    contentWindows ) const
{
    const QRectF& group = displayGroup_->getCoordinates();

    BOOST_FOREACH( ContentWindowPtr window, contentWindows )