<commit_before>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of libdui.
**
** 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 <QVector>
#include <QGraphicsSceneEvent>
#include <QGraphicsGridLayout>
#include <QItemSelectionModel>

#include <DuiDebug>
#include "duilist.h"
#include "duitheme.h"
#include "duibutton.h"
#include "duilist_p.h"
#include "duilabel.h"
#include "duipannableviewport.h"

#include "duiwidgetcreator.h"
DUI_REGISTER_WIDGET(DuiList)

DuiListPrivate::DuiListPrivate()
{
}

DuiListPrivate::~DuiListPrivate()
{
}

void DuiListPrivate::init()
{
    Q_Q(DuiList);

    q->setSelectionMode(DuiList::NoSelection);
    q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); //grow to available space in both directions
}

DuiList::DuiList(DuiListPrivate *dd, DuiListModel *model, QGraphicsItem *parent)
    : DuiWidgetController(dd, model, parent)
{
    Q_D(DuiList);
    d->init();
}

DuiList::DuiList(QGraphicsItem *parent)
    : DuiWidgetController(new DuiListPrivate, new DuiListModel, parent)

{
    Q_D(DuiList);
    d->init();
}

DuiList::~DuiList()
{
}

void DuiList::updateData(const QList<const char *>& modifications)
{
    const char *member;
    for (int i = 0; i < modifications.count(); i++) {
        member = modifications[i];
        if (member == DuiListModel::ListIsMoving) {
            model()->listIsMoving() ? emit panningStarted() : emit panningStopped();
        }
    }
}

void DuiList::setItemModel(QAbstractItemModel *itemModel)
{
    setSelectionModel(NULL);

    if (itemModel)
        setSelectionModel(new QItemSelectionModel(itemModel));

    model()->setItemModel(itemModel);
}


QAbstractItemModel *DuiList::itemModel() const
{
    return model()->itemModel();
}

void DuiList::scrollTo(const QModelIndex &index)
{
    emit scrollToIndex(index);
    scrollTo(index, DuiList::EnsureVisibleHint);
}

void DuiList::scrollTo(const QModelIndex &index, ScrollHint hint)
{
    emit scrollToIndex(index);

    model()->beginTransaction();
    model()->setScrollHint(hint);
    model()->setScrollToIndex(index);
    model()->commitTransaction();
}

QItemSelectionModel *DuiList::selectionModel() const
{
    return model()->selectionModel();
}

void DuiList::setSelectionModel(QItemSelectionModel *selectionModel)
{
    if (selectionModel == this->selectionModel()) {
        return;
    }

    model()->setSelectionModel(selectionModel);
    emit selectionModelChanged(selectionModel);<commit_msg>Fixed: bug #156962 DuiList scrollToIndex signal emitted twice<commit_after>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of libdui.
**
** 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 <QVector>
#include <QGraphicsSceneEvent>
#include <QGraphicsGridLayout>
#include <QItemSelectionModel>

#include <DuiDebug>
#include "duilist.h"
#include "duitheme.h"
#include "duibutton.h"
#include "duilist_p.h"
#include "duilabel.h"
#include "duipannableviewport.h"

#include "duiwidgetcreator.h"
DUI_REGISTER_WIDGET(DuiList)

DuiListPrivate::DuiListPrivate()
{
}

DuiListPrivate::~DuiListPrivate()
{
}

void DuiListPrivate::init()
{
    Q_Q(DuiList);

    q->setSelectionMode(DuiList::NoSelection);
    q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); //grow to available space in both directions
}

DuiList::DuiList(DuiListPrivate *dd, DuiListModel *model, QGraphicsItem *parent)
    : DuiWidgetController(dd, model, parent)
{
    Q_D(DuiList);
    d->init();
}

DuiList::DuiList(QGraphicsItem *parent)
    : DuiWidgetController(new DuiListPrivate, new DuiListModel, parent)

{
    Q_D(DuiList);
    d->init();
}

DuiList::~DuiList()
{
}

void DuiList::updateData(const QList<const char *>& modifications)
{
    const char *member;
    for (int i = 0; i < modifications.count(); i++) {
        member = modifications[i];
        if (member == DuiListModel::ListIsMoving) {
            model()->listIsMoving() ? emit panningStarted() : emit panningStopped();
        }
    }
}

void DuiList::setItemModel(QAbstractItemModel *itemModel)
{
    setSelectionModel(NULL);

    if (itemModel)
        setSelectionModel(new QItemSelectionModel(itemModel));

    model()->setItemModel(itemModel);
}


QAbstractItemModel *DuiList::itemModel() const
{
    return model()->itemModel();
}

void DuiList::scrollTo(const QModelIndex &index)
{
    scrollTo(index, DuiList::EnsureVisibleHint);
}

void DuiList::scrollTo(const QModelIndex &index, ScrollHint hint)
{
    emit scrollToIndex(index);

    model()->beginTransaction();
    model()->setScrollHint(hint);
    model()->setScrollToIndex(index);
    model()->commitTransaction();
}

QItemSelectionModel *DuiList::selectionModel() const
{
    return model()->selectionModel();
}

void DuiList::setSelectionModel(QItemSelectionModel *selectionModel)
{
    if (selectionModel == this->selectionModel()) {
        return;
    }

    model()->setSelectionModel(selectionModel);
    emit selectionModelChanged(selectionModel);
{'fraction_non_alphanumeric': 0.17335499593826156, 'fraction_numerical': 0.003249390739236393, 'mean_word_length': 5.193158953722334, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 47, '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': '83144', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1868, 'n_words': 436}