TQRootDialog.cxx

Go to the documentation of this file.
00001 // @(#)root/qtgsi:$Id: TQRootDialog.cxx 33896 2010-06-15 08:02:13Z bellenot $
00002 // Author: Denis Bertini, M. Al-Turany  01/11/2000
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include <stdlib.h>
00013 #include "qevent.h"
00014 #include "qdialog.h"
00015 #include "qpushbutton.h"
00016 #include "qlabel.h"
00017 #include "qobject.h"
00018 #include "qlineedit.h"
00019 #if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
00020 # include "q3hbox.h"
00021 typedef Q3HBox QHBox;
00022 #endif
00023 
00024 #include "TQRootDialog.h"
00025 #include "TMethod.h"
00026 #include "TCanvas.h"
00027 #include "TROOT.h"
00028 #include "TClass.h"
00029 #include "TObjString.h"
00030 
00031 ClassImp(TQRootDialog)
00032 
00033 //______________________________________________________________________________
00034 TQRootDialog::TQRootDialog(QWidget *wparent, const char *wname, WFlags f,
00035                          TObject* obj, TMethod *method ) :
00036    QVBox(wparent,wname, f | WType_Modal | WStyle_Dialog   ),
00037    fLineEdit(0),
00038    fParent(wparent)
00039 {
00040    // ctor
00041    fCurObj=obj;
00042    fCurMethod=method;
00043    setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
00044                             QSizePolicy::Expanding));
00045    fArgBox = new QVBox(this, "args");
00046    fArgBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
00047                  QSizePolicy::Expanding));
00048    QHBox *hbox = new QHBox(this,"buttons");
00049    QPushButton *bOk = new QPushButton("Apply",hbox,"Apply");
00050    QPushButton *bCancel = new QPushButton("Cancel",hbox,"Close");
00051    connect(bCancel,SIGNAL (clicked()), this, SLOT(close()));
00052    connect(bOk,SIGNAL( clicked() ), this, SLOT( ExecuteMethod() ));
00053 }
00054 
00055 //______________________________________________________________________________
00056 void TQRootDialog::ExecuteMethod()
00057 {
00058    // Execute ROOT methods.
00059 
00060    Bool_t deletion = kFALSE;
00061    TVirtualPad *psave =  gROOT->GetSelectedPad();
00062 
00063    //if (fCurObj)
00064    TObjArray tobjlist(fCurMethod->GetListOfMethodArgs()->LastIndex()+1);
00065 #if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
00066    typedef QList<QLineEdit*>::iterator iter;
00067    for (iter st = fList.begin(); st != fList.end(); ++st) {
00068      QString s = (*st)->text();
00069       TObjString *t = new TObjString( (const char*) s );
00070       tobjlist.AddLast((TObject*) t) ;
00071    }
00072 #else
00073    for ( QLineEdit* st = fList.first(); st; st = fList.next()) {
00074       QString s = st->text();
00075       TObjString *t = new TObjString( (const char*) s );
00076       tobjlist.AddLast((TObject*) t) ;
00077    }
00078 #endif
00079    // handle command if existing object
00080    if ( fCurObj ) {
00081       if( strcmp(fCurMethod->GetName(),"Delete") == 0  ) {
00082          if (fCurObj) {
00083             delete fCurObj;
00084             fCurObj=0;
00085             deletion = kTRUE;
00086          }
00087       }
00088       else if (  strcmp(fCurMethod->GetName(),"SetCanvasSize") == 0 ) {
00089          int value[2] = {0,0};
00090          int l=0;
00091 #if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
00092          for (iter st = fList.begin(); st != fList.end(); ++st) {
00093             QString s = (*st)->text();
00094             value[l++] = atoi ( s );
00095          }
00096 #else
00097          for ( QLineEdit* st = fList.first(); st; st = fList.next()) {
00098             QString s = st->text();
00099             value[l++] = atoi ( s );
00100          }
00101 #endif
00102          fParent->resize(value[0], value[1]);
00103       }
00104       else {
00105          // here call cint call
00106          fCurObj->Execute( fCurMethod, &tobjlist);
00107       }
00108    } // ! fCurrent Obj
00109 
00110    if (!deletion ) {
00111       gROOT->SetSelectedPad(psave);
00112       gROOT->GetSelectedPad()->Modified();
00113       gROOT->GetSelectedPad()->Update();
00114    }
00115    else {
00116       gROOT->SetSelectedPad( gPad );
00117       gROOT->GetSelectedPad()->Update();
00118    }
00119 }
00120 
00121 //______________________________________________________________________________
00122 TQRootDialog::~TQRootDialog()
00123 {
00124    // dtor
00125 
00126    if (fArgBox) delete fArgBox;
00127    if (fLineEdit) delete fLineEdit;
00128 #if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
00129    // Perhaps we need to deallocate all? 
00130    fList.erase(fList.begin(),fList.end());
00131 #else
00132    fList.remove();
00133 #endif
00134 }
00135 
00136 //______________________________________________________________________________
00137 void TQRootDialog::Add(const char* argname, const char* value, const char* /*type*/)
00138 {
00139    // Add widgets for arguments.
00140 
00141    QString s;
00142    s = value;
00143    new QLabel(argname,fArgBox);
00144    QLineEdit* lineEdit = new  QLineEdit(fArgBox);
00145    fLineEdit->setGeometry(10,10, 130, 30);
00146    fLineEdit->setFocus();
00147    fLineEdit->setText(s);
00148    fList.append( lineEdit );
00149 }
00150 
00151 //______________________________________________________________________________
00152 void TQRootDialog::Popup()
00153 {
00154    // Show the dialog.
00155 
00156    show();
00157 }
00158 
00159 //______________________________________________________________________________
00160 void TQRootDialog::closeEvent( QCloseEvent* ce )
00161 {
00162    // Handle close event.
00163 
00164    ce->accept();
00165 }

Generated on Tue Jul 5 14:22:20 2011 for ROOT_528-00b_version by  doxygen 1.5.1