Ejemplo n.º 1
0
QVariant
TableModel::data(const QModelIndex &index,
                 int role) const
{
    TableItem *itm = item(index);

    if (itm) {
        return itm->data(role);
    }

    return QVariant();
}
Ejemplo n.º 2
0
bool
TableModel::setItemData(const QModelIndex &index,
                        const QMap<int, QVariant> &roles)
{
    if ( !index.isValid() ) {
        return false;
    }

    TableView *view = qobject_cast<TableView*>( QObject::parent() );
    TableItem *itm = item(index);
    if (itm) {
        itm->view = 0; // prohibits item from calling itemChanged()
        bool changed = false;
        for (QMap<int, QVariant>::ConstIterator it = roles.constBegin(); it != roles.constEnd(); ++it) {
            if ( itm->data( it.key() ) != it.value() ) {
                itm->setData( it.key(), it.value() );
                changed = true;
            }
        }
        itm->view = view;
        if (changed) {
            itemChanged(itm);
        }

        return true;
    }

    if (!view) {
        return false;
    }

    itm = createItem();
    for (QMap<int, QVariant>::ConstIterator it = roles.constBegin(); it != roles.constEnd(); ++it) {
        itm->setData( it.key(), it.value() );
    }
    view->setItem(index.row(), index.column(), itm);

    return true;
}
Ejemplo n.º 3
0
QVariant
TableModel::headerData(int section,
                       Qt::Orientation orientation,
                       int role) const
{
    if (section < 0) {
        return QVariant();
    }

    TableItem *itm = 0;
    if ( (orientation == Qt::Horizontal) && ( section < (int)_imp->horizontalHeaderItems.size() ) ) {
        itm = _imp->horizontalHeaderItems.at(section);
    } else {
        return QVariant(); // section is out of bounds
    }
    if (itm) {
        return itm->data(role);
    }
    if (role == Qt::DisplayRole) {
        return section + 1;
    }

    return QVariant();
}