29 #include <qcheckbox.h>
30 #include <qlineedit.h>
31 #include <qcombobox.h>
32 #include <qlistview.h>
33 #include <qtabwidget.h>
34 #include <qvalidator.h>
35 #include <qpushbutton.h>
36 #include <qmessagebox.h>
40 : QDialog(d_, 0, TRUE, Qt::WDestructiveClose)
45 setCaption(tr(
"Edit Optimization Properties"));
47 Expr.setPattern(
"[\\w_]+");
49 numVal =
new QDoubleValidator(
this);
50 intVal =
new QIntValidator(
this);
52 all =
new QVBoxLayout(
this);
53 QTabWidget *
t =
new QTabWidget(
this);
57 QWidget *Tab1 =
new QWidget(t);
58 QGridLayout *gp1 =
new QGridLayout(Tab1,3,2,3,3);
60 gp1->addWidget(
new QLabel(tr(
"Name:"), Tab1), 0,0);
65 gp1->addWidget(
new QLabel(tr(
"Simulation:"), Tab1), 1,0);
70 t->addTab(Tab1, tr(
"General"));
73 QWidget *Tab4 =
new QWidget(t);
74 QGridLayout *gp4 =
new QGridLayout(Tab4,11,2,3,3);
76 gp4->addWidget(
new QLabel(tr(
"Method:"), Tab4), 0,0);
90 gp4->addWidget(
new QLabel(tr(
"Maximum number of iterations:"), Tab4), 1,0);
95 gp4->addWidget(
new QLabel(tr(
"Output refresh cycle:"), Tab4), 2,0);
100 gp4->addWidget(
new QLabel(tr(
"Number of parents:"), Tab4), 3,0);
105 gp4->addWidget(
new QLabel(tr(
"Constant F:"), Tab4), 4,0);
110 gp4->addWidget(
new QLabel(tr(
"Crossing over factor:"), Tab4), 5,0);
115 gp4->addWidget(
new QLabel(tr(
"Pseudo random number seed:"), Tab4), 6,0);
120 gp4->addWidget(
new QLabel(tr(
"Minimum cost variance:"), Tab4), 7,0);
125 gp4->addWidget(
new QLabel(tr(
"Cost objectives:"), Tab4), 8,0);
130 gp4->addWidget(
new QLabel(tr(
"Cost constraints:"), Tab4), 9,0);
135 t->addTab(Tab4, tr(
"Algorithm"));
138 QWidget *Tab2 =
new QWidget(t);
139 QGridLayout *gp2 =
new QGridLayout(Tab2,5,3,3,3);
142 VarList->addColumn(tr(
"Name"));
143 VarList->addColumn(tr(
"active"));
144 VarList->addColumn(tr(
"initial"));
147 VarList->addColumn(tr(
"Type"));
149 gp2->addMultiCellWidget(
VarList,0,0,0,2);
150 connect(
VarList, SIGNAL(selectionChanged(QListViewItem*)),
151 SLOT(slotEditVariable(QListViewItem*)));
153 QHBox *VarLine =
new QHBox(Tab2);
154 VarLine->setSpacing(3);
155 gp2->addMultiCellWidget(VarLine, 1,1,0,2);
157 new QLabel(tr(
"Name:"), VarLine);
160 connect(
VarNameEdit, SIGNAL(textChanged(
const QString&)),
161 SLOT(slotChangeVarName(
const QString&)));
165 SLOT(slotChangeVarActive(
bool)));
167 gp2->addWidget(
new QLabel(tr(
"initial:"), Tab2), 2,0);
168 gp2->addWidget(
new QLabel(tr(
"min:"), Tab2), 2,1);
169 gp2->addWidget(
new QLabel(tr(
"max:"), Tab2), 2,2);
173 connect(
VarInitEdit, SIGNAL(textChanged(
const QString&)),
174 SLOT(slotChangeVarInit(
const QString&)));
178 connect(
VarMinEdit, SIGNAL(textChanged(
const QString&)),
179 SLOT(slotChangeVarMin(
const QString&)));
183 connect(
VarMaxEdit, SIGNAL(textChanged(
const QString&)),
184 SLOT(slotChangeVarMax(
const QString&)));
186 QHBox *VarButtons =
new QHBox(Tab2);
187 VarButtons->setSpacing(3);
188 gp2->addMultiCellWidget(VarButtons, 4,4,0,2);
190 new QLabel(tr(
"Type:"), VarButtons);
196 connect(
VarTypeCombo, SIGNAL(activated(
const QString&)),
197 SLOT(slotChangeVarType(
const QString&)));
199 VarButtons->setStretchFactor(
new QWidget(VarButtons), 10);
200 QPushButton *AddVar_Butt =
new QPushButton(tr(
"Add"), VarButtons);
201 connect(AddVar_Butt, SIGNAL(clicked()), SLOT(slotAddVariable()));
202 QPushButton *DelVar_Butt =
new QPushButton(tr(
"Delete"), VarButtons);
203 connect(DelVar_Butt, SIGNAL(clicked()), SLOT(slotDeleteVariable()));
205 t->addTab(Tab2, tr(
"Variables"));
208 QWidget *Tab3 =
new QWidget(t);
209 QGridLayout *gp3 =
new QGridLayout(Tab3,4,3,3,3);
216 gp3->addMultiCellWidget(
GoalList,0,0,0,2);
217 connect(
GoalList, SIGNAL(selectionChanged(QListViewItem*)),
218 SLOT(slotEditGoal(QListViewItem*)));
220 gp3->addWidget(
new QLabel(tr(
"Name:"), Tab3), 1,0);
224 connect(
GoalNameEdit, SIGNAL(textChanged(
const QString&)),
225 SLOT(slotChangeGoalName(
const QString&)));
227 gp3->addWidget(
new QLabel(tr(
"Value:"), Tab3), 2,0);
231 connect(
GoalNumEdit, SIGNAL(textChanged(
const QString&)),
232 SLOT(slotChangeGoalNum(
const QString&)));
243 SLOT(slotChangeGoalType(
const QString&)));
245 QHBox *GoalButtons =
new QHBox(Tab3);
246 GoalButtons->setSpacing(3);
247 gp3->addMultiCellWidget(GoalButtons, 3,3,0,2);
249 GoalButtons->setStretchFactor(
new QWidget(GoalButtons),5);
250 QPushButton *AddGoal_Butt =
new QPushButton(tr(
"Add"), GoalButtons);
251 connect(AddGoal_Butt, SIGNAL(clicked()), SLOT(slotAddGoal()));
252 QPushButton *DelGoal_Butt =
new QPushButton(tr(
"Delete"), GoalButtons);
253 connect(DelGoal_Butt, SIGNAL(clicked()), SLOT(slotDeleteGoal()));
255 t->addTab(Tab3, tr(
"Goals"));
259 QHBox *Butts =
new QHBox(
this);
260 Butts->setSpacing(3);
262 all->addWidget(Butts);
264 QPushButton *OkButt =
new QPushButton(tr(
"OK"), Butts);
265 connect(OkButt, SIGNAL(clicked()), SLOT(slotOK()));
266 QPushButton *ApplyButt =
new QPushButton(tr(
"Apply"), Butts);
267 connect(ApplyButt, SIGNAL(clicked()), SLOT(slotApply()));
268 QPushButton *CancelButt =
new QPushButton(tr(
"Cancel"), Butts);
269 connect(CancelButt, SIGNAL(clicked()), SLOT(slotCancel()));
278 if(pc->
Model[0] ==
'.' && pc->
Model !=
".Opt")
283 if(!pp->
Value.isEmpty())
287 if(!pp->
Value.isEmpty()) {
303 if(pp->
Name ==
"Var") {
305 pp->
Value.section(
'|',1,1) ==
"yes" ? tr(
"yes") : tr(
"no"),
306 pp->
Value.section(
'|',2,2),
307 pp->
Value.section(
'|',3,3), pp->
Value.section(
'|',4,4),
308 ((pp->
Value.section(
'|',5,5)==
"LIN_DOUBLE")?tr(
"linear double") :
309 ((pp->
Value.section(
'|',5,5)==
"LOG_DOUBLE")?tr(
"logarithmic double") :
310 ((pp->
Value.section(
'|',5,5)==
"LIN_INT")?tr(
"linear integer") :
311 tr(
"logarithmic integer")))));
313 if(pp->
Name ==
"Goal") {
315 ((pp->
Value.section(
'|',1,1) ==
"MIN") ? tr(
"minimize") :
316 ((pp->
Value.section(
'|',1,1) ==
"MAX") ? tr(
"maximize") :
317 ((pp->
Value.section(
'|',1,1) ==
"LE") ? tr(
"less") :
318 ((pp->
Value.section(
'|',1,1) ==
"GE") ? tr(
"greater") :
319 ((pp->
Value.section(
'|',1,1) ==
"EQ") ? tr(
"equal") :
321 pp->
Value.section(
'|',2,2));
337 void OptimizeDialog::slotEditVariable(QListViewItem *Item)
362 void OptimizeDialog::slotAddVariable()
366 QMessageBox::critical(
this, tr(
"Error"),
367 tr(
"Every text field must be non-empty!"));
372 for(item =
VarList->firstChild(); item != 0; item = item->itemBelow())
374 QMessageBox::critical(
this, tr(
"Error"),
390 void OptimizeDialog::slotDeleteVariable()
392 QListViewItem *next_item = 0;
394 QListViewItem *Item =
VarList->selectedItem();
396 next_item = Item->itemBelow();
397 if(next_item == 0) next_item = Item->itemAbove();
402 slotEditVariable(next_item);
406 void OptimizeDialog::slotChangeVarActive(
bool On)
408 QListViewItem *Item =
VarList->selectedItem();
409 if(Item == 0)
return;
411 Item->setText(1, On ? tr(
"yes") : tr(
"no"));
415 void OptimizeDialog::slotChangeVarName(
const QString&)
421 void OptimizeDialog::slotChangeVarInit(
const QString&
Text)
423 QListViewItem *Item =
VarList->selectedItem();
424 if(Item == 0)
return;
426 Item->setText(2, Text);
430 void OptimizeDialog::slotChangeVarMin(
const QString& Text)
432 QListViewItem *Item =
VarList->selectedItem();
433 if(Item == 0)
return;
435 Item->setText(3, Text);
439 void OptimizeDialog::slotChangeVarMax(
const QString& Text)
441 QListViewItem *Item =
VarList->selectedItem();
442 if(Item == 0)
return;
444 Item->setText(4, Text);
448 void OptimizeDialog::slotChangeVarType(
const QString& Text)
450 QListViewItem *Item =
VarList->selectedItem();
451 if(Item == 0)
return;
453 Item->setText(5, Text);
457 void OptimizeDialog::slotEditGoal(QListViewItem *Item)
476 void OptimizeDialog::slotAddGoal()
479 QMessageBox::critical(
this, tr(
"Error"),
480 tr(
"Every text field must be non-empty!"));
485 for(item =
GoalList->firstChild(); item != 0; item = item->itemBelow())
487 QMessageBox::critical(
this, tr(
"Error"),
501 void OptimizeDialog::slotDeleteGoal()
503 QListViewItem *next_item = 0;
505 QListViewItem *Item =
GoalList->selectedItem();
507 next_item = Item->itemBelow();
508 if(next_item == 0) next_item = Item->itemAbove();
513 slotEditGoal(next_item);
517 void OptimizeDialog::slotChangeGoalName(
const QString&)
523 void OptimizeDialog::slotChangeGoalType(
const QString& Text)
525 QListViewItem *Item =
GoalList->selectedItem();
526 if(Item == 0)
return;
528 Item->setText(1, Text);
532 void OptimizeDialog::slotChangeGoalNum(
const QString& Text)
534 QListViewItem *Item =
GoalList->selectedItem();
535 if(Item == 0)
return;
537 Item->setText(2, Text);
541 void OptimizeDialog::slotOK()
548 void OptimizeDialog::slotApply()
571 Prop = QString::number(
MethodCombo->currentItem()+1) +
"|" +
589 for(item =
VarList->firstChild(); item != 0; item = item->itemBelow()) {
590 Prop = item->text(0) +
"|" +
591 ((item->text(1) == tr(
"yes")) ?
"yes" :
"no") +
"|" +
592 item->text(2) +
"|" + item->text(3) +
"|" +
593 item->text(4) +
"|" +
594 ((item->text(5) == tr(
"linear double")) ?
"LIN_DOUBLE" :
595 ((item->text(5) == tr(
"logarithmic double")) ?
"LOG_DOUBLE" :
596 ((item->text(5) == tr(
"linear integer")) ?
"LIN_INT" :
"LOG_INT")));
599 if(pp->
Name !=
"Var") {
603 if(pp->
Value != Prop) {
615 for(item =
GoalList->firstChild(); item != 0; item = item->itemBelow()) {
616 Prop = item->text(0) +
"|" +
617 ((item->text(1) == tr(
"minimize")) ?
"MIN" :
618 ((item->text(1) == tr(
"maximize")) ?
"MAX" :
619 ((item->text(1) == tr(
"less")) ?
"LE" :
620 ((item->text(1) == tr(
"greater")) ?
"GE" :
621 ((item->text(1) == tr(
"equal")) ?
"EQ" :
"MON"))))) +
"|" +
625 if(pp->
Name !=
"Goal") {
629 if(pp->
Value != Prop) {
651 Doc->viewport()->repaint();
656 void OptimizeDialog::slotCancel()