<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.
**
****************************************************************************/

#include "toolbarpage.h"
#include <MAction>
#include <MButton>
#include <MTextEdit>
#include <MLocale>
#include <MLabel>
#include <MWidgetAction>
#include <MLayout>
#include <MSeparator>
#include <MToolBar>
#include <MApplication>
#include <MApplicationWindow>
#include <MLinearLayoutPolicy>

#include <MContentItem>
#include <QDebug>

TestModel::TestModel(QObject *parent)
  : QAbstractListModel(parent), mode(InitiatedCall) {
    maxRowCount = 4;
    listNames << "Lauri" << "Santeri" << "Kaarle" << "imran" << "Iqbal" << "Jakub" << "Mihaly" << "Ilias" << "Antti" <<"Jani" << "Tomas" << "Denis";
}

int TestModel::rowCount(const QModelIndex &parent) const
{
  Q_UNUSED(parent);
  return maxRowCount;
}

QVariant TestModel::data(const QModelIndex &index, int role) const
{
 if (role == Qt::DisplayRole) {
     QStringList rowData;
     rowData << listNames[(mode*rowCount())+index.row()];

     switch(mode) {
         case TestModel::MissedCall: {
            rowData << "Missed Call";
            break;
         }
         case TestModel::ReceivedCall: {
            rowData << "Received Call";
            break;
         }
         case TestModel::InitiatedCall: {
            rowData << "Initiated Call";
            break;
         }
     }
     return QVariant(rowData);
 }

 return QVariant();
}

void TestModel::reloadData()
{
    if (rowCount() > 0 ) {
        emit dataChanged(index(0,0), index(rowCount()-1,0));
    }
}

void TestModel::setMode(TestModel::CallMode mode) {
   this->mode = mode;
}

class MContentItemCreator : public MAbstractCellCreator<MContentItem>
{
public:
    MContentItemCreator() {
    }

    void updateCell(const QModelIndex &index, MWidget *cell) const {
        MContentItem *contentItem = qobject_cast<MContentItem *>(cell);

        QVariant data = index.data(Qt::DisplayRole);
        QStringList rowData = data.value<QStringList>();
        contentItem->setTitle(rowData[0]);
        contentItem->setSubtitle(rowData[1]);

        updateContentItemMode(index, contentItem);
    }

    void updateContentItemMode(const QModelIndex &index, MContentItem *contentItem) const {
        int row = index.row();

        bool thereIsNextRow;

        if (amountOfColumns == 1) {
            thereIsNextRow = index.sibling(row + 1, 0).isValid();

            if (row == 0) {
                contentItem->setItemMode(MContentItem::SingleColumnTop);
            } else if (thereIsNextRow) {
                contentItem->setItemMode(MContentItem::SingleColumnCenter);
            } else {
                contentItem->setItemMode(MContentItem::SingleColumnBottom);
            }
        } else {
            bool left = ((row % 2) == 0);
            thereIsNextRow = left ? index.sibling(row + 2, 0).isValid() : index.sibling(row + 1, 0).isValid();
            if (row == 0 || row == 1) {
                left ? contentItem->setItemMode(MContentItem::TopLeft) : contentItem->setItemMode(MContentItem::TopRight);
            } else if (thereIsNextRow) {
                left ? contentItem->setItemMode(MContentItem::Left) : contentItem->setItemMode(MContentItem::Right);
            } else {
                left ? contentItem->setItemMode(MContentItem::BottomLeft) : contentItem->setItemMode(MContentItem::BottomRight);
            }
        }
    }

    void setColumns(int columns) {
        Q_ASSERT(columns > 0 && columns < 3);
        amountOfColumns = columns;
    }

private:
    int amountOfColumns;
};

ToolBarPage::ToolBarPage()
{
    gid = TemplatePage::ViewsAndDialogs;
}

ToolBarPage::~ToolBarPage()
{
    delete callModel;
}<commit_msg>Fixes: NB#166710 - widgetsgallery exits in crash<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.
**
****************************************************************************/

#include "toolbarpage.h"
#include <MAction>
#include <MButton>
#include <MTextEdit>
#include <MLocale>
#include <MLabel>
#include <MWidgetAction>
#include <MLayout>
#include <MSeparator>
#include <MToolBar>
#include <MApplication>
#include <MApplicationWindow>
#include <MLinearLayoutPolicy>

#include <MContentItem>
#include <QDebug>

TestModel::TestModel(QObject *parent)
  : QAbstractListModel(parent), mode(InitiatedCall) {
    maxRowCount = 4;
    listNames << "Lauri" << "Santeri" << "Kaarle" << "imran" << "Iqbal" << "Jakub" << "Mihaly" << "Ilias" << "Antti" <<"Jani" << "Tomas" << "Denis";
}

int TestModel::rowCount(const QModelIndex &parent) const
{
  Q_UNUSED(parent);
  return maxRowCount;
}

QVariant TestModel::data(const QModelIndex &index, int role) const
{
 if (role == Qt::DisplayRole) {
     QStringList rowData;
     rowData << listNames[(mode*rowCount())+index.row()];

     switch(mode) {
         case TestModel::MissedCall: {
            rowData << "Missed Call";
            break;
         }
         case TestModel::ReceivedCall: {
            rowData << "Received Call";
            break;
         }
         case TestModel::InitiatedCall: {
            rowData << "Initiated Call";
            break;
         }
     }
     return QVariant(rowData);
 }

 return QVariant();
}

void TestModel::reloadData()
{
    if (rowCount() > 0 ) {
        emit dataChanged(index(0,0), index(rowCount()-1,0));
    }
}

void TestModel::setMode(TestModel::CallMode mode) {
   this->mode = mode;
}

class MContentItemCreator : public MAbstractCellCreator<MContentItem>
{
public:
    MContentItemCreator() {
    }

    void updateCell(const QModelIndex &index, MWidget *cell) const {
        MContentItem *contentItem = qobject_cast<MContentItem *>(cell);

        QVariant data = index.data(Qt::DisplayRole);
        QStringList rowData = data.value<QStringList>();
        contentItem->setTitle(rowData[0]);
        contentItem->setSubtitle(rowData[1]);

        updateContentItemMode(index, contentItem);
    }

    void updateContentItemMode(const QModelIndex &index, MContentItem *contentItem) const {
        int row = index.row();

        bool thereIsNextRow;

        if (amountOfColumns == 1) {
            thereIsNextRow = index.sibling(row + 1, 0).isValid();

            if (row == 0) {
                contentItem->setItemMode(MContentItem::SingleColumnTop);
            } else if (thereIsNextRow) {
                contentItem->setItemMode(MContentItem::SingleColumnCenter);
            } else {
                contentItem->setItemMode(MContentItem::SingleColumnBottom);
            }
        } else {
            bool left = ((row % 2) == 0);
            thereIsNextRow = left ? index.sibling(row + 2, 0).isValid() : index.sibling(row + 1, 0).isValid();
            if (row == 0 || row == 1) {
                left ? contentItem->setItemMode(MContentItem::TopLeft) : contentItem->setItemMode(MContentItem::TopRight);
            } else if (thereIsNextRow) {
                left ? contentItem->setItemMode(MContentItem::Left) : contentItem->setItemMode(MContentItem::Right);
            } else {
                left ? contentItem->setItemMode(MContentItem::BottomLeft) : contentItem->setItemMode(MContentItem::BottomRight);
            }
        }
    }

    void setColumns(int columns) {
        Q_ASSERT(columns > 0 && columns < 3);
        amountOfColumns = columns;
    }

private:
    int amountOfColumns;
};

ToolBarPage::ToolBarPage() :
    callList(0),
    callModel(0),
    cellCreator(0),
    exampleAction1(0),
    exampleAction2(0),
    defaultViewAction(0),
    tabViewAction(0)
{
    gid = TemplatePage::ViewsAndDialogs;
}

ToolBarPage::~ToolBarPage()
{
    delete callModel;
}
{'fraction_non_alphanumeric': 0.15904707884288144, 'fraction_numerical': 0.008054452637549631, 'mean_word_length': 3.1742424242424243, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 69, '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': '4536858', 'n_tokens_mistral': 2695, 'n_tokens_neox': 2593, 'n_words': 600}