Beispiel #1
0
bool
TableModel::setData(const QModelIndex &index,
                    const QVariant &value,
                    int role)
{
    if ( !index.isValid() ) {
        return false;
    }

    TableItem *itm = item(index);
    if (itm) {
        itm->setData(role, value);

        return true;
    }

    // don't create dummy table items for empty values
    if ( !value.isValid() ) {
        return false;
    }

    TableView *view = qobject_cast<TableView*>( QObject::parent() );
    if (!view) {
        return false;
    }

    itm = createItem();
    itm->setData(role, value);
    view->setItem(index.row(), index.column(), itm);

    return true;
}
Beispiel #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;
}
Beispiel #3
0
bool
TableModel::setHeaderData(int section,
                          Qt::Orientation orientation,
                          const QVariant &value,
                          int role)
{
    if ( (section < 0) ||
         ( (orientation == Qt::Horizontal) && ( (int)_imp->horizontalHeaderItems.size() <= section ) ) ) {
        return false;
    }

    TableItem *itm = 0;
    if (orientation == Qt::Horizontal) {
        itm = _imp->horizontalHeaderItems.at(section);
    }

    if (itm) {
        itm->setData(role, value);

        return true;
    }

    return false;
}