Logo ROOT   master
Reference Guide
RMenuItem.hxx
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
3  * All rights reserved. *
4  * *
5  * For the licensing terms see $ROOTSYS/LICENSE. *
6  * For the list of contributors see $ROOTSYS/README/CREDITS. *
7  *************************************************************************/
8 
9 #ifndef ROOT7_RMenuItem
10 #define ROOT7_RMenuItem
11 
12 #include <string>
13 #include <vector>
14 #include <memory>
15 
16 class TClass;
17 
18 namespace ROOT {
19 namespace Experimental {
20 namespace Detail {
21 
22 /** \class RMenuItem
23 \ingroup GpadROOT7
24 \brief Base class for menu items, shown on JS side.
25 \author Sergey Linev
26 \date 2017-06-29
27 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
28 */
29 
30 class RMenuItem {
31 protected:
32  std::string fName; ///< name of the menu item
33  std::string fTitle; ///< title of menu item
34  std::string fExec; ///< execute when item is activated
35 public:
36  /** Default constructor */
37  RMenuItem() = default;
38 
39  /** Create menu item with the name and title
40  * name used to display item in the object context menu,
41  * title shown as hint info for that item */
42  RMenuItem(const std::string &name, const std::string &title) : fName(name), fTitle(title), fExec() {}
43 
44  /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
45  virtual ~RMenuItem() = default;
46 
47  /** Set execution string with all required arguments,
48  * which will be executed when menu item is selected */
49  void SetExec(const std::string &exec) { fExec = exec; }
50 
51  /** Returns menu item name */
52  const std::string &GetName() const { return fName; }
53 
54  /** Returns execution string for the menu item */
55  const std::string &GetExec() const { return fExec; }
56 };
57 
58 /** \class RCheckedMenuItem
59 \ingroup GpadROOT7
60 \brief Menu item with check box
61 \author Sergey Linev
62 \date 2017-06-29
63 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
64 */
65 
66 class RCheckedMenuItem : public RMenuItem {
67 protected:
68  bool fChecked = false; ///< state of checkbox
69 public:
70  /** Default constructor */
71  RCheckedMenuItem() = default;
72 
73  /** Create checked menu item */
74  RCheckedMenuItem(const std::string &name, const std::string &title, bool checked = false)
75  : RMenuItem(name, title), fChecked(checked)
76  {
77  }
78 
79  /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
80  virtual ~RCheckedMenuItem() {}
81 
82  /** Set checked state for the item, default is none */
83  void SetChecked(bool on = true) { fChecked = on; }
84 
85  bool IsChecked() const { return fChecked; }
86 };
87 
88 /** \class RMenuArgument
89 \ingroup GpadROOT7
90 \brief Argument description for menu item which should invoke class method
91 \author Sergey Linev
92 \date 2017-06-29
93 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
94 */
95 
97 protected:
98  std::string fName; ///< name of call argument
99  std::string fTitle; ///< title of call argument
100  std::string fTypeName; ///< typename
101  std::string fDefault; ///< default value
102 public:
103  /** Default constructor */
104  RMenuArgument() = default;
105 
106  RMenuArgument(const std::string &name, const std::string &title, const std::string &typname,
107  const std::string &dflt = "")
108  : fName(name), fTitle(title), fTypeName(typname), fDefault(dflt)
109  {
110  }
111 
112  void SetDefault(const std::string &dflt) { fDefault = dflt; }
113 };
114 
115 /** \class RArgsMenuItem
116 \ingroup GpadROOT7
117 \brief Menu item which requires extra arguments for invoked class method
118 \author Sergey Linev
119 \date 2017-06-29
120 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
121 */
122 
123 class RArgsMenuItem : public RMenuItem {
124 protected:
125  std::vector<RMenuArgument> fArgs;
126 
127 public:
128  /** Default constructor */
129  RArgsMenuItem() = default;
130 
131  RArgsMenuItem(const std::string &name, const std::string &title) : RMenuItem(name, title) {}
132 
133  /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
134  virtual ~RArgsMenuItem() {}
135 
136  void AddArg(const RMenuArgument &arg) { fArgs.emplace_back(arg); }
137 };
138 
139 } // namespace Detail
140 
141 ///////////////////////////////////////////////////////////////////////
142 
143 /** \class RMenuItems
144 \ingroup GpadROOT7
145 \brief List of items for object context menu
146 \author Sergey Linev
147 \date 2017-06-29
148 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
149 */
150 
151 class RMenuItems {
152 protected:
153  std::string fId; ///< object identifier
154  std::vector<std::unique_ptr<Detail::RMenuItem>> fItems; ///< list of items in the menu
155 public:
156  void SetFullId(const std::string &id) { fId = id; }
157  const std::string &GetFullId() const { return fId; }
158 
159  std::string GetDrawableId();
160  std::string GetSpecifier();
161 
162  auto Size() const { return fItems.size(); }
163 
164  void Add(std::unique_ptr<Detail::RMenuItem> &&item) { fItems.emplace_back(std::move(item)); }
165 
166  void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
167  {
168  auto item = std::make_unique<Detail::RMenuItem>(name, title);
169  item->SetExec(exec);
170  Add(std::move(item));
171  }
172 
173  void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle)
174  {
175  auto item = std::make_unique<Detail::RCheckedMenuItem>(name, title, checked);
176  item->SetExec(toggle);
177  Add(std::move(item));
178  }
179 
180  void PopulateObjectMenu(void *obj, TClass *cl);
181 };
182 
183 } // namespace Experimental
184 } // namespace ROOT
185 
186 #endif
RCheckedMenuItem()=default
Default constructor.
void PopulateObjectMenu(void *obj, TClass *cl)
Fill menu for provided object, using MENU as indicator in method comments.
Definition: RMenuItem.cxx:47
Menu item which requires extra arguments for invoked class method.
Definition: RMenuItem.hxx:123
virtual ~RCheckedMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItem.hxx:80
Returns the available number of logical cores.
Definition: StringConv.hxx:21
std::string fId
object identifier
Definition: RMenuItem.hxx:153
std::vector< std::unique_ptr< Detail::RMenuItem > > fItems
list of items in the menu
Definition: RMenuItem.hxx:154
std::string fName
name of call argument
Definition: RMenuItem.hxx:98
void SetFullId(const std::string &id)
Definition: RMenuItem.hxx:156
RMenuArgument()=default
Default constructor.
Argument description for menu item which should invoke class method.
Definition: RMenuItem.hxx:96
RCheckedMenuItem(const std::string &name, const std::string &title, bool checked=false)
Create checked menu item.
Definition: RMenuItem.hxx:74
void SetChecked(bool on=true)
Set checked state for the item, default is none.
Definition: RMenuItem.hxx:83
Base class for menu items, shown on JS side.
Definition: RMenuItem.hxx:30
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
Definition: RMenuItem.hxx:166
virtual ~RArgsMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItem.hxx:134
std::string fExec
execute when item is activated
Definition: RMenuItem.hxx:34
std::vector< RMenuArgument > fArgs
Definition: RMenuItem.hxx:125
void SetDefault(const std::string &dflt)
Definition: RMenuItem.hxx:112
XFontStruct * id
Definition: TGX11.cxx:108
RArgsMenuItem()=default
Default constructor.
std::string fTitle
title of menu item
Definition: RMenuItem.hxx:33
std::string GetDrawableId()
Returns drawable id coded, fullid can include # with extra specifier.
Definition: RMenuItem.cxx:23
std::string fName
name of the menu item
Definition: RMenuItem.hxx:32
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle)
Definition: RMenuItem.hxx:173
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
RMenuItem(const std::string &name, const std::string &title)
Create menu item with the name and title name used to display item in the object context menu...
Definition: RMenuItem.hxx:42
const std::string & GetFullId() const
Definition: RMenuItem.hxx:157
std::string fTitle
title of call argument
Definition: RMenuItem.hxx:99
RMenuItem()=default
Default constructor.
const std::string & GetExec() const
Returns execution string for the menu item.
Definition: RMenuItem.hxx:55
void AddArg(const RMenuArgument &arg)
Definition: RMenuItem.hxx:136
void SetExec(const std::string &exec)
Set execution string with all required arguments, which will be executed when menu item is selected...
Definition: RMenuItem.hxx:49
List of items for object context menu.
Definition: RMenuItem.hxx:151
RArgsMenuItem(const std::string &name, const std::string &title)
Definition: RMenuItem.hxx:131
RMenuArgument(const std::string &name, const std::string &title, const std::string &typname, const std::string &dflt="")
Definition: RMenuItem.hxx:106
std::string fDefault
default value
Definition: RMenuItem.hxx:101
const std::string & GetName() const
Returns menu item name.
Definition: RMenuItem.hxx:52
std::string GetSpecifier()
Returns specifier string after # in fullid.
Definition: RMenuItem.cxx:35
virtual ~RMenuItem()=default
virtual destructor need for vtable, used when vector of RMenuItem* is stored
char name[80]
Definition: TGX11.cxx:109
void Add(std::unique_ptr< Detail::RMenuItem > &&item)
Definition: RMenuItem.hxx:164