Logo ROOT   6.16/01
Reference Guide
RMenuItem.cxx
Go to the documentation of this file.
1/// \file RMenuItem.cxx
2/// \ingroup Base ROOT7
3/// \author Sergey Linev
4/// \date 2017-07-18
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#include "ROOT/RMenuItem.hxx"
17
18#include "TROOT.h"
19#include "TClass.h"
20#include "TList.h"
21#include "TMethod.h"
22#include "TMethodArg.h"
23#include "TMethodCall.h"
24#include "TBufferJSON.h"
25
27{
28 for (unsigned n = 0; n < fItems.size(); ++n) delete fItems[n];
29
30 fItems.clear();
31}
32
34{
35 Cleanup();
36
37 TList *lst = new TList;
38 cl->GetMenuItems(lst);
39
40 TIter iter(lst);
41 TMethod *m = 0;
42
43 while ((m = (TMethod *)iter()) != 0) {
44
45 if (m->IsMenuItem() == kMenuToggle) {
46 TString getter;
47 if (m->Getter() && strlen(m->Getter()) > 0) {
48 getter = m->Getter();
49 } else if (strncmp(m->GetName(), "Set", 3) == 0) {
50 getter = TString(m->GetName())(3, strlen(m->GetName()) - 3);
51 if (cl->GetMethodAllAny(TString("Has") + getter))
52 getter = TString("Has") + getter;
53 else if (cl->GetMethodAllAny(TString("Get") + getter))
54 getter = TString("Get") + getter;
55 else if (cl->GetMethodAllAny(TString("Is") + getter))
56 getter = TString("Is") + getter;
57 else
58 getter = "";
59 }
60
61 if ((getter.Length() > 0) && cl->GetMethodAllAny(getter)) {
62 // execute getter method to get current state of toggle item
63
64 TMethodCall *call = new TMethodCall(cl, getter, "");
65
66 if (call->ReturnType() == TMethodCall::kLong) {
67 Long_t l(0);
68 call->Execute(obj, l);
69
70 AddChkMenuItem(m->GetName(), m->GetTitle(), l != 0, Form("%s(%s)", m->GetName(), (l != 0) ? "0" : "1"));
71
72 } else {
73 // Error("CheckModifiedFlag", "Cannot get toggle value with getter %s", getter.Data());
74 }
75
76 delete call;
77 }
78 } else {
79 TList *args = m->GetListOfMethodArgs();
80
81 if (!args || (args->GetSize() == 0)) {
82 AddMenuItem(m->GetName(), m->GetTitle(), Form("%s()", m->GetName()));
83 } else {
84 Detail::RArgsMenuItem *item = new Detail::RArgsMenuItem(m->GetName(), m->GetTitle());
85 item->SetExec(Form("%s()", m->GetName()));
86
87 TIter args_iter(args);
88 TMethodArg *arg = 0;
89
90 while ((arg = dynamic_cast<TMethodArg *>(args_iter())) != 0) {
91 Detail::RMenuArgument menu_arg(arg->GetName(), arg->GetTitle(), arg->GetFullTypeName());
92 if (arg->GetDefault()) menu_arg.SetDefault(arg->GetDefault());
93 item->AddArg(menu_arg);
94 }
95
96 Add(item);
97 }
98 }
99 }
100
101 delete lst;
102}
103
105{
106 TClass *cl = gROOT->GetClass("std::vector<ROOT::Experimental::Detail::RMenuItem*>");
107
108 // FIXME: got problem with std::list<RMenuItem>, can be generic TBufferJSON
109 TString res = TBufferJSON::ConvertToJSON(&fItems, cl);
110
111 // printf("Got JSON %s\n", res.Data());
112
113 return res.Data();
114}
long Long_t
Definition: RtypesCore.h:50
@ kMenuToggle
Definition: TMethod.h:34
#define gROOT
Definition: TROOT.h:410
char * Form(const char *fmt,...)
void AddArg(const RMenuArgument &arg)
Definition: RMenuItem.hxx:114
void SetDefault(const std::string &dflt)
Definition: RMenuItem.hxx:98
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::vector< Detail::RMenuItem * > fItems
list of items in the menu
Definition: RMenuItem.hxx:123
void PopulateObjectMenu(void *obj, TClass *cl)
Definition: RMenuItem.cxx:33
static TString ConvertToJSON(const TObject *obj, Int_t compact=0, const char *member_name=nullptr)
Converts object, inherited from TObject class, to JSON string Lower digit of compact parameter define...
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
void GetMenuItems(TList *listitems)
Returns list of methods accessible by context menu.
Definition: TClass.cxx:3726
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition: TClass.cxx:4237
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
A doubly linked list.
Definition: TList.h:44
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition: TMethodArg.h:31
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: "class TDirectory*".
Definition: TMethodArg.cxx:75
const char * GetDefault() const
Get default value of method argument.
Definition: TMethodArg.cxx:58
Method or function calling interface.
Definition: TMethodCall.h:37
EReturnType ReturnType()
Returns the return type of the method.
static const EReturnType kLong
Definition: TMethodCall.h:43
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
Definition: TMethodCall.h:64
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
const char * Data() const
Definition: TString.h:364
const Int_t n
Definition: legend1.C:16
void Add(RHist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const RHist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
Definition: RHist.hxx:310
auto * m
Definition: textangle.C:8
auto * l
Definition: textangle.C:4