mapselector.h
author hegyi
Wed, 25 Oct 2006 13:21:24 +0000
changeset 172 fc1e478697d3
parent 123 a3781bff1032
child 174 95872af46fc4
permissions -rw-r--r--
Currently visualized map can be saved and loaded from file.
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@172
    64
  std::vector<std::string> cbt_content;
hegyi@172
    65
hegyi@122
    66
  ///New button.
hegyi@115
    67
hegyi@122
    68
  ///By pressing it
hegyi@122
    69
  ///\ref NewMapWin wilol pop-up
hegyi@122
    70
  Gtk::Button * newbut;
hegyi@122
    71
hegyi@122
    72
  ///Reset button.
hegyi@122
    73
hegyi@122
    74
  ///If pressed \ref cbt will
hegyi@122
    75
  ///set to 'Default' option.
hegyi@122
    76
  ///
hegyi@122
    77
  ///It is visible only if \ref def is true.
hegyi@122
    78
  Gtk::Button * defbut;
hegyi@122
    79
hegyi@122
    80
  ///Container in which GUI elements are packed.
hegyi@115
    81
  Gtk::HBox hbox;
hegyi@115
    82
hegyi@122
    83
  ///Shows purpose of \ref MapSelector piece.
hegyi@115
    84
  Gtk::Label * label;
hegyi@115
    85
hegyi@115
    86
 public:
hegyi@115
    87
hegyi@122
    88
  ///Constructor of \ref MapSelector
hegyi@115
    89
hegyi@122
    90
  ///Creates the layout and binds signal to the correct place.
hegyi@122
    91
  ///\param optionlist list of names to place in \ref cbt
hegyi@122
    92
  ///\param act preselected option
hegyi@122
    93
  ///\param purpose text of label indicating purpose of \ref MapStorage
hegyi@122
    94
  ///\param itisedge do \ref MapSelector contains edgemap names or nodemapnames.
hegyi@122
    95
  ///\param def do we need 'Default' option. See \ref def.
hegyi@122
    96
  MapSelector(std::vector<std::string> optionlist, std::string act, std::string purpose, bool itisedge, bool def=true);
hegyi@122
    97
hegyi@123
    98
  ///Returns signal emitted if the user has changed the selection. (\ref signal_cbt)
hegyi@115
    99
  sigc::signal<void, std::string> signal_cbt_ch();
hegyi@122
   100
hegyi@123
   101
  ///Returns signal emitted if the user has pressed New button (\ref newbut) (\ref signal_newmapwin)
hegyi@115
   102
  sigc::signal<void, bool> signal_newmapwin_needed();
hegyi@115
   103
hegyi@122
   104
  ///Maintain \ref cbt.
hegyi@122
   105
hegyi@122
   106
  ///Fills in \ref cbt with names, taking
hegyi@122
   107
  ///into account that the previously selected option
hegyi@122
   108
  ///has to be set back after the operation.
hegyi@115
   109
  void update_list( std::vector<std::string> );
hegyi@115
   110
hegyi@122
   111
  ///Handles changement in \ref cbt.
hegyi@122
   112
hegyi@122
   113
  ///In default case it emits a signal with the selected option.
hegyi@122
   114
  ///But if 'Default' option is selected, it resets the \ref MapSelector
hegyi@115
   115
  virtual void comboChanged();
hegyi@115
   116
hegyi@122
   117
  ///Requests a \ref NewMapWin
hegyi@122
   118
hegyi@122
   119
  ///See \ref set_new_map.
hegyi@122
   120
  ///First it sets \ref set_new_map true to be identified
hegyi@122
   121
  ///at registration of new map that
hegyi@122
   122
  ///it has sent the \ref signal_newmapwin, therefore it
hegyi@122
   123
  ///has to set \ref cbt to that option.
hegyi@115
   124
  virtual void new_but_pressed();
hegyi@115
   125
hegyi@122
   126
  ///If called, 'Default' option is selected, that means unselection of any maps.
hegyi@122
   127
hegyi@122
   128
  ///Practically this means that if this is called,
hegyi@122
   129
  ///properties of graph will set to default state.
hegyi@122
   130
  ///The function achieves this by emitting appropriately
hegyi@122
   131
  ///parametrized signal_cbt.
hegyi@115
   132
  virtual void reset();
hegyi@115
   133
hegyi@122
   134
  ///Returns the currently selected option.
hegyi@115
   135
  Glib::ustring get_active_text();
hegyi@122
   136
hegyi@122
   137
  ///Sets the parameter active in \ref cbt.
hegyi@122
   138
hegyi@122
   139
  ///\param new_value the
hegyi@122
   140
  ///new value to be set in \ref cbt.
hegyi@122
   141
  void set_active_text(Glib::ustring new_value);
hegyi@122
   142
hegyi@122
   143
  ///Sets the parameter active in \ref cbt.
hegyi@122
   144
  ///\param index the
hegyi@122
   145
  ///index of row to be set in \ref cbt.
hegyi@115
   146
  void set_active(int index){cbt.set_active(index);};
hegyi@122
   147
hegyi@122
   148
  ///Clear all options from \ref cbt.
hegyi@115
   149
  void clear(){cbt.clear();};
hegyi@122
   150
hegyi@122
   151
  ///Appends a new option to the existing ones in \ref cbt.
hegyi@122
   152
hegyi@122
   153
  ///If \ref set_new_map is true, the
hegyi@122
   154
  ///\ref MapSelector has requested the opened \ref NewMapWin,
hegyi@122
   155
  ///from that the option to append is coming. In this case
hegyi@122
   156
  ///this function  will set \ref cbt to the new option.
hegyi@122
   157
  ///\param new_option new option to append
hegyi@122
   158
  void append_text(Glib::ustring new_option);
hegyi@115
   159
};
hegyi@115
   160
#endif //MAPSELECTOR_H