mapselector.h
author alpar
Tue, 07 Nov 2006 21:27:28 +0000
changeset 180 911c6ba0e3c8
parent 172 fc1e478697d3
child 194 6b2b718420eb
permissions -rw-r--r--
Bugfix + polishing
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #ifndef MAPSELECTOR_H
    20 #define MAPSELECTOR_H
    21 
    22 class MapSelector;
    23 
    24 #include <all_include.h>
    25 #include <map_win.h>
    26 #include <libgnomecanvasmm.h>
    27 #include <libgnomecanvasmm/polygon.h>
    28 
    29 ///A widget by which node and edgemaps can be selected, deselected and created.
    30 
    31 ///During the usage of \ref glemon we have to select
    32 ///maps several times. We also need some aid-function
    33 ///like new map creation and deselecting previously
    34 ///selected map. Instead of writing a the mapselection
    35 ///at all occurences we can use this widget by connecting
    36 ///its signals to the correct place.
    37 class MapSelector : public Gtk::HBox
    38 {
    39  protected:
    40   ///This signal indicates that the selection has been changed by user.
    41   sigc::signal<void, std::string> signal_cbt;
    42 
    43   ///Signal that indicates that user wants to create a new map.
    44   sigc::signal<void, bool> signal_newmapwin;
    45 
    46   ///If this is true, beyond the mapnames a 'Default' selection is available as well.
    47 
    48   ///For example \ref MapWin needs 'Default' option as well. In this case no map
    49   ///will be visualized by the appropriate property.
    50   ///But \ref AlgoWin do not need 'Default' option, because if no map is selected,
    51   ///no algorithm can be run.
    52   ///Its value is got and set in contructor.
    53   bool def;
    54 
    55   ///Are the names of edgemaps or nodemaps stored here.
    56   bool itisedge;
    57 
    58   ///Shows whether 'Default' option is selected or not.
    59   bool default_state;
    60 
    61   ///It is true when the new button had been pressed but the new map has not been registrated yet.
    62 
    63   ///Before signal of \ref NewMapWin request is emitted by the \ref MapSelector
    64   ///this variable is set to true. When the new map
    65   ///is done, it will be registrated in all existing \ref MapSelector 
    66   ///by \ref append_text function. That function checks
    67   ///whether this variable is true. If it is true that means
    68   ///that this \ref MapSelector has requested \ref NewMapWin.
    69   ///Therefore it set itself to the recently created map.
    70   ///After that \ref set_new_map is set again false, not to
    71   ///set maps active if \ref MapSelector piece is not the requester.
    72   bool set_new_map;
    73 
    74   ///The widget that holds the names of maps.
    75 
    76   ///It can be rolled down
    77   ///Names in it are selectable.
    78   Gtk::ComboBoxText cbt;
    79 
    80   std::vector<std::string> cbt_content;
    81 
    82   ///New button.
    83 
    84   ///By pressing it
    85   ///\ref NewMapWin wilol pop-up
    86   Gtk::Button * newbut;
    87 
    88   ///Reset button.
    89 
    90   ///If pressed \ref cbt will
    91   ///set to 'Default' option.
    92   ///
    93   ///It is visible only if \ref def is true.
    94   Gtk::Button * defbut;
    95 
    96   ///Container in which GUI elements are packed.
    97   Gtk::HBox hbox;
    98 
    99   ///Shows purpose of \ref MapSelector piece.
   100   Gtk::Label * label;
   101 
   102  public:
   103 
   104   ///Constructor of \ref MapSelector
   105 
   106   ///Creates the layout and binds signal to the correct place.
   107   ///\param optionlist list of names to place in \ref cbt
   108   ///\param act preselected option
   109   ///\param purpose text of label indicating purpose of \ref MapStorage
   110   ///\param itisedge do \ref MapSelector contains edgemap names or nodemapnames.
   111   ///\param def do we need 'Default' option. See \ref def.
   112   MapSelector(std::vector<std::string> optionlist, std::string act, std::string purpose, bool itisedge, bool def=true);
   113 
   114   ///Returns signal emitted if the user has changed the selection. (\ref signal_cbt)
   115   sigc::signal<void, std::string> signal_cbt_ch();
   116 
   117   ///Returns signal emitted if the user has pressed New button (\ref newbut) (\ref signal_newmapwin)
   118   sigc::signal<void, bool> signal_newmapwin_needed();
   119 
   120   ///Maintain \ref cbt.
   121 
   122   ///Fills in \ref cbt with names, taking
   123   ///into account that the previously selected option
   124   ///has to be set back after the operation.
   125   void update_list( std::vector<std::string> );
   126 
   127   ///Handles changement in \ref cbt.
   128 
   129   ///In default case it emits a signal with the selected option.
   130   ///But if 'Default' option is selected, it resets the \ref MapSelector
   131   virtual void comboChanged();
   132 
   133   ///Requests a \ref NewMapWin
   134 
   135   ///See \ref set_new_map.
   136   ///First it sets \ref set_new_map true to be identified
   137   ///at registration of new map that
   138   ///it has sent the \ref signal_newmapwin, therefore it
   139   ///has to set \ref cbt to that option.
   140   virtual void new_but_pressed();
   141 
   142   ///If called, 'Default' option is selected, that means unselection of any maps.
   143 
   144   ///Practically this means that if this is called,
   145   ///properties of graph will set to default state.
   146   ///The function achieves this by emitting appropriately
   147   ///parametrized signal_cbt.
   148   virtual void reset();
   149 
   150   ///Returns the currently selected option.
   151   Glib::ustring get_active_text();
   152 
   153   ///Sets the parameter active in \ref cbt.
   154 
   155   ///\param new_value the
   156   ///new value to be set in \ref cbt.
   157   void set_active_text(Glib::ustring new_value);
   158 
   159   ///Sets the parameter active in \ref cbt.
   160   ///\param index the
   161   ///index of row to be set in \ref cbt.
   162   void set_active(int index){cbt.set_active(index);};
   163 
   164   ///Clear all options from \ref cbt.
   165   void clear(){cbt.clear();};
   166 
   167   ///Appends a new option to the existing ones in \ref cbt.
   168 
   169   ///If \ref set_new_map is true, the
   170   ///\ref MapSelector has requested the opened \ref NewMapWin,
   171   ///from that the option to append is coming. In this case
   172   ///this function  will set \ref cbt to the new option.
   173   ///\param new_option new option to append
   174   void append_text(Glib::ustring new_option);
   175 };
   176 #endif //MAPSELECTOR_H