hsqml-0.2.0.3: Haskell binding for Qt Quick

Safe HaskellNone

Graphics.QML.Objects

Contents

Description

Facilities for defining new object types which can be marshalled between Haskell and QML.

Synopsis

Class Definition

class Typeable tt => Object tt where

The class Object allows Haskell types to expose an object-oriented interface to QML.

Methods

classDef :: ClassDef tt

data ClassDef tt

Represents the API of the QML class which wraps the type tt.

data Member tt

Represents a named member of the QML class which wraps type tt.

defClass :: forall tt. Object tt => [Member tt] -> ClassDef tt

Generates a ClassDef from a list of Members.

Methods

defMethod :: forall tt ms. (Marshal tt, MarshalFromObj (MarshalMode tt), MethodSuffix (MSHelp ms)) => String -> (tt -> ms) -> Member (ThisObj tt)

Defines a named method using a function f in the IO monad.

The first argument to f receives the "this" object and hence must match the type of the class on which the method is being defined. Subsequently, there may be zero or more parameter arguments followed by an optional return argument in the IO monad.

class MethodSuffix a

Supports marshalling Haskell functions with an arbitrary number of arguments.

Properties

defPropertyRO :: forall tt tr. (Marshal tt, MarshalFromObj (MarshalMode tt), Marshal tr, MarshalToVal (MarshalMode tr)) => String -> (tt -> IO tr) -> Member (ThisObj tt)

Defines a named read-only property using an accessor function in the IO monad.

defPropertyRW :: forall tt tr. (Marshal tt, MarshalFromObj (MarshalMode tt), Marshal tr, MarshalToHs (MarshalMode tr), MarshalToVal (MarshalMode tr)) => String -> (tt -> IO tr) -> (tt -> tr -> IO ()) -> Member (ThisObj tt)

Defines a named read-write property using a pair of accessor and mutator functions in the IO monad.

Signals

defSignal :: forall obj sk. (Object obj, SignalKey sk) => Tagged sk String -> Member obj

Defines a named signal using a SignalKey.

fireSignal :: forall tt sk. (Marshal tt, MarshalToObj (MarshalMode tt), Object (ThisObj tt), SignalKey sk) => Tagged sk tt -> SignalParams sk

Fires a signal on an Object, specified using a SignalKey.

class (SignalSuffix (SignalParams sk), Typeable sk) => SignalKey sk

Instances of the SignalKey class identify distinct signals. The associated SignalParams type specifies the signal's signature.

Associated Types

type SignalParams sk

class SignalSuffix ss

Supports marshalling an arbitrary number of arguments into a QML signal.

Instances

Object References

data ObjRef tt

Represents an instance of the QML class which wraps the type tt.

Instances

Object tt => Marshal (ObjRef tt) 

newObject :: forall tt. Object tt => tt -> IO (ObjRef tt)

Creates an instance of a QML class given a value of the underlying Haskell type tt.

fromObjRef :: ObjRef tt -> tt

Returns the associated value of the underlying Haskell type tt from an instance of the QML class which wraps it.

Dynamic Object References

data AnyObjRef

Represents an instance of a QML class which wraps an arbitrary Haskell type. Unlike ObjRef, an AnyObjRef only carries the type of its Haskell value dynamically and does not encode it into the static type.

Instances

anyObjRef :: ObjRef tt -> AnyObjRef

Upcasts an ObjRef into an AnyObjRef.

fromAnyObjRef :: Object tt => AnyObjRef -> Maybe (ObjRef tt)

Attempts to downcast an AnyObjRef into an ObjRef with the specific underlying Haskell type tt.

Customer Marshallers

objSimpleMarshaller :: forall obj. Object obj => Marshaller obj (ValObjToOnly obj)

Provides a QML-to-Haskell Marshaller which allows you to define instances of Marshal for custom Object types. This allows a custom types to be passed into Haskell code as method parameters without having to manually deal with ObjRefs.

For example, an instance for MyObjectType would be defined as follows:

 instance Marshal MyObjectType where
     type MarshalMode MyObjectType = ValObjToOnly MyObjectType
     marshaller = objSimpleMarshaller

objBidiMarshaller :: forall obj. Object obj => (obj -> IO (ObjRef obj)) -> Marshaller obj (ValObjBidi obj)

Provides a bidirectional QML-to-Haskell and Haskell-to-QML Marshaller which allows you to define instances of Marshal for custom object types. This allows a custom type to be passed in and out of Haskell code via methods, properties, and signals, without having to manually deal with ObjRefs. Unlike the simple marshaller, this one must be given a function which specifies how to obtain an ObjRef given a Haskell value.

For example, an instance for MyObjectType which simply creates a new object whenever one is required would be defined as follows:

 instance Marshal MyObjectType where
     type MarshalMode MyObjectType = ValObjBidi MyObjectType
     marshaller = objBidiMarshaller newObject