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
13 #include <qbuttongroup.h>
14 #include <qcombobox.h>
17 #include <qlineedit.h>
18 #include <qpushbutton.h>
19 #include <qradiobutton.h>
23 #include <qwhatsthis.h>
24 #include <qmessagebox.h>
27 * Constructs a selectwindow which is a child of 'parent', with the
28 * name 'name' and widget flags set to 'f'
30 * The dialog will by default be modeless, unless you set 'modal' to
31 * TRUE to construct a modal dialog.
33 @author Bruno M. Carvalho
35 selectwindow::selectwindow( QWidget* parent, const char* name, bool modal, WFlags fl )
36 : QDialog( parent, name, modal, fl )
39 setName( "selectwindow" );
41 setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sizePolicy().hasHeightForWidth() ) );
42 setMinimumSize( QSize( 390, 350 ) );
43 setMaximumSize( QSize( 390, 350 ) );
44 setCaption( tr( "Select Window" ) );
46 selectlabel = new QLabel( this, "selectlabel" );
47 selectlabel->setGeometry( QRect( 10, 10, 90, 30 ) );
48 selectlabel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, selectlabel->sizePolicy().hasHeightForWidth() ) );
49 selectlabel->setMinimumSize( QSize( 90, 30 ) );
50 selectlabel->setMaximumSize( QSize( 90, 30 ) );
51 selectlabel->setText( tr( "SELECT" ) );
53 selectbuttongroup = new QButtonGroup( this, "selectbuttongroup" );
54 selectbuttongroup->setGeometry( QRect( 20, 40, 110, 90 ) );
55 selectbuttongroup->setTitle( tr( "type" ) );
56 selectbuttongroup->setAlignment( int( QButtonGroup::AlignHCenter ) );
58 userbutton = new QRadioButton( selectbuttongroup, "userbutton" );
59 userbutton->setGeometry( QRect( 10, 20, 80, 24 ) );
60 userbutton->setText( tr( "USER" ) );
62 snarkbutton = new QRadioButton( selectbuttongroup, "snarkbutton" );
63 snarkbutton->setGeometry( QRect( 10, 50, 80, 24 ) );
64 snarkbutton->setText( tr( "SNARK" ) );
65 snarkbutton->setChecked(true);
67 // QObject::connect(okbutton,SIGNAL(clicked()),this,SLOT(checkValues()));
69 type1 = new QComboBox( this, "type1" );
70 type1->setGeometry( QRect( 20, 170, 120, 28 ) );
71 type1->insertItem("RAYSEQ",-1);
72 type1->insertItem("PROJSEQ",-1);
73 type1->insertItem("RANDOM",-1);
75 type1label = new QLabel( this, "type1label" );
76 type1label->setGeometry( QRect( 50, 150, 40, 20 ) );
77 type1label->setText( tr( "type1" ) );
79 n1 = new QLineEdit( this, "n1" );
80 n1->setGeometry( QRect( 150, 170, 40, 28 ) );
82 n1label = new QLabel( this, "n1label" );
83 n1label->setGeometry( QRect( 160, 150, 20, 20 ) );
84 n1label->setText( tr( "n1" ) );
86 type2 = new QComboBox( this, "type2" );
87 type2->setGeometry( QRect( 200, 170, 120, 28 ) );
88 type2->insertItem("",-1);
89 type2->insertItem("RAYSEQ",-1);
90 type2->insertItem("PROJSEQ",-1);
91 type2->insertItem("RANDOM",-1);
93 type2label = new QLabel( this, "type2label" );
94 type2label->setGeometry( QRect( 230, 150, 40, 20 ) );
95 type2label->setText( tr( "type2" ) );
97 n2 = new QLineEdit( this, "n2" );
98 n2->setGeometry( QRect( 330, 170, 40, 28 ) );
100 n2label = new QLabel( this, "n2label" );
101 n2label->setGeometry( QRect( 340, 150, 20, 20 ) );
102 n2label->setText( tr( "n2" ) );
104 steplabel = new QLabel( this, "steplabel" );
105 steplabel->setGeometry( QRect( 20, 245, 50, 20 ) );
106 steplabel->setText( tr( "STEP" ) );
108 mod1 = new QLineEdit( this, "mod1" );
109 mod1->setGeometry( QRect( 80, 240, 40, 28 ) );
111 mod1label = new QLabel( this, "mod1label" );
112 mod1label->setGeometry( QRect( 80, 220, 40, 20 ) );
113 mod1label->setText( tr( "mod1" ) );
115 mod2 = new QLineEdit( this, "mod2" );
116 mod2->setGeometry( QRect( 130, 240, 40, 28 ) );
118 mod2label = new QLabel( this, "mod2label" );
119 mod2label->setGeometry( QRect( 130, 220, 40, 20 ) );
120 mod2label->setText( tr( "mod2" ) );
122 Line12 = new QFrame( this, "Line12" );
123 Line12->setGeometry( QRect( 0, 275, 405, 16 ) );
124 Line12->setFrameStyle( QFrame::HLine | QFrame::Sunken );
126 efficientcb = new QCheckBox( this, "efficientcb" );
127 efficientcb->setGeometry( QRect( 147, 90, 100, 24 ) );
128 efficientcb->setText( "EFFICIENT" );
129 efficientcb->setChecked(true);
130 QObject::connect(efficientcb,SIGNAL(clicked()),this,SLOT(grayOrNot()));
133 okbutton = new QPushButton( this, "okbutton" );
134 okbutton->setGeometry( QRect( 50, 290, 100, 40 ) );
135 okbutton->setText( tr( "OK" ) );
136 QObject::connect(okbutton,SIGNAL(clicked()),this,SLOT(checkValues()));
138 cancelbutton = new QPushButton( this, "cancelbutton" );
139 cancelbutton->setGeometry( QRect( 250, 290, 100, 40 ) );
140 cancelbutton->setText( tr( "Cancel" ) );
141 QObject::connect(cancelbutton,SIGNAL(clicked()),this,SLOT(reject()));
146 @description grays out or ungrays out fields based on EFFICIENT
148 void selectwindow::grayOrNot() {
149 bool enab = (! (efficientcb->isChecked()));
151 type1->setEnabled(enab);
152 type1label->setEnabled(enab);
153 type2->setEnabled(enab);
154 type2label->setEnabled(enab);
155 n1->setEnabled(enab);
156 n2->setEnabled(enab);
157 n1label->setEnabled(enab);
158 n2label->setEnabled(enab);
159 steplabel->setEnabled(enab);
160 mod1->setEnabled(enab);
161 mod2->setEnabled(enab);
162 mod1label->setEnabled(enab);
163 mod2label->setEnabled(enab);
167 * Destroys the object and frees any allocated resources
169 selectwindow::~selectwindow()
171 // no need to delete child widgets, Qt does it all for us
174 /** Returns a string for SELECT input sequence
175 pre: assume checkValues() accepts
178 @author Bruno M. Carvalho [simplified / fixed bug #118 by Deniz]
180 QString selectwindow::getOutput()
182 QString output = "SELECT ";
183 if(userbutton->isChecked()) {
184 output += userbutton->text() + " ";
186 if(snarkbutton->isChecked()) {
187 output += snarkbutton->text() + " ";
190 if(efficientcb->isChecked()) {
191 output += efficientcb->text();
193 output += type1->currentText() + " ";
194 output += n1->text().simplifyWhiteSpace() + " ";
195 if(type2->currentItem()) {
196 output += type2->currentText() + " ";
197 output += n2->text().simplifyWhiteSpace() + " ";
199 // if passed checkValues(), add the next line iff mod1 is non-whitespace
200 if (! (mod1->text().simplifyWhiteSpace().isEmpty())) {
201 output += "\nSTEP " +
202 mod1->text().simplifyWhiteSpace() + " " +
203 mod2->text().simplifyWhiteSpace();
207 } // --selectwindow::getOutput()
209 /** @author deniz -- totally rewrote it while fixing bug #118
211 void selectwindow::checkValues()
214 if(efficientcb->isChecked()) { accept(); return; } // nothing can go wrong
217 /** the grammar of SELECT looks like:
218 > SELECT {USER, SNARK} [type1 [n1 type2 [n2] ] ]
219 (where of course args in [] are optional and nesting them has the usual meaning)
220 (this means that n1 is there iff type2 is there)
221 cond, that is, ((type1==RANDOM) && (type2 does not appear)) XOR
222 this line is followed by a line:
224 (all textbox arguments must be positive integers)
225 The new behavior coded by deniz:
226 selectwindow forces user to choose exactly one of USER and SNARK, so ignore those.
227 last 6 values: first check for existence and if exist, parse.
228 if exist, report parse errors first depending on desired types ranges etc
229 THEN check grammar (i.e., are "existences" compatible) and report grammar errors
232 bool n1E = false, type2E = false, n2E = false, mod1E = false, mod2E = false;
233 bool type1isRandom = false, type2isRandom = false;
234 int n1i, n2i, mod1i, mod2i; // integers to read values into for range checking
236 type1isRandom = (type1->currentText().contains("RANDOM") ); // do NOT rely on position in combobox
238 QString n1simple = n1->text().simplifyWhiteSpace();
239 // strs in textboxes: first check if empty, then check if type and rangewise valid
240 if (!n1simple.isEmpty()) {
243 n1i = n1simple.toInt(&ok);
245 QMessageBox::information(this,"SnarkInput","Error!\n"
246 "Invalid n1 format (must be positive integer).");
250 QMessageBox::information(this,"SnarkInput","Error!\n"
251 "n1 must be greater than 0.");
257 if(type2->currentItem()) { // if something is selected at all in combobox for type 2...
259 type2isRandom = (type2->currentText().contains("RANDOM") ); // do NOT rely on position in combobox
262 QString n2simple = n2->text().simplifyWhiteSpace();
263 if(!n2simple.isEmpty()) {
266 n2i = n2simple.toInt(&ok);
268 QMessageBox::information(this,"SnarkInput","Error!\n"
269 "Invalid n2 format (must be positive integer).");
273 QMessageBox::information(this,"SnarkInput","Error!\n"
274 "n2 must be greater than 0.");
280 QString mod1simple = mod1->text().simplifyWhiteSpace();
281 if(!mod1simple.isEmpty()) {
284 mod1i = mod1simple.toInt(&ok);
286 QMessageBox::information(this,"SnarkInput","Error!\n"
287 "Invalid mod1 format (must be positive integer).");
290 } else if(mod1i < 1) {
291 QMessageBox::information(this,"SnarkInput","Error!\n"
292 "mod1 must be greater than 0.");
298 QString mod2simple = mod2->text().simplifyWhiteSpace();
299 if(!mod2simple.isEmpty()) {
302 mod2i = mod2simple.toInt(&ok);
304 QMessageBox::information(this,"SnarkInput","Error!\n"
305 "Invalid mod2 format (must be positive integer).");
308 } else if(mod2i < 1) {
309 QMessageBox::information(this,"SnarkInput","Error!\n"
310 "mod2 must be greater than 0.");
316 // check the grammar for "first line", from the outside in
317 // if control reaches here, EFFICIENT not selected and type1 necessarily there
322 QMessageBox::information(this,"SnarkInput","Error!\n"
323 "Check your grammar--optional parameter dependencies are like:\n"
324 "[type1 [n1 type2 [n2] ] ]");
328 if(type2E) { // which of course implies type1E since we got here
329 if(type1isRandom == type2isRandom) {
330 QMessageBox::information(this,"SnarkInput","Error!\n"
331 "Since both type1 and type2 are present,\n"
332 "exactly one of them must be RANDOM");
337 // bool cond = (type1isRandom && (!type2E));
338 if(! (type1isRandom && (!type2E)) ) { // "Unless cond, 'STEP' line must follow"
339 if (! (mod1E && mod2E)) {
340 QMessageBox::information(this,"SnarkInput","Error!\n"
341 "Check your grammar: "
342 "since it's not the case that type1 is random and type2 blank, \n"
343 "values must be entered for both mod1 and mod2");
347 } else { // "Restrictions: 'STEP' must be absent if cond "
348 if (mod1E || mod2E) {
349 QMessageBox::information(this,"SnarkInput","Error!\n"
350 "Check your grammar: "
351 "since type1 is random and type2 is blank, \n"
352 "both mod1 and mod2 must be blank");
358 // control getting here implies the arguments were valid
361 } // --selectwindow::checkValues()