Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
96 class RMenuArgument {
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 SetId(const std::string &id) { fId = id; }
157 
158  auto Size() const { return fItems.size(); }
159 
160  void Add(std::unique_ptr<Detail::RMenuItem> &&item) { fItems.emplace_back(std::move(item)); }
161 
162  void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
163  {
164  auto item = std::make_unique<Detail::RMenuItem>(name, title);
165  item->SetExec(exec);
166  Add(std::move(item));
167  }
168 
169  void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle)
170  {
171  auto item = std::make_unique<Detail::RCheckedMenuItem>(name, title, checked);
172  item->SetExec(toggle);
173  Add(std::move(item));
174  }
175 
176  void PopulateObjectMenu(void *obj, TClass *cl);
177 };
178 
179 } // namespace Experimental
180 } // namespace ROOT
181 
182 #endif