Logo ROOT   6.10/09
Reference Guide
TQRootDialog.cxx
Go to the documentation of this file.
1 // @(#)root/qtgsi:$Id$
2 // Author: Denis Bertini, M. Al-Turany 01/11/2000
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include <stdlib.h>
13 #include "qevent.h"
14 #include "qdialog.h"
15 #include "qpushbutton.h"
16 #include "qlabel.h"
17 #include "qobject.h"
18 #include "qlineedit.h"
19 #if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
20 # include "q3hbox.h"
21 typedef Q3HBox QHBox;
22 #endif
23 
24 #include "TQRootDialog.h"
25 #include "TMethod.h"
26 #include "TCanvas.h"
27 #include "TROOT.h"
28 #include "TClass.h"
29 #include "TObjString.h"
30 
31 using namespace Qt;
32 
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// ctor
37 
38 TQRootDialog::TQRootDialog(QWidget *wparent, const char *wname, WFlags f,
39  TObject* obj, TMethod *method ) :
40  QVBox(wparent,wname, f | WType_Modal | WStyle_Dialog ),
41  fLineEdit(0),
42  fCurCanvas(0),
43  fParent(wparent)
44 {
45  fCurObj=obj;
46  fCurMethod=method;
47  setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
48  QSizePolicy::Expanding));
49  fArgBox = new QVBox(this, "args");
50  fArgBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
51  QSizePolicy::Expanding));
52  QHBox *hbox = new QHBox(this,"buttons");
53  QPushButton *bOk = new QPushButton("Apply",hbox,"Apply");
54  QPushButton *bCancel = new QPushButton("Cancel",hbox,"Close");
55  connect(bCancel,SIGNAL (clicked()), this, SLOT(close()));
56  connect(bOk,SIGNAL( clicked() ), this, SLOT( ExecuteMethod() ));
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Execute ROOT methods.
61 
63 {
64  Bool_t deletion = kFALSE;
65  TVirtualPad *psave = gROOT->GetSelectedPad();
66 
67  //if (fCurObj)
68  TObjArray tobjlist(fCurMethod->GetListOfMethodArgs()->LastIndex()+1);
69 #if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
70  typedef QList<QLineEdit*>::iterator iter;
71  for (iter st = fList.begin(); st != fList.end(); ++st) {
72  QString s = (*st)->text();
73  TObjString *t = new TObjString( (const char*) s );
74  tobjlist.AddLast((TObject*) t) ;
75  }
76 #else
77  for ( QLineEdit* st = fList.first(); st; st = fList.next()) {
78  QString s = st->text();
79  TObjString *t = new TObjString( (const char*) s );
80  tobjlist.AddLast((TObject*) t) ;
81  }
82 #endif
83  // handle command if existing object
84  if ( fCurObj ) {
85  if( strcmp(fCurMethod->GetName(),"Delete") == 0 ) {
86  if (fCurObj) {
87  delete fCurObj;
88  fCurObj=0;
89  deletion = kTRUE;
90  }
91  }
92  else if ( strcmp(fCurMethod->GetName(),"SetCanvasSize") == 0 ) {
93  int value[2] = {0,0};
94  int l=0;
95 #if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
96  for (iter st = fList.begin(); st != fList.end(); ++st) {
97  QString s = (*st)->text();
98  value[l++] = atoi ( s );
99  }
100 #else
101  for ( QLineEdit* st = fList.first(); st; st = fList.next()) {
102  QString s = st->text();
103  value[l++] = atoi ( s );
104  }
105 #endif
106  fParent->resize(value[0], value[1]);
107  }
108  else {
109  // here call cint call
110  fCurObj->Execute( fCurMethod, &tobjlist);
111  }
112  } // ! fCurrent Obj
113 
114  if (!deletion ) {
115  gROOT->SetSelectedPad(psave);
116  gROOT->GetSelectedPad()->Modified();
117  gROOT->GetSelectedPad()->Update();
118  }
119  else {
120  gROOT->SetSelectedPad( gPad );
121  gROOT->GetSelectedPad()->Update();
122  }
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// dtor
127 
129 {
130  if (fArgBox) delete fArgBox;
131  if (fLineEdit) delete fLineEdit;
132 #if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
133  // Perhaps we need to deallocate all?
134  fList.erase(fList.begin(),fList.end());
135 #else
136  fList.remove();
137 #endif
138 }
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Add widgets for arguments.
142 
143 void TQRootDialog::Add(const char* argname, const char* value, const char* /*type*/)
144 {
145  QString s;
146  s = value;
147  new QLabel(argname,fArgBox);
148  QLineEdit* lineEdit = new QLineEdit(fArgBox);
149  if (fLineEdit) {
150  fLineEdit->setGeometry(10,10, 130, 30);
151  fLineEdit->setFocus();
152  fLineEdit->setText(s);
153  }
154  fList.append( lineEdit );
155 }
156 
157 ////////////////////////////////////////////////////////////////////////////////
158 /// Show the dialog.
159 
161 {
162  show();
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Handle close event.
167 
168 void TQRootDialog::closeEvent( QCloseEvent* ce )
169 {
170  ce->accept();
171 }
An array of TObjects.
Definition: TObjArray.h:37
Collectable string class.
Definition: TObjString.h:28
QWidget * fParent
Definition: TQRootCanvas.h:173
#define gROOT
Definition: TROOT.h:375
bool Bool_t
Definition: RtypesCore.h:59
void Add(const char *argname, const char *value, const char *type)
Add widgets for arguments.
void closeEvent(QCloseEvent *ce)
Handle close event.
TQRootDialog(const TQRootDialog &)
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:49
TLine * l
Definition: textangle.C:4
virtual ~TQRootDialog()
dtor
const Bool_t kFALSE
Definition: RtypesCore.h:92
#define ClassImp(name)
Definition: Rtypes.h:336
double f(double x)
Mother of all ROOT objects.
Definition: TObject.h:37
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
#define gPad
Definition: TVirtualPad.h:284
void Popup()
Show the dialog.
const Bool_t kTRUE
Definition: RtypesCore.h:91
void ExecuteMethod()
Execute ROOT methods.