From: Johan N. <Joh...@br...> - 2009-09-15 20:31:08
|
Maybe you should use something like " i' <- treeModelSortConvertIterToChildIter sortList i " when using rows in a sorted model for retrieving data in an unsorted store. Works fine for me. /J -----Ursprungligt meddelande----- Från: Axel Simon [mailto:Axe...@en...] Skickat: den 10 september 2009 21:34 Till: Marcus Pedersén Kopia: Gtk2hs List Ämne: Re: [Gtk2hs-users] Reorder TreeView and model not updated On Sep 10, 2009, at 21:26, Marcus Pedersén wrote: > Yes, I am with you so far... > > using (as before): > selection <- treeViewGetSelection treeview > listOfInt <- treeSelectionGetSelectedRows selection > > I get my list of selected rows and I use my ListStore to get the > value: > value <- listStoreGetValue model row > > It works fine so far. > But when I start to sort my view by pressing the column titles the > order > in the view and the ListStore isn't the same and there is where I am > failing. > If I do like above I get the wrong row. > How do I keep control of the order between view and ListStore? You can't. The View can sort the rows according to your own sorting criteria. The Store always stays the same. Why would you want the user to sort the ListStore? Does treeSelectionGetSelectedRows return the row numbers as they occur in the TreeView? In that case, we have a bug to fix... Axel. > Thanks again! > Marcus > > tor 2009-09-10 klockan 20:22 +0200 skrev Axel Simon: >> Hi Marcus, >> >> On Sep 10, 2009, at 19:04, Marcus Pedersén wrote: >> >>> Sorry for stupid questions, but I do not seems to get it all right! >>> As I understand it I have to get the selected object from the >>> TreeView >>> and then search for it in the model. >>> But I can not figure out how to get the selected object out of the >>> TreeView. I can get the selected row number by using: >>> >>> selection <- treeViewGetSelection treeview >>> listOfInt <- treeSelectionGetSelectedRows selection >>> >>> But how do I get the object so I can compare and find it in my >>> model? >>> I realy must be missing somthing here!! >> >> First of all, make sure you use only modules form >> Graphics.UI.Gtk.ModelView.* not those under TreeList.* since those >> are deprecated. Your view must somehow be backed by a store in which >> the data reside. You can either use ListStore or TreeStore which are >> two models that handle a list of rows and a hierarchical arrangement >> of rows, respectively. If you use a ListStore, the selection will >> return a TreePath (a list of indices) which will have one element >> [i], indicating that the user selected the ith row in the ListStore. >> >> Is that what you're asking? >> >> Cheers, >> Axel. >> >>> Many, many thanks! >>> >>> Marcus >>> >>> >>> fre 2009-09-04 klockan 17:37 +0200 skrev Axel Simon: >>>> On Fri, 2009-09-04 at 16:11 +0200, Marcus Pedersén wrote: >>>>> Hi all! >>>>> I have started to find my way around the tables in gtk2hs, but one >>>>> problem I can not figure out is: >>>>> See code below for details. >>>>> When I reorder my table by clicking column title the model and >>>>> the view >>>>> does not get the same ordering. >>>> >>>> The model never changes! You can have several TreeViews using the >>>> same >>>> model. In each view, the user can reorder the columns in a >>>> different >>>> way. Note that you can insert several CellRenderer into the same >>>> column >>>> of a TreeView, thus there generally is no one-to-one correspondance >>>> between columns in the model and those in the view. >>>> >>>> Note that you should not use the modules under TreeList.* but only >>>> those >>>> under ModelView.*. The former are deprecated. Using the latter, you >>>> usually don't need column numbers in the model anymore since each >>>> in the >>>> ListStore is a simply Haskell value. >>>> >>>> Cheers, >>>> Axel. >>>> >>>>> What am I doing wrong?? >>>>> >>>>> Many thanks! >>>>> Marcus >>>>> >>>>> >>>>> I have written a test list store: >>>>> model <- listStoreNew >>>>> [ User (Just "192.168.1.1") (Just "192.168.1.0") (Just >>>>> "255.255.255.0") Nothing "Per" "Pelle" (Just "Chef") (Just >>>>> "Uppsala") >>>>> Available Male, >>>>> User (Just "192.168.1.2") (Just "192.168.1.0") (Just >>>>> "255.255.255.0") (Just "Debian2") "Arne" "Banan" (Just "Chef") >>>>> (Just >>>>> "Uppsala") Offline Male, >>>>> User (Just "192.168.1.3") (Just "192.168.1.0") (Just >>>>> "255.255.255.0") (Just "Debian3") "Jenny" "Li" (Just "Worker") >>>>> (Just >>>>> "Uppsala") Busy Female ] >>>>> >>>>> Made a sort model: >>>>> >>>>> sortModel <- treeModelSortNewWithModel model >>>>> treeSortableSetSortFunc sortModel 1 $ \iter1 iter2 -> do >>>>> a <- treeModelGetRow model iter1 >>>>> b <- treeModelGetRow model iter2 >>>>> return (compare (username a) (username b)) >>>>> treeSortableSetSortFunc sortModel 2 $ \iter1 iter2 -> do >>>>> a <- treeModelGetRow model iter1 >>>>> b <- treeModelGetRow model iter2 >>>>> return (compare (nickname a) (nickname b)) >>>>> >>>>> Made a treView with my sortmodel: >>>>> >>>>> view <- treeViewNewWithModel sortModel >>>>> >>>>> >>>>> ------------------------------------------------------------------ >>>>> -- >>>>> ---------- >>>>> Let Crystal Reports handle the reporting - Free Crystal Reports >>>>> 2008 30-Day >>>>> trial. Simplify your report design, integration and deployment - >>>>> and focus on >>>>> what you do best, core application coding. Discover what's new >>>>> with >>>>> Crystal Reports now. http://p.sf.net/sfu/bobj-july >>>>> _______________________________________________ >>>>> Gtk2hs-users mailing list >>>>> Gtk...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/gtk2hs-users >>>> >> ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gtk2hs-users mailing list Gtk...@li... https://lists.sourceforge.net/lists/listinfo/gtk2hs-users |