My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
optimizedialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  optimizedialog.cpp
3  --------------------
4  begin : Sun Jul 30 2006
5  copyright : (C) 2006 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 
22 #include "optimizedialog.h"
23 #include "opt_sim.h"
24 #include "schematic.h"
25 
26 #include <qhbox.h>
27 #include <qlabel.h>
28 #include <qlayout.h>
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>
37 
38 
40  : QDialog(d_, 0, TRUE, Qt::WDestructiveClose)
41 {
42  Comp = c_;
43  Doc = d_;
44  changed = false;
45  setCaption(tr("Edit Optimization Properties"));
46 
47  Expr.setPattern("[\\w_]+");
48  Validator = new QRegExpValidator(Expr, this);
49  numVal = new QDoubleValidator(this);
50  intVal = new QIntValidator(this);
51 
52  all = new QVBoxLayout(this); // to provide the neccessary size
53  QTabWidget *t = new QTabWidget(this);
54  all->addWidget(t);
55 
56  // ...........................................................
57  QWidget *Tab1 = new QWidget(t);
58  QGridLayout *gp1 = new QGridLayout(Tab1,3,2,3,3);
59 
60  gp1->addWidget(new QLabel(tr("Name:"), Tab1), 0,0);
61  NameEdit = new QLineEdit(Tab1);
62  NameEdit->setValidator(Validator);
63  gp1->addWidget(NameEdit,0,1);
64 
65  gp1->addWidget(new QLabel(tr("Simulation:"), Tab1), 1,0);
66  SimEdit = new QComboBox(Tab1);
67  SimEdit->setEditable(true);
68  gp1->addWidget(SimEdit,1,1);
69 
70  t->addTab(Tab1, tr("General"));
71 
72  // ...........................................................
73  QWidget *Tab4 = new QWidget(t);
74  QGridLayout *gp4 = new QGridLayout(Tab4,11,2,3,3);
75 
76  gp4->addWidget(new QLabel(tr("Method:"), Tab4), 0,0);
77  MethodCombo = new QComboBox(Tab4);
78  MethodCombo->insertItem("DE/best/1/exp");
79  MethodCombo->insertItem("DE/rand/1/exp");
80  MethodCombo->insertItem("DE/rand-to-best/1/exp");
81  MethodCombo->insertItem("DE/best/2/exp");
82  MethodCombo->insertItem("DE/rand/1/exp");
83  MethodCombo->insertItem("DE/best/1/bin");
84  MethodCombo->insertItem("DE/rand/1/bin");
85  MethodCombo->insertItem("DE/rand-to-best/1/bin");
86  MethodCombo->insertItem("DE/best/2/bin");
87  MethodCombo->insertItem("DE/rand/2/bin");
88  gp4->addWidget(MethodCombo,0,1);
89 
90  gp4->addWidget(new QLabel(tr("Maximum number of iterations:"), Tab4), 1,0);
91  IterEdit = new QLineEdit(Tab4);
92  IterEdit->setValidator(intVal);
93  gp4->addWidget(IterEdit,1,1);
94 
95  gp4->addWidget(new QLabel(tr("Output refresh cycle:"), Tab4), 2,0);
96  RefreshEdit = new QLineEdit(Tab4);
97  RefreshEdit->setValidator(intVal);
98  gp4->addWidget(RefreshEdit,2,1);
99 
100  gp4->addWidget(new QLabel(tr("Number of parents:"), Tab4), 3,0);
101  ParentsEdit = new QLineEdit(Tab4);
102  ParentsEdit->setValidator(intVal);
103  gp4->addWidget(ParentsEdit,3,1);
104 
105  gp4->addWidget(new QLabel(tr("Constant F:"), Tab4), 4,0);
106  ConstEdit = new QLineEdit(Tab4);
107  ConstEdit->setValidator(new QDoubleValidator(0.0,2.0,20,ConstEdit));
108  gp4->addWidget(ConstEdit,4,1);
109 
110  gp4->addWidget(new QLabel(tr("Crossing over factor:"), Tab4), 5,0);
111  CrossEdit = new QLineEdit(Tab4);
112  CrossEdit->setValidator(new QDoubleValidator(0.0,1.0,20,CrossEdit));
113  gp4->addWidget(CrossEdit,5,1);
114 
115  gp4->addWidget(new QLabel(tr("Pseudo random number seed:"), Tab4), 6,0);
116  SeedEdit = new QLineEdit(Tab4);
117  SeedEdit->setValidator(numVal);
118  gp4->addWidget(SeedEdit,6,1);
119 
120  gp4->addWidget(new QLabel(tr("Minimum cost variance:"), Tab4), 7,0);
121  CostVarEdit = new QLineEdit(Tab4);
122  CostVarEdit->setValidator(numVal);
123  gp4->addWidget(CostVarEdit,7,1);
124 
125  gp4->addWidget(new QLabel(tr("Cost objectives:"), Tab4), 8,0);
126  CostObjEdit = new QLineEdit(Tab4);
127  CostObjEdit->setValidator(numVal);
128  gp4->addWidget(CostObjEdit,8,1);
129 
130  gp4->addWidget(new QLabel(tr("Cost constraints:"), Tab4), 9,0);
131  CostConEdit = new QLineEdit(Tab4);
132  CostConEdit->setValidator(numVal);
133  gp4->addWidget(CostConEdit,9,1);
134 
135  t->addTab(Tab4, tr("Algorithm"));
136 
137  // ...........................................................
138  QWidget *Tab2 = new QWidget(t);
139  QGridLayout *gp2 = new QGridLayout(Tab2,5,3,3,3);
140 
141  VarList = new QListView(Tab2);
142  VarList->addColumn(tr("Name"));
143  VarList->addColumn(tr("active"));
144  VarList->addColumn(tr("initial"));
145  VarList->addColumn(tr("min"));
146  VarList->addColumn(tr("max"));
147  VarList->addColumn(tr("Type"));
148  VarList->setSorting(-1); // no sorting
149  gp2->addMultiCellWidget(VarList,0,0,0,2);
150  connect(VarList, SIGNAL(selectionChanged(QListViewItem*)),
151  SLOT(slotEditVariable(QListViewItem*)));
152 
153  QHBox *VarLine = new QHBox(Tab2);
154  VarLine->setSpacing(3);
155  gp2->addMultiCellWidget(VarLine, 1,1,0,2);
156 
157  new QLabel(tr("Name:"), VarLine);
158  VarNameEdit = new QLineEdit(VarLine);
159  VarNameEdit->setValidator(Validator);
160  connect(VarNameEdit, SIGNAL(textChanged(const QString&)),
161  SLOT(slotChangeVarName(const QString&)));
162  VarActiveCheck = new QCheckBox(tr("active"), VarLine);
163  VarActiveCheck->setChecked(true);
164  connect(VarActiveCheck, SIGNAL(toggled(bool)),
165  SLOT(slotChangeVarActive(bool)));
166 
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);
170  VarInitEdit = new QLineEdit(Tab2);
171  VarInitEdit->setValidator(numVal);
172  gp2->addWidget(VarInitEdit,3,0);
173  connect(VarInitEdit, SIGNAL(textChanged(const QString&)),
174  SLOT(slotChangeVarInit(const QString&)));
175  VarMinEdit = new QLineEdit(Tab2);
176  VarMinEdit->setValidator(numVal);
177  gp2->addWidget(VarMinEdit,3,1);
178  connect(VarMinEdit, SIGNAL(textChanged(const QString&)),
179  SLOT(slotChangeVarMin(const QString&)));
180  VarMaxEdit = new QLineEdit(Tab2);
181  VarMaxEdit->setValidator(numVal);
182  gp2->addWidget(VarMaxEdit,3,2);
183  connect(VarMaxEdit, SIGNAL(textChanged(const QString&)),
184  SLOT(slotChangeVarMax(const QString&)));
185 
186  QHBox *VarButtons = new QHBox(Tab2);
187  VarButtons->setSpacing(3);
188  gp2->addMultiCellWidget(VarButtons, 4,4,0,2);
189 
190  new QLabel(tr("Type:"), VarButtons);
191  VarTypeCombo = new QComboBox(VarButtons);
192  VarTypeCombo->insertItem(tr("linear double"));
193  VarTypeCombo->insertItem(tr("logarithmic double"));
194  VarTypeCombo->insertItem(tr("linear integer"));
195  VarTypeCombo->insertItem(tr("logarithmic integer"));
196  connect(VarTypeCombo, SIGNAL(activated(const QString&)),
197  SLOT(slotChangeVarType(const QString&)));
198 
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()));
204 
205  t->addTab(Tab2, tr("Variables"));
206 
207  // ...........................................................
208  QWidget *Tab3 = new QWidget(t);
209  QGridLayout *gp3 = new QGridLayout(Tab3,4,3,3,3);
210 
211  GoalList = new QListView(Tab3);
212  GoalList->addColumn(tr("Name"));
213  GoalList->addColumn(tr("Type"));
214  GoalList->addColumn(tr("Value"));
215  GoalList->setSorting(-1); // no sorting
216  gp3->addMultiCellWidget(GoalList,0,0,0,2);
217  connect(GoalList, SIGNAL(selectionChanged(QListViewItem*)),
218  SLOT(slotEditGoal(QListViewItem*)));
219 
220  gp3->addWidget(new QLabel(tr("Name:"), Tab3), 1,0);
221  GoalNameEdit = new QLineEdit(Tab3);
222  GoalNameEdit->setValidator(Validator);
223  gp3->addWidget(GoalNameEdit,1,1);
224  connect(GoalNameEdit, SIGNAL(textChanged(const QString&)),
225  SLOT(slotChangeGoalName(const QString&)));
226 
227  gp3->addWidget(new QLabel(tr("Value:"), Tab3), 2,0);
228  GoalNumEdit = new QLineEdit(Tab3);
229  GoalNumEdit->setValidator(numVal);
230  gp3->addWidget(GoalNumEdit,2,1);
231  connect(GoalNumEdit, SIGNAL(textChanged(const QString&)),
232  SLOT(slotChangeGoalNum(const QString&)));
233 
234  GoalTypeCombo = new QComboBox(Tab3);
235  GoalTypeCombo->insertItem(tr("minimize"));
236  GoalTypeCombo->insertItem(tr("maximize"));
237  GoalTypeCombo->insertItem(tr("less"));
238  GoalTypeCombo->insertItem(tr("greater"));
239  GoalTypeCombo->insertItem(tr("equal"));
240  GoalTypeCombo->insertItem(tr("monitor"));
241  gp3->addWidget(GoalTypeCombo,2,2);
242  connect(GoalTypeCombo, SIGNAL(activated(const QString&)),
243  SLOT(slotChangeGoalType(const QString&)));
244 
245  QHBox *GoalButtons = new QHBox(Tab3);
246  GoalButtons->setSpacing(3);
247  gp3->addMultiCellWidget(GoalButtons, 3,3,0,2);
248 
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()));
254 
255  t->addTab(Tab3, tr("Goals"));
256 
257  // ...........................................................
258  // buttons on the bottom of the dialog (independent of the TabWidget)
259  QHBox *Butts = new QHBox(this);
260  Butts->setSpacing(3);
261  Butts->setMargin(3);
262  all->addWidget(Butts);
263 
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()));
270 
271  OkButt->setFocus();
272 
273  // ...........................................................
274 
275  Component *pc;
276  for(pc=Doc->Components->first(); pc!=0; pc=Doc->Components->next())
277  if(pc != Comp)
278  if(pc->Model[0] == '.' && pc->Model != ".Opt")
279  SimEdit->insertItem(pc->Name);
280 
281  Property *pp;
282  pp = Comp->Props.at(0);
283  if(!pp->Value.isEmpty())
284  SimEdit->setCurrentText(pp->Value);
285 
286  pp = Comp->Props.at(1);
287  if(!pp->Value.isEmpty()) {
288  MethodCombo->setCurrentItem(pp->Value.section('|',0,0).toInt()-1);
289  IterEdit->setText(pp->Value.section('|',1,1));
290  RefreshEdit->setText(pp->Value.section('|',2,2));
291  ParentsEdit->setText(pp->Value.section('|',3,3));
292  ConstEdit->setText(pp->Value.section('|',4,4));
293  CrossEdit->setText(pp->Value.section('|',5,5));
294  SeedEdit->setText(pp->Value.section('|',6,6));
295  CostVarEdit->setText(pp->Value.section('|',7,7));
296  CostObjEdit->setText(pp->Value.section('|',8,8));
297  CostConEdit->setText(pp->Value.section('|',9,9));
298  }
299 
300  NameEdit->setText(Comp->Name);
301 
302  for(pp = Comp->Props.at(2); pp != 0; pp = Comp->Props.next()) {
303  if(pp->Name == "Var") {
304  new QListViewItem(VarList, pp->Value.section('|',0,0),
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")))));
312  }
313  if(pp->Name == "Goal") {
314  new QListViewItem(GoalList, pp->Value.section('|',0,0),
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") :
320  tr("monitor")))))),
321  pp->Value.section('|',2,2));
322  }
323  }
324 
325  resize(300, 250);
326 }
327 
329 {
330  delete all;
331  delete numVal;
332  delete intVal;
333  delete Validator;
334 }
335 
336 // -----------------------------------------------------------
337 void OptimizeDialog::slotEditVariable(QListViewItem *Item)
338 {
339  VarNameEdit->blockSignals(true);
340 
341  if(Item == 0) {
342  VarNameEdit->clear();
343  VarActiveCheck->setChecked(true);
344  VarInitEdit->clear();
345  VarMinEdit->clear();
346  VarMaxEdit->clear();
347  VarTypeCombo->setCurrentItem(0);
348  VarNameEdit->blockSignals(false);
349  return;
350  }
351 
352  VarNameEdit->setText(Item->text(0));
353  VarActiveCheck->setChecked(Item->text(1) == tr("yes"));
354  VarInitEdit->setText(Item->text(2));
355  VarMinEdit->setText(Item->text(3));
356  VarMaxEdit->setText(Item->text(4));
357  VarTypeCombo->setCurrentText(Item->text(5));
358  VarNameEdit->blockSignals(false);
359 }
360 
361 // -----------------------------------------------------------
362 void OptimizeDialog::slotAddVariable()
363 {
364  if(VarNameEdit->text().isEmpty() || VarInitEdit->text().isEmpty() ||
365  VarMinEdit->text().isEmpty() || VarMaxEdit->text().isEmpty()) {
366  QMessageBox::critical(this, tr("Error"),
367  tr("Every text field must be non-empty!"));
368  return;
369  }
370 
371  QListViewItem *item;
372  for(item = VarList->firstChild(); item != 0; item = item->itemBelow())
373  if(item->text(0) == VarNameEdit->text()) {
374  QMessageBox::critical(this, tr("Error"),
375  tr("Variable \"%1\" already in list!").arg(VarNameEdit->text()));
376  return;
377  }
378 
379 
380  new QListViewItem(VarList, VarNameEdit->text(),
381  VarActiveCheck->isChecked() ? tr("yes") : tr("no"),
382  VarInitEdit->text(), VarMinEdit->text(), VarMaxEdit->text(),
383  VarTypeCombo->currentText());
384 
385  slotEditVariable(0); // clear entry fields
386  VarList->clearSelection();
387 }
388 
389 // -----------------------------------------------------------
390 void OptimizeDialog::slotDeleteVariable()
391 {
392  QListViewItem *next_item = 0;
393 
394  QListViewItem *Item = VarList->selectedItem();
395  if(Item) {
396  next_item = Item->itemBelow();
397  if(next_item == 0) next_item = Item->itemAbove();
398  VarList->takeItem(Item); // remove from ListView
399  delete Item; // delete item
400  }
401 
402  slotEditVariable(next_item);
403 }
404 
405 // -----------------------------------------------------------
406 void OptimizeDialog::slotChangeVarActive(bool On)
407 {
408  QListViewItem *Item = VarList->selectedItem();
409  if(Item == 0) return;
410 
411  Item->setText(1, On ? tr("yes") : tr("no"));
412 }
413 
414 // -----------------------------------------------------------
415 void OptimizeDialog::slotChangeVarName(const QString&)
416 {
417  VarList->clearSelection();
418 }
419 
420 // -----------------------------------------------------------
421 void OptimizeDialog::slotChangeVarInit(const QString& Text)
422 {
423  QListViewItem *Item = VarList->selectedItem();
424  if(Item == 0) return;
425 
426  Item->setText(2, Text);
427 }
428 
429 // -----------------------------------------------------------
430 void OptimizeDialog::slotChangeVarMin(const QString& Text)
431 {
432  QListViewItem *Item = VarList->selectedItem();
433  if(Item == 0) return;
434 
435  Item->setText(3, Text);
436 }
437 
438 // -----------------------------------------------------------
439 void OptimizeDialog::slotChangeVarMax(const QString& Text)
440 {
441  QListViewItem *Item = VarList->selectedItem();
442  if(Item == 0) return;
443 
444  Item->setText(4, Text);
445 }
446 
447 // -----------------------------------------------------------
448 void OptimizeDialog::slotChangeVarType(const QString& Text)
449 {
450  QListViewItem *Item = VarList->selectedItem();
451  if(Item == 0) return;
452 
453  Item->setText(5, Text);
454 }
455 
456 // -----------------------------------------------------------
457 void OptimizeDialog::slotEditGoal(QListViewItem *Item)
458 {
459  GoalNameEdit->blockSignals(true);
460 
461  if(Item == 0) {
462  GoalNameEdit->clear();
463  GoalTypeCombo->setCurrentItem(0);
464  GoalNumEdit->clear();
465  GoalNameEdit->blockSignals(false);
466  return;
467  }
468 
469  GoalNameEdit->setText(Item->text(0));
470  GoalTypeCombo->setCurrentText(Item->text(1));
471  GoalNumEdit->setText(Item->text(2));
472  GoalNameEdit->blockSignals(false);
473 }
474 
475 // -----------------------------------------------------------
476 void OptimizeDialog::slotAddGoal()
477 {
478  if(GoalNameEdit->text().isEmpty() || GoalNumEdit->text().isEmpty()) {
479  QMessageBox::critical(this, tr("Error"),
480  tr("Every text field must be non-empty!"));
481  return;
482  }
483 
484  QListViewItem *item;
485  for(item = GoalList->firstChild(); item != 0; item = item->itemBelow())
486  if(item->text(0) == GoalNameEdit->text()) {
487  QMessageBox::critical(this, tr("Error"),
488  tr("Goal \"%1\" already in list!").arg(GoalNameEdit->text()));
489  return;
490  }
491 
492 
493  new QListViewItem(GoalList, GoalNameEdit->text(),
494  GoalTypeCombo->currentText(), GoalNumEdit->text());
495 
496  slotEditGoal(0); // clear entry fields
497  GoalList->clearSelection();
498 }
499 
500 // -----------------------------------------------------------
501 void OptimizeDialog::slotDeleteGoal()
502 {
503  QListViewItem *next_item = 0;
504 
505  QListViewItem *Item = GoalList->selectedItem();
506  if(Item) {
507  next_item = Item->itemBelow();
508  if(next_item == 0) next_item = Item->itemAbove();
509  GoalList->takeItem(Item); // remove from ListView
510  delete Item; // delete item
511  }
512 
513  slotEditGoal(next_item);
514 }
515 
516 // -----------------------------------------------------------
517 void OptimizeDialog::slotChangeGoalName(const QString&)
518 {
519  GoalList->clearSelection();
520 }
521 
522 // -----------------------------------------------------------
523 void OptimizeDialog::slotChangeGoalType(const QString& Text)
524 {
525  QListViewItem *Item = GoalList->selectedItem();
526  if(Item == 0) return;
527 
528  Item->setText(1, Text);
529 }
530 
531 // -----------------------------------------------------------
532 void OptimizeDialog::slotChangeGoalNum(const QString& Text)
533 {
534  QListViewItem *Item = GoalList->selectedItem();
535  if(Item == 0) return;
536 
537  Item->setText(2, Text);
538 }
539 
540 // -----------------------------------------------------------
541 void OptimizeDialog::slotOK()
542 {
543  slotApply();
544  slotCancel();
545 }
546 
547 // -----------------------------------------------------------
548 void OptimizeDialog::slotApply()
549 {
550  Component *pc;
551  if(NameEdit->text().isEmpty())
552  NameEdit->setText(Comp->Name);
553  else
554  if(NameEdit->text() != Comp->Name) {
555  for(pc = Doc->Components->first(); pc!=0; pc = Doc->Components->next())
556  if(pc->Name == NameEdit->text())
557  break; // found component with the same name ?
558  if(pc)
559  NameEdit->setText(Comp->Name);
560  else {
561  Comp->Name = NameEdit->text();
562  changed = true;
563  }
564  }
565 
566  QString Prop;
567  if(SimEdit->currentText() != Comp->Props.at(0)->Value) {
568  Comp->Props.at(0)->Value = SimEdit->currentText();
569  changed = true;
570  }
571  Prop = QString::number(MethodCombo->currentItem()+1) + "|" +
572  IterEdit->text() + "|" +
573  RefreshEdit->text() + "|" +
574  ParentsEdit->text() + "|" +
575  ConstEdit->text() + "|" +
576  CrossEdit->text() + "|" +
577  SeedEdit->text() + "|" +
578  CostVarEdit->text() + "|" +
579  CostObjEdit->text() + "|" +
580  CostConEdit->text();
581  if(Prop != Comp->Props.at(1)->Value) {
582  Comp->Props.at(1)->Value = Prop;
583  changed = true;
584  }
585 
586  QListViewItem *item;
587  Property *pp = Comp->Props.at(2);
588  // apply all the new property values in the ListView
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")));
597 
598  if(pp) {
599  if(pp->Name != "Var") {
600  pp->Name = "Var";
601  changed = true;
602  }
603  if(pp->Value != Prop) {
604  pp->Value = Prop;
605  changed = true;
606  }
607  }
608  else {
609  Comp->Props.append(new Property("Var", Prop, false, ""));
610  changed = true;
611  }
612  pp = Comp->Props.next();
613  }
614 
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"))))) + "|" +
622  item->text(2);
623 
624  if(pp) {
625  if(pp->Name != "Goal") {
626  pp->Name = "Goal";
627  changed = true;
628  }
629  if(pp->Value != Prop) {
630  pp->Value = Prop;
631  changed = true;
632  }
633  }
634  else {
635  Comp->Props.append(new Property("Goal", Prop, false, ""));
636  changed = true;
637  }
638  pp = Comp->Props.next();
639  }
640 
641  // if more properties than in ListView -> delete the rest
642  if(pp) {
643  pp = Comp->Props.prev();
644  Comp->Props.last();
645  while(pp != Comp->Props.current())
646  Comp->Props.remove();
647  changed = true;
648  }
649 
650  if(changed)
651  Doc->viewport()->repaint();
652 }
653 
654 // -------------------------------------------------------------------------
655 // Is called if the "Cancel"-button is pressed.
656 void OptimizeDialog::slotCancel()
657 {
658  if(changed) done(1); // changed could have been done before
659  else done(0); // (by "Apply"-button)
660 }