changing the content of a model/view/store at run time

classic Classic list List threaded Threaded
7 messages Options
pcr
Reply | Threaded
Open this post in threaded view
|

changing the content of a model/view/store at run time

pcr

I'm trying to learn how to iterate over model rows in a manner similar to the code segment in section 9.3 of the gnome gtkmm tutorial.  Consider me a newbie; the "something" I want to do below is delete/clear/erase a row - really all rows so I can display a new set of rows in response to a user action like changing a radio button.  But I haven't been able to do it. Here is the snippit from section 9.3:

typedef Gtk::TreeModel::Children type_children; //minimise code length.
type_children children = refModel->children();
for(type_children::iterator iter = children.begin();
    iter != children.end(); ++iter)
{
  Gtk::TreeModel::Row row = *iter;
  //Do something with the row - see above for set/get.
}

I'm also confused by the following comment I found on line; I don't see how this can work with the above code either. 

iterator Gtk::TreeStore:erase(const iterator& iter)
	Returns an iterator to the next row or end() if there is none"

I hope you can help me .  Thanks, PCR


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: changing the content of a model/view/store at run time

Gtkmm mailing list
 From the Gtk::TreeModel reference: "This class defines a generic tree
interface for use by the Gtk::TreeView widget. ... It is important to
note that *this interface only provides a way of examining a model and
observing changes. The implementation of each individual model decides
how and if changes are made.*"

Have a look at Gtk::TreeStore and Gtk::ListStore, which are
implementations based on Gtk::TreeModel. One or the other will likely
provide the functionality you're looking for.

On 8/8/19 2:46 PM, pcr wrote:

>
> I'm trying to learn how to iterate over model rows in a manner similar
> to the code segment in section 9.3 of the gnome gtkmm tutorial. 
> Consider me a newbie; the "something" I want to do below is
> delete/clear/erase a row - really all rows so I can display a new set
> of rows in response to a user action like changing a radio button. 
> But I haven't been able to do it. Here is the snippit from section 9.3:
>
> typedef Gtk::TreeModel::Children type_children; //minimise code length.
> type_children children = refModel->children();
> for(type_children::iterator iter = children.begin();
>      iter != children.end(); ++iter)
> {
>    Gtk::TreeModel::Row row = *iter;
>    //Do something with the row - see above for set/get.
> }
>
> *I'm also confused by the following comment I found on line; I don't
> see how this can work with the above code either. ***
> iterator Gtk::TreeStore:erase(const iterator& iter)
> Returns an iterator to the next row or end() if there is none"
Note that this refers to Gtk:TreeStore, not Gtk::TreeModel.
> I hope you can help me .  Thanks, PCR
>
>
> _______________________________________________
> gtkmm-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtkmm-list
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
pcr
Reply | Threaded
Open this post in threaded view
|

Re: changing the content of a model/view/store at run time

pcr
In reply to this post by pcr

I have changed from a tree store to a list store now, and I have working code, except for the last line in this call back used when a radio button is clicked in order to erase the list store and replace it with another at run time:

  void ExampleWindow::on_rb2_clicked()
 {
    std::cout << "rb2 clicked" << std::endl;

    typedef Gtk::TreeModel::Children type_children;
    type_children children = liststore1->children();
    type_children::iterator iter;
    for(iter=children.begin(); iter!=children.end(); ++iter)
               gtk_list_store_remove (*liststore1,*iter);

}

The compiler message I get is

test3.cc: In member function ‘void ExampleWindow::on_rb2_clicked()’:
test3.cc:104:27: error: no match for ‘operator*’ (operand type is ‘Glib::RefPtr<Gtk::ListStore>’)
    gtk_list_store_remove (*liststore1,*iter);

So my question is, I suppose, what is the proper syntax for using gtk_list_store_remove ???

On 8/8/19 3:46 PM, pcr wrote:

I'm trying to learn how to iterate over model rows in a manner similar to the code segment in section 9.3 of the gnome gtkmm tutorial.  Consider me a newbie; the "something" I want to do below is delete/clear/erase a row - really all rows so I can display a new set of rows in response to a user action like changing a radio button.  But I haven't been able to do it. Here is the snippit from section 9.3:

typedef Gtk::TreeModel::Children type_children; //minimise code length.
type_children children = refModel->children();
for(type_children::iterator iter = children.begin();
    iter != children.end(); ++iter)
{
  Gtk::TreeModel::Row row = *iter;
  //Do something with the row - see above for set/get.
}

I'm also confused by the following comment I found on line; I don't see how this can work with the above code either. 

iterator Gtk::TreeStore:erase(const iterator& iter)
	Returns an iterator to the next row or end() if there is none"

I hope you can help me .  Thanks, PCR


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: changing the content of a model/view/store at run time

Gtkmm mailing list
if you think you have to use c api, you're almost certainlt doing it wrong. why? does the c++ wrapper not provide remove() ?

On Sat, 10 Aug 2019, 16:28 pcr, <[hidden email]> wrote:

I have changed from a tree store to a list store now, and I have working code, except for the last line in this call back used when a radio button is clicked in order to erase the list store and replace it with another at run time:

  void ExampleWindow::on_rb2_clicked()
 {
    std::cout << "rb2 clicked" << std::endl;

    typedef Gtk::TreeModel::Children type_children;
    type_children children = liststore1->children();
    type_children::iterator iter;
    for(iter=children.begin(); iter!=children.end(); ++iter)
               gtk_list_store_remove (*liststore1,*iter);

}

The compiler message I get is

test3.cc: In member function ‘void ExampleWindow::on_rb2_clicked()’:
test3.cc:104:27: error: no match for ‘operator*’ (operand type is ‘Glib::RefPtr<Gtk::ListStore>’)
    gtk_list_store_remove (*liststore1,*iter);

So my question is, I suppose, what is the proper syntax for using gtk_list_store_remove ???

On 8/8/19 3:46 PM, pcr wrote:

I'm trying to learn how to iterate over model rows in a manner similar to the code segment in section 9.3 of the gnome gtkmm tutorial.  Consider me a newbie; the "something" I want to do below is delete/clear/erase a row - really all rows so I can display a new set of rows in response to a user action like changing a radio button.  But I haven't been able to do it. Here is the snippit from section 9.3:

typedef Gtk::TreeModel::Children type_children; //minimise code length.
type_children children = refModel->children();
for(type_children::iterator iter = children.begin();
    iter != children.end(); ++iter)
{
  Gtk::TreeModel::Row row = *iter;
  //Do something with the row - see above for set/get.
}

I'm also confused by the following comment I found on line; I don't see how this can work with the above code either. 

iterator Gtk::TreeStore:erase(const iterator& iter)
	Returns an iterator to the next row or end() if there is none"

I hope you can help me .  Thanks, PCR


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: changing the content of a model/view/store at run time

Gtkmm mailing list
also, check whether removing invalidates iterators, in which case you cant just iterate naively like that but would need to get a valid iterator back from the erase call, as iirc someone already indicated earlier

On Sat, 10 Aug 2019, 16:30 Daniel Boles, <[hidden email]> wrote:
if you think you have to use c api, you're almost certainlt doing it wrong. why? does the c++ wrapper not provide remove() ?

On Sat, 10 Aug 2019, 16:28 pcr, <[hidden email]> wrote:

I have changed from a tree store to a list store now, and I have working code, except for the last line in this call back used when a radio button is clicked in order to erase the list store and replace it with another at run time:

  void ExampleWindow::on_rb2_clicked()
 {
    std::cout << "rb2 clicked" << std::endl;

    typedef Gtk::TreeModel::Children type_children;
    type_children children = liststore1->children();
    type_children::iterator iter;
    for(iter=children.begin(); iter!=children.end(); ++iter)
               gtk_list_store_remove (*liststore1,*iter);

}

The compiler message I get is

test3.cc: In member function ‘void ExampleWindow::on_rb2_clicked()’:
test3.cc:104:27: error: no match for ‘operator*’ (operand type is ‘Glib::RefPtr<Gtk::ListStore>’)
    gtk_list_store_remove (*liststore1,*iter);

So my question is, I suppose, what is the proper syntax for using gtk_list_store_remove ???

On 8/8/19 3:46 PM, pcr wrote:

I'm trying to learn how to iterate over model rows in a manner similar to the code segment in section 9.3 of the gnome gtkmm tutorial.  Consider me a newbie; the "something" I want to do below is delete/clear/erase a row - really all rows so I can display a new set of rows in response to a user action like changing a radio button.  But I haven't been able to do it. Here is the snippit from section 9.3:

typedef Gtk::TreeModel::Children type_children; //minimise code length.
type_children children = refModel->children();
for(type_children::iterator iter = children.begin();
    iter != children.end(); ++iter)
{
  Gtk::TreeModel::Row row = *iter;
  //Do something with the row - see above for set/get.
}

I'm also confused by the following comment I found on line; I don't see how this can work with the above code either. 

iterator Gtk::TreeStore:erase(const iterator& iter)
	Returns an iterator to the next row or end() if there is none"

I hope you can help me .  Thanks, PCR


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: changing the content of a model/view/store at run time

Gtkmm mailing list
In reply to this post by pcr
As indicated by the error message, liststore1 is a RefPtr to a ListStore
model, which is a C++ entity that

     1) cannot be used as an argument to a gtk+ function, and

     2) cannot be dereferenced with the * operator.

At a more fundamental level, this approach is unnecessarily complicated.
The entire contents of the function can be replace with a single statement:

     liststore1->clear ();


On 8/10/19 8:20 AM, pcr wrote:

>
> I have changed from a tree store to a list store now, and I have
> working code, except for the last line in this call back used when a
> radio button is clicked in order to erase the list store and replace
> it with another at run time:
>
>   void ExampleWindow::on_rb2_clicked()
>  {
>     std::cout << "rb2 clicked" << std::endl;
>
>     typedef Gtk::TreeModel::Children type_children;
>     type_children children = liststore1->children();
>     type_children::iterator iter;
>     for(iter=children.begin(); iter!=children.end(); ++iter)
>                gtk_list_store_remove (*liststore1,*iter);
>
> }
>
> The compiler message I get is
>
> test3.cc: In member function ‘void ExampleWindow::on_rb2_clicked()’:
> test3.cc:104:27: error: no match for ‘operator*’ (operand type is
> ‘Glib::RefPtr<Gtk::ListStore>’)
>     gtk_list_store_remove (*liststore1,*iter);
>
> So my question is, I suppose, what is the proper syntax for using
> gtk_list_store_remove ???
>
> On 8/8/19 3:46 PM, pcr wrote:
>>
>> I'm trying to learn how to iterate over model rows in a manner
>> similar to the code segment in section 9.3 of the gnome gtkmm
>> tutorial.  Consider me a newbie; the "something" I want to do below
>> is delete/clear/erase a row - really all rows so I can display a new
>> set of rows in response to a user action like changing a radio
>> button.  But I haven't been able to do it. Here is the snippit from
>> section 9.3:
>>
>> typedef Gtk::TreeModel::Children type_children; //minimise code length.
>> type_children children = refModel->children();
>> for(type_children::iterator iter = children.begin();
>>      iter != children.end(); ++iter)
>> {
>>    Gtk::TreeModel::Row row = *iter;
>>    //Do something with the row - see above for set/get.
>> }
>>
>> *I'm also confused by the following comment I found on line; I don't
>> see how this can work with the above code either. ***
>> iterator Gtk::TreeStore:erase(const iterator& iter)
>> Returns an iterator to the next row or end() if there is none"
>>
>> I hope you can help me .  Thanks, PCR
>>
>>
>> _______________________________________________
>> gtkmm-list mailing list
>> [hidden email]
>> https://mail.gnome.org/mailman/listinfo/gtkmm-list
>
> _______________________________________________
> gtkmm-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtkmm-list
--
What was that about a rising tide lifting all boats? What if you don't
have a boat?
    — Eugene Robinson
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
pcr
Reply | Threaded
Open this post in threaded view
|

Re: changing the content of a model/view/store at run time

pcr
A grand "Thank you" to Daniel Boles and Phil Wolff for their help.  I
had been mixing up gtk and gtkmm documentation!  I am attaching the
complete now working code for anyone interested.

On 8/10/19 10:04 AM, Phil Wolff via gtkmm-list wrote:

> As indicated by the error message, liststore1 is a RefPtr to a
> ListStore model, which is a C++ entity that
>
>     1) cannot be used as an argument to a gtk+ function, and
>
>     2) cannot be dereferenced with the * operator.
>
> At a more fundamental level, this approach is unnecessarily
> complicated. The entire contents of the function can be replace with a
> single statement:
>
>     liststore1->clear ();
>
>
> On 8/10/19 8:20 AM, pcr wrote:
>>
>> I have changed from a tree store to a list store now, and I have
>> working code, except for the last line in this call back used when a
>> radio button is clicked in order to erase the list store and replace
>> it with another at run time:
>>
>>   void ExampleWindow::on_rb2_clicked()
>>  {
>>     std::cout << "rb2 clicked" << std::endl;
>>
>>     typedef Gtk::TreeModel::Children type_children;
>>     type_children children = liststore1->children();
>>     type_children::iterator iter;
>>     for(iter=children.begin(); iter!=children.end(); ++iter)
>>                gtk_list_store_remove (*liststore1,*iter);
>>
>> }
>>
>> The compiler message I get is
>>
>> test3.cc: In member function ‘void ExampleWindow::on_rb2_clicked()’:
>> test3.cc:104:27: error: no match for ‘operator*’ (operand type is
>> ‘Glib::RefPtr<Gtk::ListStore>’)
>>     gtk_list_store_remove (*liststore1,*iter);
>>
>> So my question is, I suppose, what is the proper syntax for using
>> gtk_list_store_remove ???
>>
>> On 8/8/19 3:46 PM, pcr wrote:
>>>
>>> I'm trying to learn how to iterate over model rows in a manner
>>> similar to the code segment in section 9.3 of the gnome gtkmm
>>> tutorial.  Consider me a newbie; the "something" I want to do below
>>> is delete/clear/erase a row - really all rows so I can display a new
>>> set of rows in response to a user action like changing a radio
>>> button.  But I haven't been able to do it. Here is the snippit from
>>> section 9.3:
>>>
>>> typedef Gtk::TreeModel::Children type_children; //minimise code length.
>>> type_children children = refModel->children();
>>> for(type_children::iterator iter = children.begin();
>>>      iter != children.end(); ++iter)
>>> {
>>>    Gtk::TreeModel::Row row = *iter;
>>>    //Do something with the row - see above for set/get.
>>> }
>>>
>>> *I'm also confused by the following comment I found on line; I don't
>>> see how this can work with the above code either. ***
>>> iterator Gtk::TreeStore:erase(const iterator& iter)
>>>     Returns an iterator to the next row or end() if there is none"
>>>
>>> I hope you can help me .  Thanks, PCR
>>>
>>>
>>> _______________________________________________
>>> gtkmm-list mailing list
>>> [hidden email]
>>> https://mail.gnome.org/mailman/listinfo/gtkmm-list
>>
>> _______________________________________________
>> gtkmm-list mailing list
>> [hidden email]
>> https://mail.gnome.org/mailman/listinfo/gtkmm-list

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list

test3.cc (3K) Download Attachment