Safe Haskell | None |
---|
Graphics.QML.Objects
Contents
Description
Facilities for defining new object types which can be marshalled between Haskell and QML.
- class Typeable tt => Object tt where
- data ClassDef tt
- data Member tt
- defClass :: forall tt. Object tt => [Member tt] -> ClassDef tt
- defMethod :: forall tt ms. (Marshal tt, MarshalFromObj (MarshalMode tt), MethodSuffix (MSHelp ms)) => String -> (tt -> ms) -> Member (ThisObj tt)
- class MethodSuffix a
- defPropertyRO :: forall tt tr. (Marshal tt, MarshalFromObj (MarshalMode tt), Marshal tr, MarshalToVal (MarshalMode tr)) => String -> (tt -> IO tr) -> Member (ThisObj tt)
- 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)
- defSignal :: forall obj sk. (Object obj, SignalKey sk) => Tagged sk String -> Member obj
- fireSignal :: forall tt sk. (Marshal tt, MarshalToObj (MarshalMode tt), Object (ThisObj tt), SignalKey sk) => Tagged sk tt -> SignalParams sk
- class (SignalSuffix (SignalParams sk), Typeable sk) => SignalKey sk where
- type SignalParams sk
- class SignalSuffix ss
- data ObjRef tt
- newObject :: forall tt. Object tt => tt -> IO (ObjRef tt)
- fromObjRef :: ObjRef tt -> tt
- data AnyObjRef
- anyObjRef :: ObjRef tt -> AnyObjRef
- fromAnyObjRef :: Object tt => AnyObjRef -> Maybe (ObjRef tt)
- objSimpleMarshaller :: forall obj. Object obj => Marshaller obj (ValObjToOnly obj)
- objBidiMarshaller :: forall obj. Object obj => (obj -> IO (ObjRef obj)) -> Marshaller obj (ValObjBidi obj)
Class Definition
class Typeable tt => Object tt where
The class Object
allows Haskell types to expose an object-oriented
interface to QML.
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
.
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
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
SignalSuffix (IO ()) | |
(Marshal a, MarshalToVal (MarshalMode a), SignalSuffix b) => SignalSuffix (a -> b) |
Object References
data ObjRef tt
Represents an instance of the QML class which wraps the type 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
fromAnyObjRef :: Object tt => AnyObjRef -> Maybe (ObjRef 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 ObjRef
s.
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
ObjRef
s. 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