Logo ROOT   6.12/07
Reference Guide
TMenuItem.hxx
Go to the documentation of this file.
1 /// \file ROOT/TMenuItem.h
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_TMenuItem
17 #define ROOT7_TMenuItem
18 
19 #include <string>
20 #include <vector>
21 
22 class TClass;
23 
24 namespace ROOT {
25 namespace Experimental {
26 namespace Detail {
27 
28 /** \class TMenuItem
29  Class contains info for producing menu item on the JS side.
30  */
31 
32 class TMenuItem {
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  TMenuItem() = 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  TMenuItem(const std::string &name, const std::string &title) : fName(name), fTitle(title), fExec() {}
45 
46  /** virtual destructor need for vtable, used when vector of TMenuItem* is stored */
47  virtual ~TMenuItem() {}
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 TCheckedMenuItem : public TMenuItem {
61 protected:
62  bool fChecked = false; ///< -1 not exists, 0 - off, 1 - on
63 public:
64  /** Default constructor */
65  TCheckedMenuItem() = default;
66 
67  /** Create checked menu item */
68  TCheckedMenuItem(const std::string &name, const std::string &title, bool checked = false)
69  : TMenuItem(name, title), fChecked(checked)
70  {
71  }
72 
73  /** virtual destructor need for vtable, used when vector of TMenuItem* is stored */
74  virtual ~TCheckedMenuItem() {}
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 
83 protected:
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
88 public:
89  /** Default constructor */
90  TMenuArgument() = default;
91 
92  TMenuArgument(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 
101 class TArgsMenuItem : public TMenuItem {
102 protected:
103  std::vector<TMenuArgument> fArgs;
104 
105 public:
106  /** Default constructor */
107  TArgsMenuItem() = default;
108 
109  TArgsMenuItem(const std::string &name, const std::string &title) : TMenuItem(name, title) {}
110 
111  /** virtual destructor need for vtable, used when vector of TMenuItem* is stored */
112  virtual ~TArgsMenuItem() {}
113 
114  void AddArg(const TMenuArgument &arg) { fArgs.push_back(arg); }
115 };
116 
117 } // namespace Detail
118 
119 ///////////////////////////////////////////////////////////////////////
120 
121 class TMenuItems {
122 protected:
123  std::vector<Detail::TMenuItem *> fItems; ///< list of items in the menu
124 public:
125  /** Default constructor */
126  TMenuItems() = default;
127 
128  ~TMenuItems() { Cleanup(); }
129 
130  void Add(Detail::TMenuItem *item) { fItems.push_back(item); }
131 
132  void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
133  {
134  Detail::TMenuItem *item = new Detail::TMenuItem(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::TCheckedMenuItem *item = new Detail::TCheckedMenuItem(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
virtual ~TArgsMenuItem()
virtual destructor need for vtable, used when vector of TMenuItem* is stored
Definition: TMenuItem.hxx:112
TMenuItem(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: TMenuItem.hxx:44
std::string fName
name of the menu item
Definition: TMenuItem.hxx:34
void SetDefault(const std::string &dflt)
Definition: TMenuItem.hxx:98
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
std::vector< TMenuArgument > fArgs
Definition: TMenuItem.hxx:103
TArgsMenuItem(const std::string &name, const std::string &title)
Definition: TMenuItem.hxx:109
TMenuItem()=default
Default constructor.
const std::string & GetExec() const
Returns execution string for the menu item.
Definition: TMenuItem.hxx:57
std::string fExec
execute when item is activated
Definition: TMenuItem.hxx:36
void SetExec(const std::string &exec)
Set execution string with all required arguments, which will be executed when menu item is selected...
Definition: TMenuItem.hxx:51
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle)
Definition: TMenuItem.hxx:139
void SetChecked(bool on=true)
Set checked state for the item, default is none.
Definition: TMenuItem.hxx:77
std::string fName
name of call argument
Definition: TMenuItem.hxx:84
std::string fTitle
title of menu item
Definition: TMenuItem.hxx:35
Class contains info for producing menu item on the JS side.
Definition: TMenuItem.hxx:32
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec)
Definition: TMenuItem.hxx:132
virtual ~TCheckedMenuItem()
virtual destructor need for vtable, used when vector of TMenuItem* is stored
Definition: TMenuItem.hxx:74
TCheckedMenuItem(const std::string &name, const std::string &title, bool checked=false)
Create checked menu item.
Definition: TMenuItem.hxx:68
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
std::vector< Detail::TMenuItem * > fItems
list of items in the menu
Definition: TMenuItem.hxx:123
TMenuArgument(const std::string &name, const std::string &title, const std::string &typname, const std::string &dflt="")
Definition: TMenuItem.hxx:92
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
Definition: THist.hxx:308
std::string fDefault
default value
Definition: TMenuItem.hxx:87
void Add(Detail::TMenuItem *item)
Definition: TMenuItem.hxx:130
virtual ~TMenuItem()
virtual destructor need for vtable, used when vector of TMenuItem* is stored
Definition: TMenuItem.hxx:47
std::string fTitle
title of call argument
Definition: TMenuItem.hxx:85
void AddArg(const TMenuArgument &arg)
Definition: TMenuItem.hxx:114
char name[80]
Definition: TGX11.cxx:109
const std::string & GetName() const
Returns menu item name.
Definition: TMenuItem.hxx:54