<commit_before>/***************************************************************************
**
** Copyright (C) 2010 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.
**
****************************************************************************/

#ifndef MLISTCELLCREATOR_H__
#define MLISTCELLCREATOR_H__

#include <QModelIndex>
#include <QSizeF>
#include <MWidgetRecycler>
#include <MWidget>

/*!
    \class MCellCreator
    \brief Interface for creating and updating items (cells) for MList.

    \section MCellCreator Overview
        MCellCreator is a purely abstract class and should be implemented by every class whose instances
        are intended to create items for MList.

        Main purpose of this interface is to create and update data of widgets which has to be inserted
        into MList. Also MCellCreator returns size of a list item widget.
  */
class M_EXPORT MCellCreator
{
public:
    /*!
      Default virtual destructor.
      */
    virtual ~MCellCreator() {}

    /*!
      \brief When MList needs a cell, it will call this function to get a pointer to a widget.
      MList keeps ownership of a pointer and will delete object when it's not needed.
      It's not required but highly recommended to use recycler. This function will be called very
      often during panning and to make panning smooth creator shouldn't allocate memory.

      Function should return fully constructed and initialized object. All data has to be set.

      \param index is a model index of the row for which widget should be created
      \param recycler is a MWidgetRecycler which allows widget reusage. MList will put widgets to
        this recycler and its possible to get recycled widget from it
      \param pointer to fully created widget

      \sa MWidgetRecycler
      */
    virtual MWidget *createCell(const QModelIndex &index, MWidgetRecycler &recycler) const = 0;

    /*!
      \brief This function should be implemented in order to update content of existing list item.

      \param index model index which data should be set
      \param cell widget where data should be updated
      */
    virtual void updateCell(const QModelIndex &index, MWidget *cell) const = 0;

    /*!
      \brief This function should return cell size. Minimum and maximum sizes of cell widget will be updated
      if returned size bigger then maximum size or smaller then minimum size. Only height will be taken into account,
      width of item will be calculate by MList.

      \return cell size
      */
    virtual QSizeF cellSize() const = 0;
};

//! \internal
template <class T>
class MListCellCreatorHelper
{
public:
    static T *createCell(MWidgetRecycler &recycler, const QString &viewType, const QString &objectName) {
        T *cell = dynamic_cast<T *>(recycler.take(T::staticMetaObject.className()));
        if (cell == NULL) {
            cell = new T;

            if (!viewType.isEmpty())<commit_msg>Fixes: NB#197889 - MAbstractCellCreator header contains dynamic_cast preventing application from using -fno-rtti when compiling.<commit_after>/***************************************************************************
**
** Copyright (C) 2010 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.
**
****************************************************************************/

#ifndef MLISTCELLCREATOR_H__
#define MLISTCELLCREATOR_H__

#include <QModelIndex>
#include <QSizeF>
#include <MWidgetRecycler>
#include <MWidget>

/*!
    \class MCellCreator
    \brief Interface for creating and updating items (cells) for MList.

    \section MCellCreator Overview
        MCellCreator is a purely abstract class and should be implemented by every class whose instances
        are intended to create items for MList.

        Main purpose of this interface is to create and update data of widgets which has to be inserted
        into MList. Also MCellCreator returns size of a list item widget.
  */
class M_EXPORT MCellCreator
{
public:
    /*!
      Default virtual destructor.
      */
    virtual ~MCellCreator() {}

    /*!
      \brief When MList needs a cell, it will call this function to get a pointer to a widget.
      MList keeps ownership of a pointer and will delete object when it's not needed.
      It's not required but highly recommended to use recycler. This function will be called very
      often during panning and to make panning smooth creator shouldn't allocate memory.

      Function should return fully constructed and initialized object. All data has to be set.

      \param index is a model index of the row for which widget should be created
      \param recycler is a MWidgetRecycler which allows widget reusage. MList will put widgets to
        this recycler and its possible to get recycled widget from it
      \param pointer to fully created widget

      \sa MWidgetRecycler
      */
    virtual MWidget *createCell(const QModelIndex &index, MWidgetRecycler &recycler) const = 0;

    /*!
      \brief This function should be implemented in order to update content of existing list item.

      \param index model index which data should be set
      \param cell widget where data should be updated
      */
    virtual void updateCell(const QModelIndex &index, MWidget *cell) const = 0;

    /*!
      \brief This function should return cell size. Minimum and maximum sizes of cell widget will be updated
      if returned size bigger then maximum size or smaller then minimum size. Only height will be taken into account,
      width of item will be calculate by MList.

      \return cell size
      */
    virtual QSizeF cellSize() const = 0;
};

//! \internal
template <class T>
class MListCellCreatorHelper
{
public:
    static T *createCell(MWidgetRecycler &recycler, const QString &viewType, const QString &objectName) {
        T *cell = static_cast<T *>(recycler.take(T::staticMetaObject.className()));
        if (cell == NULL) {
            cell = new T;

            if (!viewType.isEmpty())
{'fraction_non_alphanumeric': 0.10473167916907097, 'fraction_numerical': 0.003462204270051933, 'mean_word_length': 3.354899497487437, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '7047869', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1687, 'n_words': 851}