- Mantain expanded state of TreeView rows while History updates.

It isn't elegant, but it's the best I can come up with in 10 minutes before
having dinner.


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@944 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-26 18:42:10 +00:00
parent 231662825d
commit aa608a1cc2
2 changed files with 56 additions and 27 deletions

View File

@ -19,7 +19,6 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "schedulables_tree_widget.hh"
#include "templates/sequences.tcc"
#include "backend/history.hh"
#include "backend/simulation.hh"
#include "backend/process.hh"
@ -27,6 +26,8 @@
#include "backend/resource.hh"
#include "add_request_dialog.hh"
#include "sequences.tcc"
#include <cassert>
#include <iostream>
#include <sstream>
@ -262,6 +263,15 @@ SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
return false;
}
void
SchedulablesTreeWidget::_update_expanded_vector(Gtk::TreeView* treeview,
const Gtk::TreeModel::Path& path)
{
_expanded_rows.push_back(path.to_string());
}
void
SchedulablesTreeWidget::update(const History& history)
{
@ -272,8 +282,13 @@ SchedulablesTreeWidget::update(const History& history)
const Environment::Processes& processes =
Simulation::get_instance().get_history().get_last_environment().get_processes();
// Save expanded rows (FIXME: find a better way?)
map_expanded_rows(sigc::mem_fun(*this, &SchedulablesTreeWidget::_update_expanded_vector));
_model->clear();
for(Iseq<ProcessIt> pit = const_iseq(processes); pit; ++pit)
{
Process& p = *(*pit);
@ -300,36 +315,44 @@ SchedulablesTreeWidget::update(const History& history)
for(unsigned int ri = 0; ri < requests.size(); ++ri)
{
Request& r = *requests[ri];
TreeModel::Row rrow = *(_model->append(trow.children()));
std::ostringstream oss;
oss << "request " << ri + 1;
rrow[_main_column] = oss.str();
rrow[_types_column] = htype_request;
Request& r = *requests[ri];
TreeModel::Row rrow = *(_model->append(trow.children()));
std::ostringstream oss;
oss << "request " << ri + 1;
rrow[_main_column] = oss.str();
rrow[_types_column] = htype_request;
rrow[_handles_column] = &r;
vector<SubRequest*> subrequests = r.get_subrequests();
for(Iseq<vector<SubRequest*>::iterator> srit = iseq(subrequests); srit; ++srit)
{
SubRequest& sr = *(*srit);
TreeModel::Row srrow = *(_model->append(rrow.children()));
// we are sure the key is valid, or no?
const Environment& env = history.get_last_environment();
Resource& res = *(env.get_resources().find(sr.get_resource_key())->second);
srrow[_main_column] = res.get_name();
srrow[_types_column] = htype_subrequest;
srrow[_handles_column] = &sr;
}
vector<SubRequest*> subrequests = r.get_subrequests();
for(Iseq<vector<SubRequest*>::iterator> srit = iseq(subrequests); srit; ++srit)
{
SubRequest& sr = *(*srit);
TreeModel::Row srrow = *(_model->append(rrow.children()));
// we are sure the key is valid, or no?
const Environment& env = history.get_last_environment();
Resource& res = *(env.get_resources().find(sr.get_resource_key())->second);
srrow[_main_column] = res.get_name();
srrow[_types_column] = htype_subrequest;
srrow[_handles_column] = &sr;
}
}
}
}
// Restore expanded rows
for(vector<Glib::ustring>::iterator it = _expanded_rows.begin(); it != _expanded_rows.end(); ++it)
expand_row(Gtk::TreeModel::Path(*it), false);
// We can clear it now, since until next update we won't need it.
_expanded_rows.clear();
}
void

View File

@ -40,6 +40,8 @@ namespace sgpem
#include "backend/history_observer.hh"
#include <vector>
namespace sgpem
{
/**
@ -118,6 +120,10 @@ namespace sgpem
Gtk::Dialog* _add_thread_dialog;
AddRequestDialog* _add_request_dialog;
CellRendererTextMarkup _cell_renderer;
void _update_expanded_vector(Gtk::TreeView* tree_view, const Gtk::TreeModel::Path& path);
std::vector<Glib::ustring> _expanded_rows;
};
} //~ namespace sgpem