X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainlistdialog.cpp;h=a29bc304c34cb822076bcdd175ea2cd755c2b482;hb=c0e076401ee76fd9a5a96ff919a8e7b4d058c51b;hp=0a31d67808c7a72a275fd41136d01c4bc0c87d67;hpb=b261812f040caed52bc3de783e8bcb86b222a9ed;p=r2c2.git diff --git a/source/engineer/trainlistdialog.cpp b/source/engineer/trainlistdialog.cpp index 0a31d67..a29bc30 100644 --- a/source/engineer/trainlistdialog.cpp +++ b/source/engineer/trainlistdialog.cpp @@ -11,19 +11,21 @@ using namespace std; using namespace Msp; using namespace R2C2; -class TrainItem: public GLtk::List::Item +class TrainItem: public GLtk::List::MultiColumnItem { -private: - GLtk::Label address; - GLtk::Label name; - -public: +public: typedef R2C2::Train *ValueType; TrainItem(ValueType); +}; + + +class DetectedLocoItem: public GLtk::List::MultiColumnItem +{ +public: + typedef const Driver::DetectedLocomotive *ValueType; -private: - virtual void on_style_change(); + DetectedLocoItem(ValueType); }; @@ -38,22 +40,47 @@ TrainListDialog::TrainListDialog(Engineer &e): lst_trains->set_data(trains); lst_trains->set_item_type(); + lst_imported = dynamic_cast(get_item(widgets, "lst_imported")); + lst_imported->set_data(detected_locos); + lst_imported->set_item_type(); + + dynamic_cast(get_item(widgets, "tgl_trains"))->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainListDialog::tab_toggled), lst_trains)); + dynamic_cast(get_item(widgets, "tgl_import"))->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainListDialog::tab_toggled), lst_imported)); + dynamic_cast(get_item(widgets, "btn_new"))->signal_clicked.connect(sigc::mem_fun(this, &TrainListDialog::new_clicked)); dynamic_cast(get_item(widgets, "btn_show"))->signal_clicked.connect(sigc::mem_fun(this, &TrainListDialog::show_clicked)); 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)))); + } + + if(layout.has_driver()) + { + Driver &driver = layout.get_driver(); + driver.signal_locomotive_detected.connect(sigc::mem_fun(this, &TrainListDialog::locomotive_detected)); + driver.signal_locomotive_gone.connect(sigc::mem_fun(this, &TrainListDialog::locomotive_gone)); + + unsigned i = 0; + while(const Driver::DetectedLocomotive *loco = driver.enumerate_detected_locos(i++)) + detected_locos.append(loco); + } + 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() { - GLtk::Container *root = parent; - while(root->get_parent()) - root = root->get_parent(); - NewTrainDialog *dlg = new NewTrainDialog(engineer); - root->add(*dlg); + if(lst_imported->is_visible()) + { + int selected = lst_imported->get_selected_index(); + if(selected>=0) + dlg->prefill(*detected_locos.get(selected)); + } + find_ancestor()->add(*dlg); dlg->autosize(); } @@ -62,37 +89,64 @@ void TrainListDialog::show_clicked() int index = lst_trains->get_selected_index(); if(index>=0) { - GLtk::Container *root = parent; - while(root->get_parent()) - root = root->get_parent(); - TrainDialog *dlg = new TrainDialog(engineer, *trains.get(index)); - root->add(*dlg); - dlg->autosize(); + find_ancestor()->add(*dlg); } } +void TrainListDialog::tab_toggled(bool value, GLtk::Widget *wdg) +{ + wdg->set_visible(value); +} -TrainItem::TrainItem(ValueType train): - address(lexical_cast(train->get_address())), - name(train->get_name()) +void TrainListDialog::locomotive_detected(const Driver::DetectedLocomotive &loco) { - add(address); - add(name); + detected_locos.append(&loco); } -void TrainItem::on_style_change() +void TrainListDialog::locomotive_gone(const Driver::DetectedLocomotive &loco) { - if(!style) - return; + int index = detected_locos.find(&loco); + if(index>=0) + detected_locos.remove(index); +} - address.autosize(); - name.autosize(); +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)))); +} - if(const GLtk::Part *part = style->get_part("children")) - { - const GLtk::Sides &margin = part->get_margin(); - address.set_position(margin.left, margin.bottom); - name.set_position(margin.left+30, margin.bottom); - } +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) +{ + add(*new GLtk::Label(train->get_protocol())); + add(*new GLtk::Label(lexical_cast(train->get_address()))); + add(*new GLtk::Label(train->get_name())); +} + + +DetectedLocoItem::DetectedLocoItem(ValueType loco) +{ + add(*new GLtk::Label(loco->protocol)); + add(*new GLtk::Label(lexical_cast(loco->address))); + add(*new GLtk::Label(loco->name)); }