As a follow up to Yesterday’s post on Linux development with C++, GTK+ and SQL Server vNext. Today’s post is about GtkTreeView and how we can use it to display tabular data, as we’re used to do with a DataGrid in .NET, but first it’s worthy to start with an introduction to GTK+.
GTK+ is a cross-platform widget toolkit that allows developers to create graphical user interfaces. It’s been around for a few years now, and it supports a variety of languages; this is long before some companies “introduced” the concept of separating code from visual representation thus decoupling the solution in a more flexible and manageable way, therefore UI can be put together by UX people while developers use their preferred language, Python being one of the most popular but in my personal case I use C++. Every GTK+ widget inherits from GtkWidget thus it provides an easy to use and succinct abstraction level that enables developers to write generic code. In other words, same Glade file that describes the user interface can easily implement code written in different languages, some screenshots of GTK+ in action can be found here on the project’s website.
The snippets above are to create the view, better said to format the GtkTreeView that exists in the Controls collection of the window (std::map<std::string, GtkWidget*>), also to populate the model (GtkTreeModel) and to handle any user selection that’s reflected in the other data entry widgets. All of this has been handcrafted unlike the way is done with Windows Forms or WPF, for instance where databinding is sometimes taken for granted.
At this moment in time, you must be wondering when and where the application calls the database and also the status bar how it is updated, both are depicted in snippets below