DUDS
Distributed Update of Data from Something
GenericMenuItem.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2019 Jeff Jackowski
9  */
10 #ifndef GENERICMENUITEM_HPP
11 #define GENERICMENUITEM_HPP
12 
14 #include <boost/signals2/signal.hpp>
15 
16 namespace duds { namespace ui { namespace menu {
17 
23 class GenericMenuItem : public MenuItem {
24 public:
32  typedef boost::signals2::signal<
33  void(
34  MenuView &invokingView,
35  const MenuAccess &access,
36  GenericMenuItem &self
37  )
38  > Signal;
39 private:
52 public:
64  const std::string &label,
66  ) : MenuItem(MenuItemToken(), label, flags) { }
80  const std::string &label,
81  const std::string &description,
83  ) : MenuItem(MenuItemToken(), label, description, flags) { }
99  const std::string &label,
100  const std::string &description,
101  const std::string &value,
103  ) : MenuItem(MenuItemToken(), label, description, value, flags) { }
110  static std::shared_ptr<GenericMenuItem> make(
111  const std::string &label,
113  ) {
114  return std::make_shared<GenericMenuItem>(MenuItemToken(), label, flags);
115  }
124  static std::shared_ptr<GenericMenuItem> make(
125  const std::string &label,
126  const std::string &description,
128  ) {
129  return std::make_shared<GenericMenuItem>(
130  MenuItemToken(),
131  label,
132  description,
133  flags
134  );
135  }
147  static std::shared_ptr<GenericMenuItem> make(
148  const std::string &label,
149  const std::string &description,
150  const std::string &value,
152  ) {
153  return std::make_shared<GenericMenuItem>(
154  MenuItemToken(),
155  label,
156  description,
157  value,
158  flags
159  );
160  }
166  virtual void chose(MenuView &invokingView, const MenuAccess &access);
171  virtual void select(MenuView &invokingView, const MenuAccess &access);
176  virtual void deselect(MenuView &invokingView, const MenuAccess &access);
183  boost::signals2::connection choseConnect(
184  const typename Signal::slot_type &slot,
185  boost::signals2::connect_position at = boost::signals2::at_back
186  ) {
187  return choseSig.connect(slot, at);
188  }
195  boost::signals2::connection choseConnect(
196  const typename Signal::group_type &group,
197  const typename Signal::slot_type &slot,
198  boost::signals2::connect_position at = boost::signals2::at_back
199  ) {
200  return choseSig.connect(group, slot, at);
201  }
208  boost::signals2::connection choseConnectExtended(
209  const typename Signal::extended_slot_type &slot,
210  boost::signals2::connect_position at = boost::signals2::at_back
211  ) {
212  return choseSig.connect_extended(slot, at);
213  }
220  boost::signals2::connection choseConnectExtended(
221  const typename Signal::group_type &group,
222  const typename Signal::extended_slot_type &slot,
223  boost::signals2::connect_position at = boost::signals2::at_back
224  ) {
225  return choseSig.connect_extended(group, slot, at);
226  }
234  const typename Signal::group_type &group
235  ) {
236  choseSig.disconnect(group);
237  }
244  template<typename Slot>
245  void choseDisconnect(const Slot &slotFunc) {
246  choseSig.disconnect(slotFunc);
247  }
254  boost::signals2::connection selectConnect(
255  const typename Signal::slot_type &slot,
256  boost::signals2::connect_position at = boost::signals2::at_back
257  ) {
258  return selSig.connect(slot, at);
259  }
266  boost::signals2::connection selectConnect(
267  const typename Signal::group_type &group,
268  const typename Signal::slot_type &slot,
269  boost::signals2::connect_position at = boost::signals2::at_back
270  ) {
271  return selSig.connect(group, slot, at);
272  }
279  boost::signals2::connection selectConnectExtended(
280  const typename Signal::extended_slot_type &slot,
281  boost::signals2::connect_position at = boost::signals2::at_back
282  ) {
283  return selSig.connect_extended(slot, at);
284  }
291  boost::signals2::connection selectConnectExtended(
292  const typename Signal::group_type &group,
293  const typename Signal::extended_slot_type &slot,
294  boost::signals2::connect_position at = boost::signals2::at_back
295  ) {
296  return selSig.connect_extended(group, slot, at);
297  }
305  const typename Signal::group_type &group
306  ) {
307  selSig.disconnect(group);
308  }
315  template<typename Slot>
316  void selectDisconnect(const Slot &slotFunc) {
317  selSig.disconnect(slotFunc);
318  }
325  boost::signals2::connection deselectConnect(
326  const typename Signal::slot_type &slot,
327  boost::signals2::connect_position at = boost::signals2::at_back
328  ) {
329  return deselSig.connect(slot, at);
330  }
337  boost::signals2::connection deselectConnect(
338  const typename Signal::group_type &group,
339  const typename Signal::slot_type &slot,
340  boost::signals2::connect_position at = boost::signals2::at_back
341  ) {
342  return deselSig.connect(group, slot, at);
343  }
350  boost::signals2::connection deselectConnectExtended(
351  const typename Signal::extended_slot_type &slot,
352  boost::signals2::connect_position at = boost::signals2::at_back
353  ) {
354  return deselSig.connect_extended(slot, at);
355  }
362  boost::signals2::connection deselectConnectExtended(
363  const typename Signal::group_type &group,
364  const typename Signal::extended_slot_type &slot,
365  boost::signals2::connect_position at = boost::signals2::at_back
366  ) {
367  return deselSig.connect_extended(group, slot, at);
368  }
376  const typename Signal::group_type &group
377  ) {
378  deselSig.disconnect(group);
379  }
386  template<typename Slot>
387  void deselectDisconnect(const Slot &slotFunc) {
388  deselSig.disconnect(slotFunc);
389  }
390 };
391 
395 typedef std::shared_ptr<GenericMenuItem> GenericMenuItemSptr;
396 
400 typedef std::weak_ptr<GenericMenuItem> GenericMenuItemWptr;
401 
402 } } }
403 
404 #endif // #ifndef GENERICMENUITEM_HPP
const std::string & description() const
Returns the optional description text for this item.
Definition: MenuItem.hpp:194
GenericMenuItem(MenuItemToken, const std::string &label, const std::string &description, Flags flags=Flags::Zero())
Constructs a new GenericMenuItem.
boost::signals2::connection deselectConnectExtended(const typename Signal::group_type &group, const typename Signal::extended_slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item deselect signal.
Signal choseSig
The signal that is invoked when the user choses this menu item.
std::shared_ptr< GenericMenuItem > GenericMenuItemSptr
A shared pointer to a GenericMenuItem.
void selectDisconnect(const Slot &slotFunc)
Disconnect from the generic menu item select signal.
const std::string & label() const
Returns the label text for this item.
Definition: MenuItem.hpp:180
GenericMenuItem(MenuItemToken, const std::string &label, Flags flags=Flags::Zero())
Constructs a new GenericMenuItem.
static constexpr BitFlags Zero()
Makes a bit flags container with all flags cleared.
Definition: BitFlags.hpp:133
Signal deselSig
The signal that is invoked when the user deselects this menu item.
boost::signals2::connection choseConnectExtended(const typename Signal::group_type &group, const typename Signal::extended_slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item chose signal.
This token is needed to construct MenuItem objects; use to force all objects to be managed by shared ...
Definition: MenuItem.hpp:119
void choseDisconnect(const Slot &slotFunc)
Disconnect from the generic menu item chose signal.
boost::signals2::connection selectConnect(const typename Signal::group_type &group, const typename Signal::slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item select signal.
boost::signals2::connection selectConnectExtended(const typename Signal::extended_slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item select signal.
static std::shared_ptr< GenericMenuItem > make(const std::string &label, const std::string &description, const std::string &value, Flags flags=Flags::Zero())
Makes a shared pointer holding a new GenericMenuItem with an associated value.
boost::signals2::connection selectConnect(const typename Signal::slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item select signal.
boost::signals2::signal< void(MenuView &invokingView, const MenuAccess &access, GenericMenuItem &self) > Signal
The signal type invoked when the item is chosen, selected, or deselected.
A generic take on MenuItem that invokes a Boost signal when the item is chosen, selected, or deselected.
boost::signals2::connection choseConnectExtended(const typename Signal::extended_slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item chose signal.
GenericMenuItem(MenuItemToken, const std::string &label, const std::string &description, const std::string &value, Flags flags=Flags::Zero())
Constructs a new GenericMenuItem with an associated value.
boost::signals2::connection deselectConnectExtended(const typename Signal::extended_slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item deselect signal.
static std::shared_ptr< GenericMenuItem > make(const std::string &label, Flags flags=Flags::Zero())
Makes a shared pointer holding a new GenericMenuItem.
void choseDisconnect(const typename Signal::group_type &group)
Disconnect a group from the generic menu item chose signal.
std::weak_ptr< GenericMenuItem > GenericMenuItemWptr
A weak pointer to a GenericMenuItem.
Flags flags() const
Returns the option flags for the item.
Definition: MenuItem.hpp:322
boost::signals2::connection selectConnectExtended(const typename Signal::group_type &group, const typename Signal::extended_slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item select signal.
boost::signals2::connection deselectConnect(const typename Signal::group_type &group, const typename Signal::slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item deselect signal.
void deselectDisconnect(const typename Signal::group_type &group)
Disconnect a group from the generic menu item deselect signal.
Keeps track of the selected menu item, and updates it based on user input.
Definition: MenuView.hpp:46
virtual void deselect(MenuView &invokingView, const MenuAccess &access)
Invokes the deselSig signal in response to the user deselecting this menu item.
static std::shared_ptr< GenericMenuItem > make(const std::string &label, const std::string &description, Flags flags=Flags::Zero())
Makes a shared pointer holding a new GenericMenuItem.
Provides an exclusive lock on a Menu to allow the menu to be changed.
Definition: MenuAccess.hpp:32
Represents an option that a user can chose from a menu of options.
Definition: MenuItem.hpp:58
virtual void chose(MenuView &invokingView, const MenuAccess &access)
Invokes the choseSig signal in response to the user chosing this menu item.
const std::string & value() const
Returns the optional value text for the item.
Definition: MenuItem.hpp:210
boost::signals2::connection choseConnect(const typename Signal::slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item chose signal.
virtual void select(MenuView &invokingView, const MenuAccess &access)
Invokes the selSig signal in response to the user selecting this menu item.
void selectDisconnect(const typename Signal::group_type &group)
Disconnect a group from the generic menu item select signal.
boost::signals2::connection deselectConnect(const typename Signal::slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item deselect signal.
boost::signals2::connection choseConnect(const typename Signal::group_type &group, const typename Signal::slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the generic menu item chose signal.
void deselectDisconnect(const Slot &slotFunc)
Disconnect from the generic menu item deselect signal.
Signal selSig
The signal that is invoked when the user selects this menu item.