From: Mikko Rasa Date: Wed, 6 Nov 2013 12:59:02 +0000 (+0200) Subject: Keep the train list dialog up to date whem trains are added or removed X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b0c84ffb369d595b1b97846d6457500643f1e9ed;p=r2c2.git Keep the train list dialog up to date whem trains are added or removed --- diff --git a/source/engineer/trainlistdialog.cpp b/source/engineer/trainlistdialog.cpp index 5d0c9fe..ce1bcb8 100644 --- a/source/engineer/trainlistdialog.cpp +++ b/source/engineer/trainlistdialog.cpp @@ -43,7 +43,13 @@ TrainListDialog::TrainListDialog(Engineer &e): const map <rains = layout.get_trains(); for(map::const_iterator i=ltrains.begin(); i!=ltrains.end(); ++i) + { trains.append(i->second); + i->second->signal_name_changed.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &TrainListDialog::train_name_changed), sigc::ref(*i->second)))); + } + + layout.signal_train_added.connect(sigc::mem_fun(this, &TrainListDialog::train_added)); + layout.signal_train_removed.connect(sigc::mem_fun(this, &TrainListDialog::train_removed)); } void TrainListDialog::new_clicked() @@ -64,6 +70,30 @@ void TrainListDialog::show_clicked() } } +void TrainListDialog::train_added(Train &train) +{ + unsigned n_items = trains.size(); + unsigned i; + for(i=0; iget_address()>train.get_address()) + break; + trains.insert(i, &train); + + train.signal_name_changed.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &TrainListDialog::train_name_changed), sigc::ref(train)))); +} + +void TrainListDialog::train_removed(Train &train) +{ + int i = trains.find(&train); + if(i>=0) + trains.remove(i); +} + +void TrainListDialog::train_name_changed(Train &train) +{ + trains.refresh(&train); +} + TrainItem::TrainItem(ValueType train): address(lexical_cast(train->get_address())), diff --git a/source/engineer/trainlistdialog.h b/source/engineer/trainlistdialog.h index c12bcd4..5757c73 100644 --- a/source/engineer/trainlistdialog.h +++ b/source/engineer/trainlistdialog.h @@ -1,6 +1,7 @@ #ifndef TRAINLISTDIALOG_H_ #define TRAINLISTDIALOG_H_ +#include #include #include #include @@ -8,7 +9,7 @@ class Engineer; -class TrainListDialog: public Msp::GLtk::Dialog +class TrainListDialog: public Msp::GLtk::Dialog, public sigc::trackable { private: Engineer &engineer; @@ -22,6 +23,9 @@ public: private: void new_clicked(); void show_clicked(); + void train_added(R2C2::Train &); + void train_removed(R2C2::Train &); + void train_name_changed(R2C2::Train &); }; #endif