<commit_before>/***************************************************************************
**
** Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include <MTheme>

#include "mcontainer.h"
#include "mcontainer_p.h"

#include "mwidgetcreator.h"
M_REGISTER_WIDGET(MContainer)


MContainerPrivate::MContainerPrivate()
{
}

MContainerPrivate::~MContainerPrivate()
{
}

void MContainerPrivate::_q_onCentralWidgetDestroyed()
{
    Q_Q(MContainer);
    q->model()->setCentralWidget(0);
}

void MContainerPrivate::init(const QString &newTitle)
{
    Q_Q(MContainer);

    q->model()->setCentralWidget(new MWidget(q));

    q->setTitle(newTitle);

    q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}

MContainer::MContainer(QGraphicsItem *parent)
    : MWidgetController(new MContainerPrivate(), new MContainerModel(), parent)
{
    Q_D(MContainer);

    d->init();
}

MContainer::MContainer(const QString &title, QGraphicsItem *parent)
    : MWidgetController(new MContainerPrivate(), new MContainerModel(), parent)
{
    Q_D(MContainer);

    d->init(title);
}

MContainer::~MContainer()
{
}

QGraphicsWidget *MContainer::centralWidget()
{
    return model()->centralWidget();
}

void MContainer::setCentralWidget(QGraphicsWidget *centralWidget, bool destroy)
{
    QGraphicsWidget *oldCentralWidget = model()->centralWidget();

    // Set the new central widget
    model()->setCentralWidget(centralWidget);

    // Destroy the old central widget if requested
    if (destroy) {
        delete oldCentralWidget;

        if (centralWidget)
            connect(centralWidget, SIGNAL(destroyed()), SLOT(_q_onCentralWidgetDestroyed()));
    } else {
        // pass the ownership back to the caller.
        oldCentralWidget->setParentItem(0);
        oldCentralWidget->setParent(0);
        if (scene())
            scene()->removeItem(oldCentralWidget);

        if (oldCentralWidget)
            disconnect(oldCentralWidget, SIGNAL(destroyed()), this, SLOT(_q_onCentralWidgetDestroyed()));
    }

}

QString MContainer::title() const
{
    return model()->title();
}

void MContainer::setTitle(const QString &newTitle)
{
    model()->setTitle(newTitle);
}

QString MContainer::text() const
{
    return model()->text();
}

void MContainer::setText(const QString &text)<commit_msg>Fixed NB#295469: <coverity> defects for libmeegotouch/0.24.16-2_0m7/src/corelib/widgets/mcontainer.cpp<commit_after>/***************************************************************************
**
** Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include <MTheme>

#include "mcontainer.h"
#include "mcontainer_p.h"

#include "mwidgetcreator.h"
M_REGISTER_WIDGET(MContainer)


MContainerPrivate::MContainerPrivate()
{
}

MContainerPrivate::~MContainerPrivate()
{
}

void MContainerPrivate::_q_onCentralWidgetDestroyed()
{
    Q_Q(MContainer);
    q->model()->setCentralWidget(0);
}

void MContainerPrivate::init(const QString &newTitle)
{
    Q_Q(MContainer);

    q->model()->setCentralWidget(new MWidget(q));

    q->setTitle(newTitle);

    q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}

MContainer::MContainer(QGraphicsItem *parent)
    : MWidgetController(new MContainerPrivate(), new MContainerModel(), parent)
{
    Q_D(MContainer);

    d->init();
}

MContainer::MContainer(const QString &title, QGraphicsItem *parent)
    : MWidgetController(new MContainerPrivate(), new MContainerModel(), parent)
{
    Q_D(MContainer);

    d->init(title);
}

MContainer::~MContainer()
{
}

QGraphicsWidget *MContainer::centralWidget()
{
    return model()->centralWidget();
}

void MContainer::setCentralWidget(QGraphicsWidget *centralWidget, bool destroy)
{
    QGraphicsWidget *oldCentralWidget = model()->centralWidget();

    // Set the new central widget
    model()->setCentralWidget(centralWidget);

    // Destroy the old central widget if requested
    if (destroy) {
        delete oldCentralWidget;

        if (centralWidget)
            connect(centralWidget, SIGNAL(destroyed()), SLOT(_q_onCentralWidgetDestroyed()));
    } else if (oldCentralWidget) {
        // pass the ownership back to the caller.
        oldCentralWidget->setParentItem(0);
        oldCentralWidget->setParent(0);
        if (scene())
            scene()->removeItem(oldCentralWidget);

        disconnect(oldCentralWidget, SIGNAL(destroyed()), this, SLOT(_q_onCentralWidgetDestroyed()));
    }

}

QString MContainer::title() const
{
    return model()->title();
}

void MContainer::setTitle(const QString &newTitle)
{
    model()->setTitle(newTitle);
}

QString MContainer::text() const
{
    return model()->text();
}

void MContainer::setText(const QString &text)
{'fraction_non_alphanumeric': 0.17393535146228836, 'fraction_numerical': 0.006841115101761587, 'mean_word_length': 4.818905472636816, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5917946', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1636, 'n_words': 406}