From: Mikko Rasa Date: Thu, 26 Mar 2015 20:09:05 +0000 (+0200) Subject: Allow zones with no qualifier or no number X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d990c03a06a494ce3596862ce61e2a5684dea7e1;p=r2c2.git Allow zones with no qualifier or no number --- diff --git a/source/designer/zoneproperties.cpp b/source/designer/zoneproperties.cpp index b1380c5..5f971b9 100644 --- a/source/designer/zoneproperties.cpp +++ b/source/designer/zoneproperties.cpp @@ -44,20 +44,24 @@ ZoneProperties::ZoneProperties(Zone &z): add(*(drp_qualifier = new GLtk::Dropdown)); GLtk::ListDataStore &data = dynamic_cast &>(drp_qualifier->get_data()); - const char *qualifiers[] = { "track", "platform", "siding", 0 }; + const char *qualifiers[] = { "(none)", "track", "platform", "siding", 0 }; for(unsigned i=0; qualifiers[i]; ++i) { data.append(qualifiers[i]); if(zone.get_qualifier()==qualifiers[i]) drp_qualifier->set_selected_index(i); } + + if(zone.get_qualifier().empty()) + drp_qualifier->set_selected_index(0); } { GLtk::Row row(*layout); add(*(lbl1 = new GLtk::Label("Number"))); layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2); - add(*(ent_number = new GLtk::Entry(lexical_cast(zone.get_number())))); + unsigned n = zone.get_number(); + add(*(ent_number = new GLtk::Entry(n ? lexical_cast(zone.get_number()) : string()))); ent_number->set_edit_size(4, 1); } @@ -117,9 +121,14 @@ void ZoneProperties::on_response(int code) { string qualifier; int sel = drp_qualifier->get_selected_index(); - if(sel>=0) + if(sel>0) qualifier = drp_qualifier->get_data().get_string(sel); - unsigned number = lexical_cast(ent_number->get_text()); + + unsigned number = 0; + string num_str = ent_number->get_text(); + if(!num_str.empty()) + number = lexical_cast(ent_number->get_text()); + zone.set_name(ent_group->get_text(), qualifier, number); sel = drp_up_direction->get_selected_index(); diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index b94cbf0..5fa3639 100644 --- a/source/libr2c2/timetable.cpp +++ b/source/libr2c2/timetable.cpp @@ -271,6 +271,7 @@ Timetable::Row::Loader::Loader(Row &r, Layout &l): add("time", &Loader::time); add("type", &Row::type); add("zone", &Loader::zone); + add("zone", &Loader::zone_numbered); } void Timetable::Row::Loader::block(unsigned id) @@ -283,7 +284,12 @@ void Timetable::Row::Loader::time(Time::RawTime t) obj.time = Time::TimeDelta(t); } -void Timetable::Row::Loader::zone(const string &name, unsigned number) +void Timetable::Row::Loader::zone(const string &name) +{ + zone_numbered(name, 0); +} + +void Timetable::Row::Loader::zone_numbered(const string &name, unsigned number) { obj.target = &layout.get_zone(name, number); } diff --git a/source/libr2c2/timetable.h b/source/libr2c2/timetable.h index 17a418e..3d7622a 100644 --- a/source/libr2c2/timetable.h +++ b/source/libr2c2/timetable.h @@ -44,7 +44,8 @@ public: private: void block(unsigned); void time(Msp::Time::RawTime); - void zone(const std::string &, unsigned); + void zone(const std::string &); + void zone_numbered(const std::string &, unsigned); }; RowType type; diff --git a/source/libr2c2/zone.cpp b/source/libr2c2/zone.cpp index e2a5177..eb5d102 100644 --- a/source/libr2c2/zone.cpp +++ b/source/libr2c2/zone.cpp @@ -215,7 +215,11 @@ void Zone::save(list &st) const DataFile::Statement Zone::save_reference() const { - return (DataFile::Statement("zone"), group, number); + DataFile::Statement st("zone"); + st.append(group); + if(number) + st.append(number); + return st; }