Hello. I have quite a few questions I hope you can find time to answer me.
For the last few weeks, I have been learning GtkD and taking notes. I made it public so you can find them here
I'm stuck with GtkD's MVC.
1) I have this TreeView. But I can't seem to find a way to find a find a TreeModelFilterVisibleFunc as described here
Here's the code:
import gtk.Application : Application;
import gtk.ApplicationWindow : ApplicationWindow;
import gtk.HeaderBar : HeaderBar;
import gtk.ListStore : ListStore;
import gtk.TreeView : TreeView;
import gtkc.gobjecttypes : GType;
import gtk.TreeViewColumn : TreeViewColumn;
import gtk.CellRendererText : CellRendererText;
import gtk.TreeIter : TreeIter;
private class Album {
private:
ListStore model;
TreeView view;
enum COLUMNS {
ARTIST,
SONG
}
static ListStore generateModel() {
return new ListStore([GType.STRING, GType.STRING]);
}
static TreeView generateView() {
auto tv = new TreeView();
auto artistColumn = new TreeViewColumn();
scope (success)
tv.appendColumn(artistColumn);
artistColumn.setTitle("Artist");
auto artistColumnCell = new CellRendererText();
artistColumn.packStart(artistColumnCell, true);
artistColumn.addAttribute(artistColumnCell, "text", COLUMNS.ARTIST);
auto songColumn = new TreeViewColumn();
scope (success)
tv.appendColumn(songColumn);
songColumn.setTitle("Song");
auto songColumnCell = new CellRendererText();
songColumn.packStart(songColumnCell, true);
songColumn.addAttribute(songColumnCell, "text", COLUMNS.SONG);
return tv;
}
public:
this() {
model = generateModel();
view = generateView();
view.setModel(model);
}
void addSong(in string artistName, in string songTitle) {
auto iter = this.model.createIter();
model.setValue(iter, COLUMNS.ARTIST, artistName);
model.setValue(iter, COLUMNS.SONG, songTitle);
}
TreeView getView() {
return this.view;
}
}
class PrimaryWindow : ApplicationWindow {
private:
HeaderBar titleBar;
Album album;
static HeaderBar makeHeaderBar(string title = "GtkD MVC Demo") {
auto hb = new HeaderBar();
hb.setTitle(title);
hb.setShowCloseButton(true);
return hb;
}
public:
this(Application app) {
super(app);
setDefaultSize(480, 360);
titleBar = makeHeaderBar;
setTitlebar(titleBar);
album = new Album();
album.addSong("Quails", "High Hopes");
album.addSong("Linkin Park", "Leave Out All The Rest");
album.addSong("Linkin Park", "Somewhere I belong");
album.addSong("ANML", "Obsession");
album.addSong("Eminem", "The Ringer");
album.addSong("Eminem", "Lucky You");
album.addSong("Eminem", "Space Bound");
album.addSong("Johnny Cash", "Hurt");
album.addSong("Johnny Cash", "Ring of Fire");
album.addSong("Owl City", "Fireflies");
album.addSong("Owl City", "On the Wing");
add(album.getView());
}
}
int main(string[] args) {
import gio.Application : GioApp = Application;
import gtkc.gtktypes : GApplicationFlags;
auto app = new Application("org.gitlab.gtkdnotes", GApplicationFlags.FLAGS_NONE);
app.addOnActivate(delegate void(GioApp _) {
auto pw = new PrimaryWindow(app);
pw.showAll();
});
return app.run(args);
}
2) How can I add a value to the model with a TreePath (AND a TreePath) instead of a TreeIter inside method addSong()?
3) How can I iterate and check for values in a model? For example, I want to find a TreeIter that points to a row that has "Eminem" in the column 0, and "Lucky You" in column 2 in the model?
I will be very happy if you find time to give me code examples, I know it's a bit too much to ask but the documentation isn't helping. Thank you.