From: Mikko Rasa Date: Fri, 3 Apr 2015 22:40:03 +0000 (+0300) Subject: Some refactoring in preparation for UI persistence X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9e96d36a21c24befc88c7bf9c1014c22169e3a6a;p=r2c2.git Some refactoring in preparation for UI persistence --- diff --git a/source/engineer/departuresdialog.cpp b/source/engineer/departuresdialog.cpp index e1f99a3..a1a3112 100644 --- a/source/engineer/departuresdialog.cpp +++ b/source/engineer/departuresdialog.cpp @@ -47,9 +47,13 @@ DeparturesDialog::DeparturesDialog(const Layout &l, const string &group): } } -void DeparturesDialog::group_selected(unsigned index) +void DeparturesDialog::set_group(const string &group) { - const string &group = groups.get(index); + int index = groups.find(group); + if(index<0) + throw key_error(group); + drp_groups->set_selected_index(index); + lbl_title->set_text("Departures from "+group); for(vector::iterator i=rows.begin(); i!=rows.end(); ++i) @@ -63,6 +67,11 @@ void DeparturesDialog::group_selected(unsigned index) update_rows(); } +void DeparturesDialog::group_selected(unsigned index) +{ + set_group(groups.get(index)); +} + void DeparturesDialog::update_rows() { const list &deps = departures->get_departures(); diff --git a/source/engineer/departuresdialog.h b/source/engineer/departuresdialog.h index 098fab8..3b7b2ce 100644 --- a/source/engineer/departuresdialog.h +++ b/source/engineer/departuresdialog.h @@ -31,6 +31,8 @@ private: public: DeparturesDialog(const R2C2::Layout &, const std::string & = std::string()); + void set_group(const std::string &); + private: void group_selected(unsigned); void update_rows(); diff --git a/source/engineer/traindialog.cpp b/source/engineer/traindialog.cpp index 432f3dd..6aa469a 100644 --- a/source/engineer/traindialog.cpp +++ b/source/engineer/traindialog.cpp @@ -134,8 +134,13 @@ void TrainDialog::ui_forward_toggled(bool value) void TrainDialog::expand_clicked() { - pnl_expander->set_visible(!pnl_expander->is_visible()); - btn_expand->set_style(pnl_expander->is_visible() ? "arrow_up" : "arrow_down"); + set_expanded(!pnl_expander->is_visible()); +} + +void TrainDialog::set_expanded(bool e) +{ + pnl_expander->set_visible(e); + btn_expand->set_style(e ? "arrow_up" : "arrow_down"); signal_autosize_changed.emit(); find_ancestor()->get_layout()->update(); } diff --git a/source/engineer/traindialog.h b/source/engineer/traindialog.h index 545c3b0..3d6d143 100644 --- a/source/engineer/traindialog.h +++ b/source/engineer/traindialog.h @@ -37,6 +37,7 @@ private: void update_forward(bool); void ui_forward_toggled(bool); void expand_clicked(); + void set_expanded(bool); void toggle_panel(bool, Msp::GLtk::Panel *); };