Logo ROOT  
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
16class TClass;
17
18namespace ROOT {
19namespace Experimental {
20namespace 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
30class RMenuItem {
31protected:
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
35public:
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
67protected:
68 bool fChecked = false; ///< state of checkbox
69public:
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
97protected:
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
102public:
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
123class RArgsMenuItem : public RMenuItem {
124protected:
125 std::vector<RMenuArgument> fArgs;
126
127public:
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
152protected:
153 std::string fId; ///< object identifier
154 std::vector<std::unique_ptr<Detail::RMenuItem>> fItems; ///< list of items in the menu
155public:
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
XFontStruct * id
Definition: TGX11.cxx:108
char name[80]
Definition: TGX11.cxx:109
Menu item which requires extra arguments for invoked class method.
Definition: RMenuItem.hxx:123
virtual ~RArgsMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItem.hxx:134
std::vector< RMenuArgument > fArgs
Definition: RMenuItem.hxx:125
RArgsMenuItem()=default
Default constructor.
void AddArg(const RMenuArgument &arg)
Definition: RMenuItem.hxx:136
RArgsMenuItem(const std::string &name, const std::string &title)
Definition: RMenuItem.hxx:131
RCheckedMenuItem()=default
Default constructor.
virtual ~RCheckedMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItem.hxx:80
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
Argument description for menu item which should invoke class method.
Definition: RMenuItem.hxx:96
RMenuArgument()=default
Default constructor.
std::string fName
name of call argument
Definition: RMenuItem.hxx:98
RMenuArgument(const std::string &name, const std::string &title, const std::string &typname, const std::string &dflt="")
Definition: RMenuItem.hxx:106
void SetDefault(const std::string &dflt)
Definition: RMenuItem.hxx:112
std::string fTitle
title of call argument
Definition: RMenuItem.hxx:99
Base class for menu items, shown on JS side.
Definition: RMenuItem.hxx:30
std::string fTitle
title of menu item
Definition: RMenuItem.hxx:33
RMenuItem()=default
Default constructor.
const std::string & GetExec() const
Returns execution string for the menu item.
Definition: RMenuItem.hxx:55
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
std::string fExec
execute when item is activated
Definition: RMenuItem.hxx:34
std::string fName
name of the menu item
Definition: RMenuItem.hxx:32
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 & GetName() const
Returns menu item name.
Definition: RMenuItem.hxx:52
virtual ~RMenuItem()=default
virtual destructor need for vtable, used when vector of RMenuItem* is stored
List of items for object context menu.
Definition: RMenuItem.hxx:151
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
Definition: RMenuItem.hxx:162
void SetId(const std::string &id)
Definition: RMenuItem.hxx:156
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle)
Definition: RMenuItem.hxx:169
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
void Add(std::unique_ptr< Detail::RMenuItem > &&item)
Definition: RMenuItem.hxx:160
void PopulateObjectMenu(void *obj, TClass *cl)
Definition: RMenuItem.cxx:20
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
VSD Structures.
Definition: StringConv.hxx:21