Fork me on GitHub

Changeset 0a67548 in git


Ignore:
Timestamp:
Nov 6, 2014, 10:58:31 AM (10 years ago)
Author:
Christophe Delaere <christophe.delaere@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
53b78e8
Parents:
6301e02
Message:

Use signal/slot to communicate with GUI elements

This removes the need to keep pointers to widgets in the class itself.
Next: do something similar to communicate the progress of the summary
plot initialization.

Location:
display
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • display/DelphesEventDisplay.cc

    r6301e02 r0a67548  
    7373   delete chain_;
    7474}
     75
     76void DelphesEventDisplay::EventChanged(Int_t e)
     77{
     78  if( e!= event_id_ ) {
     79    event_id_ = e;
     80    Emit("EventChanged(Int_t)",e);
     81    load_event();
     82  }
     83}
     84
    7585
    7686DelphesEventDisplay::DelphesEventDisplay(const char *configFile, const char *inputFile, Delphes3DGeometry& det3D)
     
    370380        b->Connect("Clicked()", "DelphesEventDisplay", this, "Bck()");
    371381
    372         numberEntry_ = new TGNumberEntry(hf,0,9,-1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, treeReader_->GetEntries());
    373         hf->AddFrame(numberEntry_, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY , 2, 0, 10, 10));
    374         numberEntry_->Connect("ValueSet(Long_t)", "DelphesEventDisplay", this, "GoTo(Long_t)");
     382        TGNumberEntry* numberEntry = new TGNumberEntry(hf,0,9,-1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, treeReader_->GetEntries());
     383        hf->AddFrame(numberEntry, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY , 2, 0, 10, 10));
     384        this->Connect("EventChanged(Int_t)","TGNumberEntry",numberEntry,"SetIntNumber(Long_t)");
     385        numberEntry->GetNumberEntry()->Connect("TextChanged(char*)", "DelphesEventDisplay", this, "PreSetEv(char*)");
     386        numberEntry->GetNumberEntry()->Connect("ReturnPressed()", "DelphesEventDisplay", this, "GoTo()");
    375387       
    376388        b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
     
    381393     vf->AddFrame(hf, new TGLayoutHints(kLHintsExpandX , 2, 2, 2, 2));
    382394
    383      progress_ = new TGHProgressBar(frmMain, TGProgressBar::kFancy, 100);
    384      progress_->SetMax( treeReader_->GetEntries());
    385      progress_->ShowPosition(kTRUE, kFALSE, "Event %.0f");
    386      progress_->SetBarColor("green");
    387      vf->AddFrame(progress_, new TGLayoutHints(kLHintsExpandX, 10, 10, 5, 5));
     395     TGHProgressBar* progress = new TGHProgressBar(frmMain, TGProgressBar::kFancy, 100);
     396     progress->SetMax( treeReader_->GetEntries());
     397     progress->ShowPosition(kTRUE, kFALSE, "Event %.0f");
     398     progress->SetBarColor("green");
     399     vf->AddFrame(progress, new TGLayoutHints(kLHintsExpandX, 10, 10, 5, 5));
     400     this->Connect("EventChanged(Int_t)","TGHProgressBar",progress,"SetPosition(Float_t)");
    388401   }
    389402   frmMain->AddFrame(vf, new TGLayoutHints(kLHintsExpandX , 5, 5, 5, 5));
  • display/DelphesEventDisplay.h

    r6301e02 r0a67548  
    3434#include "TGNumberEntry.h"
    3535#include "TGProgressBar.h"
     36#include <RQ_OBJECT.h>
    3637
    3738
     
    4647class DelphesEventDisplay
    4748{
     49    RQ_OBJECT("DelphesEventDisplay")
    4850  public:
    4951    DelphesEventDisplay();
    5052    DelphesEventDisplay(const char *configFile, const char *inputFile, Delphes3DGeometry& det3D);
    5153    ~DelphesEventDisplay();
     54    void EventChanged(Int_t); // *SIGNAL*
    5255
    5356  private:
     
    5962    // Configuration and global variables.
    6063    Int_t event_id_;
     64    Int_t event_id_tmp_;
    6165    ExRootTreeReader *treeReader_;
    6266    Double_t tkRadius_, totRadius_, tkHalfLength_, muHalfLength_, bz_;
     
    6973    DelphesPlotSummary *plotSummary_;
    7074    TGStatusBar* fStatusBar_;
    71     TGNumberEntry* numberEntry_; // event_id
    72     TGHProgressBar* progress_; // event_id
    7375   
    74 
    7576    // gui controls
    7677  public:
    7778     void Fwd() { 
    7879        if (event_id_ < treeReader_->GetEntries() - 2) {
    79            ++event_id_;
    80            numberEntry_->SetIntNumber(event_id_);
    81            progress_->SetPosition(event_id_);
    82            load_event();
     80           EventChanged(event_id_+1);
    8381        } else {
    8482           printf("Already at last event.\n");
     
    8886     void Bck() {
    8987        if (event_id_ > 0) {
    90            --event_id_;
    91            numberEntry_->SetIntNumber(event_id_);
    92            progress_->SetPosition(event_id_);
    93            load_event();
     88           EventChanged(event_id_-1);
    9489        } else {
    9590           printf("Already at first event.\n");
     
    9792     }
    9893
    99     void GoTo(Long_t ev) {
    100       Int_t event = Int_t(numberEntry_->GetNumber());
    101       if (event < treeReader_->GetEntries()-1) {
    102         event_id_ = event;
    103         progress_->SetPosition(event_id_);  //TODO we could provide a signal related to event_id changes
    104         load_event();
     94    void PreSetEv(char* ev) {
     95      event_id_tmp_ = Int_t(atoi(ev));
     96    }
     97
     98    void GoTo() {
     99      if (event_id_tmp_>=0 && event_id_tmp_ < treeReader_->GetEntries()-1) {
     100        EventChanged(event_id_tmp_);
    105101      } else {
    106102        printf("Error: no such event.\n");
Note: See TracChangeset for help on using the changeset viewer.