Logo ROOT   6.18/05
Reference Guide
RMenuItem.hxx
Go to the documentation of this file.
1/// \file ROOT/RMenuItem.hxx
2/// \ingroup Base ROOT7
3/// \author Sergey Linev
4/// \date 2017-06-29
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#ifndef ROOT7_RMenuItem
17#define ROOT7_RMenuItem
18
19#include <string>
20#include <vector>
21
22class TClass;
23
24namespace ROOT {
25namespace Experimental {
26namespace Detail {
27
28/** \class RMenuItem
29 Class contains info for producing menu item on the JS side.
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
37public:
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() {}
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
61protected:
62 bool fChecked = false; ///< -1 not exists, 0 - off, 1 - on
63public:
64 /** Default constructor */
65 RCheckedMenuItem() = default;
66
67 /** Create checked menu item */
68 RCheckedMenuItem(const std::string &name, const std::string &title, bool checked = false)
69 : RMenuItem(name, title), fChecked(checked)
70 {
71 }
72
73 /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
74 virtual ~RCheckedMenuItem() {}
75
76 /** Set checked state for the item, default is none */
77 void SetChecked(bool on = true) { fChecked = on; }
78
79 bool IsChecked() const { return fChecked; }
80};
81
83protected:
84 std::string fName; ///< name of call argument
85 std::string fTitle; ///< title of call argument
86 std::string fTypeName; ///< typename
87 std::string fDefault; ///< default value
88public:
89 /** Default constructor */
90 RMenuArgument() = default;
91
92 RMenuArgument(const std::string &name, const std::string &title, const std::string &typname,
93 const std::string &dflt = "")
94 : fName(name), fTitle(title), fTypeName(typname), fDefault(dflt)
95 {
96 }
97
98 void SetDefault(const std::string &dflt) { fDefault = dflt; }
99};
100
101class RArgsMenuItem : public RMenuItem {
102protected:
103 std::vector<RMenuArgument> fArgs;
104
105public:
106 /** Default constructor */
107 RArgsMenuItem() = default;
108
109 RArgsMenuItem(const std::string &name, const std::string &title) : RMenuItem(name, title) {}
110
111 /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
112 virtual ~RArgsMenuItem() {}
113
114 void AddArg(const RMenuArgument &arg) { fArgs.push_back(arg); }
115};
116
117} // namespace Detail
118
119///////////////////////////////////////////////////////////////////////
120
122protected:
123 std::vector<Detail::RMenuItem *> fItems; ///< list of items in the menu
124public:
125 /** Default constructor */
126 RMenuItems() = default;
127
129
130 void Add(Detail::RMenuItem *item) { fItems.push_back(item); }
131
132 void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
133 {
134 Detail::RMenuItem *item = new Detail::RMenuItem(name, title);
135 item->SetExec(exec);
136 Add(item);
137 }
138
139 void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle)
140 {
141 Detail::RCheckedMenuItem *item = new Detail::RCheckedMenuItem(name, title, checked);
142 item->SetExec(toggle);
143 Add(item);
144 }
145
146 unsigned Size() const { return fItems.size(); }
147
148 void Cleanup();
149
150 void PopulateObjectMenu(void *obj, TClass *cl);
151
152 std::string ProduceJSON();
153};
154
155} // namespace Experimental
156} // namespace ROOT
157
158#endif
char name[80]
Definition: TGX11.cxx:109
virtual ~RArgsMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItem.hxx:112
std::vector< RMenuArgument > fArgs
Definition: RMenuItem.hxx:103
RArgsMenuItem()=default
Default constructor.
void AddArg(const RMenuArgument &arg)
Definition: RMenuItem.hxx:114
RArgsMenuItem(const std::string &name, const std::string &title)
Definition: RMenuItem.hxx:109
RCheckedMenuItem()=default
Default constructor.
virtual ~RCheckedMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItem.hxx:74
RCheckedMenuItem(const std::string &name, const std::string &title, bool checked=false)
Create checked menu item
Definition: RMenuItem.hxx:68
bool fChecked
-1 not exists, 0 - off, 1 - on
Definition: RMenuItem.hxx:62
void SetChecked(bool on=true)
Set checked state for the item, default is none.
Definition: RMenuItem.hxx:77
RMenuArgument()=default
Default constructor.
std::string fName
name of call argument
Definition: RMenuItem.hxx:84
RMenuArgument(const std::string &name, const std::string &title, const std::string &typname, const std::string &dflt="")
Definition: RMenuItem.hxx:92
void SetDefault(const std::string &dflt)
Definition: RMenuItem.hxx:98
std::string fTitle
title of call argument
Definition: RMenuItem.hxx:85
std::string fDefault
default value
Definition: RMenuItem.hxx:87
Class contains info for producing menu item on the JS side.
Definition: RMenuItem.hxx:32
std::string fTitle
title of menu item
Definition: RMenuItem.hxx:35
virtual ~RMenuItem()
virtual destructor need for vtable, used when vector of RMenuItem* is stored
Definition: RMenuItem.hxx:47
RMenuItem()=default
Default constructor.
const std::string & GetExec() const
Returns execution string for the menu item.
Definition: RMenuItem.hxx:57
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:51
std::string fExec
execute when item is activated
Definition: RMenuItem.hxx:36
std::string fName
name of the menu item
Definition: RMenuItem.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: RMenuItem.hxx:44
const std::string & GetName() const
Returns menu item name.
Definition: RMenuItem.hxx:54
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
Definition: RMenuItem.hxx:132
void Add(Detail::RMenuItem *item)
Definition: RMenuItem.hxx:130
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle)
Definition: RMenuItem.hxx:139
std::vector< Detail::RMenuItem * > fItems
list of items in the menu
Definition: RMenuItem.hxx:123
RMenuItems()=default
Default constructor.
void PopulateObjectMenu(void *obj, TClass *cl)
Definition: RMenuItem.cxx:34
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21