lib: Model should use iter_to_id()

This is cleaner than doing the calculation in several places.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-01-13 19:09:40 -05:00
parent 06853b4f31
commit 315a169136
2 changed files with 7 additions and 13 deletions

View File

@ -35,8 +35,8 @@ public:
void on_row_deleted(unsigned int);
void on_row_changed(unsigned int);
void on_path_selected(const Gtk::TreePath &);
unsigned int iter_to_id(const Gtk::TreeIter &);
unsigned int path_to_id(const Gtk::TreePath &);
unsigned int iter_to_id(const Gtk::TreeIter &) const;
unsigned int path_to_id(const Gtk::TreePath &) const;
};
#endif /* OCARINA_LIB_MODEL_H */

View File

@ -61,12 +61,12 @@ void QueueModel::on_path_selected(const Gtk::TreePath &path)
audio :: play();
}
unsigned int QueueModel :: iter_to_id(const Gtk::TreeIter &iter)
unsigned int QueueModel :: iter_to_id(const Gtk::TreeIter &iter) const
{
return GPOINTER_TO_UINT(iter.gobj()->user_data);
}
unsigned int QueueModel::path_to_id(const Gtk::TreePath &path)
unsigned int QueueModel::path_to_id(const Gtk::TreePath &path) const
{
return queue->operator[](path[0])->index();
}
@ -167,7 +167,6 @@ void QueueModel::get_value_str(Track *track, int column,
void QueueModel::get_value_vfunc(const Gtk::TreeIter &iter, int column,
Glib::ValueBase &value) const
{
unsigned int row;
Track *track;
if (!check_iter_validity(iter))
@ -176,8 +175,7 @@ void QueueModel::get_value_vfunc(const Gtk::TreeIter &iter, int column,
if (column > get_n_columns_vfunc())
return;
row = GPOINTER_TO_UINT(iter.gobj()->user_data);
track = queue->operator[](row);
track = queue->operator[](iter_to_id(iter));
switch (column) {
case 0:
@ -193,15 +191,11 @@ void QueueModel::get_value_vfunc(const Gtk::TreeIter &iter, int column,
bool QueueModel::iter_next_vfunc(const Gtk::TreeIter &iter,
Gtk::TreeIter &iter_next) const
{
unsigned int index;
if (!check_iter_validity(iter)) {
iter_next = Gtk::TreeIter();
return false;
}
index = GPOINTER_TO_UINT(iter.gobj()->user_data);
return iter_nth_root_child_vfunc(++index, iter_next);
return iter_nth_root_child_vfunc(iter_to_id(iter) + 1, iter_next);
}
int QueueModel::iter_n_root_children_vfunc() const
@ -225,7 +219,7 @@ Gtk::TreeModel::Path QueueModel::get_path_vfunc(const Gtk::TreeIter &iter) const
Gtk::TreeModel::Path path;
if (check_iter_validity(iter))
path.push_back(GPOINTER_TO_UINT(iter.gobj()->user_data));
path.push_back(iter_to_id(iter));
return path;
}