QTfrontend/themesmodel.cpp
author orange.hg@gmail.com
Tue, 28 Jun 2011 20:42:04 +0000
changeset 5327 f3635f25f706
parent 5289 9d18b61bd3eb
child 5330 0f31c8ab064b
permissions -rw-r--r--
Second passage (second time I correct), -nouvelles phrases de jeu (new sentences) -correction de fautes (correction of mistakes) -reformulations pour plus de compréhension et de cohérence (reformulation for more understanding)


#include "themesmodel.h"

ThemesModel::ThemesModel(QStringList themes, QObject *parent) :
    QAbstractListModel(parent)
{
    m_data.reserve(themes.size());

    foreach(QString theme, themes)
    {
        m_data.append(QHash<int, QVariant>());
        m_data.last().insert(Qt::DisplayRole, theme);
    }
}

int ThemesModel::rowCount(const QModelIndex &parent) const
{
    if(parent.isValid())
        return 0;
    else
        return m_data.size();
}

QVariant ThemesModel::data(const QModelIndex &index, int role) const
{
    if(index.column() > 0 || index.row() >= m_data.size())
        return QVariant();
    else
        return m_data.at(index.row()).value(role);
}

bool ThemesModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
    if(index.column() > 0 || index.row() >= m_data.size())
        return false;
    else
    {
        m_data[index.row()].insert(role, value);

        return true;
    }

}