gui/mapselector.cc
author hegyi
Fri, 21 Oct 2005 13:32:12 +0000
changeset 1733 5e0d97823ba2
parent 1731 616bc933c2bc
child 1737 dc821d2668c1
permissions -rw-r--r--
MapSelector widget is able to pop up NewMap window. At the moment I hope MapSelector widget is done.
     1 #include "mapselector.h"
     2 
     3 MapSelector::MapSelector(GraphDisplayerCanvas & grdispc, MapStorage & mapst, NewMapWin & newmapw, int identifier, bool edge):gdc(grdispc),ms(mapst),nmw(newmapw),id(identifier),itisedge(edge),default_state(true),node_to_update(INVALID),edge_to_update(INVALID)
     4 {
     5   update_list();
     6 
     7   cbt.set_active(0);
     8 
     9   //binding signal to the actual entry
    10   cbt.signal_changed().connect
    11     (
    12      sigc::mem_fun((*this), &MapSelector::comboChanged),
    13      false
    14      );
    15   
    16   if(itisedge)
    17     {
    18       label=new Gtk::Label(edge_property_strings[id]);
    19     }
    20   else
    21     {
    22       label=new Gtk::Label(node_property_strings[id]);
    23     }
    24 
    25   label->set_width_chars(longest_property_string_length);
    26 
    27   defbut=new Gtk::Button();
    28   defbut->set_label("Reset");
    29 
    30   defbut->signal_pressed().connect
    31     (
    32      sigc::mem_fun(*this, &MapSelector::reset)
    33      );
    34 
    35   newbut=new Gtk::Button(Gtk::Stock::NEW);
    36 
    37   newbut->signal_pressed().connect
    38     (
    39      sigc::mem_fun(nmw, &NewMapWin::show)
    40      );
    41 
    42   add(*label);
    43 
    44   add(cbt);
    45 
    46   add(*defbut);
    47   add(*newbut);
    48 }
    49 
    50 void MapSelector::update_list()
    51 {
    52   cbt.clear();
    53   if(itisedge)
    54     {
    55       std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
    56       for(;emsi!=ms.endOfEdgeMaps();emsi++)
    57 	{
    58 	  cbt.append_text(emsi->first);
    59 	}
    60     }
    61   else
    62     {
    63       std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
    64       for(;emsi!=ms.endOfNodeMaps();emsi++)
    65 	{
    66 	  cbt.append_text(emsi->first);
    67 	}
    68     }
    69   cbt.prepend_text("Default values");
    70 }
    71 
    72 void MapSelector::comboChanged()
    73 {
    74   if(cbt.get_active_row_number()!=0)
    75     {
    76       default_state=false;
    77       Glib::ustring mapname = cbt.get_active_text();
    78       if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
    79 	{
    80 	  if(itisedge)
    81 	    {
    82 	      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) )
    83 		{
    84 		  Edge edge=edge_to_update;
    85 		  switch(id)
    86 		    {
    87 		    case E_WIDTH:
    88 		      gdc.changeEdgeWidth(mapname, edge);
    89 		      break;
    90 		    case E_COLOR:
    91 		      gdc.changeEdgeColor(mapname, edge);
    92 		      break;
    93 		    case E_TEXT:
    94 		      gdc.changeEdgeText(mapname, edge);
    95 		      break;
    96 		    default:
    97 		      std::cerr<<"Error\n";
    98 		    }
    99 		}
   100 	    }
   101 	  else
   102 	    {
   103 	      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) )
   104 		{
   105 		  Node node=node_to_update;
   106 		  switch(id)
   107 		    {
   108 		    case N_RADIUS:
   109 		      gdc.changeNodeRadius(mapname, node);
   110 		      break;
   111 		    case N_COLOR:
   112 		      gdc.changeNodeColor(mapname, node);
   113 		      break;
   114 		    case N_TEXT:
   115 		      gdc.changeNodeText(mapname, node);
   116 		      break;
   117 		    default:
   118 		      std::cerr<<"Error\n";
   119 		    }
   120 		}
   121 	    }
   122 	}
   123     }
   124   else if((!default_state)&&(cbt.get_active_row_number()==0))
   125     {
   126       reset();
   127     }
   128 }
   129 
   130 void MapSelector::reset()
   131 {
   132   default_state=true;
   133   cbt.set_active(0);
   134 
   135   if(itisedge)
   136     {
   137       Edge edge=edge_to_update;
   138       switch(id)
   139 	{
   140 	case E_WIDTH:
   141 	  gdc.resetEdgeWidth(edge);
   142 	  break;
   143 	case E_COLOR:
   144 	  gdc.resetEdgeColor(edge);
   145 	  break;
   146 	case E_TEXT:
   147 	  gdc.resetEdgeText(edge);
   148 	  break;
   149 	default:
   150 	  std::cerr<<"Error\n";
   151 	}
   152     }
   153   else
   154     {
   155       Node node=node_to_update;	
   156       switch(id)
   157 	{
   158 	case N_RADIUS:
   159 	  gdc.resetNodeRadius(node);
   160 	  break;
   161 	case N_COLOR:
   162 	  gdc.resetNodeColor(node);
   163 	  break;
   164 	case N_TEXT:
   165 	  gdc.resetNodeText(node);
   166 	  break;
   167 	default:
   168 	  std::cerr<<"Error\n";
   169 	}
   170     }
   171 }
   172 
   173 void MapSelector::update(Node node)
   174 {
   175   node_to_update=node;
   176   if(default_state)
   177     {
   178       reset();
   179     }
   180   else
   181     {
   182       comboChanged();
   183     }
   184   node_to_update=INVALID;
   185 }
   186 
   187 void MapSelector::update(Edge edge)
   188 {
   189   edge_to_update=edge;
   190   if(default_state)
   191     {
   192       reset();
   193     }
   194   else
   195     {
   196       comboChanged();
   197     }
   198   edge_to_update=INVALID;
   199 }
   200 
   201 Glib::ustring MapSelector::get_active_text()
   202 {
   203   return cbt.get_active_text();
   204 }
   205 
   206 void MapSelector::set_active_text(Glib::ustring text)
   207 {
   208   cbt.set_active_text(text);
   209 }
   210 
   211 void MapSelector::append_text(Glib::ustring text)
   212 {
   213   cbt.append_text(text);
   214 }