Logo ROOT  
Reference Guide
RMenuItems.hxx
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 1995-2020, 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_RMenuItems
10 #define ROOT7_RMenuItems
11 
12 #include <string>
13 #include <vector>
14 #include <memory>
15 
17 
18 class TClass;
19 
20 namespace ROOT {
21 namespace Experimental {
22 namespace Detail {
23 
24 /** \class RMenuItem
25 \ingroup GpadROOT7
26 \brief Base class for menu items, shown on JS side.
27 \author Sergey Linev
28 \date 2017-06-29
29 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
30 */
31 
32 class RMenuItem {
33 protected:
34  std::string fName; ///< name of the menu item
35  std::string fTitle; ///< title of menu item
36  std::string fExec; ///< execute when item is activated
37 public:
38  /** Default constructor */
39  RMenuItem() = default;
40 
41  /** Create menu item with the name and title
42  * name used to display item in the object context menu,
43  * title shown as hint info for that item */
44  RMenuItem(const std::string &name, const std::string &title) : fName(name), fTitle(title), fExec() {}
45 
46  /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
47  virtual ~RMenuItem() = default;
48 
49  /** Set execution string with all required arguments,
50  * which will be executed when menu item is selected */
51  void SetExec(const std::string &exec) { fExec = exec; }
52 
53  /** Returns menu item name */
54  const std::string &GetName() const { return fName; }
55 
56  /** Returns execution string for the menu item */
57  const std::string &GetExec() const { return fExec; }
58 };
59 
60 /** \class RCheckedMenuItem
61 \ingroup GpadROOT7
62 \brief Menu item with check box
63 \author Sergey Linev
64 \date 2017-06-29
65 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
66 */
67 
68 class RCheckedMenuItem : public RMenuItem {
69 protected:
70  bool fChecked = false; ///< state of checkbox
71 public:
72  /** Default constructor */
73  RCheckedMenuItem() = default;
74 
75  /** Create checked menu item */
76  RCheckedMenuItem(const std::string &name, const std::string &title, bool checked = false)
77  : RMenuItem(name, title), fChecked(checked)
78  {
79  }
80 
81  /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
82  virtual ~RCheckedMenuItem() {}
83 
84  /** Set checked state for the item, default is none */
85  void SetChecked(bool on = true) { fChecked = on; }
86 
87  bool IsChecked() const { return fChecked; }
88 };
89 
90 /** \class RMenuArgument
91 \ingroup GpadROOT7
92 \brief Argument description for menu item which should invoke class method
93 \author Sergey Linev
94 \date 2017-06-29
95 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
96 */
97 
99 protected:
100  std::string fName; ///< name of call argument
101  std::string fTitle; ///< title of call argument
102  std::string fTypeName; ///< typename
103  std::string fDefault; ///< default value
104 public:
105  /** Default constructor */
106  RMenuArgument() = default;
107 
108  RMenuArgument(const std::string &name, const std::string &title, const std::string &typname,
109  const std::string &dflt = "")
110  : fName(name), fTitle(title), fTypeName(typname), fDefault(dflt)
111  {
112  }
113 
114  void SetDefault(const std::string &dflt) { fDefault = dflt; }
115 };
116 
117 /** \class RArgsMenuItem
118 \ingroup GpadROOT7
119 \brief Menu item which requires extra arguments for invoked class method
120 \author Sergey Linev
121 \date 2017-06-29
122 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
123 */
124 
125 class RArgsMenuItem : public RMenuItem {
126 protected:
127  std::vector<RMenuArgument> fArgs;
128 
129 public:
130  /** Default constructor */
131  RArgsMenuItem() = default;
132 
133  RArgsMenuItem(const std::string &name, const std::string &title) : RMenuItem(name, title) {}
134 
135  /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
136  virtual ~RArgsMenuItem() {}
137 
138  void AddArg(const RMenuArgument &arg) { fArgs.emplace_back(arg); }
139 };
140 
141 } // namespace Detail
142 
143 ///////////////////////////////////////////////////////////////////////
144 
145 /** \class RMenuItems
146 \ingroup GpadROOT7
147 \brief List of items for object context menu
148 \author Sergey Linev
149 \date 2017-06-29
150 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
151 */
152 
153 class RMenuItems : public RDrawableReply {
154 protected:
155  std::string fId; ///< object identifier
156  std::string fSpecifier; ///<! extra specifier, used only on server
157  std::vector<std::unique_ptr<Detail::RMenuItem>> fItems; ///< list of items in the menu
158 public:
159  RMenuItems() = default;
160 
161  RMenuItems(const std::string &_id, const std::string &_specifier)
162  {
163  fId = _id;
164  fSpecifier = _specifier;
165  }
166 
167  virtual ~RMenuItems();
168 
169  const std::string &GetFullId() const { return fId; }
170  const std::string &GetSpecifier() const { return fSpecifier; }
171 
172  auto Size() const { return fItems.size(); }
173 
174  void Add(std::unique_ptr<Detail::RMenuItem> &&item) { fItems.emplace_back(std::move(item)); }
175 
176  void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
177  {
178  auto item = std::make_unique<Detail::RMenuItem>(name, title);
179  item->SetExec(exec);
180  Add(std::move(item));
181  }
182 
183  void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle)
184  {
185  auto item = std::make_unique<Detail::RCheckedMenuItem>(name, title, checked);
186  item->SetExec(toggle);
187  Add(std::move(item));
188  }
189 
190  void PopulateObjectMenu(void *obj, TClass *cl);
191 };
192 
193 
194 /** \class RDrawableMenuRequest
195 \ingroup GpadROOT7
196 \brief Request menu items for the drawable object
197 \author Sergey Linev
198 \date 2020-04-14
199 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
200 */
201 
203  std::string menukind;
204  std::string menureqid;
205 public:
206  std::unique_ptr<RDrawableReply> Process() override;
207 };
208 
209 
210 } // namespace Experimental
211 } // namespace ROOT
212 
213 #endif
ROOT::Experimental::RMenuItems::GetSpecifier
const std::string & GetSpecifier() const
Definition: RMenuItems.hxx:170
ROOT::Experimental::RMenuItems::RMenuItems
RMenuItems()=default
ROOT::Experimental::RMenuItems::AddChkMenuItem
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle)
Definition: RMenuItems.hxx:183
ROOT::Experimental::RMenuItems::fItems
std::vector< std::unique_ptr< Detail::RMenuItem > > fItems
list of items in the menu
Definition: RMenuItems.hxx:157
ROOT::Experimental::Detail::RMenuItem::fTitle
std::string fTitle
title of menu item
Definition: RMenuItems.hxx:35
ROOT::Experimental::RMenuItems::fId
std::string fId
object identifier
Definition: RMenuItems.hxx:155
ROOT::Experimental::Detail::RMenuItem::fExec
std::string fExec
execute when item is activated
Definition: RMenuItems.hxx:36
ROOT::Experimental::RMenuItems::GetFullId
const std::string & GetFullId() const
Definition: RMenuItems.hxx:169
ROOT::Experimental::Detail::RCheckedMenuItem::~RCheckedMenuItem
virtual ~RCheckedMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItems.hxx:82
ROOT::Experimental::Detail::RMenuArgument::SetDefault
void SetDefault(const std::string &dflt)
Definition: RMenuItems.hxx:114
ROOT::Experimental::Detail::RMenuArgument::fDefault
std::string fDefault
default value
Definition: RMenuItems.hxx:103
ROOT::Experimental::Detail::RMenuItem::RMenuItem
RMenuItem()=default
Default constructor.
ROOT::Experimental::RDrawableMenuRequest
Request menu items for the drawable object.
Definition: RMenuItems.hxx:202
ROOT::Experimental::Detail::RCheckedMenuItem
Menu item with check box.
Definition: RMenuItems.hxx:68
ROOT::Experimental::RDrawableReply
Base class for replies on RDrawableRequest.
Definition: RDrawableRequest.hxx:42
ROOT::Experimental::Detail::RArgsMenuItem::fArgs
std::vector< RMenuArgument > fArgs
Definition: RMenuItems.hxx:127
ROOT::Experimental::Detail::RMenuItem::GetName
const std::string & GetName() const
Returns menu item name.
Definition: RMenuItems.hxx:54
ROOT::Experimental::Detail::RArgsMenuItem::~RArgsMenuItem
virtual ~RArgsMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItems.hxx:136
ROOT::Experimental::Detail::RCheckedMenuItem::SetChecked
void SetChecked(bool on=true)
Set checked state for the item, default is none.
Definition: RMenuItems.hxx:85
ROOT::Experimental::Detail::RCheckedMenuItem::IsChecked
bool IsChecked() const
Definition: RMenuItems.hxx:87
ROOT::Experimental::RMenuItems::PopulateObjectMenu
void PopulateObjectMenu(void *obj, TClass *cl)
Fill menu for provided object, using MENU as indicator in method comments.
Definition: RMenuItems.cxx:31
ROOT::Experimental::Detail::RMenuArgument::fTitle
std::string fTitle
title of call argument
Definition: RMenuItems.hxx:101
ROOT::Experimental::Detail::RMenuArgument::RMenuArgument
RMenuArgument(const std::string &name, const std::string &title, const std::string &typname, const std::string &dflt="")
Definition: RMenuItems.hxx:108
ROOT::Experimental::Detail::RArgsMenuItem::AddArg
void AddArg(const RMenuArgument &arg)
Definition: RMenuItems.hxx:138
ROOT::Experimental::RMenuItems::~RMenuItems
virtual ~RMenuItems()
destructor - pin vtable
ROOT::Experimental::RMenuItems
List of items for object context menu.
Definition: RMenuItems.hxx:153
ROOT::Experimental::Detail::RMenuArgument::fTypeName
std::string fTypeName
typename
Definition: RMenuItems.hxx:102
ROOT::Experimental::Detail::RMenuArgument
Argument description for menu item which should invoke class method.
Definition: RMenuItems.hxx:98
ROOT::Experimental::Detail::RArgsMenuItem::RArgsMenuItem
RArgsMenuItem()=default
Default constructor.
ROOT::Experimental::Detail::RMenuArgument::fName
std::string fName
name of call argument
Definition: RMenuItems.hxx:100
ROOT::Experimental::RDrawableRequest
Base class for requests which can be submitted from the clients.
Definition: RDrawableRequest.hxx:62
ROOT::Experimental::Detail::RMenuItem::SetExec
void SetExec(const std::string &exec)
Set execution string with all required arguments, which will be executed when menu item is selected
Definition: RMenuItems.hxx:51
ROOT::Experimental::Detail::RMenuItem::GetExec
const std::string & GetExec() const
Returns execution string for the menu item.
Definition: RMenuItems.hxx:57
ROOT::Experimental::Detail::RMenuArgument::RMenuArgument
RMenuArgument()=default
Default constructor.
ROOT::Experimental::RDrawableMenuRequest::menureqid
std::string menureqid
Definition: RMenuItems.hxx:204
ROOT::Experimental::RDrawableMenuRequest::menukind
std::string menukind
Definition: RMenuItems.hxx:203
ROOT::Experimental::Detail::RMenuItem::RMenuItem
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: RMenuItems.hxx:44
ROOT::Experimental::Detail::RArgsMenuItem::RArgsMenuItem
RArgsMenuItem(const std::string &name, const std::string &title)
Definition: RMenuItems.hxx:133
ROOT::Experimental::Detail::RMenuItem
Base class for menu items, shown on JS side.
Definition: RMenuItems.hxx:32
ROOT::Experimental::RMenuItems::RMenuItems
RMenuItems(const std::string &_id, const std::string &_specifier)
Definition: RMenuItems.hxx:161
ROOT::Experimental::RMenuItems::AddMenuItem
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
Definition: RMenuItems.hxx:176
TClass
Definition: TClass.h:80
ROOT::Experimental::Detail::RMenuItem::~RMenuItem
virtual ~RMenuItem()=default
virtual destructor need for vtable, used when vector of RMenuItem* is stored
ROOT::Experimental::Detail::RCheckedMenuItem::RCheckedMenuItem
RCheckedMenuItem()=default
Default constructor.
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Experimental::Detail::RArgsMenuItem
Menu item which requires extra arguments for invoked class method.
Definition: RMenuItems.hxx:125
ROOT::Experimental::RMenuItems::Add
void Add(std::unique_ptr< Detail::RMenuItem > &&item)
Definition: RMenuItems.hxx:174
ROOT::Experimental::Detail::RMenuItem::fName
std::string fName
name of the menu item
Definition: RMenuItems.hxx:34
RDrawableRequest.hxx
ROOT::Experimental::Detail::RCheckedMenuItem::RCheckedMenuItem
RCheckedMenuItem(const std::string &name, const std::string &title, bool checked=false)
Create checked menu item
Definition: RMenuItems.hxx:76
ROOT::Experimental::RDrawableMenuRequest::Process
std::unique_ptr< RDrawableReply > Process() override
fill menu items for the drawable
Definition: RMenuItems.cxx:101
fTypeName
struct void * fTypeName
Definition: cppyy.h:9
ROOT::Experimental::RMenuItems::fSpecifier
std::string fSpecifier
! extra specifier, used only on server
Definition: RMenuItems.hxx:156
ROOT::Experimental::RMenuItems::Size
auto Size() const
Definition: RMenuItems.hxx:172
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Experimental::Detail::RCheckedMenuItem::fChecked
bool fChecked
state of checkbox
Definition: RMenuItems.hxx:70