packages feed

hsqml-datamodel 0.1.0.0 → 0.2.0.0

raw patch · 7 files changed

+43/−78 lines, 7 files

Files

hsqml-datamodel.cabal view
@@ -1,5 +1,5 @@ name:                hsqml-datamodel-version:             0.1.0.0+version:             0.2.0.0 synopsis:            HsQML (Qt5) data model. description:         HsQML (Qt5) data model. Use any collection (actually, any (Int -> IO a) action) of single constructor data types as a model for use with QML views. license:             BSD3@@ -34,7 +34,6 @@                         Graphics.QML.DataModel.Internal.Generic.Get                         Graphics.QML.DataModel.Internal.Generic.Set                         Graphics.QML.DataModel.Internal.Generic.Count-                        Graphics.QML.DataModel.Internal.Generic.Mock                         Graphics.QML.DataModel.Internal.Types                         Graphics.QML.DataModel.TH                         Graphics.QML.DataModel.Generic@@ -77,7 +76,7 @@                 Qt5Qml     >= 5.0 && < 6.0,                 Qt5Quick   >= 5.0 && < 6.0         Extra-libraries: stdc++-  ghc-options: -Wall +  ghc-options: -Wall -fno-warn-partial-type-signatures   if flag(devel)      ghc-options: -Werror 
src/Graphics/QML/DataModel/Internal/Generic/Count.hs view
@@ -4,8 +4,10 @@     DefaultSignatures   , DeriveDataTypeable   , FlexibleContexts+  , PartialTypeSignatures   , PolyKinds   , ScopedTypeVariables+  , TypeFamilies   , TypeOperators    #-} @@ -25,8 +27,6 @@ import Data.Typeable import GHC.Generics -import Graphics.QML.DataModel.Internal.Generic.Mock- -- |Exception thrown when QML tries to acces a column that is not available. Shouldn't really happen. data ColumnIndexException =     ColumnIndexNegative Int        -- ^QML called for a negative column index.@@ -37,24 +37,28 @@  -- |A class of types that have a specific number of fields. Generic implementation is provided for all purely product types. class CountFields t where-  countFields :: sing t -> Int+  countFields :: proxy t -> Int  -  default countFields :: (Mock t, Generic t, GCountFields (Rep t)) => sing t -> Int-  countFields _ = gCountFields $ from (mock :: t)+  default countFields :: (Generic t, GCountFields f, (Rep t ~ f a)) => proxy t -> Int+  countFields _ = gCountFields p+    where p :: Proxy (Rep t) = Proxy  -- |Generic implementation of the 'CountFields' class. class GCountFields f where-  gCountFields :: f a -> Int+  gCountFields :: proxy (f a) -> Int --- |A container type has a single column.+-- |A container type has a proxyle column. instance GCountFields (K1 i c) where-  gCountFields (K1 _) = 1+  gCountFields _ = 1  -- |Meta information is skipped, and the recursion proceeds further down. instance GCountFields f => GCountFields (M1 i t f) where-  gCountFields (M1 a) = gCountFields a+  gCountFields _ = gCountFields p+    where p :: Proxy (f _) = Proxy  -- |A product type's number of columns is a sum of the terms' column numbers. instance (GCountFields a, GCountFields b) => GCountFields (a :*: b) where-  gCountFields (a :*: b) = gCountFields a + gCountFields b+  gCountFields _ = gCountFields a + gCountFields b+    where a :: Proxy (a _) = Proxy+          b :: Proxy (b _) = Proxy 
src/Graphics/QML/DataModel/Internal/Generic/Get.hs view
@@ -4,7 +4,9 @@     DefaultSignatures   , FlexibleContexts   , FlexibleInstances+  , PartialTypeSignatures   , PolyKinds+  , ScopedTypeVariables   , TypeOperators   #-} @@ -25,6 +27,7 @@  import Control.Exception import Control.Monad+import Data.Proxy import Data.Text (Text, unpack) import Foreign.C.Types import GHC.Generics@@ -57,8 +60,10 @@        if ix < na            then gGetColumn  ix       a           else gGetColumn (ix - na) b-     where na = gCountFields a-           nb = gCountFields b+     where na = gCountFields pa+           nb = gCountFields pb+           pa :: Proxy (a _) = Proxy+           pb :: Proxy (b _) = Proxy  -- |A class of types with columns that can be cast to a 'QtVariant'. class QtField t where
− src/Graphics/QML/DataModel/Internal/Generic/Mock.hs
@@ -1,45 +0,0 @@-{-# OPTIONS_HADDOCK show-extensions #-}--{-# LANGUAGE -    DefaultSignatures-  , FlexibleContexts-  , PolyKinds-  , TypeOperators -  #-}--{-|-Module      : Graphics.QML.DataModel.Internal.Generic.Mock-Copyright   : (c) Marcin Mrotek, 2015-License     : BSD3-Maintainer  : marcin.jan.mrotek@gmail.com-Stability   : experimental--}--module Graphics.QML.DataModel.Internal.Generic.Mock where--import GHC.Generics -{-|-A class that constructs a mock object, with all fields set to 'undefined',-for use with generic implementations that don't actually use the supplied data.-Only data types with a single constuctor can have an unambiguous mock object.--}-class Mock t where-  -- |Construct a mock object of a data type with a single constructor, with 'undefined' fields.-  mock :: t--  default mock :: (Generic t, GMock (Rep t)) => t-  mock = to gMock- -class GMock f where-  -- |Generic version of 'mock'.-  gMock :: f a--instance GMock (K1 i c) where-  gMock = K1 undefined--instance GMock f => GMock (M1 i t f) where-  gMock = M1 gMock--instance (GMock a, GMock b) => GMock (a :*: b) where-  gMock = gMock :*: gMock -
src/Graphics/QML/DataModel/Internal/Generic/Set.hs view
@@ -4,8 +4,10 @@     DefaultSignatures   , FlexibleContexts   , FlexibleInstances+  , PartialTypeSignatures   , PolyKinds   , ScopedTypeVariables+  , TypeFamilies   , TypeOperators   #-} @@ -23,39 +25,39 @@  import Graphics.QML.DataModel.Internal.FFI import Graphics.QML.DataModel.Internal.Generic.Count-import Graphics.QML.DataModel.Internal.Generic.Mock +import Data.Proxy import GHC.Generics --- |A class of types that can provide a template to setup the QT HaskellModel. A generic implementation is provided for all single constructor types.+-- |A class of types that can provide a template to setup the QT HaskellModel. A generic implementation is provided for all proxyle constructor types. class SetupColumns t where-  setupColumns :: HmDelegateHandle -> sing t -> IO ()+  setupColumns :: HmDelegateHandle -> proxy t -> IO ()    default setupColumns -    :: ( Mock t-       , Generic t-       , GSetupColumns (Rep t)-       ) +    :: ( Generic t, GSetupColumns f, (Rep t ~ f a) )      => HmDelegateHandle -    -> sing t +    -> proxy t      -> IO ()-  setupColumns d _ = gSetupColumns d $ from (mock :: t)+  setupColumns d _ = gSetupColumns d p+    where p :: Proxy (Rep t) = Proxy    -- |A generic implementation for 'SetupColumns'. class GSetupColumns f where-  gSetupColumns :: HmDelegateHandle -> f a -> IO ()+  gSetupColumns :: HmDelegateHandle -> proxy (f a) -> IO ()  -- |A helper class for the generic implementation for 'SetupColumns', starts its work at a particular index. class GSetupColumnIx f where-  gSetupColumnIx :: HmDelegateHandle -> Int -> f a -> IO ()+  gSetupColumnIx :: HmDelegateHandle -> Int -> proxy (f a) -> IO ()  -- |Meta information for a whole datatype is skipped, and the recursion proceeds further down. instance GSetupColumns f => GSetupColumns (M1 D t f) where-  gSetupColumns h (M1 t) = gSetupColumns h t+  gSetupColumns h _ = gSetupColumns h p+    where p :: Proxy (f _) = Proxy  -- |Meta information for a constructor is skipped, and 'SetupColumnIx' is used starting at index 0. instance GSetupColumnIx f => GSetupColumns (M1 C t f) where-  gSetupColumns h (M1 t) = gSetupColumnIx h 0 t+  gSetupColumns h _ = gSetupColumnIx h 0 p+    where p :: Proxy (f _) = Proxy  -- |Setups both terms of the product. instance ( GCountFields a@@ -63,11 +65,14 @@          , GSetupColumnIx a          , GSetupColumnIx b          ) => GSetupColumnIx (a :*: b) where-  gSetupColumnIx h ix (a :*: b) = do+  gSetupColumnIx h ix _ = do      gSetupColumnIx h  ix                   a      gSetupColumnIx h (ix + gCountFields a) b+   where a :: Proxy (a _) = Proxy+         b :: Proxy (b _) = Proxy  -- |A model role name is added accoring to the record selector's name. instance Selector t => GSetupColumnIx (M1 S t f) where-  gSetupColumnIx h ix t = addHaskellModelRole h ix $ selName t+  gSetupColumnIx h ix _ = addHaskellModelRole h ix $ selName u+    where u :: M1 S t f _ = undefined 
src/Graphics/QML/DataModel/TH.hs view
@@ -16,7 +16,6 @@  @  instance QtTable      T- instance Mock         T  instance CountFields  T  instance SetupColumns T @@@ -24,7 +23,6 @@ -} dataModelInstances name =     [d| instance QtTable      $t; -       instance Mock         $t;        instance CountFields  $t;        instance SetupColumns $t;    |] 
src/Graphics/QML/DataModel/Tutorial.hs view
@@ -33,7 +33,6 @@  @  instance QtTable      Row- instance Mock         Row  instance CountFields  Row  instance SetupColumns Row @