const map<unsigned, Train *> <rains = layout.get_trains();
for(map<unsigned, Train *>::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()
}
}
+void TrainListDialog::train_added(Train &train)
+{
+ unsigned n_items = trains.size();
+ unsigned i;
+ for(i=0; i<n_items; ++i)
+ if(trains.get(i)->get_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<string>(train->get_address())),
#ifndef TRAINLISTDIALOG_H_
#define TRAINLISTDIALOG_H_
+#include <sigc++/trackable.h>
#include <msp/gltk/dialog.h>
#include <msp/gltk/list.h>
#include <msp/gltk/listdata.h>
class Engineer;
-class TrainListDialog: public Msp::GLtk::Dialog
+class TrainListDialog: public Msp::GLtk::Dialog, public sigc::trackable
{
private:
Engineer &engineer;
private:
void new_clicked();
void show_clicked();
+ void train_added(R2C2::Train &);
+ void train_removed(R2C2::Train &);
+ void train_name_changed(R2C2::Train &);
};
#endif