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