COIN-OR::LEMON - Graph Library

source: glemon-0.x/mapselector.h @ 172:fc1e478697d3

Last change on this file since 172:fc1e478697d3 was 172:fc1e478697d3, checked in by Hegyi Péter, 18 years ago

Currently visualized map can be saved and loaded from file.

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