Build for /usr/local/qt3
[snark14.git] / tools / Display / selectEvalExecutions.cpp
1 /** @file selectEvalExecutions.cpp
2     @package snark14Display
3     @author Bruno M. Carvalho and Deniz Sarioz
4     licensed under (open-source) QPL v1.0
5     which accompanies this distribution in the file QPL
6 */
7
8 #include "variables.hpp"
9 #include "selectEvalExecutions.hpp"
10 #include "chooseYVar.hpp"
11 #include "SnarkDisplay.hpp"
12
13 #include <stdio.h>
14 #include <qapplication.h>
15 #include <qframe.h>
16 #include <qlistbox.h>
17 #include <qpushbutton.h>
18 #include <qlayout.h>
19 #include <qvariant.h>
20 #include <qtooltip.h>
21 #include <qwhatsthis.h>
22
23 // extern displaywindow **displaywindowset;
24
25 /* 
26  *  Constructs a  selectEvalExecutionsWindow which is a child of 'parent', with the 
27  *  name 'name' and widget flags set to 'f' 
28  *
29  *  The dialog will by default be modeless, unless you set 'modal' to
30  *  TRUE to construct a modal dialog.
31  */
32
33 selectEvalExecutionsWindow::selectEvalExecutionsWindow( QWidget* parent,  const char* name, bool modal, WFlags fl , int x , int y )
34   : QDialog( parent, name, modal, fl )
35 {
36     QPoint topleft;
37
38     ///    myYVarWinP = 0;
39
40     const int WINWIDTH = 760;
41     const int WINHEIGHT = 350;
42     if ( !name )
43         setName( "selectEvalExecutionsWindow" );
44     resize( WINWIDTH, WINHEIGHT );     
45     setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sizePolicy().hasHeightForWidth() ) );
46     setMinimumSize( QSize( WINWIDTH, WINHEIGHT ) );
47     setMaximumSize( QSize( WINWIDTH, WINHEIGHT ) );
48     setCaption( tr( "Select Evaluate Executions to be plotted" ) );
49
50     ///    Parent=parent;
51     topleft.setX(x);
52     topleft.setY(y);
53     this->move(topleft);
54
55     const int BUTTONWIDTH = 140; // for (most) buttons
56     const int BUTTONHEIGHT = 40;
57     const int LRPADDING = 10; // left-to-right padding
58     openbutton = new QPushButton( this, "openbutton" );
59     openbutton->setGeometry( QRect( LRPADDING, 15, BUTTONWIDTH, BUTTONHEIGHT ) ); 
60     openbutton->setText( tr( "Proceed" ) ); // makes more sense than "open"
61     QObject::connect(openbutton,SIGNAL(clicked()),this,SLOT(openEvalExecutions()));
62
63     selectbutton = new QPushButton( this, "selectbutton" );
64     selectbutton->setGeometry( QRect( LRPADDING, 65, BUTTONWIDTH, BUTTONHEIGHT ) ); 
65     selectbutton->setText( tr( "Select All" ) );
66     QObject::connect(selectbutton,SIGNAL(clicked()),this,SLOT(selectAll()));
67
68     clearselectbutton = new QPushButton( this, "clearselectbutton" );
69     clearselectbutton->setGeometry( QRect( LRPADDING, 115, BUTTONWIDTH, BUTTONHEIGHT ) ); 
70     clearselectbutton->setText( tr( "Clear Selected" ) );
71     QObject::connect(clearselectbutton,SIGNAL(clicked()),this,SLOT(clearSelected()));
72
73     evalExecutionsListBox = new QListBox( this, "evalExecutionsListBox" );
74     evalExecutionsListBox->setSelectionMode(QListBox::Multi);
75     QFont f = QFont("courier",10,25,false);
76     f.setFixedPitch(true);
77     evalExecutionsListBox->setFont(f);
78
79     for(unsigned i=0; i < myEES.num_eval_execs(); i++) {
80       ///      QString s = QString("Execution %1" ) . arg(i);
81       QString s(static_cast<char*>(myEES.getExecName(i)));
82       evalExecutionsListBox->insertItem(s);      
83     }
84     int tmpi = BUTTONWIDTH + LRPADDING*2;
85     evalExecutionsListBox->setGeometry( QRect( tmpi, 15, WINWIDTH - tmpi - LRPADDING , 250 ) ); 
86     
87     Line6 = new QFrame( this, "Line6" );
88     Line6->setGeometry( QRect( 0, 280, WINWIDTH, 16 ) ); 
89     Line6->setFrameStyle( QFrame::HLine | QFrame::Sunken );
90
91     closebutton = new QPushButton( this, "closebutton" );
92     closebutton->setGeometry( QRect( 380, 300, 100, 40 ) ); 
93     closebutton->setText( tr( "Close" ) );
94     QObject::connect(closebutton,SIGNAL(clicked()),this,SLOT(reject()));
95 }
96
97 /*  
98  *  Destroys the object and frees any allocated resources
99  */
100 selectEvalExecutionsWindow::~selectEvalExecutionsWindow()
101 {
102   // no need to delete child widgets, Qt does it all for us
103 }
104
105 void selectEvalExecutionsWindow::openEvalExecutions()
106 {
107   if(std::verbose >= 2) std::cout << "in selectEvalExecutionsWindow::openEvalExecutions()" << std::endl;
108   //  int c=0,x,y;
109   int x,y;
110   QPoint topleft;
111   topleft=this->pos();
112   x=topleft.x();
113   y=topleft.y();
114   for(unsigned i=0; i < myEES.num_eval_execs(); i++) {
115     if(evalExecutionsListBox->isSelected(i)) {
116       myEES.select_exec(i);
117     } else {
118       myEES.deselect_exec(i);
119     }
120   } // for
121   ///// just to debug: 
122   ///  myEES.show_selected();
123
124   bool hasG, hasP;
125   // if stmts have necessary side effects
126   if(hasG = myEES.selectionHasGlobal()) {
127     //    if(std::verbose >=1) std::cout << "The selection has global." << std::endl;
128   }
129   if(hasP = myEES.selectionHasPBP()) {
130     //    if(std::verbose >=1) std::cout << "The selection has PBP." << std::endl;
131   }
132   if(!(hasG || hasP)) {
133     std::cout << "Selection has neither global nor PBP!  Nothing to plot!" << std::endl;
134   } else {
135     // do something like open a brand new window... onward!
136     QPoint topleft;
137     topleft = this->pos();
138     //    chooseYVarWindow* w;
139     ///    if(myYVarWinP) delete myYVarWinP;
140     //    myYVarWinP = new chooseYVarWindow(this, "blah", true, topleft.x(), topleft.y() );
141     chooseYVarWindow* myYVarWinP;
142     myYVarWinP = new chooseYVarWindow(desk, "Eval::chooseYVarWindow", false, 0, (this->pos()).x() + 30, (this->pos()).y() + 50 );
143 // w = new chooseYVarWindow(this, "Please choose the Y-variable to be plotted.", false, topleft.x() - 10, topleft.y() - 10);
144     myYVarWinP->show();
145 // w->show();
146   }
147 } // --selectEvalExecutionsWindow::openEvalExecutions()
148
149 void selectEvalExecutionsWindow::selectAll()
150 {
151   evalExecutionsListBox->selectAll(true);
152 }
153
154 void selectEvalExecutionsWindow::clearSelected()
155 {
156   evalExecutionsListBox->selectAll(false);
157 }
158