//---------------------------------------------------------------------------------------
int tNdp2kTableDataSources::SetTableData( unsigned row, unsigned col, eSetType setType, const void* pSetData, unsigned dataSize )
{
    if (col != TABLE_COL_ALL)
        return TABLE_ERROR_INVALID_ARGUMENT;

    if (pSetData == NULL)
    {
        if (setType < SetType_MultiStart)
            return TABLE_ERROR_INVALID_ARGUMENT;

        int result = TABLE_OK;
        if (setType == SetType_MultiEnd)
        {
            // as breakdown is always by row, SetType_MultiEnd can only occur for full table transfers
            tTableFormat format = GetFormat();
            if (dataSize > format)
                SetFormat( tTableFormat(dataSize) );
            else if (dataSize < format)
                result = TABLE_OK_OLDER_FORMAT;

            emit TableChanged();
        }
        return result;
    }

    if (row >= unsigned(m_cMaxRows))
        return TABLE_ERROR_INVALID_ROW;

    Assert( DATA_ENGINE_ENUM_MIN >= -127 && DATA_ENGINE_ENUM_MAX <= 127 );

    tSourceSelections selections;
    tDecoder data( pSetData, dataSize );

    uint8_t count;
    if (data.GetFixed( count ) < 0)
        return data.Result();
    if (count == 0 || --count >= m_cMaxInstances)
        return TABLE_ERROR_CORRUPT_DATA;

    uint16_t type;
    if (data.GetFixed( type ) < 0)
        return data.Result();

    tDataType dataType = tDataType( type );
    selections.reserve( count );
    for (int i = 0; i < count; ++i)
    {
        const void* pColData;
        int size = data.GetSized( pColData );
        if (size < 0)
            return data.Result();
        if (size > 127)
            return TABLE_ERROR_CORRUPT_DATA;

        if (size == 0)
        {
            selections << tDataId();
        }
        else
        {
            const uint8_t* pData = static_cast< const uint8_t* >( pColData );
            selections << tDataId( dataType, tDataId::tDataSource( uint8_t(size-1), pData+1 ), tDataEngineType( int8_t(*pData) ) );
        }
    }

    if (data.Remaining() != 0)
        return TABLE_ERROR_CORRUPT_DATA;

    bool changed = false;
    {
        tQMutexLocker locker( &m_Lock );
        if (row >= unsigned(m_Table.count()))
        {
            if (setType != SetType_Table)
                return TABLE_ERROR_NEWER_FORMAT;

            if (row != unsigned(m_Table.count()))
                return TABLE_ERROR_MISSING_ROW;

            m_Table.resize( m_Table.count()+1 );
            m_Table[ row ].dataType = dataType;
        }
        else if (dataType != m_Table[ row ].dataType)
        {
//            Assert( 0 );
            return TABLE_ERROR_CORRUPT_DATA;
        }

        m_Table[ row ].dirty = false;

        if (selections != m_Table[ row ].selections)
        {
            m_Table[ row ].selections = selections;
            changed = true;
        }
    }
    if (changed == true && setType != SetType_Table)
        emit RowChanged( row );

    return TABLE_OK;
}
Exemple #2
0
void CResolverUIModel::Toggle(unsigned int row)
{
  if (m_model.toggle(row)) {
    RowChanged(row);
  }
}