]> git.tdb.fi Git - r2c2.git/commitdiff
Allow zones with no qualifier or no number
authorMikko Rasa <tdb@tdb.fi>
Thu, 26 Mar 2015 20:09:05 +0000 (22:09 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 26 Mar 2015 20:09:05 +0000 (22:09 +0200)
source/designer/zoneproperties.cpp
source/libr2c2/timetable.cpp
source/libr2c2/timetable.h
source/libr2c2/zone.cpp

index b1380c5d25f779de3ee627ea4225c2843995ae17..5f971b920a1596c37a41e854b29cb1859e3969bf 100644 (file)
@@ -44,20 +44,24 @@ ZoneProperties::ZoneProperties(Zone &z):
 
                add(*(drp_qualifier = new GLtk::Dropdown));
                GLtk::ListDataStore<string> &data = dynamic_cast<GLtk::ListDataStore<string> &>(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<string>(zone.get_number()))));
+               unsigned n = zone.get_number();
+               add(*(ent_number = new GLtk::Entry(n ? lexical_cast<string>(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<unsigned>(ent_number->get_text());
+
+               unsigned number = 0;
+               string num_str = ent_number->get_text();
+               if(!num_str.empty())
+                       number = lexical_cast<unsigned>(ent_number->get_text());
+
                zone.set_name(ent_group->get_text(), qualifier, number);
 
                sel = drp_up_direction->get_selected_index();
index b94cbf08fcfc37ad9d3485aeaf78f1ffe76ec615..5fa36395825d0afdb6dfb92df83e76f97d3cd6cb 100644 (file)
@@ -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);
 }
index 17a418ebab2b7c4da358a7a0e5fd78623b67936a..3d7622aeb918c8ac35462df46e28cdc105548964 100644 (file)
@@ -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;
index e2a5177ba96e0cf97af7eed450189b1ef0349ff5..eb5d102b8414570ff6d01578b04994d675701205 100644 (file)
@@ -215,7 +215,11 @@ void Zone::save(list<DataFile::Statement> &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;
 }