@@ -12,11 +12,12 @@ module FF.Qt.TaskWidget (
1212
1313import Control.Monad (void , when )
1414import Data.Foldable (for_ )
15+ import Data.Function (fix )
1516import Data.IORef (IORef , atomicWriteIORef , newIORef , readIORef )
1617import Data.Maybe (fromMaybe )
1718import Data.Text qualified as Text
1819import Data.Time (defaultTimeLocale , formatTime )
19- import Foreign.Hoppy.Runtime (delete , nullptr )
20+ import Foreign.Hoppy.Runtime (CppPtr , delete , nullptr )
2021import Graphics.UI.Qtah.Core.Types qualified as Qt
2122import Graphics.UI.Qtah.Signal (connect_ )
2223import Graphics.UI.Qtah.Widgets.QAbstractButton qualified as QAbstractButton
@@ -157,18 +158,18 @@ update keepOpen this noteDoc = do
157158 this. onTaskUpdated keepOpen entity
158159 where
159160 resetTags tags = do
160- deleteChildrenWidgets this. tags
161+ deleteAllLayoutWidgets this. tags
161162 for_ tags \ tag ->
162163 void $
163164 QBoxLayout. addWidget this. tags
164165 =<< qPushButton ! # text (Text. unpack tag) ! defaults
165166
166- deleteChildrenWidgets :: (QLayoutPtr layout ) => layout -> IO ()
167- deleteChildrenWidgets layout = loop
168- where
169- loop = do
170- child <- QLayout. takeAt layout 0
171- when (child /= nullptr) do
172- delete =<< QLayoutItem. widget child
173- delete child
174- loop
167+ deleteAllLayoutWidgets :: (QLayoutPtr layout ) => layout -> IO ()
168+ deleteAllLayoutWidgets layout =
169+ whilePtrAlive ( QLayout. takeAt layout 0 ) \ childItem -> do
170+ delete =<< QLayoutItem. widget childItem
171+ delete childItem
172+
173+ whilePtrAlive :: ( CppPtr t , Eq t , Monad m ) => m t -> ( t -> m a ) -> m ()
174+ whilePtrAlive get action =
175+ fix \ w -> do x <- get; when (x /= nullptr) $ action x *> w
0 commit comments