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
20namespace ROOT {
21namespace Experimental {
22namespace 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
32class RMenuItem {
33protected:
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
38public:
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
73protected:
74 bool fChecked = false; ///< state of checkbox
75public:
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
103protected:
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
108public:
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
129class RArgsMenuItem : public RMenuItem {
130protected:
131 std::vector<RMenuArgument> fArgs;
132
133public:
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
158protected:
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
162public:
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;
211public:
212 std::unique_ptr<RDrawableReply> Process() override;
213};
214
215
216} // namespace Experimental
217} // namespace ROOT
218
219#endif
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
char name[80]
Definition: TGX11.cxx:110
Menu item which requires extra arguments for invoked class method.
Definition: RMenuItems.hxx:129
virtual ~RArgsMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItems.hxx:140
std::vector< RMenuArgument > fArgs
Definition: RMenuItems.hxx:131
RArgsMenuItem()=default
Default constructor.
void AddArg(const RMenuArgument &arg)
Definition: RMenuItems.hxx:142
RArgsMenuItem(const std::string &name, const std::string &title)
Definition: RMenuItems.hxx:137
RCheckedMenuItem()=default
Default constructor.
virtual ~RCheckedMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItems.hxx:86
RCheckedMenuItem(const std::string &name, const std::string &title, bool checked=false)
Create checked menu item
Definition: RMenuItems.hxx:80
void SetChecked(bool on=true)
Set checked state for the item, default is none.
Definition: RMenuItems.hxx:89
Argument description for menu item which should invoke class method.
Definition: RMenuItems.hxx:102
RMenuArgument()=default
Default constructor.
std::string fName
name of call argument
Definition: RMenuItems.hxx:104
RMenuArgument(const std::string &name, const std::string &title, const std::string &typname, const std::string &dflt="")
Definition: RMenuItems.hxx:112
void SetDefault(const std::string &dflt)
Definition: RMenuItems.hxx:118
std::string fTitle
title of call argument
Definition: RMenuItems.hxx:105
Base class for menu items, shown on JS side.
Definition: RMenuItems.hxx:32
std::string fTitle
title of menu item
Definition: RMenuItems.hxx:35
RMenuItem()=default
Default constructor.
const std::string & GetExec() const
Returns execution string for the menu item.
Definition: RMenuItems.hxx:61
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
void SetClassName(const std::string &clname)
Set class name for menu item, will be used to group items together.
Definition: RMenuItems.hxx:55
std::string fClassName
class to which belongs menu item
Definition: RMenuItems.hxx:37
std::string fExec
execute when item is activated
Definition: RMenuItems.hxx:36
std::string fName
name of the menu item
Definition: RMenuItems.hxx:34
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
const std::string & GetName() const
Returns menu item name.
Definition: RMenuItems.hxx:58
virtual ~RMenuItem()=default
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Request menu items for the drawable object.
Definition: RMenuItems.hxx:208
std::unique_ptr< RDrawableReply > Process() override
fill menu items for the drawable
Definition: RMenuItems.cxx:146
Base class for replies on RDrawableRequest.
Base class for requests which can be submitted from the clients.
List of items for object context menu.
Definition: RMenuItems.hxx:157
RMenuItems(const std::string &_id, const std::string &_specifier)
Definition: RMenuItems.hxx:165
std::string fSpecifier
! extra specifier, used only on server
Definition: RMenuItems.hxx:160
virtual ~RMenuItems()
destructor - pin vtable
std::string fId
object identifier
Definition: RMenuItems.hxx:159
std::vector< std::unique_ptr< Detail::RMenuItem > > fItems
list of items in the menu
Definition: RMenuItems.hxx:161
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle, const TClass *cl=nullptr)
Definition: RMenuItems.hxx:188
void Add(std::unique_ptr< Detail::RMenuItem > &&item)
Definition: RMenuItems.hxx:178
const std::string & GetFullId() const
Definition: RMenuItems.hxx:173
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec, const TClass *cl=nullptr)
Definition: RMenuItems.hxx:180
void PopulateObjectMenu(void *obj, TClass *cl)
Fill menu for provided object, using MENU as indicator in method comments.
Definition: RMenuItems.cxx:31
const std::string & GetSpecifier() const
Definition: RMenuItems.hxx:174
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:81
struct void * fTypeName
Definition: cppyy.h:9
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.