GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TWebMenuItem.h
Go to the documentation of this file.
1 // Author: Sergey Linev, GSI 29/06/2017
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2018, 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 
21 class TClass;
22 
27 class TWebMenuItem {
28 protected:
29  std::string fName; // name of the menu item
30  std::string fTitle; // title of menu item
31  std::string fExec; // execute when item is activated
32  std::string fClassName; // class name
33 public:
34 
35  TWebMenuItem(const std::string &name, const std::string &title) : fName(name), fTitle(title), fExec(), fClassName() {}
36  TWebMenuItem(const TWebMenuItem &rhs) : fName(rhs.fName), fTitle(rhs.fTitle), fExec(rhs.fExec), fClassName(rhs.fClassName) {}
37  virtual ~TWebMenuItem() = default;
38 
41  void SetExec(const std::string &exec) { fExec = exec; }
42 
44  void SetClassName(const std::string &clname) { fClassName = clname; }
45 
47  const std::string &GetName() const { return fName; }
48 
50  const std::string &GetExec() const { return fExec; }
51 };
52 
54 
56 protected:
57  bool fChecked{false};
58 public:
60  TWebCheckedMenuItem(const std::string &name, const std::string &title, bool checked = false)
61  : TWebMenuItem(name, title), fChecked(checked)
62  {
63  }
64 
66  virtual ~TWebCheckedMenuItem() = default;
67 
69  void SetChecked(bool on = true) { fChecked = on; }
70 
71  bool IsChecked() const { return fChecked; }
72 };
73 
75 
77 protected:
78  std::string fName;
79  std::string fTitle;
80  std::string fTypeName;
81  std::string fDefault;
82 public:
83  TWebMenuArgument() = default;
84 
85  TWebMenuArgument(const std::string &name, const std::string &title, const std::string &typname,
86  const std::string &dflt = "")
87  : fName(name), fTitle(title), fTypeName(typname), fDefault(dflt)
88  {
89  }
90 
91  void SetDefault(const std::string &dflt) { fDefault = dflt; }
92 };
93 
95 
97 protected:
98  std::vector<TWebMenuArgument> fArgs;
99 
100 public:
101 
102  TWebArgsMenuItem(const std::string &name, const std::string &title) : TWebMenuItem(name, title) {}
103 
105  virtual ~TWebArgsMenuItem() = default;
106 
107  std::vector<TWebMenuArgument> &GetArgs() { return fArgs; }
108 
109 };
110 
112 
114 protected:
115  std::string fId;
116  std::vector<std::unique_ptr<TWebMenuItem>> fItems;
117 public:
118  TWebMenuItems() = default;
119  TWebMenuItems(const std::string &snapid) : fId(snapid) {}
120 
121  void Add(TWebMenuItem *item) { fItems.emplace_back(item); }
122 
123  void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec, TClass *cl = nullptr)
124  {
125  TWebMenuItem *item = new TWebMenuItem(name, title);
126  item->SetExec(exec);
127  if (cl) item->SetClassName(cl->GetName());
128  Add(item);
129  }
130 
131  void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle, TClass *cl = nullptr)
132  {
133  TWebCheckedMenuItem *item = new TWebCheckedMenuItem(name, title, checked);
134  item->SetExec(toggle);
135  if (cl) item->SetClassName(cl->GetName());
136  Add(item);
137  }
138 
139  std::size_t Size() const { return fItems.size(); }
140 
141  void PopulateObjectMenu(void *obj, TClass *cl);
142 };
143 
144 #endif
void SetExec(const std::string &exec)
Definition: TWebMenuItem.h:41
TWebMenuItems(const std::string &snapid)
Definition: TWebMenuItem.h:119
TWebMenuArgument(const std::string &name, const std::string &title, const std::string &typname, const std::string &dflt="")
Definition: TWebMenuItem.h:85
std::size_t Size() const
Definition: TWebMenuItem.h:139
virtual ~TWebMenuItem()=default
void PopulateObjectMenu(void *obj, TClass *cl)
std::vector< TWebMenuArgument > fArgs
Definition: TWebMenuItem.h:98
TWebArgsMenuItem(const std::string &name, const std::string &title)
Definition: TWebMenuItem.h:102
std::vector< std::unique_ptr< TWebMenuItem > > fItems
list of items in the menu
Definition: TWebMenuItem.h:116
bool IsChecked() const
Definition: TWebMenuItem.h:71
void Add(TWebMenuItem *item)
Definition: TWebMenuItem.h:121
std::string fName
name of call argument
Definition: TWebMenuItem.h:78
std::string fDefault
default value
Definition: TWebMenuItem.h:81
std::string fTitle
Definition: TWebMenuItem.h:30
TWebMenuItem(const std::string &name, const std::string &title)
Definition: TWebMenuItem.h:35
std::string fExec
Definition: TWebMenuItem.h:31
TWebCheckedMenuItem(const std::string &name, const std::string &title, bool checked=false)
Definition: TWebMenuItem.h:60
std::string fTypeName
typename
Definition: TWebMenuItem.h:80
std::string fTitle
title of call argument
Definition: TWebMenuItem.h:79
TWebMenuItems()=default
std::vector< TWebMenuArgument > & GetArgs()
Definition: TWebMenuItem.h:107
void SetChecked(bool on=true)
Definition: TWebMenuItem.h:69
const std::string & GetExec() const
Definition: TWebMenuItem.h:50
std::string fId
object identifier
Definition: TWebMenuItem.h:115
TWebMenuArgument()=default
std::string fName
Definition: TWebMenuItem.h:29
virtual ~TWebArgsMenuItem()=default
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec, TClass *cl=nullptr)
Definition: TWebMenuItem.h:123
TWebMenuItem(const TWebMenuItem &rhs)
Definition: TWebMenuItem.h:36
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle, TClass *cl=nullptr)
Definition: TWebMenuItem.h:131
const std::string & GetName() const
Definition: TWebMenuItem.h:47
virtual ~TWebCheckedMenuItem()=default
std::string fClassName
Definition: TWebMenuItem.h:32
void SetClassName(const std::string &clname)
Definition: TWebMenuItem.h:44
void SetDefault(const std::string &dflt)
Definition: TWebMenuItem.h:91