Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
QRootMethodDialog.cpp
Go to the documentation of this file.
1// Original code derived from QRootDialog
2// from https://go4.gsi.de project
3// Author : Denis Bertini 01.11.2000
4
5// Author: Sergey Linev, GSI 30/06/2026
6
7/*************************************************************************
8 * Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
9 * All rights reserved. *
10 * *
11 * For the licensing terms see $ROOTSYS/LICENSE. *
12 * For the list of contributors see $ROOTSYS/README/CREDITS. *
13 *************************************************************************/
14
15#include "QRootMethodDialog.h"
16
17#include <QGridLayout>
18#include <QVBoxLayout>
19#include <QHBoxLayout>
20#include <QLabel>
21#include <QPushButton>
22#include <QLineEdit>
23
24#include "TString.h"
25#include "TROOT.h"
26#include "TVirtualPad.h"
27#include "TMethod.h"
28#include "TMethodArg.h"
29#include "TMethodCall.h"
30#include "TObjString.h"
31#include "TContextMenu.h"
32
33#include <iostream>
34
35/** \class QRootMethodDialog
36 \ingroup qt6canvas
37
38Specialized dialog to enter arguments for method exection
39*/
40
41////////////////////////////////////////////////////////////////////////////////
42/// Create method dialog
43
45{
47 gridLayout->setSpacing(1);
48 gridLayout->setContentsMargins(1,1,1,1);
49
51
52 QPushButton *bOk = new QPushButton(this);
53 bOk->setText("Apply");
54 QObject::connect(bOk, &QPushButton::clicked, this, &QRootMethodDialog::accept);
55 buttLayout->addWidget(bOk);
56
57 QPushButton *bCancel = new QPushButton(this);
58 bCancel->setText("Cancel");
59 QObject::connect(bCancel, &QPushButton::clicked, this, &QRootMethodDialog::reject);
60 buttLayout->addWidget(bCancel);
61
62 argLayout = new QVBoxLayout();
63
64 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
65 QSizePolicy::Expanding));
66
67 gridLayout->addLayout(argLayout, 0, 0);
68 gridLayout->addLayout(buttLayout, 1, 0, Qt::AlignBottom);
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Add argument
73
74void QRootMethodDialog::addArg(const char *argname, const char *value, const char *)
75{
76 QLabel* lbl = new QLabel(argname);
77 argLayout->addWidget(lbl);
78
79 QLineEdit* le = new QLineEdit();
80 le->setGeometry(10,10, 130, 30);
81 le->setFocus();
82 le->setText(value);
83 argLayout->addWidget(le);
84
85 fArgs.push_back(le);
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Get argument value
90
92{
93 if ((n<0) || (n>=fArgs.size())) return QString("");
94 return fArgs[n]->text();
95}
96
97
98////////////////////////////////////////////////////////////////////////////////
99/// Run method dialog
100
102{
103 if (!menu || !object || !func)
104 return;
105
106 setWindowTitle(menu->CreateDialogTitle(object, func));
107
108 // iterate through all arguments and create appropriate input-data objects:
109 // inputlines, option menus...
110 TIter next(func->GetListOfMethodArgs());
111
112 while (auto argument = (TMethodArg *) next()) {
113 TString argTitle = menu->CreateArgumentTitle(argument);
114 TString type = argument->GetTypeName();
115 TDataType *datatype = gROOT->GetType(type);
117
118 if (datatype) {
119 basictype = datatype->GetTypeName();
120 } else {
121 if (type.CompareTo("enum") != 0)
122 std::cout << "*** Warning in Dialog(): data type is not basic type, assuming (int)\n";
123 basictype = "int";
124 }
125
126 if (TString(argument->GetTitle()).Index("*") != kNPOS) {
127 basictype += "*";
128 type = "char*";
129 }
130
131 TDataMember *m = argument->GetDataMember();
132 if (m && m->GetterMethod()) {
133
134 m->GetterMethod()->Init(object->IsA(), m->GetterMethod()->GetMethodName(), "");
135
136 // Get the current value and form it as a text:
137
138 TString val;
139
140 if (basictype == "char*") {
141 char *tdefval = nullptr;
142 m->GetterMethod()->Execute(object, "", &tdefval);
143 if (tdefval) val = tdefval;
144 } else
145 if ((basictype == "float") ||
146 (basictype == "double")) {
147 Double_t ddefval = 0.;
148 m->GetterMethod()->Execute(object, "", ddefval);
149 val = TString::Format("%g", ddefval);
150 } else
151 if ((basictype == "char") ||
152 (basictype == "int") ||
153 (basictype == "bool") ||
154 (basictype == "long") ||
155 (basictype == "short")) {
156 Longptr_t ldefval = 0;
157 m->GetterMethod()->Execute(object, "", ldefval);
158 val = TString::Format("%ld", (long) ldefval);
159 }
160
161 // Find out whether we have options ...
162
163 TList *opt;
164 if ((opt = m->GetOptions()) != nullptr) {
165 // should stop dialog
166 // workaround JAM: do not stop dialog, use textfield (for time display toggle)
167 addArg(argTitle.Data(), val.Data(), type.Data());
168 //return;
169 } else {
170 // we haven't got options - textfield ...
171 addArg(argTitle.Data(), val.Data(), type.Data());
172 }
173 } else { // if m not found ...
175 if (argument->GetDefault())
176 argDflt = argument->GetDefault();
177
178 if ((argDflt.Length() > 1) &&
179 (argDflt[0]=='\"') && (argDflt[argDflt.Length()-1]=='\"')) {
180 // cut "" from the string argument
181 argDflt.Remove(0,1);
182 argDflt.Remove(argDflt.Length()-1,1);
183 }
184
185 addArg(argTitle.Data(), argDflt.Data(), type.Data());
186 }
187 }
188
189 if (exec() != QDialog::Accepted)
190 return;
191
193 for (int n = 0; n <= func->GetListOfMethodArgs()->LastIndex(); n++) {
194 QString s = getArg(n);
195 tobjlist.AddLast(new TObjString(s.toLatin1().constData()));
196 }
197
198 menu->Execute(object, func, &tobjlist);
199}
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:90
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:132
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
#define gROOT
Definition TROOT.h:417
QVector< QLineEdit * > fArgs
QString getArg(int n)
Get argument value.
QVBoxLayout * argLayout
void addArg(const char *argname, const char *value, const char *type)
Add argument.
void methodDialog(TContextMenu *menu, TObject *object, TFunction *func)
Run method dialog.
QRootMethodDialog()
Create method dialog.
This class provides an interface to context sensitive popup menus.
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
Basic data type descriptor (datatype information is obtained from CINT).
Definition TDataType.h:44
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
TList * GetListOfMethodArgs()
Return list containing the TMethodArgs of a TFunction.
A doubly linked list.
Definition TList.h:38
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
An array of TObjects.
Definition TObjArray.h:31
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:42
virtual void Execute(const char *method, const char *params, Int_t *error=nullptr)
Execute method on this object with the given parameter string, e.g.
Definition TObject.cxx:377
Int_t LastIndex() const
Basic string class.
Definition TString.h:137
const char * Data() const
Definition TString.h:385
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2460
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:661
const Int_t n
Definition legend1.C:16
TMarker m
Definition textangle.C:8