Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TWebMenuItem.h
Go to the documentation of this file.
1// Author: Sergey Linev, GSI 29/06/2017
2
3/*************************************************************************
4 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_TWebMenuItem
12#define ROOT_TWebMenuItem
13
14#include "TString.h"
15#include "TClass.h"
16
17#include <string>
18#include <vector>
19#include <memory>
20
21class TClass;
22
23/** \class TWebMenuItem
24\ingroup webgui6
25
26Class contains info for producing menu item on the JS side.
27
28*/
29
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
35 std::string fClassName; ///< class name
36public:
37
38 TWebMenuItem(const std::string &name, const std::string &title) : fName(name), fTitle(title), fExec(), fClassName() {}
40 virtual ~TWebMenuItem() = default;
41
42 /** Set execution string with all required arguments,
43 * which will be executed when menu item is selected */
44 void SetExec(const std::string &exec) { fExec = exec; }
45
46 /** Set class name, to which method belongs to */
47 void SetClassName(const std::string &clname) { fClassName = clname; }
48
49 /** Returns menu item name */
50 const std::string &GetName() const { return fName; }
51
52 /** Returns execution string for the menu item */
53 const std::string &GetExec() const { return fExec; }
54};
55
56////////////////////////////////////////////////////////////////////////////
57
59protected:
60 bool fChecked{false}; ///<
61public:
62 /** Create checked menu item */
63 TWebCheckedMenuItem(const std::string &name, const std::string &title, bool checked = false)
64 : TWebMenuItem(name, title), fChecked(checked)
65 {
66 }
67
68 /** virtual destructor need for vtable, used when vector of TMenuItem* is stored */
69 ~TWebCheckedMenuItem() override = default;
70
71 /** Set checked state for the item, default is none */
72 void SetChecked(bool on = true) { fChecked = on; }
73
74 bool IsChecked() const { return fChecked; }
75};
76
77////////////////////////////////////////////////////////////////////////////
78
80protected:
81 std::string fName; ///< name of call argument
82 std::string fTitle; ///< title of call argument
83 std::string fTypeName; ///< typename
84 std::string fDefault; ///< default value
85public:
86 TWebMenuArgument() = default;
87
88 TWebMenuArgument(const std::string &name, const std::string &title, const std::string &typname,
89 const std::string &dflt = "")
90 : fName(name), fTitle(title), fTypeName(typname), fDefault(dflt)
91 {
92 }
93
94 void SetDefault(const std::string &dflt) { fDefault = dflt; }
95};
96
97////////////////////////////////////////////////////////////////////////////
98
100protected:
101 std::vector<TWebMenuArgument> fArgs;
102
103public:
104
105 TWebArgsMenuItem(const std::string &name, const std::string &title) : TWebMenuItem(name, title) {}
106
107 /** virtual destructor need for vtable, used when vector of TMenuItem* is stored */
108 ~TWebArgsMenuItem() override = default;
109
110 std::vector<TWebMenuArgument> &GetArgs() { return fArgs; }
111
112};
113
114///////////////////////////////////////////////////////////////////////
115
117protected:
118 std::string fId; ///< object identifier
119 std::vector<std::unique_ptr<TWebMenuItem>> fItems; ///< list of items in the menu
120public:
121 TWebMenuItems() = default;
122 TWebMenuItems(const std::string &snapid) : fId(snapid) {}
123
124 void Add(TWebMenuItem *item) { fItems.emplace_back(item); }
125
126 void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec, TClass *cl = nullptr)
127 {
128 TWebMenuItem *item = new TWebMenuItem(name, title);
129 item->SetExec(exec);
130 if (cl) item->SetClassName(cl->GetName());
131 Add(item);
132 }
133
134 void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle, TClass *cl = nullptr)
135 {
136 TWebCheckedMenuItem *item = new TWebCheckedMenuItem(name, title, checked);
137 item->SetExec(toggle);
138 if (cl) item->SetClassName(cl->GetName());
139 Add(item);
140 }
141
142 std::size_t Size() const { return fItems.size(); }
143
144 void PopulateObjectMenu(void *obj, TClass *cl);
145};
146
147#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
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
std::vector< TWebMenuArgument > fArgs
~TWebArgsMenuItem() override=default
virtual destructor need for vtable, used when vector of TMenuItem* is stored
std::vector< TWebMenuArgument > & GetArgs()
TWebArgsMenuItem(const std::string &name, const std::string &title)
void SetChecked(bool on=true)
Set checked state for the item, default is none.
TWebCheckedMenuItem(const std::string &name, const std::string &title, bool checked=false)
Create checked menu item
bool IsChecked() const
~TWebCheckedMenuItem() override=default
virtual destructor need for vtable, used when vector of TMenuItem* is stored
void SetDefault(const std::string &dflt)
std::string fTypeName
typename
std::string fName
name of call argument
TWebMenuArgument()=default
std::string fTitle
title of call argument
TWebMenuArgument(const std::string &name, const std::string &title, const std::string &typname, const std::string &dflt="")
std::string fDefault
default value
Class contains info for producing menu item on the JS side.
std::string fClassName
class name
TWebMenuItem(const TWebMenuItem &rhs)
std::string fExec
execute when item is activated
const std::string & GetExec() const
Returns execution string for the menu item.
TWebMenuItem(const std::string &name, const std::string &title)
std::string fName
name of the menu item
void SetExec(const std::string &exec)
Set execution string with all required arguments, which will be executed when menu item is selected
std::string fTitle
title of menu item
virtual ~TWebMenuItem()=default
void SetClassName(const std::string &clname)
Set class name, to which method belongs to
const std::string & GetName() const
Returns menu item name.
TWebMenuItems(const std::string &snapid)
std::size_t Size() const
std::string fId
object identifier
void PopulateObjectMenu(void *obj, TClass *cl)
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec, TClass *cl=nullptr)
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle, TClass *cl=nullptr)
std::vector< std::unique_ptr< TWebMenuItem > > fItems
list of items in the menu
TWebMenuItems()=default
void Add(TWebMenuItem *item)
struct void * fTypeName
Definition cppyy.h:9