convertIterFromParentToChildModel ::
     TreeIter -- ^ the iterator
  -> TreeModel -- ^ the model that we got from the all back
  -> TreeModel -- ^ the model that we actually want
  -> IO TreeIter
convertIterFromParentToChildModel iter parentModel@(TreeModel parentModelPtr) childModel =
  let (TreeModel modelPtr) = childModel in
  if managedForeignPtr modelPtr == managedForeignPtr parentModelPtr
    then return iter
    else
        castTo TreeModelFilter parentModel >>= \case
            Just tmFilter -> do
                childIter <- treeModelFilterConvertIterToChildIter tmFilter iter
                Just child@(TreeModel childPtr) <- getTreeModelFilterChildModel tmFilter
                if managedForeignPtr childPtr == managedForeignPtr modelPtr
                    then return childIter
                    else convertIterFromParentToChildModel childIter child childModel
            Nothing -> do
                castTo TreeModelSort parentModel >>= \case
                    Just tmSort -> do
                        childIter <- treeModelSortConvertIterToChildIter tmSort iter
                        child@(TreeModel childPtr) <- getTreeModelSortModel tmSort
                        if managedForeignPtr childPtr == managedForeignPtr modelPtr
                            then return childIter
                            else convertIterFromParentToChildModel childIter child childModel
                    Nothing -> do
                        stamp <- getTreeIterStamp iter
                        ud1 <- getTreeIterUserData iter
                        ud2 <- getTreeIterUserData2 iter
                        ud3 <- getTreeIterUserData3 iter
                        error ("CellLayout: don't know how to convert iter "++show (stamp, ud1, ud2, ud3)++
                               " from model "++show (managedForeignPtr parentModelPtr)++" to model "++
                               show (managedForeignPtr modelPtr)++". Is it possible that you are setting the "++
                               "attributes of a CellRenderer using a different model than "++
                               "that which was set in the view?")
convertIterFromParentToChildModel ::
     TreeIter -- ^ the iterator
  -> TreeModel -- ^ the model that we got from the all back
  -> TreeModel -- ^ the model that we actually want
  -> IO TreeIter
convertIterFromParentToChildModel iter parentModel@(TreeModel parentModelPtr) childModel =
  let (TreeModel modelPtr) = childModel in
  if managedForeignPtr modelPtr == managedForeignPtr parentModelPtr
    then return iter
    else
        castTo TreeModelFilter parentModel >>= \case
            Just tmFilter -> do
                childIter <- treeModelFilterConvertIterToChildIter tmFilter iter
                Just child@(TreeModel childPtr) <- getTreeModelFilterChildModel tmFilter
                if managedForeignPtr childPtr == managedForeignPtr modelPtr
                    then return childIter
                    else convertIterFromParentToChildModel childIter child childModel
            Nothing -> do
                castTo TreeModelSort parentModel >>= \case
                    Just tmSort -> do
                        childIter <- treeModelSortConvertIterToChildIter tmSort iter
                        child@(TreeModel childPtr) <- getTreeModelSortModel tmSort
                        if managedForeignPtr childPtr == managedForeignPtr modelPtr
                            then return childIter
                            else convertIterFromParentToChildModel childIter child childModel
                    Nothing -> do
                        stamp <- getTreeIterStamp iter
                        ud1 <- getTreeIterUserData iter
                        ud2 <- getTreeIterUserData2 iter
                        ud3 <- getTreeIterUserData3 iter
                        error ("CellLayout: don't know how to convert iter "++show (stamp, ud1, ud2, ud3)++
                               " from model "++show (managedForeignPtr parentModelPtr)++" to model "++
                               show (managedForeignPtr modelPtr)++". Is it possible that you are setting the "++
                               "attributes of a CellRenderer using a different model than "++
                               "that which was set in the view?")
convertIterFromParentToChildModel iter parentModel@(TreeModel parentModelPtr) childModel =
  let (TreeModel modelPtr) = childModel in
  if managedForeignPtr modelPtr == managedForeignPtr parentModelPtr
    then return iter
    else
        castTo TreeModelFilter parentModel >>= \case
            Just tmFilter -> do
                childIter <- treeModelFilterConvertIterToChildIter tmFilter iter
                Just child@(TreeModel childPtr) <- getTreeModelFilterChildModel tmFilter
                if managedForeignPtr childPtr == managedForeignPtr modelPtr
                    then return childIter
                    else convertIterFromParentToChildModel childIter child childModel
            Nothing -> do
                castTo TreeModelSort parentModel >>= \case
                    Just tmSort -> do
                        childIter <- treeModelSortConvertIterToChildIter tmSort iter
                        child@(TreeModel childPtr) <- getTreeModelSortModel tmSort
                        if managedForeignPtr childPtr == managedForeignPtr modelPtr
                            then return childIter
                            else convertIterFromParentToChildModel childIter child childModel
                    Nothing -> do
                        stamp <- getTreeIterStamp iter
                        ud1 <- getTreeIterUserData iter
                        ud2 <- getTreeIterUserData2 iter
                        ud3 <- getTreeIterUserData3 iter
                        error ("CellLayout: don't know how to convert iter "++show (stamp, ud1, ud2, ud3)++
                               " from model "++show (managedForeignPtr parentModelPtr)++" to model "++
                               show (managedForeignPtr modelPtr)++". Is it possible that you are setting the "++
                               "attributes of a CellRenderer using a different model than "++
                               "that which was set in the view?")