<commit_before>#include "timezonecontainer.h"
#include "timezonelistitem.h"
#include "dcptimezoneconf.h"
#include "dcptimezonedata.h"
#include "dcpspaceritem.h"

#include <duilayout.h>
#include <duigridlayoutpolicy.h>
#include <qtimer.h>
#include <duiscenemanager.h>

TimeZoneContainer::TimeZoneContainer(DuiWidget *parent)
                  :DuiWidget(parent)
{
    initWidget();
}

TimeZoneContainer::~TimeZoneContainer()
{
    m_ItemMap.clear();
}

QMap<int, TimeZoneListItem*> TimeZoneContainer::getMap()
{
    return m_ItemMap;
}

void TimeZoneContainer::updateLayout()
{
    for (int i = m_MainLayout->count() - 1; i >= 0; i--) {
        static_cast<TimeZoneListItem*>(m_MainLayout->itemAt(i))->setVisible(false);
        m_MainLayout->removeAt(i);
    }
    delete m_MainLayoutPolicy;
    m_MainLayoutPolicy = new DuiGridLayoutPolicy(m_MainLayout);
    m_MainLayout->setPolicy(m_MainLayoutPolicy);
    m_MainLayoutPolicy->setSpacing(10);

    // add Items to m_MainLayoutPolicy
    int count = 0;
    QMapIterator<int, TimeZoneListItem*> iter(m_ItemMap);
    while (iter.hasNext()) {
        iter.next();
        if (iter.value()->isFiltered()) {
            m_MainLayoutPolicy->addItemAtPosition(iter.value(), count / 2, count % 2);
            iter.value()->setVisible(true);
            count++;
        }
    }

    if (m_MainLayout->count() == 1) {
        m_MainLayoutPolicy->addItemAtPosition(
                new DcpSpacerItem(this, 
                    DuiSceneManager::instance()->visibleSceneRect().width() / 2 - 35, 
                    10, QSizePolicy::Fixed, QSizePolicy::Expanding),
                0, 1);
    } else if (m_MainLayout->count() == 0) {
        m_MainLayoutPolicy->addItemAtPosition(
                new DcpSpacerItem(this, 
                    DuiSceneManager::instance()->visibleSceneRect().width() / 2 - 35, 
                    10, QSizePolicy::Fixed, QSizePolicy::Expanding),
                0, 0);
        m_MainLayoutPolicy->addItemAtPosition(
                new DcpSpacerItem(this, 
                    DuiSceneManager::instance()->visibleSceneRect().width() / 2 - 35, 
                    10, QSizePolicy::Fixed, QSizePolicy::Expanding),
                0, 1);
    }
}

void TimeZoneContainer::initWidget()
{
    // m_MainLayout
    m_MainLayout = new DuiLayout(this);
    m_MainLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0);
    this->setLayout(m_MainLayout);
    m_MainLayoutPolicy = new DuiGridLayoutPolicy(m_MainLayout);
    m_MainLayoutPolicy->setSpacing(10);
    m_MainLayout->setPolicy(m_MainLayoutPolicy);

    // add items to m_ItemMap<commit_msg>Changed: after filtering hide the last items' separator in timezonedialog. (DateTimeApplet)<commit_after>#include "timezonecontainer.h"
#include "timezonelistitem.h"
#include "dcptimezoneconf.h"
#include "dcptimezonedata.h"
#include "dcpspaceritem.h"

#include <duilayout.h>
#include <duigridlayoutpolicy.h>
#include <qtimer.h>
#include <duiscenemanager.h>

TimeZoneContainer::TimeZoneContainer(DuiWidget *parent)
                  :DuiWidget(parent)
{
    initWidget();
}

TimeZoneContainer::~TimeZoneContainer()
{
    m_ItemMap.clear();
}

QMap<int, TimeZoneListItem*> TimeZoneContainer::getMap()
{
    return m_ItemMap;
}

void TimeZoneContainer::updateLayout()
{
    for (int i = m_MainLayout->count() - 1; i >= 0; i--) {
        static_cast<TimeZoneListItem*>(m_MainLayout->itemAt(i))->setVisible(false);
        m_MainLayout->removeAt(i);
    }
    delete m_MainLayoutPolicy;
    m_MainLayoutPolicy = new DuiGridLayoutPolicy(m_MainLayout);
    m_MainLayout->setPolicy(m_MainLayoutPolicy);
    m_MainLayoutPolicy->setSpacing(10);

    // add Items to m_MainLayoutPolicy
    int count = 0;
    QMapIterator<int, TimeZoneListItem*> iter(m_ItemMap);
    while (iter.hasNext()) {
        iter.next();
        iter.value()->setVisibleSeparator(true);
        if (iter.value()->isFiltered()) {
            m_MainLayoutPolicy->addItemAtPosition(iter.value(), count / 2, count % 2);
            iter.value()->setVisible(true);
            count++;
        }
    }

    if (m_MainLayout->count() == 0) {
        m_MainLayoutPolicy->addItemAtPosition(
                new DcpSpacerItem(this, 
                    DuiSceneManager::instance()->visibleSceneRect().width() / 2 - 35, 
                    10, QSizePolicy::Fixed, QSizePolicy::Expanding),
                0, 0);
        m_MainLayoutPolicy->addItemAtPosition(
                new DcpSpacerItem(this, 
                    DuiSceneManager::instance()->visibleSceneRect().width() / 2 - 35, 
                    10, QSizePolicy::Fixed, QSizePolicy::Expanding),
                0, 1);
    } else {
        int count = m_MainLayout->count();
        if (count % 2 == 0) {
            static_cast<TimeZoneListItem*>(m_MainLayout->itemAt(count - 1))->setVisibleSeparator(false);
            static_cast<TimeZoneListItem*>(m_MainLayout->itemAt(count - 2))->setVisibleSeparator(false);
        } else {
            static_cast<TimeZoneListItem*>(m_MainLayout->itemAt(count - 1))->setVisibleSeparator(false);
        }
    }

    if (m_MainLayout->count() == 1) {
        m_MainLayoutPolicy->addItemAtPosition(
                new DcpSpacerItem(this, 
                    DuiSceneManager::instance()->visibleSceneRect().width() / 2 - 35, 
                    10, QSizePolicy::Fixed, QSizePolicy::Expanding),
                0, 1);
    } 
}

void TimeZoneContainer::initWidget()
{
    // m_MainLayout
    m_MainLayout = new DuiLayout(this);
    m_MainLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0);
    this->setLayout(m_MainLayout);
    m_MainLayoutPolicy = new DuiGridLayoutPolicy(m_MainLayout);
    m_MainLayoutPolicy->setSpacing(10);
    m_MainLayout->setPolicy(m_MainLayoutPolicy);

    // add items to m_ItemMap
{'fraction_non_alphanumeric': 0.13103089205137106, 'fraction_numerical': 0.01475182228392919, 'mean_word_length': 2.87038280725319, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 72, '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': '3099179', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1803, 'n_words': 284}