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