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