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