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