Beispiel #1
0
// Field.value (getter)
static KJSObject fieldGetValue( KJSContext *context, void *object )
{
    FormField *field = reinterpret_cast< FormField * >( object );
    if ( field->isReadOnly() )
    {
        KJSObject value = g_fieldCache->value( field );
        if ( g_fieldCache.exists() && g_fieldCache->contains( field ) )
            value = g_fieldCache->value( field );
        else
            value = KJSString("");
        qCDebug(OkularCoreDebug) << "Getting the value of a readonly field" << field->name() << ":" << value.toString( context );
        return value;
    }

    switch ( field->type() )
    {
        case FormField::FormButton:
        {
            const FormFieldButton *button = static_cast< const FormFieldButton * >( field );
            Q_UNUSED( button ); // ###
            break;
        }
        case FormField::FormText:
        {
            const FormFieldText *text = static_cast< const FormFieldText * >( field );
            return KJSString( text->text() );
        }
        case FormField::FormChoice:
        {
            const FormFieldChoice *choice = static_cast< const FormFieldChoice * >( field );
            Q_UNUSED( choice ); // ###
            break;
        }
        case FormField::FormSignature:
        {
            break;
        }
    }

    return KJSUndefined();
}
Beispiel #2
0
// Field.value (setter)
static void fieldSetValue( KJSContext *context, void *object, KJSObject value )
{
    FormField *field = reinterpret_cast< FormField * >( object );

    if ( field->isReadOnly() )
    {
        // ### throw exception?
        qCDebug(OkularCoreDebug) << "Trying to change the readonly field" << field->name() << "to" << value.toString( context );
        g_fieldCache->insert( field, value );
        return;
    }

    switch ( field->type() )
    {
        case FormField::FormButton:
        {
            FormFieldButton *button = static_cast< FormFieldButton * >( field );
            Q_UNUSED( button ); // ###
            break;
        }
        case FormField::FormText:
        {
            FormFieldText *text = static_cast< FormFieldText * >( field );
            text->setText( value.toString( context ) );
            break;
        }
        case FormField::FormChoice:
        {
            FormFieldChoice *choice = static_cast< FormFieldChoice * >( field );
            Q_UNUSED( choice ); // ###
            break;
        }
        case FormField::FormSignature:
        {
            break;
        }
    }
}