GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 30, 2014 3:11 pm

All times are UTC




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to remove (unset) values from TreeModel
PostPosted: Fri May 31, 2013 7:44 am 
Offline
Familiar Face

Joined: Mon Dec 21, 2009 4:36 pm
Posts: 22
Sorry for beginner's question... How can I remove values from TreeStore and ListStore. When tree row is created it contain no values and displayed as blank, empty row. Is there any way to clear cells again?


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Sat Jun 01, 2013 3:46 am 
Offline
GTK+ Geek

Joined: Fri Sep 04, 2009 6:53 am
Posts: 68
https://developer.gnome.org/gtk3/stable/GtkListStore.html#gtk-list-store-remove
https://developer.gnome.org/gtk3/stable/GtkTreeStore.html#gtk-tree-store-remove


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Mon Jun 03, 2013 10:33 am 
Offline
Familiar Face

Joined: Mon Dec 21, 2009 4:36 pm
Posts: 22
Thank you but this is not what I want... I don't want to remove ROW, I want to remove VALUES from the row. The row itself shoud remain.


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Mon Jun 10, 2013 11:23 am 
Offline
Familiar Face

Joined: Mon Dec 21, 2009 4:36 pm
Posts: 22
Any ideas? Pleas help...


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Mon Jun 10, 2013 11:49 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 766
Location: UK
Hi,

The only way to clear the values on a row as if you have just created a row with GtkTreeStore or GtkListStore is to :-
1 - Delete your old row
2 - Create a new blank row
3 - Move the new row to where your old row was

_________________
E.


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Mon Jun 10, 2013 11:56 am 
Offline
Familiar Face

Joined: Mon Dec 21, 2009 4:36 pm
Posts: 22
But what about tree? In this case, I have to copy all rows from old iter to new one... This is not very good idea....
Ok, thank you anyway.


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Mon Jun 10, 2013 12:42 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 766
Location: UK
If you were much more clear what you want to do then that would help. Your original question was about a single row. Now you are talking about copying all your rows. Never in my answer did I say that you needed to copy any of your original rows.

_________________
E.


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Mon Jun 10, 2013 1:27 pm 
Offline
Familiar Face

Joined: Mon Dec 21, 2009 4:36 pm
Posts: 22
Sorry for misunderstanding. My goal is just to clear one row in the tree or table. Another goal is to clear memory occupied by data, used for row rendering. Of course this row can have child rows... I want to remove all data from the row and make it's values clear as of new-created row.


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Mon Jun 10, 2013 5:22 pm 
Offline
GTK+ Geek

Joined: Fri Sep 04, 2009 6:53 am
Posts: 68
I was always under the impression that GtkListStore and GtkTreeStore does the memory management for you.

Quote:
The value will be referenced by the store if it is a G_TYPE_OBJECT, and it will be copied if it is a G_TYPE_STRING or G_TYPE_BOXED.


https://developer.gnome.org/gtk3/stable/GtkListStore.html#gtk-list-store-set

Code:
gtk_list_store_set(store,iter,1,"This is a long stringgggggggggggggggggggggggggggggggggggggg",-1);
// liststore has made a copy of the long string

gtk_list_store_set(store,iter,1,"",-1);
// liststore doesn't need the copy of the long string anymore. The copy has been g_free'ed in gtk_list_store_set.



Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Tue Jun 11, 2013 6:16 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 766
Location: UK
asdfgh2091 is correct in that GtkTreeStore and GtkListStore copy the data you provide and do their own memory management..

_________________
E.


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Thu Jun 13, 2013 3:12 pm 
Offline
Familiar Face

Joined: Mon Dec 21, 2009 4:36 pm
Posts: 22
Thank you for your replies. One more question: I have a column of type GDK_TYPE_PIXBUF and corresponding cell renderer. It can render an arbitary image ("pixbuf" attribute) or stock icon ("stock-id" attribute). What value should I set to the column to clear it (for "pixbuf" and "stock-id" case)? Can I use NULL value for this?


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Thu Jun 13, 2013 8:43 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
Hi,
Have you looked at http://www.gtkforums.com/viewtopic.php?f=3&t=2412? Tadeboro has given an excellent example of what you have asked.
Code:
      GdkPixbuf *pixbuf;
     
      pixbuf = gtk_widget_render_icon( GTK_WIDGET( treeview ),
                               GTK_STOCK_CANCEL,GTK_ICON_SIZE_BUTTON,
                               NULL );
     
      gtk_list_store_append( store, &iter );
      gtk_list_store_set( store, &iter,
                     COL_TEXT, g_strdup_printf( "Sample %d", i + 1 ),
                     COL_IMG, pixbuf,
                     -1 );
     
      g_object_unref( G_OBJECT( pixbuf ) );


NB: I assume you are asking to clear it from memory


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Fri Jun 14, 2013 6:06 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 766
Location: UK
Rudra that example came from a topic on memory management with that one showing how not to write your code.

I think that you can pass a NULL value for the PixBuf. I do recall doing something similar to this some time ago, but in C++.

Just give it a go on a test example, looking for any errors and warnings that may turn up on the console.

_________________
E.


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Fri Jun 14, 2013 12:05 pm 
Offline
Familiar Face

Joined: Mon Dec 21, 2009 4:36 pm
Posts: 22
rudra
Thank you for article

errol
Yes, my question was about passing NULL values. I don't quite understand what should I set to pixbuff and stock columns. When I try set NULL values to these columns I get the following error:
Code:
Gtk-CRITICAL **: gtk_list_store_set_value: assertion `G_IS_VALUE (value)' failed


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Tue Jul 02, 2013 5:59 am 
Offline
Familiar Face

Joined: Mon Dec 21, 2009 4:36 pm
Posts: 22
Is there any way to pass null values to these columns?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group