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