TQtRootSlot.cxx

Go to the documentation of this file.
00001 // @(#)root/gt:$Id: TQtRootSlot.cxx 33707 2010-06-02 06:27:34Z brun $
00002 // Author: Valery Fine      18/01/2007
00003 
00004 /****************************************************************************
00005 ** $Id: TQtRootSlot.cxx 33707 2010-06-02 06:27:34Z brun $
00006 **
00007 ** Copyright (C) 2007 by Valeri Fine. Brookhaven National Laboratory.
00008 **                                    All rights reserved.
00009 **
00010 ** This file may be distributed under the terms of the Q Public License
00011 ** as defined by Trolltech AS of Norway and appearing in the file
00012 ** LICENSE.QPL included in the packaging of this file.
00013 **
00014 *****************************************************************************/
00015 ///////////////////////////////////////////////////////////////////////////
00016 //
00017 // The TQRootSlot singleton class introduces the global SLOT to invoke
00018 // the  ROOT command line from the GUI signals
00019 // Optionally one can execute TApplication::Terminate method directly
00020 //
00021 // It provides a Qt slot to attach the the CINT C++ interpreter 
00022 // to any Qt signal
00023 // To execute any C++ statement from the GUI oen should connect 
00024 // his/her Qt signal with the Qt slot of the global instance of this class
00025 //
00026 //  connect(GUI object, SIGNAL(const char *editedLine),TQtRootSlot::CintSlot(),SLOT(ProcessLine(const char*)))
00027 //
00028 //  To terminate the ROOT from Qt GUI element connect the signal with 
00029 //  the Terminate  or TerminateAndQuite slot.
00030 //  For example to terminate ROOT and Qt smoothly do
00031 //  
00032 //  connect(qApp,SIGNAL(lastWindowClosed()),TQtRootSlot::CintSlot(),SLOT(TerminateAndQuit())
00033 //
00034 //  To terminate just ROOT (in case the Qt is terminated by the other means)
00035 //  connect(qApp,SIGNAL(lastWindowClosed()),TQtRootSlot::CintSlot(),SLOT(Terminate())
00036 //
00037 ///////////////////////////////////////////////////////////////////////////
00038 
00039 #include "TQtRootSlot.h"
00040 #include "TROOT.h"
00041 #include "TApplication.h"
00042 #include "TInterpreter.h"
00043 #include <qapplication.h>
00044 #include <QString>
00045 
00046 TQtRootSlot *TQtRootSlot::fgTQtRootSlot = 0;
00047 //____________________________________________________
00048 TQtRootSlot *TQtRootSlot::CintSlot()
00049 {
00050    // create and return the singleton
00051    if (!fgTQtRootSlot) fgTQtRootSlot = new TQtRootSlot();
00052    return fgTQtRootSlot;
00053 }
00054 //____________________________________________________
00055 void TQtRootSlot::EndOfLine()
00056 {
00057    // slot to perform the standard "EndOfLine" ROOT action
00058    // it used to update the current gPad
00059    if (gInterpreter)  gInterpreter->EndOfLineAction();
00060 }
00061 
00062 //____________________________________________________
00063 void TQtRootSlot::ProcessLine(const QString &command)
00064 {
00065      // execute the arbitrary ROOT /CINt command via 
00066      // CINT C++ interpreter and emit the result
00067    std::string cmd = command.toStdString();
00068    ProcessLine(cmd.c_str());
00069 }
00070 
00071 //____________________________________________________
00072 void TQtRootSlot::ProcessLine(const char *command)
00073 {
00074      // execute the arbitrary ROOT /CINt command via 
00075      // CINT C++ interpreter and emit the result
00076      int error;
00077      gROOT->ProcessLine(command,&error);
00078      emit Error(error);
00079 }
00080 //____________________________________________________
00081 void TQtRootSlot::Terminate(int status)const
00082 {
00083    // the dedicated slot to terminate the ROOT application
00084    // with "status"
00085    if (gApplication) gApplication->Terminate(status);
00086 }
00087 
00088 //____________________________________________________
00089 void TQtRootSlot::Terminate()const
00090 {
00091    // the dedicated slot to terminate the ROOT application
00092    // and return the "0" status
00093    Terminate(0);
00094 }
00095 
00096 //____________________________________________________
00097 void TQtRootSlot::TerminateAndQuit() const
00098 {
00099     // the dedicated  slot to terminate the ROOT application
00100     // and quit the Qt Application if any
00101 
00102    Bool_t rtrm = kTRUE;
00103    if (gApplication) {
00104       rtrm = gApplication->ReturnFromRun();
00105       gApplication->SetReturnFromRun(kTRUE);
00106       gApplication->Terminate(0);
00107    }
00108    if (qApp) qApp->quit();
00109    else if (!rtrm && gApplication ) {
00110       gApplication->SetReturnFromRun(rtrm);
00111       // to make sure the ROOT event loop is terminated
00112       gROOT->ProcessLine(".q");
00113    }
00114 }
00115 
00116 //__________________________________________________________________
00117 bool QConnectCint(const QObject * sender, const char * signal)
00118 {
00119    // Connect the Qt signal to the "execute C++ statement" via CINT SLOT
00120    // The first parameter of the Qt signal must be "const char*"
00121    return
00122    QObject::connect(sender,signal
00123       ,TQtRootSlot::CintSlot(),SLOT(ProcessLine(const char*)));
00124 }
00125 
00126 //__________________________________________________________________
00127 bool QConnectTerminate(const QObject * sender, const char * signal)
00128 {
00129    // Connect the Qt signal to the "TApplication::Terminate" method 
00130    // Any extra parameters of the Qt signal are discarded
00131    return
00132    QObject::connect(sender,signal
00133       ,TQtRootSlot::CintSlot(),SLOT(Terminate()));
00134 }

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